X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=install.php;h=1826a8494bc18b9f575efb54ab3647f5d8f890eb;hb=6d60d74093005992701418edda5be4422e46262f;hp=9f48c919de3c0642b0d4c57e8ed6636fa2874dc1;hpb=343e2010ae276fa4ca5e56c40eb6f06cd01a6136;p=quix0rs-gnu-social.git
diff --git a/install.php b/install.php
index 9f48c919de..1826a8494b 100644
--- a/install.php
+++ b/install.php
@@ -43,8 +43,8 @@ function checkPrereqs()
$pass = false;
}
- if (version_compare(PHP_VERSION, '5.0.0', '<')) {
- ?>
Require PHP version 5 or greater.
Require PHP version 5.2.3 or greater.
Cannot write avatar directory: /avatar/
- On your server, try this command: chmod a+w /avatar/
-
- $pass = false;
- }
- if (!is_writable(INSTALLDIR.'/background/')) {
- ?>Cannot write background directory: /background/
- On your server, try this command: chmod a+w /background/
-
- $pass = false;
+ // Check the subdirs used for file uploads
+ $fileSubdirs = array('avatar', 'background', 'file');
+ foreach ($fileSubdirs as $fileSubdir) {
+ $fileFullPath = INSTALLDIR."/$fileSubdir/";
+ if (!is_writable($fileFullPath)) {
+ ?>Cannot write directory:
+ On your server, try this command: chmod a+w
+
- >
+ >
- Page notice
@@ -220,20 +222,42 @@ function handlePost()
}
switch($dbtype) {
- case 'mysql': mysql_db_installer($host, $database, $username, $password, $sitename);
- break;
- case 'pgsql': pgsql_db_installer($host, $database, $username, $password, $sitename);
- 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;
}
- if ($path) $path .= '/';
- updateStatus("You can visit your new Laconica site.");
+
+ updateStatus("Writing config file...");
+ $res = writeConf($sitename, $server, $path, $fancy, $db);
+
+ if (!$res) {
+ updateStatus("Can't write config file.", true);
+ showForm();
+ return;
+ }
+
+ /*
+ 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.");
?>
server_encoding != 'UTF8') {
+ updateStatus("Laconica requires UTF8 character encoding. Your database is ". htmlentities($record->server_encoding));
+ showForm();
+ return false;
+ }
+
+ 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 false;
+ }
+ 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 false;
+ }
+ }
+ pg_query($conn, 'COMMIT');
+ if (empty($password)) {
+ $sqlUrl = "pgsql://$username@$host/$database";
+ }
+ else {
+ $sqlUrl = "pgsql://$username:$password@$host/$database";
+ }
+
+ $db = array('type' => 'pgsql', 'database' => $sqlUrl);
+
+ return $db;
}
-function mysql_db_installer($host, $database, $username, $password, $sitename) {
+function mysql_db_installer($host, $database, $username, $password) {
updateStatus("Starting installation...");
updateStatus("Checking database...");
@@ -254,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',
@@ -279,33 +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)
+ $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)
+function runDbScript($filename, $conn, $type = 'mysql')
{
$sql = trim(file_get_contents($filename));
$stmts = explode(';', $sql);
@@ -314,8 +397,18 @@ function runDbScript($filename, $conn)
if (!mb_strlen($stmt)) {
continue;
}
- $res = mysql_query($stmt, $conn);
+ 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");
return $res;
}
}