summaryrefslogtreecommitdiffstats
path: root/apis/taskmanager.inc.php
blob: c7cdb8811337c00732d9cace48effb1a83c47347 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

require_once 'inc/taskmanager.inc.php';
require_once 'inc/property.inc.php';

if (!is_array($_POST['ids'])) {
	die('{"error" : "No Task ids given in POST data."}');
}

$callbacks = false;

$return = array();
foreach ($_POST['ids'] as $id) {
	// Get task status
	$status = Taskmanager::status($id);
	if ($status === false) {
		$return[] = array('id' => $id, 'error' => 'No connection to TaskManager');
		continue;
	}
	$return[] = $status;
	// Handle callbacks (if any)
	if ($callbacks === false)
		$callbacks = TaskmanagerCallback::getPendingCallbacks();
	if (isset($callbacks[$id])) {
		foreach ($callbacks[$id] as $callback) {
			TaskmanagerCallback::handleCallback($callback, $status);
		}
	}
	// Release task if done
	if (Taskmanager::isFailed($status) || Taskmanager::isFinished($status)) {
		Taskmanager::release($id);
	}
}

Header('Content-Type: application/json');
echo json_encode(array('tasks' => $return));