/** * Unit test for eZContentObjectTreeNode::fetchMainNodeArray * * Outline: * 1) Call the function with an empty array and check that the output is null * 2) Create a few objects/nodes * 3) Call the method with these objects' IDs as a parameter * 3) Check that the returned values are eZContentObjectTreeNodes, and match * the parameter list * * @todo Also test with $asObject = false **/ public function testFindMainNodeArray() { // 1) Check that the method returns null on an empty array $this->assertNull(eZContentObjectTreeNode::findMainNodeArray(array())); // 2) Create a few objects/nodes $objectIDArray = $objectsArray = $nodesIDArray = array(); for ($i = 0; $i < 5; $i++) { $object = new ezpObject('article', 2); $object->title = "Test object #{$i} for " . __FUNCTION__; $object->publish(); $objectsIDArray[] = $object->attribute('id'); } // 3) Call the method $mainNodeArray = eZContentObjectTreeNode::findMainNodeArray($objectsIDArray); // 4) Check the result $this->assertEquals(count($objectsIDArray), count($mainNodeArray), "Return value count doesn't matche parameter count"); foreach ($mainNodeArray as $mainNode) { $mainNodeContentObjectID = $mainNode->attribute('contentobject_id'); $this->assertType('eZContentObjectTreeNode', $mainNode); $this->assertTrue($mainNode->attribute('is_main')); $this->assertTrue(in_array($mainNodeContentObjectID, $objectsIDArray), "A returned node's contentobject_id isn't part of the original parameters"); } }
ini_set('max_execution_time', 0); ini_set('memory_limit', '-1'); eZDebug::addTimingPoint('Fetch update pending list'); // Get list of paex objects marked to updatechildren $pendingList = eZPaEx::fetchUpdateChildrenPendingList(); $pendingListCount = count($pendingList); if (!$pendingListCount) { $cli->output("No pending update subtrees found"); } else { $cli->output("Found " . $pendingListCount . " ezpaex objects with pending updatechildren"); $pendingIdList = array(); foreach ($pendingList as $pendingObject) { $pendingIdList[] = $pendingObject->attribute('contentobject_id'); } // Fetch array of nodes corresponding to objects in the pendingIDList to sort them by depth $nodeArray = eZContentObjectTreeNode::findMainNodeArray($pendingIdList, false); // Make an array of objects ids with its deph based on the corresponding node $objectDepthList = array(); foreach ($nodeArray as $key => $node) { $objectDepthList[0][$key] = $node["depth"]; $objectDepthList[1][$key] = $node["contentobject_id"]; } // Sort objectDepthList by depth to apply updatechildren in the right order if (!array_multisort($objectDepthList[0], SORT_ASC, $objectDepthList[1], SORT_ASC)) { eZDebug::writeError('Error in array_multisort', 'ezmbpaex_updatechildren.php'); } else { // Generate array of paex objects to update $paexObjectArray = array(); foreach ($objectDepthList[1] as $contentobjectId) { if (isset($pendingList[$contentobjectId])) { // Generate update children data for every pending object in pendingIDList
function relatedObjects() { $return = false; if ($this->ObjectAttributeID) { $return = array(); // Fetch words $db = eZDB::instance(); $wordArray = $db->arrayQuery("SELECT * FROM ezkeyword_attribute_link\n WHERE objectattribute_id='" . $this->ObjectAttributeID . "' "); $keywordIDArray = array(); // Fetch the objects which have one of these words foreach ($wordArray as $word) { $keywordIDArray[] = $word['keyword_id']; } $keywordCondition = $db->generateSQLINStatement($keywordIDArray, 'keyword_id'); if (count($keywordIDArray) > 0) { $objectArray = $db->arrayQuery("SELECT DISTINCT ezcontentobject_attribute.contentobject_id FROM ezkeyword_attribute_link, ezcontentobject_attribute\n WHERE {$keywordCondition} AND\n ezcontentobject_attribute.id = ezkeyword_attribute_link.objectattribute_id\n AND objectattribute_id <> '" . $this->ObjectAttributeID . "' "); $objectIDArray = array(); foreach ($objectArray as $object) { $objectIDArray[] = $object['contentobject_id']; } if (count($objectIDArray) > 0) { $aNodes = eZContentObjectTreeNode::findMainNodeArray($objectIDArray); foreach ($aNodes as $key => $node) { $theObject = $node->object(); if ($theObject->canRead()) { $return[] = $node; } } } } } return $return; }