From ae8e6416686df3da242d59bdd82860df4b940ce7 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Mon, 31 Mar 2025 20:08:47 +0300 Subject: [PATCH] Remove `operations:upgrade` console command --- src/Console/Upgrade.php | 18 ---- src/Constants/Names.php | 1 - src/Processors/Upgrade.php | 191 ------------------------------------- src/ServiceProvider.php | 1 - 4 files changed, 211 deletions(-) delete mode 100644 src/Console/Upgrade.php delete mode 100644 src/Processors/Upgrade.php diff --git a/src/Console/Upgrade.php b/src/Console/Upgrade.php deleted file mode 100644 index 20a00333..00000000 --- a/src/Console/Upgrade.php +++ /dev/null @@ -1,18 +0,0 @@ -alreadyUpgraded()) { - $this->notification->info('Operations upgrade already done'); - - return; - } - - $this->run(); - } - - protected function run(): void - { - $this->moveFiles(); - $this->moveConfig(); - $this->moveStub(); - $this->callMigration(); - $this->clean(); - } - - protected function moveFiles(): void - { - foreach ($this->getOldFiles() as $filename) { - $this->notification->task($filename, fn () => $this->move( - $this->oldPath($filename . '.php'), - $this->newPath($filename . '.php') - )); - } - } - - protected function move(string $from, string $to): void - { - $content = $this->open($from); - - $content = $this->replaceNamespace($content); - $content = $this->replaceClassName($content); - $content = $this->replaceMethod($content); - $content = $this->replaceDeclareStrictType($content); - $content = $this->replaceWithInvoke($content); - - $this->store($to, $content); - } - - protected function clean(): void - { - $this->notification->task( - 'Delete old directory', - fn () => Directory::ensureDelete($this->oldPath()) - ); - } - - protected function open(string $filename): string - { - return file_get_contents($filename); - } - - protected function store(string $filename, string $content): void - { - File::store($filename, $content); - } - - protected function replaceNamespace(string $content): string - { - return Str::of($content)->replace( - ['DragonCode\\LaravelActions\\Action', 'Action'], - ['DragonCode\\LaravelDeployOperations\\Operation', 'Operation'], - )->toString(); - } - - protected function replaceClassName(string $content): string - { - return Str::of($content) - ->pregReplace( - '/((?:return\s+new\s+class\s*\(?\s*\)?|final\s+class|class)\s*.+extends\s+Action)/', - 'return new class extends Operation' - ) - ->trim() - ->trim(';') - ->append(';') - ->append(PHP_EOL) - ->toString(); - } - - protected function replaceMethod(string $content): string - { - return Str::of($content) - ->replace('enabledTransactions', 'hasTransactions') - ->toString(); - } - - protected function replaceDeclareStrictType(string $content): string - { - return Str::of($content) - ->pregReplace('(declare\s*\(\s*strict_types\s*=\s*[1|0]\);)', '') - ->replace("toString(); - } - - protected function replaceWithInvoke(string $content): string - { - return Str::of($content) - ->when(! Str::matchContains($content, '/public\s+function\s+down/'), function (Stringable $string) { - return $string->pregReplace('/(public\s+function\s+up)/', 'public function __invoke'); - })->toString(); - } - - protected function moveConfig(): void - { - $this->notification->task('Moving config file', function () { - $this->runCommand('vendor:publish', [ - '--provider' => ServiceProvider::class, - '--force' => true, - ]); - - $path = config_path('deploy-operations.php'); - - $table = config('actions.table', 'operations'); - - $content = Str::replace(file_get_contents($path), "'table' => 'operations'", "'table' => '$table'"); - - file_put_contents($path, $content); - - File::ensureDelete(config_path('actions.php')); - }); - } - - protected function moveStub(): void - { - if (! File::exists(base_path('stubs/action.stub'))) { - $this->notification->info('Stub file doesn\'t exist.'); - - return; - } - - $this->notification->task('Moving stub file', fn () => $this->move( - base_path('stubs/action.stub'), - base_path('stubs/deploy-operation.stub'), - )); - } - - protected function callMigration(): void - { - $this->notification->task('Call migrations', function () { - $this->runCommand('migrate', [ - '--path' => __DIR__ . '/../../database/migrations/2024_05_21_112438_rename_actions_table_to_operations.php', - '--realpath' => true, - '--force' => true, - ]); - - $this->runCommand('migrate', [ - '--path' => __DIR__ . '/../../database/migrations/2024_05_21_114318_rename_column_in_operations_table', - '--realpath' => true, - '--force' => true, - ]); - }); - } - - protected function getOldFiles(): array - { - return $this->getFiles($this->oldPath()); - } - - protected function oldPath(?string $filename = null): string - { - return base_path('actions/' . $filename); - } - - protected function newPath(?string $filename = null): string - { - return $this->options->path . '/' . $filename; - } - - protected function alreadyUpgraded(): bool - { - return Directory::exists($this->newPath()); - } -} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 80309343..f3eec5bb 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -39,7 +39,6 @@ protected function registerCommands(): void Console\Reset::class, Console\Rollback::class, Console\Status::class, - Console\Upgrade::class, ]); }