MediaWiki
REL1_24
|
00001 <?php 00033 abstract class SqlDataUpdate extends DataUpdate { 00035 protected $mDb; 00036 00038 protected $mOptions; 00039 00041 private $mHasTransaction; 00042 00044 protected $mUseTransaction; 00045 00053 public function __construct( $withTransaction = true ) { 00054 global $wgAntiLockFlags; 00055 00056 parent::__construct(); 00057 00058 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) { 00059 $this->mOptions = array(); 00060 } else { 00061 $this->mOptions = array( 'FOR UPDATE' ); 00062 } 00063 00064 // @todo Get connection only when it's needed? Make sure that doesn't 00065 // break anything, especially transactions! 00066 $this->mDb = wfGetDB( DB_MASTER ); 00067 00068 $this->mWithTransaction = $withTransaction; 00069 $this->mHasTransaction = false; 00070 } 00071 00080 public function beginTransaction() { 00081 if ( !$this->mWithTransaction ) { 00082 return; 00083 } 00084 00085 // NOTE: nested transactions are not supported, only start a transaction if none is open 00086 if ( $this->mDb->trxLevel() === 0 ) { 00087 $this->mDb->begin( get_class( $this ) . '::beginTransaction' ); 00088 $this->mHasTransaction = true; 00089 } 00090 } 00091 00095 public function commitTransaction() { 00096 if ( $this->mHasTransaction ) { 00097 $this->mDb->commit( get_class( $this ) . '::commitTransaction' ); 00098 $this->mHasTransaction = false; 00099 } 00100 } 00101 00105 public function abortTransaction() { 00106 if ( $this->mHasTransaction ) { //XXX: actually... maybe always? 00107 $this->mDb->rollback( get_class( $this ) . '::abortTransaction' ); 00108 $this->mHasTransaction = false; 00109 } 00110 } 00111 00119 protected function invalidatePages( $namespace, array $dbkeys ) { 00120 if ( $dbkeys === array() ) { 00121 return; 00122 } 00123 00129 $now = $this->mDb->timestamp(); 00130 $ids = array(); 00131 $res = $this->mDb->select( 'page', array( 'page_id' ), 00132 array( 00133 'page_namespace' => $namespace, 00134 'page_title' => $dbkeys, 00135 'page_touched < ' . $this->mDb->addQuotes( $now ) 00136 ), __METHOD__ 00137 ); 00138 00139 foreach ( $res as $row ) { 00140 $ids[] = $row->page_id; 00141 } 00142 00143 if ( $ids === array() ) { 00144 return; 00145 } 00146 00152 $this->mDb->update( 'page', array( 'page_touched' => $now ), 00153 array( 00154 'page_id' => $ids, 00155 'page_touched < ' . $this->mDb->addQuotes( $now ) 00156 ), __METHOD__ 00157 ); 00158 } 00159 }