19declare(strict_types=1);
59 $this->
logger = $DIC->logger()->wsrv();
60 $this->db =
$DIC->database();
80 return array(self::TYPE_REMOTE_COURSE, self::TYPE_REMOTE_CATEGORY,
81 self::TYPE_REMOTE_FILE, self::TYPE_REMOTE_GLOSSARY, self::TYPE_REMOTE_GROUP,
82 self::TYPE_REMOTE_LEARNING_MODULE, self::TYPE_REMOTE_WIKI, self::TYPE_REMOTE_TEST);
96 foreach ($a_types as $type) {
99 $list[$type] = $robj->getAllResourceIds(
$server, $a_sender_only);
121 $this->
logger->info(__METHOD__ .
': Imported = ' . print_r($imported,
true));
122 $this->
logger->info(__METHOD__ .
': List = ' . print_r($list,
true));
124 foreach ($list as $resource_type => $link_ids) {
126 $this->
logger->info(__METHOD__ .
': Ignoring resource type ' . $resource_type);
131 foreach ((array) $link_ids as $link_id) {
132 if (!isset($imported[$link_id])) {
148 if (isset($imported[$link_id])) {
149 unset($imported[$link_id]);
154 if (is_array($imported)) {
156 foreach ($imported as $econtent_id => $obj_id) {
168 $this->
logger->info(
'Cannot connect to ECS server: ' . $e1->getMessage());
171 $this->
logger->info(
'Update failed: ' . $e2->getMessage());
191 $local_econtent_ids = $exportManager->_getAllEContentIds($this->
settings->getServerId());
198 $all_remote_ids = [];
199 foreach ($list as $resource_type => $remote_ids) {
200 $all_remote_ids += (array) $remote_ids;
202 $all_remote_ids = array_unique($all_remote_ids);
204 $this->
logger->info(__METHOD__ .
': Resources = ' . print_r($all_remote_ids,
true));
205 $this->
logger->info(__METHOD__ .
': Local = ' . print_r($local_econtent_ids,
true));
206 foreach ($local_econtent_ids as $local_econtent_id => $local_obj_id) {
207 if (!in_array($local_econtent_id, $all_remote_ids,
true)) {
209 $this->
logger->info(__METHOD__ .
': Deleting deprecated econtent id ' . $local_econtent_id);
210 $exportManager->_deleteEContentIds($this->
settings->getServerId(), array($local_econtent_id));
231 return $this->events ?: array();
239 $query =
"DELETE FROM ecs_events " .
240 'WHERE server_id = ' . $this->db->quote($this->
settings->getServerId(),
'integer');
241 $this->db->manipulate($query);
250 $query =
"DELETE FROM ecs_events " .
251 "WHERE " . $this->db->in(
"type", $a_types,
false,
"text") .
' ' .
252 'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer');
253 $this->db->manipulate($query);
262 $query =
"DELETE FROM ecs_events " .
263 "WHERE type = " . $this->db->quote(self::TYPE_EXPORTED,
'text') .
' ' .
264 'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer');
265 $this->db->manipulate($query);
279 $res = $connector->readEventFifo(
false);
281 if (!count(
$res->getResult())) {
285 foreach (
$res->getResult() as $result) {
288 $this->
logger->info(__METHOD__ .
' ---------------------------- Handling new event ');
289 $this->
logger->info(__METHOD__ . print_r($event,
true));
290 $this->
logger->info(__METHOD__ .
' ---------------------------- Done! ');
296 $connector->readEventFifo(
true);
299 $this->
logger->error(__METHOD__ .
': Cannot read event fifo. Aborting');
306 public function delete():
void
308 $query =
'DELETE FROM ecs_events ' .
309 'WHERE server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer');
310 $this->db->manipulate($query);
320 case 'directory_trees':
324 case 'course_members':
352 case 'learningmodules':
368 case 'member_status':
378 $query =
"SELECT * FROM ecs_events " .
379 "WHERE type = " . $this->db->quote($type,
'text') .
" " .
380 "AND id = " . $this->db->quote($ev->
getRessourceId(),
'integer') .
" " .
381 'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer');
382 $res = $this->db->query($query);
386 $event_id = $row->event_id;
391 $query =
"INSERT ecs_events (event_id,type,id,op,server_id) " .
393 $this->db->quote($this->db->nextId(
'ecs_events'),
'integer') .
',' .
394 $this->db->quote($type,
'text') .
', ' .
396 $this->db->quote($ev->
getStatus(),
'text') .
', ' .
397 $this->db->quote($this->
getServer()->getServerId(),
'integer') .
' ' .
399 $this->db->manipulate($query);
422 $query =
"UPDATE ecs_events " .
423 "SET op = " . $this->db->quote($ev->
getStatus(),
'text') .
" " .
424 "WHERE event_id = " . $this->db->quote($event_id,
'integer') .
' ' .
425 'AND type = ' . $this->db->quote($type,
'text') .
' ' .
426 'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer');
427 $this->db->manipulate($query);
437 $event = array_shift($this->events);
445 public function add(
string $a_type,
int $a_id,
string $a_op): bool
447 $next_id = $this->db->nextId(
'ecs_events');
448 $query =
"INSERT INTO ecs_events (event_id,type,id,op,server_id) " .
450 $this->db->quote($next_id,
'integer') .
", " .
451 $this->db->quote($a_type,
'text') .
", " .
452 $this->db->quote($a_id,
'integer') .
", " .
453 $this->db->quote($a_op,
'text') .
", " .
454 $this->db->quote($this->
getServer()->getServerId(),
'integer') .
' ' .
456 $this->db->manipulate($query);
458 $new_event[
'event_id'] = $next_id;
459 $new_event[
'type'] = $a_type;
460 $new_event[
'id'] = $a_id;
461 $new_event[
'op'] = $a_op;
463 $this->events[] = $new_event;
464 $this->econtent_ids[$a_id] = $a_id;
471 private function update(
string $a_type,
int $a_id,
string $a_operation): void
473 $query =
"UPDATE ecs_events " .
474 "SET op = " . $this->db->quote($a_operation,
'text') .
" " .
475 "WHERE type = " . $this->db->quote($a_type,
'text') .
" " .
476 "AND id = " . $this->db->quote($a_id,
'integer') .
" " .
477 'AND server_id = ' . $this->db->quote($this->
settings->getServerId(),
'integer');
478 $this->db->manipulate($query);
486 $query =
"DELETE FROM ecs_events " .
487 "WHERE event_id = " . $this->db->quote($a_event_id,
'integer') .
" " .
488 'AND server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer');
489 $this->db->manipulate($query);
490 unset($this->econtent_ids[$a_event_id]);
499 $query =
"SELECT * FROM ecs_events " .
500 'WHERE server_id = ' . $this->db->quote($this->
getServer()->getServerId(),
'integer') .
' ' .
503 $res = $this->db->query($query);
506 $event[
'event_id'] = (
int) $row->event_id;
507 $event[
'type'] = $row->type;
508 $event[
'id'] = (
int) $row->id;
509 $event[
'op'] = $row->op;
510 $this->events[] = $event;
512 $this->econtent_ids[(
int) $row->event_id] = (
int) $row->event_id;
523 $query =
'DELETE FROM ecs_events' .
524 ' WHERE server_id = ' .
$ilDB->quote($a_server_id,
'integer');
525 $ilDB->manipulate($query);
Reads ECS events and stores them in the database.
static getAllEContentTypes()
All available content types.
handleImportReset()
Reread all imported econtent.
const TYPE_REMOTE_GLOSSARY
handleExportReset()
Handle export reset.
deleteAllEContentEvents(array $a_types)
Delete all econtents.
getEvents()
get all events
add(string $a_type, int $a_id, string $a_op)
add
writeEventToDB(ilECSEvent $ev)
Write event to db.
refresh()
Fetch events from fifo Using fifo.
getServer()
get server settings
shift()
get and delete the first event entry
const TYPE_REMOTE_LEARNING_MODULE
const TYPE_DIRECTORY_TREES
const TYPE_REMOTE_CATEGORY
update(string $a_type, int $a_id, string $a_operation)
update one entry
deleteAll()
Delete all events.
deleteAllExportedEvents()
Delete all exported events.
const TYPE_CMS_COURSE_MEMBERS
static deleteByServerId(int $a_server_id)
__construct(ilECSSetting $settings)
Constructor.
const TYPE_ENROLMENT_STATUS
static getEventTypeFromObjectType(string $a_obj_type)
Convert object type to event type.
deleteEvent(int $a_event_id)
delete
static getAllResourceIds(ilECSSetting $server, array $a_types, bool $a_sender_only=false)
Get all resource ids by resource type.
getRessourceType()
Get ressource type.
getRessourceId()
Get ressource id.
static getInstance()
Get the singelton instance of this ilECSExportManager.
static getInstance()
Get the singleton instance of this ilECSImportManager.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
Base class for ILIAS Exception handling.
Component logger with individual log levels by component id.
static _lookupType(int $id, bool $reference=false)
static getInstanceByEventType(string $a_type)
Get instance by ilECSEvent(QueueReader) type.