Introducing abstract base classes for LinksUpdate, so we can nicely handle updates...
[lhc/web/wiklou.git] / includes / SecondaryDBDataUpdate.php
1 <?php
2 /**
3 * See docs/deferred.txt
4 *
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.
9 *
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.
14 *
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
19 *
20 * Abstract base class for update jobs that put some secondary data extracted
21 * from article content into the database.
22 */
23 abstract class SecondaryDBDataUpdate extends SecondaryDataUpdate {
24
25 /**@{{
26 * @private
27 */
28 var $mDb, //!< Database connection reference
29 $mOptions; //!< SELECT options to be used (array)
30 /**@}}*/
31
32 /**
33 * Constructor
34 *
35 * @param $title Title of the page we're updating
36 * @param $parserOutput ParserOutput: output from a full parse of this page
37 * @param $recursive Boolean: queue jobs for recursive updates?
38 */
39 public function __construct( Title $title, ParserOutput $parserOutput ) {
40 global $wgAntiLockFlags;
41
42 parent::__construct( $title, $parserOutput );
43
44 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) {
45 $this->mOptions = array();
46 } else {
47 $this->mOptions = array( 'FOR UPDATE' );
48 }
49 $this->mDb = wfGetDB( DB_MASTER );
50 }
51
52 /**
53 * Invalidate the cache of a list of pages from a single namespace
54 *
55 * @param $namespace Integer
56 * @param $dbkeys Array
57 */
58 public function invalidatePages( $namespace, $dbkeys ) {
59 if ( !count( $dbkeys ) ) {
60 return;
61 }
62
63 /**
64 * Determine which pages need to be updated
65 * This is necessary to prevent the job queue from smashing the DB with
66 * large numbers of concurrent invalidations of the same page
67 */
68 $now = $this->mDb->timestamp();
69 $ids = array();
70 $res = $this->mDb->select( 'page', array( 'page_id' ),
71 array(
72 'page_namespace' => $namespace,
73 'page_title IN (' . $this->mDb->makeList( $dbkeys ) . ')',
74 'page_touched < ' . $this->mDb->addQuotes( $now )
75 ), __METHOD__
76 );
77 foreach ( $res as $row ) {
78 $ids[] = $row->page_id;
79 }
80 if ( !count( $ids ) ) {
81 return;
82 }
83
84 /**
85 * Do the update
86 * We still need the page_touched condition, in case the row has changed since
87 * the non-locking select above.
88 */
89 $this->mDb->update( 'page', array( 'page_touched' => $now ),
90 array(
91 'page_id IN (' . $this->mDb->makeList( $ids ) . ')',
92 'page_touched < ' . $this->mDb->addQuotes( $now )
93 ), __METHOD__
94 );
95 }
96
97 }