ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

@access public

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

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

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

+ 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

@access private

Returns
ilECSTaskScheduler

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

81 {
82 if(self::$instances[$a_server_id])
83 {
84 return self::$instances[$a_server_id];
85 }
86 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
87 return self::$instances[$a_server_id] =
90 );
91 }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.

References ilECSSetting\getInstanceByServerId().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkNextExecution()

ilECSTaskScheduler::checkNextExecution ( )

Start.

@access public

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

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

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

+ Here is the call graph for this function:

◆ getServer()

ilECSTaskScheduler::getServer ( )

Get server setting.

Returns
ilECSSetting

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

References $settings.

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

+ Here is the caller graph for this function:

◆ handleDeprecatedAccounts()

ilECSTaskScheduler::handleDeprecatedAccounts ( )
private

Delete deprecate ECS accounts.

@access private

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

316 {
317 global $ilDB;
318
319 $query = "SELECT usr_id FROM usr_data WHERE auth_mode = 'ecs' ".
320 "AND time_limit_until < ".time()." ".
321 "AND time_limit_unlimited = 0 ".
322 "AND (time_limit_until - time_limit_from) < 7200";
323 $res = $ilDB->query($query);
324 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
325 {
326 if($user_obj = ilObjectFactory::getInstanceByObjId($row->usr_id,false))
327 {
328 $this->log->write(__METHOD__.': Deleting deprecated ECS user account '.$user_obj->getLogin());
329 $user_obj->delete();
330 }
331 // only one user
332 break;
333 }
334 return true;
335 }
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id

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

Referenced by startTaskExecution().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleEvents()

ilECSTaskScheduler::handleEvents ( )
private

Handle events.

@access private

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

193 {
194 include_once './Services/WebServices/ECS/classes/class.ilECSEvent.php';
195
196 for($i = 0;$i < self::MAX_TASKS;$i++)
197 {
198 if(!$event = $this->event_reader->shift())
199 {
200 $this->log->write(__METHOD__.': No more pending events found. DONE');
201 break;
202 }
203
204 $this->log->write(print_r($event, true));
205
206 // determine event handler
207
208 $event_ignored = false;
209 switch($event['type'])
210 {
219 include_once 'Services/WebServices/ECS/classes/class.ilRemoteObjectBase.php';
220 $handler = ilRemoteObjectBase::getInstanceByEventType($event['type']);
221 $this->log->write("got handler ".get_class($handler));
222 break;
223
225 $this->log->debug('Handling new cms tree event.');
226 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeCommandQueueHandler.php';
227 $handler = new ilECSCmsTreeCommandQueueHandler($this->getServer());
228 break;
229
231 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseCommandQueueHandler.php';
232 $handler = new ilECSCmsCourseCommandQueueHandler($this->getServer());
233 break;
234
236 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCmsCourseMemberCommandQueueHandler.php';
237 $handler = new ilECSCmsCourseMemberCommandQueueHandler($this->getServer());
238 break;
239
241 $this->log->write(__METHOD__.': Ignoring event type in queue '.$event['type']);
242 $event_ignored = true;
243 break;
244
246 include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusCommandQueueHandler.php';
247 $handler = new ilECSEnrolmentStatusCommandQueueHandler($this->getServer());
248 break;
249
250 default:
251
252 $this->log->warning('Unknown type in queue, raising new event handling event: '. $event['type']);
253 $event_ignored = true;
254
255 $GLOBALS['ilAppEventHandler']->raise(
256 'Services/WebServices/ECS',
257 'newEcsEvent',
258 array('event' => $event)
259 );
260 break;
261 }
262
263 if($event_ignored)
264 {
265 $this->event_reader->delete($event['event_id']);
266 continue;
267 }
268
269 $res = false;
270 switch($event['op'])
271 {
273 // DEPRECATED?
274 // $this->handleNewlyCreate($event['id']);
275 // $this->log->write(__METHOD__.': Handling new creation. DONE');
276 break;
277
279 $res = $handler->handleDelete($this->getServer(), $event['id'],$this->mids);
280 $this->log->write(__METHOD__.': Handling delete. DONE');
281 break;
282
284 $res = $handler->handleCreate($this->getServer(), $event['id'], $this->mids);
285 $this->log->write(__METHOD__.': Handling create. DONE');
286 break;
287
289 $res = $handler->handleUpdate($this->getServer(), $event['id'], $this->mids);
290 $this->log->write(__METHOD__.': Handling update. DONE');
291 break;
292
293 default:
294 $this->log->write(__METHOD__.': Unknown event operation in queue '.$event['op']);
295 break;
296 }
297 if($res)
298 {
299 $this->log->write(__METHOD__.': Processing of event done '.$event['event_id']);
300 $this->event_reader->delete($event['event_id']);
301 }
302 else
303 {
304 $this->log->write(__METHOD__.': Processing of event failed '.$event['event_id']);
305 }
306 }
307 }
getServer()
Get server setting.
static getInstanceByEventType($a_type)
Get instance by ilECSEvent(QueueReader) type.

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

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

416 {
417 global $ilLog;
418
419 // Start task execution as backend process
420 include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
421
422 $soap_client = new ilSoapClient();
423 $soap_client->setResponseTimeout(1);
424 $soap_client->enableWSDL(true);
425
426 $new_session_id = ilSession::_duplicate($_COOKIE['PHPSESSID']);
427 $client_id = $_COOKIE['ilClientId'];
428
429 if($soap_client->init() and 0)
430 {
431 $this->log->info('Calling soap handleECSTasks method...');
432 $res = $soap_client->call('handleECSTasks',array($new_session_id.'::'.$client_id,$this->settings->getServerId()));
433 }
434 else
435 {
436 $this->log->info('SOAP call failed. Calling clone method manually. ');
437 include_once('./webservice/soap/include/inc.soap_functions.php');
438 $res = ilSoapFunctions::handleECSTasks($new_session_id.'::'.$client_id,$this->settings->getServerId());
439 }
440 }
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
static _duplicate($a_session_id)
Duplicate session.
static handleECSTasks($sid, $a_server_id)
$client_id

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

+ Here is the call graph for this function:

◆ readEvents()

ilECSTaskScheduler::readEvents ( )
private

Read EContent.

@access private

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

173 {
174 try
175 {
176 include_once('./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
177 $this->event_reader = new ilECSEventQueueReader($this->getServer()->getServerId());
178 $this->event_reader->refresh();
179 }
180 catch(ilException $exc)
181 {
182 throw $exc;
183 }
184 }
Reads ECS events and stores them in the database.
Base class for ILIAS Exception handling.

References getServer().

Referenced by startTaskExecution().

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

@access private

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

344 {
345 try
346 {
347 $this->mids = array();
348
349 include_once('./Services/WebServices/ECS/classes/class.ilECSCommunityReader.php');
351 foreach($reader->getCommunities() as $com)
352 {
353 foreach($com->getParticipants() as $part)
354 {
355 if($part->isSelf())
356 {
357 $this->mids[] = $part->getMID();
358 }
359 }
360 }
361 }
362 catch(ilException $exc)
363 {
364 throw $exc;
365 }
366 }
static getInstanceByServerId($a_server_id)
Get instance by server id.

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

Referenced by startTaskExecution().

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

97 {
98 include_once './Services/Context/classes/class.ilContext.php';
100 {
101 return;
102 }
103
104 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
106 foreach($servers->getServers() as $server)
107 {
108 $sched = new ilECSTaskScheduler($server);
109 if($sched->checkNextExecution())
110 {
111 $sched->initNextExecution();
112 }
113 }
114 }
const CONTEXT_WEB
static getType()
Get context type.
static getInstance()
Get singleton instance.
$server

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

Referenced by ilInitialisation\initILIAS().

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

120 {
121 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
123 foreach($server->getServers() as $server)
124 {
125 $sched = new ilECSTaskScheduler($server);
126 $sched->startTaskExecution();
127 }
128 }

References $server, and ilECSServerSettings\getInstance().

+ Here is the call graph for this function:

◆ startTaskExecution()

ilECSTaskScheduler::startTaskExecution ( )

Start Tasks.

@access private

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

147 {
148 global $ilLog;
149
150 try
151 {
152 $this->readMIDs();
153 $this->readEvents();
154 $this->handleEvents();
155
157 }
158 catch(ilException $exc)
159 {
160 $this->log->warning('Cannot start ecs task execution: ' . $exc->getMessage());
161 return false;
162 }
163 return true;
164 }
handleDeprecatedAccounts()
Delete deprecate ECS accounts.
readMIDs()
Read MID's of this installation.

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

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

Referenced by handleEvents().


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