46 parent::__construct();
47 $this->
addDescription(
'Script for periodic off-peak updating of the search index' );
48 $this->
addOption(
's',
'Starting timestamp',
false,
true );
49 $this->
addOption(
'e',
'Ending timestamp',
false,
true );
52 'File for saving/loading timestamps, searchUpdate.WIKI_ID.pos by default',
58 'Deprecated, has no effect (formerly lock time)',
69 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
70 $posFile = $this->
getOption(
'p',
'searchUpdate.' . rawurlencode( $dbDomain ) .
'.pos' );
74 } elseif ( is_readable( $posFile ) ) {
75 $start = file_get_contents( $posFile );
80 $this->doUpdateSearchIndex( $start, $end );
81 $file = fopen( $posFile,
'w' );
82 if ( $file !==
false ) {
83 fwrite( $file, $end );
86 $this->
error(
"*** Couldn't write to the $posFile!\n" );
90 private function doUpdateSearchIndex( $start, $end ) {
97 $this->
output(
"Updating searchindex between $start and $end\n" );
99 # Select entries from recentchanges which are on top and between the specified times
100 $start = $dbw->timestamp( $start );
101 $end = $dbw->timestamp( $end );
103 $res = $dbw->newSelectQueryBuilder()
104 ->select(
'rc_cur_id' )
105 ->from(
'recentchanges' )
106 ->join(
'page',
null,
'rc_cur_id=page_id AND rc_this_oldid=page_latest' )
108 $dbw->expr(
'rc_type',
'!=',
RC_LOG ),
109 'rc_timestamp BETWEEN ' . $dbw->addQuotes( $start ) .
' AND ' . $dbw->addQuotes( $end )
111 ->caller( __METHOD__ )->fetchResultSet();
113 foreach ( $res as $row ) {
114 $this->updateSearchIndexForPage( (
int)$row->rc_cur_id );
116 $this->
output(
"Done\n" );
124 private function updateSearchIndexForPage(
int $pageId ) {
127 ->getRevisionLookup()
128 ->getRevisionByPageId( $pageId, 0, IDBAccessObject::READ_LATEST );
131 $titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
132 $title = $titleObj->getPrefixedDBkey();
133 $this->
output(
"$title..." );
135 $u =
new SearchUpdate( $pageId, $titleObj, $rev->getContent( SlotRecord::MAIN ) );
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.