babe4057b385070ebe2615fb754a6581fc8c1d26
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 put some secondary data extracted
21 * from article content into the database.
23 abstract class SecondaryDBDataUpdate
extends SecondaryDataUpdate
{
28 var $mDb, //!< Database connection reference
29 $mOptions, //!< SELECT options to be used (array)
30 $mHasTransaction;//!< bool whether a transaction is open on this object (internal use only!)
36 public function __construct( ) {
37 global $wgAntiLockFlags;
39 parent
::__construct( );
41 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK
) {
42 $this->mOptions
= array();
44 $this->mOptions
= array( 'FOR UPDATE' );
46 $this->mDb
= wfGetDB( DB_MASTER
);
47 $this->mHasTransaction
= false;
51 * Begin a database transaction.
53 * Because nested transactions are not supportred by the Database class, this implementation
54 * checked Database::trxLevel() and only opens a transaction if none is yet active.
56 public function beginTransaction() {
57 // NOTE: nested transactions are not supported, only start a transaction if none is open
58 if ( $this->mDb
->trxLevel() === 0 ) {
59 $this->mDb
->begin( get_class( $this ) . '::beginTransaction' );
60 $this->mHasTransaction
= true;
65 * Commit the database transaction started via beginTransaction (if any).
67 public function commitTransaction() {
68 if ( $this->mHasTransaction
) {
69 $this->mDb
->commit( get_class( $this ) . '::commitTransaction' );
74 * Abort the database transaction started via beginTransaction (if any).
76 public function abortTransaction() {
77 if ( $this->mHasTransaction
) {
78 $this->mDb
->rollback( get_class( $this ) . '::abortTransaction' );
83 * Invalidate the cache of a list of pages from a single namespace.
84 * This is intended for use by subclasses.
86 * @param $namespace Integer
87 * @param $dbkeys Array
89 protected function invalidatePages( $namespace, $dbkeys ) {
90 if ( !count( $dbkeys ) ) {
95 * Determine which pages need to be updated
96 * This is necessary to prevent the job queue from smashing the DB with
97 * large numbers of concurrent invalidations of the same page
99 $now = $this->mDb
->timestamp();
101 $res = $this->mDb
->select( 'page', array( 'page_id' ),
103 'page_namespace' => $namespace,
104 'page_title IN (' . $this->mDb
->makeList( $dbkeys ) . ')',
105 'page_touched < ' . $this->mDb
->addQuotes( $now )
108 foreach ( $res as $row ) {
109 $ids[] = $row->page_id
;
111 if ( !count( $ids ) ) {
117 * We still need the page_touched condition, in case the row has changed since
118 * the non-locking select above.
120 $this->mDb
->update( 'page', array( 'page_touched' => $now ),
122 'page_id IN (' . $this->mDb
->makeList( $ids ) . ')',
123 'page_touched < ' . $this->mDb
->addQuotes( $now )