/** definition of ezsrRatingObjectTreeNode, extends eZContentObjectTreeNode definition * * @return array */ static function definition() { static $def = null; if ($def === null) { $def = parent::definition(); $def['class_name'] = 'ezsrRatingObjectTreeNode'; $def['fields']['rating'] = array('name' => 'Rating', 'datatype' => 'integer', 'default' => 0, 'required' => false); $def['fields']['rating_count'] = array('name' => 'RatingCount', 'datatype' => 'integer', 'default' => 0, 'required' => false); } return $def; }
if ($dbUser !== false) { $params['user'] = $dbUser; $params['password'] = ''; } if ($dbPassword !== false) { $params['password'] = $dbPassword; } if ($dbName !== false) { $params['database'] = $dbName; } $db = eZDB::instance($dbImpl, $params, true); eZDB::setInstance($db); } $db->setIsSQLOutputEnabled($showSQL); // Get top nodes $topNodeArray = eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), null, array('parent_node_id' => 1, 'depth' => 1)); $subTreeCount = 0; foreach ($topNodeArray as $node) { $subTreeCount += $node->subTreeCount(array('Limitation' => array())); } $cli->output("Number of objects to update: {$subTreeCount}"); $i = 0; $dotMax = 70; $dotCount = 0; $limit = 50; foreach ($topNodeArray as $node) { $offset = 0; $subTree = $node->subTree(array('Offset' => $offset, 'Limit' => $limit, 'Limitation' => array())); while ($subTree != null) { foreach ($subTree as $innerNode) { $object = $innerNode->attribute('object');
static function fetchByContentObjectID($contentObjectID, $asObject = true, $contentObjectVersion = false) { $conds = array('contentobject_id' => $contentObjectID); if ($contentObjectVersion !== false) { $conds['contentobject_version'] = $contentObjectVersion; } return eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), null, $conds, null, null, $asObject); }
/** * Get total number of objects * * @return int Total object count */ protected function objectCount() { $topNodeArray = eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), null, array('parent_node_id' => 1, 'depth' => 1)); $subTreeCount = 0; foreach (array_keys($topNodeArray) as $key) { $subTreeCount += $topNodeArray[$key]->subTreeCount(array('Limitation' => array(), 'MainNodeOnly' => true)); } return $subTreeCount; }
$treeNode->store(); } $totalCount += $nonUniqueRemoteIDData['cnt'] - 1; $cli->output(''); $cli->output(''); } if ($db->databaseName() == 'oracle') { $nonUniqueRemoteIDDataList = $db->arrayQuery("SELECT node_id FROM ezcontentobject_tree WHERE remote_id IS NULL"); } else { $nonUniqueRemoteIDDataList = $db->arrayQuery("SELECT node_id FROM ezcontentobject_tree WHERE remote_id = ''"); } $nonUniqueRemoteIDDataListCount = count($nonUniqueRemoteIDDataList); $cli->output(''); $cli->output("Found {$nonUniqueRemoteIDDataListCount} tree nodes with empty remote IDs."); $cli->output(''); if ($nonUniqueRemoteIDDataListCount) { $cli->output('Fixing', false); foreach ($nonUniqueRemoteIDDataList as $nonUniqueRemoteIDData) { // fetch nodes with eZPersistentObject to avoid object cache $treeNodes = eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), null, array('node_id' => $nonUniqueRemoteIDData['node_id']), array('modified_subnode' => 'asc')); foreach ($treeNodes as $i => $treeNode) { $treeNode->setAttribute('remote_id', eZRemoteIdUtility::generate('node')); $treeNode->store(); } ++$totalCount; $cli->output('.', false); } } $cli->output(''); $cli->output("Number of tree nodes that received a new remote ID : {$totalCount}"); $script->shutdown(0);
function execute( $xmlNode ) { $xmlObjectID = $xmlNode->getAttribute( 'contentObject' ); $xmlParentNodeID = $xmlNode->getAttribute( 'addToNode' ); $setReferenceID = $xmlNode->getAttribute( 'setReference' ); $priority = $xmlNode->getAttribute( 'priority' ); $objectID = $this->getReferenceID( $xmlObjectID ); $parentNodeID = $this->getReferenceID( $xmlParentNodeID ); if ( !$objectID ) { $this->writeMessage( "\tNo object defined.", 'error' ); return false; } if ( !$parentNodeID ) { $this->writeMessage( "\tNo location defined.", 'error' ); return false; } $object = eZContentObject::fetch( $objectID ); if ( !$object ) { $this->writeMessage( "\tObject not found.", 'error' ); return false; } $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID ); if ( !$parentNode ) { $this->writeMessage( "\tparent node not found.", 'error' ); return false; } $node = $object->attribute( 'main_node' ); $nodeAssignmentList = eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false ); $assignedNodes = $object->assignedNodes(); $parentNodeIDArray = array(); $setMainNode = false; $hasMainNode = false; foreach ( $assignedNodes as $assignedNode ) { if ( $assignedNode->attribute( 'is_main' ) ) $hasMainNode = true; $append = false; foreach ( $nodeAssignmentList as $nodeAssignment ) { if ( $nodeAssignment['parent_node'] == $assignedNode->attribute( 'parent_node_id' ) ) { $append = true; break; } } if ( $append ) { $parentNodeIDArray[] = $assignedNode->attribute( 'parent_node_id' ); } } if ( !$hasMainNode ) $setMainNode = true; $mainNodeID = $parentNode->attribute( 'main_node_id' ); $objectName = $object->attribute( 'name' ); $db = eZDB::instance(); $db->begin(); $locationAdded = false; $destNode = null; if ( !in_array( $parentNodeID, $parentNodeIDArray ) ) { $parentNodeObject = $parentNode->attribute( 'object' ); $insertedNode = $object->addLocation( $parentNodeID, true ); // Now set is as published and fix main_node_id $insertedNode->setAttribute( 'contentobject_is_published', 1 ); $insertedNode->setAttribute( 'main_node_id', $node->attribute( 'main_node_id' ) ); $insertedNode->setAttribute( 'contentobject_version', $node->attribute( 'contentobject_version' ) ); // Make sure the url alias is set updated. $insertedNode->updateSubTreePath(); $insertedNode->sync(); $locationAdded = true; } if ( $locationAdded ) { $ini = eZINI::instance(); $userClassID = $ini->variable( "UserSettings", "UserClassID" ); if ( $object->attribute( 'contentclass_id' ) == $userClassID ) { eZUser::cleanupCache(); } $this->writeMessage( "\tAdded location of " . $object->attribute( 'name' ) . " to Node $parentNodeID", 'notice' ); $destNode = $insertedNode; } else { $this->writeMessage( "\tLocation of " . $object->attribute( 'name' ) . " to Node $parentNodeID already exists.", 'notice' ); $destNode = eZContentObjectTreeNode::fetchObject( eZContentObjectTreeNode::definition(), null, array( 'parent_node_id' => $parentNodeID, 'contentobject_id' => $objectID ) ); } $db->commit(); if( $destNode && $priority ) { $destNode->setAttribute( 'priority', $priority ); $destNode->store(); } if( $destNode && $setReferenceID ) { $this->addReference( array( $setReferenceID => $destNode->attribute( 'node_id' ) ) ); } eZContentCacheManager::clearContentCacheIfNeeded( $objectID ); }
/** * \static * Check whether the given object should cause access mode change. * It it should, this method does not return. */ static function checkObject($module, $view, $object) { if (!eZSSLZone::enabled()) { return; } /* If the given module/view is not in the list of 'keep mode' views, * i.e. it cannot choose access mode itself, * then do nothing. */ if (!eZSSLZone::isKeepModeView($module, $view)) { return; } $pathStringList = eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), array('path_string'), array('contentobject_id' => $object->attribute('id')), null, null, false); if (is_array($pathStringList) && count($pathStringList)) { /* The object has some assigned nodes. * If at least one of those nodes belongs to an SSL zone, * we switch to SSL. */ // "flatten" the array array_walk($pathStringList, create_function('&$a', '$a = $a[\'path_string\'];')); } else { /* The object has no assigned nodes. * Let's work with its parent nodes. * If at least one of the parent nodes belongs to an SSL zone, * we switch to SSL. */ $pathStringList = array(); $nodes = $object->parentNodes($object->attribute('current')); if (!is_array($nodes)) { eZDebug::writeError('Object ' . $object->attribute('is') . 'does not have neither assigned nor parent nodes.'); } else { foreach ($nodes as $node) { $pathStringList[] = $node->attribute('path_string'); } } } $inSSL = false; // does the object belong to an SSL zone? foreach ($pathStringList as $pathString) { if (eZSSLZone::checkNodePath($module, $view, $pathString, false)) { $inSSL = true; break; } } eZSSLZone::switchIfNeeded($inSSL); }
/** * Get total number of objects * * @return int Total object count */ protected function objectCount() { $topNodeArray = eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), null, array('parent_node_id' => 1, 'depth' => 1)); $subTreeCount = 0; $nodeTreeParams = array('Limitation' => array(), 'MainNodeOnly' => true); if (count($this->classIdentifiers) > 0) { $nodeTreeParams['ClassFilterType'] = 'include'; $nodeTreeParams['ClassFilterArray'] = $this->classIdentifiers; } //print_r($nodeTreeParams); foreach (array_keys($topNodeArray) as $key) { $subTreeCount += $topNodeArray[$key]->subTreeCount($nodeTreeParams); } return $subTreeCount; }
$params['user'] = $dbUser; $params['password'] = ''; } if ( $dbPassword !== false ) $params['password'] = $dbPassword; if ( $dbName !== false ) $params['database'] = $dbName; $db = eZDB::instance( $dbImpl, $params, true ); eZDB::setInstance( $db ); } $db->setIsSQLOutputEnabled( $showSQL ); // Get top nodes $topNodeArray = eZPersistentObject::fetchObjectList( eZContentObjectTreeNode::definition(), null, array( 'parent_node_id' => 1, 'depth' => 1 ) ); $subTreeCount = 0; foreach ( $topNodeArray as $node ) { $subTreeCount += $node->subTreeCount( array( 'Limitation' => array() ) );
} $nonUniqueRemoteIDDataListCount = count( $nonUniqueRemoteIDDataList ); $cli->output( '' ); $cli->output( "Found $nonUniqueRemoteIDDataListCount tree nodes with empty remote IDs." ); $cli->output( '' ); if ( $nonUniqueRemoteIDDataListCount ) { $cli->output( 'Fixing', false ); foreach ( $nonUniqueRemoteIDDataList as $nonUniqueRemoteIDData ) { // fetch nodes with eZPersistentObject to avoid object cache $treeNodes = eZPersistentObject::fetchObjectList( eZContentObjectTreeNode::definition(), null, array( 'node_id' => $nonUniqueRemoteIDData['node_id'] ), array( 'modified_subnode' => 'asc' ) ); foreach ( $treeNodes as $i => $treeNode ) { $treeNode->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'node' ) ); $treeNode->store(); } ++$totalCount; $cli->output( '.', false ); } } $cli->output( '' );