ExtensionUninstallCommand.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Dcat\Admin\Console;
  3. use Dcat\Admin\Admin;
  4. use Illuminate\Console\Command;
  5. class ExtensionUninstallCommand extends Command
  6. {
  7. protected $signature = 'admin:ext-uninstall
  8. {name : The name of the extension. Eg: author-name/extension-name}';
  9. protected $description = 'Uninstall an existing extension';
  10. public function handle()
  11. {
  12. $name = $this->argument('name');
  13. $confirmQuestion = 'Please confirm that you wish to completely rollback this extension. This may result in potential data loss.';
  14. if ($this->confirm($confirmQuestion)) {
  15. try {
  16. Admin::extension()
  17. ->updateManager()
  18. ->setOutPut($this->output)
  19. ->uninstall($name);
  20. } catch (\Throwable $exception) {
  21. $lastVersion = Admin::extension()->versionManager()->getCurrentVersion($name);
  22. $this->output->writeln(sprintf('<comment>An exception occurred during the rollback and the process has been stopped. The extension was rolled back to version v%s.</comment>', $lastVersion));
  23. throw $exception;
  24. }
  25. }
  26. }
  27. }