コード例 #1
0
/**
 * Parses the XML for the attributes in $classAttributeIdentifiers, and fixes the relations for $object
 * @param eZContentObject $object
 * @param array $classAttributeIdentifiers
 * @return int The number of created relations
 */
function restoreXmlRelations(eZContentObject $object, array $classAttributeIdentifiers)
{
    $currentVersion = $object->currentVersion();
    $langMask = $currentVersion->attribute('language_mask');
    $languageList = eZContentLanguage::decodeLanguageMask($langMask, true);
    $languageList = $languageList['language_list'];
    // nothing to do if the object isn't translated
    if (count($languageList) < 2) {
        return 0;
    }
    $attributeArray = $object->fetchAttributesByIdentifier($classAttributeIdentifiers, $currentVersion->attribute('version'), $languageList);
    $embedRelationsCount = $object->relatedContentObjectCount(false, 0, array('AllRelations' => eZContentObject::RELATION_EMBED));
    $linkRelationsCount = $object->relatedContentObjectCount(false, 0, array('AllRelations' => eZContentObject::RELATION_LINK));
    $embeddedObjectIdArray = $linkedObjectIdArray = array();
    foreach ($attributeArray as $attribute) {
        $xmlText = eZXMLTextType::rawXMLText($attribute);
        $dom = new DOMDocument('1.0', 'utf-8');
        if (!$dom->loadXML($xmlText)) {
            continue;
        }
        // linked objects
        $linkedObjectIdArray = array_merge($linkedObjectIdArray, getRelatedObjectList($dom->getElementsByTagName('link')));
        // embedded objects
        $embeddedObjectIdArray = array_merge($embeddedObjectIdArray, getRelatedObjectList($dom->getElementsByTagName('embed')), getRelatedObjectList($dom->getElementsByTagName('embed-inline')));
    }
    $doCommit = false;
    $restoredRelations = 0;
    if (!empty($embeddedObjectIdArray)) {
        $object->appendInputRelationList($embeddedObjectIdArray, eZContentObject::RELATION_EMBED);
        $restoredRelations += count($embeddedObjectIdArray) - $embedRelationsCount;
        $doCommit = true;
    }
    if (!empty($linkedObjectIdArray)) {
        $object->appendInputRelationList($linkedObjectIdArray, eZContentObject::RELATION_LINK);
        $restoredRelations += count($linkedObjectIdArray) - $linkRelationsCount;
        $doCommit = true;
    }
    if ($doCommit) {
        $object->commitInputRelations($currentVersion->attribute('version'));
    }
    return $restoredRelations;
}
コード例 #2
0
 /**
  * Search through valid ezxmltext occurrences, and fix missing url object links if
  * specified.
  *
  * @return void
  */
 public function processData()
 {
     while ($this->processedCount < $this->xmlTextContentObjectAttributeCount()) {
         $limit = array('offset' => $this->offset, 'length' => $this->fetchLimit);
         $xmlAttributeChunk = eZContentObjectAttribute::fetchListByClassID($this->xmlClassAttributeIds(), false, $limit, true, false);
         foreach ($xmlAttributeChunk as $xmlAttr) {
             $result = true;
             // If the current entry has been logged, we don't increment the running number
             // so that the entries can be displayed together on output.
             $currentEntryLogged = false;
             $currentId = $xmlAttr->attribute('id');
             $objectId = $xmlAttr->attribute('contentobject_id');
             $version = $xmlAttr->attribute('version');
             $languageCode = $xmlAttr->attribute('language_code');
             $label = "Attribute [id:{$currentId}] - [Object-id:{$objectId}] - [Version:{$version}] - [Language:{$languageCode}]";
             $xmlText = eZXMLTextType::rawXMLText($xmlAttr);
             if (empty($xmlText)) {
                 if ($this->verboseLevel > 0) {
                     $this->outputString("Empty XML-data", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                 }
                 $result = false;
                 continue;
             }
             $dom = new DOMDocument('1.0', 'utf-8');
             $success = $dom->loadXML($xmlText);
             if (!$success) {
                 if ($this->verboseLevel > 0) {
                     $this->outputString("XML not loaded correctly for attribute", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                 }
                 $result = false;
                 continue;
             }
             $linkNodes = $dom->getElementsByTagName('link');
             $urlIdArray = array();
             foreach ($linkNodes as $link) {
                 // We are looking for external 'http://'-style links, not the internal
                 // object or node links.
                 if ($link->hasAttribute('url_id')) {
                     $urlIdArray[] = $link->getAttribute('url_id');
                 }
             }
             if (count($urlIdArray) > 0) {
                 if ($this->verboseLevel > 0) {
                     $this->outputString("Found http-link elements in xml-block", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                 }
                 $urlIdArray = array_unique($urlIdArray);
                 foreach ($urlIdArray as $url) {
                     $linkObjectLink = eZURLObjectLink::fetch($url, $currentId, $version);
                     if ($linkObjectLink === null) {
                         $result = false;
                         $this->outputString("Missing url object link: [id:{$currentId}] - [version:{$version}] - [url:{$url}]", $label, $currentEntryLogged);
                         $currentEntryLogged = true;
                     }
                     $storedUrl = eZURL::url($url);
                     if ($storedUrl === false) {
                         $result = false;
                         $this->outputString("Missing URL, the referenced url does not exist, [url_id:{$url}]", $label, $currentEntryLogged);
                         $currentEntryLogged = true;
                     }
                 }
                 if ($this->doFix and $linkObjectLink === null and $storedUrl !== false) {
                     $this->outputString("Reconstructing ezurl-object-link", $label, $currentEntryLogged);
                     $currentEntryLogged = true;
                     eZSimplifiedXMLInput::updateUrlObjectLinks($xmlAttr, $urlIdArray);
                 }
             }
             $this->script->iterate($this->cli, $result);
             $label = null;
         }
         $this->processedCount += count($xmlAttributeChunk);
         $this->offset += $this->fetchLimit;
         unset($xmlAttributeChunk);
     }
 }
コード例 #3
0
ファイル: ezxmltexttype.php プロジェクト: nlescure/ezpublish
 function title($contentObjectAttribute, $value = null)
 {
     $text = eZXMLTextType::rawXMLText($contentObjectAttribute);
     $dom = new DOMDocument('1.0', 'utf-8');
     $success = $dom->loadXML($text);
     // Get first text element of xml
     if (!$success) {
         return $text;
     }
     $root = $dom->documentElement;
     $section = $root->firstChild;
     $textDom = false;
     if ($section) {
         $textDom = $section->firstChild;
     }
     if ($textDom and $textDom->hasChildNodes) {
         $text = $textDom->firstChild->textContent;
     } elseif ($textDom) {
         $text = $textDom->textContent;
     }
     return $text;
 }