[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <06-Apr-2004 14:26:28 amos> 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 function upgradeMenuINI( $menuGroup, $newNodeID ) 28 { 29 $cli = eZCLI::instance(); 30 $menuINI = eZINI::instance( 'menu.ini' ); 31 32 if ( !$menuINI->hasVariable( "Topmenu_$menuGroup", 'URL' ) ) 33 return; 34 $oldURLList = $menuINI->variable( "Topmenu_$menuGroup", 'URL' ); 35 $changed = false; 36 foreach ( $oldURLList as $context => $url ) 37 { 38 if ( is_numeric( $newNodeID ) ) 39 { 40 $url = preg_replace( "/\/(\d+)(\/?)$/", '/'. $newNodeID . "\\2", $url ); 41 $oldURLList[$context] = $url; 42 $changed = true; 43 } 44 } 45 if ( $changed ) 46 { 47 $menuINI->setVariable( "Topmenu_$menuGroup", 'URL', $oldURLList ); 48 49 $cli->output(); 50 $cli->output( "Writing back changes to menu.ini" ); 51 $menuINI->save( false, false, 'append', true ); 52 53 } 54 } 55 include_once ( 'lib/ezutils/classes/ezcli.php' ); 56 include_once ( 'kernel/classes/ezscript.php' ); 57 58 $cli =& eZCLI::instance(); 59 $script =& eZScript::instance( array( 'description' => ( "eZ publish Top Level Nodes Creator\n\n" . 60 "This script will create the top level nodes that are missing,\n" . 61 "\n" . 62 "updatetoplevel.php" ), 63 'use-session' => false, 64 'use-modules' => true, 65 'use-extensions' => true ) ); 66 67 $script->startup(); 68 69 $options = $script->getOptions( "[class-identifier:]", "", 70 array( 'class-identifier' => "Which class to create top level nodes from, default is 'folder'" ) ); 71 $script->initialize(); 72 73 $db =& eZDB::instance(); 74 75 $contentINI =& eZINI::instance( 'content.ini' ); 76 77 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 78 79 $checkNodes = array( array( 'Content', 'RootNode', '', 'Standard section', 'ezcontentnavigationpart', false ), 80 array( 'Users', 'UserRootNode', 'users', 'Users', 'ezusernavigationpart', true ), 81 array( 'Media', 'MediaRootNode', 'media', 'Media', 'ezmedianavigationpart', true ), 82 array( 'Design', 'DesignRootNode', 'design', 'Design', 'ezvisualnavigationpart', true ), 83 array( 'Setup', 'SetupRootNode', 'setup', 'Setup', 'ezsetupnavigationpart', true ) ); 84 85 $contentClassIdentifier = 'folder'; 86 if ( $options['class-identifier'] ) 87 $contentClassIdentifier = $options['class-identifier']; 88 89 $sectionID = 1; 90 $userID = 14; 91 $class = eZContentClass::fetchByIdentifier( $contentClassIdentifier ); 92 if ( !is_object( $class ) ) 93 $script->shutdown( 1, "Failed to load content class for identifier '$contentClassIdentifier'" ); 94 95 include_once ( 'kernel/classes/ezsection.php' ); 96 $sections = eZSection::fetchList(); 97 98 $storeContentINI = false; 99 $i = 0; 100 foreach ( $checkNodes as $checkNode ) 101 { 102 if ( $i > 0 ) 103 $cli->output(); 104 $name = $checkNode[0]; 105 $iniVariable = $checkNode[1]; 106 $nodeURLName = $checkNode[2]; 107 $nodeSectionName = strtolower( $checkNode[3] ); 108 $nodeNavigationPartIdentifier = $checkNode[4]; 109 $createNewNode = $checkNode[5]; 110 $rootNodeID = $contentINI->variable( 'NodeSettings', $iniVariable ); 111 112 $cli->output( "Checking node " . $cli->stylize( 'highlight', $name ) . " (" . $cli->stylize( 'emphasize', $rootNodeID ) . ")", 113 false ); 114 115 $rootNode = eZContentObjectTreeNode::fetch( $rootNodeID ); 116 117 $createNode = false; 118 if ( is_object( $rootNode ) ) 119 { 120 $parentNodeID = $rootNode->attribute( 'parent_node_id' ); 121 if ( $parentNodeID != 1 ) 122 { 123 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'failure', "[ Failed ]" ) ); 124 $cli->output( "This is not a top level node, a new one will be created" ); 125 $createNode = true; 126 } 127 else 128 { 129 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'success', "[ OK ]" ) ); 130 } 131 } 132 else 133 { 134 $rootNode = eZContentObjectTreeNode::fetchByURLPath( $nodeURLName ); 135 if ( is_object( $rootNode ) ) 136 { 137 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'success', "[ OK ]" ) ); 138 $cli->output( "The actual node ID is " . $cli->stylize( 'emphasize', $rootNode->attribute( 'node_id' ) ) . ", will update content.ini with this" ); 139 $contentINI->setVariable( 'NodeSettings', $iniVariable, $rootNode->attribute( 'node_id' ) ); 140 upgradeMenuINI( $nodeURLName, $rootNode->attribute( 'node_id' ) ); 141 $cli->output( "Updated content.ini with new ID " ); 142 $storeContentINI = true; 143 } 144 else 145 { 146 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'failure', "[ Failed ]" ) ); 147 $cli->output( "The node does not exist, a new one will be created" ); 148 $createNode = true; 149 } 150 } 151 152 if ( $createNode ) 153 { 154 $cli->output( 'Creating', false ); 155 156 $sectionID = false; 157 foreach ( $sections as $section ) 158 { 159 $sectionName = strtolower( $section->attribute( 'name' ) ); 160 $sectionNavigationPartIdentifier = $section->attribute( 'navigation_part_identifier' ); 161 if ( $sectionName == $nodeSectionName and 162 $sectionNavigationPartIdentifier == $nodeNavigationPartIdentifier ) 163 { 164 $sectionID = $section->attribute( 'id' ); 165 break; 166 } 167 } 168 if ( !$sectionID ) 169 { 170 if ( $createNewNode ) 171 { 172 $row = array( 'id' => false, 173 'name' => $name, 174 'navigation_part_identifier' => $nodeNavigationPartIdentifier ); 175 $section = new eZSection( $row ); 176 $section->store(); 177 $sectionID = $section->attribute( 'id' ); 178 $sections[] = $section; 179 } 180 else 181 { 182 $sectionID = 1; 183 } 184 } 185 186 $contentObject = $class->instantiate( $userID, $sectionID ); 187 188 if ( is_object( $contentObject ) ) 189 { 190 $contentVersion =& $contentObject->version( $contentObject->attribute( 'current_version' ) ); 191 $contentObjectAttributes =& $contentVersion->contentObjectAttributes(); 192 foreach ( array_keys( $contentObjectAttributes ) as $contentObjectAttributeKey ) 193 { 194 $contentObjectAttribute =& $contentObjectAttributes[$contentObjectAttributeKey]; 195 $contentClassAttribute =& $contentObjectAttribute->attribute( 'contentclass_attribute' ); 196 $contentClassAttributeIdentifier = $contentClassAttribute->attribute( 'identifier' ); 197 $contentObjectAttributeType = $contentObjectAttribute->attribute( 'data_type_string' ); 198 if ( ( $contentObjectAttributeType == 'ezstring' or 199 $contentObjectAttributeType == 'eztext' ) and 200 ( $contentClassAttributeIdentifier == 'name' or 201 $contentClassAttributeIdentifier == 'title' ) ) 202 { 203 $contentObjectAttribute->setAttribute( 'data_text', $name ); 204 $contentObjectAttribute->store(); 205 break; 206 } 207 } 208 209 $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ), 210 'contentobject_version' => $contentObject->attribute( 'current_version' ), 211 'parent_node' => 1, 212 'is_main' => 1 ) ); 213 $nodeAssignment->store(); 214 215 include_once ( 'lib/ezutils/classes/ezoperationhandler.php' ); 216 $operationResult = eZOperationHandler::execute( 'content', 'publish', 217 array( 'object_id' => $contentObject->attribute( 'id' ), 218 'version' => $contentObject->attribute( 'current_version' ) ) ); 219 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'success', " [ OK ]" ) ); 220 221 $contentObject = eZContentObject::fetch( $contentObject->attribute( 'id' ) ); 222 $node = $contentObject->mainNode(); 223 if ( is_object( $node ) ) 224 { 225 $cli->output( "New root node ID: " . $cli->stylize( 'emphasize', $node->attribute( 'node_id' ) ) ); 226 if ( $rootNodeID != $node->attribute( 'node_id' ) ) 227 { 228 $contentINI->setVariable( 'NodeSettings', $iniVariable, $node->attribute( 'node_id' ) ); 229 upgradeMenuINI( $nodeURLName, $node->attribute( 'node_id' ) ); 230 $cli->output( "Updated content.ini with new ID " ); 231 $storeContentINI = true; 232 } 233 } 234 235 if ( $name == 'Design' ) 236 { 237 $cli->output( "Moving node /setup/ez_publish to /design", false ); 238 $setupEzPublushNode = eZContentObjectTreeNode::fetchByURLPath( 'setup/ez_publish' ); 239 if ( !is_object( $setupEzPublushNode ) ) 240 { 241 242 $cli->output( '' ); // \n 243 $cli->output( "Node not found.", false ); 244 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'failure', "[ Failed ]" ) ); 245 } 246 else 247 { 248 $setupEzPublushNode->move( $node->attribute( 'node_id' ) ); 249 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'success', "[ OK ]" ) ); 250 } 251 unset( $setupEzPublushNode ); 252 } 253 } 254 else 255 { 256 $cli->output( $cli->gotoColumn( 50 ) . $cli->stylize( 'failure', " [ Failed ]" ) ); 257 } 258 } 259 260 ++$i; 261 } 262 263 if ( $storeContentINI ) 264 { 265 $cli->output(); 266 $cli->output( "Writing back changes to content.ini" ); 267 $contentINI->save( false, false, 'append', true ); 268 } 269 270 $script->shutdown(); 271 272 ?>
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 |