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.

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

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.
+ Here is the call graph for this function:

Member Function Documentation

◆ delete()

ilBackgroundTask::delete ( )

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

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

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

◆ doCreate()

ilBackgroundTask::doCreate ( )
protected

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

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

Referenced by save().

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  }
setStartDate(ilDateTime $a_val)
Sets the date when the download was started.
global $DIC
Definition: saml.php:7
setId($a_val)
Sets the id.
const IL_CAL_UNIX
Date and time handling
Create styles array
The data for the language used.
exists()
Gets whether the download object exists.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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.

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

Referenced by delete().

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  }
global $DIC
Definition: saml.php:7
Create styles array
The data for the language used.
global $ilDB
+ 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.

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

Referenced by __construct(), and isToBeCancelled().

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  }
setStatus($a_val)
Sets the status.
setStartDate(ilDateTime $a_val)
Sets the date when the download was started.
const IL_CAL_DATETIME
setCurrentStep($a_val)
Sets the current step.
global $DIC
Definition: saml.php:7
setHandlerId($a_val)
Sets the handler id.
setId($a_val)
Sets the id.
Date and time handling
getHandlerId()
Gets the handler.
Create styles array
The data for the language used.
setParams(array $a_params=null)
Sets the params.
exists()
Gets whether the download object exists.
setSteps($a_val)
Sets the steps.
global $ilDB
setUserId($a_val)
Sets the user id.
+ 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.

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

Referenced by save().

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  }
global $DIC
Definition: saml.php:7
Create styles array
The data for the language used.
global $ilDB
+ 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.

References $exists.

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

276  {
277  return $this->exists;
278  }
+ 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.

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

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

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  }
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
global $ilDB
+ 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.

References $current_step.

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

236  {
237  return $this->current_step;
238  }
+ 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.

References $handler.

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

101  {
102  return $this->handler;
103  }
+ Here is the caller graph for this function:

◆ getHandlerInstance()

ilBackgroundTask::getHandlerInstance ( )
Returns

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

References getHandlerId().

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  }
getHandlerId()
Gets the handler.
+ 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.

References $id.

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

121  {
122  return $this->id;
123  }
+ 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.

References $params.

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

256  {
257  return $this->params;
258  }
+ 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.

References $start_date.

Referenced by preparePropertiesForDB().

161  {
162  return $this->start_date;
163  }
+ 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.

References $status.

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

181  {
182  return $this->status;
183  }
+ 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.

References $steps.

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

216  {
217  return $this->steps;
218  }
+ 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.

References $user_id.

Referenced by preparePropertiesForDB().

141  {
142  return $this->user_id;
143  }
+ Here is the caller graph for this function:

◆ getValidStatus()

ilBackgroundTask::getValidStatus ( )
protected

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

References array.

Referenced by setStatus().

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  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ isToBeCancelled()

ilBackgroundTask::isToBeCancelled ( )

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

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

85  {
86  $this->doRead($this->getId());
87  return ($this->getStatus() == self::STATUS_CANCELLING);
88  }
getStatus()
Gets the status.
+ Here is the call graph for this function:

◆ preparePropertiesForDB()

ilBackgroundTask::preparePropertiesForDB ( )
protected

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

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

Referenced by doCreate(), and doUpdate().

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  }
const IL_CAL_DATETIME
getSteps()
Gets the steps.
getParams()
Gets the params.
getStartDate()
Gets the date when the download was started.
getCurrentStep()
Gets the current step.
getHandlerId()
Gets the handler.
Create styles array
The data for the language used.
getStatus()
Gets the status.
getUserId()
Gets the user id.
+ 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.

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

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  }
getHandlerId()
Gets the handler.
exists()
Gets whether the download object exists.
+ 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.

References getSteps().

Referenced by doRead().

246  {
247  $this->current_step = min(abs($a_val), $this->getSteps());
248  }
getSteps()
Gets the steps.
+ 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.

Referenced by doRead().

111  {
112  $this->handler = $a_val;
113  }
+ 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.

Referenced by doCreate(), and doRead().

131  {
132  $this->id = (int) $a_val;
133  }
+ 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.

Referenced by doRead().

266  {
267  $this->params = $a_params;
268  }
+ 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.

Referenced by doCreate(), and doRead().

171  {
172  $this->start_date = $a_val;
173  }
+ 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.

References getValidStatus().

Referenced by doRead().

204  {
205  if (in_array($a_val, $this->getValidStatus())) {
206  $this->status = $a_val;
207  }
208  }
+ 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.

Referenced by doRead().

226  {
227  $this->steps = abs($a_val);
228  }
+ 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.

Referenced by doRead().

151  {
152  $this->user_id = (int) $a_val;
153  }
+ 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: