Esempio n. 1
0
File: index.php Progetto: truffo/eep
 public function run($argv, $additional)
 {
     $command = @$argv[2];
     $param1 = @$argv[3];
     $param2 = @$argv[4];
     $param3 = @$argv[5];
     $param4 = @$argv[6];
     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::attribute_delete:
             $classIdentifier = $param1;
             $attributeIdentifier = $param2;
             AttributeFunctions::deleteAttribute($classIdentifier, $attributeIdentifier);
             break;
         case self::attribute_newattributexml:
             $attr = new AttributeFunctions();
             echo $attr->newAttributeXML;
             break;
         case self::attribute_update:
             $classIdentifier = $param1;
             $xml = file_get_contents($param2);
             if (false === $xml) {
                 throw new Exception("Failed to locate parameter xml file: '" . $param2 . "'");
             }
             $dom = new DOMDocument();
             $dom->preserveWhiteSpace = false;
             $loadResult = $dom->loadXML($xml);
             if (false === $loadResult) {
                 throw new Exception("XML file '" . $param2 . "' does not contain valid XML");
             }
             $xpath = new DOMXPath($dom);
             AttributeFunctions::updateAttribute($classIdentifier, $xpath);
             break;
         case self::attribute_setfield:
             $classIdentifier = $param1;
             $attributeIdentifier = $param2;
             $fieldIdentifier = $param3;
             $fieldValue = $param4;
             AttributeFunctions::setField($classIdentifier, $attributeIdentifier, $fieldIdentifier, $fieldValue);
             break;
         case self::attribute_info:
             $classIdentifier = $param1;
             $attributeIdentifier = $param2;
             $fieldIdentifier = $param3;
             AttributeFunctions::info($classIdentifier, $attributeIdentifier, $fieldIdentifier);
             break;
         case self::attribute_migrate:
             $classIdentifier = $param1;
             $srcAttribute = $param2;
             $conversion = $param3;
             $destAttribute = $param4;
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             $this->attribute_migrate($classIdentifier, $srcAttribute, $conversion, $destAttribute);
             break;
         case self::attribute_fromstring:
             $contentObjectId = $param1;
             $attributeIdentifier = $param2;
             $newValue = $param3;
             AttributeFunctions::fromString($contentObjectId, $attributeIdentifier, $newValue);
             break;
         case self::attribute_tostring:
             $contentObjectId = $param1;
             $attributeIdentifier = $param2;
             echo AttributeFunctions::toString($contentObjectId, $attributeIdentifier) . "\n";
             break;
         case self::attribute_createalias:
             $contentObjectId = $param1;
             $attributeIdentifier = $param2;
             $aliasName = $param3;
             echo AttributeFunctions::createAlias($contentObjectId, $attributeIdentifier, $aliasName) . "\n";
             break;
         case self::attribute_contentobjectid:
             $contentObjectAttributeId = $param1;
             $version = $param2 ? $param2 : 1;
             echo AttributeFunctions::contentobjectid($contentObjectAttributeId, $version) . "\n";
             break;
     }
 }
Esempio n. 2
0
File: index.php Progetto: truffo/eep
 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::list_contentclasses:
             $this->listContentClasses();
             break;
         case self::list_attributes:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             AttributeFunctions::listAttributes($classIdentifier);
             break;
         case self::list_all_attributes:
             $this->listAllAttributes();
             break;
         case self::list_children:
             $parentNodeId = $eepCache->readFromCache(eepCache::use_key_contentnode);
             if ($param1) {
                 $parentNodeId = $param1;
             }
             $this->listChildNodes($parentNodeId, $additional);
             break;
         case self::list_siteaccesses:
             $this->listSiteAccesses();
             break;
         case self::list_allinifiles:
             $this->allinifiles();
             break;
         case self::list_subtree:
             $subtreeNodeId = $eepCache->readFromCache(eepCache::use_key_contentnode);
             if ($param1) {
                 $subtreeNodeId = $param1;
             }
             $this->listSubtree($subtreeNodeId, $additional);
             break;
         case self::list_subtreeordered:
             $subtreeNodeId = $eepCache->readFromCache(eepCache::use_key_contentnode);
             if ($param1) {
                 $subtreeNodeId = $param1;
             }
             $this->listSubtreeOrdered($subtreeNodeId, $additional);
             break;
         case self::list_extensions:
             $this->listExtensions();
             break;
     }
 }
Esempio n. 3
0
File: index.php Progetto: truffo/eep
 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::contentclass_listattributes:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             AttributeFunctions::listAttributes($classIdentifier);
             break;
         case self::contentclass_deleteclass:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             $this->deleteClass($classIdentifier);
             break;
         case self::contentclass_fetchallinstances:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             $this->fetchallinstances($classIdentifier, $additional);
             break;
         case self::contentclass_appendtogroup:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             if ($param2) {
                 $groupIdentifier = $param2;
             } else {
                 $groupIdentifier = null;
             }
             $this->appendToGroup($classIdentifier, $groupIdentifier);
             break;
         case self::contentclass_removefromgroup:
             $classIdentifier = $eepCache->readFromCache(eepCache::use_key_contentclass);
             if ($param1) {
                 $classIdentifier = $param1;
             }
             if ($param2) {
                 $groupIdentifier = $param2;
             } else {
                 $groupIdentifier = null;
             }
             $this->removeFromGroup($classIdentifier, $groupIdentifier);
             break;
             // eep createclass <Display name> <Content class group identifier>
         // eep createclass <Display name> <Content class group identifier>
         case self::contentclass_createclass:
             $displayName = $param1;
             // convert the display name to lowercase and solo underscores
             $classIdentifier = strtolower(trim($displayName));
             $classIdentifier = preg_replace("/[^a-z0-9]/", "_", $classIdentifier);
             $classIdentifier = preg_replace("/_[_]+/", "_", $classIdentifier);
             if (0 == strlen($classIdentifier)) {
                 throw new Exception("Empty content class identifier");
             }
             $classId = eZContentClass::classIDByIdentifier($classIdentifier);
             if ($classId) {
                 throw new Exception("This content class identifier is already used: '" . $classIdentifier . "'");
             }
             $groupIdentifier = $param2;
             $groupObject = eZContentClassGroup::fetchByName($groupIdentifier);
             if (!is_object($groupObject)) {
                 throw new Exception("Failed to locate the content class group '" . $groupIdentifier . "'");
             }
             $groupId = $groupObject->ID;
             $this->createClass($displayName, $classIdentifier, $groupIdentifier, $groupId);
             echo "created " . $classIdentifier . " ok\n";
             break;
             // eep contentclass setclassobjectidentifier <class identifier> <object naming string or pattern>
         // eep contentclass setclassobjectidentifier <class identifier> <object naming string or pattern>
         case self::contentclass_setclassobjectidentifier:
             $classIdentifier = $param1;
             $classId = eZContentClass::classIDByIdentifier($classIdentifier);
             $contentClass = eZContentClass::fetch($classId);
             if (!is_object($contentClass)) {
                 throw new Exception("Failed to instantiate content class. [" . $classIdentifier . "]");
             }
             $contentClass->setAttribute('contentobject_name', $param2);
             $contentClass->store();
             break;
         case self::contentclass_setiscontainer:
             $classIdentifier = $param1;
             $classId = eZContentClass::classIDByIdentifier($classIdentifier);
             $contentClass = eZContentClass::fetch($classId);
             if (!is_object($contentClass)) {
                 throw new Exception("Failed to instantiate content class. [" . $classIdentifier . "]");
             }
             $newSetting = 0;
             if (0 != $param2) {
                 $newSetting = 1;
             }
             $contentClass->setAttribute('is_container', $newSetting);
             $contentClass->store();
             break;
     }
 }
Esempio n. 4
0
 static function addAttributeToClass($contentClass, $newAttributeXPath)
 {
     $classID = $contentClass->attribute("id");
     // extracting from the xml, it's gross, but it's better than from an assoc array
     $xmlValues = array("identifier" => trim($newAttributeXPath->query("//newattribute/identifier")->item(0)->nodeValue), "display_name" => trim($newAttributeXPath->query("//newattribute/displayname")->item(0)->nodeValue), "description" => trim($newAttributeXPath->query("//newattribute/description")->item(0)->nodeValue), "language" => trim($newAttributeXPath->query("//newattribute/language")->item(0)->nodeValue), "can_translate" => trim($newAttributeXPath->query("//newattribute/can_translate")->item(0)->nodeValue), "is_required" => trim($newAttributeXPath->query("//newattribute/is_required")->item(0)->nodeValue), "is_searchable" => trim($newAttributeXPath->query("//newattribute/is_searchable")->item(0)->nodeValue), "is_information_collector" => trim($newAttributeXPath->query("//newattribute/is_information_collector")->item(0)->nodeValue), "datatypestring" => trim($newAttributeXPath->query("//newattribute/datatypestring")->item(0)->nodeValue), "content" => trim($newAttributeXPath->query("//newattribute/content")->item(0)->nodeValue));
     // create new attribute
     $attributeCreationInfo = array("identifier" => $xmlValues["identifier"], "serialized_name_list" => serialize(array($xmlValues["language"] => $xmlValues["display_name"], "always-available" => $xmlValues["language"])), "description" => $xmlValues["description"], "can_translate" => $xmlValues["can_translate"], "is_required" => $xmlValues["is_required"], "is_searchable" => $xmlValues["is_searchable"], "is_information_collector" => $xmlValues["is_information_collector"]);
     $newAttribute = eZContentClassAttribute::create($classID, $xmlValues["datatypestring"], $attributeCreationInfo);
     $dataType = $newAttribute->dataType();
     if (!$dataType) {
         throw new Exception("Unknown datatype: [ " . $datatype . " ]");
     }
     $dataType->initializeClassAttribute($newAttribute);
     $newAttribute->store();
     AttributeFunctions::updateParameters($newAttribute, $newAttributeXPath);
     $newAttribute->sync();
     $content = $xmlValues["content"];
     if ("eep-no-content" != $content) {
         $newAttribute->setContent($content);
     }
     // store attribute, update placement, etc...
     $allAttributesList = $contentClass->fetchAttributes();
     $allAttributesList[] = $newAttribute;
     // remove temporary version
     if ($newAttribute->attribute("id") !== null) {
         $newAttribute->remove();
     }
     $newAttribute->setAttribute("version", eZContentClass::VERSION_STATUS_DEFINED);
     $newAttribute->setAttribute("placement", count($allAttributesList));
     $contentClass->adjustAttributePlacements($allAttributesList);
     foreach ($allAttributesList as $attribute) {
         $attribute->storeDefined();
     }
     $classAttributeID = $newAttribute->attribute("id");
     echo "\n\nAttribute with ID " . $classAttributeID . " added\n\n";
     return $classAttributeID;
 }