Jack Phoenix has submitted this change and it was merged.

Change subject: PostgreSQL support for VoteNY
......................................................................


PostgreSQL support for VoteNY

Use integer value for votes to count averages.

Initial contributor: Sebastian Fiedler <[email protected]>

Bug: 51441

Change-Id: I9c09b84d3652449d3328586332c636a7a676273a
---
M Vote.js
M VoteClass.php
M VoteHooks.php
R vote.mysql
A vote.postgres
5 files changed, 37 insertions(+), 10 deletions(-)

Approvals:
  Jack Phoenix: Verified; Looks good to me, approved



diff --git a/Vote.js b/Vote.js
index f1ca0bb..021e398 100644
--- a/Vote.js
+++ b/Vote.js
@@ -165,4 +165,4 @@
                        jQuery( this ).data( 'vote-id' )
                );
        } );
-} );
\ No newline at end of file
+} );
diff --git a/VoteClass.php b/VoteClass.php
index 60e4e7f..250c7c3 100644
--- a/VoteClass.php
+++ b/VoteClass.php
@@ -45,13 +45,13 @@
                        $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 @@
                        $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 @@
         */
        function delete() {
                $dbw = wfGetDB( DB_MASTER );
+               $dbw->begin();
                $dbw->delete(
                        'Vote',
                        array(
@@ -149,6 +150,7 @@
                $voteDate = date( 'Y-m-d H:i:s' );
                wfRestoreWarnings();
                if( $this->UserAlreadyVoted() == false ) {
+                       $dbw->begin();
                        $dbw->insert(
                                'Vote',
                                array(
@@ -276,7 +278,7 @@
                $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>';
                }
diff --git a/VoteHooks.php b/VoteHooks.php
index eb69ae6..f028b57 100644
--- a/VoteHooks.php
+++ b/VoteHooks.php
@@ -149,9 +149,13 @@
         * @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;
        }
-}
\ No newline at end of file
+}
diff --git a/vote.sql b/vote.mysql
similarity index 100%
rename from vote.sql
rename to vote.mysql
diff --git a/vote.postgres b/vote.postgres
new file mode 100644
index 0000000..81f397f
--- /dev/null
+++ b/vote.postgres
@@ -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);

-- 
To view, visit https://gerrit.wikimedia.org/r/98353
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9c09b84d3652449d3328586332c636a7a676273a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VoteNY
Gerrit-Branch: master
Gerrit-Owner: saper <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Cook879 <[email protected]>
Gerrit-Reviewer: Isarra <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Lewis Cawte <[email protected]>
Gerrit-Reviewer: saper <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to