X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSiteStatsUpdate.php;h=1c82d086688bf5b4fddc7245ae23774a1f1b7594;hb=39bb950f401807a71cb9e9b3d5f91d71876178bc;hp=900956b6398da93d1f3c11a7ee29ddcd91a4b0ba;hpb=80a4a131d1f380044da1aa073a90eadbf1f769dd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SiteStatsUpdate.php b/includes/SiteStatsUpdate.php index 900956b639..1c82d08668 100644 --- a/includes/SiteStatsUpdate.php +++ b/includes/SiteStatsUpdate.php @@ -1,42 +1,83 @@ mViews = $views; $this->mEdits = $edits; $this->mGood = $good; + $this->mPages = $pages; + $this->mUsers = $users; } - function doUpdate() - { - global $wgIsMySQL; - $a = array(); - - if ( $this->mViews < 0 ) { $m = "-1"; } - else if ( $this->mViews > 0 ) { $m = "+1"; } - else $m = ""; - array_push( $a, "ss_total_views=(ss_total_views$m)" ); - - if ( $this->mEdits < 0 ) { $m = "-1"; } - else if ( $this->mEdits > 0 ) { $m = "+1"; } - else $m = ""; - array_push( $a, "ss_total_edits=(ss_total_edits$m)" ); - - if ( $this->mGood < 0 ) { $m = "-1"; } - else if ( $this->mGood > 0 ) { $m = "+1"; } - else $m = ""; - array_push( $a, "ss_good_articles=(ss_good_articles$m)" ); - $lowpri=$wgIsMySQL?"LOW_PRIORITY":""; - $sql = "UPDATE $lowpri site_stats SET " . implode ( ",", $a ) . - " WHERE ss_row_id=1"; - wfQuery( $sql, DB_WRITE, "SiteStatsUpdate::doUpdate" ); + function appendUpdate( &$sql, $field, $delta ) { + if ( $delta ) { + if ( $sql ) { + $sql .= ','; + } + if ( $delta < 0 ) { + $sql .= "$field=$field-1"; + } else { + $sql .= "$field=$field+1"; + } + } } -} + function doUpdate() { + global $wgDBname; + $fname = 'SiteStatsUpdate::doUpdate'; + $dbw =& wfGetDB( DB_MASTER ); + + # First retrieve the row just to find out which schema we're in + $row = $dbw->selectRow( 'site_stats', '*', false, $fname ); + + $updates = ''; + + $this->appendUpdate( $updates, 'ss_total_views', $this->mViews ); + $this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits ); + $this->appendUpdate( $updates, 'ss_good_articles', $this->mGood ); + + if ( isset( $row->ss_total_pages ) ) { + # Update schema if required + if ( $row->ss_total_pages == -1 && !$this->mViews ) { + $dbr =& wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') ); + extract( $dbr->tableNames( 'page', 'user' ) ); + + $sql = "SELECT COUNT(page_namespace) AS total FROM $page"; + $res = $dbr->query( $sql, $fname ); + $pageRow = $dbr->fetchObject( $res ); + $pages = $pageRow->total + $this->mPages; + + $sql = "SELECT COUNT(user_id) AS total FROM $user"; + $res = $dbr->query( $sql, $fname ); + $userRow = $dbr->fetchObject( $res ); + $users = $userRow->total + $this->mUsers; + + if ( $updates ) { + $updates .= ','; + } + $updates .= "ss_total_pages=$pages, ss_users=$users"; + } else { + $this->appendUpdate( $updates, 'ss_total_pages', $this->mPages ); + $this->appendUpdate( $updates, 'ss_users', $this->mUsers ); + } + } + if ( $updates ) { + $site_stats = $dbw->tableName( 'site_stats' ); + $sql = $dbw->limitResultForUpdate("UPDATE $site_stats SET $updates", 1); + $dbw->query( $sql, $fname ); + } + } +} ?>