Support plural for 'linkstoimage', 'redirectstofile' and 'duplicatesoffile'
[lhc/web/wiklou.git] / maintenance / runJobs.php
1 <?php
2 /**
3 * @file
4 * @ingroup Maintenance
5 */
6
7 $optionsWithArgs = array( 'maxjobs', 'type' );
8 $wgUseNormalUser = true;
9 require_once( 'commandLine.inc' );
10 require_once( "$IP/includes/JobQueue.php" );
11 require_once( "$IP/includes/FakeTitle.php" );
12
13 if ( isset( $options['maxjobs'] ) ) {
14 $maxJobs = $options['maxjobs'];
15 } else {
16 $maxJobs = 10000;
17 }
18
19 $type = false;
20 if ( isset( $options['type'] ) )
21 $type = $options['type'];
22
23 $wgTitle = Title::newFromText( 'RunJobs.php' );
24
25 $dbw = wfGetDB( DB_MASTER );
26 $n = 0;
27 $conds = '';
28 if ($type !== false)
29 $conds = "job_cmd = " . $dbw->addQuotes($type);
30
31 while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) {
32 $offset=0;
33 for (;;) {
34 $job = ($type == false) ?
35 Job::pop($offset)
36 : Job::pop_type($type);
37
38 if ($job == false)
39 break;
40
41 wfWaitForSlaves( 5 );
42 print wfTimestamp( TS_DB ) . " " . $job->id . " " . $job->toString() . "\n";
43 $offset=$job->id;
44 if ( !$job->run() ) {
45 print wfTimestamp( TS_DB ) . " Error: {$job->error}\n";
46 }
47 if ( $maxJobs && ++$n > $maxJobs ) {
48 break 2;
49 }
50 }
51 }
52