summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-09-15 17:26:26 +0200
committerSimon Rettberg2014-09-15 17:26:26 +0200
commit825e994444fcdb73d62710d0d934e93a227bd30f (patch)
tree4fdf795389ebc9f554b65a89dd8bee1faa1f3c5a
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.
-rw-r--r--apis/update.inc.php105
-rw-r--r--inc/database.inc.php14
-rw-r--r--inc/eventlog.inc.php15
-rw-r--r--inc/property.inc.php5
-rw-r--r--index.php6
-rw-r--r--lang/de/messages.json2
-rw-r--r--lang/en/messages.json6
-rw-r--r--lang/pt/messages.json3
-rw-r--r--style/default.css6
-rw-r--r--templates/main-menu-login.html3
-rw-r--r--templates/main-menu-logout.html3
11 files changed, 125 insertions, 43 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;
}
diff --git a/inc/database.inc.php b/inc/database.inc.php
index e7a16ba1..a729b7fc 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -9,6 +9,20 @@ class Database
private static $dbh = false;
private static $statements = array();
+
+ /**
+ * Get database schema version - used for checking for updates
+ * @return int Version of db schema
+ */
+ public static function getExpectedSchemaVersion()
+ {
+ return 5;
+ }
+
+ public static function needSchemaUpdate()
+ {
+ return Property::getCurrentSchemaVersion() < self::getExpectedSchemaVersion();
+ }
/**
* Connect to the DB if not already connected.
diff --git a/inc/eventlog.inc.php b/inc/eventlog.inc.php
new file mode 100644
index 00000000..0d7f6d4a
--- /dev/null
+++ b/inc/eventlog.inc.php
@@ -0,0 +1,15 @@
+<?php
+
+class EventLog
+{
+
+ public static function log($eventId, $message)
+ {
+ Database::exec("INSERT INTO eventlog (dateline, logtypeid, description)"
+ . " VALUES (UNIX_TIMESTAMP(), :eventid, :message)", array(
+ 'eventid' => $eventId,
+ 'message' => $message
+ ));
+ }
+
+}
diff --git a/inc/property.inc.php b/inc/property.inc.php
index 81de137f..605d901d 100644
--- a/inc/property.inc.php
+++ b/inc/property.inc.php
@@ -141,5 +141,10 @@ class Property
{
self::set('dl-' . $name, $taskId, 5);
}
+
+ public static function getCurrentSchemaVersion()
+ {
+ return self::get('webif-version');
+ }
}
diff --git a/index.php b/index.php
index 3b1effa6..919c4620 100644
--- a/index.php
+++ b/index.php
@@ -114,16 +114,18 @@ if (AJAX) {
Page::preprocess();
// Generate Main menu
-//$menu = new Menu;
+//$menu = new Menu;// TODO: Merge both templates again - having 99% copy&paste sucks...
if (User::getName() === false) {
Render::addTemplate('main-menu-login', array(
'url' => urlencode($_SERVER['REQUEST_URI']),
- 'langs' => Dictionary::getLanguages(true)
+ 'langs' => Dictionary::getLanguages(true),
+ 'dbupdate' => Database::needSchemaUpdate()
));
} else {
Render::addTemplate('main-menu-logout', array(
'url' => urlencode($_SERVER['REQUEST_URI']),
'langs' => Dictionary::getLanguages(true),
+ 'dbupdate' => Database::needSchemaUpdate(),
'user' => User::getName()
));
}
diff --git a/lang/de/messages.json b/lang/de/messages.json
index 9ffbc24e..0c9bd3d6 100644
--- a/lang/de/messages.json
+++ b/lang/de/messages.json
@@ -3,6 +3,7 @@
"adduser-success": "Benutzer erfolgreich hinzugef\u00fcgt",
"config-activated": "Konfiguration {{0}} wurde aktiviert",
"config-invalid": "Konfiguration mit ID {{0}} existiert nicht",
+ "db-update-done": "Datenbank wurde aktualisiert",
"debug-mode": "Der Debug-Modus ist aktiv!",
"deleted-tag": "Tag wurde entfernt",
"empty-archive": "Das Archiv enth\u00e4lt keine Dateien oder Verzeichnisse",
@@ -18,7 +19,6 @@
"invalid-action": "Ung\u00fcltige Aktion: {{0}}",
"invalid-file": "Die Datei {{0}} existiert nicht!",
"invalid-ip": "Kein Interface ist auf die Adresse {{0}} konfiguriert",
- "invalid-path": "",
"invalid-template": "Ausgew\u00e4hlte Template ist nicht g\u00fcltig",
"loginfail": "Benutzername oder Kennwort falsch",
"missing-file": "Es wurde keine Datei ausgew\u00e4hlt!",
diff --git a/lang/en/messages.json b/lang/en/messages.json
index 3302545c..fbec163e 100644
--- a/lang/en/messages.json
+++ b/lang/en/messages.json
@@ -3,6 +3,7 @@
"adduser-success": "User successfully added",
"config-activated": "Configuration {{0}} has been activated",
"config-invalid": "Configuration with id {{0}} does not exist",
+ "db-update-done": "Database successfully updated",
"debug-mode": "The debug mode is active!",
"deleted-tag": "Tag was successfully removed",
"empty-archive": "The archive contains no files or directories",
@@ -13,12 +14,9 @@
"error-read": "Error reading {{0}}",
"error-rename": "Could not rename {{0}} into {{1}}",
"error-write": "Failed to write {{0}}",
- "i18n-empty-tag": "",
- "i18n-invalid-lang": "",
"invalid-action": "Invalid action: {{0}}",
"invalid-file": "The file {{0}} does not exist!",
"invalid-ip": "No interface is configured with the address {{0}}",
- "invalid-path": "",
"invalid-template": "Selected template is not valid",
"loginfail": "Username or Password incorrect",
"missing-file": "There was no file selected!",
@@ -38,8 +36,6 @@
"taskmanager-error": "Failed to connect to the Task Manager",
"taskmanager-format": "Task Manager has returned invalid data",
"token": "Invalid token. CSRF attack?",
- "unsuccessful-action": "",
- "updated-tags": "",
"upload-complete": "Upload of {{0}} was successful",
"upload-failed": "Upload failed: {{0}}",
"value-invalid": "The value {{1}} is invalid for option {{0}} and has been ignored"
diff --git a/lang/pt/messages.json b/lang/pt/messages.json
index e02f9a1a..290f8378 100644
--- a/lang/pt/messages.json
+++ b/lang/pt/messages.json
@@ -13,12 +13,9 @@
"error-read": "Erro ao ler {{0}}",
"error-rename": "N\u00e3o foi poss\u00edvel renomear {{0}} em {{1}}",
"error-write": "Erro ao escrever {{0}}",
- "i18n-empty-tag": "",
- "i18n-invalid-lang": "",
"invalid-action": "A\u00e7\u00e3o inv\u00e1lida: {{0}}",
"invalid-file": "O arquivo {{0}} n\u00e3o existe!",
"invalid-ip": "Nenhuma interface est\u00e1 configurada com o endere\u00e7o {{0}}",
- "invalid-path": "",
"invalid-template": "Template selecionado n\u00e3o \u00e9 v\u00e1lido",
"loginfail": "Nome de usu\u00e1rio ou senha incorreta",
"missing-file": "N\u00e3o havia nenhum arquivo selecionado!",
diff --git a/style/default.css b/style/default.css
index 9b87f75c..0f1c8e3e 100644
--- a/style/default.css
+++ b/style/default.css
@@ -129,8 +129,12 @@ body {
animation-iteration-count: infinite;
animation-timing-function: linear;
}
-
+
@keyframes rotateThis {
from { transform: scale( 1 ) rotate( 0deg ); }
to { transform: scale( 1 ) rotate( 360deg ); }
}
+
+.slx-text-red {
+ color: red;
+}
diff --git a/templates/main-menu-login.html b/templates/main-menu-login.html
index 3f06e40b..06e729fe 100644
--- a/templates/main-menu-login.html
+++ b/templates/main-menu-login.html
@@ -37,6 +37,9 @@
{{/langs}}
</ul>
</li>
+ {{#dbupdate}}
+ <li><a href="api.php?do=update"><span class="slx-text-red"><span class="glyphicon glyphicon-exclamation-sign"></span> Update</span></a></li>
+ {{/dbupdate}}
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="?do=Session&amp;action=login">{{lang_login}}</a></li>
diff --git a/templates/main-menu-logout.html b/templates/main-menu-logout.html
index 149e0369..e70e1def 100644
--- a/templates/main-menu-logout.html
+++ b/templates/main-menu-logout.html
@@ -37,6 +37,9 @@
{{/langs}}
</ul>
</li>
+ {{#dbupdate}}
+ <li><a href="api.php?do=update"><span class="slx-text-red"><span class="glyphicon glyphicon-exclamation-sign"></span> Update</span></a></li>
+ {{/dbupdate}}
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="?do=Session&amp;action=logout&amp;token={{{token}}}"><b>{{user}}</b> ({{lang_logout}})</a></li>