ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 $DIC, $GLOBALS, $ilDB, $ilLog, and settings().

57  {
58  global $DIC;
59 
60  $ilDB = $DIC['ilDB'];
61  $ilLog = $DIC['ilLog'];
62 
63  $this->db = $ilDB;
64 
65  $this->log = $GLOBALS['DIC']->logger()->wsrv();
66 
67  include_once('./Services/WebServices/ECS/classes/class.ilECSSetting.php');
68  $this->settings = $setting;
69  }
settings()
Definition: settings.php:2
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
global $ilDB
$DIC
Definition: xapitoken.php:46
+ 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 83 of file class.ilECSTaskScheduler.php.

References ilECSSetting\getInstanceByServerId().

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

84  {
85  if (self::$instances[$a_server_id]) {
86  return self::$instances[$a_server_id];
87  }
88  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
89  return self::$instances[$a_server_id] =
92  );
93  }
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 355 of file class.ilECSTaskScheduler.php.

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

356  {
357  global $DIC;
358 
359  $ilDB = $DIC['ilDB'];
360 
361 
362  if (!$this->settings->isEnabled()) {
363  return false;
364  }
365 
366  if (!$this->settings->checkImportId()) {
367  $this->log->warning('Import ID is deleted or not of type "category". Aborting');
368  return false;
369  }
370 
371  // check next task excecution time:
372  // If it's greater than time() directly increase this value with the polling time
373  /* synchronized { */
374  $query = 'UPDATE settings SET ' .
375  'value = ' . $ilDB->quote(time() + $this->settings->getPollingTime(), 'text') . ' ' .
376  'WHERE module = ' . $ilDB->quote('ecs', 'text') . ' ' .
377  'AND keyword = ' . $ilDB->quote('next_execution_' . $this->settings->getServerId(), 'text') . ' ' .
378  'AND value < ' . $ilDB->quote(time(), 'text');
379  $affected_rows = $ilDB->manipulate($query);
380  /* } */
381 
382 
383  if (!$affected_rows) {
384  // Nothing to do
385  return false;
386  }
387  return true;
388  }
settings()
Definition: settings.php:2
$query
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

◆ getServer()

ilECSTaskScheduler::getServer ( )

Get server setting.

Returns
ilECSSetting

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

References $settings.

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

133  {
134  return $this->settings;
135  }
+ Here is the caller graph for this function:

◆ handleDeprecatedAccounts()

ilECSTaskScheduler::handleDeprecatedAccounts ( )
private

Delete deprecate ECS accounts.

private

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

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

Referenced by startTaskExecution().

302  {
303  global $DIC;
304 
305  $ilDB = $DIC['ilDB'];
306 
307  $query = "SELECT usr_id FROM usr_data WHERE auth_mode = 'ecs' " .
308  "AND time_limit_until < " . time() . " " .
309  "AND time_limit_unlimited = 0 " .
310  "AND (time_limit_until - time_limit_from) < 7200";
311  $res = $ilDB->query($query);
312  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
313  if ($user_obj = ilObjectFactory::getInstanceByObjId($row->usr_id, false)) {
314  $this->log->write(__METHOD__ . ': Deleting deprecated ECS user account ' . $user_obj->getLogin());
315  $user_obj->delete();
316  }
317  // only one user
318  break;
319  }
320  return true;
321  }
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
$DIC
Definition: xapitoken.php:46
+ 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 186 of file class.ilECSTaskScheduler.php.

References $GLOBALS, $i, $res, 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().

187  {
188  include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php';
189 
190  for ($i = 0;$i < self::MAX_TASKS;$i++) {
191  if (!$event = $this->event_reader->shift()) {
192  $this->log->write(__METHOD__ . ': No more pending events found. DONE');
193  break;
194  }
195 
196  $this->log->write(print_r($event, true));
197 
198  // determine event handler
199 
200  $event_ignored = false;
201  switch ($event['type']) {
210  include_once 'Services/WebServices/ECS/classes/class.ilRemoteObjectBase.php';
211  $handler = ilRemoteObjectBase::getInstanceByEventType($event['type']);
212  $this->log->write("got handler " . get_class($handler));
213  break;
214 
216  $this->log->debug('Handling new cms tree event.');
217  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeCommandQueueHandler.php';
218  $handler = new ilECSCmsTreeCommandQueueHandler($this->getServer());
219  break;
220 
222  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseCommandQueueHandler.php';
223  $handler = new ilECSCmsCourseCommandQueueHandler($this->getServer());
224  break;
225 
227  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseMemberCommandQueueHandler.php';
228  $handler = new ilECSCmsCourseMemberCommandQueueHandler($this->getServer());
229  break;
230 
232  $this->log->write(__METHOD__ . ': Ignoring event type in queue ' . $event['type']);
233  $event_ignored = true;
234  break;
235 
237  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusCommandQueueHandler.php';
238  $handler = new ilECSEnrolmentStatusCommandQueueHandler($this->getServer());
239  break;
240 
241  default:
242 
243  $this->log->warning('Unknown type in queue, raising new event handling event: ' . $event['type']);
244  $event_ignored = true;
245 
246  $GLOBALS['DIC']['ilAppEventHandler']->raise(
247  'Services/WebServices/ECS',
248  'newEcsEvent',
249  array('event' => $event)
250  );
251  break;
252  }
253 
254  if ($event_ignored) {
255  $this->event_reader->delete($event['event_id']);
256  continue;
257  }
258 
259  $res = false;
260  switch ($event['op']) {
262  // DEPRECATED?
263  // $this->handleNewlyCreate($event['id']);
264  // $this->log->write(__METHOD__.': Handling new creation. DONE');
265  break;
266 
268  $res = $handler->handleDelete($this->getServer(), $event['id'], $this->mids);
269  $this->log->write(__METHOD__ . ': Handling delete. DONE');
270  break;
271 
272  case ilECSEvent::CREATED:
273  $res = $handler->handleCreate($this->getServer(), $event['id'], $this->mids);
274  $this->log->write(__METHOD__ . ': Handling create. DONE');
275  break;
276 
277  case ilECSEvent::UPDATED:
278  $res = $handler->handleUpdate($this->getServer(), $event['id'], $this->mids);
279  $this->log->write(__METHOD__ . ': Handling update. DONE');
280  break;
281 
282  default:
283  $this->log->write(__METHOD__ . ': Unknown event operation in queue ' . $event['op']);
284  break;
285  }
286  if ($res) {
287  $this->log->write(__METHOD__ . ': Processing of event done ' . $event['event_id']);
288  $this->event_reader->delete($event['event_id']);
289  } else {
290  $this->log->write(__METHOD__ . ': Processing of event failed ' . $event['event_id']);
291  }
292  }
293  }
getServer()
Get server setting.
static getInstanceByEventType($a_type)
Get instance by ilECSEvent(QueueReader) type.
foreach($_POST as $key=> $value) $res
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$i
Definition: metadata.php:24
+ 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 394 of file class.ilECSTaskScheduler.php.

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

395  {
396  global $DIC;
397 
398  $ilLog = $DIC['ilLog'];
399 
400  // Start task execution as backend process
401  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
402 
403  $soap_client = new ilSoapClient();
404  $soap_client->setResponseTimeout(1);
405  $soap_client->enableWSDL(true);
406 
407  $new_session_id = ilSession::_duplicate($_COOKIE[session_name()]);
408  $client_id = $_COOKIE['ilClientId'];
409 
410  if ($soap_client->init() and 0) {
411  $this->log->info('Calling soap handleECSTasks method...');
412  $res = $soap_client->call('handleECSTasks', array($new_session_id . '::' . $client_id,$this->settings->getServerId()));
413  } else {
414  $this->log->info('SOAP call failed. Calling clone method manually. ');
415  include_once('./webservice/soap/include/inc.soap_functions.php');
416  $res = ilSoapFunctions::handleECSTasks($new_session_id . '::' . $client_id, $this->settings->getServerId());
417  }
418  }
settings()
Definition: settings.php:2
static handleECSTasks($sid, $a_server_id)
foreach($_POST as $key=> $value) $res
static _duplicate($a_session_id)
Duplicate session.
$DIC
Definition: xapitoken.php:46
$client_id
$_COOKIE[session_name()]
Definition: xapitoken.php:39
+ Here is the call graph for this function:

◆ readEvents()

ilECSTaskScheduler::readEvents ( )
private

Read EContent.

private

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

References getServer().

Referenced by startTaskExecution().

170  {
171  try {
172  include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
173  $this->event_reader = new ilECSEventQueueReader($this->getServer()->getServerId());
174  $this->event_reader->refresh();
175  } catch (ilException $exc) {
176  throw $exc;
177  }
178  }
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 329 of file class.ilECSTaskScheduler.php.

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

Referenced by startTaskExecution().

330  {
331  try {
332  $this->mids = array();
333 
334  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
336  foreach ($reader->getCommunities() as $com) {
337  foreach ($com->getParticipants() as $part) {
338  if ($part->isSelf()) {
339  $this->mids[] = $part->getMID();
340  }
341  }
342  }
343  } catch (ilException $exc) {
344  throw $exc;
345  }
346  }
getServer()
Get server setting.
static getInstanceByServerId($a_server_id)
Get instance by server id.
+ 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 98 of file class.ilECSTaskScheduler.php.

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

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

◆ startExecution()

static ilECSTaskScheduler::startExecution ( )
static

Static version iterates over all active instances.

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

References $server, and ilECSServerSettings\getInstance().

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

◆ startTaskExecution()

ilECSTaskScheduler::startTaskExecution ( )

Start Tasks.

private

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

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

145  {
146  global $DIC;
147 
148  $ilLog = $DIC['ilLog'];
149 
150  try {
151  $this->readMIDs();
152  $this->readEvents();
153  $this->handleEvents();
154 
155  $this->handleDeprecatedAccounts();
156  } catch (ilException $exc) {
157  $this->log->warning('Cannot start ecs task execution: ' . $exc->getMessage());
158  return false;
159  }
160  return true;
161  }
readMIDs()
Read MID&#39;s of this installation.
handleDeprecatedAccounts()
Delete deprecate ECS accounts.
$DIC
Definition: xapitoken.php:46
+ 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: