summaryrefslogtreecommitdiffstats
path: root/apis/update.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-09-15 17:26:26 +0200
committerSimon Rettberg2014-09-15 17:26:26 +0200
commit825e994444fcdb73d62710d0d934e93a227bd30f (patch)
tree4fdf795389ebc9f554b65a89dd8bee1faa1f3c5a /apis/update.inc.php
parent[news-API] tag content as 'content' instead of 'info' (diff)
downloadslx-admin-825e994444fcdb73d62710d0d934e93a227bd30f.tar.gz
slx-admin-825e994444fcdb73d62710d0d934e93a227bd30f.tar.xz
slx-admin-825e994444fcdb73d62710d0d934e93a227bd30f.zip
Added eventlog class, improved db-update machanism.
A warning will be shown in the main menu bar if the database schema needs to be updated.
Diffstat (limited to 'apis/update.inc.php')
-rw-r--r--apis/update.inc.php105
1 files changed, 74 insertions, 31 deletions
diff --git a/apis/update.inc.php b/apis/update.inc.php
index 3c4acfb2..3c8984b6 100644
--- a/apis/update.inc.php
+++ b/apis/update.inc.php
@@ -1,6 +1,6 @@
<?php
-$targetVersion = 4;
+$targetVersion = Database::getExpectedSchemaVersion();
// #######################
@@ -11,27 +11,31 @@ $currentVersion = (int) ($res === false ? 1 : $res['value']);
if ($currentVersion >= $targetVersion)
die('Up to date :-)');
-$function = 'update_' . $currentVersion;
+while ($currentVersion < $targetVersion) {
-if (!function_exists($function))
- die("Don't know how to update from version $currentVersion to $targetVersion :-(");
+ $function = 'update_' . $currentVersion;
-if (!$function())
- die("Update from $currentVersion to $targetVersion failed! :-(");
+ if (!function_exists($function))
+ die("Don't know how to update from version $currentVersion to $targetVersion :-(");
-$currentVersion++;
+ if (!$function())
+ die("Update from $currentVersion to $targetVersion failed! :-(");
-$ret = Database::exec("INSERT INTO property (name, value) VALUES ('webif-version', :version) ON DUPLICATE KEY UPDATE value = VALUES(value)", array('version' => $currentVersion), false);
-if ($ret === false)
- die('Writing version information back to DB failed. Next update will probably break.');
+ $currentVersion++;
-if ($currentVersion < $targetVersion) {
- Header('Location: api.php?do=update&random=' . mt_rand());
- die("Updated to $currentVersion - press F5 to continue");
+ $ret = Database::exec("INSERT INTO property (name, value) VALUES ('webif-version', :version) ON DUPLICATE KEY UPDATE value = VALUES(value)", array('version' => $currentVersion), false);
+ if ($ret === false)
+ die('Writing version information back to DB failed. Next update will probably break.');
+
+ if ($currentVersion < $targetVersion) {
+ echo("Updated to $currentVersion...\n");
+ }
}
-die("Updated to $currentVersion");
+Message::addSuccess('db-update-done');
+Util::redirect('index.php?do=Main');
+// The update functions. Number at the end refers to current version, the function will update to the next version
// #######################
// ##### 2014-05-28
// Add dateline field to property table
@@ -91,29 +95,68 @@ function update_3()
{
$res = Database::simpleQuery("DESCRIBE setting", array(), false);
if ($res !== false) {
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- switch ($row['Field']) {
- case 'de':
- case 'en':
- case 'pt':
- case 'description':
- Database::exec("ALTER TABLE setting DROP {$row['Field']}");
- break;
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ switch ($row['Field']) {
+ case 'de':
+ case 'en':
+ case 'pt':
+ case 'description':
+ Database::exec("ALTER TABLE setting DROP {$row['Field']}");
+ break;
+ }
}
}
- }
$res = Database::simpleQuery("DESCRIBE cat_setting", array(), false);
if ($res !== false) {
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- switch ($row['Field']) {
- case 'de':
- case 'en':
- case 'pt':
- case 'name':
- Database::exec("ALTER TABLE cat_setting DROP {$row['Field']}");
- break;
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ switch ($row['Field']) {
+ case 'de':
+ case 'en':
+ case 'pt':
+ case 'name':
+ Database::exec("ALTER TABLE cat_setting DROP {$row['Field']}");
+ break;
+ }
}
}
+ return true;
+}
+
+// #######################
+// ##### 2014-08-18
+// Remove description column from permission table, add eventlog table
+function update_4()
+{
+ $res = Database::simpleQuery("DESCRIBE permission", array(), false);
+ if ($res !== false) {
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ switch ($row['Field']) {
+ case 'description':
+ Database::exec("ALTER TABLE permission DROP {$row['Field']}");
+ break;
+ }
+ }
+ }
+ $res = Database::simpleQuery("show tables", array(), false);
+ $found = false;
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ if ($row['Tables_in_openslx'] !== 'eventlog')
+ continue;
+ $found = true;
+ break;
+ }
+ if ($found === false) {
+ // create table
+ Database::exec("CREATE TABLE `eventlog` (
+ `logid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `dateline` int(10) unsigned NOT NULL,
+ `logtypeid` varchar(30) NOT NULL,
+ `description` varchar(255) NOT NULL,
+ PRIMARY KEY (`logid`),
+ KEY `dateline` (`dateline`),
+ KEY `logtypeid` (`logtypeid`,`dateline`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ ");
}
return true;
}