ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSCmsCourseCommandQueueHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
27
29 private int $mid = 0;
30
31
36 {
37 global $DIC;
38
39 $this->logger = $DIC->logger()->wsrv();
40
41 $this->server = $server;
42 }
43
47 public function getServer(): ilECSSetting
48 {
49 return $this->server;
50 }
51
55 public function getMid(): int
56 {
57 return $this->mid;
58 }
59
66 public function checkAllocationActivation(ilECSSetting $server, $a_content_id): ?bool
67 {
68 try {
69 $crs_reader = new ilECSCourseConnector($server);
70 $details = $crs_reader->getCourse($a_content_id, true);
71 $this->mid = $details->getMySender();
72
73 // Check if import is enabled
74 $part = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $this->getMid());
75 if (!$part->isImportEnabled()) {
76 $this->logger->info(__METHOD__ . ': Import disabled for mid ' . $this->getMid());
77 return false;
78 }
79 // Check course allocation setting
81 $this->getServer()->getServerId(),
82 $this->getMid()
83 );
84 $enabled = $gl_settings->isCourseAllocationEnabled();
85 if (!$enabled) {
86 $this->logger->info(__METHOD__ . ': Course allocation disabled for ' . $this->getMid());
87 }
88 return $enabled;
89 } catch (ilECSConnectorException $e) {
90 $this->logger->error(__METHOD__ . ': Reading course details failed with message ' . $e->getMessage());
91 return false;
92 }
93 }
94
95
99 public function handleCreate(ilECSSetting $server, $a_content_id): bool
100 {
101 if (!$this->checkAllocationActivation($server, $a_content_id)) {
102 return true;
103 }
104 try {
105 $course = $this->readCourse($server, $a_content_id);
106 $this->logger->info(__METHOD__ . ': ' . print_r($course, true));
107 $this->doUpdate($a_content_id, $course);
108 return true;
109 } catch (ilECSConnectorException $e) {
110 $this->logger->error(__METHOD__ . ': Course creation failed with mesage ' . $e->getMessage());
111 return false;
112 }
113 return true;
114 }
115
119 public function handleDelete(ilECSSetting $server, $a_content_id): bool
120 {
121 // nothing todo
122 return true;
123 }
124
128 public function handleUpdate(ilECSSetting $server, $a_content_id): bool
129 {
130 if (!$this->checkAllocationActivation($server, $a_content_id)) {
131 return true;
132 }
133
134 try {
135 $course = $this->readCourse($server, $a_content_id);
136 $this->doUpdate($a_content_id, $course);
137 return true;
138 } catch (ilECSConnectorException $e) {
139 $this->logger->error(__METHOD__ . ': Course creation failed with mesage ' . $e->getMessage());
140 return false;
141 }
142 return true;
143 }
144
145
149 protected function doUpdate(int $a_content_id, $course): void
150 {
151 $this->logger->info(__METHOD__ . ': Starting course creation/update');
152
153 $creation_handler = new ilECSCourseCreationHandler($this->getServer(), $this->mid);
154 $creation_handler->handle($a_content_id, $course);
155 }
156
160 private function readCourse(ilECSSetting $server, $a_content_id)
161 {
162 return (new ilECSCourseConnector($server))->getCourse($a_content_id, false);
163 }
164}
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.
Interface for all command queue handler classes.
global $DIC
Definition: shib_login.php:26