$cli->warning("This script will NOT republish objects, but rather update ALL versions"); $cli->warning("of content objects. If you do not wish to do that, you have"); $cli->warning("15 seconds to cancel the script! (press Ctrl-C)\n"); sleep(15); $db = eZDB::instance(); $offset = 0; $limit = 50; $attributeCount = (int) eZPersistentObject::count(eZContentObjectAttribute::definition(), array('data_type_string' => 'sckenhancedselection')); while ($offset < $attributeCount) { eZContentObject::clearCache(); /** @var eZContentObjectAttribute[] $attributes */ $attributes = eZPersistentObject::fetchObjectList(eZContentObjectAttribute::definition(), null, array('data_type_string' => 'sckenhancedselection'), null, array('offset' => $offset, 'length' => $limit)); foreach ($attributes as $attribute) { SckEnhancedSelection::removeByAttribute($attribute->attribute('id'), $attribute->attribute('version')); $identifiers = unserialize((string) $attribute->attribute('data_text')); if (is_array($identifiers) && !empty($identifiers)) { foreach ($identifiers as $identifier) { $sckEnhancedSelection = new SckEnhancedSelection(array('contentobject_attribute_id' => $attribute->attribute('id'), 'contentobject_attribute_version' => $attribute->attribute('version'), 'identifier' => $identifier)); $sckEnhancedSelection->store(); } } $attribute->setAttribute('data_text', null); $attribute->store(); $cli->output("Converted attribute #{$attribute->attribute('id')} in version {$attribute->attribute('version')}"); } unset($attributes); $offset += $limit; } $cli->output("\nDone!"); $cli->output("\nFor changes to take effect, please clear the caches, reindex your content and so on.\n"); $script->shutdown(0);
/** * Stores the datatype data to the database which is related to the object attribute. * * @param eZContentObjectAttribute $objectAttribute */ public function storeObjectAttribute($objectAttribute) { $content = $objectAttribute->content(); SckEnhancedSelection::removeByAttribute($objectAttribute->attribute('id'), $objectAttribute->attribute('version')); if (!is_array($content)) { $content = array(); } foreach ($content as $identifier) { $sckEnhancedSelection = new SckEnhancedSelection(array('contentobject_attribute_id' => $objectAttribute->attribute('id'), 'contentobject_attribute_version' => $objectAttribute->attribute('version'), 'identifier' => $identifier)); $sckEnhancedSelection->store(); } }