summaryrefslogtreecommitdiffstats
path: root/install.php
diff options
context:
space:
mode:
Diffstat (limited to 'install.php')
-rw-r--r--install.php68
1 files changed, 66 insertions, 2 deletions
diff --git a/install.php b/install.php
index 7937ec38..a5d18f0c 100644
--- a/install.php
+++ b/install.php
@@ -99,7 +99,7 @@ function tableRename($old, $new) {
* @param string $refColumn referenced column
* @return false|string[] list of constraints matching the request, false on error
*/
-function tableGetContraints($table, $column, $refTable, $refColumn)
+function tableGetConstraints($table, $column, $refTable, $refColumn)
{
$db = 'openslx';
if (defined('CONFIG_SQL_DB')) {
@@ -120,6 +120,51 @@ function tableGetContraints($table, $column, $refTable, $refColumn)
}
/**
+ * Because I'm stupid and can't type properly.
+ */
+function tableGetContraints($table, $column, $refTable, $refColumn)
+{
+ return tableGetConstraints($table, $column, $refTable, $refColumn);
+}
+
+/**
+ * Add constraint to table if it doesn't exist already.
+ * On failure, trigger finalResponse with error message.
+ *
+ * @param string $table table to add constraint to
+ * @param string $column foreign key column of that table
+ * @param string $refTable destination table
+ * @param string $refColumn primary key column in destination table
+ * @param string $actions "ON xxx ON yyy" string
+ * @return string UPDATE_* result code
+ */
+function tableAddConstraint($table, $column, $refTable, $refColumn, $actions)
+{
+ $test = tableExists($refTable) && tableHasColumn($refTable, $refColumn);
+ if ($test === false) {
+ // Most likely, destination table does not exist yet or isn't up to date
+ return UPDATE_RETRY;
+ }
+ $test = tableGetConstraints($table, $column, $refTable, $refColumn);
+ if ($test === false) {
+ // Should never happen!?
+ finalResponse(UPDATE_FAILED, 'DB: Cannot query constraints: ' . Database::lastError());
+ }
+ if (!empty($test)) {
+ // Already exists
+ return UPDATE_NOOP;
+ }
+ // Need to create
+ $ret = Database::exec("ALTER TABLE `$table` ADD CONSTRAINT FOREIGN KEY (`$column`)
+ REFERENCES `$refTable` (`$refColumn`)
+ $actions");
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'DB: Cannot add constraint: ' . Database::lastError());
+ }
+ return UPDATE_DONE;
+}
+
+/**
* Drop constraint from a table.
*
* @param string $table table name
@@ -146,6 +191,22 @@ function tableCreate($table, $structure, $fatalOnError = true)
return UPDATE_FAILED;
}
+function responseFromArray($array)
+{
+ if (in_array(UPDATE_FAILED, $array)) {
+ finalResponse(UPDATE_FAILED, 'Update failed!');
+ }
+ if (in_array(UPDATE_RETRY, $array)) {
+ finalResponse(UPDATE_RETRY, 'Temporary failure, will try again.');
+ }
+ if (in_array(UPDATE_DONE, $array)) {
+ finalResponse(UPDATE_DONE, 'Tables created/updated successfully');
+ }
+
+ finalResponse(UPDATE_NOOP, 'Everything already up to date');
+
+}
+
/*
* Rest of install script....
*/
@@ -282,6 +343,9 @@ if (DIRECT_MODE) {
</head>
<body>
<h1>Modules</h1>
+ <button onclick="slxRunInstall()" class="install-btn">Install/Upgrade</button>
+ <br>
+ <br>
<table>
<tr><th>Module</th><th>Status</th></tr>
HERE;
@@ -292,7 +356,7 @@ HERE;
echo <<<HERE
</table>
<br><br>
- <button onclick="slxRunInstall(this)">Install/Upgrade</button>
+ <button onclick="slxRunInstall()" class="install-btn">Install/Upgrade</button>
<script src="script/jquery.js"></script>
<script src="script/install.js"></script>
</body>