ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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

 $settings = null
 
 $log = 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 52 of file class.ilECSTaskScheduler.php.

References $ilDB, and $ilLog.

53  {
54  global $ilDB,$ilLog;
55 
56  $this->db = $ilDB;
57  $this->log = $ilLog;
58 
59  include_once('./Services/WebServices/ECS/classes/class.ilECSSetting.php');
60  $this->settings = $setting;
61  }
global $ilDB

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 75 of file class.ilECSTaskScheduler.php.

References ilECSSetting\getInstanceByServerId().

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

76  {
77  if(self::$instances[$a_server_id])
78  {
79  return self::$instances[$a_server_id];
80  }
81  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
82  return self::$instances[$a_server_id] =
85  );
86  }
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 369 of file class.ilECSTaskScheduler.php.

References $ilDB, $ilLog, and $query.

370  {
371  global $ilLog, $ilDB;
372 
373 
374  if(!$this->settings->isEnabled())
375  {
376  return false;
377  }
378 
379  if(!$this->settings->checkImportId())
380  {
381  $this->log->write(__METHOD__.': Import ID is deleted or not of type "category". Aborting');
382  return false;
383  }
384 
385  // check next task excecution time:
386  // If it's greater than time() directly increase this value with the polling time
387  /* synchronized { */
388  $query = 'UPDATE settings SET '.
389  'value = '.$ilDB->quote(time() + $this->settings->getPollingTime(),'text').' '.
390  'WHERE module = '.$ilDB->quote('ecs','text').' '.
391  'AND keyword = '.$ilDB->quote('next_execution_'.$this->settings->getServerId(),'text').' '.
392  'AND value < '.$ilDB->quote(time(),'text');
393  $affected_rows = $ilDB->manipulate($query);
394  /* } */
395 
396 
397  if(!$affected_rows)
398  {
399  // Nothing to do
400  return false;
401  }
402  return true;
403  }
global $ilDB

◆ 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 308 of file class.ilECSTaskScheduler.php.

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, and ilObjectFactory\getInstanceByObjId().

Referenced by startTaskExecution().

309  {
310  global $ilDB;
311 
312  $query = "SELECT usr_id FROM usr_data WHERE auth_mode = 'ecs' ".
313  "AND time_limit_until < ".time()." ".
314  "AND time_limit_unlimited = 0 ".
315  "AND (time_limit_until - time_limit_from) < 7200";
316  $res = $ilDB->query($query);
317  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
318  {
319  if($user_obj = ilObjectFactory::getInstanceByObjId($row->usr_id,false))
320  {
321  $this->log->write(__METHOD__.': Deleting deprecated ECS user account '.$user_obj->getLogin());
322  $user_obj->delete();
323  }
324  // only one user
325  break;
326  }
327  return true;
328  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
global $ilDB
+ 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 187 of file class.ilECSTaskScheduler.php.

References $GLOBALS, $res, ilECSEvent\CREATED, ilECSEvent\DESTROYED, ilRemoteObjectBase\getInstanceByEventType(), ilLoggerFactory\getRootLogger(), 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().

188  {
189  include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php';
190 
191  for($i = 0;$i < self::MAX_TASKS;$i++)
192  {
193  if(!$event = $this->event_reader->shift())
194  {
195  $this->log->write(__METHOD__.': No more pending events found. DONE');
196  break;
197  }
198 
199  $this->log->write(print_r($event, true));
200 
201  // determine event handler
202 
203  $event_ignored = false;
204  switch($event['type'])
205  {
214  include_once 'Services/WebServices/ECS/classes/class.ilRemoteObjectBase.php';
215  $handler = ilRemoteObjectBase::getInstanceByEventType($event['type']);
216  $this->log->write("got handler ".get_class($handler));
217  break;
218 
220  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeCommandQueueHandler.php';
221  $handler = new ilECSCmsTreeCommandQueueHandler($this->getServer());
222  break;
223 
225  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseCommandQueueHandler.php';
226  $handler = new ilECSCmsCourseCommandQueueHandler($this->getServer());
227  break;
228 
230  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseMemberCommandQueueHandler.php';
231  $handler = new ilECSCmsCourseMemberCommandQueueHandler($this->getServer());
232  break;
233 
235  $this->log->write(__METHOD__.': Ignoring event type in queue '.$event['type']);
236  $event_ignored = true;
237  break;
238 
240  include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusCommandQueueHandler.php';
241  $handler = new ilECSEnrolmentStatusCommandQueueHandler($this->getServer());
242  break;
243 
244  default:
245  ilLoggerFactory::getRootLogger()->warning('Unknown type in queue, raising new event handling event: '. $event['type']);
246  $event_ignored = true;
247 
248  $GLOBALS['ilAppEventHandler']->raise(
249  'Services/WebServices/ECS',
250  'newEcsEvent',
251  array('event' => $event)
252  );
253  break;
254  }
255 
256  if($event_ignored)
257  {
258  $this->event_reader->delete($event['event_id']);
259  continue;
260  }
261 
262  $res = false;
263  switch($event['op'])
264  {
266  // DEPRECATED?
267  // $this->handleNewlyCreate($event['id']);
268  // $this->log->write(__METHOD__.': Handling new creation. DONE');
269  break;
270 
272  $res = $handler->handleDelete($this->getServer(), $event['id'],$this->mids);
273  $this->log->write(__METHOD__.': Handling delete. DONE');
274  break;
275 
276  case ilECSEvent::CREATED:
277  $res = $handler->handleCreate($this->getServer(), $event['id'], $this->mids);
278  $this->log->write(__METHOD__.': Handling create. DONE');
279  break;
280 
281  case ilECSEvent::UPDATED:
282  $res = $handler->handleUpdate($this->getServer(), $event['id'], $this->mids);
283  $this->log->write(__METHOD__.': Handling update. DONE');
284  break;
285 
286  default:
287  $this->log->write(__METHOD__.': Unknown event operation in queue '.$event['op']);
288  break;
289  }
290  if($res)
291  {
292  $this->log->write(__METHOD__.': Processing of event done '.$event['event_id']);
293  $this->event_reader->delete($event['event_id']);
294  }
295  else
296  {
297  $this->log->write(__METHOD__.': Processing of event failed '.$event['event_id']);
298  }
299  }
300  }
getServer()
Get server setting.
static getInstanceByEventType($a_type)
Get instance by ilECSEvent(QueueReader) type.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
static getRootLogger()
The unique root logger has a fixed error level.
+ 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 409 of file class.ilECSTaskScheduler.php.

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

410  {
411  global $ilLog;
412 
413  // Start task execution as backend process
414  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
415 
416  $soap_client = new ilSoapClient();
417  $soap_client->setResponseTimeout(1);
418  $soap_client->enableWSDL(true);
419 
420  #$ilLog->write(__METHOD__.': Trying to call Soap client...');
421  $new_session_id = ilSession::_duplicate($_COOKIE['PHPSESSID']);
422  $client_id = $_COOKIE['ilClientId'];
423 
424  if($soap_client->init() and 0)
425  {
426  $ilLog->write(__METHOD__.': Calling soap handleECSTasks method...');
427  $res = $soap_client->call('handleECSTasks',array($new_session_id.'::'.$client_id,$this->settings->getServerId()));
428  }
429  else
430  {
431  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
432  include_once('./webservice/soap/include/inc.soap_functions.php');
433  $res = ilSoapFunctions::handleECSTasks($new_session_id.'::'.$client_id,$this->settings->getServerId());
434  }
435  }
$_COOKIE["ilClientId"]
Definition: cron.php:11
static handleECSTasks($sid, $a_server_id)
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 167 of file class.ilECSTaskScheduler.php.

References getServer().

Referenced by startTaskExecution().

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

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

Referenced by startTaskExecution().

337  {
338  try
339  {
340  $this->mids = array();
341 
342  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
344  foreach($reader->getCommunities() as $com)
345  {
346  foreach($com->getParticipants() as $part)
347  {
348  if($part->isSelf())
349  {
350  $this->mids[] = $part->getMID();
351  #$this->log->write('Fetch MID: '.$part->getMID());
352  }
353  }
354  }
355  }
356  catch(ilException $exc)
357  {
358  throw $exc;
359  }
360  }
Base class for ILIAS Exception handling.
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 91 of file class.ilECSTaskScheduler.php.

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

Referenced by ilInitialisation\initILIAS().

92  {
93  include_once './Services/Context/classes/class.ilContext.php';
95  {
96  return;
97  }
98 
99  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
101  foreach($servers->getServers() as $server)
102  {
103  $sched = new ilECSTaskScheduler($server);
104  if($sched->checkNextExecution())
105  {
106  $sched->initNextExecution();
107  }
108  }
109  }
static getInstance()
Get singleton instance.
$server
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 114 of file class.ilECSTaskScheduler.php.

References $server, and ilECSServerSettings\getInstance().

115  {
116  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
118  foreach($server->getServers() as $server)
119  {
120  $sched = new ilECSTaskScheduler($server);
121  $sched->startTaskExecution();
122  }
123  }
static getInstance()
Get singleton instance.
$server
+ 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  {
147  $this->readMIDs();
148  $this->readEvents();
149  $this->handleEvents();
150 
151  $this->handleDeprecatedAccounts();
152  }
153  catch(ilException $exc)
154  {
155  $this->log->write(__METHOD__.': Caught exception: '.$exc->getMessage());
156  return false;
157  }
158  return true;
159  }
Base class for ILIAS Exception handling.
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 42 of file class.ilECSTaskScheduler.php.

◆ $event_reader

ilECSTaskScheduler::$event_reader = null
private

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

◆ $instances

ilECSTaskScheduler::$instances = array()
staticprivate

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

◆ $log

ilECSTaskScheduler::$log = null
protected

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

◆ $mids

ilECSTaskScheduler::$mids = array()
private

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

◆ $settings

ilECSTaskScheduler::$settings = null
protected

Definition at line 40 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: