62 include_once(
'Services/WebServices/ECS/classes/class.ilECSSettings.php');
63 include_once(
'Services/WebServices/ECS/classes/class.ilECSReaderException.php');
82 include_once(
'Services/WebServices/ECS/classes/class.ilECSConnector.php');
83 include_once(
'Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
87 include_once(
'./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
88 include_once(
'./Services/WebServices/ECS/classes/class.ilECSEventQueueReader.php');
89 include_once(
'./Services/WebServices/ECS/classes/class.ilECSImport.php');
90 include_once(
'./Services/WebServices/ECS/classes/class.ilECSExport.php');
93 $event_queue->deleteAllEContentEvents();
97 $all_content =
$reader->getEContent();
104 foreach($all_content as $content)
107 if(!isset($imported[$content->getEContentId()]) and 0)
111 $content->getEContentId(),
119 $content->getEContentId(),
124 if(isset($imported[$content->getEContentId()]))
126 unset($imported[$content->getEContentId()]);
128 if(isset($exported[$content->getEContentId()]))
130 unset($exported[$content->getEContentId()]);
135 if(is_array($imported))
137 foreach($imported as $econtent_id =>
$null)
146 if(is_array($exported))
153 $ilLog->write(
'Cannot connect to ECS server: '.$e1->getMessage());
158 $ilLog->write(
'Update failed: '.$e1->getMessage());
173 include_once(
'./Services/WebServices/ECS/classes/class.ilECSExport.php');
176 $queue->deleteAllExportedEvents();
180 $queue->add(self::TYPE_EXPORTED,$obj_id,self::OPERATION_NEWLY_CREATED);
195 return $this->events ? $this->events : array();
207 $query =
"DELETE FROM ecs_events";
221 $query =
"DELETE FROM ecs_events ".
222 "WHERE type = ".$this->db->quote(self::TYPE_ECONTENT,
'text');
236 $query =
"DELETE FROM ecs_events ".
237 "WHERE type = ".$this->db->quote(self::TYPE_EXPORTED,
'text');
256 include_once(
'Services/WebServices/ECS/classes/class.ilECSConnector.php');
257 include_once(
'Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
260 $res = $connector->getEventQueues();
262 if(!is_array(
$res->getResult()))
264 $ilLog->write(__METHOD__.
': No new events found.');
267 $this->log->write(__METHOD__.
': Found '.count(
$res->getResult()).
' new events.');
268 foreach(
$res->getResult() as $event)
271 if(isset($event->cmd) and is_object($event->cmd))
273 if(!isset($event->cmd->admin) and !is_object($event->cmd->admin))
275 throw new ilECSReaderException(
'Received invalid command queue structure. Property "admin" is missing');
277 $admin_cmd = $event->cmd->admin;
278 $this->log->write(__METHOD__.
': Received new Commandqueue command: '.$admin_cmd);
281 case self::ADMIN_RESET:
284 case self::ADMIN_RESET_ALL:
291 if(isset($event->econtents) and is_object($event->econtents))
293 $operation = $event->econtents->op;
295 if(!in_array($event->econtents->eid,$this->econtent_ids))
299 $this->
add(
'econtents',$event->econtents->eid,$event->econtents->op);
300 $this->log->write(__METHOD__.
': Added new entry for EContentId: '.$event->econtents->eid);
302 elseif($operation == self::OPERATION_DELETE)
304 $this->log->write(__METHOD__.
': Updating delete operation for EContentId: '.$event->econtents->eid);
305 $this->
update(
'econtents',$event->econtents->eid,$event->econtents->op);
310 $this->log->write(__METHOD__.
': Ignoring multiple operations for EContentId: '.$event->econtents->eid);
319 $ilLog->write(__METHOD__.
': Error connecting to ECS server. '.$e->getMessage());
324 $ilLog->write(__METHOD__.
': Error reading EventQueue. '.$e->getMessage());
337 $event = array_shift($this->events);
344 $this->
delete($event[
'event_id']);
355 public function add($a_type,$a_id,$a_op)
359 $next_id = $ilDB->nextId(
'ecs_events');
360 $query =
"INSERT INTO ecs_events (event_id,type,id,op) ".
362 $ilDB->quote($next_id,
'integer').
", ".
363 $this->db->quote($a_type,
'text').
", ".
364 $this->db->quote($a_id,
'integer').
", ".
365 $this->db->quote($a_op,
'text').
" ".
369 $new_event[
'event_id'] = $next_id;
370 $new_event[
'type'] = $a_type;
371 $new_event[
'id'] = $a_id;
372 $new_event[
'op'] = $a_op;
374 $this->events[] = $new_event;
375 $this->econtent_ids[$a_id] = $a_id;
385 private function update($a_type,$a_id,$a_operation)
389 $query =
"UPDATE ecs_events ".
390 "SET op = ".$this->db->quote($a_operation,
'text').
" ".
391 "WHERE type = ".$this->db->quote($a_type,
'text').
" ".
392 "AND id = ".$this->db->quote($a_id,
'integer').
" ";
402 private function delete($a_event_id)
406 $query =
"DELETE FROM ecs_events ".
407 "WHERE event_id = ".$this->db->quote($a_event_id,
'integer').
" ";
409 unset($this->econtent_ids[$a_event_id]);
421 $query =
"SELECT * FROM ecs_events ORDER BY event_id ";
426 $this->events[$counter][
'event_id'] =
$row->event_id;
427 $this->events[$counter][
'type'] =
$row->type;
428 $this->events[$counter][
'id'] =
$row->id;
429 $this->events[$counter][
'op'] =
$row->op;
431 $this->econtent_ids[
$row->event_id] =
$row->event_id;