* Use local context to get messages
[lhc/web/wiklou.git] / includes / ViewCountUpdate.php
index 8dc8fa0..28ba341 100644 (file)
  */
 
 /**
- * Update for the 'page_counter' field, when $wgDisableCounters is true.
+ * Update for the 'page_counter' field, when $wgDisableCounters is false.
  *
  * Depending on $wgHitcounterUpdateFreq, this will directly increment the
  * 'page_counter' field or use the 'hitcounter' table and then collect the data
  * from that table to update the 'page_counter' field in a batch operation.
  */
-class ViewCountUpdate {
+class ViewCountUpdate implements DeferrableUpdate {
        protected $id;
 
        /**
@@ -48,8 +48,7 @@ class ViewCountUpdate {
                $dbw = wfGetDB( DB_MASTER );
 
                if ( $wgHitcounterUpdateFreq <= 1 || $dbw->getType() == 'sqlite' ) {
-                       $pageTable = $dbw->tableName( 'page' );
-                       $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = {$this->id}" );
+                       $dbw->update( 'page', array( 'page_counter = page_counter + 1' ), array( 'page_id' => $this->id ), __METHOD__ );
                        return;
                }
 
@@ -71,10 +70,7 @@ class ViewCountUpdate {
 
                $dbw = wfGetDB( DB_MASTER );
 
-               $hitcounterTable = $dbw->tableName( 'hitcounter' );
-               $res = $dbw->query( "SELECT COUNT(*) as n FROM $hitcounterTable" );
-               $row = $dbw->fetchObject( $res );
-               $rown = intval( $row->n );
+               $rown = $dbw->selectField( 'hitcounter', 'COUNT(*)', array(), __METHOD__ );
 
                if ( $rown < $wgHitcounterUpdateFreq ) {
                        return;
@@ -87,6 +83,7 @@ class ViewCountUpdate {
 
                $dbType = $dbw->getType();
                $tabletype = $dbType == 'mysql' ? "ENGINE=HEAP " : '';
+               $hitcounterTable = $dbw->tableName( 'hitcounter' );
                $acchitsTable = $dbw->tableName( 'acchits' );
                $pageTable = $dbw->tableName( 'page' );
 
@@ -107,7 +104,5 @@ class ViewCountUpdate {
 
                ignore_user_abort( $old_user_abort );
                wfProfileOut( __METHOD__ . '-collect' );
-               throw new MWException( 'test' );
        }
-
-}
\ No newline at end of file
+}