diff --git a/src/Commands/DomainMigrationCommand.php b/src/Commands/DomainMigrationCommand.php new file mode 100644 index 0000000..c067613 --- /dev/null +++ b/src/Commands/DomainMigrationCommand.php @@ -0,0 +1,47 @@ +handle(); + } + + public function handle() + { + + $oldDomain = $this->ask('Enter the old domain:'); + $newDomain = $this->ask('Enter the new domain to replace the old domain:'); + + if( !strlen($oldDomain) || !strlen($newDomain) ){ + $this->error('Please enter your old and new domain!'); + } else { + DB::statement( DB::raw("UPDATE pages SET content = replace(content, :olddomain, :newdomain)"), [ 'olddomain' => $oldDomain, 'newdomain' => $newDomain ]); + DB::statement( DB::raw("UPDATE posts SET content = replace(content, :olddomain, :newdomain)"), [ 'olddomain' => $oldDomain, 'newdomain' => $newDomain ]); + + DB::statement( DB::raw("UPDATE pages SET block_content = replace(block_content::TEXT,:olddomain,:newdomain)::json"), [ 'olddomain' => $oldDomain, 'newdomain' => $newDomain ]); + DB::statement( DB::raw("UPDATE posts SET block_content = replace(block_content::TEXT,:olddomain,:newdomain)::json"), [ 'olddomain' => $oldDomain, 'newdomain' => $newDomain ]); + + $this->info('Clearing cache.'); + $this->call('cache:clear'); + $this->call('view:clear'); + + $this->info('Domain has been updated in pages and posts.'); + } + + } + + + +} diff --git a/src/NeutrinoServiceProvider.php b/src/NeutrinoServiceProvider.php index 2bd38cc..1565c36 100644 --- a/src/NeutrinoServiceProvider.php +++ b/src/NeutrinoServiceProvider.php @@ -129,6 +129,7 @@ private function registerConsoleCommands() $this->commands(Commands\InstallCommand::class); $this->commands(Commands\AdminCommand::class); $this->commands(Commands\UpdateCommand::class); + $this->commands(Commands\DomainMigrationCommand::class); } private function initActions()