/** * Store the modification made to an eZContentClass. * * @param eZContentClass Content class to be stored. * @param array[eZContentClassAttribute] Attributes of the new content class. * @param array Unordered view parameters */ public function store(eZContentClass $class, array $attributes, array &$unorderedParameters) { $oldClassAttributes = $class->fetchAttributes($class->attribute('id'), true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExists = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($class->fetchAttributes() as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExists = true; break; } } if (!$attributeExists) { foreach (eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID) as $objectAttribute) { $objectAttribute->removeThis($objectAttribute->attribute('id')); } } } $class->storeDefined($attributes); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExists = false; $newClassAttributeID = $newClassAttribute->attribute('id'); foreach ($oldClassAttributes as $oldClassAttribute) { if ($newClassAttributeID == $oldClassAttribute->attribute('id')) { $attributeExists = true; break; } } if (!$attributeExists) { $newClassAttribute->initializeObjectAttributes($objects); } } }
public static function removeClassAttribute($class_identifier, $attribute_identifier) { if (isset($class_identifier)) { $class = eZContentClass::fetchByIdentifier($class_identifier); } if (!is_object($class)) { return; } $classAttributeIdentifier = $attribute_identifier; // get attributes of 'temporary' version as well $classAttributeList = eZContentClassAttribute::fetchFilteredList(array('contentclass_id' => $class->ID, 'identifier' => $classAttributeIdentifier), true); $validation = array(); foreach ($classAttributeList as $classAttribute) { $dataType = $classAttribute->dataType(); if ($dataType->isClassAttributeRemovable($classAttribute)) { $objectAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList($classAttribute->attribute('id')); foreach ($objectAttributes as $objectAttribute) { $objectAttributeID = $objectAttribute->attribute('id'); $objectAttribute->removeThis($objectAttributeID); } $classAttribute->removeThis(); } else { $removeInfo = $dataType->classAttributeRemovableInformation($classAttribute); } } }
function updateClass($classId, $scheduledScript) { $cli = eZCLI::instance(); /* // If the class is not stored yet, store it now $class = eZContentClass::fetch( $classId, true, eZContentClass::VERSION_STATUS_TEMPORARY ); if ( $class ) { $cli->output( "Storing class" ); $class->storeDefined( $class->fetchAttributes() ); } */ // Fetch the stored class $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); if (!$class) { $cli->error('No class in a modified version status with ID: ' . $classId); return; } // Fetch attributes and definitions $attributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); $oldClassAttributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExist = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($attributes as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExist = true; } } if (!$attributeExist) { foreach (eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID) as $objectAttribute) { $objectAttribute->removeThis($objectAttribute->attribute('id')); } } } $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExist = false; foreach ($oldClassAttributes as $oldClassAttribute) { if ($oldClassAttribute->attribute('id') == $newClassAttribute->attribute('id')) { $attributeExist = true; break; } } if (!$attributeExist) { $objects = null; $newClassAttribute->initializeObjectAttributes($objects); } } if ($scheduledScript !== false) { $scheduledScript->updateProgress(100); } }
/** * Fetch content object 'image' attributes by content class attributes * * @param array $contentClassImageAttributes Array of content class attributes * @return array Array of content object attributes, empty array if not * @static */ static function fetchImageAttributesByClassAttributes($contentClassImageAttributes = array(), $firstVersion = false) { // Default datatypes to create image alias variations $imageDataTypeStrings = eZINI::instance('bcimagealias.ini')->variable('BCImageAliasSettings', 'ImageDataTypeStringList'); $contentObjectImageAttributes = array(); foreach ($contentClassImageAttributes as $contentClassAttribute) { $contentObjectAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList($contentClassAttribute->attribute('id'), true, $firstVersion ? 1 : false); foreach ($contentObjectAttributes as $contentObjectAttribute) { if (in_array($contentObjectAttribute->attribute('data_type_string'), $imageDataTypeStrings) && $contentObjectAttribute->attribute('has_content')) { $contentObjectImageAttributes[] = $contentObjectAttribute; } } } return $contentObjectImageAttributes; }
$i = 0; foreach ($oldOptions as $enumValueID => $name) { $optionNode = $doc->createElement("option"); $optionNode->setAttribute('id', $i); $optionNode->setAttribute('name', $name); $oldToNewIDMap[$enumValueID] = $i; $i++; $options->appendChild($optionNode); } $xml = $doc->saveXML(); $db = eZDB::instance(); $db->begin(); $classAttribute->setAttribute('data_text5', $xml); $classAttribute->setAttribute('data_type_string', 'ezselection'); $classAttribute->store(); $attributes = eZContentObjectAttribute::fetchSameClassAttributeIDList($classAttribute->attribute('id')); $count = count($attributes); $cli->output('number of object attributes to convert: ' . $count); $script->setIterationData('.', '~'); $script->resetIteration($count); for ($i = 0; $i < $count; $i++) { $objectAttributeID = $attributes[$i]->attribute('id'); $objectAttributeVersion = $attributes[$i]->attribute('version'); $selectOptions = array(); $enumContent = $attributes[$i]->attribute('content'); $enumObjectValues = $enumContent->attribute('enumobject_list'); foreach ($enumObjectValues as $enumObjectValue) { $value = $enumObjectValue->attribute('enumvalue'); $element = $enumObjectValue->attribute('enumelement'); $enumValueID = $enumObjectValue->attribute('enumid'); if (!array_key_exists($enumValueID, $oldToNewIDMap)) {
function removeClassAttribute( $params ) { $contentClassID = $params['class_id']; $classAttributeIdentifier = $params['attribute_identifier']; // get attributes of 'temporary' version as well $classAttributeList = eZContentClassAttribute::fetchFilteredList( array( 'contentclass_id' => $contentClassID, 'identifier' => $classAttributeIdentifier ), true ); $validation = array(); foreach( $classAttributeList as $classAttribute ) { $dataType = $classAttribute->dataType(); if( $dataType->isClassAttributeRemovable( $classAttribute ) ) { $objectAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList( $classAttribute->attribute( 'id' ) ); foreach( $objectAttributes as $objectAttribute ) { $objectAttributeID = $objectAttribute->attribute( 'id' ); $objectAttribute->removeThis( $objectAttributeID ); } $classAttribute->removeThis(); } else { $removeInfo = $dataType->classAttributeRemovableInformation( $classAttribute ); if( $removeInfo === false ) $removeInfo = "Unknow reason"; $validation[] = array( 'id' => $classAttribute->attribute( 'id' ), 'identifier' => $classAttribute->attribute( 'identifier' ), 'reason' => $removeInfo ); } } if( count( $validation ) > 0 ) { $this->reportError( $validation, 'eZSiteInstaller::removeClassAttribute: Unable to remove eZClassAttribute(s)' ); } }
$priceClassAttribute->setAttribute(eZMultiPriceType::DEFAULT_CURRENCY_CODE_FIELD, $defaultCurrencyCode); $priceClassAttribute->store(); unset($GLOBALS['eZContentClassAttributeCache'][$priceClassAttributeID]); // update objects $offset = 0; $limit = 1000; $cli->output('Converting', false); while ($offset < $objectListCount) { $objectList = eZContentObject::fetchSameClassList($class->attribute('id'), true, $offset, $limit); $offset += count($objectList); foreach ($objectList as $object) { $contentObjectID = $object->attribute('id'); $objectVersions =& $object->versions(); foreach ($objectVersions as $objectVersion) { $version = $objectVersion->attribute('version'); $objectAttributeList = eZContentObjectAttribute::fetchSameClassAttributeIDList($priceClassAttributeID, true, $version, $contentObjectID); foreach ($objectAttributeList as $objectAttribute) { $priceValue = $objectAttribute->attribute('data_float'); $multiprice = eZMultiPriceData::create($objectAttribute->attribute('id'), $version, $defaultCurrencyCode, $priceValue, eZMultiPriceData::VALUE_TYPE_CUSTOM); $multiprice->store(); $objectAttribute->setAttribute('data_type_string', 'ezmultiprice'); $objectAttribute->setAttribute('data_float', 0); $objectAttribute->setAttribute('sort_key_int', 0); $objectAttribute->store(); } } $cli->output('.', false); ++$convertedObjectsCount; } } $cli->output(' ');
/** * @param eZContentClassAttribute $localeAttribute * @param string $newDataTypeString */ protected function changeContentObjectAttributeDataTypeString($localeAttribute, $newDataTypeString) { /** @var eZContentObjectAttribute[] $contentAttributes */ $contentAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList($localeAttribute->attribute('id'), true); foreach ($contentAttributes as $attribute) { $attribute->setAttribute('data_type_string', $newDataTypeString); $attribute->store(); } }
function updateClass($classId, $scheduledScript) { $cli = eZCLI::instance(); /* // If the class is not stored yet, store it now $class = eZContentClass::fetch( $classId, true, eZContentClass::VERSION_STATUS_TEMPORARY ); if ( $class ) { $cli->output( "Storing class" ); $class->storeDefined( $class->fetchAttributes() ); } */ // Fetch the stored class $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); if (!$class) { $cli->error('No class in a modified version status with ID: ' . $classId); return; } // Fetch attributes and definitions $attributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_MODIFIED); $oldClassAttributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_DEFINED); // Delete object attributes which have been removed. foreach ($oldClassAttributes as $oldClassAttribute) { $attributeExist = false; $oldClassAttributeID = $oldClassAttribute->attribute('id'); foreach ($attributes as $newClassAttribute) { if ($oldClassAttributeID == $newClassAttribute->attribute('id')) { $attributeExist = true; } } if (!$attributeExist) { $ezscriptmonitorINI = eZINI::instance('ezscriptmonitor.ini'); $objectLimit = $ezscriptmonitorINI->variable('GeneralSettings', 'ObjectLimit'); $limit = array('offset' => 0, 'length' => $objectLimit); do { $objectAttributes = eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID, false, false, false, $limit); $objectAttributeCount = count($objectAttributes); $conditions = array("contentclassattribute_id" => $oldClassAttributeID); $totalObjectAttributeCount = eZContentObjectAttribute::count(eZContentObjectAttribute::definition(), array("contentclassattribute_id" => $oldClassAttributeID)); if (is_array($objectAttributes) && $objectAttributeCount > 0) { $db = eZDB::instance(); $db->begin(); foreach ($objectAttributes as $objectAttribute) { $objectAttribute = new eZContentObjectAttribute($objectAttribute); $objectAttribute->removeThis($objectAttribute->attribute('id')); } $db->commit(); $limit['offset'] += $objectAttributeCount; $percentage = round(100 * $limit['offset'] / $totalObjectAttributeCount, 2); // for ezscriptmonitor 100 means the script is all the way done if ($percentage < 100 && $scheduledScript !== false) { $scheduledScript->updateProgress($percentage); } $cli->output("Removing attributes - Progress: " . $percentage . " %"); } } while ($objectAttributeCount == $objectLimit); } } $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED); // Add object attributes which have been added. foreach ($attributes as $newClassAttribute) { $attributeExist = false; foreach ($oldClassAttributes as $oldClassAttribute) { if ($oldClassAttribute->attribute('id') == $newClassAttribute->attribute('id')) { $attributeExist = true; break; } } if (!$attributeExist) { $objects = null; $cli->output("Adding attribute : " . $newClassAttribute->attribute('name')); $newClassAttribute->initializeObjectAttributes($objects); } } if ($scheduledScript !== false) { $scheduledScript->updateProgress(100); } }