ExtensionInstallCommand.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Dcat\Admin\Console;
  3. use Dcat\Admin\Admin;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Arr;
  6. class ExtensionInstallCommand extends Command
  7. {
  8. protected $signature = 'admin:ext-install
  9. {name : The name of the extension. Eg: author-name/extension-name}
  10. {--path= : The path of the extension.}';
  11. protected $description = 'Install an extension';
  12. public function handle()
  13. {
  14. $name = $this->argument('name');
  15. $path = $this->option('path');
  16. $manager = Admin::extension()->setOutput($this->output);
  17. if ($path) {
  18. if (! is_file($path)) {
  19. $path = rtrim($path, '/').sprintf('/%s.zip', str_replace('/', '.', $name));
  20. }
  21. } else {
  22. $extensionDetails = $manager->requestDetails($name);
  23. $path = $hash = Arr::get($extensionDetails, 'hash');
  24. $this->output->writeln(sprintf('<info>Downloading extension: %s[%s]</info>', $name, $hash));
  25. $manager->download($name, $hash, true);
  26. }
  27. $this->output->writeln(sprintf('<info>Unpacking extension: %s</info>', $name));
  28. $manager->extract($path);
  29. $this->output->writeln(sprintf('<info>Migrating extension...</info>', $name));
  30. Admin::extension()->load();
  31. $manager
  32. ->updateManager()
  33. ->setOutPut($this->output)
  34. ->update($name);
  35. }
  36. }