MediaWiki  REL1_24
JobSpecification.php
Go to the documentation of this file.
00001 <?php
00030 interface IJobSpecification {
00034     public function getType();
00035 
00039     public function getParams();
00040 
00044     public function getReleaseTimestamp();
00045 
00049     public function ignoreDuplicates();
00050 
00059     public function getDeduplicationInfo();
00060 
00064     public function getTitle();
00065 }
00066 
00084 class JobSpecification implements IJobSpecification {
00086     protected $type;
00087 
00089     protected $params;
00090 
00092     protected $title;
00093 
00095     protected $ignoreDuplicates;
00096 
00103     public function __construct(
00104         $type, array $params, array $opts = array(), Title $title = null
00105     ) {
00106         $this->validateParams( $params );
00107 
00108         $this->type = $type;
00109         $this->params = $params;
00110         $this->title = $title ?: Title::newMainPage();
00111         $this->ignoreDuplicates = !empty( $opts['removeDuplicates'] );
00112     }
00113 
00117     protected function validateParams( array $params ) {
00118         foreach ( $params as $p => $v ) {
00119             if ( is_array( $v ) ) {
00120                 $this->validateParams( $v );
00121             } elseif ( !is_scalar( $v ) && $v !== null ) {
00122                 throw new UnexpectedValueException( "Job parameter $p is not JSON serializable." );
00123             }
00124         }
00125     }
00126 
00130     public function getType() {
00131         return $this->type;
00132     }
00133 
00137     public function getTitle() {
00138         return $this->title;
00139     }
00140 
00144     public function getParams() {
00145         return $this->params;
00146     }
00147 
00151     public function getReleaseTimestamp() {
00152         return isset( $this->params['jobReleaseTimestamp'] )
00153             ? wfTimestampOrNull( TS_UNIX, $this->params['jobReleaseTimestamp'] )
00154             : null;
00155     }
00156 
00160     public function ignoreDuplicates() {
00161         return $this->ignoreDuplicates;
00162     }
00163 
00172     public function getDeduplicationInfo() {
00173         $info = array(
00174             'type' => $this->getType(),
00175             'namespace' => $this->getTitle()->getNamespace(),
00176             'title' => $this->getTitle()->getDBkey(),
00177             'params' => $this->getParams()
00178         );
00179         if ( is_array( $info['params'] ) ) {
00180             // Identical jobs with different "root" jobs should count as duplicates
00181             unset( $info['params']['rootJobSignature'] );
00182             unset( $info['params']['rootJobTimestamp'] );
00183             // Likewise for jobs with different delay times
00184             unset( $info['params']['jobReleaseTimestamp'] );
00185         }
00186 
00187         return $info;
00188     }
00189 }