ILIAS  release_8 Revision v8.24
class.ilECSCmsCourseCommandQueueHandler.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
26
28 private int $mid = 0;
29
30
35 {
36 global $DIC;
37
38 $this->logger = $DIC->logger()->wsrv();
39
40 $this->server = $server;
41 }
42
46 public function getServer(): ilECSSetting
47 {
48 return $this->server;
49 }
50
54 public function getMid(): int
55 {
56 return $this->mid;
57 }
58
65 public function checkAllocationActivation(ilECSSetting $server, $a_content_id): ?bool
66 {
67 try {
68 $crs_reader = new ilECSCourseConnector($server);
69 $details = $crs_reader->getCourse($a_content_id, true);
70 $this->mid = $details->getMySender();
71
72 // Check if import is enabled
73 $part = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $this->getMid());
74 if (!$part->isImportEnabled()) {
75 $this->logger->info(__METHOD__ . ': Import disabled for mid ' . $this->getMid());
76 return false;
77 }
78 // Check course allocation setting
80 $this->getServer()->getServerId(),
81 $this->getMid()
82 );
83 $enabled = $gl_settings->isCourseAllocationEnabled();
84 if (!$enabled) {
85 $this->logger->info(__METHOD__ . ': Course allocation disabled for ' . $this->getMid());
86 }
87 return $enabled;
88 } catch (ilECSConnectorException $e) {
89 $this->logger->error(__METHOD__ . ': Reading course details failed with message ' . $e->getMessage());
90 return false;
91 }
92 }
93
94
98 public function handleCreate(ilECSSetting $server, $a_content_id): bool
99 {
100 if (!$this->checkAllocationActivation($server, $a_content_id)) {
101 return true;
102 }
103 try {
104 $course = $this->readCourse($server, $a_content_id);
105 $this->logger->info(__METHOD__ . ': ' . print_r($course, true));
106 $this->doUpdate($a_content_id, $course);
107 return true;
108 } catch (ilECSConnectorException $e) {
109 $this->logger->error(__METHOD__ . ': Course creation failed with mesage ' . $e->getMessage());
110 return false;
111 }
112 return true;
113 }
114
118 public function handleDelete(ilECSSetting $server, $a_content_id): bool
119 {
120 // nothing todo
121 return true;
122 }
123
127 public function handleUpdate(ilECSSetting $server, $a_content_id): bool
128 {
129 if (!$this->checkAllocationActivation($server, $a_content_id)) {
130 return true;
131 }
132
133 try {
134 $course = $this->readCourse($server, $a_content_id);
135 $this->doUpdate($a_content_id, $course);
136 return true;
137 } catch (ilECSConnectorException $e) {
138 $this->logger->error(__METHOD__ . ': Course creation failed with mesage ' . $e->getMessage());
139 return false;
140 }
141 return true;
142 }
143
144
148 protected function doUpdate(int $a_content_id, $course): void
149 {
150 $this->logger->info(__METHOD__ . ': Starting course creation/update');
151
152 $creation_handler = new ilECSCourseCreationHandler($this->getServer(), $this->mid);
153 $creation_handler->handle($a_content_id, $course);
154 }
155
159 private function readCourse(ilECSSetting $server, $a_content_id)
160 {
161 return (new ilECSCourseConnector($server))->getCourse($a_content_id, false);
162 }
163}
checkAllocationActivation(ilECSSetting $server, $a_content_id)
Check if course allocation is activated for one recipient of the.
handleCreate(ilECSSetting $server, $a_content_id)
Handle create.
handleUpdate(ilECSSetting $server, $a_content_id)
Handle update.
handleDelete(ilECSSetting $server, $a_content_id)
Handle delete.
doUpdate(int $a_content_id, $course)
Perform update.
readCourse(ilECSSetting $server, $a_content_id)
Read course from ecs.
static getInstanceByServerMid(int $a_server_id, int $a_mid)
Get instance.
static getInstance(int $a_server_id, int $mid)
Get instance by server id and mid.
Component logger with individual log levels by component id.
global $DIC
Definition: feed.php:28
Interface for all command queue handler classes.
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
array $details
Details for error message relating to last request processed.
Definition: System.php:109