mirror of
https://bitbucket.org/vertlach/voteny.git
synced 2024-04-29 11:19:18 +03:00
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:
parent
c0269be5b3
commit
5daeba21b7
2
Vote.js
2
Vote.js
|
@ -165,4 +165,4 @@ jQuery( document ).ready( function() {
|
||||||
jQuery( this ).data( 'vote-id' )
|
jQuery( this ).data( 'vote-id' )
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -45,13 +45,13 @@ class Vote {
|
||||||
$vote_count = 0;
|
$vote_count = 0;
|
||||||
$res = $dbr->select(
|
$res = $dbr->select(
|
||||||
'Vote',
|
'Vote',
|
||||||
'COUNT(*) AS VoteCount',
|
'COUNT(*) AS votecount',
|
||||||
array( 'vote_page_id' => $this->PageID ),
|
array( 'vote_page_id' => $this->PageID ),
|
||||||
__METHOD__
|
__METHOD__
|
||||||
);
|
);
|
||||||
$row = $dbr->fetchObject( $res );
|
$row = $dbr->fetchObject( $res );
|
||||||
if( $row ) {
|
if( $row ) {
|
||||||
$vote_count = $row->VoteCount;
|
$vote_count = $row->votecount;
|
||||||
}
|
}
|
||||||
$wgMemc->set( $key, $vote_count );
|
$wgMemc->set( $key, $vote_count );
|
||||||
}
|
}
|
||||||
|
@ -76,13 +76,13 @@ class Vote {
|
||||||
$dbr = wfGetDB( DB_SLAVE );
|
$dbr = wfGetDB( DB_SLAVE );
|
||||||
$res = $dbr->select(
|
$res = $dbr->select(
|
||||||
'Vote',
|
'Vote',
|
||||||
'AVG(vote_value) AS VoteAvg',
|
'AVG(vote_value) AS voteavg',
|
||||||
array( 'vote_page_id' => $this->PageID ),
|
array( 'vote_page_id' => $this->PageID ),
|
||||||
__METHOD__
|
__METHOD__
|
||||||
);
|
);
|
||||||
$row = $dbr->fetchObject( $res );
|
$row = $dbr->fetchObject( $res );
|
||||||
if( $row ) {
|
if( $row ) {
|
||||||
$voteAvg = $row->VoteAvg;
|
$voteAvg = $row->voteavg;
|
||||||
}
|
}
|
||||||
$wgMemc->set( $key, $voteAvg );
|
$wgMemc->set( $key, $voteAvg );
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ class Vote {
|
||||||
*/
|
*/
|
||||||
function delete() {
|
function delete() {
|
||||||
$dbw = wfGetDB( DB_MASTER );
|
$dbw = wfGetDB( DB_MASTER );
|
||||||
|
$dbw->begin();
|
||||||
$dbw->delete(
|
$dbw->delete(
|
||||||
'Vote',
|
'Vote',
|
||||||
array(
|
array(
|
||||||
|
@ -149,6 +150,7 @@ class Vote {
|
||||||
$voteDate = date( 'Y-m-d H:i:s' );
|
$voteDate = date( 'Y-m-d H:i:s' );
|
||||||
wfRestoreWarnings();
|
wfRestoreWarnings();
|
||||||
if( $this->UserAlreadyVoted() == false ) {
|
if( $this->UserAlreadyVoted() == false ) {
|
||||||
|
$dbw->begin();
|
||||||
$dbw->insert(
|
$dbw->insert(
|
||||||
'Vote',
|
'Vote',
|
||||||
array(
|
array(
|
||||||
|
@ -276,7 +278,7 @@ class VoteStars extends Vote {
|
||||||
$output .= '<div class="rating-section">';
|
$output .= '<div class="rating-section">';
|
||||||
$output .= $this->displayStars( $id, $display_stars_rating, $voted );
|
$output .= $this->displayStars( $id, $display_stars_rating, $voted );
|
||||||
$count = $this->count();
|
$count = $this->count();
|
||||||
if( $count ) {
|
if( isset( $count ) ) {
|
||||||
$output .= ' <span class="rating-total">(' .
|
$output .= ' <span class="rating-total">(' .
|
||||||
wfMsgExt( 'voteny-votes', 'parsemag', $count ) . ')</span>';
|
wfMsgExt( 'voteny-votes', 'parsemag', $count ) . ')</span>';
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,9 +149,13 @@ class VoteHooks {
|
||||||
* @return Boolean: true
|
* @return Boolean: true
|
||||||
*/
|
*/
|
||||||
public static function addTable( $updater ) {
|
public static function addTable( $updater ) {
|
||||||
$dir = dirname( __FILE__ );
|
$dbt = $updater->getDB()->getType();
|
||||||
$file = "$dir/vote.sql";
|
$file = dirname( __FILE__ ) . "/vote.$dbt";
|
||||||
$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
|
if ( file_exists( $file ) ) {
|
||||||
|
$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
|
||||||
|
} else {
|
||||||
|
throw new MWException("VoteNY does not support $dbt.");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
vote.postgres
Normal file
21
vote.postgres
Normal 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);
|
Loading…
Reference in a new issue