X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=install.php;h=9bcee275f1973b04b55ffdde02788613fb251210;hb=7d33478e867cc6610aded42a8f2fa71bae46804d;hp=133f2b30f68843220461fb7fcefd52c01cf738f9;hpb=adfb79a9bbdfb43f35c0f022c1de6118b10ce115;p=quix0rs-gnu-social.git
diff --git a/install.php b/install.php
index 133f2b30f6..9bcee275f1 100644
--- a/install.php
+++ b/install.php
@@ -1,7 +1,7 @@
Config file "config.php" already exists.
Require PHP version 5 or greater.
Require PHP version 5.2.3 or greater.
Cannot find mysql or pgsql extension. You need one or the other:
Cannot write config file to:
@@ -66,11 +70,16 @@ function checkPrereqs()
$pass = false;
}
- if (!is_writable(INSTALLDIR.'/avatar/')) {
- ?>Cannot write avatar directory: /avatar/
- On your server, try this command: chmod a+w /avatar/
-
- $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
+
@@ -116,18 +124,21 @@ function showForm()
disable
Enable fancy (pretty) URLs. Auto-detection failed, it depends on Javascript.
-
-
-
- Site path, following the "/" after the domain name in the URL. Empty is fine. Field should be filled automatically.
-
Database hostname
-
+
+
+ MySQL
+ PostgreSQL
+ Database type
+
+
+
+
Database name
@@ -139,7 +150,7 @@ function showForm()
- Database password
+ Database password (optional)
@@ -152,7 +163,7 @@ E_O_T;
function updateStatus($status, $error=false)
{
?>
- >
+ >
- Page notice
@@ -176,7 +190,7 @@ function handlePost()
'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);
- if ($res === false) {
- updateStatus(sprintf("Can't run %d script.", $name), true);
- showForm();
- return;
- }
+
+ if (!$db) {
+ // database connection failed, do not move on to create config file.
+ return false;
}
+
updateStatus("Writing config file...");
- $sqlUrl = "mysqli://$username:$password@$host/$database";
- $res = writeConf($sitename, $sqlUrl, $fancy, $path);
+ $res = writeConf($sitename, $server, $path, $fancy, $db);
+
if (!$res) {
updateStatus("Can't write config file.", true);
showForm();
return;
}
- updateStatus("Done!");
- 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.");
?>
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) {
+ updateStatus("Starting installation...");
+ updateStatus("Checking database...");
+
+ $conn = mysql_connect($host, $username, $password);
+ if (!$conn) {
+ updateStatus("Can't connect to server '$host' as '$username'.", true);
+ showForm();
+ return false;
+ }
+ updateStatus("Changing to database...");
+ $res = mysql_select_db($database, $conn);
+ if (!$res) {
+ updateStatus("Can't change to database.", true);
+ showForm();
+ 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 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);
+ if ($res === false) {
+ updateStatus(sprintf("Can't run %d script.", $name), true);
+ showForm();
+ return false;
+ }
+ }
+
+ $sqlUrl = "mysqli://$username:$password@$host/$database";
+ $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);
@@ -279,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;
}
}
@@ -289,9 +417,7 @@ function runDbScript($filename, $conn)
?>
xml version="1.0" encoding="UTF-8" "; ?>
-
+
Install Laconica