123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Console\Commands\Base;
- use App\Repositories\Models\Base\Dict;
- use App\Repositories\Models\Base\DictDetail;
- use App\Repositories\Models\Base\Role;
- use App\Repositories\Models\Base\Setting;
- use App\Repositories\Models\Human\Human;
- use Illuminate\Console\Command;
- use Illuminate\Support\Arr;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Schema;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Str;
- /**
- * Class PresenterCommand
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- class RemoveModuleCommand extends Command
- {
- /**
- * The name of command.
- *
- * @var string
- */
- protected $signature = 'remove:module {name}';
- /**
- * The description of command.
- *
- * @var string
- */
- protected $description = 'init setting';
- /**
- * The type of class being generated.
- *
- * @var string
- */
- protected $type = 'setting';
- /**
- * Execute the command.
- *
- * @return void
- * @see fire()
- */
- public function handle()
- {
- $name = $this->argument('name');
- try {
- if ($name) {
- $repositoriesPath = "app/Contracts/Repositories/{$name}";
- $adminControllerPath = "app/Http/Controllers/Admin/{$name}";
- $apiControllerPath = "app/Http/Controllers/Api/{$name}";
- $jobPath = "app/Jobs/{$name}";
- $criteriaPath = "app/Repositories/Criteria/{$name}";
- $eloquentPath = "app/Repositories/Eloquent/{$name}";
- $enumsPath = "app/Repositories/Enums/{$name}";
- $modelsPath = "app/Repositories/Models/{$name}";
- $presentersPath = "app/Repositories/Presenters/{$name}";
- $transformersPath = "app/Repositories/Transformers/{$name}";
- $validatorsPath = "app/Repositories/Validators/{$name}";
- $servicesPath = "app/Services/{$name}";
- $commandsPath = "app/Console/Commands/{$name}";
- exec('rm -r ' . base_path($repositoriesPath));
- exec('rm -r ' . base_path($adminControllerPath));
- exec('rm -r ' . base_path($apiControllerPath));
- exec('rm -r ' . base_path($jobPath));
- exec('rm -r ' . base_path($criteriaPath));
- exec('rm -r ' . base_path($eloquentPath));
- exec('rm -r ' . base_path($enumsPath));
- exec('rm -r ' . base_path($modelsPath));
- exec('rm -r ' . base_path($presentersPath));
- exec('rm -r ' . base_path($transformersPath));
- exec('rm -r ' . base_path($validatorsPath));
- exec('rm -r ' . base_path($servicesPath));
- exec('rm -r ' . base_path($commandsPath));
- $tables = js2php(php2js(DB::select('show tables')));
- $tables = array_column($tables, 'Tables_in_' . env('DB_DATABASE'));
- foreach ($tables as $table) {
- $if = Str::is(strtolower($name) . '_*', $table);
- $this->line('删除数据库:' . $table);
- if ($if) {
- Schema::dropIfExists($table);
- }
- }
- $this->line('删除成功');
- }
- } catch (\Exception $exception) {
- dd($exception);
- }
- $this->line('ok');
- }
- }
|