ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilBackgroundTaskHub Class Reference

background task hub (aka ajax handler, GUI) More...

+ Collaboration diagram for ilBackgroundTaskHub:

Public Member Functions

 __construct ()
 Constructor. More...
 
 executeCommand ()
 Execute current command. More...
 
 isSOAPEnabled ()
 Is soap enabled? More...
 

Protected Member Functions

 sendJson (stdClass $a_json)
 Send Json to client. More...
 
 validate ()
 Validate given task. More...
 
 unblock ()
 Cancel all other tasks, start current one. More...
 
 process ()
 Process current task. More...
 
 progress ()
 Check progress of current task. More...
 
 cancel ()
 Cancel current task. More...
 
 deliver ()
 Deliver result. More...
 

Protected Attributes

 $task
 
 $handler
 

Detailed Description

background task hub (aka ajax handler, GUI)

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

ilBackgroundTaskHub:

Definition at line 13 of file class.ilBackgroundTaskHub.php.

Constructor & Destructor Documentation

◆ __construct()

ilBackgroundTaskHub::__construct ( )

Constructor.

Returns

Definition at line 23 of file class.ilBackgroundTaskHub.php.

References $DIC, and $lng.

24  {
25  global $DIC;
26  $lng = $DIC['lng'];
27 
28  $lng->loadLanguageModule("bgtask");
29 
30  if ((int) $_REQUEST["tid"]) {
31  $this->task = new ilBackgroundTask((int) $_REQUEST["tid"]);
32  $this->handler = $this->task->getHandlerInstance();
33  }
34  }
global $DIC
Definition: saml.php:7
global $lng
Definition: privfeed.php:17

Member Function Documentation

◆ cancel()

ilBackgroundTaskHub::cancel ( )
protected

Cancel current task.

Definition at line 175 of file class.ilBackgroundTaskHub.php.

References ilBackgroundTask\STATUS_CANCELLING.

176  {
177  // just emit cancelling status, (background) process will stop ASAP
178  $this->task->setStatus(ilBackgroundTask::STATUS_CANCELLING);
179  $this->task->save();
180  }

◆ deliver()

ilBackgroundTaskHub::deliver ( )
protected

Deliver result.

Definition at line 185 of file class.ilBackgroundTaskHub.php.

186  {
187  // :TODO: delete task?
188 
189  $this->handler->deliver();
190  }

◆ executeCommand()

ilBackgroundTaskHub::executeCommand ( )

Execute current command.

Definition at line 44 of file class.ilBackgroundTaskHub.php.

References $DIC, $ilCtrl, and exit.

45  {
46  global $DIC;
47  $ilCtrl = $DIC['ilCtrl'];
48 
49  $next_class = $ilCtrl->getNextClass($this);
50  $cmd = $ilCtrl->getCmd("validate");
51 
52  switch ($next_class) {
53  default:
54  if ($cmd == "deliver" ||
55  $ilCtrl->isAsynch()) {
56  $this->$cmd();
57  break;
58  }
59  }
60 
61  // deliver file and ajax require exit
62  exit();
63  }
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18

◆ isSOAPEnabled()

ilBackgroundTaskHub::isSOAPEnabled ( )

Is soap enabled?

Returns
bool

Definition at line 143 of file class.ilBackgroundTaskHub.php.

References $DIC, $ilSetting, ilContext\CONTEXT_CRON, and ilContext\getType().

Referenced by process().

144  {
145  global $DIC;
146  $ilSetting = $DIC['ilSetting'];
147 
148  // see ilMail
149  return (extension_loaded('curl') &&
150  $ilSetting->get('soap_user_administration') &&
152  }
global $DIC
Definition: saml.php:7
const CONTEXT_CRON
global $ilSetting
Definition: privfeed.php:17
static getType()
Get context type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ process()

ilBackgroundTaskHub::process ( )
protected

Process current task.

Definition at line 118 of file class.ilBackgroundTaskHub.php.

References $_COOKIE, array, isSOAPEnabled(), and ilBackgroundTask\STATUS_PROCESSING.

119  {
120  $this->task->setStatus(ilBackgroundTask::STATUS_PROCESSING);
121  $this->task->save();
122 
123  if (!$this->isSOAPEnabled()) {
124  $this->handler->process();
125  } else {
126  require_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
127  $soap_client = new ilSoapClient();
128  $soap_client->setResponseTimeout(1);
129  $soap_client->enableWSDL(true);
130  $soap_client->init();
131  $soap_client->call('processBackgroundTask', array(
132  session_id() . '::' . $_COOKIE['ilClientId'],
133  $this->task->getId()
134  ));
135  }
136  }
$_COOKIE['client_id']
Definition: server.php:9
isSOAPEnabled()
Is soap enabled?
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ progress()

ilBackgroundTaskHub::progress ( )
protected

Check progress of current task.

Definition at line 157 of file class.ilBackgroundTaskHub.php.

References $result, ilBackgroundTaskJson\getProgressJson(), sendJson(), and ilBackgroundTask\STATUS_FINISHED.

158  {
159  include_once "Services/BackgroundTask/classes/class.ilBackgroundTaskJson.php";
160 
161  // if task has been finished, get result action
162  if ($this->task->getStatus() == ilBackgroundTask::STATUS_FINISHED) {
163  $result = $this->handler->finish();
164  $json = ilBackgroundTaskJson::getProgressJson($this->task, $result[0], $result[1]);
165  } else {
166  $json = ilBackgroundTaskJson::getProgressJson($this->task);
167  }
168 
169  $this->sendJson($json);
170  }
$result
static getProgressJson(ilBackgroundTask $a_task, $a_finished_cmd=null, $a_finished_result=null)
Get json for task progress.
sendJson(stdClass $a_json)
Send Json to client.
+ Here is the call graph for this function:

◆ sendJson()

ilBackgroundTaskHub::sendJson ( stdClass  $a_json)
protected

Send Json to client.

Parameters
stdClass$a_json

Definition at line 70 of file class.ilBackgroundTaskHub.php.

Referenced by progress(), unblock(), and validate().

71  {
72  echo json_encode($a_json);
73  }
+ Here is the caller graph for this function:

◆ unblock()

ilBackgroundTaskHub::unblock ( )
protected

Cancel all other tasks, start current one.

Definition at line 95 of file class.ilBackgroundTaskHub.php.

References $DIC, $ilUser, $task, ilBackgroundTask\getActiveByUserId(), sendJson(), and ilBackgroundTask\STATUS_CANCELLING.

96  {
97  global $DIC;
98  $ilUser = $DIC['ilUser'];
99 
100  foreach (ilBackgroundTask::getActiveByUserId($ilUser->getId()) as $task_id) {
101  // leave current task alone
102  if ($task_id != $this->task->getId()) {
103  // emit cancelling status, running processes will cancel
104  $task = new ilBackgroundTask($task_id);
106  $task->save();
107  }
108  }
109 
110  // init/start current task
111  $json = $this->handler->init();
112  $this->sendJson($json);
113  }
global $DIC
Definition: saml.php:7
static getActiveByUserId($a_user_id)
$ilUser
Definition: imgupload.php:18
sendJson(stdClass $a_json)
Send Json to client.
+ Here is the call graph for this function:

◆ validate()

ilBackgroundTaskHub::validate ( )
protected

Validate given task.

Definition at line 78 of file class.ilBackgroundTaskHub.php.

References $_GET, $file, $handler, and sendJson().

79  {
80  $class = trim($_GET["hid"]);
81  $file = "Services/BackgroundTask/classes/class." . $class . ".php";
82  if (file_exists($file)) {
83  include_once $file;
84  $handler = new $class();
85  $json = $handler->init($_GET["par"]);
86 
87  $this->sendJson($json);
88  }
89  }
$_GET["client_id"]
sendJson(stdClass $a_json)
Send Json to client.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $handler

ilBackgroundTaskHub::$handler
protected

Definition at line 16 of file class.ilBackgroundTaskHub.php.

Referenced by validate().

◆ $task

ilBackgroundTaskHub::$task
protected

Definition at line 15 of file class.ilBackgroundTaskHub.php.

Referenced by unblock().


The documentation for this class was generated from the following file: