Пример #1
0
 function install($package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
 {
     $serializedNameListNode = $content->getElementsByTagName('serialized-name-list')->item(0);
     $serializedNameList = $serializedNameListNode ? $serializedNameListNode->textContent : false;
     $classNameList = new eZContentClassNameList($serializedNameList);
     if ($classNameList->isEmpty()) {
         $classNameList->initFromString($content->getElementsByTagName('name')->item(0)->textContent);
         // for backward compatibility( <= 3.8 )
     }
     $classNameList->validate();
     $serializedDescriptionListNode = $content->getElementsByTagName('serialized-description-list')->item(0);
     $serializedDescriptionList = $serializedDescriptionListNode ? $serializedDescriptionListNode->textContent : false;
     $classDescriptionList = new eZSerializedObjectNameList($serializedDescriptionList);
     $classIdentifier = $content->getElementsByTagName('identifier')->item(0)->textContent;
     $classRemoteID = $content->getElementsByTagName('remote-id')->item(0)->textContent;
     $classObjectNamePattern = $content->getElementsByTagName('object-name-pattern')->item(0)->textContent;
     $classURLAliasPattern = is_object($content->getElementsByTagName('url-alias-pattern')->item(0)) ? $content->getElementsByTagName('url-alias-pattern')->item(0)->textContent : null;
     $classIsContainer = $content->getAttribute('is-container');
     if ($classIsContainer !== false) {
         $classIsContainer = $classIsContainer == 'true' ? 1 : 0;
     }
     $classRemoteNode = $content->getElementsByTagName('remote')->item(0);
     $classID = $classRemoteNode->getElementsByTagName('id')->item(0)->textContent;
     $classGroupsNode = $classRemoteNode->getElementsByTagName('groups')->item(0);
     $classCreated = $classRemoteNode->getElementsByTagName('created')->item(0)->textContent;
     $classModified = $classRemoteNode->getElementsByTagName('modified')->item(0)->textContent;
     $classCreatorNode = $classRemoteNode->getElementsByTagName('creator')->item(0);
     $classModifierNode = $classRemoteNode->getElementsByTagName('modifier')->item(0);
     $classAttributesNode = $content->getElementsByTagName('attributes')->item(0);
     $dateTime = time();
     $classCreated = $dateTime;
     $classModified = $dateTime;
     $userID = false;
     if (isset($installParameters['user_id'])) {
         $userID = $installParameters['user_id'];
     }
     $class = eZContentClass::fetchByRemoteID($classRemoteID);
     if ($class) {
         $className = $class->name();
         $description = ezpI18n::tr('kernel/package', "Class '%classname' already exists.", false, array('%classname' => $className));
         $choosenAction = $this->errorChoosenAction(self::ERROR_EXISTS, $installParameters, $description, $this->HandlerType);
         switch ($choosenAction) {
             case eZPackage::NON_INTERACTIVE:
             case self::ACTION_REPLACE:
                 if (eZContentClassOperations::remove($class->attribute('id')) == false) {
                     eZDebug::writeWarning("Unable to remove class '{$className}'.");
                     return true;
                 }
                 eZDebug::writeNotice("Class '{$className}' will be replaced.", 'eZContentClassPackageHandler');
                 break;
             case self::ACTION_SKIP:
                 return true;
             case self::ACTION_NEW:
                 $class->setAttribute('remote_id', eZRemoteIdUtility::generate('class'));
                 $class->store();
                 $classNameList->appendGroupName(" (imported)");
                 break;
             default:
                 $installParameters['error'] = array('error_code' => self::ERROR_EXISTS, 'element_id' => $classRemoteID, 'description' => $description, 'actions' => array());
                 if ($class->isRemovable()) {
                     $errorMsg = ezpI18n::tr('kernel/package', "Replace existing class");
                     $objectsCount = eZContentObject::fetchSameClassListCount($class->attribute('id'));
                     if ($objectsCount) {
                         $errorMsg .= ' ' . ezpI18n::tr('kernel/package', "(Warning! {$objectsCount} content object(s) and their sub-items will be removed)");
                     }
                     $installParameters['error']['actions'][self::ACTION_REPLACE] = $errorMsg;
                 }
                 $installParameters['error']['actions'][self::ACTION_SKIP] = ezpI18n::tr('kernel/package', 'Skip installing this class');
                 $installParameters['error']['actions'][self::ACTION_NEW] = ezpI18n::tr('kernel/package', 'Keep existing and create a new one');
                 return false;
         }
     }
     unset($class);
     // Try to create a unique class identifier
     $currentClassIdentifier = $classIdentifier;
     $unique = false;
     while (!$unique) {
         $classList = eZContentClass::fetchByIdentifier($currentClassIdentifier);
         if ($classList) {
             // "increment" class identifier
             if (preg_match('/^(.*)_(\\d+)$/', $currentClassIdentifier, $matches)) {
                 $currentClassIdentifier = $matches[1] . '_' . ($matches[2] + 1);
             } else {
                 $currentClassIdentifier = $currentClassIdentifier . '_1';
             }
         } else {
             $unique = true;
         }
         unset($classList);
     }
     $classIdentifier = $currentClassIdentifier;
     $values = array('version' => 0, 'serialized_name_list' => $classNameList->serializeNames(), 'serialized_description_list' => $classDescriptionList->serializeNames(), 'create_lang_if_not_exist' => true, 'identifier' => $classIdentifier, 'remote_id' => $classRemoteID, 'contentobject_name' => $classObjectNamePattern, 'url_alias_name' => $classURLAliasPattern, 'is_container' => $classIsContainer, 'created' => $classCreated, 'modified' => $classModified);
     if ($content->hasAttribute('sort-field')) {
         $values['sort_field'] = eZContentObjectTreeNode::sortFieldID($content->getAttribute('sort-field'));
     } else {
         eZDebug::writeNotice('The sort field was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__);
     }
     if ($content->hasAttribute('sort-order')) {
         $values['sort_order'] = $content->getAttribute('sort-order');
     } else {
         eZDebug::writeNotice('The sort order was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__);
     }
     if ($content->hasAttribute('always-available')) {
         $values['always_available'] = $content->getAttribute('always-available') === 'true' ? 1 : 0;
     } else {
         eZDebug::writeNotice('The default object availability was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__);
     }
     // create class
     $class = eZContentClass::create($userID, $values);
     $class->store();
     $classID = $class->attribute('id');
     if (!isset($installData['classid_list'])) {
         $installData['classid_list'] = array();
     }
     if (!isset($installData['classid_map'])) {
         $installData['classid_map'] = array();
     }
     $installData['classid_list'][] = $class->attribute('id');
     $installData['classid_map'][$classID] = $class->attribute('id');
     // create class attributes
     $classAttributeList = $classAttributesNode->getElementsByTagName('attribute');
     foreach ($classAttributeList as $classAttributeNode) {
         $isNotSupported = strtolower($classAttributeNode->getAttribute('unsupported')) == 'true';
         if ($isNotSupported) {
             continue;
         }
         $attributeDatatype = $classAttributeNode->getAttribute('datatype');
         $attributeIsRequired = strtolower($classAttributeNode->getAttribute('required')) == 'true';
         $attributeIsSearchable = strtolower($classAttributeNode->getAttribute('searchable')) == 'true';
         $attributeIsInformationCollector = strtolower($classAttributeNode->getAttribute('information-collector')) == 'true';
         $attributeIsTranslatable = strtolower($classAttributeNode->getAttribute('translatable')) == 'true';
         $attributeSerializedNameListNode = $classAttributeNode->getElementsByTagName('serialized-name-list')->item(0);
         $attributeSerializedNameListContent = $attributeSerializedNameListNode ? $attributeSerializedNameListNode->textContent : false;
         $attributeSerializedNameList = new eZSerializedObjectNameList($attributeSerializedNameListContent);
         if ($attributeSerializedNameList->isEmpty()) {
             $attributeSerializedNameList->initFromString($classAttributeNode->getElementsByTagName('name')->item(0)->textContent);
         }
         // for backward compatibility( <= 3.8 )
         $attributeSerializedNameList->validate();
         $attributeSerializedDescriptionListNode = $classAttributeNode->getElementsByTagName('serialized-description-list')->item(0);
         $attributeSerializedDescriptionListContent = $attributeSerializedDescriptionListNode ? $attributeSerializedDescriptionListNode->textContent : false;
         $attributeSerializedDescriptionList = new eZSerializedObjectNameList($attributeSerializedDescriptionListContent);
         $attributeCategoryNode = $classAttributeNode->getElementsByTagName('category')->item(0);
         $attributeCategory = $attributeCategoryNode ? $attributeCategoryNode->textContent : '';
         $attributeSerializedDataTextNode = $classAttributeNode->getElementsByTagName('serialized-description-text')->item(0);
         $attributeSerializedDataTextContent = $attributeSerializedDataTextNode ? $attributeSerializedDataTextNode->textContent : false;
         $attributeSerializedDataText = new eZSerializedObjectNameList($attributeSerializedDataTextContent);
         $attributeIdentifier = $classAttributeNode->getElementsByTagName('identifier')->item(0)->textContent;
         $attributePlacement = $classAttributeNode->getElementsByTagName('placement')->item(0)->textContent;
         $attributeDatatypeParameterNode = $classAttributeNode->getElementsByTagName('datatype-parameters')->item(0);
         $classAttribute = $class->fetchAttributeByIdentifier($attributeIdentifier);
         if (!$classAttribute) {
             $classAttribute = eZContentClassAttribute::create($class->attribute('id'), $attributeDatatype, array('version' => 0, 'identifier' => $attributeIdentifier, 'serialized_name_list' => $attributeSerializedNameList->serializeNames(), 'serialized_description_list' => $attributeSerializedDescriptionList->serializeNames(), 'category' => $attributeCategory, 'serialized_data_text' => $attributeSerializedDataText->serializeNames(), 'is_required' => $attributeIsRequired, 'is_searchable' => $attributeIsSearchable, 'is_information_collector' => $attributeIsInformationCollector, 'can_translate' => $attributeIsTranslatable, 'placement' => $attributePlacement));
             $dataType = $classAttribute->dataType();
             $classAttribute->store();
             $dataType->unserializeContentClassAttribute($classAttribute, $classAttributeNode, $attributeDatatypeParameterNode);
             $classAttribute->sync();
         }
     }
     // add class to a class group
     $classGroupsList = $classGroupsNode->getElementsByTagName('group');
     foreach ($classGroupsList as $classGroupNode) {
         $classGroupName = $classGroupNode->getAttribute('name');
         $classGroup = eZContentClassGroup::fetchByName($classGroupName);
         if (!$classGroup) {
             $classGroup = eZContentClassGroup::create();
             $classGroup->setAttribute('name', $classGroupName);
             $classGroup->store();
         }
         $classGroup->appendClass($class);
     }
     return true;
 }
Пример #2
0
 static function nameFromSerializedString($serializedNameList)
 {
     return eZContentClassNameList::nameFromSerializedString($serializedNameList);
 }
Пример #3
0
                                   ( SELECT DISTINCT ezinfocollection.contentobject_id FROM ezinfocollection )
                             ORDER BY ezcontentobject.name ASC', array('limit' => (int) $limit, 'offset' => (int) $offset));
$infoCollectorObjectsQuery = $db->arrayQuery('SELECT COUNT( DISTINCT ezinfocollection.contentobject_id ) as count
                                               FROM ezinfocollection,
                                                    ezcontentobject,
                                                    ezcontentobject_tree
                                               WHERE
                                                    ezinfocollection.contentobject_id=ezcontentobject.id
                                                    AND ezinfocollection.contentobject_id=ezcontentobject_tree.contentobject_id');
$numberOfInfoCollectorObjects = 0;
if ($infoCollectorObjectsQuery) {
    $numberOfInfoCollectorObjects = $infoCollectorObjectsQuery[0]['count'];
}
foreach (array_keys($objects) as $i) {
    $firstCollections = eZInformationCollection::fetchCollectionsList((int) $objects[$i]['contentobject_id'], false, false, array('limit' => 1, 'offset' => 0), array('created', true), false);
    $objects[$i]['first_collection'] = $firstCollections[0]['created'];
    $lastCollections = eZInformationCollection::fetchCollectionsList((int) $objects[$i]['contentobject_id'], false, false, array('limit' => 1, 'offset' => 0), array('created', false), false);
    $objects[$i]['last_collection'] = $lastCollections[0]['created'];
    $objects[$i]['class_name'] = eZContentClassNameList::nameFromSerializedString($objects[$i]['serialized_name_list']);
    $objects[$i]['collections'] = eZInformationCollection::fetchCollectionCountForObject($objects[$i]['contentobject_id']);
}
$viewParameters = array('offset' => $offset);
$tpl = eZTemplate::factory();
$tpl->setVariable('module', $module);
$tpl->setVariable('limit', $limit);
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('object_array', $objects);
$tpl->setVariable('object_count', $numberOfInfoCollectorObjects);
$Result = array();
$Result['content'] = $tpl->fetch('design:infocollector/overview.tpl');
$Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('kernel/infocollector', 'Collected information')));
Пример #4
0
 function execute($xml)
 {
     $classList = $xml->getElementsByTagName('ContentClass');
     $refArray = array();
     $availableLanguageList = eZContentLanguage::fetchLocaleList();
     foreach ($classList as $class) {
         $this->adjustAttributesPlacement = false;
         $user = eZUser::currentUser();
         $userID = $user->attribute('contentobject_id');
         $classIdentifier = $class->getAttribute('identifier');
         $classRemoteID = $class->getAttribute('remoteID');
         $classObjectNamePattern = $class->getAttribute('objectNamePattern');
         $classExistAction = $class->getAttribute('classExistAction');
         $referenceID = $class->getAttribute('referenceID');
         $this->writeMessage("\tClass '{$classIdentifier}' will be updated.", 'notice');
         $classURLAliasPattern = $class->getAttribute('urlAliasPattern') ? $class->getAttribute('urlAliasPattern') : null;
         $classIsContainer = $class->getAttribute('isContainer');
         if ($classIsContainer !== false) {
             $classIsContainer = $classIsContainer == 'true' ? 1 : 0;
         }
         $classGroupsNode = $class->getElementsByTagName('Groups')->item(0);
         $classAttributesNode = $class->getElementsByTagName('Attributes')->item(0);
         $nameList = array();
         $nameListObject = $class->getElementsByTagName('Names')->item(0);
         if ($nameListObject && $nameListObject->parentNode === $class && $nameListObject->hasAttributes()) {
             $attributes = $nameListObject->attributes;
             if (!is_null($attributes)) {
                 foreach ($attributes as $index => $attr) {
                     if (in_array($attr->name, $availableLanguageList)) {
                         $nameList[$attr->name] = $attr->value;
                     }
                 }
             }
         }
         if (!empty($nameList)) {
             $classNameList = new eZContentClassNameList(serialize($nameList));
             $classNameList->validate();
         } else {
             $classNameList = null;
         }
         $dateTime = time();
         $classCreated = $dateTime;
         $classModified = $dateTime;
         $class = eZContentClass::fetchByRemoteID($classRemoteID);
         if (!$class) {
             $class = eZContentClass::fetchByIdentifier($classIdentifier);
         }
         if ($class) {
             $className = $class->name();
             switch ($classExistAction) {
                 case 'replace':
                     $this->writeMessage("\t\tClass '{$classIdentifier}' will be replaced.", 'notice');
                     foreach ($nameList as $lang => $name) {
                         if (in_array($lang, $availableLanguageList)) {
                             $class->setName($name, $lang);
                         }
                     }
                     $class->setAttribute('contentobject_name', $classObjectNamePattern);
                     $class->setAttribute('identifier', $classIdentifier);
                     $class->setAttribute('is_container', $classIsContainer);
                     $class->setAttribute('url_alias_name', $classURLAliasPattern);
                     $class->store();
                     $class->removeAttributes();
                     break;
                 case 'new':
                     unset($class);
                     $class = false;
                     break;
                     break;
                 case 'extend':
                     $this->writeMessage("\t\tClass '{$classIdentifier}' will be extended.", 'notice');
                     foreach ($nameList as $lang => $name) {
                         if (in_array($lang, $availableLanguageList)) {
                             $class->setName($name, $lang);
                         }
                     }
                     $class->setAttribute('contentobject_name', $classObjectNamePattern);
                     $class->setAttribute('identifier', $classIdentifier);
                     $class->setAttribute('is_container', $classIsContainer);
                     $class->setAttribute('url_alias_name', $classURLAliasPattern);
                     $class->store();
                     break;
                 case 'skip':
                 default:
                     continue;
                     break;
             }
         }
         if (!$class) {
             // Try to create a unique class identifier
             $currentClassIdentifier = $classIdentifier;
             $unique = false;
             while (!$unique) {
                 $classList = eZContentClass::fetchByIdentifier($currentClassIdentifier);
                 if ($classList) {
                     // "increment" class identifier
                     if (preg_match('/^(.*)_(\\d+)$/', $currentClassIdentifier, $matches)) {
                         $currentClassIdentifier = $matches[1] . '_' . ($matches[2] + 1);
                     } else {
                         $currentClassIdentifier = $currentClassIdentifier . '_1';
                     }
                 } else {
                     $unique = true;
                 }
                 unset($classList);
             }
             $classIdentifier = $currentClassIdentifier;
             // create class
             $class = eZContentClass::create($userID, array('version' => 1, 'serialized_name_list' => $classNameList->serializeNames(), 'create_lang_if_not_exist' => true, 'identifier' => $classIdentifier, 'remote_id' => $classRemoteID, 'contentobject_name' => $classObjectNamePattern, 'url_alias_name' => $classURLAliasPattern, 'is_container' => $classIsContainer, 'created' => $classCreated, 'modified' => $classModified));
             $class->store();
             $attributes = $class->fetchAttributes();
             $class->storeDefined($attributes);
             $classID = $class->attribute('id');
             $this->writeMessage("\t\tClass '{$classIdentifier}' will be newly created.", 'notice');
         }
         // create class attributes
         $classAttributeList = $classAttributesNode->getElementsByTagName('Attribute');
         $classDataMap = $class->attribute('data_map');
         $updateAttributeList = array();
         if ($classDataMap == NULL) {
             $classDataMap = array();
         }
         foreach ($classAttributeList as $classAttributeNode) {
             $attributeDatatype = $classAttributeNode->getAttribute('datatype');
             $attributeIsRequired = strtolower($classAttributeNode->getAttribute('required')) == 'true';
             $attributeIsSearchable = strtolower($classAttributeNode->getAttribute('searchable')) == 'true';
             $attributeIsInformationCollector = strtolower($classAttributeNode->getAttribute('informationCollector')) == 'true';
             $attributeIsTranslatable = strtolower($classAttributeNode->getAttribute('translatable')) == 'false' ? 0 : 1;
             $attributeIdentifier = $classAttributeNode->getAttribute('identifier');
             $attributePlacement = $classAttributeNode->getAttribute('placement');
             $attributeNameListObject = $classAttributeNode->getElementsByTagName('Names')->item(0);
             if ($attributeNameListObject->hasAttributes()) {
                 if ($attributeNameListObject->hasAttributes()) {
                     $attributes = $attributeNameListObject->attributes;
                     if (!is_null($attributes)) {
                         $attributeNameList = array();
                         foreach ($attributes as $index => $attr) {
                             $attributeNameList[$attr->name] = $attr->value;
                         }
                     }
                 }
             }
             $classAttributeNameList = new eZContentClassNameList(serialize($attributeNameList));
             $classAttributeNameList->validate();
             $attributeDatatypeParameterNode = $classAttributeNode->getElementsByTagName('DatatypeParameters')->item(0);
             $classAttribute = $class->fetchAttributeByIdentifier($attributeIdentifier);
             $params = array();
             $params['identifier'] = $attributeIdentifier;
             $params['name_list'] = $classAttributeNameList;
             $params['data_type_string'] = $attributeDatatype;
             $params['default_value'] = '';
             $params['can_translate'] = $attributeIsTranslatable;
             $params['is_required'] = $attributeIsRequired;
             $params['is_searchable'] = $attributeIsSearchable;
             $params['content'] = '';
             $params['placement'] = $attributePlacement;
             $params['is_information_collector'] = $attributeIsInformationCollector;
             $params['datatype-parameter'] = $this->parseAndReplaceNodeStringReferences($attributeDatatypeParameterNode);
             $params['attribute-node'] = $classAttributeNode;
             if (!array_key_exists($attributeIdentifier, $classDataMap)) {
                 $this->writeMessage("\t\tClass '{$classIdentifier}' will get new Attribute '{$attributeIdentifier}'.", 'notice');
                 $updateAttributeList[] = $this->addClassAttribute($class, $params);
             } else {
                 $this->writeMessage("\t\tClass '{$classIdentifier}' will get updated Attribute '{$attributeIdentifier}'.", 'notice');
                 $this->updateClassAttribute($class, $params);
             }
         }
         if ($this->adjustAttributesPlacement) {
             //once every attribute has been processed, we may reset placement
             $this->writeMessage("\t\tAdjusting attributes placement.", 'notice');
             $this->adjustClassAttributesPlacement($class);
         }
         if (count($updateAttributeList)) {
             $this->writeMessage("\t\tUpdating content object attributes.", 'notice');
             $classID = $class->attribute('id');
             // update object attributes
             $objects = eZContentObject::fetchSameClassList($classID, false);
             foreach ($objects as $objectID) {
                 $object = eZContentObject::fetch($objectID['id']);
                 if ($object) {
                     $contentobjectID = $object->attribute('id');
                     $objectVersions = $object->versions();
                     foreach ($objectVersions as $objectVersion) {
                         $translations = $objectVersion->translations(false);
                         $version = $objectVersion->attribute('version');
                         foreach ($translations as $translation) {
                             foreach ($updateAttributeList as $classAttributeID) {
                                 $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version);
                                 $objectAttribute->setAttribute('language_code', $translation);
                                 $objectAttribute->initialize();
                                 $objectAttribute->store();
                                 $objectAttribute->postInitialize();
                             }
                         }
                     }
                 }
                 unset($object);
             }
         }
         if ($classNameList) {
             $classNameList->store($class);
         }
         // add class to a class group
         $classGroupsList = $classGroupsNode->getElementsByTagName('Group');
         foreach ($classGroupsList as $classGroupNode) {
             $classGroupName = $classGroupNode->getAttribute('name');
             $classGroup = eZContentClassGroup::fetchByName($classGroupName);
             if (!$classGroup) {
                 $classGroup = eZContentClassGroup::create();
                 $classGroup->setAttribute('name', $classGroupName);
                 $classGroup->store();
             }
             $classGroup->appendClass($class);
         }
         if ($referenceID) {
             $refArray[$referenceID] = $class->attribute('id');
         }
     }
     $this->addReference($refArray);
     eZContentCacheManager::clearAllContentCache();
 }
 public function sync($force = false, $removeExtras = false)
 {
     $modified = eZContentClass::fetch($this->id, true, eZContentClass::VERSION_STATUS_MODIFIED);
     if (is_object($modified)) {
         throw new Exception("Classe bloccata in modifica");
     }
     $this->compare();
     if ($this->getData()->hasError && !$force) {
         throw new Exception("La classe contiene campi che ne impediscono la sincronizzazione automatica");
     }
     $temporary = eZContentClass::fetch($this->id, true, eZContentClass::VERSION_STATUS_TEMPORARY);
     if (!is_object($temporary) or $temporary->attribute('id') == null) {
         $temporary = eZContentClass::fetch($this->id, true, eZContentClass::VERSION_STATUS_DEFINED);
         if ($temporary === null) {
             throw new Exception("La classe non esiste");
         }
         /** @var eZContentClassClassGroup[] $classGroups */
         $classGroups = eZContentClassClassGroup::fetchGroupList($this->id, eZContentClass::VERSION_STATUS_DEFINED);
         foreach ($classGroups as $classGroup) {
             $groupID = $classGroup->attribute('group_id');
             $groupName = $classGroup->attribute('group_name');
             $ingroup = eZContentClassClassGroup::create($this->id, eZContentClass::VERSION_STATUS_TEMPORARY, $groupID, $groupName);
             $ingroup->store();
         }
         if (count($classGroups) > 0) {
             $mainGroupID = $classGroups[0]->attribute('group_id');
             $mainGroupName = $classGroups[0]->attribute('group_name');
         }
     } else {
         $user = eZUser::currentUser();
         $contentIni = eZINI::instance('content.ini');
         $timeOut = $contentIni->variable('ClassSettings', 'DraftTimeout');
         /** @var eZContentClassClassGroup[] $groupList */
         $groupList = $temporary->fetchGroupList();
         if (count($groupList) > 0) {
             $mainGroupID = $groupList[0]->attribute('group_id');
             $mainGroupName = $groupList[0]->attribute('group_name');
         }
         if ($temporary->attribute('modifier_id') != $user->attribute('contentobject_id') && $temporary->attribute('modified') + $timeOut > time()) {
             throw new Exception("Modifica alla classe non permessa");
         }
     }
     /** @var eZContentClassAttribute[] $localeAttributes */
     $localeAttributes = array();
     foreach ($this->currentClass->fetchAttributes() as $attribute) {
         /** @var eZContentClassAttribute $attribute */
         $attribute->setAttribute('version', eZContentClass::VERSION_STATUS_TEMPORARY);
         $localeAttributes[$attribute->attribute('identifier')] = $attribute;
     }
     $this->currentClass->setAttribute('version', eZContentClass::VERSION_STATUS_TEMPORARY);
     $remote = $this->getRemote();
     if ($remote === null) {
         throw new Exception("Classe remota non trovata");
     }
     if ($force && $this->getData()->hasError) {
         foreach ($this->getData()->errors as $identifier => $value) {
             if (!$localeAttributes[$identifier] instanceof eZContentClassAttribute) {
                 throw new Exception('Errore forzando la sincronizzazione');
             }
             foreach ($remote->DataMap[0] as $originalAttribute) {
                 if ($originalAttribute->Identifier == $identifier) {
                     ezpEvent::getInstance()->notify('classtools/switch_class_attribute', array($localeAttributes[$identifier], $originalAttribute));
                     if ($value == 'data_type_string') {
                         $localeAttributes[$identifier]->setAttribute('data_type_string', $originalAttribute->DataTypeString);
                         $localeAttributes[$identifier]->store();
                         $this->changeContentObjectAttributeDataTypeString($localeAttributes[$identifier], $originalAttribute->DataTypeString);
                         unset($this->notifications[self::ERROR][$originalAttribute->Identifier]);
                     } else {
                         $this->data->missingAttributes[] = $originalAttribute;
                         $this->currentClass->removeAttributes(array($localeAttributes[$identifier]));
                         unset($localeAttributes[$identifier]);
                     }
                     break;
                 }
             }
         }
     }
     $attributes = array();
     foreach ($this->properties as $identifier => $remoteProperty) {
         if ($remote->{$remoteProperty} != $this->currentClass->attribute($identifier)) {
             $this->currentClass->setAttribute($identifier, $remote->{$remoteProperty});
             if ($identifier == 'serialized_name_list') {
                 $nameList = new eZContentClassNameList();
                 $nameList->initFromSerializedList($remote->{$remoteProperty});
                 $this->currentClass->NameList = $nameList;
             } elseif ($identifier == 'serialized_description_list') {
                 $descriptionList = new eZSerializedObjectNameList();
                 $descriptionList->initFromSerializedList($remote->{$remoteProperty});
                 $this->currentClass->DescriptionList = $descriptionList;
             }
         }
     }
     foreach ($this->getData()->missingAttributes as $originalAttribute) {
         $add = $this->addAttribute($originalAttribute);
         if ($add) {
             $attributes[] = $add;
         }
     }
     foreach ($remote->DataMap[0] as $originalAttribute) {
         if (isset($localeAttributes[$originalAttribute->Identifier])) {
             $modified = $this->syncAttribute($originalAttribute, $localeAttributes[$originalAttribute->Identifier]);
             if ($modified) {
                 $attributes[] = $modified;
             }
         }
     }
     if (!$removeExtras) {
         foreach ($this->extraContentObjectAttributes as $extra) {
             $extra->setAttribute('placement', count($attributes) + 1);
             $attributes[] = $extra;
         }
     }
     $this->currentClass->store($attributes);
     $db = eZDB::instance();
     $db->begin();
     $unorderedParameters = array('Language' => $this->EditLanguage);
     if (eZContentObject::fetchSameClassListCount($this->id) > 0) {
         eZExtension::getHandlerClass(new ezpExtensionOptions(array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'ContentClassEditHandler')))->store($this->currentClass, $attributes, $unorderedParameters);
     } else {
         $unorderedParameters['ScheduledScriptID'] = 0;
         $this->currentClass->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED);
     }
     $db->commit();
     $this->syncGroups();
 }
Пример #6
0
 public static function parseClassesDefinition(DOMDocument $dom, array $options = null)
 {
     $classes = array();
     $classNodes = $dom->getElementsByTagName('content-class');
     foreach ($classNodes as $classNode) {
         $serializedNameListNode = $classNode->getElementsByTagName('serialized-name-list')->item(0);
         $serializedNameList = $serializedNameListNode ? $serializedNameListNode->textContent : false;
         $classNameList = new eZContentClassNameList($serializedNameList);
         $classNameList->validate();
         $class = array('name' => $classNameList->name(), 'identifier' => $classNode->getElementsByTagName('identifier')->item(0)->textContent, 'object_name_patter' => is_object($classNode->getElementsByTagName('object-name-pattern')->item(0)) ? $classNode->getElementsByTagName('object-name-pattern')->item(0)->textContent : null, 'is_container' => $classNode->getAttribute('is-container') == 'true', 'attributes' => array());
         $classAttributesNode = $classNode->getElementsByTagName('attributes')->item(0);
         $classAttributeList = $classAttributesNode->getElementsByTagName('attribute');
         foreach ($classAttributeList as $classAttributeNode) {
             $attributeSerializedNameListNode = $classAttributeNode->getElementsByTagName('serialized-name-list')->item(0);
             $attributeSerializedNameListContent = $attributeSerializedNameListNode ? $attributeSerializedNameListNode->textContent : false;
             $attributeSerializedNameList = new eZSerializedObjectNameList($attributeSerializedNameListContent);
             $attributeSerializedNameList->validate();
             $datatypeParameters = array();
             $datatypeParameterNodes = $classAttributeNode->getElementsByTagName('datatype-parameters')->item(0)->childNodes;
             if ($datatypeParameterNodes->length > 0) {
                 // set default value for default-placement parameter for object relation list datatype
                 if ($classAttributeNode->getAttribute('datatype') == 'ezobjectrelationlist') {
                     $datatypeParameters['default-placement'] = '';
                 }
                 foreach ($datatypeParameterNodes as $datatypeParameterNode) {
                     if ($datatypeParameterNode instanceof DOMText) {
                         $value = trim($datatypeParameterNode->textContent);
                         if (strlen($value) > 0) {
                             $datatypeParameters[] = $datatypeParameterNode->textContent;
                         }
                     } else {
                         if ($datatypeParameterNode->tagName == 'class-constraints') {
                             $tmp = array();
                             $classIdentifiers = $classAttributeNode->getElementsByTagName('class-constraint');
                             foreach ($classIdentifiers as $classIdentifier) {
                                 if ($classIdentifier->hasAttribute('class-identifier')) {
                                     $tmp[] = $classIdentifier->getAttribute('class-identifier');
                                 }
                             }
                             asort($tmp);
                             $value = implode(',', $tmp);
                         } elseif ($datatypeParameterNode->tagName == 'options') {
                             $tmp = array();
                             $optionValues = $classAttributeNode->getElementsByTagName('option');
                             foreach ($optionValues as $option) {
                                 if ($option->hasAttribute('id')) {
                                     $tmp[] = $option->getAttribute('id') . ':' . $option->getAttribute('name');
                                 }
                             }
                             asort($tmp);
                             $value = implode(',', $tmp);
                         } else {
                             $value = trim($datatypeParameterNode->textContent);
                         }
                         $datatypeParameters[$datatypeParameterNode->tagName] = $value;
                     }
                 }
             }
             $attribute = array('name' => $attributeSerializedNameList->name(), 'identifier' => $classAttributeNode->getElementsByTagName('identifier')->item(0)->textContent, 'placement' => $classAttributeNode->getElementsByTagName('placement')->item(0)->textContent, 'datatype' => $classAttributeNode->getAttribute('datatype'), 'required' => strtolower($classAttributeNode->getAttribute('required')) == 'true', 'searchable' => strtolower($classAttributeNode->getAttribute('searchable')) == 'true', 'information_collector' => strtolower($classAttributeNode->getAttribute('information-collector')) == 'true', 'translatable' => strtolower($classAttributeNode->getAttribute('translatable')) == 'true', 'datatype_parameters' => $datatypeParameters);
             if (is_array($options) && count($options) > 0) {
                 foreach ($attribute as $key => $value) {
                     if ($key == 'identifier') {
                         continue;
                     }
                     if (isset($options[$key]) === false) {
                         unset($attribute[$key]);
                     }
                 }
             }
             $class['attributes'][$attribute['identifier']] = $attribute;
         }
         ksort($class['attributes']);
         $classes[$class['identifier']] = $class;
     }
     return $classes;
 }