Skip to content

Instantly share code, notes, and snippets.

@dvesh3
Last active January 16, 2024 13:03
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 dvesh3/50a1a99fd337d461e1652f2fd3b4d6cd to your computer and use it in GitHub Desktop.
Save dvesh3/50a1a99fd337d461e1652f2fd3b4d6cd to your computer and use it in GitHub Desktop.
Scripts for re-saving versions & recycle-bin items for the purpose of migrating o_ prefix properties on Pimcore 10.6
<?php
// file should be located in project root
use Pimcore\Tool\Serialize;
use Pimcore\Tool\Storage;
ini_set('max_execution_time', 0);
ini_set("memory_limit", "-1");
include_once __DIR__ . "/vendor/autoload.php";
$bootstrap = new \Pimcore\Bootstrap();
$bootstrap->startup();
$offset = 0;
$limit = 100;
$storage = Storage::get('recycle_bin');
while (true) {
$list = new \Pimcore\Model\Element\Recyclebin\Item\Listing();
$list->setOffset($offset);
$list->setLimit($limit);
$list->setCondition("`type` = 'object'");
$list = $list->load();
if (!$list) {
break;
}
foreach ($list as $item) {
$filePath = $item->getStoreageFile();
$data = $storage->read($item->getStoreageFile());
if (!$data) {
echo sprintf("RecycleBin (ID %d): cannot read recycled data.\n ", $item->getId());
continue;
}
$data = Serialize::unserialize($data);
if ($data instanceof Pimcore\Model\DataObject\AbstractObject) {
echo "Migrating recycled item: " . $item->getId() . "\n";
$item->setElement($data);
$item->save();
}
}
$offset += $limit;
Pimcore::collectGarbage();
}
echo "Done Recyclebin migration.";
<?php
// file should be located in project root
ini_set('max_execution_time', 0);
ini_set("memory_limit", "-1");
include_once __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->setCondition("`ctype` = 'object'");
$list = $list->load();
if (!$list) {
break;
}
foreach ($list as $version) {
$data = null;
$data = $version->getData();
if (!$data) {
echo sprintf("Version (ID %d): cannot read version data.\n ", $version->getId());
continue;
}
if ($data instanceof Pimcore\Model\DataObject\AbstractObject) {
echo "Migrating version ID: " . $version->getId() . "\n";
$version->setData($data);
$version->save();
}
}
$offset += $limit;
Pimcore::collectGarbage();
}
echo "Done Versions migration.";
@Daniel-Ateles
Copy link

Have anyone made similar script for PricingRule-objects in the ecom-framework backed by the db table ecommerceframework_pricing_rule?

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