function execute($process, $event) { // get object being published $parameters = $process->attribute('parameter_list'); $objectID = $parameters['object_id']; eZDebug::writeDebug('Update object state for object: ' . $objectID); $object = eZContentObject::fetch($objectID); $state_before = $event->attribute('state_before'); $state_after = $event->attribute('state_after'); if ($object == null) { eZDebug::writeError('Update object state failed for inexisting object: ' . $objectID, __METHOD__); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } if ($state_before == null || $state_after == null) { eZDebug::writeError('Update object state failed: badly configured states', __METHOD__); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } $currentStateIDArray = $object->attribute('state_id_array'); if (in_array($state_before->attribute('id'), $currentStateIDArray)) { $canAssignStateIDList = $object->attribute('allowed_assign_state_id_list'); if (!in_array($state_after->attribute('id'), $canAssignStateIDList)) { eZDebug::writeWarning("Not enough rights to assign state to object {$objectID}: " . $state_after->attribute('id'), __METHOD__); } else { eZDebug::writeDebug('Changing object state from ' . $state_before->attribute('name') . ' to ' . $state_after->attribute('name'), __METHOD__); if (eZOperationHandler::operationIsAvailable('content_updateobjectstate')) { $operationResult = eZOperationHandler::execute('content', 'updateobjectstate', array('object_id' => $objectID, 'state_id_list' => array($state_after->attribute('id')))); } else { eZContentOperationCollection::updateObjectState($objectID, array($state_after->attribute('id'))); } } } return eZWorkflowType::STATUS_ACCEPTED; }
public static function message($publishHandler, eZContentObject $object, $message, $messageLength = null, $options) { $url = false; if (isset($options['include_url']) && (bool) $options['include_url'] === true) { $url = $object->attribute('main_node')->attribute('url_alias'); eZURI::transformURI($url, true, 'full'); if (isset($options['shorten_url']) && (bool) $options['shorten_url'] === true) { $urlReturned = $publishHandler->shorten($url, $options['shorten_handler']); if (is_string($urlReturned)) { $url = $urlReturned; } } if ($messageLength != null) { $messageLength = $messageLength - strlen($url) - 1; } } if (class_exists('Normalizer')) { $message = Normalizer::normalize($message, Normalizer::FORM_C); } if ($messageLength != null) { $message = mb_substr($message, 0, $messageLength); } if ($url) { $message .= ' ' . $url; } return $message; }
/** * Create a copy of an object. * * The basis for this method is taken from kernel/content/copy.php * * @todo Merge this method into kernel wrapper's object class. * * @param eZContentObject $object * @param int $newParentNodeID * @return eZContentObject */ public static function copyObject($object, $newParentNodeID) { $newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID); $db = eZDB::instance(); $db->begin(); $newObject = $object->copy(true); // We should reset section that will be updated in updateSectionID(). // If sectionID is 0 than the object has been newly created $newObject->setAttribute('section_id', 0); $newObject->store(); $curVersion = $newObject->attribute('current_version'); $curVersionObject = $newObject->attribute('current'); $newObjAssignments = $curVersionObject->attribute('node_assignments'); unset($curVersionObject); // remove old node assignments foreach ($newObjAssignments as $assignment) { $assignment->purge(); } // and create a new one $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1)); $nodeAssignment->store(); // publish the newly created object eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion)); // Update "is_invisible" attribute for the newly created node. $newNode = $newObject->attribute('main_node'); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); $db->commit(); return $newObject; }
/** * Removes object $contentObject from the search database. * * @deprecated Since 5.0, use removeObjectById() * @param eZContentObject $contentObject the content object to remove * @param bool $commit Whether to commit after removing the object * @return bool True if the operation succeed. */ static function removeObject($contentObject, $commit = null) { $searchEngine = eZSearch::getEngine(); if ($searchEngine instanceof ezpSearchEngine) { return $searchEngine->removeObjectById($contentObject->attribute("id"), $commit); } return false; }
function unLock(eZContentObject $object) { $filterConds = array('action' => 'creating_translation', 'param' => $object->attribute('id')); $rows = eZPersistentObject::fetchObjectList(eZPendingActions::definition(), null, $filterConds); foreach ($rows as $row) { $row->remove(); } }
static function fetchByObject(eZContentObject $object) { $attributes = $object->fetchDataMap(); foreach ($attributes as $attribute) { if ($attribute->DataTypeString == 'xrowmetadata' and $attribute->hasContent()) { return $attribute->content(); } } return false; }
/** * Initializes a level one ezpContentFieldSet from an eZContentObject * @param eZContentObject $contentObject * @return ezpContentFieldSet */ public static function fromContentObject(eZContentObject $contentObject) { $set = new ezpContentFieldSet(); $languages = $contentObject->availableLanguages(); foreach ($languages as $language) { $set->childrenFieldSets[$language] = ezpContentFieldSet::fromDataMap($contentObject->fetchDataMap(false, $language)); } // this sequence is REALLY ugly reset($languages); $set->setActiveLanguage(current($languages)); return $set; }
/** * get the contentobject of one comment * @return eZContentObject */ public function contentObject() { if (isset($this->ContentObjectID) and $this->ContentObjectID) { return eZContentObject::fetch($this->ContentObjectID); } return null; }
/** * Returns part of the data for the attribute * * @param string $dataMember * * @return string */ public function getDataMember($dataMember) { if ($dataMember === 'related_images') { $images = array(); $relations = $this->ContentObjectAttribute->attribute('content'); foreach ($relations['relation_list'] as $relation) { $object = eZContentObject::fetch($relation['contentobject_id']); if ($object instanceof eZContentObject) { $dataMap = $object->attribute('data_map'); foreach ($dataMap as $attribute) { /** @var eZContentObjectAttribute $attribute */ if ($attribute->attribute('data_type_string') !== eZImageType::DATA_TYPE_STRING) { continue; } if ($attribute->hasContent()) { $imageAliasHandler = $attribute->attribute('content'); $imageAlias = $imageAliasHandler->imageAlias('opengraph'); if ($imageAlias['is_valid'] == 1) { $images[] = eZSys::serverURL() . '/' . $imageAlias['full_path']; } } } } } if (empty($images)) { $images[] = eZSys::serverURL() . eZURLOperator::eZImage(null, 'opengraph_default_image.png', ''); } return $images; } return $this->getData(); }
function runOperation(&$node) { $object = $node->attribute('object'); $object_id = $object->attribute('id'); $objectLocales = $object->attribute('available_languages'); // If the alternative locale does not exist for object, create it if (!in_array($this->altLocale, $objectLocales)) { // The only translation is in locate to be removed - create a version in another locale first. echo "Copying the single translation in " . $this->remLocale . " to " . $this->altLocale . " so former could be removed.\n"; $newVersion = $object->createNewVersionIn($this->altLocale, $this->remLocale, false, true, eZContentObjectVersion::STATUS_DRAFT); $publishResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object_id, 'version' => $newVersion->attribute('version'))); eZContentObject::clearCache(); $object = eZContentObject::fetch($object_id); } // Change objects main language to alternative language, if its current main language is to be removed. if ($object->attribute('initial_language_code') == $this->remLocale) { eZContentObject::clearCache(); $object = eZContentObject::fetch($object_id); echo "Switching initial language to {$this->altLocale} so that " . $this->remLocale . " could be removed.\n"; $updateResult = eZContentOperationCollection::updateInitialLanguage($object_id, $this->altLangID); $object->store(); eZContentObject::clearCache(); $object = eZContentObject::fetch($object_id); } // Now it should be safe to remove translation. return $object->removeTranslation($this->remLangID); }
function execute($process, $event) { $parameters = $process->attribute('parameter_list'); $object = eZContentObject::fetch($parameters['object_id']); $versionID = $parameters['version']; if (!$object) { return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } $version = $object->version($versionID); if (!$version) { return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } $akismetObject = new eZContentObjectAkismet(); $comment = $akismetObject->akismetInformationExtractor($version); if ($comment) { $akismet = new eZAkismet($comment); if ($akismet) { $isSpam = $akismet->isCommentSpam(); eZDebug::writeDebug($comment); eZDebug::writeDebug("this is spam: " . $isSpam); } else { return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } if (!$isSpam) { $response = $akismet->submitHam(); return eZWorkflowType::STATUS_ACCEPTED; } return eZWorkflowType::STATUS_REJECTED; } }
function feZMetaData_ContentActionHandler( &$module, &$http, &$objectID ) { // Action when user clicks on the Add Button if( $http->hasPostVariable( 'AddMetaDataButton' ) ) { $link = 'fezmetadata/edit/0/(contentObjectID)/'.$objectID; $link .= '/(metaDataName)/'.$_POST['metaDataName']; $link .= '/(language)/'.$_POST['language']; eZURI::transformURI( $link ); $http->redirect( $link ); } // Action when user clicks on the Remove Button if( $http->hasPostVariable( 'RemoveMetaDataButton' ) and $http->hasPostVariable( 'MetaDataIDSelection' ) ) { $metaDataSelection = $http->postVariable( 'MetaDataIDSelection' ); foreach( $metaDataSelection as $metaData ) { $metaDataObject = feZMetaData::fetch( $metaData ); $metaDataObject->remove(); } eZContentCacheManager::clearContentCache( $objectID ); $ContentObject = eZContentObject::fetch( $objectID ); $ContentNodeID = $ContentObject->mainNodeID(); return $module->redirect( 'content', 'view', array( 'full', $ContentNodeID ) ); } }
static function remove($objectID, $removeSubtrees = true) { eZContentCacheManager::clearContentCacheIfNeeded($objectID); $object = eZContentObject::fetch($objectID); if (!is_object($object)) { return false; } // TODO: Is content cache cleared for all objects in subtree ?? if ($removeSubtrees) { $assignedNodes = $object->attribute('assigned_nodes'); if (count($assignedNodes) == 0) { $object->purge(); eZContentObject::expireAllViewCache(); return true; } $assignedNodeIDArray = array(); foreach ($assignedNodes as $node) { $assignedNodeIDArray[] = $node->attribute('node_id'); } eZContentObjectTreeNode::removeSubtrees($assignedNodeIDArray, false); } else { $object->purge(); } return true; }
/** * Makes the following function attributes field attribtues, for testing purposes : * - class_name * - class_identifier * - main_node_id * - main_parent_node_id * * @return the overridden definition array */ public static function definition() { $definitionOverride = array( 'fields' => array( 'class_name' => array( 'name' => "LocalClassName", 'datatype' => 'mixed' ), 'class_identifier' => array( 'name' => "LocalClassIdentifier", 'datatype' => 'mixed' ), 'main_node_id' => array( 'name' => "MainNodeId", 'datatype' => 'mixed' ), 'main_parent_node_id' => array( 'name' => "MainParentNodeId", 'datatype' => 'mixed' ) ) ); $definition = array_merge_recursive( parent::definition(), $definitionOverride ); $definition['class_name'] = __CLASS__; unset( $definition['function_attributes']['class_name'] ); unset( $definition['function_attributes']['class_identifier'] ); unset( $definition['function_attributes']['main_node_id'] ); unset( $definition['function_attributes']['main_parent_node_id'] ); return $definition; }
function akismet_ContentActionHandler($module, $http, $objectID) { $object = eZContentObject::fetch($objectID); $version = $object->attribute('current'); if ($http->hasPostVariable('AkismetSubmitSpam')) { $user = eZUser::currentUser(); $accessResult = $user->hasAccessTo('akismet', 'submit'); if ($accessResult['accessWord'] === 'yes') { $mainNode = $object->attribute('main_node'); $module->redirectTo($mainNode->attribute('url_alias')); $akismetObject = new eZContentObjectAkismet(); $comment = $akismetObject->akismetInformationExtractor($version); if ($comment) { $akismet = new eZAkismet($comment); if ($akismet) { $feedback = $akismet->submitSpam(); $response[] = $feedback[1]; } else { $response[] = ezi18n('extension/contactivity/akismet/submit', "An error has occured, unable to submit spam to Akismet."); } } else { $response[] = ezi18n('extension/contactivity/akismet/submit', "An error has occured, unable to submit spam to Akismet."); } } $mainNode = $object->attribute('main_node'); $module->redirectTo($mainNode->attribute('url_alias')); return true; } }
/** * Regression test for issue {@see #19174 http://issues.ez.no/19174} */ public function testIssue19174() { $bkpLanguages = eZContentLanguage::prioritizedLanguageCodes(); // add a secondary language $locale = eZLocale::instance('fre-FR'); $translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName()); // create related objects $relatedObjectsIds = array($this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation()); $xmlTextEn = "<embed href=\"ezobject://{$relatedObjectsIds[0]}\" /><link href=\"ezobject://{$relatedObjectsIds[1]}\">link</link>"; $xmlTextFr = "<embed href=\"ezobject://{$relatedObjectsIds[2]}\" /><link href=\"ezobject://{$relatedObjectsIds[3]}\">link</link>"; // Create an article in eng-GB, and embed related object one in the intro $article = new ezpObject('article', 2, 14, 1, 'eng-GB'); $article->title = __METHOD__ . ' eng-GB'; $article->intro = $xmlTextEn; $articleId = $article->publish(); // Workaround as setting folder->name directly doesn't produce the expected result $article->addTranslation('fre-FR', array('title' => __METHOD__ . ' fre-FR', 'intro' => $xmlTextFr)); $relatedObjects = eZContentObject::fetch($articleId)->relatedObjects(false, false, 0, false, array('AllRelations' => eZContentObject::RELATION_LINK | eZContentObject::RELATION_EMBED)); self::assertEquals(4, count($relatedObjects)); $expectedRelations = array_flip($relatedObjectsIds); foreach ($relatedObjects as $relatedObject) { if (isset($expectedRelations[$relatedObject->ID])) { unset($expectedRelations[$relatedObject->ID]); } } self::assertEquals(0, count($expectedRelations)); $article->remove(); $translation->removeThis(); eZContentLanguage::setPrioritizedLanguages($bkpLanguages); }
private function solrMetaDataExists( $contentObjectID=0, $attributeIdentifier='', $subattr='' ) { try { $contentObject = eZContentObject::fetch( $contentObjectID ); $dataMap = $contentObject->dataMap(); if ( array_key_exists( $attributeIdentifier, $dataMap ) ) { $contentObjectAttribute = $dataMap[$attributeIdentifier]; $eZType = eZDataType::create( solrMetaDataType::DATA_TYPE_STRING ); $value = $eZType->getValue( $contentObjectAttribute->ID, $subattr ); return ( ! empty( $value ) ); } else { eZDebug::writeError( 'Object '.$contentObjectID.' has no attribute '.$attributeIdentifier, 'solrMetaDataExists Error' ); } return false; } catch ( Exception $e ) { eZDebug::writeError( $e, 'solrMetaDataExists Exception' ); return false; } }
public function execute($process, $event) { $params = $process->attribute('parameter_list'); $object_id = $params['object_id']; $object = eZContentObject::fetch($object_id); if (!is_object($object)) { eZDebug::writeError("Unable to fetch object: '{$object_id}'", __METHOD__); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } // current parent node(s) $parentNodeIds = $object->attribute('parent_nodes'); $checkedObjs = array(); foreach ($parentNodeIds as $parentNodeId) { //eZDebug::writeDebug( "Checking parent node: " . $parentNodeId, __METHOD__ ); $parentNode = eZContentObjectTreeNode::fetch($parentNodeId); $parentObj = $parentNode->attribute('object'); if (!in_array($parentObj->attribute('id'), $checkedObjs)) { //eZDebug::writeDebug( "Checking all nodes of parent obj: " . $parentObj->attribute( 'id' ), __METHOD__ ); foreach ($parentObj->attribute('assigned_nodes') as $node) { if (!in_array($node->attribute('node_id'), $parentNodeIds)) { //eZDebug::writeDebug( "Found a node which is not parent of current obj: " . $node->attribute( 'node_id' ), __METHOD__ ); // the current obj has no node which is children of the given node of one of its parent objects $operationResult = eZOperationHandler::execute('content', 'addlocation', array('node_id' => $object->attribute('main_node_id'), 'object_id' => $object->attribute('id'), 'select_node_id_array' => array($node->attribute('node_id'))), null, true); if ($operationResult == null || $operationResult['status'] != true) { eZDebug::writeError("Unable to add new location to object: " . $object->attribute('id'), __METHOD__); } } else { //eZDebug::writeDebug( "Found a node which is already parent of current obj: " . $node->attribute( 'node_id' ), __METHOD__ ); } } } $checkedObjs[] = $parentObj->attribute('id'); } return eZWorkflowType::STATUS_ACCEPTED; }
static function remove($classID) { $contentClass = eZContentClass::fetch($classID); if ($contentClass == null or !$contentClass->isRemovable()) { return false; } // Remove all objects $contentObjects = eZContentObject::fetchSameClassList($classID); foreach ($contentObjects as $contentObject) { eZContentObjectOperations::remove($contentObject->attribute('id')); } if (count($contentObjects) == 0) { eZContentObject::expireAllViewCache(); } eZContentClassClassGroup::removeClassMembers($classID, 0); eZContentClassClassGroup::removeClassMembers($classID, 1); // Fetch real version and remove it $contentClass->remove(true); // Fetch temp version and remove it $tempDeleteClass = eZContentClass::fetch($classID, true, 1); if ($tempDeleteClass != null) { $tempDeleteClass->remove(true, 1); } return true; }
function modifier() { if ($this->Modifier === null) { $this->Modifier = eZContentObject::fetch($this->ModifierID); } return $this->Modifier; }
/** * @param eZContentObjectTreeNode $node * @return string */ public function getNodeUrl(&$node = null) { $token = $this->getToken(); $dataMap = $node->dataMap(); $mediaContentAttribute = $dataMap['media_content']; $mediaContentAttributeContent = $mediaContentAttribute->content(); $linkObjectID = $mediaContentAttributeContent['relation_list'][0]['contentobject_id']; $linkObject = eZContentObject::fetch( $linkObjectID ); $linkDatamap = $linkObject->dataMap(); $url = $linkDatamap['url']->content(); $queryStringPosition = strpos($url, '?'); $queryString = substr($url, $queryStringPosition + 1); $url = substr($url, 0, $queryStringPosition); $queryStringParts = array(); parse_str($queryString, $queryStringParts); $queryStringParts[self::SESSION_ID_FIELD] = $token; $queryString = http_build_query($queryStringParts); $url .= '?' . $queryString; return $url; }
/** * The modify method gets the current content object AND the list of * Solr Docs (for each available language version). * * * @param eZContentObject $contentObect * @param array $docList */ public function modify(eZContentObject $contentObject, &$docList) { $contentNode = $contentObject->attribute('main_node'); $parentNode = $contentNode->attribute('parent'); if ($parentNode instanceof eZContentObjectTreeNode) { $parentObject = $parentNode->attribute('object'); $parentVersion = $parentObject->currentVersion(); if ($parentVersion === false) { return; } $availableLanguages = $parentVersion->translationList(false, false); foreach ($availableLanguages as $languageCode) { $docList[$languageCode]->addField('extra_parent_node_name_t', $parentObject->name(false, $languageCode)); } } }
public function testUpdateAndPublishObject() { // create content object first $object = new ezpObject("folder", 2); $object->title = __FUNCTION__ . '::' . __LINE__ . '::' . time(); $object->publish(); $contentObjectID = $object->attribute('id'); if ($object instanceof eZContentObject) { $now = date('Y/m/d H:i:s', time()); $sectionID = 3; $remoteID = md5($now); $attributeList = array('name' => 'name ' . $now, 'short_name' => 'short_name ' . $now, 'short_description' => 'short_description' . $now, 'description' => 'description' . $now, 'show_children' => false); $params = array(); $params['attributes'] = $attributeList; $params['remote_id'] = $remoteID; $params['section_id'] = $sectionID; $result = eZContentFunctions::updateAndPublishObject($object, $params); $this->assertTrue($result); $object = eZContentObject::fetch($contentObjectID); $this->assertEquals($object->attribute('section_id'), $sectionID); $this->assertEquals($object->attribute('remote_id'), $remoteID); $dataMap = $object->dataMap(); $this->assertEquals($attributeList['name'], $dataMap['name']->content()); $this->assertEquals($attributeList['short_name'], $dataMap['short_name']->content()); $this->assertEquals($attributeList['short_description'], $dataMap['short_description']->content()); $this->assertEquals($attributeList['description'], $dataMap['description']->content()); $this->assertEquals($attributeList['show_children'], (bool) $dataMap['show_children']->content()); } }
static function process() { $limit = 100; $offset = 0; $availableHandlers = eZNotificationEventFilter::availableHandlers(); do { $eventList = eZNotificationEvent::fetchUnhandledList(array('offset' => $offset, 'length' => $limit)); foreach ($eventList as $event) { $db = eZDB::instance(); $db->begin(); foreach ($availableHandlers as $handler) { if ($handler === false) { eZDebug::writeError("Notification handler does not exist: {$handlerKey}", __METHOD__); } else { $handler->handle($event); } } $itemCountLeft = eZNotificationCollectionItem::fetchCountForEvent($event->attribute('id')); if ($itemCountLeft == 0) { $event->remove(); } else { $event->setAttribute('status', eZNotificationEvent::STATUS_HANDLED); $event->store(); } $db->commit(); } eZContentObject::clearCache(); } while (count($eventList) == $limit); // If less than limit, we're on the last iteration eZNotificationCollection::removeEmpty(); }
/** * @group issue18073 * @link http://issues.ez.no/18073 */ public function testUnauthorizedContentByObject() { $this->setExpectedException('ezpContentAccessDeniedException'); // Let's take content node #5 / object #4 (users) as unauthorized content for anonymous user $unauthorizedObjectID = 4; $content = ezpContent::fromObject(eZContentObject::fetch($unauthorizedObjectID)); }
private function updateContentObject(eZContentObject $eZContentObject) { $mainNodeID = $eZContentObject->mainNodeID(); $parentNodeID = eZContentObjectTreeNode::getParentNodeId($mainNodeID); $classIdentifier = $eZContentObject->ClassIdentifier; $remoteID = $eZContentObject->RemoteID; if (!eZContentClass::fetchByIdentifier($classIdentifier)) { throw new Exception("La classe" . $classIdentifier . "non esiste in questa installazione"); } $params = array(); $params['class_identifier'] = $classIdentifier; $params['remote_id'] = $remoteID; $params['parent_node_id'] = $parentNodeID; $params['attributes'] = $this->getAttributesStringArray($eZContentObject); $result = eZContentFunctions::updateAndPublishObject($eZContentObject, $params); return $result; }
/** * Adds a "pending clear cache" action if ViewCaching is disabled. * This method should be called at publish time. * Cache should then be cleared by a cronjob * @return void */ public function addPendingClearCacheIfNeeded() { if (eZINI::instance()->variable('ContentSettings', 'ViewCaching') === 'disabled') { $rowPending = array('action' => self::ACTION_CLEAR_CACHE, 'created' => time(), 'param' => $this->contentObject->attribute('id')); $pendingItem = new eZPendingActions($rowPending); $pendingItem->store(); } }
public function execute($process, $event) { $processParameters = $process->attribute('parameter_list'); $object = eZContentObject::fetch($processParameters['object_id']); $targetClassIdentifier = $object->contentClass()->attribute('identifier'); $iniGroups = eZINI::instance('ngindexer.ini')->groups(); $targets = array(); foreach ($iniGroups as $iniGroupName => $iniGroup) { $iniGroupNameArray = explode('/', $iniGroupName); if (is_array($iniGroupNameArray) && count($iniGroupNameArray) == 3) { $class = eZContentClass::fetchByIdentifier($iniGroupNameArray[0]); if ($class instanceof eZContentClass) { $classAttribute = $class->fetchAttributeByIdentifier($iniGroupNameArray[1]); if ($classAttribute instanceof eZContentClassAttribute) { $indexTarget = isset($iniGroup['IndexTarget']) ? trim($iniGroup['IndexTarget']) : ''; $referencedClassIdentifiers = isset($iniGroup['ClassIdentifiers']) && is_array($iniGroup['ClassIdentifiers']) ? $iniGroup['ClassIdentifiers'] : null; if ($referencedClassIdentifiers != null && (empty($referencedClassIdentifiers) || in_array($targetClassIdentifier, $referencedClassIdentifiers))) { switch ($indexTarget) { case 'parent': case 'parent_line': $children = eZContentObjectTreeNode::subTreeByNodeID(array('ClassFilterType' => 'include', 'ClassFilterArray' => array($iniGroupNameArray[0]), 'Depth' => $indexTarget == 'parent' ? 1 : false), $object->mainNode()->attribute('node_id')); if (is_array($children)) { $targets = array_merge($targets, $children); } break; case 'children': $parentNode = $object->mainNode()->fetchParent(); if ($parentNode->classIdentifier() == $iniGroupNameArray[0]) { $targets[] = $parentNode; } break; case 'subtree': $path = $object->mainNode()->fetchPath(); foreach ($path as $pathNode) { if ($pathNode->classIdentifier() == $iniGroupNameArray[0]) { $targets[] = $parentNode; } } break; default: continue; } } } } } } $filteredTargets = array(); foreach ($targets as $target) { $objectID = $target->attribute('contentobject_id'); $version = $target->object()->attribute('current_version'); if (!isset($filteredTargets[$objectID])) { $filteredTargets[$objectID] = $version; eZContentOperationCollection::registerSearchObject($objectID, $version); } } return eZWorkflowType::STATUS_ACCEPTED; }
public static function execute($exclusiveParentID = 1) { $db = eZDB::instance(); $cli = eZCLI::instance(); //1. delete the assignments from eznode_assignment table // delete the assignments which don't have relevant entry in ezconentobject_tree // select the data that doesn't exist in either eznode_assignment or ezcontentobject_tree $deletedAssignmentList = $db->arrayQuery("SELECT * FROM eznode_assignment WHERE id NOT IN " . "(SELECT assign.id FROM eznode_assignment assign, ezcontentobject_tree tree WHERE " . "assign.contentobject_id = tree.contentobject_id AND assign.parent_node = tree.parent_node_id)"); $deletedCount = 0; foreach ($deletedAssignmentList as $deletedAssignment) { // select the content object which is published. //If the object of the assignment is in trash or draft, it's not the one to be deleted $tempAssignID = $deletedAssignment["id"]; $content = eZContentObject::fetch($deletedAssignment["contentobject_id"], false); if ($content && $deletedAssignment['parent_node'] != $exclusiveParentID) { if ($content["status"] == eZContentObject::STATUS_PUBLISHED) { // iterate the data to be deleted, delete them $cli->notice('Node assignment [ id: ' . $deletedAssignment['id'] . ' ] for contentobject [ id: ' . $deletedAssignment['contentobject_id'] . ' ] is not consistent with entries in contentobject_tree' . ' table thus will be removed.'); $sql = "DELETE FROM eznode_assignment WHERE id = " . $tempAssignID; $result = $db->query($sql); if ($result === false) { $cli->notice('Node assignment [ id: ' . $deletedAssignment['id'] . ' ] ' . 'could not be removed. Please restore your database from backup and try again.'); return; } $deletedCount++; } } } //2. Delete the duplicated entries which have same contentobject_id, contentobject_version and is_main // The process of deleting duplicated entries deletes the old entries, keeps the latest entry in the // duplicated entry list. $tempDeleteList = array(); $duplicatedContentList = $db->arrayQuery("SELECT contentobject_id, contentobject_version, is_main, parent_node\n FROM eznode_assignment\n GROUP BY contentobject_id, contentobject_version, is_main, parent_node\n HAVING COUNT(*) > 1"); foreach ($duplicatedContentList as $duplicatedContent) { $assignmentList = $db->arrayQuery("SELECT * FROM eznode_assignment" . " WHERE contentobject_id = " . $duplicatedContent['contentobject_id'] . " AND contentobject_version = " . $duplicatedContent["contentobject_version"] . " AND parent_node =" . $duplicatedContent["parent_node"] . " ORDER BY id DESC"); $assignmentListCount = count($assignmentList); //Find the duplicated entries( array index start from 1 ) and delete them. Leave the one entry( array index is 0 ) for ($i = 1; $i < $assignmentListCount; $i++) { if ($assignmentList[$i]["parent_node"] != $exclusiveParentID) { $tempAssignID = $assignmentList[$i]["id"]; $cli->notice('Node assignment [ id: ' . $tempAssignID . ' ] for contentobject [ id: ' . $assignmentList[$i]["contentobject_id"] . '] is duplicated thus will be removed.'); $sql = "DELETE FROM eznode_assignment WHERE id = " . $tempAssignID; $result = $db->query($sql); if ($result === false) { $cli->notice('Node assignment [ id: ' . $tempAssignID . ' ] ' . 'could not be removed. Please restore your database from backup and try again.'); return; } $deletedCount++; } } } if ($deletedCount != 0) { $cli->output($deletedCount . ' node assignments have been deleted.'); } else { $cli->output('None of available node assignments has been deleted.'); } }
/** * Test for issue #16322: eZTextFileUser makes user names with newline (with patch) */ public function testLoginCorrect() { $userClass = eZUserLoginHandler::instance('textfile'); $user = $userClass->loginUser($this->username, $this->password); // the username and password were accepted $this->assertEquals(true, $user instanceof eZUser); // check that the name doesn't contain new line at the end $userObject = eZContentObject::fetch($user->ContentObjectID); $this->assertEquals($this->firstname . ' ' . $this->lastname, $userObject->Name); }