Last modified: 2014-09-07 20:59:00 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T53441, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 51441 - VoteNY not working with Postgresql.
VoteNY not working with Postgresql.
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
VoteNY (Other open bugs)
unspecified
All All
: Unprioritized normal (vote)
: ---
Assigned To: Jack Phoenix
:
Depends on:
Blocks: postgres
  Show dependency treegraph
 
Reported: 2013-07-16 14:18 UTC by basti
Modified: 2014-09-07 20:59 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
SQL file for Postgresql (1.20 KB, text/x-sql)
2013-11-29 22:48 UTC, basti
Details

Description basti 2013-07-16 14:18:53 UTC
VoteNY not working with Postgresql.
The vote.sql I have convert to pgsql, now it looks like

-- Postgres Version
-- author: basti

-- set Schemata
SET search_path = mediawiki;

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 char(1) NOT NULL default '',
  -- 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);

Next I try to create a BlogPost by calling Spezial:CreateBlogPost but this returns

SELECT vote_value FROM "Vote" WHERE vote_page_id = '0' AND username = 'Admin' LIMIT 1 

The " are too mutch, you can found the code in VoteClass.php line 182 ff.

Then I run 
SET search_path=mediawiki;
SELECT vote_value FROM Vote WHERE vote_page_id = '0' AND username = 'Admin' LIMIT 1 

in PgAdmin all works fine.

"SET search_path" is normally done by includes/db/DatabasePostgres.php

How can I fix this?
Regards,
Basti
Comment 1 basti 2013-07-16 20:40:15 UTC
I have found the error, but I don't know how to solve it.
There is a Problem with the Postgres "serach Path" in the plugin.

On the database site there is only one schema "mediawiki".
The $wgDBuser has the default schema "mediawiki" on server site.
(Use "SHOW search_path;" in SQL console to check this.)

$wgDBmwschema = "mediawiki"; and
$wgDBtype     = "postgres";  are also set in LocalSettings.php

The Wiki-DEBUG output say "Schema "mediawiki" already in the search path".

There is always the same Error on Database site:

SELECT COUNT(*) AS VoteCount FROM "Vote" WHERE vote_page_id = '0'

Postgres log:

FEHLER: Relation »Vote« existiert nicht LINE 1: ...Vote::count Admin */ COUNT(*) AS VoteCount FROM "Vote" WH... ^ “.
(in english: Relation »Vote« does not exist)

When i change in VoteNY/VoteClass.php it runs.

function UserAlreadyVoted() {
	$dbr = wfGetDB( DB_SLAVE );
	$s = $dbr->selectRow(
# Here add Postgres schema
		'mediawiki.vote',
		array( 'vote_value' ),
		array(
			'vote_page_id' => $this->PageID,
			'username' => $this->Username
 		),
		__METHOD__
	);
# Exit for debug 
	exit("UserAlreadyVoted() done");
 	
	if( $s === false ) {
		return false;
	} else {
		return $s->vote_value;
	}
}

I have done also some changes in VoteNY/Hooks.php 

public static function addTable( $updater ) {
	$dir = dirname( __FILE__ );
/** change to use Postgres **/
	$dbr = wfGetDB( DB_SLAVE );
	if ($dbr->getType() == "postgres") {
		$file = "$dir/vote.postgres.sql";
	} 
        else {
		$file = "$dir/vote.sql";
	}
	/** check if table exists, 
	    else the update.php won't run because Postgres exit with Error
	**/ 
	if (!$dbr->tableExists('vote')) {
		$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
	}
/** end of changes **/
	return true;
}

vote.postgres.sql

-- Postgres Version

-- set Schemata for debug, normally done by includes/db/DatabasePostgres.sql ?
SET search_path = mediawiki;

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 char(1) NOT NULL default '',
  -- 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);
--EOF

So it seems that includes/db/DatabasePostgres.sql isn't use by this Plugin or
something else is goning wrong that the database connection don't know anything about the schema.

Regards,
basti
Comment 2 Marcin Cieślak 2013-07-17 14:39:30 UTC
You need not normally to deal with PostgreSQL schema at all, it will be set automatically.

Isn't the problem because the table is called "Vote" (capital "V") and not "vote"? Can you change your sql to use

CREATE TABLE "Vote"

and not

CREATE TABLE vote

and see if it works?
Comment 3 basti 2013-11-29 22:48:25 UTC
Created attachment 13938 [details]
SQL file for Postgresql
Comment 4 Marcin Cieślak 2013-11-30 23:31:09 UTC
basti, unfortunately more changes are needed - avg() function for example does not work on characters in PostgreSQL.

I have pushed an improved patch (ready to include in the extension) to Gerrit.
Comment 5 Marcin Cieślak 2013-11-30 23:33:00 UTC
Gerrit change #98353 pushed and tested on both MySQL and PostgreSQL.
Comment 6 Jeff Janes 2014-09-07 20:52:29 UTC
This bug seems to be "resolved fixed".  Is there anything else to be done?
Comment 7 Andre Klapper 2014-09-07 20:59:00 UTC
Good catch. Setting status.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links