static function unserialize( $domNode, $contentObject, $ownerID, $sectionID, $activeVersion, $firstVersion, &$nodeList, &$options, $package, $handlerType = 'ezcontentobject' ) { $oldVersion = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'version' ); $status = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'status' ); $languageNodeArray = $domNode->getElementsByTagName( 'object-translation' ); $initialLanguage = false; $importedLanguages = $options['language_array']; $currentLanguages = array(); foreach( $languageNodeArray as $languageNode ) { $language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options ); if ( in_array( $language, $importedLanguages ) ) { $currentLanguages[] = $language; } } foreach ( eZContentLanguage::prioritizedLanguages() as $language ) { if ( in_array( $language->attribute( 'locale' ), $currentLanguages ) ) { $initialLanguage = $language->attribute( 'locale' ); break; } } if ( !$initialLanguage ) { $initialLanguage = $currentLanguages[0]; } if ( $firstVersion ) { $contentObjectVersion = $contentObject->version( 1 ); } else { // Create new version in specific language but with empty data. $contentObjectVersion = $contentObject->createNewVersionIn( $initialLanguage ); } $created = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'created' ) ); $modified = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ); $contentObjectVersion->setAttribute( 'created', $created ); $contentObjectVersion->setAttribute( 'modified', $modified ); $contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT ); $contentObjectVersion->store(); $db = eZDB::instance(); $db->begin(); foreach( $languageNodeArray as $languageNode ) { $language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options ); // Only import allowed languages. if ( !in_array( $language, $importedLanguages ) ) { continue; } $attributeArray = $contentObjectVersion->contentObjectAttributes( $language ); if ( count( $attributeArray ) == 0) { $hasTranslation = eZContentLanguage::fetchByLocale( $language ); if ( !$hasTranslation ) { // if there is no needed translation in system then add it $locale = eZLocale::instance( $language ); if ( $locale->isValid() ) { eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() ); $hasTranslation = true; } else $hasTranslation = false; } if ( $hasTranslation ) { // Add translated attributes for the translation $originalContentAttributes = $contentObjectVersion->contentObjectAttributes( $initialLanguage ); foreach ( $originalContentAttributes as $originalContentAttribute ) { $contentAttribute = $originalContentAttribute->translateTo( $language ); $contentAttribute->sync(); $attributeArray[] = $contentAttribute; } } // unserialize object name in current version-translation $objectName = $languageNode->getAttribute( 'object_name' ); if ( $objectName ) $contentObject->setName( $objectName, $contentObjectVersion->attribute( 'version' ), $language ); } $xpath = new DOMXPath( $domNode->ownerDocument ); $xpath->registerNamespace( 'ezobject', 'http://ez.no/object/' ); $xpath->registerNamespace( 'ezremote', 'http://ez.no/ezobject' ); foreach( $attributeArray as $attribute ) { $attributeIdentifier = $attribute->attribute( 'contentclass_attribute_identifier' ); $xpathQuery = "ezobject:attribute[@ezremote:identifier='$attributeIdentifier']"; $attributeDomNodes = $xpath->query( $xpathQuery, $languageNode ); $attributeDomNode = $attributeDomNodes->item( 0 ); if ( !$attributeDomNode ) { continue; } $attribute->unserialize( $package, $attributeDomNode ); $attribute->store(); } } $objectRelationList = $domNode->getElementsByTagName( 'object-relation-list' )->item( 0 ); if ( $objectRelationList ) { $objectRelationArray = $objectRelationList->getElementsByTagName( 'related-object-remote-id' ); foreach( $objectRelationArray as $objectRelation ) { $relatedObjectRemoteID = $objectRelation->textContent; if ( $relatedObjectRemoteID ) { $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID ); $relatedObjectID = ( $object !== null ) ? $object->attribute( 'id' ) : null; if ( $relatedObjectID ) { $contentObject->addContentObjectRelation( $relatedObjectID, $contentObjectVersion->attribute( 'version' ) ); } else { if ( !isset( $options['suspended-relations'] ) ) { $options['suspended-relations'] = array(); } $options['suspended-relations'][] = array( 'related-object-remote-id' => $relatedObjectRemoteID, 'contentobject-id' => $contentObject->attribute( 'id' ), 'contentobject-version' => $contentObjectVersion->attribute( 'version' ) ); } } } } $nodeAssignmentNodeList = $domNode->getElementsByTagName( 'node-assignment-list' )->item( 0 ); $nodeAssignmentNodeArray = $nodeAssignmentNodeList->getElementsByTagName( 'node-assignment' ); foreach( $nodeAssignmentNodeArray as $nodeAssignmentNode ) { $result = eZContentObjectTreeNode::unserialize( $nodeAssignmentNode, $contentObject, $contentObjectVersion->attribute( 'version' ), ( $oldVersion == $activeVersion ? 1 : 0 ), $nodeList, $options, $handlerType ); if ( $result === false ) { $db->commit(); $retValue = false; return $retValue; } } $contentObjectVersion->store(); $db->commit(); return $contentObjectVersion; }