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

Background task. More...

+ Collaboration diagram for ilBackgroundTask:

Public Member Functions

 __construct ($a_id=0)
 Constructor. More...
 
 getHandlerInstance ()
 
 isToBeCancelled ()
 
 getHandlerId ()
 Gets the handler. More...
 
 setHandlerId ($a_val)
 Sets the handler id. More...
 
 getId ()
 Gets the id. More...
 
 getUserId ()
 Gets the user id. More...
 
 setUserId ($a_val)
 Sets the user id. More...
 
 getStartDate ()
 Gets the date when the download was started. More...
 
 getStatus ()
 Gets the status. More...
 
 setStatus ($a_val)
 Sets the status. More...
 
 getSteps ()
 Gets the steps. More...
 
 setSteps ($a_val)
 Sets the steps. More...
 
 getCurrentStep ()
 Gets the current step. More...
 
 setCurrentStep ($a_val)
 Sets the current step. More...
 
 getParams ()
 Gets the params. More...
 
 setParams (array $a_params=null)
 Sets the params. More...
 
 exists ()
 Gets whether the download object exists. More...
 
 save ()
 
 delete ()
 

Static Public Member Functions

static getActiveByUserId ($a_user_id)
 

Data Fields

const STATUS_INITIALIZED = "initialized"
 
const STATUS_PROCESSING = "processing"
 
const STATUS_PROCESSED = "processed"
 
const STATUS_CANCELLING = "cancelling"
 
const STATUS_CANCELLED = "cancelled"
 
const STATUS_FINISHED = "finished"
 
const STATUS_FAILED = "failed"
 
const DB_NAME = "background_task"
 

Protected Member Functions

 setId ($a_val)
 Sets the id. More...
 
 setStartDate (ilDateTime $a_val)
 Sets the date when the download was started. More...
 
 getValidStatus ()
 
 doRead ($a_id)
 
 preparePropertiesForDB ()
 
 doCreate ()
 
 doUpdate ()
 
 doDelete ()
 Deletes the object from the database. More...
 

Protected Attributes

 $id
 
 $user_id
 
 $start_date
 
 $status
 
 $steps
 
 $current_step
 
 $handler
 
 $params
 
 $exists
 
 $log
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBackgroundTask::__construct (   $a_id = 0)

Constructor.

Parameters
int$a_id
Returns
self

Definition at line 45 of file class.ilBackgroundTask.php.

46 {
47 $this->log = ilLoggerFactory::getLogger('btsk');
48 if ($a_id != 0) {
49 $this->doRead($a_id);
50 }
51 }
static getLogger($a_component_id)
Get component logger.

References doRead(), and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

ilBackgroundTask::delete ( )

Definition at line 296 of file class.ilBackgroundTask.php.

297 {
298 $this->log->debug($this->getHandlerId());
299 if (!$this->exists) {
300 return;
301 }
302
303 return $this->doDelete();
304 }
doDelete()
Deletes the object from the database.
exists()
Gets whether the download object exists.
getHandlerId()
Gets the handler.

References doDelete(), exists(), and getHandlerId().

+ Here is the call graph for this function:

◆ doCreate()

ilBackgroundTask::doCreate ( )
protected

Definition at line 351 of file class.ilBackgroundTask.php.

352 {
353 global $DIC;
354 $ilDB = $DIC['ilDB'];
355
356 $this->setId($ilDB->nextId(self::DB_NAME));
357 $this->setStartDate(new ilDateTime(time(), IL_CAL_UNIX));
358
359 $fields = $this->preparePropertiesForDB();
360 $fields["id"] = array("integer", $this->getId());
361
362 $ilDB->insert(self::DB_NAME, $fields);
363
364 $this->exists = true;
365 }
const IL_CAL_UNIX
setStartDate(ilDateTime $a_val)
Sets the date when the download was started.
setId($a_val)
Sets the id.
@classDescription Date and time handling
global $DIC
Definition: saml.php:7
global $ilDB

References $DIC, $ilDB, exists(), getId(), IL_CAL_UNIX, preparePropertiesForDB(), setId(), and setStartDate().

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doDelete()

ilBackgroundTask::doDelete ( )
protected

Deletes the object from the database.

Definition at line 382 of file class.ilBackgroundTask.php.

383 {
384 global $DIC;
385 $ilDB = $DIC['ilDB'];
386
387 return $ilDB->manipulateF(
388 "DELETE FROM " . self::DB_NAME . " WHERE id=%s",
389 array("integer"),
390 array($this->getId())
391 );
392 }

References $DIC, $ilDB, and getId().

Referenced by delete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doRead()

ilBackgroundTask::doRead (   $a_id)
protected

Definition at line 307 of file class.ilBackgroundTask.php.

308 {
309 global $DIC;
310 $ilDB = $DIC['ilDB'];
311
312 $this->log->debug($this->getHandlerId() . "/" . $a_id);
313
314 $set = $ilDB->queryF(
315 "SELECT * FROM " . self::DB_NAME . " WHERE id=%s",
316 array("integer"),
317 array($a_id)
318 );
319
320 while ($rec = $ilDB->fetchAssoc($set)) {
321 $this->setId($a_id);
322 $this->exists = true;
323
324 $this->setUserId($rec["user_id"]);
325 $this->setStartDate(new ilDateTime($rec["start_date"], IL_CAL_DATETIME));
326 $this->setStatus($rec["status"]);
327 $this->setSteps($rec["steps"]);
328 $this->setCurrentStep($rec["cstep"]);
329 $this->setHandlerId($rec["handler"]);
330 $this->setParams($rec["params"]
331 ? unserialize($rec["params"])
332 : null);
333 }
334 }
const IL_CAL_DATETIME
setSteps($a_val)
Sets the steps.
setUserId($a_val)
Sets the user id.
setHandlerId($a_val)
Sets the handler id.
setStatus($a_val)
Sets the status.
setParams(array $a_params=null)
Sets the params.
setCurrentStep($a_val)
Sets the current step.

References $DIC, $ilDB, exists(), getHandlerId(), IL_CAL_DATETIME, setCurrentStep(), setHandlerId(), setId(), setParams(), setStartDate(), setStatus(), setSteps(), and setUserId().

Referenced by __construct(), and isToBeCancelled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doUpdate()

ilBackgroundTask::doUpdate ( )
protected

Definition at line 367 of file class.ilBackgroundTask.php.

368 {
369 global $DIC;
370 $ilDB = $DIC['ilDB'];
371
372 $ilDB->update(
373 self::DB_NAME,
374 $this->preparePropertiesForDB(),
375 array("id" => array("integer", $this->getId()))
376 );
377 }

References $DIC, $ilDB, getId(), and preparePropertiesForDB().

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exists()

ilBackgroundTask::exists ( )

Gets whether the download object exists.

Returns
boolean The value.

Definition at line 275 of file class.ilBackgroundTask.php.

276 {
277 return $this->exists;
278 }

References $exists.

Referenced by delete(), doCreate(), doRead(), and save().

+ Here is the caller graph for this function:

◆ getActiveByUserId()

static ilBackgroundTask::getActiveByUserId (   $a_user_id)
static

Definition at line 67 of file class.ilBackgroundTask.php.

68 {
69 global $DIC;
70 $ilDB = $DIC['ilDB'];
71
72 $res = array();
73
74 $set = $ilDB->query("SELECT id FROM " . self::DB_NAME .
75 " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
76 " AND status = " . $ilDB->quote(self::STATUS_PROCESSING, "text"));
77 while ($row = $ilDB->fetchAssoc($set)) {
78 $res[] = $row["id"];
79 }
80
81 return $res;
82 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $res, and $row.

Referenced by ilFolderDownloadBackgroundTaskHandler\init(), and ilBackgroundTaskHub\unblock().

+ Here is the caller graph for this function:

◆ getCurrentStep()

ilBackgroundTask::getCurrentStep ( )

Gets the current step.

Returns
int The value.

Definition at line 235 of file class.ilBackgroundTask.php.

236 {
237 return $this->current_step;
238 }

References $current_step.

Referenced by ilBackgroundTaskJson\getProgressJson(), and preparePropertiesForDB().

+ Here is the caller graph for this function:

◆ getHandlerId()

ilBackgroundTask::getHandlerId ( )

Gets the handler.

Returns
string The value.

Definition at line 100 of file class.ilBackgroundTask.php.

101 {
102 return $this->handler;
103 }

References $handler.

Referenced by delete(), doRead(), getHandlerInstance(), preparePropertiesForDB(), and save().

+ Here is the caller graph for this function:

◆ getHandlerInstance()

ilBackgroundTask::getHandlerInstance ( )
Returns
\ilBackgroundTaskHandler

Definition at line 57 of file class.ilBackgroundTask.php.

58 {
59 $handler_id = $this->getHandlerId();
60 $this->log->debug("Handler ID: " . $handler_id);
61 if ($handler_id) {
62 include_once "Services/BackgroundTask/classes/class." . $handler_id . ".php";
63 return $handler_id::getInstanceFromTask($this);
64 }
65 }

References getHandlerId().

+ Here is the call graph for this function:

◆ getId()

ilBackgroundTask::getId ( )

Gets the id.

Returns
int The value.

Definition at line 120 of file class.ilBackgroundTask.php.

121 {
122 return $this->id;
123 }

References $id.

Referenced by doCreate(), doDelete(), doUpdate(), and isToBeCancelled().

+ Here is the caller graph for this function:

◆ getParams()

ilBackgroundTask::getParams ( )

Gets the params.

Returns
int The value.

Definition at line 255 of file class.ilBackgroundTask.php.

256 {
257 return $this->params;
258 }

References $params.

Referenced by ilFolderDownloadBackgroundTaskHandler\getInstanceFromTask(), and preparePropertiesForDB().

+ Here is the caller graph for this function:

◆ getStartDate()

ilBackgroundTask::getStartDate ( )

Gets the date when the download was started.

Returns
ilDateTime The value.

Definition at line 160 of file class.ilBackgroundTask.php.

161 {
162 return $this->start_date;
163 }

References $start_date.

Referenced by preparePropertiesForDB().

+ Here is the caller graph for this function:

◆ getStatus()

ilBackgroundTask::getStatus ( )

Gets the status.

Returns
int The value.

Definition at line 180 of file class.ilBackgroundTask.php.

181 {
182 return $this->status;
183 }

References $status.

Referenced by ilBackgroundTaskJson\getProgressJson(), isToBeCancelled(), and preparePropertiesForDB().

+ Here is the caller graph for this function:

◆ getSteps()

ilBackgroundTask::getSteps ( )

Gets the steps.

Returns
int The value.

Definition at line 215 of file class.ilBackgroundTask.php.

216 {
217 return $this->steps;
218 }

References $steps.

Referenced by ilBackgroundTaskJson\getProgressJson(), preparePropertiesForDB(), and setCurrentStep().

+ Here is the caller graph for this function:

◆ getUserId()

ilBackgroundTask::getUserId ( )

Gets the user id.

Returns
int The value.

Definition at line 140 of file class.ilBackgroundTask.php.

141 {
142 return $this->user_id;
143 }

References $user_id.

Referenced by preparePropertiesForDB().

+ Here is the caller graph for this function:

◆ getValidStatus()

ilBackgroundTask::getValidStatus ( )
protected

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

186 {
187 return array(
188 self::STATUS_INITIALIZED,
189 self::STATUS_PROCESSING,
190 self::STATUS_CANCELLING,
191 self::STATUS_CANCELLED,
192 self::STATUS_PROCESSED,
193 self::STATUS_FINISHED,
194 self::STATUS_FAILED,
195 );
196 }

Referenced by setStatus().

+ Here is the caller graph for this function:

◆ isToBeCancelled()

ilBackgroundTask::isToBeCancelled ( )

Definition at line 84 of file class.ilBackgroundTask.php.

85 {
86 $this->doRead($this->getId());
87 return ($this->getStatus() == self::STATUS_CANCELLING);
88 }
getStatus()
Gets the status.

References doRead(), getId(), and getStatus().

+ Here is the call graph for this function:

◆ preparePropertiesForDB()

ilBackgroundTask::preparePropertiesForDB ( )
protected

Definition at line 336 of file class.ilBackgroundTask.php.

337 {
338 return array(
339 "user_id" => array("integer", $this->getUserId()),
340 "start_date" => array("timestamp", $this->getStartDate()->get(IL_CAL_DATETIME)),
341 "status" => array("text", $this->getStatus()),
342 "steps" => array("integer", $this->getSteps()),
343 "cstep" => array("integer", $this->getCurrentStep()),
344 "handler" => array("string", $this->getHandlerId()),
345 "params" => array("string", is_array($this->getParams())
346 ? serialize($this->getParams())
347 : null)
348 );
349 }
getSteps()
Gets the steps.
getStartDate()
Gets the date when the download was started.
getCurrentStep()
Gets the current step.
getUserId()
Gets the user id.
getParams()
Gets the params.

References getCurrentStep(), getHandlerId(), getParams(), getStartDate(), getStatus(), getSteps(), getUserId(), and IL_CAL_DATETIME.

Referenced by doCreate(), and doUpdate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBackgroundTask::save ( )

Definition at line 285 of file class.ilBackgroundTask.php.

286 {
287 $this->log->debug($this->getHandlerId());
288 // does not exist yet?
289 if (!$this->exists) {
290 $this->doCreate();
291 } else {
292 $this->doUpdate();
293 }
294 }

References doCreate(), doUpdate(), exists(), and getHandlerId().

+ Here is the call graph for this function:

◆ setCurrentStep()

ilBackgroundTask::setCurrentStep (   $a_val)

Sets the current step.

Parameters
int$a_valThe new value.

Definition at line 245 of file class.ilBackgroundTask.php.

246 {
247 $this->current_step = min(abs($a_val), $this->getSteps());
248 }

References getSteps().

Referenced by doRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlerId()

ilBackgroundTask::setHandlerId (   $a_val)

Sets the handler id.

Parameters
$a_valThe new value.

Definition at line 110 of file class.ilBackgroundTask.php.

111 {
112 $this->handler = $a_val;
113 }

Referenced by doRead().

+ Here is the caller graph for this function:

◆ setId()

ilBackgroundTask::setId (   $a_val)
protected

Sets the id.

Parameters
int$a_valThe new value.

Definition at line 130 of file class.ilBackgroundTask.php.

131 {
132 $this->id = (int) $a_val;
133 }

Referenced by doCreate(), and doRead().

+ Here is the caller graph for this function:

◆ setParams()

ilBackgroundTask::setParams ( array  $a_params = null)

Sets the params.

Parameters
array$a_valThe new value.

Definition at line 265 of file class.ilBackgroundTask.php.

266 {
267 $this->params = $a_params;
268 }

Referenced by doRead().

+ Here is the caller graph for this function:

◆ setStartDate()

ilBackgroundTask::setStartDate ( ilDateTime  $a_val)
protected

Sets the date when the download was started.

Parameters
ilDateTime$a_valThe new value.

Definition at line 170 of file class.ilBackgroundTask.php.

171 {
172 $this->start_date = $a_val;
173 }

Referenced by doCreate(), and doRead().

+ Here is the caller graph for this function:

◆ setStatus()

ilBackgroundTask::setStatus (   $a_val)

Sets the status.

Parameters
int$a_valThe new value.

Definition at line 203 of file class.ilBackgroundTask.php.

204 {
205 if (in_array($a_val, $this->getValidStatus())) {
206 $this->status = $a_val;
207 }
208 }

References getValidStatus().

Referenced by doRead().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSteps()

ilBackgroundTask::setSteps (   $a_val)

Sets the steps.

Parameters
int$a_valThe new value.

Definition at line 225 of file class.ilBackgroundTask.php.

226 {
227 $this->steps = abs($a_val);
228 }

Referenced by doRead().

+ Here is the caller graph for this function:

◆ setUserId()

ilBackgroundTask::setUserId (   $a_val)

Sets the user id.

Parameters
int$a_valThe new value.

Definition at line 150 of file class.ilBackgroundTask.php.

151 {
152 $this->user_id = (int) $a_val;
153 }

Referenced by doRead().

+ Here is the caller graph for this function:

Field Documentation

◆ $current_step

ilBackgroundTask::$current_step
protected

Definition at line 18 of file class.ilBackgroundTask.php.

Referenced by getCurrentStep().

◆ $exists

ilBackgroundTask::$exists
protected

Definition at line 21 of file class.ilBackgroundTask.php.

Referenced by exists().

◆ $handler

ilBackgroundTask::$handler
protected

Definition at line 19 of file class.ilBackgroundTask.php.

Referenced by getHandlerId().

◆ $id

ilBackgroundTask::$id
protected

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

Referenced by getId().

◆ $log

ilBackgroundTask::$log
protected

Definition at line 26 of file class.ilBackgroundTask.php.

◆ $params

ilBackgroundTask::$params
protected

Definition at line 20 of file class.ilBackgroundTask.php.

Referenced by getParams().

◆ $start_date

ilBackgroundTask::$start_date
protected

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

Referenced by getStartDate().

◆ $status

ilBackgroundTask::$status
protected

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

Referenced by getStatus().

◆ $steps

ilBackgroundTask::$steps
protected

Definition at line 17 of file class.ilBackgroundTask.php.

Referenced by getSteps().

◆ $user_id

ilBackgroundTask::$user_id
protected

Definition at line 14 of file class.ilBackgroundTask.php.

Referenced by getUserId().

◆ DB_NAME

const ilBackgroundTask::DB_NAME = "background_task"

◆ STATUS_CANCELLED

const ilBackgroundTask::STATUS_CANCELLED = "cancelled"

Definition at line 33 of file class.ilBackgroundTask.php.

Referenced by ilZipBackgroundTaskHandler\cancel().

◆ STATUS_CANCELLING

const ilBackgroundTask::STATUS_CANCELLING = "cancelling"

◆ STATUS_FAILED

const ilBackgroundTask::STATUS_FAILED = "failed"

Definition at line 35 of file class.ilBackgroundTask.php.

◆ STATUS_FINISHED

const ilBackgroundTask::STATUS_FINISHED = "finished"

◆ STATUS_INITIALIZED

const ilBackgroundTask::STATUS_INITIALIZED = "initialized"

◆ STATUS_PROCESSED

const ilBackgroundTask::STATUS_PROCESSED = "processed"

Definition at line 31 of file class.ilBackgroundTask.php.

◆ STATUS_PROCESSING

const ilBackgroundTask::STATUS_PROCESSING = "processing"

Definition at line 30 of file class.ilBackgroundTask.php.

Referenced by ilBackgroundTaskHub\process().


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