|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZContentObjectTreeNodeOperations class 00004 // 00005 // Created on: <12-Sep-2005 12:02:22 dl> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezcontentobjecttreenodeoperations.php 00032 */ 00033 00034 /*! 00035 \class eZContentObjectTreeNodeOperations ezcontentobjecttreenodeoperations.php 00036 \brief The class eZContentObjectTreeNodeOperations is a wrapper for node's 00037 core-operations. It takes care about interface stuff. 00038 Example: there is a 'move' core-operation that moves a node from one location 00039 to another. But, for example, before and after moving we have to clear 00040 view caches for old and new placements. Clearing of the cache is handled by 00041 this class. 00042 */ 00043 00044 class eZContentObjectTreeNodeOperations 00045 { 00046 /*! 00047 Constructor 00048 */ 00049 function eZContentObjectTreeNodeOperations() 00050 { 00051 } 00052 00053 /*! 00054 \static 00055 A wrapper for eZContentObjectTreeNode's 'move' operation. 00056 It does: 00057 - clears caches for old placement; 00058 - performs actual move( calls eZContentObjectTreeNode->move() ); 00059 - updates subtree path; 00060 - updates node's section; 00061 - updates assignment( setting new 'parent_node' ); 00062 - clears caches for new placement; 00063 00064 \param $nodeID The id of a node to move. 00065 \param $newParentNodeID The id of a new parent. 00066 \return \c true if 'move' was done successfully, otherwise \c false; 00067 */ 00068 static function move( $nodeID, $newParentNodeID ) 00069 { 00070 $result = false; 00071 00072 if ( !is_numeric( $nodeID ) || !is_numeric( $newParentNodeID ) ) 00073 return false; 00074 00075 //include_once( 'kernel/classes/ezcontentobjecttreenode.php' ); 00076 00077 $node = eZContentObjectTreeNode::fetch( $nodeID ); 00078 if ( !$node ) 00079 return false; 00080 00081 $object = $node->object(); 00082 if ( !$object ) 00083 return false; 00084 00085 $objectID = $object->attribute( 'id' ); 00086 $oldParentNode = $node->fetchParent(); 00087 $oldParentObject = $oldParentNode->object(); 00088 00089 // clear user policy cache if this is a user object 00090 if ( in_array( $object->attribute( 'contentclass_id' ), eZUser::contentClassIDs() ) ) 00091 { 00092 //include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 00093 eZUser::cleanupCache(); 00094 } 00095 00096 // clear cache for old placement. 00097 //include_once( 'kernel/classes/ezcontentcachemanager.php' ); 00098 eZContentCacheManager::clearContentCacheIfNeeded( $objectID ); 00099 00100 //include_once( "lib/ezdb/classes/ezdb.php" ); 00101 $db = eZDB::instance(); 00102 $db->begin(); 00103 00104 $node->move( $newParentNodeID ); 00105 00106 $newNode = eZContentObjectTreeNode::fetchNode( $objectID, $newParentNodeID ); 00107 00108 if ( $newNode ) 00109 { 00110 $newNode->updateSubTreePath( true, true ); 00111 if ( $newNode->attribute( 'main_node_id' ) == $newNode->attribute( 'node_id' ) ) 00112 { 00113 // If the main node is moved we need to check if the section ID must change 00114 $newParentNode = $newNode->fetchParent(); 00115 $newParentObject = $newParentNode->object(); 00116 if ( $object->attribute( 'section_id' ) != $newParentObject->attribute( 'section_id' ) ) 00117 { 00118 00119 eZContentObjectTreeNode::assignSectionToSubTree( $newNode->attribute( 'main_node_id' ), 00120 $newParentObject->attribute( 'section_id' ), 00121 $oldParentObject->attribute( 'section_id' ) ); 00122 } 00123 } 00124 00125 // modify assignment 00126 //include_once( "kernel/classes/eznodeassignment.php" ); 00127 $curVersion = $object->attribute( 'current_version' ); 00128 $nodeAssignment = eZNodeAssignment::fetch( $objectID, $curVersion, $oldParentNode->attribute( 'node_id' ) ); 00129 00130 if ( $nodeAssignment ) 00131 { 00132 $nodeAssignment->setAttribute( 'parent_node', $newParentNodeID ); 00133 $nodeAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_MOVE ); 00134 $nodeAssignment->store(); 00135 } 00136 00137 $result = true; 00138 } 00139 else 00140 { 00141 eZDebug::writeError( "Node $nodeID was moved to $newParentNodeID but fetching the new node failed" ); 00142 } 00143 00144 $db->commit(); 00145 00146 // clear cache for new placement. 00147 eZContentCacheManager::clearContentCacheIfNeeded( $objectID ); 00148 00149 return $result; 00150 } 00151 } 00152 00153 00154 ?>