Merge "Consistently follow conventions for documenting parameters"
[lhc/web/wiklou.git] / includes / ViewCountUpdate.php
index a30b0f7..22a4649 100644 (file)
@@ -48,22 +48,18 @@ class ViewCountUpdate implements DeferrableUpdate {
                $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;
                }
 
                # Not important enough to warrant an error page in case of failure
-               $oldignore = $dbw->ignoreErrors( true );
-
-               $dbw->insert( 'hitcounter', array( 'hc_id' => $this->id ), __METHOD__ );
-
-               $checkfreq = intval( $wgHitcounterUpdateFreq / 25 + 1 );
-               if ( rand() % $checkfreq == 0 && $dbw->lastErrno() == 0 ) {
-                       $this->collect();
-               }
-
-               $dbw->ignoreErrors( $oldignore );
+               try {
+                       $dbw->insert( 'hitcounter', array( 'hc_id' => $this->id ), __METHOD__ );
+                       $checkfreq = intval( $wgHitcounterUpdateFreq / 25 + 1 );
+                       if ( rand() % $checkfreq == 0 && $dbw->lastErrno() == 0 ) {
+                               $this->collect();
+                       }
+               } catch ( DBError $e ) {}
        }
 
        protected function collect() {
@@ -71,10 +67,7 @@ class ViewCountUpdate implements DeferrableUpdate {
 
                $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 +80,7 @@ class ViewCountUpdate implements DeferrableUpdate {
 
                $dbType = $dbw->getType();
                $tabletype = $dbType == 'mysql' ? "ENGINE=HEAP " : '';
+               $hitcounterTable = $dbw->tableName( 'hitcounter' );
                $acchitsTable = $dbw->tableName( 'acchits' );
                $pageTable = $dbw->tableName( 'page' );