RemoveModuleCommand.php 3.4 KB

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