We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 4f9c3b50 authored by Brenda Wallace's avatar Brenda Wallace

install.php works for postgres

parent 343e2010
......@@ -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;
}
}
......
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