48 parent::__construct();
49 $this->
addDescription(
'Script for periodic off-peak updating of the search index' );
50 $this->
addOption(
's',
'Starting timestamp',
false,
true );
51 $this->
addOption(
'e',
'Ending timestamp',
false,
true );
54 'File for saving/loading timestamps, searchUpdate.WIKI_ID.pos by default',
60 'Deprecated, has no effect (formerly lock time)',
71 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
72 $posFile = $this->
getOption(
'p',
'searchUpdate.' . rawurlencode( $dbDomain ) .
'.pos' );
76 } elseif ( is_readable( $posFile ) ) {
77 $start = file_get_contents( $posFile );
82 $this->doUpdateSearchIndex( $start, $end );
83 $file = fopen( $posFile,
'w' );
84 if ( $file !==
false ) {
85 fwrite( $file, $end );
88 $this->
error(
"*** Couldn't write to the $posFile!\n" );
92 private function doUpdateSearchIndex( $start, $end ) {
99 $this->
output(
"Updating searchindex between $start and $end\n" );
101 # Select entries from recentchanges which are on top and between the specified times
102 $start = $dbw->timestamp( $start );
103 $end = $dbw->timestamp( $end );
105 $res = $dbw->newSelectQueryBuilder()
106 ->select(
'rc_cur_id' )
107 ->from(
'recentchanges' )
108 ->join(
'page',
null,
'rc_cur_id=page_id AND rc_this_oldid=page_latest' )
110 $dbw->expr(
'rc_type',
'!=',
RC_LOG ),
111 $dbw->expr(
'rc_timestamp',
'>=', $start ),
112 $dbw->expr(
'rc_timestamp',
'<=', $end ),
114 ->caller( __METHOD__ )->fetchResultSet();
116 foreach ( $res as $row ) {
117 $this->updateSearchIndexForPage( (
int)$row->rc_cur_id );
119 $this->
output(
"Done\n" );
127 private function updateSearchIndexForPage(
int $pageId ) {
130 ->getRevisionLookup()
131 ->getRevisionByPageId( $pageId, 0, IDBAccessObject::READ_LATEST );
134 $titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
135 $title = $titleObj->getPrefixedDBkey();
136 $this->
output(
"$title..." );
138 $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.