Last active
July 15, 2020 11:11
-
-
Save weisswurstkanone/a63f733fe58930778f41c695f862724a to your computer and use it in GitHub Desktop.
Version/Recyclebin files - Namespace migration of ElementDescriptor
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
<?php | |
// for recyclebin files | |
// file should be located in project root | |
ini_set('max_execution_time', 0); | |
ini_set("memory_limit", "-1"); | |
include __DIR__ . "/vendor/autoload.php"; | |
$bootstrap = new \Pimcore\Bootstrap(); | |
$bootstrap->startup(); | |
$offset = 0; | |
$limit = 100; | |
while (true) { | |
$list = new \Pimcore\Model\Element\Recyclebin\Item\Listing();; | |
$list->setOffset($offset); | |
$list->setLimit($limit); | |
$list = $list->load(); | |
if (!$list) { | |
break; | |
} | |
/** @var \Pimcore\Model\Element\Recyclebin\Item $item */ | |
foreach ($list as $item) { | |
echo("migrating recycled item: " . $item->getId() . "\n"); | |
$filePath = $item->getStoreageFile(); | |
if (is_file($filePath) && is_readable($filePath)) { | |
$data = file_get_contents($filePath); | |
} | |
if (!$data) { | |
echo('RecycleBin: cannot read recycled data from file system. ' . $filePath ."\n"); | |
continue; | |
} | |
if (strpos($data, 'Pimcore\\Model\\Version\\ElementDescriptor') !== false) { | |
$newData = str_replace('Pimcore\\Model\\Version\\ElementDescriptor', 'Pimcore\\Model\\Version\\ElementDescriptor', $data); | |
if ($data != $newData) { | |
echo("Updating " . $filePath . "\n"); | |
// write update | |
file_put_contents($filePath, $newData); | |
} | |
} | |
$offset += $limit; | |
Pimcore::collectGarbage(); | |
} | |
} | |
echo("done\n"); |
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
<?php | |
// for version files | |
// file should be located in project root | |
ini_set('max_execution_time', 0); | |
ini_set("memory_limit", "-1"); | |
include __DIR__ . "/vendor/autoload.php"; | |
$bootstrap = new \Pimcore\Bootstrap(); | |
$bootstrap->startup(); | |
$offset = 0; | |
$limit = 100; | |
while (true) { | |
$list = new \Pimcore\Model\Version\Listing(); | |
$list->setOffset($offset); | |
$list->setLimit($limit); | |
$list = $list->load(); | |
if (!$list) { | |
break; | |
} | |
/** @var \Pimcore\Model\Version $version */ | |
foreach ($list as $version) { | |
echo("migrate version " . $version->getId() . "\n"); | |
$data = null; | |
$zipped = false; | |
$filePath = null; | |
// check both the legacy file path and the new structure | |
foreach ([$version->getFilePath(), $version->getLegacyFilePath()] as $path) { | |
if (file_exists($path)) { | |
$filePath = $path; | |
break; | |
} | |
if (file_exists($path . '.gz')) { | |
$filePath = $path . '.gz'; | |
$zipped = true; | |
break; | |
} | |
} | |
if ($zipped && is_file($filePath) && is_readable($filePath)) { | |
$data = gzdecode(file_get_contents($filePath)); | |
} elseif (is_file($filePath) && is_readable($filePath)) { | |
$data = file_get_contents($filePath); | |
} | |
if (!$data) { | |
echo('Version: cannot read version data from file system. ' . $filePath ."\n"); | |
continue; | |
} | |
if (strpos($data, 'Pimcore\\Model\\Version\\ElementDescriptor') !== false) { | |
$newData = str_replace('Pimcore\\Model\\Version\\ElementDescriptor', 'Pimcore\\Model\\Element\\ElementDescriptor', $data); | |
if ($data != $newData) { | |
echo("Updating " . $filePath . "\n"); | |
// write update | |
if ($zipped) { | |
$newData = gzencode($data); | |
file_put_contents($filePath, $newData); | |
} else { | |
file_put_contents($filePath, $newData); | |
} | |
} | |
} | |
} | |
$offset += $limit; | |
Pimcore::collectGarbage(); | |
} | |
echo("done"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment