MediaWiki  1.27.2
DataUpdate.php
Go to the documentation of this file.
1 <?php
32 abstract class DataUpdate implements DeferrableUpdate {
33  public function __construct() {
34  // noop
35  }
36 
41  public function beginTransaction() {
42  // noop
43  }
44 
49  public function commitTransaction() {
50  // noop
51  }
52 
57  public function rollbackTransaction() {
58  // noop
59  }
60 
77  public static function runUpdates( array $updates, $mode = 'run' ) {
78  if ( $mode === 'enqueue' ) {
79  // When possible, push updates as jobs instead of calling doUpdate()
80  $updates = self::enqueueUpdates( $updates );
81  }
82 
83  if ( !count( $updates ) ) {
84  return; // nothing to do
85  }
86 
87  $open_transactions = [];
88  $exception = null;
89 
90  try {
91  // begin transactions
92  foreach ( $updates as $update ) {
93  $update->beginTransaction();
94  $open_transactions[] = $update;
95  }
96 
97  // do work
98  foreach ( $updates as $update ) {
99  $update->doUpdate();
100  }
101 
102  // commit transactions
103  while ( count( $open_transactions ) > 0 ) {
104  $trans = array_pop( $open_transactions );
105  $trans->commitTransaction();
106  }
107  } catch ( Exception $ex ) {
108  $exception = $ex;
109  wfDebug( "Caught exception, will rethrow after rollback: " .
110  $ex->getMessage() . "\n" );
111  }
112 
113  // rollback remaining transactions
114  while ( count( $open_transactions ) > 0 ) {
115  $trans = array_pop( $open_transactions );
116  $trans->rollbackTransaction();
117  }
118 
119  if ( $exception ) {
120  throw $exception; // rethrow after cleanup
121  }
122  }
123 
132  protected static function enqueueUpdates( array $updates ) {
133  $remaining = [];
134 
135  foreach ( $updates as $update ) {
136  if ( $update instanceof EnqueueableDataUpdate ) {
137  $spec = $update->getAsJobSpecification();
138  JobQueueGroup::singleton( $spec['wiki'] )->push( $spec['job'] );
139  } else {
140  $remaining[] = $update;
141  }
142  }
143 
144  return $remaining;
145  }
146 }
147 
160  public function getAsJobSpecification();
161 }
beginTransaction()
Begin an appropriate transaction, if any.
Definition: DataUpdate.php:41
commitTransaction()
Commit the transaction started via beginTransaction, if any.
Definition: DataUpdate.php:49
the array() calling protocol came about after MediaWiki 1.4rc1.
Interface that deferrable updates should implement.
static enqueueUpdates(array $updates)
Enqueue jobs for every DataUpdate that support enqueueUpdate() and return the remaining DataUpdate ob...
Definition: DataUpdate.php:132
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition: DataUpdate.php:156
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static runUpdates(array $updates, $mode= 'run')
Convenience method, calls doUpdate() on every DataUpdate in the array.
Definition: DataUpdate.php:77
rollbackTransaction()
Abort / roll back the transaction started via beginTransaction, if any.
Definition: DataUpdate.php:57
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static singleton($wiki=false)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Abstract base class for update jobs that do something with some secondary data extracted from article...
Definition: DataUpdate.php:32