3 * Base code for update jobs that do something with some secondary
4 * data extracted from article.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
25 * Abstract base class for update jobs that do something with some secondary
26 * data extracted from article.
28 abstract class DataUpdate
implements DeferrableUpdate
{
33 public function __construct( ) {
38 * Begin an appropriate transaction, if any.
39 * This default implementation does nothing.
41 public function beginTransaction() {
46 * Commit the transaction started via beginTransaction, if any.
47 * This default implementation does nothing.
49 public function commitTransaction() {
54 * Abort / roll back the transaction started via beginTransaction, if any.
55 * This default implementation does nothing.
57 public function rollbackTransaction() {
62 * Convenience method, calls doUpdate() on every DataUpdate in the array.
64 * This methods supports transactions logic by first calling beginTransaction()
65 * on all updates in the array, then calling doUpdate() on each, and, if all goes well,
66 * then calling commitTransaction() on each update. If an error occurrs,
67 * rollbackTransaction() will be called on any update object that had beginTranscation()
68 * called but not yet commitTransaction().
70 * This allows for limited transactional logic across multiple backends for storing
74 * @param $updates array a list of DataUpdate instances
76 public static function runUpdates( $updates ) {
77 if ( empty( $updates ) ) return; # nothing to do
79 $open_transactions = array();
83 * @var $update StorageUpdate
84 * @var $trans StorageUpdate
89 foreach ( $updates as $update ) {
90 $update->beginTransaction();
91 $open_transactions[] = $update;
95 foreach ( $updates as $update ) {
99 // commit transactions
100 while ( count( $open_transactions ) > 0 ) {
101 $trans = array_pop( $open_transactions );
102 $trans->commitTransaction();
104 } catch ( Exception
$ex ) {
106 wfDebug( "Caught exception, will rethrow after rollback: " . $ex->getMessage() );
109 // rollback remaining transactions
110 while ( count( $open_transactions ) > 0 ) {
111 $trans = array_pop( $open_transactions );
112 $trans->rollbackTransaction();
116 throw $exception; // rethrow after cleanup