MediaWiki  1.23.2
SqlDataUpdate.php
Go to the documentation of this file.
1 <?php
33 abstract class SqlDataUpdate extends DataUpdate {
35  protected $mDb;
36 
38  protected $mOptions;
39 
41  private $mHasTransaction;
42 
44  protected $mUseTransaction;
45 
53  public function __construct( $withTransaction = true ) {
54  global $wgAntiLockFlags;
55 
56  parent::__construct();
57 
58  if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) {
59  $this->mOptions = array();
60  } else {
61  $this->mOptions = array( 'FOR UPDATE' );
62  }
63 
64  // @todo Get connection only when it's needed? Make sure that doesn't
65  // break anything, especially transactions!
66  $this->mDb = wfGetDB( DB_MASTER );
67 
68  $this->mWithTransaction = $withTransaction;
69  $this->mHasTransaction = false;
70  }
71 
80  public function beginTransaction() {
81  if ( !$this->mWithTransaction ) {
82  return;
83  }
84 
85  // NOTE: nested transactions are not supported, only start a transaction if none is open
86  if ( $this->mDb->trxLevel() === 0 ) {
87  $this->mDb->begin( get_class( $this ) . '::beginTransaction' );
88  $this->mHasTransaction = true;
89  }
90  }
91 
95  public function commitTransaction() {
96  if ( $this->mHasTransaction ) {
97  $this->mDb->commit( get_class( $this ) . '::commitTransaction' );
98  $this->mHasTransaction = false;
99  }
100  }
101 
105  public function abortTransaction() {
106  if ( $this->mHasTransaction ) { //XXX: actually... maybe always?
107  $this->mDb->rollback( get_class( $this ) . '::abortTransaction' );
108  $this->mHasTransaction = false;
109  }
110  }
111 
119  protected function invalidatePages( $namespace, array $dbkeys ) {
120  if ( $dbkeys === array() ) {
121  return;
122  }
123 
129  $now = $this->mDb->timestamp();
130  $ids = array();
131  $res = $this->mDb->select( 'page', array( 'page_id' ),
132  array(
133  'page_namespace' => $namespace,
134  'page_title' => $dbkeys,
135  'page_touched < ' . $this->mDb->addQuotes( $now )
136  ), __METHOD__
137  );
138 
139  foreach ( $res as $row ) {
140  $ids[] = $row->page_id;
141  }
142 
143  if ( $ids === array() ) {
144  return;
145  }
146 
152  $this->mDb->update( 'page', array( 'page_touched' => $now ),
153  array(
154  'page_id' => $ids,
155  'page_touched < ' . $this->mDb->addQuotes( $now )
156  ), __METHOD__
157  );
158  }
159 }
SqlDataUpdate\$mUseTransaction
bool $mUseTransaction
Whether this update should be wrapped in a transaction *.
Definition: SqlDataUpdate.php:40
SqlDataUpdate\$mOptions
array $mOptions
SELECT options to be used (array) *.
Definition: SqlDataUpdate.php:36
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
SqlDataUpdate\__construct
__construct( $withTransaction=true)
Constructor.
Definition: SqlDataUpdate.php:49
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
ALF_NO_LINK_LOCK
const ALF_NO_LINK_LOCK
Definition: Defines.php:160
SqlDataUpdate\invalidatePages
invalidatePages( $namespace, array $dbkeys)
Invalidate the cache of a list of pages from a single namespace.
Definition: SqlDataUpdate.php:115
SqlDataUpdate\commitTransaction
commitTransaction()
Commit the database transaction started via beginTransaction (if any).
Definition: SqlDataUpdate.php:91
SqlDataUpdate\beginTransaction
beginTransaction()
Begin a database transaction, if $withTransaction was given as true in the constructor for this SqlDa...
Definition: SqlDataUpdate.php:76
DataUpdate
Abstract base class for update jobs that do something with some secondary data extracted from article...
Definition: DataUpdate.php:32
SqlDataUpdate\$mDb
DatabaseBase $mDb
Database connection reference *.
Definition: SqlDataUpdate.php:34
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SqlDataUpdate\$mHasTransaction
bool $mHasTransaction
Whether a transaction is open on this object (internal use only!) *.
Definition: SqlDataUpdate.php:38
DatabaseBase
Database abstraction object.
Definition: Database.php:219
SqlDataUpdate
Abstract base class for update jobs that put some secondary data extracted from article content into ...
Definition: SqlDataUpdate.php:33
SqlDataUpdate\abortTransaction
abortTransaction()
Abort the database transaction started via beginTransaction (if any).
Definition: SqlDataUpdate.php:101
DataUpdate\__construct
__construct()
Constructor.
Definition: DataUpdate.php:36
as
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
$res
$res
Definition: database.txt:21