[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <28-Nov-2002 12:45:40 bf> 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 set_time_limit( 0 ); 29 30 include_once ( 'lib/ezutils/classes/ezcli.php' ); 31 include_once ( 'kernel/classes/ezscript.php' ); 32 33 $cli =& eZCLI::instance(); 34 $endl = $cli->endlineString(); 35 36 $script =& eZScript::instance( array( 'description' => ( "eZ publish search index updater.\n\n" . 37 "Goes trough all objects and reindexes the meta data to the search engine" . 38 "\n" . 39 "updatesearchindex.php"), 40 'use-session' => true, 41 'use-modules' => true, 42 'use-extensions' => true ) ); 43 44 $script->startup(); 45 46 $options = $script->getOptions( "[db-host:][db-user:][db-password:][db-database:][db-type:|db-driver:][sql][clean]", 47 "", 48 array( 'db-host' => "Database host", 49 'db-user' => "Database user", 50 'db-password' => "Database password", 51 'db-database' => "Database name", 52 'db-driver' => "Database driver", 53 'db-type' => "Database driver, alias for --db-driver", 54 'sql' => "Display sql queries", 55 'clean' => "Remove all search data before beginning indexing" 56 ) ); 57 $script->initialize(); 58 59 $dbUser = $options['db-user'] ? $options['db-user'] : false; 60 $dbPassword = $options['db-password'] ? $options['db-password'] : false; 61 $dbHost = $options['db-host'] ? $options['db-host'] : false; 62 $dbName = $options['db-database'] ? $options['db-database'] : false; 63 $dbImpl = $options['db-driver'] ? $options['db-driver'] : false; 64 $showSQL = $options['sql'] ? true : false; 65 $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false; 66 $cleanupSearch = $options['clean'] ? true : false; 67 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 search index update" ); 82 } 83 else 84 { 85 if ( !$isQuiet ) 86 $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" ); 87 } 88 } 89 90 print( "Starting object re-indexing\n" ); 91 92 include_once ( 'lib/ezutils/classes/ezexecution.php' ); 93 include_once ( "lib/ezutils/classes/ezdebug.php" ); 94 include_once ( "kernel/classes/ezsearch.php" ); 95 96 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 97 98 $db =& eZDB::instance(); 99 100 if ( $dbHost or $dbName or $dbUser or $dbImpl ) 101 { 102 $params = array(); 103 if ( $dbHost !== false ) 104 $params['server'] = $dbHost; 105 if ( $dbUser !== false ) 106 { 107 $params['user'] = $dbUser; 108 $params['password'] = ''; 109 } 110 if ( $dbPassword !== false ) 111 $params['password'] = $dbPassword; 112 if ( $dbName !== false ) 113 $params['database'] = $dbName; 114 $db =& eZDB::instance( $dbImpl, $params, true ); 115 eZDB::setInstance( $db ); 116 } 117 118 $db->setIsSQLOutputEnabled( $showSQL ); 119 120 if ( $cleanupSearch ) 121 { 122 print( "{eZSearchEngine: Cleaning up search data" ); 123 eZSearch::cleanup(); 124 print( "}$endl" ); 125 } 126 127 // Get top node 128 $topNodeArray = eZPersistentObject::fetchObjectList( eZContentObjectTreeNode::definition(), 129 null, 130 array( 'parent_node_id' => 1, 131 'depth' => 1 ) ); 132 $subTreeCount = 0; 133 foreach ( array_keys ( $topNodeArray ) as $key ) 134 { 135 $subTreeCount += $topNodeArray[$key]->subTreeCount( array( 'Limitation' => false ) ); 136 } 137 138 print( "Number of objects to index: $subTreeCount $endl" ); 139 140 $i = 0; 141 $dotMax = 70; 142 $dotCount = 0; 143 $limit = 50; 144 145 foreach ( $topNodeArray as $node ) 146 { 147 $offset = 0; 148 $subTree = $node->subTree( array( 'Offset' => $offset, 'Limit' => $limit, 149 'Limitation' => array() ) ); 150 while ( $subTree != null ) 151 { 152 foreach ( $subTree as $innerNode ) 153 { 154 $object = $innerNode->attribute( 'object' ); 155 if ( !$object ) 156 { 157 continue; 158 } 159 eZSearch::removeObject( $object ); 160 eZSearch::addObject( $object ); 161 ++$i; 162 ++$dotCount; 163 print( "." ); 164 if ( $dotCount >= $dotMax or $i >= $subTreeCount ) 165 { 166 $dotCount = 0; 167 $percent = (float)( ($i*100.0) / $subTreeCount ); 168 print( " " . $percent . "%" . $endl ); 169 } 170 } 171 $offset += $limit; 172 $subTree = $node->subTree( array( 'Offset' => $offset, 'Limit' => $limit, 173 'Limitation' => array() ) ); 174 } 175 } 176 177 print( $endl . "done" . $endl ); 178 179 $script->shutdown(); 180 181 ?>
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 |