From e1dc0d3c99217504de2ac8467156274786efc0bd Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 9 Oct 2014 16:01:11 +0200 Subject: Big load of changes - Added callback functionality for taskmanager tasks. You can launch a task and define a callback function to be run when the task finished. This requires activating the cronjob - Added cron functionality: Add cronjob that calls the cron api every 5 minutes to use it. (See cron.inc.php) - Added eventlog - Added missing translations - Merged main-menu-login and main-menu-logout --- apis/cron.inc.php | 28 +++++++++++ apis/init.inc.php | 61 ++--------------------- apis/update.inc.php | 137 +++++++++++++++++++++++++++------------------------- 3 files changed, 102 insertions(+), 124 deletions(-) create mode 100644 apis/cron.inc.php (limited to 'apis') diff --git a/apis/cron.inc.php b/apis/cron.inc.php new file mode 100644 index 00000000..2d0fc66c --- /dev/null +++ b/apis/cron.inc.php @@ -0,0 +1,28 @@ + 86400 * 90"); + break; +case 2: + Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 90"); + break; +case 3: + Database::exec("DELETE FROM property WHERE dateline <> 0 AND dateline < UNIX_TIMESTAMP()"); + break; +case 4: + Database::exec("DELETE FROM callback WHERE (UNIX_TIMESTAMP() - dateline) > 86400"); + break; +} + +Trigger::checkCallbacks(); diff --git a/apis/init.inc.php b/apis/init.inc.php index a1344fc4..617114d7 100644 --- a/apis/init.inc.php +++ b/apis/init.inc.php @@ -1,62 +1,9 @@ fetch(PDO::FETCH_ASSOC)) { + if ((is_array($column) && in_array($row['Field'], $column)) || (is_string($column) && $row['Field'] === $column)) + return true; + } + } + return false; +} + +function tableDropColumn($table, $column) +{ + $table = preg_replace('/\W/', '', $table); + $column = preg_replace('/\W/', '', $column); + $res = Database::simpleQuery("DESCRIBE `$table`", array(), false); + if ($res !== false) { + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if ((is_array($column) && in_array($row['Field'], $column)) || (is_string($column) && $row['Field'] === $column)) + Database::exec("ALTER TABLE `$table` DROP `{$row['Field']}`"); + } + } +} + +function tableExists($table) +{ + $res = Database::simpleQuery("SHOW TABLES", array(), false); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if ($row['Tables_in_openslx'] === $table) + return true; + } + return false; +} + // The update functions. Number at the end refers to current version, the function will update to the next version // ####################### // ##### 2014-05-28 @@ -48,17 +88,7 @@ Util::redirect('index.php?do=Main'); function update_1() { - $res = Database::simpleQuery("DESCRIBE property", array(), false); - $type = false; - if ($res === false) - return; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ($row['Field'] !== 'dateline') - continue; - $type = $row['Type']; - break; - } - if ($type === false) { + if (!tableHasColumn('property', 'dateline')) { Database::exec("ALTER TABLE `property` ADD `dateline` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `name` , ADD INDEX ( `dateline` )"); } else { Database::exec("ALTER TABLE `property` CHANGE `dateline` `dateline` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); @@ -71,17 +101,9 @@ function update_1() // Add 'news' table to database schema function update_2() { - $res = Database::simpleQuery("show tables", array(), false); - $found = false; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ($row['Tables_in_openslx'] !== 'news') - continue; - $found = true; - break; - } - if ($found === false) { + if (!tableExists('news')) { // create table - Database::exec("CREATE TABLE `news` ( + Database::exec("CREATE TABLE IF NOT EXISTS `news` ( `newsid` int(10) unsigned NOT NULL AUTO_INCREMENT, `dateline` int(10) unsigned NOT NULL, `title` varchar(200) DEFAULT NULL, @@ -99,32 +121,8 @@ function update_2() // Remove setting descriptions from DB, put into json files now 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; - } - } - } - $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; - } - } - } + tableDropColumn('setting', array('de', 'en', 'pt', 'description')); + tableDropColumn('cat_setting', array('de', 'en', 'pt', 'name')); return true; } @@ -133,27 +131,10 @@ function update_3() // 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) { + tableDropColumn('permission', 'description'); + if (!tableExists('eventlog')) { // create table - Database::exec("CREATE TABLE `eventlog` ( + Database::exec("CREATE TABLE IF NOT EXISTS `eventlog` ( `logid` int(10) unsigned NOT NULL AUTO_INCREMENT, `dateline` int(10) unsigned NOT NULL, `logtypeid` varchar(30) NOT NULL, @@ -166,3 +147,25 @@ function update_4() } return true; } + +// ####################### +// ##### 2014-08-18 +// Add details column to eventlog table, add callback table +function update_5() +{ + if (!tableHasColumn('eventlog', 'extra')) + Database::exec("ALTER TABLE `eventlog` ADD `extra` TEXT NOT NULL"); + if (!tableHasColumn('user', 'lasteventid')) + Database::exec("ALTER TABLE `user` ADD `lasteventid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); + if (!tableExists('callback')) { + Database::exec("CREATE TABLE IF NOT EXISTS `callback` ( + `taskid` varchar(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + `dateline` int(10) unsigned NOT NULL, + `cbfunction` varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + PRIMARY KEY (`taskid`,`cbfunction`), + KEY `dateline` (`dateline`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + "); + } + return true; +} -- cgit v1.2.3-55-g7522