ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilECSTaskScheduler Class Reference
+ Collaboration diagram for ilECSTaskScheduler:

Public Member Functions

 getServer ()
 Get server setting. More...
 
 startTaskExecution ()
 Start Tasks. More...
 
 checkNextExecution ()
 Start. More...
 

Static Public Member Functions

static _getInstanceByServerId ($a_server_id)
 get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTaskExecution More...
 
static start ()
 Start task scheduler for each server instance. More...
 
static startExecution ()
 Static version iterates over all active instances. More...
 

Data Fields

const MAX_TASKS = 30
 

Protected Member Functions

 initNextExecution ()
 Call next task scheduler run. More...
 

Protected Attributes

 $log
 
 $settings = null
 
 $db
 

Private Member Functions

 __construct (ilECSSetting $setting)
 Singleton constructor. More...
 
 readEvents ()
 Read EContent. More...
 
 handleEvents ()
 Handle events. More...
 
 handleDeprecatedAccounts ()
 Delete deprecate ECS accounts. More...
 
 readMIDs ()
 Read MID's of this installation. More...
 

Private Attributes

 $event_reader = null
 
 $mids = array()
 

Static Private Attributes

static $instances = array()
 

Detailed Description

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 32 of file class.ilECSTaskScheduler.php.

Constructor & Destructor Documentation

◆ __construct()

ilECSTaskScheduler::__construct ( ilECSSetting  $setting)
private

Singleton constructor.

public

Definition at line 56 of file class.ilECSTaskScheduler.php.

References $GLOBALS, $ilDB, $ilLog, and settings().

57  {
58  global $ilDB,$ilLog;
59 
60  $this->db = $ilDB;
61 
62  $this->log = $GLOBALS['DIC']->logger()->wsrv();
63 
64  include_once('./Services/WebServices/ECS/classes/class.ilECSSetting.php');
65  $this->settings = $setting;
66  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
settings()
Definition: settings.php:2
global $ilDB
+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstanceByServerId()

static ilECSTaskScheduler::_getInstanceByServerId (   $a_server_id)
static

get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTaskExecution

private

Returns
ilECSTaskScheduler

Definition at line 80 of file class.ilECSTaskScheduler.php.

References ilECSSetting\getInstanceByServerId().

Referenced by ilSoapUtils\handleECSTasks(), and ilECSSettingsGUI\readAll().

81  {
82  if (self::$instances[$a_server_id]) {
83  return self::$instances[$a_server_id];
84  }
85  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
86  return self::$instances[$a_server_id] =
89  );
90  }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkNextExecution()

ilECSTaskScheduler::checkNextExecution ( )

Start.

public

Definition at line 348 of file class.ilECSTaskScheduler.php.

References $ilDB, $query, settings(), and time.

349  {
350  global $ilDB;
351 
352 
353  if (!$this->settings->isEnabled()) {
354  return false;
355  }
356 
357  if (!$this->settings->checkImportId()) {
358  $this->log->warning('Import ID is deleted or not of type "category". Aborting');
359  return false;
360  }
361 
362  // check next task excecution time:
363  // If it's greater than time() directly increase this value with the polling time
364  /* synchronized { */
365  $query = 'UPDATE settings SET ' .
366  'value = ' . $ilDB->quote(time() + $this->settings->getPollingTime(), 'text') . ' ' .
367  'WHERE module = ' . $ilDB->quote('ecs', 'text') . ' ' .
368  'AND keyword = ' . $ilDB->quote('next_execution_' . $this->settings->getServerId(), 'text') . ' ' .
369  'AND value < ' . $ilDB->quote(time(), 'text');
370  $affected_rows = $ilDB->manipulate($query);
371  /* } */
372 
373 
374  if (!$affected_rows) {
375  // Nothing to do
376  return false;
377  }
378  return true;
379  }
$query
settings()
Definition: settings.php:2
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:

◆ getServer()

ilECSTaskScheduler::getServer ( )

Get server setting.

Returns
ilECSSetting

Definition at line 129 of file class.ilECSTaskScheduler.php.

References $settings.

Referenced by handleEvents(), readEvents(), and readMIDs().

130  {
131  return $this->settings;
132  }
+ Here is the caller graph for this function:

◆ handleDeprecatedAccounts()

ilECSTaskScheduler::handleDeprecatedAccounts ( )
private

Delete deprecate ECS accounts.

private

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

References $ilDB, $query, $res, $row, ilDBConstants\FETCHMODE_OBJECT, ilObjectFactory\getInstanceByObjId(), and time.

Referenced by startTaskExecution().

297  {
298  global $ilDB;
299 
300  $query = "SELECT usr_id FROM usr_data WHERE auth_mode = 'ecs' " .
301  "AND time_limit_until < " . time() . " " .
302  "AND time_limit_unlimited = 0 " .
303  "AND (time_limit_until - time_limit_from) < 7200";
304  $res = $ilDB->query($query);
305  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
306  if ($user_obj = ilObjectFactory::getInstanceByObjId($row->usr_id, false)) {
307  $this->log->write(__METHOD__ . ': Deleting deprecated ECS user account ' . $user_obj->getLogin());
308  $user_obj->delete();
309  }
310  // only one user
311  break;
312  }
313  return true;
314  }
foreach($_POST as $key=> $value) $res
$query
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
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:

◆ handleEvents()

ilECSTaskScheduler::handleEvents ( )
private

Handle events.

private

Definition at line 181 of file class.ilECSTaskScheduler.php.

References $GLOBALS, $handler, $i, $res, array, ilECSEvent\CREATED, ilECSEvent\DESTROYED, ilRemoteObjectBase\getInstanceByEventType(), getServer(), ilECSEvent\NEW_EXPORT, ilECSEventQueueReader\TYPE_CMS_COURSE_MEMBERS, ilECSEventQueueReader\TYPE_CMS_COURSES, ilECSEventQueueReader\TYPE_COURSE_URLS, ilECSEventQueueReader\TYPE_DIRECTORY_TREES, ilECSEventQueueReader\TYPE_ENROLMENT_STATUS, ilECSEventQueueReader\TYPE_REMOTE_CATEGORY, ilECSEventQueueReader\TYPE_REMOTE_COURSE, ilECSEventQueueReader\TYPE_REMOTE_FILE, ilECSEventQueueReader\TYPE_REMOTE_GLOSSARY, ilECSEventQueueReader\TYPE_REMOTE_GROUP, ilECSEventQueueReader\TYPE_REMOTE_LEARNING_MODULE, ilECSEventQueueReader\TYPE_REMOTE_TEST, ilECSEventQueueReader\TYPE_REMOTE_WIKI, and ilECSEvent\UPDATED.

Referenced by startTaskExecution().

182  {
183  include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php';
184 
185  for ($i = 0;$i < self::MAX_TASKS;$i++) {
186  if (!$event = $this->event_reader->shift()) {
187  $this->log->write(__METHOD__ . ': No more pending events found. DONE');
188  break;
189  }
190 
191  $this->log->write(print_r($event, true));
192 
193  // determine event handler
194 
195  $event_ignored = false;
196  switch ($event['type']) {
205  include_once 'Services/WebServices/ECS/classes/class.ilRemoteObjectBase.php';
207  $this->log->write("got handler " . get_class($handler));
208  break;
209 
211  $this->log->debug('Handling new cms tree event.');
212  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeCommandQueueHandler.php';
214  break;
215 
217  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseCommandQueueHandler.php';
219  break;
220 
222  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseMemberCommandQueueHandler.php';
224  break;
225 
227  $this->log->write(__METHOD__ . ': Ignoring event type in queue ' . $event['type']);
228  $event_ignored = true;
229  break;
230 
232  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusCommandQueueHandler.php';
234  break;
235 
236  default:
237 
238  $this->log->warning('Unknown type in queue, raising new event handling event: ' . $event['type']);
239  $event_ignored = true;
240 
241  $GLOBALS['ilAppEventHandler']->raise(
242  'Services/WebServices/ECS',
243  'newEcsEvent',
244  array('event' => $event)
245  );
246  break;
247  }
248 
249  if ($event_ignored) {
250  $this->event_reader->delete($event['event_id']);
251  continue;
252  }
253 
254  $res = false;
255  switch ($event['op']) {
257  // DEPRECATED?
258  // $this->handleNewlyCreate($event['id']);
259  // $this->log->write(__METHOD__.': Handling new creation. DONE');
260  break;
261 
263  $res = $handler->handleDelete($this->getServer(), $event['id'], $this->mids);
264  $this->log->write(__METHOD__ . ': Handling delete. DONE');
265  break;
266 
267  case ilECSEvent::CREATED:
268  $res = $handler->handleCreate($this->getServer(), $event['id'], $this->mids);
269  $this->log->write(__METHOD__ . ': Handling create. DONE');
270  break;
271 
272  case ilECSEvent::UPDATED:
273  $res = $handler->handleUpdate($this->getServer(), $event['id'], $this->mids);
274  $this->log->write(__METHOD__ . ': Handling update. DONE');
275  break;
276 
277  default:
278  $this->log->write(__METHOD__ . ': Unknown event operation in queue ' . $event['op']);
279  break;
280  }
281  if ($res) {
282  $this->log->write(__METHOD__ . ': Processing of event done ' . $event['event_id']);
283  $this->event_reader->delete($event['event_id']);
284  } else {
285  $this->log->write(__METHOD__ . ': Processing of event failed ' . $event['event_id']);
286  }
287  }
288  }
getServer()
Get server setting.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getInstanceByEventType($a_type)
Get instance by ilECSEvent(QueueReader) type.
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
$handler
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initNextExecution()

ilECSTaskScheduler::initNextExecution ( )
protected

Call next task scheduler run.

Definition at line 385 of file class.ilECSTaskScheduler.php.

References $_COOKIE, $client_id, $ilLog, $res, ilSession\_duplicate(), array, ilSoapFunctions\handleECSTasks(), and settings().

386  {
387  global $ilLog;
388 
389  // Start task execution as backend process
390  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
391 
392  $soap_client = new ilSoapClient();
393  $soap_client->setResponseTimeout(1);
394  $soap_client->enableWSDL(true);
395 
396  $new_session_id = ilSession::_duplicate($_COOKIE['PHPSESSID']);
397  $client_id = $_COOKIE['ilClientId'];
398 
399  if ($soap_client->init() and 0) {
400  $this->log->info('Calling soap handleECSTasks method...');
401  $res = $soap_client->call('handleECSTasks', array($new_session_id . '::' . $client_id,$this->settings->getServerId()));
402  } else {
403  $this->log->info('SOAP call failed. Calling clone method manually. ');
404  include_once('./webservice/soap/include/inc.soap_functions.php');
405  $res = ilSoapFunctions::handleECSTasks($new_session_id . '::' . $client_id, $this->settings->getServerId());
406  }
407  }
$_COOKIE['client_id']
Definition: server.php:9
static handleECSTasks($sid, $a_server_id)
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
settings()
Definition: settings.php:2
static _duplicate($a_session_id)
Duplicate session.
$client_id
+ Here is the call graph for this function:

◆ readEvents()

ilECSTaskScheduler::readEvents ( )
private

Read EContent.

private

Definition at line 164 of file class.ilECSTaskScheduler.php.

References getServer().

Referenced by startTaskExecution().

165  {
166  try {
167  include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
168  $this->event_reader = new ilECSEventQueueReader($this->getServer()->getServerId());
169  $this->event_reader->refresh();
170  } catch (ilException $exc) {
171  throw $exc;
172  }
173  }
getServer()
Get server setting.
Reads ECS events and stores them in the database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readMIDs()

ilECSTaskScheduler::readMIDs ( )
private

Read MID's of this installation.

private

Definition at line 322 of file class.ilECSTaskScheduler.php.

References $reader, array, ilECSCommunityReader\getInstanceByServerId(), and getServer().

Referenced by startTaskExecution().

323  {
324  try {
325  $this->mids = array();
326 
327  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
329  foreach ($reader->getCommunities() as $com) {
330  foreach ($com->getParticipants() as $part) {
331  if ($part->isSelf()) {
332  $this->mids[] = $part->getMID();
333  }
334  }
335  }
336  } catch (ilException $exc) {
337  throw $exc;
338  }
339  }
getServer()
Get server setting.
static getInstanceByServerId($a_server_id)
Get instance by server id.
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

static ilECSTaskScheduler::start ( )
static

Start task scheduler for each server instance.

Definition at line 95 of file class.ilECSTaskScheduler.php.

References $server, ilContext\CONTEXT_WEB, ilECSServerSettings\getInstance(), and ilContext\getType().

Referenced by ilInitialisation\initILIAS().

96  {
97  include_once './Services/Context/classes/class.ilContext.php';
99  return;
100  }
101 
102  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
104  foreach ($servers->getServers() as $server) {
105  $sched = new ilECSTaskScheduler($server);
106  if ($sched->checkNextExecution()) {
107  $sched->initNextExecution();
108  }
109  }
110  }
static getInstance()
Get singleton instance.
$server
Definition: getUserInfo.php:12
const CONTEXT_WEB
static getType()
Get context type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startExecution()

static ilECSTaskScheduler::startExecution ( )
static

Static version iterates over all active instances.

Definition at line 115 of file class.ilECSTaskScheduler.php.

References $server, and ilECSServerSettings\getInstance().

116  {
117  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
119  foreach ($server->getServers() as $server) {
120  $sched = new ilECSTaskScheduler($server);
121  $sched->startTaskExecution();
122  }
123  }
static getInstance()
Get singleton instance.
$server
Definition: getUserInfo.php:12
+ Here is the call graph for this function:

◆ startTaskExecution()

ilECSTaskScheduler::startTaskExecution ( )

Start Tasks.

private

Definition at line 141 of file class.ilECSTaskScheduler.php.

References $ilLog, handleDeprecatedAccounts(), handleEvents(), readEvents(), and readMIDs().

142  {
143  global $ilLog;
144 
145  try {
146  $this->readMIDs();
147  $this->readEvents();
148  $this->handleEvents();
149 
150  $this->handleDeprecatedAccounts();
151  } catch (ilException $exc) {
152  $this->log->warning('Cannot start ecs task execution: ' . $exc->getMessage());
153  return false;
154  }
155  return true;
156  }
readMIDs()
Read MID&#39;s of this installation.
handleDeprecatedAccounts()
Delete deprecate ECS accounts.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilECSTaskScheduler::$db
protected

Definition at line 46 of file class.ilECSTaskScheduler.php.

◆ $event_reader

ilECSTaskScheduler::$event_reader = null
private

Definition at line 43 of file class.ilECSTaskScheduler.php.

◆ $instances

ilECSTaskScheduler::$instances = array()
staticprivate

Definition at line 36 of file class.ilECSTaskScheduler.php.

◆ $log

ilECSTaskScheduler::$log
protected

Definition at line 41 of file class.ilECSTaskScheduler.php.

◆ $mids

ilECSTaskScheduler::$mids = array()
private

Definition at line 48 of file class.ilECSTaskScheduler.php.

◆ $settings

ilECSTaskScheduler::$settings = null
protected

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

Referenced by getServer().

◆ MAX_TASKS

const ilECSTaskScheduler::MAX_TASKS = 30

Definition at line 34 of file class.ilECSTaskScheduler.php.


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