RemoveModuleCommand.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Console\Commands\Base;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. use Illuminate\Support\Str;
  7. /**
  8. * Class PresenterCommand
  9. * @package Prettus\Repository\Generators\Commands
  10. * @author Anderson Andrade <contato@andersonandra.de>
  11. */
  12. class RemoveModuleCommand extends Command
  13. {
  14. /**
  15. * The name of command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'remove:module {name}';
  20. /**
  21. * The description of command.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'init setting';
  26. /**
  27. * The type of class being generated.
  28. *
  29. * @var string
  30. */
  31. protected $type = 'setting';
  32. /**
  33. * Execute the command.
  34. *
  35. * @return void
  36. * @see fire()
  37. */
  38. public function handle()
  39. {
  40. $name = $this->argument('name');
  41. try {
  42. if ($name) {
  43. $repositoriesPath = "app/Contracts/Repositories/{$name}";
  44. $adminControllerPath = "app/Http/Controllers/Admin/{$name}";
  45. $apiControllerPath = "app/Http/Controllers/Api/{$name}";
  46. $jobPath = "app/Jobs/{$name}";
  47. $criteriaPath = "app/Repositories/Criteria/{$name}";
  48. $eloquentPath = "app/Repositories/Eloquent/{$name}";
  49. $enumsPath = "app/Repositories/Enums/{$name}";
  50. $modelsPath = "app/Repositories/Models/{$name}";
  51. $presentersPath = "app/Repositories/Presenters/{$name}";
  52. $transformersPath = "app/Repositories/Transformers/{$name}";
  53. $validatorsPath = "app/Repositories/Validators/{$name}";
  54. $servicesPath = "app/Services/{$name}";
  55. $commandsPath = "app/Console/Commands/{$name}";
  56. exec('rm -r ' . base_path($repositoriesPath));
  57. exec('rm -r ' . base_path($adminControllerPath));
  58. exec('rm -r ' . base_path($apiControllerPath));
  59. exec('rm -r ' . base_path($jobPath));
  60. exec('rm -r ' . base_path($criteriaPath));
  61. exec('rm -r ' . base_path($eloquentPath));
  62. exec('rm -r ' . base_path($enumsPath));
  63. exec('rm -r ' . base_path($modelsPath));
  64. exec('rm -r ' . base_path($presentersPath));
  65. exec('rm -r ' . base_path($transformersPath));
  66. exec('rm -r ' . base_path($validatorsPath));
  67. exec('rm -r ' . base_path($servicesPath));
  68. exec('rm -r ' . base_path($commandsPath));
  69. $tables = js2php(php2js(DB::select('show tables')));
  70. $tables = array_column($tables, 'Tables_in_' . env('DB_DATABASE'));
  71. foreach ($tables as $table) {
  72. $if = Str::is(strtolower($name) . '_*', $table);
  73. $this->line('删除数据库:' . $table);
  74. if ($if) {
  75. Schema::dropIfExists($table);
  76. }
  77. }
  78. $this->line('删除成功');
  79. }
  80. } catch (\Exception $exception) {
  81. dd($exception);
  82. }
  83. $this->line('ok');
  84. }
  85. }