summaryrefslogtreecommitdiffstats
path: root/inc/taskmanagercallback.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-12-02 19:22:48 +0100
committerSimon Rettberg2014-12-02 19:22:48 +0100
commitba2a49e9875eda489385e370bb9f2259779caa7b (patch)
tree2654d7b4a6bf99d584e146f7708c75a5b8beaeac /inc/taskmanagercallback.inc.php
parentFix wrong event type when displaying event log (diff)
downloadslx-admin-ba2a49e9875eda489385e370bb9f2259779caa7b.tar.gz
slx-admin-ba2a49e9875eda489385e370bb9f2259779caa7b.tar.xz
slx-admin-ba2a49e9875eda489385e370bb9f2259779caa7b.zip
Tweaks and fixes
Diffstat (limited to 'inc/taskmanagercallback.inc.php')
-rw-r--r--inc/taskmanagercallback.inc.php56
1 files changed, 55 insertions, 1 deletions
diff --git a/inc/taskmanagercallback.inc.php b/inc/taskmanagercallback.inc.php
index 3ef4745c..951a1de3 100644
--- a/inc/taskmanagercallback.inc.php
+++ b/inc/taskmanagercallback.inc.php
@@ -5,7 +5,7 @@
*/
class TaskmanagerCallback
{
-
+
/**
* Add a callback for given task id. This is the only exception in this class,
* as this is not a callback, but a function to define one :)
@@ -32,6 +32,51 @@ class TaskmanagerCallback
}
/**
+ * Get all pending callbacks from the callback table.
+ *
+ * @return array list of array(taskid => list of callbacks)
+ */
+ public static function getPendingCallbacks()
+ {
+ $retval = array();
+ $res = Database::simpleQuery("SELECT taskid, cbfunction FROM callback");
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $retval[$row['taskid']][] = $row;
+ }
+ return $retval;
+ }
+
+ /**
+ * Handle the given callback. Will delete the entry from the callback
+ * table if appropriate.
+ *
+ * @param array $callback entry from the callback table (cbfunction + taskid)
+ * @param array $status status of the task as returned by the taskmanager. If NULL it will be queried.
+ */
+ public static function handleCallback($callback, $status = NULL)
+ {
+ if (is_null($status))
+ $status = Taskmanager::status($callback['taskid']);
+ if ($status === false) // No reply from Taskmanager, retry later
+ return;
+ if (Taskmanager::isFailed($status) || Taskmanager::isFinished($status)) {
+ $del = Database::exec("DELETE FROM callback WHERE taskid = :task AND cbfunction = :cb LIMIT 1", array('task' => $callback['taskid'], 'cb' => $callback['cbfunction']));
+ if ($del === 0) // No entry deleted, so someone else must have deleted it - race condition, do nothing
+ return;
+ }
+ if (Taskmanager::isFinished($status)) {
+ $func = array('TaskmanagerCallback', preg_replace('/\W/', '', $callback['cbfunction']));
+ if (!call_user_func_array('method_exists', $func)) {
+ Eventlog::warning("handleCallback: Callback {$callback['cbfunction']} doesn't exist.");
+ } else {
+ call_user_func($func, $status);
+ }
+ }
+ }
+
+ // ####################################################################
+
+ /**
* Result of trying to (re)launch ldadp.
*/
public static function ldadpStartup($task)
@@ -40,4 +85,13 @@ class TaskmanagerCallback
EventLog::warning("Could not start/stop LDAP-AD-Proxy instances", $task['data']['messages']);
}
+ public static function dbRestored($task)
+ {
+ error_log("dbRestored.");
+ if (Taskmanager::isFinished($task) && !Taskmanager::isFailed($task)) {
+ error_log("LOGGING.");
+ EventLog::info('Configuration backup restored.');
+ }
+ }
+
}