| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Definition of Updateniceurls class 5 // 6 // Created on: <03-Apr-2003 16:05:43 sp> 7 // 8 // SOFTWARE NAME: eZ publish 9 // SOFTWARE RELEASE: 3.9.0 10 // BUILD VERSION: 17785 11 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 12 // SOFTWARE LICENSE: GNU General Public License v2.0 13 // NOTICE: > 14 // This program is free software; you can redistribute it and/or 15 // modify it under the terms of version 2.0 of the GNU General 16 // Public License as published by the Free Software Foundation. 17 // 18 // This program is distributed in the hope that it will be useful, 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 // GNU General Public License for more details. 22 // 23 // You should have received a copy of version 2.0 of the GNU General 24 // Public License along with this program; if not, write to the Free 25 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 26 // MA 02110-1301, USA. 27 // 28 // 29 30 /*! \file updateniceurls.php 31 */ 32 33 set_time_limit ( 0 ); 34 35 include_once ( 'lib/ezutils/classes/ezcli.php' ); 36 include_once ( 'kernel/classes/ezscript.php' ); 37 38 $cli =& eZCLI::instance(); 39 $script =& eZScript::instance( array( 'description' => ( "eZ publish nice url updater.\n\n" . 40 "Will go trough and remake all nice urls" . 41 "\n" . 42 "updateniceurls.php" ), 43 'use-session' => true, 44 'use-modules' => true, 45 'use-extensions' => true ) ); 46 47 $script->startup(); 48 49 $options = $script->getOptions( "[db-user:][db-password:][db-database:][db-type:|db-driver:][sql]", 50 "", 51 array( 'db-host' => "Database host", 52 'db-user' => "Database user", 53 'db-password' => "Database password", 54 'db-database' => "Database name", 55 'db-driver' => "Database driver", 56 'db-type' => "Database driver, alias for --db-driver", 57 'sql' => "Display sql queries" 58 ) ); 59 $script->initialize(); 60 61 $dbUser = $options['db-user'] ? $options['db-user'] : false; 62 $dbPassword = $options['db-password'] ? $options['db-password'] : false; 63 $dbHost = isset( $options['db-host'] ) && $options['db-host'] ? $options['db-host'] : false; 64 $dbName = $options['db-database'] ? $options['db-database'] : false; 65 $dbImpl = $options['db-driver'] ? $options['db-driver'] : false; 66 $showSQL = $options['sql'] ? true : false; 67 $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false;; 68 if ( $siteAccess ) 69 { 70 changeSiteAccessSetting( $siteaccess, $siteAccess ); 71 } 72 73 function changeSiteAccessSetting( &$siteaccess, $optionData ) 74 { 75 global $isQuiet; 76 $cli =& eZCLI::instance(); 77 if ( file_exists( 'settings/siteaccess/' . $optionData ) ) 78 { 79 $siteaccess = $optionData; 80 if ( !$isQuiet ) 81 $cli->notice( "Using siteaccess $siteaccess for nice url update" ); 82 } 83 else 84 { 85 if ( !$isQuiet ) 86 $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" ); 87 } 88 } 89 90 include_once ( 'lib/ezdb/classes/ezdb.php' ); 91 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 92 93 $db =& eZDb::instance(); 94 95 if ( $dbHost or $dbName or $dbUser or $dbImpl ) 96 { 97 $params = array(); 98 if ( $dbHost !== false ) 99 $params['server'] = $dbHost; 100 if ( $dbUser !== false ) 101 { 102 $params['user'] = $dbUser; 103 $params['password'] = ''; 104 } 105 if ( $dbPassword !== false ) 106 $params['password'] = $dbPassword; 107 if ( $dbName !== false ) 108 $params['database'] = $dbName; 109 $db =& eZDB::instance( $dbImpl, $params, true ); 110 eZDB::setInstance( $db ); 111 } 112 113 $db->setIsSQLOutputEnabled( $showSQL ); 114 115 $fetchLimit = 30; 116 $percentLength = 6; 117 $timeLength = 12; 118 $maxColumn = 72 - $percentLength - $timeLength; 119 $totalChangedNodes = 0; 120 $totalNodeCount = 0; 121 122 $topLevelNodesArray = $db->arrayQuery( 'SELECT node_id FROM ezcontentobject_tree WHERE depth = 1 ORDER BY node_id' ); 123 124 foreach ( array_keys( $topLevelNodesArray ) as $key ) 125 { 126 $topLevelNodeID = $topLevelNodesArray[$key]['node_id']; 127 $rootNode = eZContentObjectTreeNode::fetch( $topLevelNodeID ); 128 if ( $rootNode->updateURLAlias() ) 129 ++$totalChangedNodes; 130 $done = false; 131 $offset = 0; 132 $counter = 0; 133 $column = 0; 134 $changedNodes = 0; 135 $nodeCount = $rootNode->subTreeCount( array( 'Limitation' => array() ) ); 136 $totalNodeCount += $nodeCount + 1; 137 $cli->output( "Starting updates for " . $cli->stylize( 'mark', $rootNode->attribute( 'name' ) ) . ", $nodeCount nodes" ); 138 $mtime = microtime(); 139 $tTime = explode( " ", $mtime ); 140 ereg( "0\.([0-9]+)", "" . $tTime[0], $t1 ); 141 $nodeStartTime = $tTime[1] . "." . $t1[1]; 142 while ( !$done ) 143 { 144 $nodes =& $rootNode->subTree( array( 'Offset' => $offset, 145 'Limit' => $fetchLimit, 146 'Limitation' => array() ) ); 147 foreach ( array_keys( $nodes ) as $key ) 148 { 149 $node =& $nodes[ $key ]; 150 $hasChanged = $node->updateURLAlias(); 151 if ( $hasChanged ) 152 { 153 ++$changedNodes; 154 ++$totalChangedNodes; 155 } 156 $changeCharacters = array( '.', '+', '*' ); 157 $changeCharacter = '.'; 158 if ( isset( $changeCharacters[$hasChanged] ) ) 159 $changeCharacter = $changeCharacters[$hasChanged]; 160 $cli->output( $changeCharacter, false ); 161 if ( $column > $maxColumn ) 162 { 163 $mtime = microtime(); 164 $tTime = explode( " ", $mtime ); 165 ereg( "0\.([0-9]+)", "" . $tTime[0], $t1 ); 166 $endTime = $tTime[1] . "." . $t1[1]; 167 $relTime = ( $endTime - $nodeStartTime ) / $counter; 168 $totalTime = ( $relTime * (float)$nodeCount ) - ( $endTime - $nodeStartTime ); 169 170 $percent = number_format( ( $counter * 100.0 ) / ( $nodeCount ), 2 ); 171 172 $timeLeft = ''; 173 // $usedTime = $endTime - $nodeStartTime; 174 // $timeSeconds = (int)( $usedTime % 60 ); 175 // $timeMinutes = (int)( ( $usedTime / 60.0 ) % 60 ); 176 // $timeHours = (int)( $usedTime / ( 60.0 * 60.0 ) ); 177 // $timeLeftArray = array(); 178 // if ( $timeHours > 0 ) 179 // $timeLeftArray[] = $timeHours . "h"; 180 // if ( $timeMinutes > 0 ) 181 // $timeLeftArray[] = $timeMinutes . "m"; 182 // $timeLeftArray[] = $timeSeconds . "s"; 183 // $timeLeft .= implode( " ", $timeLeftArray ); 184 185 $timeSeconds = (int)( $totalTime % 60 ); 186 $timeMinutes = (int)( ( $totalTime / 60.0 ) % 60 ); 187 $timeHours = (int)( $totalTime / ( 60.0 * 60.0 ) ); 188 $timeLeftArray = array(); 189 if ( $timeHours > 0 ) 190 $timeLeftArray[] = $timeHours . "h"; 191 if ( $timeMinutes > 0 ) 192 $timeLeftArray[] = $timeMinutes . "m"; 193 $timeLeftArray[] = $timeSeconds . "s"; 194 $timeLeft .= implode( " ", $timeLeftArray ); 195 196 $cli->output( " " . $percent . "% " . $timeLeft ); 197 198 $column = 0; 199 } 200 else 201 { 202 ++$column; 203 } 204 ++$counter; 205 flush(); 206 } 207 if ( count( $nodes ) == 0 ) 208 $done = true; 209 unset( $nodes ); 210 $offset += $fetchLimit; 211 } 212 if ( $column > 0 ) 213 $cli->output(); 214 $cli->output( "Updated " . $cli->stylize( 'emphasize', "$changedNodes/$nodeCount" ) . " for " . $cli->stylize( 'mark', $rootNode->attribute( 'name' ) ) ); 215 $cli->output(); 216 } 217 218 eZURLAlias::expireWildcards(); 219 220 $cli->output(); 221 $cli->output( "Total update " . $cli->stylize( 'emphasize', "$totalChangedNodes/$totalNodeCount" ) ); 222 223 $script->shutdown(); 224 225 ?>
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 |