+ /**
+ * Create an object of a subclass
+ */
+ static function factory( $command, $title, $params = false, $id = 0 ) {
+ switch ( $command ) {
+ case 'refreshLinks':
+ return new RefreshLinksJob( $title, $params, $id );
+ case 'htmlCacheUpdate':
+ case 'html_cache_update': # BC
+ return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id );
+ case 'sendMail':
+ return new EmaillingJob($params);
+ case 'enotifNotify':
+ return new EnotifNotifyJob($title, $params);
+ default:
+ throw new MWException( "Invalid job command \"$command\"" );
+ }
+ }
+
+ static function makeBlob( $params ) {
+ if ( $params !== false ) {
+ return serialize( $params );
+ } else {
+ return '';
+ }
+ }
+
+ static function extractBlob( $blob ) {
+ if ( (string)$blob !== '' ) {
+ return unserialize( $blob );
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Batch-insert a group of jobs into the queue.
+ * This will be wrapped in a transaction with a forced commit.
+ *
+ * This may add duplicate at insert time, but they will be
+ * removed later on, when the first one is popped.
+ *
+ * @param $jobs array of Job objects
+ */
+ static function batchInsert( $jobs ) {
+ if( count( $jobs ) ) {
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->begin();
+ foreach( $jobs as $job ) {
+ $rows[] = $job->insertFields();
+ }
+ $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' );
+ $dbw->commit();
+ }
+ }
+