Пример #1
0
 private function attribute_migrate($classIdentifier, $srcAttribute, $conversion, $destAttribute)
 {
     $contentClass = eZContentClass::fetchByIdentifier($classIdentifier);
     if (!$contentClass) {
         throw new Exception("Failed to instantiate content class [" . $classIdentifier . "]");
     }
     $classDataMap = $contentClass->attribute("data_map");
     if (!isset($classDataMap[$srcAttribute])) {
         throw new Exception("Content class '" . $classIdentifier . "' does not contain this attribute: [" . $srcAttribute . "]");
     }
     if (!isset($classDataMap[$destAttribute])) {
         throw new Exception("Content class '" . $classIdentifier . "' does not contain this attribute: [" . $destAttribute . "]");
     }
     $classId = $contentClass->attribute("id");
     $objects = eZContentObject::fetchSameClassList($classId, false);
     $numObjects = count($objects);
     $conversionFunc = null;
     switch ($conversion) {
         default:
             echo "This mapping is not supported: [" . $conversion . "]\n";
             return;
             break;
         case "rot13":
             $conversionFunc = "convertStringToRot13";
             break;
         case "time2integer":
             $conversionFunc = "convertTimeToInteger";
             break;
         case "trim":
             $conversionFunc = "convertTrim";
             break;
         case "date2ts":
             $conversionFunc = "dateToTS";
             break;
     }
     foreach ($objects as $n => $object) {
         $object = eZContentObject::fetch($object["id"]);
         if ($object) {
             // copy data with conversion
             $dataMap = $object->DataMap();
             $src = $dataMap[$srcAttribute];
             $dest = $dataMap[$destAttribute];
             $dest->fromString(eep::$conversionFunc($src->toString()));
             $dest->store();
             // publish to get changes recognized, eg object title updated
             eep::republishObject($object->attribute("id"));
         }
         echo "Percent complete: " . sprintf("% 3.3f", ($n + 1.0) / $numObjects * 100.0) . "%\r";
         // clear caches
         unset($GLOBALS["eZContentObjectContentObjectCache"]);
         unset($GLOBALS["eZContentObjectDataMapCache"]);
         unset($GLOBALS["eZContentObjectVersionCache"]);
         unset($object);
     }
     echo "\n";
 }
Пример #2
0
 public static function fromString($contentObjectId, $attributeIdentifier, $value)
 {
     $contentObject = eZContentObject::fetch($contentObjectId);
     if (!is_object($contentObject)) {
         throw new Exception("This is not an object id [" . $contentObjectId . "]");
     }
     $dataMap = $contentObject->dataMap();
     if (!isset($dataMap[$attributeIdentifier])) {
         throw new Exception("This is not an attribute identifer [" . $attributeIdentifier . "] on content class '" . $contentObject->ClassIdentifier . "'");
     }
     $dataMap[$attributeIdentifier]->FromString($value);
     $dataMap[$attributeIdentifier]->store();
     eep::republishObject($contentObjectId);
 }
Пример #3
0
 public function run($argv, $additional)
 {
     $command = @$argv[2];
     $param1 = @$argv[3];
     $param2 = @$argv[4];
     if (!in_array($command, $this->availableCommands)) {
         throw new Exception("Command '" . $command . "' not recognized.");
     }
     $eepCache = eepCache::getInstance();
     switch ($command) {
         case "help":
             echo "\nAvailable commands:: " . implode(", ", $this->availableCommands) . "\n";
             echo "\n" . $this->help . "\n";
             break;
         case self::contentobject_info:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->fetchContentObjectFromId($objectId);
             break;
         case self::contentobject_datamap:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->fetchDataMapFromId($objectId);
             break;
         case self::contentobject_related:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->fetchRelated($objectId, false, $additional);
             break;
         case self::contentobject_reverserelated:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->fetchReverseRelated($objectId, $additional);
             break;
         case self::contentobject_delete:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->delete($objectId);
             break;
         case self::contentobject_contentnode:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             echo $this->convertToNodeId($objectId) . "\n";
             break;
         case self::contentobject_republish:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             eep::republishObject($objectId);
             echo "republished " . $objectId . "\n";
             break;
         case self::contentobject_clearcache:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->clearObjectCache($objectId);
             break;
         case self::contentobject_sitemapxml:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->sitemapxml($objectId, $param2, $param3, $param4);
             // objid, domain, change-frequency, priority
             break;
         case self::contentobject_deleteversions:
             $objectId = $eepCache->readFromCache(eepCache::use_key_object);
             if ($param1) {
                 $objectId = $param1;
             }
             if (!eepValidate::validateContentObjectId($objectId)) {
                 throw new Exception("This is not an object id: [" . $objectId . "]");
             }
             $this->deleteversions($objectId);
             break;
         case self::contentobject_fetchbyremoteid:
             $this->fetchbyremoteid($param1);
             break;
     }
 }
Пример #4
0
 private function location($objectId, $parentNodeId)
 {
     if (!eepValidate::validateContentObjectId($objectId)) {
         throw new Exception("This is not an object id: [" . $objectId . "]");
     }
     if (!eepValidate::validateContentNodeId($parentNodeId)) {
         throw new Exception("This is not a node id: [" . $parentNodeId . "]");
     }
     $object = eZContentObject::fetch($objectId);
     $object->addLocation($parentNodeId);
     // this is a guess; but otherwise, the new node doesn't become available
     eep::republishObject($objectId);
 }