ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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  {
50  $this->doRead($a_id);
51  }
52  }
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 302 of file class.ilBackgroundTask.php.

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

303  {
304  $this->log->debug($this->getHandlerId());
305  if(!$this->exists)
306  {
307  return;
308  }
309 
310  return $this->doDelete();
311  }
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 357 of file class.ilBackgroundTask.php.

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

Referenced by save().

358  {
359  global $ilDB;
360 
361  $this->setId($ilDB->nextId(self::DB_NAME));
362  $this->setStartDate(new ilDateTime(time(), IL_CAL_UNIX));
363 
364  $fields = $this->preparePropertiesForDB();
365  $fields["id"] = array("integer", $this->getId());
366 
367  $ilDB->insert(self::DB_NAME, $fields);
368 
369  $this->exists = true;
370  }
setStartDate(ilDateTime $a_val)
Sets the date when the download was started.
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 386 of file class.ilBackgroundTask.php.

References $ilDB, array, and getId().

Referenced by delete().

387  {
388  global $ilDB;
389 
390  return $ilDB->manipulateF(
391  "DELETE FROM " . self::DB_NAME . " WHERE id=%s",
392  array("integer"),
393  array($this->getId()));
394  }
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 314 of file class.ilBackgroundTask.php.

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

Referenced by __construct(), and isToBeCancelled().

315  {
316  global $ilDB;
317 
318  $this->log->debug($this->getHandlerId()."/".$a_id);
319 
320  $set = $ilDB->queryF(
321  "SELECT * FROM " . self::DB_NAME . " WHERE id=%s",
322  array("integer"),
323  array($a_id));
324 
325  while ($rec = $ilDB->fetchAssoc($set))
326  {
327  $this->setId($a_id);
328  $this->exists = true;
329 
330  $this->setUserId($rec["user_id"]);
331  $this->setStartDate(new ilDateTime($rec["start_date"], IL_CAL_DATETIME));
332  $this->setStatus($rec["status"]);
333  $this->setSteps($rec["steps"]);
334  $this->setCurrentStep($rec["cstep"]);
335  $this->setHandlerId($rec["handler"]);
336  $this->setParams($rec["params"]
337  ? unserialize($rec["params"])
338  : null);
339  }
340  }
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.
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 372 of file class.ilBackgroundTask.php.

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

Referenced by save().

373  {
374  global $ilDB;
375 
376  $ilDB->update(
377  self::DB_NAME,
378  $this->preparePropertiesForDB(),
379  array("id" => array("integer", $this->getId()))
380  );
381  }
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 278 of file class.ilBackgroundTask.php.

References $exists.

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

279  {
280  return $this->exists;
281  }
+ Here is the caller graph for this function:

◆ getActiveByUserId()

static ilBackgroundTask::getActiveByUserId (   $a_user_id)
static

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

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

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

70  {
71  global $ilDB;
72 
73  $res = array();
74 
75  $set = $ilDB->query("SELECT id FROM ".self::DB_NAME.
76  " WHERE user_id = ".$ilDB->quote($a_user_id, "integer").
77  " AND status = ".$ilDB->quote(self::STATUS_PROCESSING, "text"));
78  while($row = $ilDB->fetchAssoc($set))
79  {
80  $res[] = $row["id"];
81  }
82 
83  return $res;
84  }
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 238 of file class.ilBackgroundTask.php.

References $current_step.

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

239  {
240  return $this->current_step;
241  }
+ Here is the caller graph for this function:

◆ getHandlerId()

ilBackgroundTask::getHandlerId ( )

Gets the handler.

Returns
string The value.

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

References $handler.

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

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

◆ getHandlerInstance()

ilBackgroundTask::getHandlerInstance ( )
Returns

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

References getHandlerId().

59  {
60  $handler_id = $this->getHandlerId();
61  $this->log->debug("Handler ID: ".$handler_id);
62  if($handler_id)
63  {
64  include_once "Services/BackgroundTask/classes/class.".$handler_id.".php";
65  return $handler_id::getInstanceFromTask($this);
66  }
67  }
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 122 of file class.ilBackgroundTask.php.

References $id.

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

123  {
124  return $this->id;
125  }
+ Here is the caller graph for this function:

◆ getParams()

ilBackgroundTask::getParams ( )

Gets the params.

Returns
int The value.

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

References $params.

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

259  {
260  return $this->params;
261  }
+ 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 162 of file class.ilBackgroundTask.php.

References $start_date.

Referenced by preparePropertiesForDB().

163  {
164  return $this->start_date;
165  }
+ Here is the caller graph for this function:

◆ getStatus()

ilBackgroundTask::getStatus ( )

Gets the status.

Returns
int The value.

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

References $status.

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

183  {
184  return $this->status;
185  }
+ Here is the caller graph for this function:

◆ getSteps()

ilBackgroundTask::getSteps ( )

Gets the steps.

Returns
int The value.

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

References $steps.

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

219  {
220  return $this->steps;
221  }
+ Here is the caller graph for this function:

◆ getUserId()

ilBackgroundTask::getUserId ( )

Gets the user id.

Returns
int The value.

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

References $user_id.

Referenced by preparePropertiesForDB().

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

◆ getValidStatus()

ilBackgroundTask::getValidStatus ( )
protected

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

References array.

Referenced by setStatus().

188  {
189  return array(
190  self::STATUS_INITIALIZED,
191  self::STATUS_PROCESSING,
192  self::STATUS_CANCELLING,
193  self::STATUS_CANCELLED,
194  self::STATUS_PROCESSED,
195  self::STATUS_FINISHED,
196  self::STATUS_FAILED,
197  );
198  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ isToBeCancelled()

ilBackgroundTask::isToBeCancelled ( )

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

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

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

◆ preparePropertiesForDB()

ilBackgroundTask::preparePropertiesForDB ( )
protected

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

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

Referenced by doCreate(), and doUpdate().

343  {
344  return array(
345  "user_id" => array("integer", $this->getUserId()),
346  "start_date" => array("timestamp", $this->getStartDate()->get(IL_CAL_DATETIME)),
347  "status" => array("text", $this->getStatus()),
348  "steps" => array("integer", $this->getSteps()),
349  "cstep" => array("integer", $this->getCurrentStep()),
350  "handler" => array("string", $this->getHandlerId()),
351  "params" => array("string", is_array($this->getParams())
352  ? serialize($this->getParams())
353  : null)
354  );
355  }
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 288 of file class.ilBackgroundTask.php.

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

289  {
290  $this->log->debug($this->getHandlerId());
291  // does not exist yet?
292  if (!$this->exists)
293  {
294  $this->doCreate();
295  }
296  else
297  {
298  $this->doUpdate();
299  }
300  }
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 248 of file class.ilBackgroundTask.php.

References getSteps().

Referenced by doRead().

249  {
250  $this->current_step = min(abs($a_val), $this->getSteps());
251  }
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 112 of file class.ilBackgroundTask.php.

Referenced by doRead().

113  {
114  $this->handler = $a_val;
115  }
+ 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 132 of file class.ilBackgroundTask.php.

Referenced by doCreate(), and doRead().

133  {
134  $this->id = (int)$a_val;
135  }
+ 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 268 of file class.ilBackgroundTask.php.

Referenced by doRead().

269  {
270  $this->params = $a_params;
271  }
+ 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 172 of file class.ilBackgroundTask.php.

Referenced by doCreate(), and doRead().

173  {
174  $this->start_date = $a_val;
175  }
+ 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 205 of file class.ilBackgroundTask.php.

References getValidStatus().

Referenced by doRead().

206  {
207  if(in_array($a_val, $this->getValidStatus()))
208  {
209  $this->status = $a_val;
210  }
211  }
+ 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 228 of file class.ilBackgroundTask.php.

Referenced by doRead().

229  {
230  $this->steps = abs($a_val);
231  }
+ 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 152 of file class.ilBackgroundTask.php.

Referenced by doRead().

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