35 require_once __DIR__ .
'/Maintenance.php';
45 parent::__construct();
46 $this->
addDescription(
'Script for periodic off-peak updating of the search index' );
47 $this->
addOption(
's',
'Starting timestamp',
false,
true );
48 $this->
addOption(
'e',
'Ending timestamp',
false,
true );
51 'File for saving/loading timestamps, searchUpdate.WIKI_ID.pos by default',
57 'Deprecated, has no effect (formerly lock time)',
68 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
69 $posFile = $this->
getOption(
'p',
'searchUpdate.' . rawurlencode( $dbDomain ) .
'.pos' );
73 } elseif ( is_readable( $posFile ) ) {
74 $start = file_get_contents( $posFile );
79 $this->doUpdateSearchIndex( $start, $end );
80 $file = fopen( $posFile,
'w' );
81 if (
$file !==
false ) {
82 fwrite(
$file, $end );
85 $this->
error(
"*** Couldn't write to the $posFile!\n" );
89 private function doUpdateSearchIndex( $start, $end ) {
96 $this->
output(
"Updating searchindex between $start and $end\n" );
98 # Select entries from recentchanges which are on top and between the specified times
99 $start = $dbw->timestamp( $start );
100 $end = $dbw->timestamp( $end );
102 $res = $dbw->newSelectQueryBuilder()
103 ->select(
'rc_cur_id' )
104 ->from(
'recentchanges' )
105 ->join(
'page',
null,
'rc_cur_id=page_id AND rc_this_oldid=page_latest' )
107 'rc_type != ' . $dbw->addQuotes(
RC_LOG ),
108 'rc_timestamp BETWEEN ' . $dbw->addQuotes( $start ) .
' AND ' . $dbw->addQuotes( $end )
110 ->caller( __METHOD__ )->fetchResultSet();
112 foreach ( $res as $row ) {
113 $this->updateSearchIndexForPage( (
int)$row->rc_cur_id );
115 $this->
output(
"Done\n" );
123 private function updateSearchIndexForPage(
int $pageId ) {
126 ->getRevisionLookup()
127 ->getRevisionByPageId( $pageId, 0, IDBAccessObject::READ_LATEST );
130 $titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
131 $title = $titleObj->getPrefixedDBkey();
132 $this->
output(
"$title..." );
134 $u =
new SearchUpdate( $pageId, $titleObj, $rev->getContent( SlotRecord::MAIN ) );
144 require_once RUN_MAINTENANCE_IF_MAIN;
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Database independent search index updater.
Maintenance script for periodic off-peak updating of the search index.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
execute()
Do the actual work.
__construct()
Default constructor.
$wgDisableSearchUpdate
Config variable stub for the DisableSearchUpdate setting, for use by phpdoc and IDEs.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.