Created
December 16, 2019 09:50
-
-
Save brusch/56f0405b5210e97bf9db6c48cd237bf3 to your computer and use it in GitHub Desktop.
Pimcore 6 Content Migration Script
This file contains hidden or 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
<?php | |
include_once __DIR__ . "/vendor/autoload.php"; | |
\Pimcore\Bootstrap::setProjectRoot(); | |
\Pimcore\Bootstrap::startupCli(); | |
use Pimcore\Model\DataObject; | |
$search = 'O:30:"Pimcore\Model\Object\Data\Link"'; | |
$replace = 'O:34:"Pimcore\Model\DataObject\Data\Link"'; | |
$db = \Pimcore\Db::get(); | |
$schema = $db->getSchemaManager(); | |
foreach($schema->listTables() as $table) { | |
if(strpos($table->getName(), 'object_') === 0) { | |
// skip relation tables | |
if(strpos($table->getName(), 'object_relations_') === 0) { | |
continue; | |
} | |
foreach($table->getColumns() as $column) { | |
//echo sprintf('[%s][%s]', $column->getName(), $table->getName()) . "\n"; | |
try { | |
$sql = sprintf("SELECT %s FROM %s WHERE %s LIKE %s ESCAPE '|'", | |
$db->quoteIdentifier($column->getName()), | |
$db->quoteIdentifier($table->getName()), | |
$db->quoteIdentifier($column->getName()), | |
$db->quote('%' . $search . '%') | |
); | |
$result = $db->fetchOne($sql); | |
if ($result) { | |
echo sprintf('Found link field [%s] in table [%s]', $column->getName(), $table->getName()) . "\n"; | |
$db->query(sprintf('UPDATE %s SET %s = REPLACE(%s, ?, ?)', | |
$db->quoteIdentifier($table->getName()), | |
$db->quoteIdentifier($column->getName()), | |
$db->quoteIdentifier($column->getName())), | |
[ | |
$search, | |
$replace, | |
]); | |
} | |
} catch (\Exception $e) { | |
echo $e->getMessage() . "\n"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment