Esempio n. 1
0
 public static function updateAttribute($classIdentifier, $newAttributeXPath)
 {
     $contentClass = eZContentClass::fetchByIdentifier($classIdentifier);
     if (!$contentClass) {
         throw new Exception("Failed to instantiate content class [" . $classIdentifier . "]");
     }
     $newAttributeIdentifier = trim($newAttributeXPath->query("//newattribute/identifier")->item(0)->nodeValue);
     $classDataMap = $contentClass->attribute('data_map');
     if (!isset($classDataMap[$newAttributeIdentifier])) {
         // attribute is not set in the class, so add it to the class
         $classAttributeID = AttributeFunctions::addAttributeToClass($contentClass, $newAttributeXPath);
         // update all the objects with the new attribute
         AttributeFunctions::updateContentObjectAttributes($contentClass, $classAttributeID, $newAttributeIdentifier);
     } else {
         // in case we're repairing an attribute that was added in the ui and
         // timed out before all the objects were updated
         $classAttributeID = $classDataMap[$newAttributeIdentifier]->attribute('id');
         AttributeFunctions::updateContentObjectAttributes($contentClass, $classAttributeID, $newAttributeIdentifier);
     }
 }