| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <27-Jul-2006 15:00:00 vd> 5 // 6 // SOFTWARE NAME: eZ publish 7 // SOFTWARE RELEASE: 3.9.0 8 // BUILD VERSION: 17785 9 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 10 // SOFTWARE LICENSE: GNU General Public License v2.0 11 // NOTICE: > 12 // This program is free software; you can redistribute it and/or 13 // modify it under the terms of version 2.0 of the GNU General 14 // Public License as published by the Free Software Foundation. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of version 2.0 of the GNU General 22 // Public License along with this program; if not, write to the Free 23 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 // MA 02110-1301, USA. 25 // 26 // 27 28 // Subtree Remove Script 29 // file bin/php/ezsubtreeremove.php 30 31 // script initializing 32 include_once ( 'lib/ezutils/classes/ezcli.php' ); 33 include_once ( 'kernel/classes/ezscript.php' ); 34 include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" ); 35 include_once ( "kernel/classes/ezcontentobjecttreenode.php" ); 36 37 $cli =& eZCLI::instance(); 38 $script =& eZScript::instance( array( 'description' => ( "\n" . 39 "This script will make a remove of a content object subtrees.\n" ), 40 'use-session' => false, 41 'use-modules' => true, 42 'use-extensions' => true, 43 'user' => true ) ); 44 $script->startup(); 45 46 $scriptOptions = $script->getOptions( "[nodes-id:][ignore-trash]", 47 "", 48 array( 'nodes-id' => "Subtree nodes ID (separated by comma ',').", 49 'ignore-trash' => "Ignore trash ('move to trash' by default)." 50 ), 51 false, 52 array( 'user' => true ) 53 ); 54 $script->initialize(); 55 $srcNodesID = $scriptOptions[ 'nodes-id' ] ? trim( $scriptOptions[ 'nodes-id' ] ) : false; 56 $moveToTrash = $scriptOptions[ 'ignore-trash' ] ? false : true; 57 $deleteIDArray = $srcNodesID ? explode( ',', $srcNodesID ) : false; 58 59 if ( !$deleteIDArray ) 60 { 61 $cli->error( "Subtree remove Error!\nCannot get subtree nodes. Please check nodes-id argument and try again." ); 62 $script->showHelp(); 63 $script->shutdown( 1 ); 64 } 65 66 $ini =& eZINI::instance(); 67 // Get user's ID who can remove subtrees. (Admin by default with userID = 14) 68 $userCreatorID = $ini->variable( "UserSettings", "UserCreatorID" ); 69 $user = eZUser::fetch( $userCreatorID ); 70 if ( !$user ) 71 { 72 $cli->error( "Subtree remove Error!\nCannot get user object by userID = '$userCreatorID'.\n(See site.ini[UserSettings].UserCreatorID)" ); 73 $script->shutdown( 1 ); 74 } 75 eZUser::setCurrentlyLoggedInUser( $user, $userCreatorID ); 76 77 $deleteIDArrayResult = array(); 78 foreach ( $deleteIDArray as $nodeID ) 79 { 80 $node = eZContentObjectTreeNode::fetch( $nodeID ); 81 if ( $node === null ) 82 { 83 $cli->error( "\nSubtree remove Error!\nCannot find subtree with nodeID: '$nodeID'." ); 84 continue; 85 } 86 $deleteIDArrayResult[] = $nodeID; 87 } 88 // Get subtree removal information 89 $info = eZContentObjectTreeNode::subtreeRemovalInformation( $deleteIDArrayResult ); 90 91 $deleteResult = $info['delete_list']; 92 93 if ( count( $deleteResult ) == 0 ) 94 { 95 $cli->output( "\nExit." ); 96 $script->shutdown( 1 ); 97 } 98 99 $totalChildCount = $info['total_child_count']; 100 $canRemoveAll = $info['can_remove_all']; 101 $moveToTrashStr = $moveToTrash ? 'true' : 'false'; 102 $reverseRelatedCount = $info['reverse_related_count']; 103 104 $cli->output( "\nTotal child count: $totalChildCount" ); 105 $cli->output( "Move to trash: $moveToTrashStr" ); 106 $cli->output( "Reverse related count: $reverseRelatedCount\n" ); 107 108 $cli->output( "Removing subtrees:\n" ); 109 110 foreach ( $deleteResult as $deleteItem ) 111 { 112 $node = $deleteItem['node']; 113 $nodeName = $deleteItem['node_name']; 114 if ( $node === null ) 115 { 116 $cli->error( "\nSubtree remove Error!\nCannot find subtree '$nodeName'." ); 117 continue; 118 } 119 $nodeID = $node->attribute( 'node_id' ); 120 $childCount = $deleteItem['child_count']; 121 $objectNodeCount = $deleteItem['object_node_count']; 122 123 $cli->output( "Node id: $nodeID" ); 124 $cli->output( "Node name: $nodeName" ); 125 126 $canRemove = $deleteItem['can_remove']; 127 if ( !$canRemove ) 128 { 129 $cli->error( "\nSubtree remove Error!\nInsufficient permissions. You do not have permissions to remove the subtree with nodeID: $nodeID\n" ); 130 continue; 131 } 132 $cli->output( "Child count: $childCount" ); 133 $cli->output( "Object node count: $objectNodeCount" ); 134 135 // Remove subtrees 136 eZContentObjectTreeNode::removeSubtrees( array( $nodeID ), $moveToTrash ); 137 138 // We should make sure that all subitems have been removed. 139 $itemInfo = eZContentObjectTreeNode::subtreeRemovalInformation( array( $nodeID ) ); 140 $itemTotalChildCount = $itemInfo['total_child_count']; 141 $itemDeleteList = $itemInfo['delete_list']; 142 143 if ( count( $itemDeleteList ) != 0 or ( $childCount != 0 and $itemTotalChildCount != 0 ) ) 144 $cli->error( "\nWARNING!\nSome subitems have not been removed.\n" ); 145 else 146 $cli->output( "Successfuly DONE.\n" ); 147 } 148 149 $cli->output( "Done." ); 150 $script->shutdown(); 151 152 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |