replace TYPE= with ENGINE=, (supported since 4.0, TYPE deprecated since 4.1)
[lhc/web/wiklou.git] / includes / JobQueue.php
index 7cd0878..c9b2146 100644 (file)
@@ -7,8 +7,9 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 class Job {
        var $command,
                $title,
-               $params, 
-               $removeDuplicates, 
+               $params,
+               $id,
+               $removeDuplicates,
                $error;
 
        /*-------------------------------------------------------------------------
@@ -16,7 +17,7 @@ class Job {
         *------------------------------------------------------------------------*/
        /**
         * Add an array of refreshLinks jobs to the queue
-        * @param array $titles Array of title objects. 
+        * @param array $titles Array of title objects.
         * @static
         */
        function queueLinksJobs( $titles ) {
@@ -41,7 +42,7 @@ class Job {
                $dbr =& wfGetDB( DB_SLAVE );
 
                // Get a job from the slave
-               $row = $dbr->selectRow( 'job', '*', '', $fname, 
+               $row = $dbr->selectRow( 'job', '*', '', $fname,
                        array( 'ORDER BY' => 'job_id', 'LIMIT' => 1 )
                );
 
@@ -59,15 +60,15 @@ class Job {
                if ( !$affected ) {
                        // Failed, someone else beat us to it
                        // Try getting a random row
-                       $row = $dbw->selectRow( 'job', array( 'MIN(job_id) as minjob', 
-                               'MAX(job_id) as maxjob' ), $fname );
+                       $row = $dbw->selectRow( 'job', array( 'MIN(job_id) as minjob',
+                               'MAX(job_id) as maxjob' ), '', $fname );
                        if ( $row === false || is_null( $row->minjob ) || is_null( $row->maxjob ) ) {
                                // No jobs to get
                                wfProfileOut( $fname );
                                return false;
                        }
                        // Get the random row
-                       $row = $dbw->selectRow( 'job', '*', 
+                       $row = $dbw->selectRow( 'job', '*',
                                array( 'job_id' => mt_rand( $row->minjob, $row->maxjob ) ),     $fname );
                        if ( $row === false ) {
                                // Random job gone before we got the chance to select it
@@ -85,17 +86,15 @@ class Job {
                                // Give up
                                wfProfileOut( $fname );
                                return false;
-                       }                               
+                       }
                }
                
                // If execution got to here, there's a row in $row that has been deleted from the database
                // by this thread. Hence the concurrent pop was successful.
-               $command = $row->job_cmd;
                $namespace = $row->job_namespace;
                $dbkey = $row->job_title;
                $title = Title::makeTitleSafe( $namespace, $dbkey );
-               $params = $row->job_params;
-               $job = new Job( $command, $title, $params );
+               $job = new Job( $row->job_cmd, $title, $row->job_params, $row->job_id );
                wfProfileOut( $fname );
                return $job;
        }
@@ -104,10 +103,11 @@ class Job {
         * Non-static functions
         *------------------------------------------------------------------------*/
 
-       function Job( $command, $title, $params = '' ) {
+       function Job( $command, $title, $params = '', $id = 0 ) {
                $this->command = $command;
                $this->title = $title;
                $this->params = $params;
+               $this->id = $id;
 
                // A bit of premature generalisation
                // Oh well, the whole class is premature generalisation really
@@ -162,6 +162,8 @@ class Job {
         */
        function refreshLinks() {
                global $wgParser;
+               $fname = 'Job::refreshLinks';
+               wfProfileIn( $fname );
                
                $dbw =& wfGetDB( DB_MASTER );
 
@@ -170,19 +172,26 @@ class Job {
                
                if ( is_null( $this->title ) ) {
                        $this->error = "refreshLinks: Invalid title";
+                       wfProfileOut( $fname );
                        return false;
                }
 
                $revision = Revision::newFromTitle( $this->title );
                if ( !$revision ) {
                        $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
+                       wfProfileOut( $fname );
                        return false;
                }
 
+               wfProfileIn( "$fname-parse" );
                $options = new ParserOptions;
                $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() );
+               wfProfileOut( "$fname-parse" );
+               wfProfileIn( "$fname-update" );
                $update = new LinksUpdate( $this->title, $parserOutput, false );
                $update->doUpdate();
+               wfProfileOut( "$fname-update" );
+               wfProfileOut( $fname );
                return true;
        }
 
@@ -195,10 +204,11 @@ class Job {
                        return $s;
                } else {
                        return "{$this->command} {$this->params}";
-               }                       
+               }
        }
 
        function getLastError() {
                return $this->error;
        }
 }
+?>