00001 <?php
00041 $optionsWithArgs = array( 'd', 's', 'e', 'n', 'b', 'startidfile', 'server', 'page' );
00042
00043 require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
00044 ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
00045 : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' );
00046
00047 global $smwgEnableUpdateJobs, $wgServer, $wgTitle;
00048 $wgTitle = Title::newFromText( 'SMW_refreshData.php' );
00049 $smwgEnableUpdateJobs = false;
00050
00051 if ( isset( $options['server'] ) ) {
00052 $wgServer = $options['server'];
00053 }
00054
00055 if ( array_key_exists( 'd', $options ) ) {
00056 $delay = intval( $options['d'] ) * 100000;
00057 } else {
00058 $delay = false;
00059 }
00060
00061 if ( isset( $options['page'] ) ) {
00062 $pages = explode( '|', $options['page'] );
00063 } else {
00064 $pages = false;
00065 }
00066
00067 $writeToStartidfile = false;
00068 if ( array_key_exists( 's', $options ) ) {
00069 $start = max( 1, intval( $options['s'] ) );
00070 } elseif ( array_key_exists( 'startidfile', $options ) ) {
00071 if ( !is_writable( file_exists( $options['startidfile'] ) ? $options['startidfile'] : dirname( $options['startidfile'] ) ) ) {
00072 die("Cannot use a startidfile that we can't write to.\n");
00073 }
00074 $writeToStartidfile = true;
00075 if ( is_readable( $options['startidfile'] ) ) {
00076 $start = max( 1, intval( file_get_contents( $options['startidfile'] ) ) );
00077 } else {
00078 $start = 1;
00079 }
00080 } else {
00081 $start = 1;
00082 }
00083
00084 if ( array_key_exists( 'e', $options ) ) {
00085 $end = intval( $options['e'] );
00086 } elseif ( array_key_exists( 'n', $options ) ) {
00087 $end = $start + intval( $options['n'] );
00088 } else {
00089 $end = false;
00090 }
00091
00092 if ( array_key_exists( 'b', $options ) ) {
00093 global $smwgDefaultStore;
00094 $smwgDefaultStore = $options['b'];
00095 print "\nSelected storage $smwgDefaultStore for update!\n\n";
00096 }
00097
00098 $verbose = array_key_exists( 'v', $options );
00099
00100 $filterarray = array();
00101 if ( array_key_exists( 'c', $options ) ) {
00102 $filterarray[] = NS_CATEGORY;
00103 }
00104 if ( array_key_exists( 'p', $options ) ) {
00105 $filterarray[] = SMW_NS_PROPERTY;
00106 }
00107 if ( array_key_exists( 't', $options ) ) {
00108 $filterarray[] = SMW_NS_TYPE;
00109 }
00110 $filter = count( $filterarray ) > 0 ? $filterarray : false;
00111
00112 if ( array_key_exists( 'f', $options ) ) {
00113 print "\n Deleting all stored data completely and rebuilding it again later!\n Semantic data in the wiki might be incomplete for some time while this operation runs.\n\n NOTE: It is usually necessary to run this script ONE MORE TIME after this operation,\n since some properties' types are not stored yet in the first run.\n The first run can normally use the parameter -p to refresh only properties.\n\n";
00114 if ( ( array_key_exists( 's', $options ) ) || ( array_key_exists( 'e', $options ) ) ) {
00115 print " WARNING: -s or -e are used, so some pages will not be refreshed at all!\n Data for those pages will only be available again when they have been\n refreshed as well!\n\n";
00116 }
00117
00118 print 'Abort with control-c in the next five seconds ... ';
00119 wfCountDown( 6 );
00120
00121 smwfGetStore()->drop( $verbose );
00122 wfRunHooks( 'smwDropTables' );
00123 print "\n";
00124 smwfGetStore()->setup( $verbose );
00125 wfRunHooks( 'smwInitializeTables' );
00126 while ( ob_get_level() > 0 ) {
00127 ob_end_flush();
00128 }
00129 echo "\nAll storage structures have been deleted and recreated.\n\n";
00130 }
00131
00132 $linkCache = LinkCache::singleton();
00133 $num_files = 0;
00134 if ( $pages == false ) {
00135 print "Refreshing all semantic data in the database!\n---\n" .
00136 " Some versions of PHP suffer from memory leaks in long-running scripts.\n" .
00137 " If your machine gets very slow after many pages (typically more than\n" .
00138 " 1000) were refreshed, please abort with CTRL-C and resume this script\n" .
00139 " at the last processed page id using the parameter -s (use -v to display\n" .
00140 " page ids during refresh). Continue this until all pages were refreshed.\n---\n";
00141 print "Processing all IDs from $start to " . ( $end ? "$end" : 'last ID' ) . " ...\n";
00142
00143 $id = $start;
00144 while ( ( ( !$end ) || ( $id <= $end ) ) && ( $id > 0 ) ) {
00145 if ( $verbose ) {
00146 print "($num_files) Processing ID " . $id . " ...\n";
00147 }
00148 smwfGetStore()->refreshData( $id, 1, $filter, false );
00149 if ( ( $delay !== false ) && ( ( $num_files + 1 ) % 100 === 0 ) ) {
00150 usleep( $delay );
00151 }
00152 $num_files++;
00153 $linkCache->clear();
00154 }
00155 if ( $writeToStartidfile ) {
00156 file_put_contents( $options['startidfile'], "$id" );
00157 }
00158 print "$num_files IDs refreshed.\n";
00159 } else {
00160 print "Refreshing specified pages!\n\n";
00161
00162 foreach ( $pages as $page ) {
00163 if ( $verbose ) {
00164 print "($num_files) Processing page " . $page . " ...\n";
00165 }
00166
00167 $title = Title::newFromText( $page );
00168
00169 if ( !is_null( $title ) ) {
00170 $updatejob = new SMWUpdateJob( $title );
00171 $updatejob->run();
00172 }
00173
00174 $num_files++;
00175 }
00176
00177 print "$num_files pages refreshed.\n";
00178 }