ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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

@ilCtrl_Calls ilBackgroundTaskHub:

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

Constructor & Destructor Documentation

◆ __construct()

ilBackgroundTaskHub::__construct ( )

Constructor.

Returns
\self

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

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

References $lng.

Member Function Documentation

◆ cancel()

ilBackgroundTaskHub::cancel ( )
protected

Cancel current task.

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

184 {
185 // just emit cancelling status, (background) process will stop ASAP
186 $this->task->setStatus(ilBackgroundTask::STATUS_CANCELLING);
187 $this->task->save();
188 }

References ilBackgroundTask\STATUS_CANCELLING.

◆ deliver()

ilBackgroundTaskHub::deliver ( )
protected

Deliver result.

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

194 {
195 // :TODO: delete task?
196
197 $this->handler->deliver();
198 }

◆ executeCommand()

ilBackgroundTaskHub::executeCommand ( )

Execute current command

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

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

References $cmd, $ilCtrl, and exit.

◆ isSOAPEnabled()

ilBackgroundTaskHub::isSOAPEnabled ( )

Is soap enabled?

Returns
bool

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

150 {
151 global $ilSetting;
152
153 // see ilMail
154 return (extension_loaded('curl') &&
155 $ilSetting->get('soap_user_administration') &&
157 }
const CONTEXT_CRON
static getType()
Get context type.
global $ilSetting
Definition: privfeed.php:17

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

Referenced by process().

+ 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 121 of file class.ilBackgroundTaskHub.php.

122 {
123 $this->task->setStatus(ilBackgroundTask::STATUS_PROCESSING);
124 $this->task->save();
125
126 if(!$this->isSOAPEnabled())
127 {
128 $this->handler->process();
129 }
130 else
131 {
132 require_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
133 $soap_client = new ilSoapClient();
134 $soap_client->setResponseTimeout(1);
135 $soap_client->enableWSDL(true);
136 $soap_client->init();
137 $soap_client->call('processBackgroundTask', array(
138 session_id() . '::' . $_COOKIE['ilClientId'],
139 $this->task->getId()
140 ));
141 }
142 }
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15

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

+ Here is the call graph for this function:

◆ progress()

ilBackgroundTaskHub::progress ( )
protected

Check progress of current task.

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

163 {
164 include_once "Services/BackgroundTask/classes/class.ilBackgroundTaskJson.php";
165
166 // if task has been finished, get result action
167 if($this->task->getStatus() == ilBackgroundTask::STATUS_FINISHED)
168 {
169 $result = $this->handler->finish();
170 $json = ilBackgroundTaskJson::getProgressJson($this->task, $result[0], $result[1]);
171 }
172 else
173 {
174 $json = ilBackgroundTaskJson::getProgressJson($this->task);
175 }
176
177 $this->sendJson($json);
178 }
$result
sendJson(stdClass $a_json)
Send Json to client.
static getProgressJson(ilBackgroundTask $a_task, $a_finished_cmd=null, $a_finished_result=null)
Get json for task progress.

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

+ 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 71 of file class.ilBackgroundTaskHub.php.

72 {
73 echo json_encode($a_json);
74 }

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

+ Here is the caller graph for this function:

◆ unblock()

ilBackgroundTaskHub::unblock ( )
protected

Cancel all other tasks, start current one.

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

98 {
99 global $ilUser;
100
101 foreach(ilBackgroundTask::getActiveByUserId($ilUser->getId()) as $task_id)
102 {
103 // leave current task alone
104 if($task_id != $this->task->getId())
105 {
106 // emit cancelling status, running processes will cancel
107 $task = new ilBackgroundTask($task_id);
109 $task->save();
110 }
111 }
112
113 // init/start current task
114 $json = $this->handler->init();
115 $this->sendJson($json);
116 }
static getActiveByUserId($a_user_id)
$ilUser
Definition: imgupload.php:18

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

+ Here is the call graph for this function:

◆ validate()

ilBackgroundTaskHub::validate ( )
protected

Validate given task.

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

80 {
81 $class = trim($_GET["hid"]);
82 $file = "Services/BackgroundTask/classes/class.".$class.".php";
83 if(file_exists($file))
84 {
85 include_once $file;
86 $handler = new $class();
87 $json = $handler->init($_GET["par"]);
88
89 $this->sendJson($json);
90 }
91 }
$_GET["client_id"]
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

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

+ 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: