ILIAS  release_8 Revision v8.19
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...
 

Static Public Member Functions

static _getInstanceByServerId ($a_server_id)
 get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTaskExecution More...
 

Data Fields

const MAX_TASKS = 30
 

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

ilLogger $log
 
ilDBInterface $db
 
ilAppEventHandler $eventHandler
 
ilECSSetting $settings
 
ilECSEventQueueReader $event_reader = null
 
array $mids = array()
 

Static Private Attributes

static array $instances = array()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilECSTaskScheduler::__construct ( ilECSSetting  $setting)
private

Singleton constructor.

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

References $DIC, and ILIAS\Repository\settings().

43  {
44  global $DIC;
45 
46  $this->db = $DIC->database();
47  $this->log = $DIC->logger()->wsrv();
48  $this->eventHandler = $DIC->event();
49 
50  $this->settings = $setting;
51  }
global $DIC
Definition: feed.php:28
+ 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

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

References ilECSSetting\getInstanceByServerId().

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

60  {
61  return self::$instances[$a_server_id] ?? (self::$instances[$a_server_id] =
64  ));
65  }
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getServer()

ilECSTaskScheduler::getServer ( )

Get server setting.

Returns
ilECSSetting

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

References $settings.

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

72  {
73  return $this->settings;
74  }
+ Here is the caller graph for this function:

◆ handleDeprecatedAccounts()

ilECSTaskScheduler::handleDeprecatedAccounts ( )
private

Delete deprecate ECS accounts.

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

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

Referenced by startTaskExecution().

218  : void
219  {
220  $query = "SELECT usr_id FROM usr_data WHERE auth_mode = 'ecs' " .
221  "AND time_limit_until < " . time() . " " .
222  "AND time_limit_unlimited = 0 " .
223  "AND (time_limit_until - time_limit_from) < 7200";
224  $res = $this->db->query($query);
225  if (($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) &&
226  $user_obj = ilObjectFactory::getInstanceByObjId((int) $row->usr_id, false)) {
227  $this->log->info(__METHOD__ . ': Deleting deprecated ECS user account ' . $user_obj->getLogin());
228  $user_obj->delete();
229  }
230  }
$res
Definition: ltiservices.php:69
$query
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleEvents()

ilECSTaskScheduler::handleEvents ( )
private

Handle events.

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

References $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().

107  : void
108  {
109  for ($i = 0;$i < self::MAX_TASKS;$i++) {
110  if (!$event = $this->event_reader->shift()) {
111  $this->log->info(__METHOD__ . ': No more pending events found. DONE');
112  break;
113  }
114 
115  $this->log->info("Eventdump" . print_r($event, true));
116 
117  // determine event handler
118 
119  $event_ignored = false;
120  switch ($event['type']) {
129  $handler = ilRemoteObjectBase::getInstanceByEventType($event['type']);
130  if ($handler) {
131  $this->log->debug("got handler " . get_class($handler));
132  } else {
133  $this->log->error("Could not get handler for :" . $event['type']);
134  }
135  break;
136 
138  $this->log->debug('Handling new cms tree event.');
139  $handler = new ilECSCmsTreeCommandQueueHandler($this->getServer());
140  break;
141 
143  $handler = new ilECSCmsCourseCommandQueueHandler($this->getServer());
144  break;
145 
147  $handler = new ilECSCmsCourseMemberCommandQueueHandler($this->getServer());
148  break;
149 
151  $this->log->info(__METHOD__ . ': Ignoring event type in queue ' . $event['type']);
152  $event_ignored = true;
153  break;
154 
156  $handler = new ilECSEnrolmentStatusCommandQueueHandler($this->getServer());
157  break;
158 
159  default:
160 
161  $this->log->warning('Unknown type in queue, raising new event handling event: ' . $event['type']);
162  $event_ignored = true;
163 
164  $this->eventHandler->raise(
165  'Services/WebServices/ECS',
166  'newEcsEvent',
167  array('event' => $event)
168  );
169  break;
170  }
171 
172  if ($event_ignored) {
173  $this->event_reader->deleteEvent($event['event_id']);
174  continue;
175  }
176 
177  $res = false;
178  if (isset($handler)) {
179  switch ($event['op']) {
181  // DEPRECATED?
182  // $this->handleNewlyCreate($event['id']);
183  // $this->log->write(__METHOD__.': Handling new creation. DONE');
184  break;
185 
187  $res = $handler->handleDelete($this->getServer(), $event['id'], $this->mids);
188  $this->log->info(__METHOD__ . ': Handling delete. DONE');
189  break;
190 
191  case ilECSEvent::CREATED:
192  $res = $handler->handleCreate($this->getServer(), $event['id'], $this->mids);
193  $this->log->info(__METHOD__ . ': Handling create. DONE');
194  break;
195 
196  case ilECSEvent::UPDATED:
197  $res = $handler->handleUpdate($this->getServer(), $event['id'], $this->mids);
198  $this->log->info(__METHOD__ . ': Handling update. DONE');
199  break;
200 
201  default:
202  $this->log->info(__METHOD__ . ': Unknown event operation in queue ' . $event['op']);
203  break;
204  }
205  }
206  if ($res) {
207  $this->log->info(__METHOD__ . ': Processing of event done ' . $event['event_id']);
208  $this->event_reader->deleteEvent($event['event_id']);
209  } else {
210  $this->log->info(__METHOD__ . ': Processing of event failed ' . $event['event_id']);
211  }
212  }
213  }
$res
Definition: ltiservices.php:69
getServer()
Get server setting.
static getInstanceByEventType(string $a_type)
Get instance by ilECSEvent(QueueReader) type.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readEvents()

ilECSTaskScheduler::readEvents ( )
private

Read EContent.

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

References getServer().

Referenced by startTaskExecution().

98  : void
99  {
100  $this->event_reader = new ilECSEventQueueReader($this->getServer());
101  $this->event_reader->refresh();
102  }
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.

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

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

Referenced by startTaskExecution().

235  : void
236  {
237  $this->mids = array();
238 
239  $reader = ilECSCommunityReader::getInstanceByServerId($this->getServer()->getServerId());
240  foreach ($reader->getCommunities() as $com) {
241  foreach ($com->getParticipants() as $part) {
242  if ($part->isSelf()) {
243  $this->mids[] = $part->getMID();
244  }
245  }
246  }
247  }
getServer()
Get server setting.
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startTaskExecution()

ilECSTaskScheduler::startTaskExecution ( )

Start Tasks.

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

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

80  : bool
81  {
82  try {
83  $this->readMIDs();
84  $this->readEvents();
85  $this->handleEvents();
86 
87  $this->handleDeprecatedAccounts();
88  } catch (ilException $exc) {
89  $this->log->warning('Cannot start ecs task execution: ' . $exc->getMessage());
90  return false;
91  }
92  return true;
93  }
readMIDs()
Read MID&#39;s of this installation.
handleDeprecatedAccounts()
Delete deprecate ECS accounts.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilECSTaskScheduler::$db
private

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

◆ $event_reader

ilECSEventQueueReader ilECSTaskScheduler::$event_reader = null
private

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

◆ $eventHandler

ilAppEventHandler ilECSTaskScheduler::$eventHandler
private

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

◆ $instances

array ilECSTaskScheduler::$instances = array()
staticprivate

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

◆ $log

ilLogger ilECSTaskScheduler::$log
private

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

◆ $mids

array ilECSTaskScheduler::$mids = array()
private

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

◆ $settings

ilECSSetting ilECSTaskScheduler::$settings
private

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

Referenced by getServer().

◆ MAX_TASKS

const ilECSTaskScheduler::MAX_TASKS = 30

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


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