From ffffab643e031524b6fdfe0c39adae1f6c8e9c4d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 8 Jun 2016 18:33:30 +0200 Subject: [install] Implement install scripts for most modules --- install.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'install.php') diff --git a/install.php b/install.php index e579dd52..f3469abc 100644 --- a/install.php +++ b/install.php @@ -33,7 +33,7 @@ function finalResponse($status, $message = '') echo json_encode(array('status' => $status, 'message' => $message)); } else { echo 'STATUS=', $status, "\n"; - echo 'MESSAGE=', $message; + echo 'MESSAGE=', str_replace("\n", " -- ", $message); } exit; } @@ -77,13 +77,28 @@ function tableDropColumn($table, $column) function tableExists($table) { $res = Database::simpleQuery("SHOW TABLES", array(), true); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ($row['Tables_in_openslx'] === $table) + while ($row = $res->fetch(PDO::FETCH_NUM)) { + if ($row[0] === $table) return true; } return false; } +function tableCreate($table, $structure, $fatalOnError = true) +{ + if (tableExists($table)) { + return UPDATE_NOOP; + } + $ret = Database::exec("CREATE TABLE IF NOT EXISTS `{$table}` ( {$structure} ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + if ($ret !== false) { + return UPDATE_DONE; + } + if ($fatalOnError) { + finalResponse(UPDATE_FAILED, 'DB-Error: ' . Database::lastError()); + } + return UPDATE_FAILED; +} + /* * Rest of install script.... */ @@ -230,7 +245,7 @@ HERE; echo <<

- + -- cgit v1.2.3-55-g7522