This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Command to help with domain migrations
- Loading branch information
1 parent
da44243
commit 2af9d6b
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters