PostgreSQL support for VoteNY

Use integer value for votes to count averages.

Initial contributor: Sebastian Fiedler <basti@unix-solution.de>

Bug: 51441

Change-Id: I9c09b84d3652449d3328586332c636a7a676273a
This commit is contained in:
saper 2013-12-01 00:19:47 +01:00
parent c0269be5b3
commit 5daeba21b7
5 changed files with 37 additions and 10 deletions

View File

@ -165,4 +165,4 @@ jQuery( document ).ready( function() {
jQuery( this ).data( 'vote-id' )
);
} );
} );
} );

View File

@ -45,13 +45,13 @@ class Vote {
$vote_count = 0;
$res = $dbr->select(
'Vote',
'COUNT(*) AS VoteCount',
'COUNT(*) AS votecount',
array( 'vote_page_id' => $this->PageID ),
__METHOD__
);
$row = $dbr->fetchObject( $res );
if( $row ) {
$vote_count = $row->VoteCount;
$vote_count = $row->votecount;
}
$wgMemc->set( $key, $vote_count );
}
@ -76,13 +76,13 @@ class Vote {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
'Vote',
'AVG(vote_value) AS VoteAvg',
'AVG(vote_value) AS voteavg',
array( 'vote_page_id' => $this->PageID ),
__METHOD__
);
$row = $dbr->fetchObject( $res );
if( $row ) {
$voteAvg = $row->VoteAvg;
$voteAvg = $row->voteavg;
}
$wgMemc->set( $key, $voteAvg );
}
@ -120,6 +120,7 @@ class Vote {
*/
function delete() {
$dbw = wfGetDB( DB_MASTER );
$dbw->begin();
$dbw->delete(
'Vote',
array(
@ -149,6 +150,7 @@ class Vote {
$voteDate = date( 'Y-m-d H:i:s' );
wfRestoreWarnings();
if( $this->UserAlreadyVoted() == false ) {
$dbw->begin();
$dbw->insert(
'Vote',
array(
@ -276,7 +278,7 @@ class VoteStars extends Vote {
$output .= '<div class="rating-section">';
$output .= $this->displayStars( $id, $display_stars_rating, $voted );
$count = $this->count();
if( $count ) {
if( isset( $count ) ) {
$output .= ' <span class="rating-total">(' .
wfMsgExt( 'voteny-votes', 'parsemag', $count ) . ')</span>';
}

View File

@ -149,9 +149,13 @@ class VoteHooks {
* @return Boolean: true
*/
public static function addTable( $updater ) {
$dir = dirname( __FILE__ );
$file = "$dir/vote.sql";
$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
$dbt = $updater->getDB()->getType();
$file = dirname( __FILE__ ) . "/vote.$dbt";
if ( file_exists( $file ) ) {
$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
} else {
throw new MWException("VoteNY does not support $dbt.");
}
return true;
}
}
}

21
vote.postgres Normal file
View File

@ -0,0 +1,21 @@
CREATE TABLE "Vote" (
-- Internal ID to identify between different vote tags on different pages
vote_id SERIAL NOT NULL PRIMARY KEY,
-- Username (if any) of the person who voted
username varchar(255) NOT NULL default '0',
-- User ID of the person who voted
vote_user_id integer NOT NULL default '0',
-- ID of the page where the vote tag is in
vote_page_id integer NOT NULL default '0',
-- Value of the vote (ranging from 1 to 5)
vote_value integer NOT NULL,
-- Timestamp when the vote was cast
vote_date timestamp without time zone NOT NULL,
-- IP address of the user who voted
vote_ip varchar(45) NOT NULL default ''
) /*$wgDBTableOptions*/;
CREATE INDEX vote_page_id_index ON "Vote" (vote_page_id);
CREATE INDEX valueidx ON "Vote" (vote_value);
CREATE INDEX usernameidx ON "Vote" (username);
CREATE INDEX vote_date ON "Vote" (vote_date);