static function removeRelationObject($contentObjectAttribute, $deletionItem) { if (self::isItemPublished($deletionItem)) { return; } $hostObject = $contentObjectAttribute->attribute('object'); $hostObjectID = $hostObject->attribute('id'); // Do not try removing the object if present in trash // Only objects being really orphaned (not even being in trash) should be removed by this method. // See issue #019457 if ((int) eZPersistentObject::count(eZContentObjectTrashNode::definition(), array("contentobject_id" => $hostObjectID)) > 0) { return; } $hostObjectVersions = $hostObject->versions(); $isDeletionAllowed = true; // check if the relation item to be deleted is unique in the domain of all host-object versions foreach ($hostObjectVersions as $version) { if ($isDeletionAllowed and $version->attribute('version') != $contentObjectAttribute->attribute('version')) { $relationAttribute = eZPersistentObject::fetchObjectList(eZContentObjectAttribute::definition(), null, array('version' => $version->attribute('version'), 'contentobject_id' => $hostObjectID, 'contentclassattribute_id' => $contentObjectAttribute->attribute('contentclassattribute_id'))); if (count($relationAttribute) > 0) { $relationContent = $relationAttribute[0]->content(); if (is_array($relationContent) and is_array($relationContent['relation_list'])) { foreach ($relationContent['relation_list'] as $relationItem) { if ($deletionItem['contentobject_id'] == $relationItem['contentobject_id'] && $deletionItem['contentobject_version'] == $relationItem['contentobject_version']) { $isDeletionAllowed = false; break 2; } } } } } } if ($isDeletionAllowed) { $subObjectVersion = eZContentObjectVersion::fetchVersion($deletionItem['contentobject_version'], $deletionItem['contentobject_id']); if ($subObjectVersion instanceof eZContentObjectVersion) { $subObjectVersion->removeThis(); } else { eZDebug::writeError('Cleanup of subobject-version failed. Could not fetch object from relation list.\\n' . 'Requested subobject id: ' . $deletionItem['contentobject_id'] . '\\n' . 'Requested Subobject version: ' . $deletionItem['contentobject_version'], __METHOD__); } } }