Skip to content

Instantly share code, notes, and snippets.

@AndreiTelteu
Last active May 21, 2019 18:14
Show Gist options
  • Save AndreiTelteu/d92553d48041221c2b3db91b13a63ede to your computer and use it in GitHub Desktop.
Save AndreiTelteu/d92553d48041221c2b3db91b13a63ede to your computer and use it in GitHub Desktop.
SQL Replace domain in Magento 1.x installation
UPDATE `core_config_data`
SET `value` = REPLACE(value, 'old-domain.com', 'new-domain.com')
WHERE `path` LIKE '%secure/base_url%' OR `path` = 'web/cookie/cookie_domain'
// with regex
UPDATE `subcategories` SET `name` = REGEXP_REPLACE(name,'^(.*)$','{"ro":"\\1","en":"\\1"}')
@AndreiTelteu
Copy link
Author

A command for laravel, with support for serialized data

        $old = 'old.domain.com';
        $new = 'new.domain.com';
        
        $coreSettings = \DB::table('core_settings')
            ->where('content', 'LIKE', '%'.$old.'%')
            ->get();
        
        foreach ($coreSettings as $row) {
            $content = unserialize($row->content);
            $contentJson = json_encode($content);
            echo "OLD: $contentJson\n";
            
            $contentJson = str_replace('http://'.$old,        'http://'.$new,        $contentJson);
            $contentJson = str_replace('https://'.$old,       'https://'.$new,       $contentJson);
            $contentJson = str_replace('http:\/\/'.$old,      'http:\/\/'.$new,      $contentJson);
            $contentJson = str_replace('https:\/\/'.$old,     'https:\/\/'.$new,     $contentJson);
            $contentJson = str_replace('http%3A%2F%2F'.$old,  'http%3A%2F%2F'.$new,  $contentJson);
            $contentJson = str_replace('https%3A%2F%2F'.$old, 'https%3A%2F%2F'.$new, $contentJson);
            
            echo "NEW: $contentJson\n\n";
            $content = json_decode($contentJson, true);
            \DB::table('core_settings')
                ->where('id', $row->id)
                ->update(['content' => serialize($content)]);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment