Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save weisswurstkanone/a63f733fe58930778f41c695f862724a to your computer and use it in GitHub Desktop.
Save weisswurstkanone/a63f733fe58930778f41c695f862724a to your computer and use it in GitHub Desktop.
Version/Recyclebin files - Namespace migration of ElementDescriptor
<?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");
<?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