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

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

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 }
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 $ilDB

References $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 386 of file class.ilBackgroundTask.php.

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 }

References $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 314 of file class.ilBackgroundTask.php.

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 }
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 $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 372 of file class.ilBackgroundTask.php.

373 {
374 global $ilDB;
375
376 $ilDB->update(
377 self::DB_NAME,
378 $this->preparePropertiesForDB(),
379 array("id" => array("integer", $this->getId()))
380 );
381 }

References $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 278 of file class.ilBackgroundTask.php.

279 {
280 return $this->exists;
281 }

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 69 of file class.ilBackgroundTask.php.

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 }

References $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 238 of file class.ilBackgroundTask.php.

239 {
240 return $this->current_step;
241 }

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 102 of file class.ilBackgroundTask.php.

103 {
104 return $this->handler;
105 }

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 58 of file class.ilBackgroundTask.php.

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 }

References getHandlerId().

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

123 {
124 return $this->id;
125 }

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 258 of file class.ilBackgroundTask.php.

259 {
260 return $this->params;
261 }

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 162 of file class.ilBackgroundTask.php.

163 {
164 return $this->start_date;
165 }

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 182 of file class.ilBackgroundTask.php.

183 {
184 return $this->status;
185 }

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 218 of file class.ilBackgroundTask.php.

219 {
220 return $this->steps;
221 }

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 142 of file class.ilBackgroundTask.php.

143 {
144 return $this->user_id;
145 }

References $user_id.

Referenced by preparePropertiesForDB().

+ Here is the caller graph for this function:

◆ getValidStatus()

ilBackgroundTask::getValidStatus ( )
protected

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

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 }

Referenced by setStatus().

+ Here is the caller graph for this function:

◆ isToBeCancelled()

ilBackgroundTask::isToBeCancelled ( )

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

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

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

+ Here is the call graph for this function:

◆ preparePropertiesForDB()

ilBackgroundTask::preparePropertiesForDB ( )
protected

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

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 }
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 288 of file class.ilBackgroundTask.php.

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 }

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 248 of file class.ilBackgroundTask.php.

249 {
250 $this->current_step = min(abs($a_val), $this->getSteps());
251 }

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 112 of file class.ilBackgroundTask.php.

113 {
114 $this->handler = $a_val;
115 }

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 132 of file class.ilBackgroundTask.php.

133 {
134 $this->id = (int)$a_val;
135 }

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 268 of file class.ilBackgroundTask.php.

269 {
270 $this->params = $a_params;
271 }

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 172 of file class.ilBackgroundTask.php.

173 {
174 $this->start_date = $a_val;
175 }

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 205 of file class.ilBackgroundTask.php.

206 {
207 if(in_array($a_val, $this->getValidStatus()))
208 {
209 $this->status = $a_val;
210 }
211 }

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 228 of file class.ilBackgroundTask.php.

229 {
230 $this->steps = abs($a_val);
231 }

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 152 of file class.ilBackgroundTask.php.

153 {
154 $this->user_id = (int)$a_val;
155 }

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: