summaryrefslogtreecommitdiff
path: root/install.php
diff options
context:
space:
mode:
authorBrenda Wallace <shiny@cpan.org>2009-06-23 18:01:03 +1200
committerBrenda Wallace <shiny@cpan.org>2009-07-15 18:46:34 +1200
commit4f9c3b50e7103498f06f7c9b0a232bcda5bf17b8 (patch)
treedb6b743042dcc0ff9ce4237c3c29b2484bfa4d5b /install.php
parent343e2010ae276fa4ca5e56c40eb6f06cd01a6136 (diff)
install.php works for postgres
Diffstat (limited to 'install.php')
-rw-r--r--install.php48
1 files changed, 46 insertions, 2 deletions
diff --git a/install.php b/install.php
index 9f48c919d..1b8b7655c 100644
--- a/install.php
+++ b/install.php
@@ -244,6 +244,45 @@ function pgsql_db_installer($host, $database, $username, $password, $sitename) {
updateStatus("Checking database...");
$conn = pg_connect($connstring);
+ updateStatus("Running database script...");
+ //wrap in transaction;
+ pg_query($conn, 'BEGIN');
+ $res = runDbScript(INSTALLDIR.'/db/laconica_pg.sql', $conn, 'pgsql');
+
+ if ($res === false) {
+ updateStatus("Can't run database script.", true);
+ showForm();
+ return;
+ }
+ foreach (array('sms_carrier' => 'SMS carrier',
+ 'notice_source' => 'notice source',
+ 'foreign_services' => 'foreign service')
+ as $scr => $name) {
+ updateStatus(sprintf("Adding %s data to database...", $name));
+ $res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn, 'pgsql');
+ if ($res === false) {
+ updateStatus(sprintf("Can't run %d script.", $name), true);
+ showForm();
+ return;
+ }
+ }
+ pg_query($conn, 'COMMIT');
+
+ updateStatus("Writing config file...");
+ if (empty($password)) {
+ $sqlUrl = "pgsql://$username@$host/$database";
+ }
+ else {
+ $sqlUrl = "pgsql://$username:$password@$host/$database";
+ }
+ $res = writeConf($sitename, $sqlUrl, $fancy);
+ if (!$res) {
+ updateStatus("Can't write config file.", true);
+ showForm();
+ return;
+ }
+ updateStatus("Done!");
+
}
function mysql_db_installer($host, $database, $username, $password, $sitename) {
@@ -305,7 +344,7 @@ function writeConf($sitename, $sqlUrl, $fancy)
return $res;
}
-function runDbScript($filename, $conn)
+function runDbScript($filename, $conn, $type='mysql')
{
$sql = trim(file_get_contents($filename));
$stmts = explode(';', $sql);
@@ -314,8 +353,13 @@ function runDbScript($filename, $conn)
if (!mb_strlen($stmt)) {
continue;
}
- $res = mysql_query($stmt, $conn);
+ if ($type == 'mysql') {
+ $res = mysql_query($stmt, $conn);
+ } elseif ($type=='pgsql') {
+ $res = pg_query($conn, $stmt);
+ }
if ($res === false) {
+ updateStatus("FAILED SQL: $stmt");
return $res;
}
}