3 * See docs/deferred.txt
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * Abstract base class for update jobs that do something with some secondary
21 * data extracted from article.
23 abstract class DataUpdate
implements DeferrableUpdate
{
28 public function __construct( ) {
33 * Begin an appropriate transaction, if any.
34 * This default implementation does nothing.
36 public function beginTransaction() {
41 * Commit the transaction started via beginTransaction, if any.
42 * This default implementation does nothing.
44 public function commitTransaction() {
49 * Abort / roll back the transaction started via beginTransaction, if any.
50 * This default implementation does nothing.
52 public function rollbackTransaction() {
57 * Convenience method, calls doUpdate() on every DataUpdate in the array.
59 * This methods supports transactions logic by first calling beginTransaction()
60 * on all updates in the array, then calling doUpdate() on each, and, if all goes well,
61 * then calling commitTransaction() on each update. If an error occurrs,
62 * rollbackTransaction() will be called on any update object that had beginTranscation()
63 * called but not yet commitTransaction().
65 * This allows for limited transactional logic across multiple backends for storing
69 * @param $updates array a list of DataUpdate instances
71 public static function runUpdates( $updates ) {
72 if ( empty( $updates ) ) return; # nothing to do
74 $open_transactions = array();
78 * @var $update StorageUpdate
79 * @var $trans StorageUpdate
84 foreach ( $updates as $update ) {
85 $update->beginTransaction();
86 $open_transactions[] = $update;
90 foreach ( $updates as $update ) {
94 // commit transactions
95 while ( count( $open_transactions ) > 0 ) {
96 $trans = array_pop( $open_transactions );
97 $trans->commitTransaction();
99 } catch ( Exception
$ex ) {
101 wfDebug( "Caught exception, will rethrow after rollback: " . $ex->getMessage() );
104 // rollback remaining transactions
105 while ( count( $open_transactions ) > 0 ) {
106 $trans = array_pop( $open_transactions );
107 $trans->rollbackTransaction();
111 throw $exception; // rethrow after cleanup