ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 363 of file class.ilECSTaskScheduler.php.

References $ilDB, $ilLog, and $query.

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

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

Referenced by startTaskExecution().

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

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  $this->log->write(__METHOD__.': Unknown event type in queue '.$event['type']);
246  $event_ignored = true;
247  break;
248  }
249 
250  if($event_ignored)
251  {
252  $this->event_reader->delete($event['event_id']);
253  continue;
254  }
255 
256  $res = false;
257  switch($event['op'])
258  {
260  // DEPRECATED?
261  // $this->handleNewlyCreate($event['id']);
262  // $this->log->write(__METHOD__.': Handling new creation. DONE');
263  break;
264 
266  $res = $handler->handleDelete($this->getServer(), $event['id'],$this->mids);
267  $this->log->write(__METHOD__.': Handling delete. DONE');
268  break;
269 
270  case ilECSEvent::CREATED:
271  $res = $handler->handleCreate($this->getServer(), $event['id'], $this->mids);
272  $this->log->write(__METHOD__.': Handling create. DONE');
273  break;
274 
275  case ilECSEvent::UPDATED:
276  $res = $handler->handleUpdate($this->getServer(), $event['id'], $this->mids);
277  $this->log->write(__METHOD__.': Handling update. DONE');
278  break;
279 
280  default:
281  $this->log->write(__METHOD__.': Unknown event operation in queue '.$event['op']);
282  break;
283  }
284  if($res)
285  {
286  $this->log->write(__METHOD__.': Processing of event done '.$event['event_id']);
287  $this->event_reader->delete($event['event_id']);
288  }
289  else
290  {
291  $this->log->write(__METHOD__.': Processing of event failed '.$event['event_id']);
292  }
293  }
294  }
getServer()
Get server setting.
static getInstanceByEventType($a_type)
Get instance by ilECSEvent(QueueReader) type.
+ 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 403 of file class.ilECSTaskScheduler.php.

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

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

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

Referenced by startTaskExecution().

331  {
332  try
333  {
334  $this->mids = array();
335 
336  include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
338  foreach($reader->getCommunities() as $com)
339  {
340  foreach($com->getParticipants() as $part)
341  {
342  if($part->isSelf())
343  {
344  $this->mids[] = $part->getMID();
345  #$this->log->write('Fetch MID: '.$part->getMID());
346  }
347  }
348  }
349  }
350  catch(ilException $exc)
351  {
352  throw $exc;
353  }
354  }
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: