X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=install.php;h=901e502f1a2e45ca347db2292dd41006634e848d;hb=a5f78449b1d1f6a517727388cfbd350914d66b6e;hp=8f500259ef442bf57ec5d7f79f0803464fd91328;hpb=8894f957cdd7dc790d9413cfbef28cc4dc1655db;p=quix0rs-gnu-social.git diff --git a/install.php b/install.php index 8f500259ef..901e502f1a 100644 --- a/install.php +++ b/install.php @@ -48,7 +48,7 @@ function checkPrereqs() $pass = false; } - $reqs = array('gd', 'mysql', 'curl', + $reqs = array('gd', 'curl', 'xmlwriter', 'mbstring', 'gettext'); @@ -58,6 +58,10 @@ function checkPrereqs() $pass = false; } } + if (!checkExtension('pgsql') && !checkExtension('mysql')) { + ?>

Cannot find mysql or pgsql extension. You need one or the other:

Cannot write config file to:

@@ -66,17 +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/

-

Cannot write background directory: /background/

-

On your server, try this command: chmod a+w /background/

-

Cannot write directory:

+

On your server, try this command: chmod a+w

+ Database hostname

  • - + + + MySQL
    + PostgreSQL
    +

    Database type

    +
  • + +
  • +

    Database name

  • @@ -139,7 +150,7 @@ function showForm()
  • -

    Database password

    +

    Database password (optional)

  • @@ -163,6 +174,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); + if($fail){ showForm(); - return; - } - } - 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!"); + + 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: + } if ($path) $path .= '/'; updateStatus("You can visit your new Laconica site."); ?> @@ -256,7 +232,120 @@ function handlePost() 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; + } + 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, 'pgsql'); + if (!$res) { + updateStatus("Can't write config file.", true); + showForm(); + return; + } + updateStatus("Done!"); + +} + +function mysql_db_installer($host, $database, $username, $password, $sitename) { + 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; + } + updateStatus("Changing to database..."); + $res = mysql_select_db($database, $conn); + if (!$res) { + updateStatus("Can't change to database.", true); + showForm(); + return; + } + updateStatus("Running database script..."); + $res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn); + 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); + if ($res === false) { + updateStatus(sprintf("Can't run %d script.", $name), true); + showForm(); + return; + } + } + + 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') { $res = file_put_contents(INSTALLDIR.'/config.php', ""); return $res; } -function runDbScript($filename, $conn) +function runDbScript($filename, $conn, $type='mysql') { $sql = trim(file_get_contents($filename)); $stmts = explode(';', $sql); @@ -277,8 +368,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; } }