Commit a7f67e01 authored by Dries's avatar Dries

- Patch #76681 by sammys: PostgreSQL support for install system. Woot! :)

parent 3ffb612a
<?php
// $Id$
// PostgreSQL specific install functions
/**
* Check if PostgreSQL is available.
*
* @return
* TRUE/FALSE
*/
function pgsql_is_available() {
return function_exists('pg_connect');
}
/**
* Check if we can connect to PostgreSQL.
*
* @return
* TRUE/FALSE
*/
function drupal_test_pgsql($url, &$success) {
if (!pgsql_is_available()) {
drupal_set_message('PHP PostgreSQL support not enabled.', 'error');
return FALSE;
}
$url = parse_url($url);
// Decode url-encoded information in the db connection string.
$url['user'] = urldecode($url['user']);
$url['pass'] = urldecode($url['pass']);
$url['host'] = urldecode($url['host']);
$url['path'] = urldecode($url['path']);
// Build pgsql connection string and allow for non-standard PostgreSQL port.
$conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
$conn_string .= isset($url['port']) ? ' port=' . $url['port'] : '';
// Test connecting to the database.
$connection = @pg_connect($conn_string);
if (!$connection) {
drupal_set_message(st('Failure to connect to your PostgreSQL database server. PostgreSQL reports the following message: %error.<ul><li>Are you sure you have the correct username and password?</li><li>Are you sure that you have typed the correct database hostname?</li><li>Are you sure that the database server is running?</li><li>Are you sure you typed the correct database name?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%error' => 'Connection failed. See log file for failure reason')), 'error');
return FALSE;
}
$success = array('CONNECT');
// Test CREATE.
$query = 'CREATE TABLE drupal_install_test (id integer NOT NULL)';
$result = pg_query($connection, $query);
if ($error = pg_result_error($result)) {
drupal_set_message(st('We were unable to create a test table on your PostgreSQL database server with the command %query. PostgreSQL reports the following message: %error.<ul><li>Are you sure the configured username has the necessary PostgreSQL permissions to create tables in the database?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%query' => $query, '%error' => $error)), 'error');
return FALSE;
}
$err = FALSE;
$success[] = 'SELECT';
$success[] = 'CREATE';
// Test INSERT.
$query = 'INSERT INTO drupal_install_test (id) VALUES (1)';
$result = pg_query($connection, $query);
if ($error = pg_result_error($result)) {
drupal_set_message(st('We were unable to insert a value into a test table on your PostgreSQL database server. We tried inserting a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
$err = TRUE;
}
else {
$success[] = 'INSERT';
}
// Test UPDATE.
$query = 'UPDATE drupal_install_test SET id = 2';
$result = pg_query($connection, $query);
if ($error = pg_result_error($result)) {
drupal_set_message(st('We were unable to update a value in a test table on your PostgreSQL database server. We tried updating a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
$err = TRUE;
}
else {
$success[] = 'UPDATE';
}
// Test LOCK.
$query = 'BEGIN; LOCK drupal_install_test IN SHARE ROW EXCLUSIVE MODE';
$result = pg_query($connection, $query);
if ($error = pg_result_error($result)) {
drupal_set_message(st('We were unable to lock a test table on your PostgreSQL database server. We tried locking a table with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
$err = TRUE;
}
else {
$success[] = 'LOCK';
}
// Test UNLOCK, which is done automatically upon transaction end in PostgreSQL
$query = 'COMMIT';
$result = pg_query($connection, $query);
if ($error = pg_result_error()) {
drupal_set_message(st('We were unable to unlock a test table on your PostgreSQL database server. We tried unlocking a table with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
$err = TRUE;
}
else {
$success[] = 'UNLOCK';
}
// Test DELETE.
$query = 'DELETE FROM drupal_install_test';
$result = pg_query($connection, $query);
if ($error = pg_result_error()) {
drupal_set_message(st('We were unable to delete a value from a test table on your PostgreSQL database server. We tried deleting a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
$err = TRUE;
}
else {
$success[] = 'DELETE';
}
// Test DROP.
$query = 'DROP TABLE drupal_install_test';
$result = pg_query($connection, $query);
if ($error = pg_result_error()) {
drupal_set_message(st('We were unable to drop a test table from your PostgreSQL database server. We tried dropping a table with the command %query and PostgreSQL reported the following error %error.', array('%query' => $query, '%error' => $error)), 'error');
$err = TRUE;
}
else {
$success[] = 'DROP';
}
if ($err) {
return FALSE;
}
pg_close($connection);
return TRUE;
}
?>
......@@ -55,6 +55,58 @@ function aggregator_install() {
PRIMARY KEY (iid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {aggregator_category} (
cid serial,
title varchar(255) NOT NULL default '',
description text NOT NULL,
block smallint NOT NULL default '0',
PRIMARY KEY (cid),
UNIQUE (title)
)");
db_query("CREATE TABLE {aggregator_category_feed} (
fid int NOT NULL default '0',
cid int NOT NULL default '0',
PRIMARY KEY (fid,cid)
)");
db_query("CREATE TABLE {aggregator_category_item} (
iid int NOT NULL default '0',
cid int NOT NULL default '0',
PRIMARY KEY (iid,cid)
)");
db_query("CREATE TABLE {aggregator_feed} (
fid serial,
title varchar(255) NOT NULL default '',
url varchar(255) NOT NULL default '',
refresh int NOT NULL default '0',
checked int NOT NULL default '0',
link varchar(255) NOT NULL default '',
description text NOT NULL,
image text NOT NULL,
etag varchar(255) NOT NULL default '',
modified int NOT NULL default '0',
block smallint NOT NULL default '0',
PRIMARY KEY (fid),
UNIQUE (url),
UNIQUE (title)
)");
db_query("CREATE TABLE {aggregator_item} (
iid serial,
fid int NOT NULL default '0',
title varchar(255) NOT NULL default '',
link varchar(255) NOT NULL default '',
author varchar(255) NOT NULL default '',
description text NOT NULL,
timestamp int default NULL,
guid varchar(255),
PRIMARY KEY (iid)
)");
break;
}
}
......@@ -14,5 +14,17 @@ function book_install() {
KEY nid (nid),
KEY parent (parent)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {book} (
vid uint NOT NULL default '0',
nid uint NOT NULL default '0',
parent int NOT NULL default '0',
weight smallint NOT NULL default '0',
PRIMARY KEY (vid)
)");
db_query("CREATE INDEX {book}_nid_idx ON {book} (nid)");
db_query("CREATE INDEX {book}_parent_idx ON {book} (parent)");
break;
}
}
\ No newline at end of file
}
......@@ -15,5 +15,18 @@ function contact_install() {
PRIMARY KEY (cid),
UNIQUE KEY category (category)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {contact} (
cid serial CHECK (cid >= 0),
category varchar(255) NOT NULL default '',
recipients text NOT NULL default '',
reply text NOT NULL default '',
weight smallint NOT NULL default '0',
selected smallint NOT NULL default '0',
PRIMARY KEY (cid),
UNIQUE (category)
)");
break;
}
}
\ No newline at end of file
}
......@@ -26,5 +26,29 @@ function drupal_install() {
type varchar(255) NOT NULL default '',
PRIMARY KEY (cid,name)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {client} (
cid serial CHECK (cid >= 0),
link varchar(255) NOT NULL default '',
name varchar(128) NOT NULL default '',
mail varchar(128) NOT NULL default '',
slogan text NOT NULL,
mission text NOT NULL,
users int NOT NULL default '0',
nodes int NOT NULL default '0',
version varchar(35) NOT NULL default'',
created int NOT NULL default '0',
changed int NOT NULL default '0',
PRIMARY KEY (cid)
)");
db_query("CREATE TABLE {client_system} (
cid int NOT NULL default '0',
name varchar(255) NOT NULL default '',
type varchar(255) NOT NULL default '',
PRIMARY KEY (cid,name)
)");
break;
}
}
\ No newline at end of file
}
......@@ -13,5 +13,16 @@ function forum_install() {
KEY nid (nid),
KEY tid (tid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {forum} (
nid uint NOT NULL default '0',
vid uint NOT NULL default '0',
tid uint NOT NULL default '0',
PRIMARY KEY (vid)
)");
db_query("CREATE INDEX {forum}_nid_idx ON {forum} (nid)");
db_query("CREATE INDEX {forum}_tid_idx ON {forum} (tid)");
break;
}
}
\ No newline at end of file
}
......@@ -33,6 +33,37 @@ function locale_install() {
KEY plid (plid),
KEY plural (plural)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {locales_meta} (
locale varchar(12) NOT NULL default '',
name varchar(64) NOT NULL default '',
enabled int NOT NULL default '0',
isdefault int NOT NULL default '0',
plurals int NOT NULL default '0',
formula varchar(128) NOT NULL default '',
PRIMARY KEY (locale)
)");
db_query("CREATE TABLE {locales_source} (
lid serial,
location varchar(255) NOT NULL default '',
source bytea NOT NULL,
PRIMARY KEY (lid)
)");
db_query("CREATE TABLE {locales_target} (
lid int NOT NULL default '0',
translation bytea NOT NULL,
locale varchar(12) NOT NULL default '',
plid int NOT NULL default '0',
plural int NOT NULL default '0'
)");
db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)");
db_query("CREATE INDEX {locales_target}_locale_idx ON {locales_target} (locale)");
db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)");
db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)");
break;
}
db_query("INSERT INTO {locales_meta} (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1')");
}
......@@ -31,5 +31,33 @@ function poll_install() {
PRIMARY KEY (chid),
KEY nid (nid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
case 'pgsql':
db_query("CREATE TABLE {poll} (
nid uint NOT NULL default '0',
runtime int NOT NULL default '0',
active uint NOT NULL default '0',
PRIMARY KEY (nid)
)");
db_query("CREATE TABLE {poll_votes} (
nid uint NOT NULL,
uid uint NOT NULL default 0,
chorder int NOT NULL default -1,
hostname varchar(128) NOT NULL default ''
)");
db_query("CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)");
db_query("CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)");
db_query("CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)");
db_query("CREATE TABLE {poll_choices} (
chid serial CHECK (chid >= 0),
nid uint NOT NULL default '0',
chtext varchar(128) NOT NULL default '',
chvotes int NOT NULL default '0',
chorder int NOT NULL default '0',
PRIMARY KEY (chid)
)");
db_query("CREATE INDEX {poll_choices}_nid_idx ON {poll_choices} (nid)");
break;
}
}
......@@ -31,5 +31,33 @@ function profile_install() {
KEY uid (uid),
KEY fid (fid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
case 'pgsql':
db_query("CREATE TABLE {profile_fields} (
fid serial,
title varchar(255) default NULL,
name varchar(128) default NULL,
explanation TEXT default NULL,
category varchar(255) default NULL,
page varchar(255) default NULL,
type varchar(128) default NULL,
weight smallint DEFAULT '0' NOT NULL,
required smallint DEFAULT '0' NOT NULL,
register smallint DEFAULT '0' NOT NULL,
visibility smallint DEFAULT '0' NOT NULL,
autocomplete smallint DEFAULT '0' NOT NULL,
options text,
UNIQUE (name),
PRIMARY KEY (fid)
)");
db_query("CREATE INDEX {profile_fields}_category_idx ON {profile_fields} (category)");
db_query("CREATE TABLE {profile_values} (
fid uint default '0',
uid uint default '0',
value text
)");
db_query("CREATE INDEX {profile_values}_uid_idx ON {profile_values} (uid)");
db_query("CREATE INDEX {profile_values}_fid_idx ON {profile_values} (fid)");
break;
}
}
\ No newline at end of file
}
......@@ -29,5 +29,32 @@ function search_install() {
count float default NULL,
PRIMARY KEY (word)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {search_dataset} (
sid uint NOT NULL default '0',
type varchar(16) default NULL,
data text NOT NULL
)");
db_query("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset} (sid, type)");
db_query("CREATE TABLE {search_index} (
word varchar(50) NOT NULL default '',
sid uint NOT NULL default '0',
type varchar(16) default NULL,
fromsid uint NOT NULL default '0',
fromtype varchar(16) default NULL,
score float default NULL
)");
db_query("CREATE INDEX {search_index}_sid_type_idx ON {search_index} (sid, type)");
db_query("CREATE INDEX {search_index}_from_sid_type_idx ON {search_index} (fromsid, fromtype)");
db_query("CREATE INDEX {search_index}_word_idx ON {search_index} (word)");
db_query("CREATE TABLE {search_total} (
word varchar(50) NOT NULL default '',
count float default NULL,
PRIMARY KEY (word)
)");
break;
}
}
\ No newline at end of file
}
......@@ -18,5 +18,21 @@ function statistics_install() {
KEY accesslog_timestamp (timestamp),
PRIMARY KEY (aid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {accesslog} (
aid serial,
sid varchar(32) NOT NULL default '',
title varchar(255) default NULL,
path varchar(255) default NULL,
url varchar(255) default NULL,
hostname varchar(128) default NULL,
uid uint default '0',
timer uint NOT NULL default '0',
timestamp uint NOT NULL default '0',
PRIMARY KEY (aid)
)");
db_query("CREATE INDEX {accesslog}_accesslog_timestamp_idx ON {accesslog} (timestamp)");
break;
}
}
\ No newline at end of file
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment