MediaWiki
REL1_22
|
00001 <?php 00033 abstract class SqlDataUpdate extends DataUpdate { 00034 00035 protected $mDb; 00036 protected $mOptions; 00037 00038 private $mHasTransaction; 00039 protected $mUseTransaction; 00040 00048 public function __construct( $withTransaction = true ) { 00049 global $wgAntiLockFlags; 00050 00051 parent::__construct(); 00052 00053 if ( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) { 00054 $this->mOptions = array(); 00055 } else { 00056 $this->mOptions = array( 'FOR UPDATE' ); 00057 } 00058 00059 // @todo get connection only when it's needed? make sure that doesn't break anything, especially transactions! 00060 $this->mDb = wfGetDB( DB_MASTER ); 00061 00062 $this->mWithTransaction = $withTransaction; 00063 $this->mHasTransaction = false; 00064 } 00065 00072 public function beginTransaction() { 00073 if ( !$this->mWithTransaction ) { 00074 return; 00075 } 00076 00077 // NOTE: nested transactions are not supported, only start a transaction if none is open 00078 if ( $this->mDb->trxLevel() === 0 ) { 00079 $this->mDb->begin( get_class( $this ) . '::beginTransaction' ); 00080 $this->mHasTransaction = true; 00081 } 00082 } 00083 00087 public function commitTransaction() { 00088 if ( $this->mHasTransaction ) { 00089 $this->mDb->commit( get_class( $this ) . '::commitTransaction' ); 00090 $this->mHasTransaction = false; 00091 } 00092 } 00093 00097 public function abortTransaction() { 00098 if ( $this->mHasTransaction ) { //XXX: actually... maybe always? 00099 $this->mDb->rollback( get_class( $this ) . '::abortTransaction' ); 00100 $this->mHasTransaction = false; 00101 } 00102 } 00103 00111 protected function invalidatePages( $namespace, array $dbkeys ) { 00112 if ( $dbkeys === array() ) { 00113 return; 00114 } 00115 00121 $now = $this->mDb->timestamp(); 00122 $ids = array(); 00123 $res = $this->mDb->select( 'page', array( 'page_id' ), 00124 array( 00125 'page_namespace' => $namespace, 00126 'page_title' => $dbkeys, 00127 'page_touched < ' . $this->mDb->addQuotes( $now ) 00128 ), __METHOD__ 00129 ); 00130 00131 foreach ( $res as $row ) { 00132 $ids[] = $row->page_id; 00133 } 00134 00135 if ( $ids === array() ) { 00136 return; 00137 } 00138 00144 $this->mDb->update( 'page', array( 'page_touched' => $now ), 00145 array( 00146 'page_id' => $ids, 00147 'page_touched < ' . $this->mDb->addQuotes( $now ) 00148 ), __METHOD__ 00149 ); 00150 } 00151 00152 }