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();
205 $query =
"DELETE FROM ecs_events";
206 $this->db->query($query);
217 $query =
"DELETE FROM ecs_events ".
218 "WHERE type = ".$this->db->quote(self::TYPE_ECONTENT);
219 $this->db->query($query);
230 $query =
"DELETE FROM ecs_events ".
231 "WHERE type = ".$this->db->quote(self::TYPE_EXPORTED);
232 $this->db->query($query);
250 include_once(
'Services/WebServices/ECS/classes/class.ilECSConnector.php');
251 include_once(
'Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
254 $res = $connector->getEventQueues();
256 if(!is_array(
$res->getResult()))
258 $ilLog->write(__METHOD__.
': No new events found.');
261 $this->log->write(__METHOD__.
': Found '.count(
$res->getResult()).
' new events.');
262 foreach(
$res->getResult() as $event)
265 if(isset($event->cmd) and is_object($event->cmd))
267 if(!isset($event->cmd->admin) and !is_object($event->cmd->admin))
269 throw new ilECSReaderException(
'Received invalid command queue structure. Property "admin" is missing');
271 $admin_cmd = $event->cmd->admin;
272 $this->log->write(__METHOD__.
': Received new Commandqueue command: '.$admin_cmd);
275 case self::ADMIN_RESET:
278 case self::ADMIN_RESET_ALL:
285 if(isset($event->econtents) and is_object($event->econtents))
287 $operation = $event->econtents->op;
289 if(!in_array($event->econtents->eid,$this->econtent_ids))
293 $this->
add(
'econtents',$event->econtents->eid,$event->econtents->op);
294 $this->log->write(__METHOD__.
': Added new entry for EContentId: '.$event->econtents->eid);
296 elseif($operation == self::OPERATION_DELETE)
298 $this->log->write(__METHOD__.
': Updating delete operation for EContentId: '.$event->econtents->eid);
299 $this->
update(
'econtents',$event->econtents->eid,$event->econtents->op);
304 $this->log->write(__METHOD__.
': Ignoring multiple operations for EContentId: '.$event->econtents->eid);
313 $ilLog->write(__METHOD__.
': Error connecting to ECS server. '.$e->getMessage());
318 $ilLog->write(__METHOD__.
': Error reading EventQueue. '.$e->getMessage());
331 $event = array_shift($this->events);
338 $this->
delete($event[
'event_id']);
349 public function add($a_type,$a_id,$a_op)
351 $query =
"INSERT INTO ecs_events ".
352 "SET type = ".$this->db->quote($a_type).
", ".
353 "id = ".$this->db->quote($a_id).
", ".
354 "op = ".$this->db->quote($a_op).
" ";
355 $res = $this->db->query($query);
357 $new_event[
'event_id'] = $this->db->getLastInsertId();
358 $new_event[
'type'] = $a_type;
359 $new_event[
'id'] = $a_id;
360 $new_event[
'op'] = $a_op;
362 $this->events[] = $new_event;
363 $this->econtent_ids[$a_id] = $a_id;
373 private function update($a_type,$a_id,$a_operation)
375 $query =
"UPDATE ecs_events ".
376 "SET op = ".$this->db->quote($a_operation).
" ".
377 "WHERE type = ".$this->db->quote($a_type).
" ".
378 "AND id = ".$this->db->quote($a_id).
" ";
379 $this->db->query($query);
388 private function delete($a_event_id)
390 $query =
"DELETE FROM ecs_events ".
391 "WHERE event_id = ".$this->db->quote($a_event_id).
" ";
392 $this->db->query($query);
393 unset($this->econtent_ids[$a_event_id]);
403 $query =
"SELECT * FROM ecs_events ORDER BY event_id ";
404 $res = $this->db->query($query);
408 $this->events[$counter][
'event_id'] = $row->event_id;
409 $this->events[$counter][
'type'] = $row->type;
410 $this->events[$counter][
'id'] = $row->id;
411 $this->events[$counter][
'op'] = $row->op;
413 $this->econtent_ids[$row->event_id] = $row->event_id;