Merge "Stop using the unholy trinity in DatabaseError"
[lhc/web/wiklou.git] / includes / job / jobs / RefreshLinksJob.php
index e81998d..78ac84d 100644 (file)
  * Job to update link tables for pages
  *
  * This job comes in a few variants:
- *   - a) Recursive jobs to update links for backlink pages for a given title
- *   - b) Jobs to update links for a set of titles (the job title is ignored)
- *   - c) Jobs to update links for a single title (the job title)
+ *   - a) Recursive jobs to update links for backlink pages for a given title.
+ *        These jobs have have (recursive:true,table:<table>) set.
+ *   - b) Jobs to update links for a set of pages (the job title is ignored).
+ *           These jobs have have (pages:(<page ID>:(<namespace>,<title>),...) set.
+ *   - c) Jobs to update links for a single page (the job title)
+ *        These jobs need no extra fields set.
  *
  * @ingroup JobQueue
  */
 class RefreshLinksJob extends Job {
-       const VERSION = 1;
-
-       function __construct( $title, $params = '', $id = 0 ) {
-               parent::__construct( 'refreshLinks', $title, $params, $id );
-               $this->params['version'] = self::VERSION;
+       function __construct( $title, $params = '' ) {
+               parent::__construct( 'refreshLinks', $title, $params );
                // Base backlink update jobs and per-title update jobs can be de-duplicated.
                // If template A changes twice before any jobs run, a clean queue will have:
                //              (A base, A base)
@@ -59,13 +59,8 @@ class RefreshLinksJob extends Job {
        function run() {
                global $wgUpdateRowsPerJob;
 
-               if ( is_null( $this->title ) ) {
-                       $this->setLastError( "Invalid page title" );
-                       return false;
-               }
-
                // Job to update all (or a range of) backlink pages for a page
-               if ( isset( $this->params['recursive'] ) ) {
+               if ( !empty( $this->params['recursive'] ) ) {
                        // Carry over information for de-duplication
                        $extraParams = $this->getRootJobParams();
                        // Avoid slave lag when fetching templates.
@@ -138,10 +133,14 @@ class RefreshLinksJob extends Job {
                if ( isset( $this->params['rootJobTimestamp'] ) ) {
                        $page = WikiPage::factory( $title );
                        $skewedTimestamp = wfTimestamp( TS_UNIX, $this->params['rootJobTimestamp'] ) + 5;
+                       if ( $page->getLinksTimestamp() > wfTimestamp( TS_MW, $skewedTimestamp ) ) {
+                               // Something already updated the backlinks since this job was made
+                               return true;
+                       }
                        if ( $page->getTouched() > wfTimestamp( TS_MW, $skewedTimestamp ) ) {
                                $parserOptions = $page->makeParserOptions( 'canonical' );
                                $parserOutput = ParserCache::singleton()->getDirty( $page, $parserOptions );
-                               if ( $parserOutput->getCacheTime() <= $skewedTimestamp ) {
+                               if ( $parserOutput && $parserOutput->getCacheTime() <= $skewedTimestamp ) {
                                        $parserOutput = false; // too stale
                                }
                        }
@@ -175,4 +174,8 @@ class RefreshLinksJob extends Job {
 
                return $info;
        }
+
+       public function workItemCount() {
+               return isset( $this->params['pages'] ) ? count( $this->params['pages'] ) : 1;
+       }
 }