From: Brett Taylor Date: Fri, 7 Aug 2009 02:17:55 +0000 (+1200) Subject: install.php: improved support for running Laconica in a sub folder and on a non-stand... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=49eb6009a54e9fd5609cce1ba7cfc9d85edff8c0;p=quix0rs-gnu-social.git install.php: improved support for running Laconica in a sub folder and on a non-standard port, tidyed up configuration file generation, removing duplication from db functions, --- diff --git a/install.php b/install.php index ea21356518..f02a066638 100644 --- a/install.php +++ b/install.php @@ -180,6 +180,9 @@ function handlePost() $password = $_POST['password']; $sitename = $_POST['sitename']; $fancy = !empty($_POST['fancy']); + $server = $_SERVER['HTTP_HOST']; + $path = substr(dirname($_SERVER['PHP_SELF']), 1); + ?>
Page notice
@@ -219,20 +222,42 @@ function handlePost() } switch($dbtype) { - case 'mysql': mysql_db_installer($host, $database, $username, $password, $sitename, $fancy); - break; - case 'pgsql': pgsql_db_installer($host, $database, $username, $password, $sitename, $fancy); - break; - default: + case 'mysql': + $db = mysql_db_installer($host, $database, $username, $password); + break; + case 'pgsql': + $db = pgsql_db_installer($host, $database, $username, $password); + break; + default: + } + + if (!$db) { + // database connection failed, do not move on to create config file. + return false; + } + + updateStatus("Writing config file..."); + $res = writeConf($sitename, $server, $path, $fancy, $db); + + if (!$res) { + updateStatus("Can't write config file.", true); + showForm(); + return; } - if ($path) $path .= '/'; - updateStatus("You can visit your new Laconica site."); + + /* + TODO https needs to be considered + */ + $link = "http://".$server.'/'.$path; + + updateStatus("Laconica has been installed at $link"); + updateStatus("You can visit your new Laconica site."); ?> 'SMS carrier', 'notice_source' => 'notice source', @@ -276,29 +301,24 @@ function pgsql_db_installer($host, $database, $username, $password, $sitename, $ if ($res === false) { updateStatus(sprintf("Can't run %d script.", $name), true); showForm(); - return; + return false; } } 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, 'pgsql'); - if (!$res) { - updateStatus("Can't write config file.", true); - showForm(); - return; - } - updateStatus("Done!"); - + + $db = array('type' => 'pgsql', 'database' => $sqlUrl); + + return $db; } -function mysql_db_installer($host, $database, $username, $password, $sitename, $fancy) { +function mysql_db_installer($host, $database, $username, $password) { updateStatus("Starting installation..."); updateStatus("Checking database..."); @@ -306,21 +326,21 @@ function mysql_db_installer($host, $database, $username, $password, $sitename, $ if (!$conn) { updateStatus("Can't connect to server '$host' as '$username'.", true); showForm(); - return; + return false; } updateStatus("Changing to database..."); $res = mysql_select_db($database, $conn); if (!$res) { updateStatus("Can't change to database.", true); showForm(); - return; + return false; } updateStatus("Running database script..."); $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn); if ($res === false) { updateStatus("Can't run database script.", true); showForm(); - return; + return false; } foreach (array('sms_carrier' => 'SMS carrier', 'notice_source' => 'notice source', @@ -331,35 +351,44 @@ function mysql_db_installer($host, $database, $username, $password, $sitename, $ if ($res === false) { updateStatus(sprintf("Can't run %d script.", $name), true); showForm(); - return; + return false; } } - updateStatus("Writing config file..."); $sqlUrl = "mysqli://$username:$password@$host/$database"; - $res = writeConf($sitename, $sqlUrl, $fancy); - if (!$res) { - updateStatus("Can't write config file.", true); - showForm(); - return; - } - updateStatus("Done!"); - } -function writeConf($sitename, $sqlUrl, $fancy, $type='mysql') + $db = array('type' => 'mysql', 'database' => $sqlUrl); + return $db; +} + +function writeConf($sitename, $server, $path, $fancy, $db) { - $res = file_put_contents(INSTALLDIR.'/config.php', - ""); + // assemble configuration file in a string + $cfg = ""; + // write configuration file out to install directory + $res = file_put_contents(INSTALLDIR.'/config.php', $cfg); + return $res; } -function runDbScript($filename, $conn, $type='mysql') +function runDbScript($filename, $conn, $type = 'mysql') { $sql = trim(file_get_contents($filename)); $stmts = explode(';', $sql); @@ -368,10 +397,15 @@ function runDbScript($filename, $conn, $type='mysql') if (!mb_strlen($stmt)) { continue; } - if ($type == 'mysql') { - $res = mysql_query($stmt, $conn); - } elseif ($type=='pgsql') { - $res = pg_query($conn, $stmt); + switch ($type) { + case 'mysql': + $res = mysql_query($stmt, $conn); + break; + case 'pgsql': + $res = pg_query($conn, $stmt); + break; + default: + updateStatus("runDbScript() error: unknown database type ". $type ." provided."); } if ($res === false) { updateStatus("FAILED SQL: $stmt");