Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Command to help with domain migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
newelement committed Jan 24, 2021
1 parent da44243 commit 2af9d6b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Commands/DomainMigrationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace Newelement\Neutrino\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Newelement\Neutrino\Facades\Neutrino;
use DB;

class DomainMigrationCommand extends Command
{

protected $name = 'neutrino:domainmigrate';

protected $description = 'Updates any old domains with the new domain.';


public function fire()
{
return $this->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.');
}

}



}
1 change: 1 addition & 0 deletions src/NeutrinoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2af9d6b

Please sign in to comment.