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; }
/** * Unserialize xml structure. Creates an object from xml input. * * Transaction unsafe. If you call several transaction unsafe methods you must enclose * the calls within a db transaction; thus within db->begin and db->commit. * * @param mixed $package * @param DOMElement $domNode * @param array $options * @param int|bool $ownerID Override owner ID, null to use XML owner id (optional) * @param string $handlerType * @return array|bool|eZContentObject|null created object, false if could not create object/xml invalid */ static function unserialize( $package, $domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' ) { if ( $domNode->localName != 'object' ) { $retValue = false; return $retValue; } $initialLanguage = eZContentObject::mapLanguage( $domNode->getAttribute( 'initial_language' ), $options ); if( $initialLanguage === 'skip' ) { $retValue = true; return $retValue; } $sectionID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'section_id' ); if ( $ownerID === false ) { $ownerID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'owner_id' ); } $remoteID = $domNode->getAttribute( 'remote_id' ); $name = $domNode->getAttribute( 'name' ); $classRemoteID = $domNode->getAttribute( 'class_remote_id' ); $classIdentifier = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'class_identifier' ); $alwaysAvailable = ( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'always_available' ) == '1' ); $contentClass = eZContentClass::fetchByRemoteID( $classRemoteID ); if ( !$contentClass ) { $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier ); } if ( !$contentClass ) { $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_NO_CLASS, 'element_id' => $remoteID, 'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." ); $retValue = false; return $retValue; } /** @var DOMElement $versionListNode */ $versionListNode = $domNode->getElementsByTagName( 'version-list' )->item( 0 ); $importedLanguages = array(); foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode ) { /** @var DOMElement $versionDOMNode */ foreach ( $versionDOMNode->getElementsByTagName( 'object-translation' ) as $versionDOMNodeChild ) { /** @var DOMElement $versionDOMNodeChild */ $importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->getAttribute( 'language' ), $options ); $language = eZContentLanguage::fetchByLocale( $importedLanguage ); // Check if the language is allowed in this setup. if ( $language ) { $hasTranslation = true; } else { if ( $importedLanguage == 'skip' ) continue; // if there is no needed translation in system then add it $locale = eZLocale::instance( $importedLanguage ); $translationName = $locale->internationalLanguageName(); $translationLocale = $locale->localeCode(); if ( $locale->isValid() ) { eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() ); $hasTranslation = true; } else $hasTranslation = false; } if ( $hasTranslation ) { $importedLanguages[] = $importedLanguage; $importedLanguages = array_unique( $importedLanguages ); } } } // If object exists we return a error. // Minimum install element is an object now. $contentObject = eZContentObject::fetchByRemoteID( $remoteID ); // Figure out initial language if ( !$initialLanguage || !in_array( $initialLanguage, $importedLanguages ) ) { $initialLanguage = false; foreach ( eZContentLanguage::prioritizedLanguages() as $language ) { if ( in_array( $language->attribute( 'locale' ), $importedLanguages ) ) { $initialLanguage = $language->attribute( 'locale' ); break; } } } if ( !$contentObject ) { $firstVersion = true; $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); } else { $firstVersion = false; $description = "Object '$name' already exists."; $choosenAction = eZPackageHandler::errorChoosenAction( self::PACKAGE_ERROR_EXISTS, $options, $description, $handlerType, false ); switch( $choosenAction ) { case eZPackage::NON_INTERACTIVE: case self::PACKAGE_UPDATE: { // Keep existing contentobject. } break; case self::PACKAGE_REPLACE: { eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) ); unset( $contentObject ); $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); $firstVersion = true; } break; case self::PACKAGE_SKIP: { $retValue = true; return $retValue; } break; case self::PACKAGE_NEW: { $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) ); $contentObject->store(); unset( $contentObject ); $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); $firstVersion = true; } break; default: { $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_EXISTS, 'element_id' => $remoteID, 'description' => $description, 'actions' => array( self::PACKAGE_REPLACE => ezpI18n::tr( 'kernel/classes', 'Replace existing object' ), self::PACKAGE_SKIP => ezpI18n::tr( 'kernel/classes', 'Skip object' ), self::PACKAGE_NEW => ezpI18n::tr( 'kernel/classes', 'Keep existing and create a new one' ), self::PACKAGE_UPDATE => ezpI18n::tr( 'kernel/classes', 'Update existing object' ) ) ); $retValue = false; return $retValue; } break; } } $db = eZDB::instance(); $db->begin(); if ( $alwaysAvailable ) { // Make sure always available bit is set. $contentObject->setAttribute( 'language_mask', (int)$contentObject->attribute( 'language_mask' ) | 1 ); } $contentObject->setAttribute( 'section_id', $sectionID ); $contentObject->store(); $activeVersion = false; $lastVersion = false; $versionListActiveVersion = $versionListNode->getAttribute( 'active_version' ); $contentObject->setAttribute( 'remote_id', $remoteID ); $contentObject->setAttribute( 'contentclass_id', $contentClass->attribute( 'id' ) ); $contentObject->store(); $sectionObject = eZSection::fetch( $sectionID ); if ( $sectionObject instanceof eZSection ) { $updateWithParentSection = false; } else { $updateWithParentSection = true; } $options['language_array'] = $importedLanguages; $versionList = array(); foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode ) { unset( $nodeList ); $nodeList = array(); $contentObjectVersion = eZContentObjectVersion::unserialize( $versionDOMNode, $contentObject, $ownerID, $sectionID, $versionListActiveVersion, $firstVersion, $nodeList, $options, $package, 'ezcontentobject', $initialLanguage ); if ( !$contentObjectVersion ) { $db->commit(); $retValue = false; return $retValue; } $versionStatus = $versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'status' ); $versionList[$versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'version' )] = array( 'node_list' => $nodeList, 'status' => $versionStatus ); unset( $versionStatus ); $firstVersion = false; $lastVersion = $contentObjectVersion->attribute( 'version' ); if ( $versionDOMNode->getAttribute( 'version' ) == $versionListActiveVersion ) { $activeVersion = $contentObjectVersion->attribute( 'version' ); } eZNodeAssignment::setNewMainAssignment( $contentObject->attribute( 'id' ), $lastVersion ); eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => $lastVersion ) ); $mainNodeInfo = null; foreach ( $nodeList as $nodeInfo ) { if ( $nodeInfo['is_main'] ) { $mainNodeInfo =& $nodeInfo; break; } } if ( $mainNodeInfo ) { $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $mainNodeInfo['parent_remote_id'], false ); if ( $existingMainNode ) { eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'], $mainNodeInfo['contentobject_id'], $mainNodeInfo['contentobject_version'], $mainNodeInfo['parent_node'], $updateWithParentSection ); } } unset( $mainNodeInfo ); // Refresh $contentObject from DB. $contentObject = eZContentObject::fetch( $contentObject->attribute( 'id' ) ); } if ( !$activeVersion ) { $activeVersion = $lastVersion; } /* $contentObject->setAttribute( 'current_version', $activeVersion ); */ $contentObject->setAttribute( 'name', $name ); if ( isset( $options['use_dates_from_package'] ) && $options['use_dates_from_package'] ) { $contentObject->setAttribute( 'published', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'published' ) ) ); $contentObject->setAttribute( 'modified', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ) ); } $contentObject->store(); $versions = $contentObject->versions(); $objectName = $contentObject->name(); $objectID = $contentObject->attribute( 'id' ); foreach ( $versions as $version ) { $versionNum = $version->attribute( 'version' ); $oldVersionStatus = $version->attribute( 'status' ); $newVersionStatus = isset( $versionList[$versionNum] ) ? $versionList[$versionNum]['status'] : null; // set the correct status for non-published versions if ( isset( $newVersionStatus ) && $oldVersionStatus != $newVersionStatus && $newVersionStatus != eZContentObjectVersion::STATUS_PUBLISHED ) { $version->setAttribute( 'status', $newVersionStatus ); $version->store( array( 'status' ) ); } // when translation does not have object name set then we copy object name from the current object version $translations = $version->translations( false ); if ( !$translations ) continue; foreach ( $translations as $translation ) { if ( ! $contentObject->name( $versionNum, $translation ) ) { eZDebug::writeNotice( "Setting name '$objectName' for version ($versionNum) of the content object ($objectID) in language($translation)" ); $contentObject->setName( $objectName, $versionNum, $translation ); } } } foreach ( $versionList[$versionListActiveVersion]['node_list'] as $nodeInfo ) { unset( $parentNode ); $parentNode = eZContentObjectTreeNode::fetchNode( $contentObject->attribute( 'id' ), $nodeInfo['parent_node'] ); if ( is_object( $parentNode ) ) { $parentNode->setAttribute( 'priority', $nodeInfo['priority'] ); $parentNode->store( array( 'priority' ) ); } } $db->commit(); return $contentObject; }
function installFetchAliases( $fetchAliasListNode, &$parameters ) { if ( !$fetchAliasListNode ) { return true; } $fetchAliasINIArray = array(); foreach( $fetchAliasListNode->getElementsByTagName( 'fetch-alias' ) as $blockNode ) { if ( isset( $parameters['site_access_map'][$blockNode->getAttribute( 'site-access' )] ) ) { $newSiteAccess = $parameters['site_access_map'][$blockNode->getAttribute( 'site-access' )]; } else { $newSiteAccess = $parameters['site_access_map']['*']; } if ( !isset( $fetchAliasINIArray[$newSiteAccess] ) ) { $fetchAliasINIArray[$newSiteAccess] = eZINI::instance( 'fetchalias.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true ); } $blockArray = array(); $blockName = $blockNode->getAttribute( 'name' ); $blockArray[$blockName] = eZContentObjectPackageHandler::createArrayFromDOMNode( $blockNode->getElementsByTagName( $blockName )->item( 0 ) ); //$blockArray[$blockName] = $blockArray[$blockName][0]; if ( isset( $blockArray[$blockName]['Constant'] ) && is_array( $blockArray[$blockName]['Constant'] ) && count( $blockArray[$blockName]['Constant'] ) > 0 ) { foreach( $blockArray[$blockName]['Constant'] as $matchKey => $value ) { if ( strpos( $matchKey, 'class_' ) === 0 && is_int( $value ) ) { $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName]['Constant']['class_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentClass->attribute( 'id' ); unset( $blockArray[$blockName]['Constant']['class_remote_id'] ); } if( strpos( $matchKey, 'node_' ) === 0 && is_int( $value ) ) { $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['node_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' ); unset( $blockArray[$blockName]['Constant']['node_remote_id'] ); } if( strpos( $matchKey, 'parent_node_' ) === 0 && is_int( $value ) ) { $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['parent_node_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' ); unset( $blockArray[$blockName]['Constant']['parent_node_remote_id'] ); } if( strpos( $matchKey, 'object_' ) === 0 && is_int( $value ) ) { $contentObject = eZContentObject::fetchByRemoteID( $blockArray[$blockName]['Constant']['object_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'id' ); unset( $blockArray[$blockName]['Constant']['object_remote_id'] ); } } } $fetchAliasINIArray[$newSiteAccess]->setVariables( $blockArray ); } foreach( $fetchAliasINIArray as $siteAccess => $iniFetchAlias ) { $fetchAliasINIArray[$siteAccess]->save(); } return true; }
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(); }