18 declare(strict_types=1);
    58         $this->
logger = $DIC->logger()->wsrv();
    59         $this->db = $DIC->database();
    79         return array(self::TYPE_REMOTE_COURSE, self::TYPE_REMOTE_CATEGORY,
    80             self::TYPE_REMOTE_FILE, self::TYPE_REMOTE_GLOSSARY, self::TYPE_REMOTE_GROUP,
    81             self::TYPE_REMOTE_LEARNING_MODULE, self::TYPE_REMOTE_WIKI, self::TYPE_REMOTE_TEST);
    95         foreach ($a_types as $type) {
    98                 $list[$type] = $robj->getAllResourceIds($server, $a_sender_only);
   113             $types = self::getAllEContentTypes();
   117             $list = self::getAllResourceIds($this->
settings, $types);
   120             $this->
logger->info(__METHOD__ . 
': Imported = ' . print_r($imported, 
true));
   121             $this->
logger->info(__METHOD__ . 
': List = ' . print_r($list, 
true));
   123             foreach ($list as $resource_type => $link_ids) {
   125                     $this->
logger->info(__METHOD__ . 
': Ignoring resource type ' . $resource_type);
   130                 foreach ((array) $link_ids as $link_id) {
   131                     if (!isset($imported[$link_id])) {
   147                     if (isset($imported[$link_id])) {
   148                         unset($imported[$link_id]);
   153             if (is_array($imported)) {
   155                 foreach ($imported as $econtent_id => $obj_id) {
   167             $this->
logger->info(
'Cannot connect to ECS server: ' . $e1->getMessage());
   170             $this->
logger->info(
'Update failed: ' . $e2->getMessage());
   190         $local_econtent_ids = $exportManager->_getAllEContentIds($this->
settings->getServerId());
   192         $types = self::getAllEContentTypes();
   193         $list = self::getAllResourceIds($this->
settings, $types, 
true);
   197         $all_remote_ids = [];
   198         foreach ($list as $resource_type => $remote_ids) {
   199             $all_remote_ids += (array) $remote_ids;
   201         $all_remote_ids = array_unique($all_remote_ids);
   203         $this->
logger->info(__METHOD__ . 
': Resources = ' . print_r($all_remote_ids, 
true));
   204         $this->
logger->info(__METHOD__ . 
': Local = ' . print_r($local_econtent_ids, 
true));
   205         foreach ($local_econtent_ids as $local_econtent_id => $local_obj_id) {
   206             if (!in_array($local_econtent_id, $all_remote_ids, 
true)) {
   208                 $this->
logger->info(__METHOD__ . 
': Deleting deprecated econtent id ' . $local_econtent_id);
   209                 $exportManager->_deleteEContentIds($this->
settings->getServerId(), array($local_econtent_id));
   230         return $this->events ?: array();
   238         $query = 
"DELETE FROM ecs_events " .
   239             'WHERE server_id = ' . $this->db->quote($this->
settings->getServerId(), 
'integer');
   240         $this->db->manipulate($query);
   249         $query = 
"DELETE FROM ecs_events " .
   250             "WHERE " . $this->db->in(
"type", $a_types, 
false, 
"text") . 
' ' .
   251             'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(), 
'integer');
   252         $this->db->manipulate($query);
   261         $query = 
"DELETE FROM ecs_events " .
   262             "WHERE type = " . $this->db->quote(self::TYPE_EXPORTED, 
'text') . 
' ' .
   263             'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(), 
'integer');
   264         $this->db->manipulate($query);
   278                 $res = $connector->readEventFifo(
false);
   280                 if (!count(
$res->getResult())) {
   284                 foreach (
$res->getResult() as $result) {
   287                     $this->
logger->info(__METHOD__ . 
' ---------------------------- Handling new event ');
   288                     $this->
logger->info(__METHOD__ . print_r($event, 
true));
   289                     $this->
logger->info(__METHOD__ . 
' ---------------------------- Done! ');
   295                 $connector->readEventFifo(
true);
   298             $this->
logger->error(__METHOD__ . 
': Cannot read event fifo. Aborting');
   305     public function delete(): 
void   307         $query = 
'DELETE FROM ecs_events ' .
   308             'WHERE server_id = ' . $this->db->quote($this->
getServer()->getServerId(), 
'integer');
   309         $this->db->manipulate($query);
   319             case 'directory_trees':
   320                 $type = self::TYPE_DIRECTORY_TREES;
   323             case 'course_members':
   324                 $type = self::TYPE_CMS_COURSE_MEMBERS;
   328                 $type = self::TYPE_CMS_COURSES;
   332                 $type = self::TYPE_REMOTE_COURSE;
   336                 $type = self::TYPE_REMOTE_CATEGORY;
   340                 $type = self::TYPE_REMOTE_FILE;
   344                 $type = self::TYPE_REMOTE_GLOSSARY;
   348                 $type = self::TYPE_REMOTE_GROUP;
   351             case 'learningmodules':
   352                 $type = self::TYPE_REMOTE_LEARNING_MODULE;
   356                 $type = self::TYPE_REMOTE_WIKI;
   360                 $type = self::TYPE_REMOTE_TEST;
   364                 $type = self::TYPE_COURSE_URLS;
   367             case 'member_status':
   368                 $type = self::TYPE_ENROLMENT_STATUS;
   377         $query = 
"SELECT * FROM ecs_events " .
   378             "WHERE type = " . $this->db->quote($type, 
'text') . 
" " .
   379             "AND id = " . $this->db->quote($ev->
getRessourceId(), 
'integer') . 
" " .
   380             'AND server_id = ' . $this->db->quote($this->getServer()->getServerId(), 
'integer');
   381         $res = $this->db->query($query);
   385             $event_id = $row->event_id;
   390             $query = 
"INSERT ecs_events (event_id,type,id,op,server_id) " .
   392                 $this->db->quote($this->db->nextId(
'ecs_events'), 
'integer') . 
',' .
   393                 $this->db->quote($type, 
'text') . 
', ' .
   395                 $this->db->quote($ev->
getStatus(), 
'text') . 
', ' .
   396                 $this->db->quote($this->getServer()->getServerId(), 
'integer') . 
' ' .
   398             $this->db->manipulate($query);
   421         $query = 
"UPDATE ecs_events " .
   422             "SET op = " . $this->db->quote($ev->
getStatus(), 
'text') . 
" " .
   423             "WHERE event_id = " . $this->db->quote($event_id, 
'integer') . 
' ' .
   424             'AND type = ' . $this->db->quote($type, 
'text') . 
' ' .
   425             'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(), 
'integer');
   426         $this->db->manipulate($query);
   436         $event = array_shift($this->events);
   444     public function add(
string $a_type, 
int $a_id, 
string $a_op): bool
   446         $next_id = $this->db->nextId(
'ecs_events');
   447         $query = 
"INSERT INTO ecs_events (event_id,type,id,op,server_id) " .
   449             $this->db->quote($next_id, 
'integer') . 
", " .
   450             $this->db->quote($a_type, 
'text') . 
", " .
   451             $this->db->quote($a_id, 
'integer') . 
", " .
   452             $this->db->quote($a_op, 
'text') . 
", " .
   453             $this->db->quote($this->
getServer()->getServerId(), 
'integer') . 
' ' .
   455         $this->db->manipulate($query);
   457         $new_event[
'event_id'] = $next_id;
   458         $new_event[
'type'] = $a_type;
   459         $new_event[
'id'] = $a_id;
   460         $new_event[
'op'] = $a_op;
   462         $this->events[] = $new_event;
   463         $this->econtent_ids[$a_id] = $a_id;
   470     private function update(
string $a_type, 
int $a_id, 
string $a_operation): void
   472         $query = 
"UPDATE ecs_events " .
   473             "SET op = " . $this->db->quote($a_operation, 
'text') . 
" " .
   474             "WHERE type = " . $this->db->quote($a_type, 
'text') . 
" " .
   475             "AND id = " . $this->db->quote($a_id, 
'integer') . 
" " .
   476             'AND server_id = ' . $this->db->quote($this->
settings->getServerId(), 
'integer');
   477         $this->db->manipulate($query);
   485         $query = 
"DELETE FROM ecs_events " .
   486             "WHERE event_id = " . $this->db->quote($a_event_id, 
'integer') . 
" " .
   487             'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(), 
'integer');
   488         $this->db->manipulate($query);
   489         unset($this->econtent_ids[$a_event_id]);
   498         $query = 
"SELECT * FROM ecs_events  " .
   499             'WHERE server_id = ' . $this->db->quote($this->
getServer()->getServerId(), 
'integer') . 
' ' .
   502         $res = $this->db->query($query);
   505             $event[
'event_id'] = (
int) $row->event_id;
   506             $event[
'type'] = $row->type;
   507             $event[
'id'] = (
int) $row->id;
   508             $event[
'op'] = $row->op;
   509             $this->events[] = $event;
   511             $this->econtent_ids[(
int) $row->event_id] = (
int) $row->event_id;
   520         $ilDB = $DIC[
'ilDB'];
   522         $query = 
'DELETE FROM ecs_events' .
   523             ' WHERE server_id = ' . 
$ilDB->quote($a_server_id, 
'integer');
   524         $ilDB->manipulate($query);
 
const TYPE_REMOTE_CATEGORY
 
update(string $a_type, int $a_id, string $a_operation)
update one entry 
 
static getAllResourceIds(ilECSSetting $server, array $a_types, bool $a_sender_only=false)
Get all resource ids by resource type. 
 
static getInstance()
Get the singelton instance of this ilECSExportManager. 
 
getRessourceType()
Get ressource type. 
 
deleteAllExportedEvents()
Delete all exported events. 
 
static getInstanceByEventType(string $a_type)
Get instance by ilECSEvent(QueueReader) type. 
 
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types. 
 
static getAllEContentTypes()
All available content types. 
 
deleteAllEContentEvents(array $a_types)
Delete all econtents. 
 
static getEventTypeFromObjectType(string $a_obj_type)
Convert object type to event type. 
 
handleImportReset()
Reread all imported econtent. 
 
deleteAll()
Delete all events. 
 
static getInstance()
Get the singleton instance of this ilECSImportManager. 
 
getRessourceId()
Get ressource id. 
 
const TYPE_DIRECTORY_TREES
 
handleExportReset()
Handle export reset. 
 
writeEventToDB(ilECSEvent $ev)
Write event to db. 
 
refresh()
Fetch events from fifo Using fifo. 
 
Reads ECS events and stores them in the database. 
 
static deleteByServerId(int $a_server_id)
 
const TYPE_REMOTE_LEARNING_MODULE
 
shift()
get and delete the first event entry 
 
const TYPE_CMS_COURSE_MEMBERS
 
const TYPE_REMOTE_GLOSSARY
 
deleteEvent(int $a_event_id)
delete 
 
getServer()
get server settings 
 
add(string $a_type, int $a_id, string $a_op)
add 
 
__construct(ilECSSetting $settings)
Constructor. 
 
getEvents()
get all events 
 
static _lookupType(int $id, bool $reference=false)
 
const TYPE_ENROLMENT_STATUS