@@ -35,269 +35,269 @@ |
||
35 | 35 | */ |
36 | 36 | class TaskScheduleService |
37 | 37 | { |
38 | - /** |
|
39 | - * Time-out after which the task will be considered not running any more. |
|
40 | - * In seconds, default 5 mins. |
|
41 | - * @var integer |
|
42 | - */ |
|
43 | - public const TASK_TIME_OUT = 600; |
|
38 | + /** |
|
39 | + * Time-out after which the task will be considered not running any more. |
|
40 | + * In seconds, default 5 mins. |
|
41 | + * @var integer |
|
42 | + */ |
|
43 | + public const TASK_TIME_OUT = 600; |
|
44 | 44 | |
45 | - private ModuleService $module_service; |
|
45 | + private ModuleService $module_service; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructor for TaskScheduleService |
|
49 | - * |
|
50 | - * @param ModuleService $module_service |
|
51 | - */ |
|
52 | - public function __construct(ModuleService $module_service) |
|
53 | - { |
|
54 | - $this->module_service = $module_service; |
|
55 | - } |
|
47 | + /** |
|
48 | + * Constructor for TaskScheduleService |
|
49 | + * |
|
50 | + * @param ModuleService $module_service |
|
51 | + */ |
|
52 | + public function __construct(ModuleService $module_service) |
|
53 | + { |
|
54 | + $this->module_service = $module_service; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns all Tasks schedules in database. |
|
59 | - * Stored records can be synchronised with the tasks actually available to the system. |
|
60 | - * |
|
61 | - * @param bool $sync_available Should tasks synchronised with available ones |
|
62 | - * @param bool $include_disabled Should disabled tasks be returned |
|
63 | - * @return Collection<TaskSchedule> Collection of TaskSchedule |
|
64 | - */ |
|
65 | - public function all(bool $sync_available = false, bool $include_disabled = true): Collection |
|
66 | - { |
|
67 | - $tasks_schedules = DB::table('maj_admintasks') |
|
68 | - ->select() |
|
69 | - ->get() |
|
70 | - ->map(self::rowMapper()); |
|
57 | + /** |
|
58 | + * Returns all Tasks schedules in database. |
|
59 | + * Stored records can be synchronised with the tasks actually available to the system. |
|
60 | + * |
|
61 | + * @param bool $sync_available Should tasks synchronised with available ones |
|
62 | + * @param bool $include_disabled Should disabled tasks be returned |
|
63 | + * @return Collection<TaskSchedule> Collection of TaskSchedule |
|
64 | + */ |
|
65 | + public function all(bool $sync_available = false, bool $include_disabled = true): Collection |
|
66 | + { |
|
67 | + $tasks_schedules = DB::table('maj_admintasks') |
|
68 | + ->select() |
|
69 | + ->get() |
|
70 | + ->map(self::rowMapper()); |
|
71 | 71 | |
72 | - if ($sync_available) { |
|
73 | - $available_tasks = clone $this->available(); |
|
74 | - foreach ($tasks_schedules as $task_schedule) { |
|
75 | - /** @var TaskSchedule $task_schedule */ |
|
76 | - if ($available_tasks->has($task_schedule->taskId())) { |
|
77 | - $available_tasks->forget($task_schedule->taskId()); |
|
78 | - } else { |
|
79 | - $this->delete($task_schedule); |
|
80 | - } |
|
81 | - } |
|
72 | + if ($sync_available) { |
|
73 | + $available_tasks = clone $this->available(); |
|
74 | + foreach ($tasks_schedules as $task_schedule) { |
|
75 | + /** @var TaskSchedule $task_schedule */ |
|
76 | + if ($available_tasks->has($task_schedule->taskId())) { |
|
77 | + $available_tasks->forget($task_schedule->taskId()); |
|
78 | + } else { |
|
79 | + $this->delete($task_schedule); |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - foreach ($available_tasks as $task_name => $task_class) { |
|
84 | - if (null !== $task = app($task_class)) { |
|
85 | - $this->insertTask($task_name, $task->defaultFrequency()); |
|
86 | - } |
|
87 | - } |
|
83 | + foreach ($available_tasks as $task_name => $task_class) { |
|
84 | + if (null !== $task = app($task_class)) { |
|
85 | + $this->insertTask($task_name, $task->defaultFrequency()); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - return $this->all(false, $include_disabled); |
|
90 | - } |
|
89 | + return $this->all(false, $include_disabled); |
|
90 | + } |
|
91 | 91 | |
92 | - return $tasks_schedules; |
|
93 | - } |
|
92 | + return $tasks_schedules; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Returns tasks exposed through modules implementing ModuleTasksProviderInterface. |
|
97 | - * |
|
98 | - * @return Collection<string, string> |
|
99 | - */ |
|
100 | - public function available(): Collection |
|
101 | - { |
|
102 | - return Registry::cache()->array()->remember( |
|
103 | - 'maj-available-admintasks', |
|
104 | - function (): Collection { |
|
105 | - /** @var Collection<string, string> $tasks */ |
|
106 | - $tasks = $this->module_service |
|
107 | - ->findByInterface(ModuleTasksProviderInterface::class) |
|
108 | - ->flatMap(fn(ModuleTasksProviderInterface $module) => $module->listTasks()); |
|
109 | - return $tasks; |
|
110 | - } |
|
111 | - ); |
|
112 | - } |
|
95 | + /** |
|
96 | + * Returns tasks exposed through modules implementing ModuleTasksProviderInterface. |
|
97 | + * |
|
98 | + * @return Collection<string, string> |
|
99 | + */ |
|
100 | + public function available(): Collection |
|
101 | + { |
|
102 | + return Registry::cache()->array()->remember( |
|
103 | + 'maj-available-admintasks', |
|
104 | + function (): Collection { |
|
105 | + /** @var Collection<string, string> $tasks */ |
|
106 | + $tasks = $this->module_service |
|
107 | + ->findByInterface(ModuleTasksProviderInterface::class) |
|
108 | + ->flatMap(fn(ModuleTasksProviderInterface $module) => $module->listTasks()); |
|
109 | + return $tasks; |
|
110 | + } |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Find a task schedule by its ID. |
|
116 | - * |
|
117 | - * @param int $task_schedule_id |
|
118 | - * @return TaskSchedule|NULL |
|
119 | - */ |
|
120 | - public function find(int $task_schedule_id): ?TaskSchedule |
|
121 | - { |
|
122 | - return DB::table('maj_admintasks') |
|
123 | - ->select() |
|
124 | - ->where('majat_id', '=', $task_schedule_id) |
|
125 | - ->get() |
|
126 | - ->map(self::rowMapper()) |
|
127 | - ->first(); |
|
128 | - } |
|
114 | + /** |
|
115 | + * Find a task schedule by its ID. |
|
116 | + * |
|
117 | + * @param int $task_schedule_id |
|
118 | + * @return TaskSchedule|NULL |
|
119 | + */ |
|
120 | + public function find(int $task_schedule_id): ?TaskSchedule |
|
121 | + { |
|
122 | + return DB::table('maj_admintasks') |
|
123 | + ->select() |
|
124 | + ->where('majat_id', '=', $task_schedule_id) |
|
125 | + ->get() |
|
126 | + ->map(self::rowMapper()) |
|
127 | + ->first(); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Add a new task schedule with the specified task ID, and frequency if defined. |
|
132 | - * Uses default for other settings. |
|
133 | - * |
|
134 | - * @param string $task_id |
|
135 | - * @param int $frequency |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function insertTask(string $task_id, int $frequency = 0): bool |
|
139 | - { |
|
140 | - $values = ['majat_task_id' => $task_id]; |
|
141 | - if ($frequency > 0) { |
|
142 | - $values['majat_frequency'] = $frequency; |
|
143 | - } |
|
130 | + /** |
|
131 | + * Add a new task schedule with the specified task ID, and frequency if defined. |
|
132 | + * Uses default for other settings. |
|
133 | + * |
|
134 | + * @param string $task_id |
|
135 | + * @param int $frequency |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function insertTask(string $task_id, int $frequency = 0): bool |
|
139 | + { |
|
140 | + $values = ['majat_task_id' => $task_id]; |
|
141 | + if ($frequency > 0) { |
|
142 | + $values['majat_frequency'] = $frequency; |
|
143 | + } |
|
144 | 144 | |
145 | - return DB::table('maj_admintasks') |
|
146 | - ->insert($values); |
|
147 | - } |
|
145 | + return DB::table('maj_admintasks') |
|
146 | + ->insert($values); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Update a task schedule. |
|
151 | - * Returns the number of tasks schedules updated. |
|
152 | - * |
|
153 | - * @param TaskSchedule $task_schedule |
|
154 | - * @return int |
|
155 | - */ |
|
156 | - public function update(TaskSchedule $task_schedule): int |
|
157 | - { |
|
158 | - return DB::table('maj_admintasks') |
|
159 | - ->where('majat_id', '=', $task_schedule->id()) |
|
160 | - ->update([ |
|
161 | - 'majat_status' => $task_schedule->isEnabled() ? 'enabled' : 'disabled', |
|
162 | - 'majat_last_run' => $task_schedule->lastRunTime()->toDateTimeString(), |
|
163 | - 'majat_last_result' => $task_schedule->wasLastRunSuccess(), |
|
164 | - 'majat_frequency' => $task_schedule->frequency(), |
|
165 | - 'majat_nb_occur' => $task_schedule->remainingOccurrences(), |
|
166 | - 'majat_running' => $task_schedule->isRunning() |
|
167 | - ]); |
|
168 | - } |
|
149 | + /** |
|
150 | + * Update a task schedule. |
|
151 | + * Returns the number of tasks schedules updated. |
|
152 | + * |
|
153 | + * @param TaskSchedule $task_schedule |
|
154 | + * @return int |
|
155 | + */ |
|
156 | + public function update(TaskSchedule $task_schedule): int |
|
157 | + { |
|
158 | + return DB::table('maj_admintasks') |
|
159 | + ->where('majat_id', '=', $task_schedule->id()) |
|
160 | + ->update([ |
|
161 | + 'majat_status' => $task_schedule->isEnabled() ? 'enabled' : 'disabled', |
|
162 | + 'majat_last_run' => $task_schedule->lastRunTime()->toDateTimeString(), |
|
163 | + 'majat_last_result' => $task_schedule->wasLastRunSuccess(), |
|
164 | + 'majat_frequency' => $task_schedule->frequency(), |
|
165 | + 'majat_nb_occur' => $task_schedule->remainingOccurrences(), |
|
166 | + 'majat_running' => $task_schedule->isRunning() |
|
167 | + ]); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Delete a task schedule. |
|
172 | - * |
|
173 | - * @param TaskSchedule $task_schedule |
|
174 | - * @return int |
|
175 | - */ |
|
176 | - public function delete(TaskSchedule $task_schedule): int |
|
177 | - { |
|
178 | - return DB::table('maj_admintasks') |
|
179 | - ->where('majat_id', '=', $task_schedule->id()) |
|
180 | - ->delete(); |
|
181 | - } |
|
170 | + /** |
|
171 | + * Delete a task schedule. |
|
172 | + * |
|
173 | + * @param TaskSchedule $task_schedule |
|
174 | + * @return int |
|
175 | + */ |
|
176 | + public function delete(TaskSchedule $task_schedule): int |
|
177 | + { |
|
178 | + return DB::table('maj_admintasks') |
|
179 | + ->where('majat_id', '=', $task_schedule->id()) |
|
180 | + ->delete(); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Find a task by its name |
|
185 | - * |
|
186 | - * @param string $task_id |
|
187 | - * @return TaskInterface|NULL |
|
188 | - */ |
|
189 | - public function findTask(string $task_id): ?TaskInterface |
|
190 | - { |
|
191 | - if ($this->available()->has($task_id)) { |
|
192 | - return app($this->available()->get($task_id)); |
|
193 | - } |
|
194 | - return null; |
|
195 | - } |
|
183 | + /** |
|
184 | + * Find a task by its name |
|
185 | + * |
|
186 | + * @param string $task_id |
|
187 | + * @return TaskInterface|NULL |
|
188 | + */ |
|
189 | + public function findTask(string $task_id): ?TaskInterface |
|
190 | + { |
|
191 | + if ($this->available()->has($task_id)) { |
|
192 | + return app($this->available()->get($task_id)); |
|
193 | + } |
|
194 | + return null; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Retrieve all tasks that are candidates to be run. |
|
199 | - * |
|
200 | - * @param bool $force Should the run be forced |
|
201 | - * @param string $task_id Specific task ID to be run |
|
202 | - * @return Collection<TaskSchedule> |
|
203 | - */ |
|
204 | - public function findTasksToRun(bool $force, string $task_id = ''): Collection |
|
205 | - { |
|
206 | - $query = DB::table('maj_admintasks') |
|
207 | - ->select() |
|
208 | - ->where('majat_status', '=', 'enabled') |
|
209 | - ->where(function (Builder $query): void { |
|
210 | - $query->where('majat_running', '=', 0) |
|
211 | - ->orWhere('majat_last_run', '<=', CarbonImmutable::now('UTC')->subSeconds(self::TASK_TIME_OUT)); |
|
212 | - }); |
|
197 | + /** |
|
198 | + * Retrieve all tasks that are candidates to be run. |
|
199 | + * |
|
200 | + * @param bool $force Should the run be forced |
|
201 | + * @param string $task_id Specific task ID to be run |
|
202 | + * @return Collection<TaskSchedule> |
|
203 | + */ |
|
204 | + public function findTasksToRun(bool $force, string $task_id = ''): Collection |
|
205 | + { |
|
206 | + $query = DB::table('maj_admintasks') |
|
207 | + ->select() |
|
208 | + ->where('majat_status', '=', 'enabled') |
|
209 | + ->where(function (Builder $query): void { |
|
210 | + $query->where('majat_running', '=', 0) |
|
211 | + ->orWhere('majat_last_run', '<=', CarbonImmutable::now('UTC')->subSeconds(self::TASK_TIME_OUT)); |
|
212 | + }); |
|
213 | 213 | |
214 | - if (!$force) { |
|
215 | - $query->where(function (Builder $query): void { |
|
214 | + if (!$force) { |
|
215 | + $query->where(function (Builder $query): void { |
|
216 | 216 | |
217 | - $query->where('majat_last_result', '=', 0) |
|
218 | - ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()'); |
|
219 | - }); |
|
220 | - } |
|
217 | + $query->where('majat_last_result', '=', 0) |
|
218 | + ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()'); |
|
219 | + }); |
|
220 | + } |
|
221 | 221 | |
222 | - if ($task_id !== '') { |
|
223 | - $query->where('majat_task_id', '=', $task_id); |
|
224 | - } |
|
222 | + if ($task_id !== '') { |
|
223 | + $query->where('majat_task_id', '=', $task_id); |
|
224 | + } |
|
225 | 225 | |
226 | - return $query->get()->map(self::rowMapper()); |
|
227 | - } |
|
226 | + return $query->get()->map(self::rowMapper()); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Run the task associated with the schedule. |
|
231 | - * The task will run if either forced to, or its next scheduled run time has been exceeded. |
|
232 | - * The last run time is recorded only if the task is successful. |
|
233 | - * |
|
234 | - * @param TaskSchedule $task_schedule |
|
235 | - * @param boolean $force |
|
236 | - */ |
|
237 | - public function run(TaskSchedule $task_schedule, $force = false): void |
|
238 | - { |
|
239 | - /** @var TaskSchedule $task_schedule */ |
|
240 | - $task_schedule = DB::table('maj_admintasks') |
|
241 | - ->select() |
|
242 | - ->where('majat_id', '=', $task_schedule->id()) |
|
243 | - ->lockForUpdate() |
|
244 | - ->get() |
|
245 | - ->map(self::rowMapper()) |
|
246 | - ->first(); |
|
229 | + /** |
|
230 | + * Run the task associated with the schedule. |
|
231 | + * The task will run if either forced to, or its next scheduled run time has been exceeded. |
|
232 | + * The last run time is recorded only if the task is successful. |
|
233 | + * |
|
234 | + * @param TaskSchedule $task_schedule |
|
235 | + * @param boolean $force |
|
236 | + */ |
|
237 | + public function run(TaskSchedule $task_schedule, $force = false): void |
|
238 | + { |
|
239 | + /** @var TaskSchedule $task_schedule */ |
|
240 | + $task_schedule = DB::table('maj_admintasks') |
|
241 | + ->select() |
|
242 | + ->where('majat_id', '=', $task_schedule->id()) |
|
243 | + ->lockForUpdate() |
|
244 | + ->get() |
|
245 | + ->map(self::rowMapper()) |
|
246 | + ->first(); |
|
247 | 247 | |
248 | - if ( |
|
249 | - !$task_schedule->isRunning() && |
|
250 | - ($force || |
|
251 | - $task_schedule->lastRunTime()->addMinutes($task_schedule->frequency()) |
|
252 | - ->lessThan(CarbonImmutable::now('UTC')) |
|
253 | - ) |
|
254 | - ) { |
|
255 | - $task_schedule->setLastResult(false); |
|
248 | + if ( |
|
249 | + !$task_schedule->isRunning() && |
|
250 | + ($force || |
|
251 | + $task_schedule->lastRunTime()->addMinutes($task_schedule->frequency()) |
|
252 | + ->lessThan(CarbonImmutable::now('UTC')) |
|
253 | + ) |
|
254 | + ) { |
|
255 | + $task_schedule->setLastResult(false); |
|
256 | 256 | |
257 | - $task = $this->findTask($task_schedule->taskId()); |
|
258 | - if ($task !== null) { |
|
259 | - $task_schedule->startRunning(); |
|
260 | - $this->update($task_schedule); |
|
257 | + $task = $this->findTask($task_schedule->taskId()); |
|
258 | + if ($task !== null) { |
|
259 | + $task_schedule->startRunning(); |
|
260 | + $this->update($task_schedule); |
|
261 | 261 | |
262 | - $first_error = $task_schedule->wasLastRunSuccess(); |
|
263 | - try { |
|
264 | - $task_schedule->setLastResult($task->run($task_schedule)); |
|
265 | - } catch (Throwable $ex) { |
|
266 | - if ($first_error) { // Only record the first error, as this could fill the log. |
|
267 | - Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()) . ' ' . |
|
268 | - '[' . get_class($ex) . '] ' . $ex->getMessage() . ' ' . $ex->getFile() . ':' |
|
269 | - . $ex->getLine() . PHP_EOL . $ex->getTraceAsString()); |
|
270 | - } |
|
271 | - } |
|
262 | + $first_error = $task_schedule->wasLastRunSuccess(); |
|
263 | + try { |
|
264 | + $task_schedule->setLastResult($task->run($task_schedule)); |
|
265 | + } catch (Throwable $ex) { |
|
266 | + if ($first_error) { // Only record the first error, as this could fill the log. |
|
267 | + Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()) . ' ' . |
|
268 | + '[' . get_class($ex) . '] ' . $ex->getMessage() . ' ' . $ex->getFile() . ':' |
|
269 | + . $ex->getLine() . PHP_EOL . $ex->getTraceAsString()); |
|
270 | + } |
|
271 | + } |
|
272 | 272 | |
273 | - if ($task_schedule->wasLastRunSuccess()) { |
|
274 | - $task_schedule->setLastRunTime(CarbonImmutable::now('UTC')); |
|
275 | - $task_schedule->decrementRemainingOccurrences(); |
|
276 | - } |
|
277 | - $task_schedule->stopRunning(); |
|
278 | - } |
|
279 | - $this->update($task_schedule); |
|
280 | - } |
|
281 | - } |
|
273 | + if ($task_schedule->wasLastRunSuccess()) { |
|
274 | + $task_schedule->setLastRunTime(CarbonImmutable::now('UTC')); |
|
275 | + $task_schedule->decrementRemainingOccurrences(); |
|
276 | + } |
|
277 | + $task_schedule->stopRunning(); |
|
278 | + } |
|
279 | + $this->update($task_schedule); |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * Mapper to return a TaskSchedule object from an object. |
|
285 | - * |
|
286 | - * @return Closure(stdClass $row): TaskSchedule |
|
287 | - */ |
|
288 | - public static function rowMapper(): Closure |
|
289 | - { |
|
290 | - return static function (stdClass $row): TaskSchedule { |
|
291 | - return new TaskSchedule( |
|
292 | - (int) $row->majat_id, |
|
293 | - $row->majat_task_id, |
|
294 | - $row->majat_status === 'enabled', |
|
295 | - CarbonImmutable::parse($row->majat_last_run, 'UTC'), |
|
296 | - (bool) $row->majat_last_result, |
|
297 | - (int) $row->majat_frequency, |
|
298 | - (int) $row->majat_nb_occur, |
|
299 | - (bool) $row->majat_running |
|
300 | - ); |
|
301 | - }; |
|
302 | - } |
|
283 | + /** |
|
284 | + * Mapper to return a TaskSchedule object from an object. |
|
285 | + * |
|
286 | + * @return Closure(stdClass $row): TaskSchedule |
|
287 | + */ |
|
288 | + public static function rowMapper(): Closure |
|
289 | + { |
|
290 | + return static function (stdClass $row): TaskSchedule { |
|
291 | + return new TaskSchedule( |
|
292 | + (int) $row->majat_id, |
|
293 | + $row->majat_task_id, |
|
294 | + $row->majat_status === 'enabled', |
|
295 | + CarbonImmutable::parse($row->majat_last_run, 'UTC'), |
|
296 | + (bool) $row->majat_last_result, |
|
297 | + (int) $row->majat_frequency, |
|
298 | + (int) $row->majat_nb_occur, |
|
299 | + (bool) $row->majat_running |
|
300 | + ); |
|
301 | + }; |
|
302 | + } |
|
303 | 303 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | { |
102 | 102 | return Registry::cache()->array()->remember( |
103 | 103 | 'maj-available-admintasks', |
104 | - function (): Collection { |
|
104 | + function(): Collection { |
|
105 | 105 | /** @var Collection<string, string> $tasks */ |
106 | 106 | $tasks = $this->module_service |
107 | 107 | ->findByInterface(ModuleTasksProviderInterface::class) |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | $query = DB::table('maj_admintasks') |
207 | 207 | ->select() |
208 | 208 | ->where('majat_status', '=', 'enabled') |
209 | - ->where(function (Builder $query): void { |
|
209 | + ->where(function(Builder $query): void { |
|
210 | 210 | $query->where('majat_running', '=', 0) |
211 | 211 | ->orWhere('majat_last_run', '<=', CarbonImmutable::now('UTC')->subSeconds(self::TASK_TIME_OUT)); |
212 | 212 | }); |
213 | 213 | |
214 | 214 | if (!$force) { |
215 | - $query->where(function (Builder $query): void { |
|
215 | + $query->where(function(Builder $query): void { |
|
216 | 216 | |
217 | 217 | $query->where('majat_last_result', '=', 0) |
218 | 218 | ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()'); |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | $task_schedule->setLastResult($task->run($task_schedule)); |
265 | 265 | } catch (Throwable $ex) { |
266 | 266 | if ($first_error) { // Only record the first error, as this could fill the log. |
267 | - Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()) . ' ' . |
|
268 | - '[' . get_class($ex) . '] ' . $ex->getMessage() . ' ' . $ex->getFile() . ':' |
|
269 | - . $ex->getLine() . PHP_EOL . $ex->getTraceAsString()); |
|
267 | + Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()).' '. |
|
268 | + '['.get_class($ex).'] '.$ex->getMessage().' '.$ex->getFile().':' |
|
269 | + . $ex->getLine().PHP_EOL.$ex->getTraceAsString()); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
@@ -287,16 +287,16 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public static function rowMapper(): Closure |
289 | 289 | { |
290 | - return static function (stdClass $row): TaskSchedule { |
|
290 | + return static function(stdClass $row): TaskSchedule { |
|
291 | 291 | return new TaskSchedule( |
292 | - (int) $row->majat_id, |
|
292 | + (int)$row->majat_id, |
|
293 | 293 | $row->majat_task_id, |
294 | 294 | $row->majat_status === 'enabled', |
295 | 295 | CarbonImmutable::parse($row->majat_last_run, 'UTC'), |
296 | - (bool) $row->majat_last_result, |
|
297 | - (int) $row->majat_frequency, |
|
298 | - (int) $row->majat_nb_occur, |
|
299 | - (bool) $row->majat_running |
|
296 | + (bool)$row->majat_last_result, |
|
297 | + (int)$row->majat_frequency, |
|
298 | + (int)$row->majat_nb_occur, |
|
299 | + (bool)$row->majat_running |
|
300 | 300 | ); |
301 | 301 | }; |
302 | 302 | } |
@@ -35,85 +35,85 @@ |
||
35 | 35 | */ |
36 | 36 | class MapAdapterEditAction implements RequestHandlerInterface |
37 | 37 | { |
38 | - private ?GeoDispersionModule $module; |
|
39 | - private MapAdapterDataService $mapadapter_data_service; |
|
40 | - private MapDefinitionsService $map_definition_service; |
|
38 | + private ?GeoDispersionModule $module; |
|
39 | + private MapAdapterDataService $mapadapter_data_service; |
|
40 | + private MapDefinitionsService $map_definition_service; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for MapAdapterEditAction Request Handler |
|
44 | - * |
|
45 | - * @param ModuleService $module_service |
|
46 | - * @param MapAdapterDataService $mapadapter_data_service |
|
47 | - * @param MapDefinitionsService $map_definition_service |
|
48 | - */ |
|
49 | - public function __construct( |
|
50 | - ModuleService $module_service, |
|
51 | - MapAdapterDataService $mapadapter_data_service, |
|
52 | - MapDefinitionsService $map_definition_service |
|
53 | - ) { |
|
54 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
55 | - $this->mapadapter_data_service = $mapadapter_data_service; |
|
56 | - $this->map_definition_service = $map_definition_service; |
|
57 | - } |
|
42 | + /** |
|
43 | + * Constructor for MapAdapterEditAction Request Handler |
|
44 | + * |
|
45 | + * @param ModuleService $module_service |
|
46 | + * @param MapAdapterDataService $mapadapter_data_service |
|
47 | + * @param MapDefinitionsService $map_definition_service |
|
48 | + */ |
|
49 | + public function __construct( |
|
50 | + ModuleService $module_service, |
|
51 | + MapAdapterDataService $mapadapter_data_service, |
|
52 | + MapDefinitionsService $map_definition_service |
|
53 | + ) { |
|
54 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
55 | + $this->mapadapter_data_service = $mapadapter_data_service; |
|
56 | + $this->map_definition_service = $map_definition_service; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
62 | - */ |
|
63 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
64 | - { |
|
65 | - $tree = Validator::attributes($request)->tree(); |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
62 | + */ |
|
63 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
64 | + { |
|
65 | + $tree = Validator::attributes($request)->tree(); |
|
66 | 66 | |
67 | - if ($this->module === null) { |
|
68 | - FlashMessages::addMessage( |
|
69 | - I18N::translate('The attached module could not be found.'), |
|
70 | - 'danger' |
|
71 | - ); |
|
72 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
73 | - } |
|
67 | + if ($this->module === null) { |
|
68 | + FlashMessages::addMessage( |
|
69 | + I18N::translate('The attached module could not be found.'), |
|
70 | + 'danger' |
|
71 | + ); |
|
72 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
73 | + } |
|
74 | 74 | |
75 | - $adapter_id = Validator::attributes($request)->integer('adapter_id', -1); |
|
76 | - $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
|
75 | + $adapter_id = Validator::attributes($request)->integer('adapter_id', -1); |
|
76 | + $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
|
77 | 77 | |
78 | - $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
|
79 | - $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
78 | + $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
|
79 | + $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
80 | 80 | |
81 | - $mapper = null; |
|
82 | - try { |
|
83 | - $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', '')); |
|
84 | - } catch (BindingResolutionException $ex) { |
|
85 | - } |
|
81 | + $mapper = null; |
|
82 | + try { |
|
83 | + $mapper = app(Validator::parsedBody($request)->string('map_adapter_mapper', '')); |
|
84 | + } catch (BindingResolutionException $ex) { |
|
85 | + } |
|
86 | 86 | |
87 | - if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
|
88 | - FlashMessages::addMessage( |
|
89 | - I18N::translate('The parameters for the map configuration are not valid.'), |
|
90 | - 'danger' |
|
91 | - ); |
|
92 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
93 | - } |
|
87 | + if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
|
88 | + FlashMessages::addMessage( |
|
89 | + I18N::translate('The parameters for the map configuration are not valid.'), |
|
90 | + 'danger' |
|
91 | + ); |
|
92 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
93 | + } |
|
94 | 94 | |
95 | - $mapper->setConfig($mapper->config()->withConfigUpdate($request)); |
|
96 | - $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property); |
|
97 | - try { |
|
98 | - $this->mapadapter_data_service->update($new_map_adapter); |
|
99 | - FlashMessages::addMessage( |
|
100 | - I18N::translate('The map configuration has been successfully updated.'), |
|
101 | - 'success' |
|
102 | - ); |
|
103 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
104 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
|
105 | - } catch (Throwable $ex) { |
|
106 | - FlashMessages::addMessage( |
|
107 | - I18N::translate('An error occured while updating the map configuration.'), |
|
108 | - 'danger' |
|
109 | - ); |
|
110 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
111 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
|
112 | - } |
|
95 | + $mapper->setConfig($mapper->config()->withConfigUpdate($request)); |
|
96 | + $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property); |
|
97 | + try { |
|
98 | + $this->mapadapter_data_service->update($new_map_adapter); |
|
99 | + FlashMessages::addMessage( |
|
100 | + I18N::translate('The map configuration has been successfully updated.'), |
|
101 | + 'success' |
|
102 | + ); |
|
103 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
104 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
|
105 | + } catch (Throwable $ex) { |
|
106 | + FlashMessages::addMessage( |
|
107 | + I18N::translate('An error occured while updating the map configuration.'), |
|
108 | + 'danger' |
|
109 | + ); |
|
110 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
111 | + Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
|
112 | + } |
|
113 | 113 | |
114 | - return Registry::responseFactory()->redirect(MapAdapterEditPage::class, [ |
|
115 | - 'tree' => $tree->name(), |
|
116 | - 'adapter_id' => $map_adapter->id() |
|
117 | - ]); |
|
118 | - } |
|
114 | + return Registry::responseFactory()->redirect(MapAdapterEditPage::class, [ |
|
115 | + 'tree' => $tree->name(), |
|
116 | + 'adapter_id' => $map_adapter->id() |
|
117 | + ]); |
|
118 | + } |
|
119 | 119 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
77 | 77 | |
78 | 78 | $map = $this->map_definition_service->find(Validator::parsedBody($request)->string('map_adapter_map', '')); |
79 | - $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
79 | + $mapping_property = Validator::parsedBody($request)->string('map_adapter_property_selected', ''); |
|
80 | 80 | |
81 | 81 | $mapper = null; |
82 | 82 | try { |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | 'success' |
102 | 102 | ); |
103 | 103 | //phpcs:ignore Generic.Files.LineLength.TooLong |
104 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
|
104 | + Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” has been updated.'); |
|
105 | 105 | } catch (Throwable $ex) { |
106 | 106 | FlashMessages::addMessage( |
107 | 107 | I18N::translate('An error occured while updating the map configuration.'), |
108 | 108 | 'danger' |
109 | 109 | ); |
110 | 110 | //phpcs:ignore Generic.Files.LineLength.TooLong |
111 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
|
111 | + Log::addErrorLog('Module '.$this->module->title().' : Error when updating Map Adapter “'.$map_adapter->id().'”: '.$ex->getMessage()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return Registry::responseFactory()->redirect(MapAdapterEditPage::class, [ |
@@ -31,58 +31,58 @@ |
||
31 | 31 | */ |
32 | 32 | class GeoAnalysisViewTabs implements RequestHandlerInterface |
33 | 33 | { |
34 | - private ?GeoDispersionModule $module; |
|
35 | - private GeoAnalysisViewDataService $geoviewdata_service; |
|
34 | + private ?GeoDispersionModule $module; |
|
35 | + private GeoAnalysisViewDataService $geoviewdata_service; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for GeoAnalysisMapsList Request Handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - ModuleService $module_service, |
|
44 | - GeoAnalysisViewDataService $geoviewdata_service |
|
45 | - ) { |
|
46 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
47 | - $this->geoviewdata_service = $geoviewdata_service; |
|
48 | - } |
|
37 | + /** |
|
38 | + * Constructor for GeoAnalysisMapsList Request Handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + ModuleService $module_service, |
|
44 | + GeoAnalysisViewDataService $geoviewdata_service |
|
45 | + ) { |
|
46 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
47 | + $this->geoviewdata_service = $geoviewdata_service; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | - */ |
|
54 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | - { |
|
56 | - if ($this->module === null) { |
|
57 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
58 | - } |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | + */ |
|
54 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | + { |
|
56 | + if ($this->module === null) { |
|
57 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
58 | + } |
|
59 | 59 | |
60 | - $tree = Validator::attributes($request)->tree(); |
|
61 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
60 | + $tree = Validator::attributes($request)->tree(); |
|
61 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
62 | 62 | |
63 | - $view = $this->geoviewdata_service->find($tree, $view_id); |
|
63 | + $view = $this->geoviewdata_service->find($tree, $view_id); |
|
64 | 64 | |
65 | - if ($view === null) { |
|
66 | - throw new HttpNotFoundException(I18N::translate('The requested dispersion analysis does not exist.')); |
|
67 | - } |
|
65 | + if ($view === null) { |
|
66 | + throw new HttpNotFoundException(I18N::translate('The requested dispersion analysis does not exist.')); |
|
67 | + } |
|
68 | 68 | |
69 | - $results = $view->analysis()->results($tree, $view->placesDepth()); |
|
69 | + $results = $view->analysis()->results($tree, $view->placesDepth()); |
|
70 | 70 | |
71 | - $params = [ |
|
72 | - 'module_name' => $this->module->name(), |
|
73 | - 'tree' => $tree, |
|
74 | - 'view' => $view, |
|
75 | - 'items_descr' => $view->analysis()->itemsDescription() |
|
76 | - ]; |
|
77 | - $response = [ |
|
78 | - 'global' => view('layouts/ajax', [ |
|
79 | - 'content' => $view->globalTabContent($this->module, $results->global(), $params) |
|
80 | - ]), |
|
81 | - 'detailed' => view('layouts/ajax', [ |
|
82 | - 'content' => $view->detailedTabContent($this->module, $results->sortedDetailed(), $params) |
|
83 | - ]) |
|
84 | - ]; |
|
71 | + $params = [ |
|
72 | + 'module_name' => $this->module->name(), |
|
73 | + 'tree' => $tree, |
|
74 | + 'view' => $view, |
|
75 | + 'items_descr' => $view->analysis()->itemsDescription() |
|
76 | + ]; |
|
77 | + $response = [ |
|
78 | + 'global' => view('layouts/ajax', [ |
|
79 | + 'content' => $view->globalTabContent($this->module, $results->global(), $params) |
|
80 | + ]), |
|
81 | + 'detailed' => view('layouts/ajax', [ |
|
82 | + 'content' => $view->detailedTabContent($this->module, $results->sortedDetailed(), $params) |
|
83 | + ]) |
|
84 | + ]; |
|
85 | 85 | |
86 | - return Registry::responseFactory()->response($response); |
|
87 | - } |
|
86 | + return Registry::responseFactory()->response($response); |
|
87 | + } |
|
88 | 88 | } |
@@ -32,65 +32,65 @@ |
||
32 | 32 | */ |
33 | 33 | class GeoAnalysisViewStatusAction implements RequestHandlerInterface |
34 | 34 | { |
35 | - private ?GeoDispersionModule $module; |
|
36 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
35 | + private ?GeoDispersionModule $module; |
|
36 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor for GeoAnalysisViewStatusAction Request Handler |
|
40 | - * |
|
41 | - * @param ModuleService $module_service |
|
42 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
43 | - */ |
|
44 | - public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
45 | - { |
|
46 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
47 | - $this->geoview_data_service = $geoview_data_service; |
|
48 | - } |
|
38 | + /** |
|
39 | + * Constructor for GeoAnalysisViewStatusAction Request Handler |
|
40 | + * |
|
41 | + * @param ModuleService $module_service |
|
42 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
43 | + */ |
|
44 | + public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
45 | + { |
|
46 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
47 | + $this->geoview_data_service = $geoview_data_service; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | - */ |
|
54 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | - { |
|
56 | - $tree = Validator::attributes($request)->tree(); |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | + */ |
|
54 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | + { |
|
56 | + $tree = Validator::attributes($request)->tree(); |
|
57 | 57 | |
58 | - if ($this->module === null) { |
|
59 | - FlashMessages::addMessage( |
|
60 | - I18N::translate('The attached module could not be found.'), |
|
61 | - 'danger' |
|
62 | - ); |
|
63 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
64 | - } |
|
58 | + if ($this->module === null) { |
|
59 | + FlashMessages::addMessage( |
|
60 | + I18N::translate('The attached module could not be found.'), |
|
61 | + 'danger' |
|
62 | + ); |
|
63 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
64 | + } |
|
65 | 65 | |
66 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
67 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
66 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
67 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
68 | 68 | |
69 | - if ($view === null) { |
|
70 | - FlashMessages::addMessage( |
|
71 | - I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)), |
|
72 | - 'danger' |
|
73 | - ); |
|
74 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
75 | - } |
|
69 | + if ($view === null) { |
|
70 | + FlashMessages::addMessage( |
|
71 | + I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)), |
|
72 | + 'danger' |
|
73 | + ); |
|
74 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
75 | + } |
|
76 | 76 | |
77 | - try { |
|
78 | - $this->geoview_data_service->updateStatus($view, Validator::attributes($request)->boolean('enable', false)); |
|
79 | - FlashMessages::addMessage( |
|
80 | - I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
|
81 | - 'success' |
|
82 | - ); |
|
83 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
84 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
85 | - } catch (Throwable $ex) { |
|
86 | - FlashMessages::addMessage( |
|
87 | - I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
|
88 | - 'danger' |
|
89 | - ); |
|
90 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
91 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
92 | - } |
|
77 | + try { |
|
78 | + $this->geoview_data_service->updateStatus($view, Validator::attributes($request)->boolean('enable', false)); |
|
79 | + FlashMessages::addMessage( |
|
80 | + I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
|
81 | + 'success' |
|
82 | + ); |
|
83 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
84 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
85 | + } catch (Throwable $ex) { |
|
86 | + FlashMessages::addMessage( |
|
87 | + I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
|
88 | + 'danger' |
|
89 | + ); |
|
90 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
91 | + Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
92 | + } |
|
93 | 93 | |
94 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
95 | - } |
|
94 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
95 | + } |
|
96 | 96 | } |
@@ -81,14 +81,14 @@ |
||
81 | 81 | 'success' |
82 | 82 | ); |
83 | 83 | //phpcs:ignore Generic.Files.LineLength.TooLong |
84 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
84 | + Log::addConfigurationLog('Module '.$this->module->title().' : View “'.$view->id().'” has been updated.'); |
|
85 | 85 | } catch (Throwable $ex) { |
86 | 86 | FlashMessages::addMessage( |
87 | 87 | I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
88 | 88 | 'danger' |
89 | 89 | ); |
90 | 90 | //phpcs:ignore Generic.Files.LineLength.TooLong |
91 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
91 | + Log::addErrorLog('Module '.$this->module->title().' : Error when updating view “'.$view->id().'”: '.$ex->getMessage()); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
@@ -31,67 +31,67 @@ |
||
31 | 31 | */ |
32 | 32 | class MapAdapterDeleteAction implements RequestHandlerInterface |
33 | 33 | { |
34 | - private ?GeoDispersionModule $module; |
|
35 | - private MapAdapterDataService $mapadapter_data_service; |
|
34 | + private ?GeoDispersionModule $module; |
|
35 | + private MapAdapterDataService $mapadapter_data_service; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for MapAdapterDeleteAction Request Handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - * @param MapAdapterDataService $mapadapter_data_service |
|
42 | - */ |
|
43 | - public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service) |
|
44 | - { |
|
45 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
46 | - $this->mapadapter_data_service = $mapadapter_data_service; |
|
47 | - } |
|
37 | + /** |
|
38 | + * Constructor for MapAdapterDeleteAction Request Handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + * @param MapAdapterDataService $mapadapter_data_service |
|
42 | + */ |
|
43 | + public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service) |
|
44 | + { |
|
45 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
46 | + $this->mapadapter_data_service = $mapadapter_data_service; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | - */ |
|
53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | - { |
|
55 | - $tree = Validator::attributes($request)->tree(); |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | + */ |
|
53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | + { |
|
55 | + $tree = Validator::attributes($request)->tree(); |
|
56 | 56 | |
57 | - if ($this->module === null) { |
|
58 | - FlashMessages::addMessage( |
|
59 | - I18N::translate('The attached module could not be found.'), |
|
60 | - 'danger' |
|
61 | - ); |
|
62 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
63 | - } |
|
57 | + if ($this->module === null) { |
|
58 | + FlashMessages::addMessage( |
|
59 | + I18N::translate('The attached module could not be found.'), |
|
60 | + 'danger' |
|
61 | + ); |
|
62 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
63 | + } |
|
64 | 64 | |
65 | - $adapter_id = Validator::attributes($request)->integer('adapter_id', -1); |
|
66 | - $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
|
65 | + $adapter_id = Validator::attributes($request)->integer('adapter_id', -1); |
|
66 | + $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
|
67 | 67 | |
68 | - if ($map_adapter === null) { |
|
69 | - FlashMessages::addMessage( |
|
70 | - I18N::translate('The map configuration with ID “%d” does not exist.', I18N::number($adapter_id)), |
|
71 | - 'danger' |
|
72 | - ); |
|
73 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
74 | - } |
|
68 | + if ($map_adapter === null) { |
|
69 | + FlashMessages::addMessage( |
|
70 | + I18N::translate('The map configuration with ID “%d” does not exist.', I18N::number($adapter_id)), |
|
71 | + 'danger' |
|
72 | + ); |
|
73 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($this->mapadapter_data_service->delete($map_adapter) > 0) { |
|
77 | - FlashMessages::addMessage( |
|
78 | - I18N::translate('The map configuration has been successfully deleted.'), |
|
79 | - 'success' |
|
80 | - ); |
|
81 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.'); |
|
83 | - } else { |
|
84 | - FlashMessages::addMessage( |
|
85 | - I18N::translate('An error occured while deleting the map configuration.'), |
|
86 | - 'danger' |
|
87 | - ); |
|
88 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
89 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.'); |
|
90 | - } |
|
76 | + if ($this->mapadapter_data_service->delete($map_adapter) > 0) { |
|
77 | + FlashMessages::addMessage( |
|
78 | + I18N::translate('The map configuration has been successfully deleted.'), |
|
79 | + 'success' |
|
80 | + ); |
|
81 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.'); |
|
83 | + } else { |
|
84 | + FlashMessages::addMessage( |
|
85 | + I18N::translate('An error occured while deleting the map configuration.'), |
|
86 | + 'danger' |
|
87 | + ); |
|
88 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
89 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.'); |
|
90 | + } |
|
91 | 91 | |
92 | - return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
93 | - 'tree' => $tree->name(), |
|
94 | - 'view_id' => $map_adapter->geoAnalysisViewId() |
|
95 | - ]); |
|
96 | - } |
|
92 | + return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
93 | + 'tree' => $tree->name(), |
|
94 | + 'view_id' => $map_adapter->geoAnalysisViewId() |
|
95 | + ]); |
|
96 | + } |
|
97 | 97 | } |
@@ -79,14 +79,14 @@ |
||
79 | 79 | 'success' |
80 | 80 | ); |
81 | 81 | //phpcs:ignore Generic.Files.LineLength.TooLong |
82 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.'); |
|
82 | + Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” has been deleted.'); |
|
83 | 83 | } else { |
84 | 84 | FlashMessages::addMessage( |
85 | 85 | I18N::translate('An error occured while deleting the map configuration.'), |
86 | 86 | 'danger' |
87 | 87 | ); |
88 | 88 | //phpcs:ignore Generic.Files.LineLength.TooLong |
89 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.'); |
|
89 | + Log::addConfigurationLog('Module '.$this->module->title().' : Map Adapter “'.$map_adapter->id().'” could not be deleted. See error log.'); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
@@ -36,81 +36,81 @@ |
||
36 | 36 | */ |
37 | 37 | class GeoAnalysisViewAddAction implements RequestHandlerInterface |
38 | 38 | { |
39 | - private ?GeoDispersionModule $module; |
|
40 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
39 | + private ?GeoDispersionModule $module; |
|
40 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for GeoAnalysisViewAddAction Request Handler |
|
44 | - * |
|
45 | - * @param ModuleService $module_service |
|
46 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
47 | - */ |
|
48 | - public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
49 | - { |
|
50 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
51 | - $this->geoview_data_service = $geoview_data_service; |
|
52 | - } |
|
42 | + /** |
|
43 | + * Constructor for GeoAnalysisViewAddAction Request Handler |
|
44 | + * |
|
45 | + * @param ModuleService $module_service |
|
46 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
47 | + */ |
|
48 | + public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
49 | + { |
|
50 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
51 | + $this->geoview_data_service = $geoview_data_service; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | - */ |
|
58 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | - { |
|
60 | - $tree = Validator::attributes($request)->tree(); |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | + */ |
|
58 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | + { |
|
60 | + $tree = Validator::attributes($request)->tree(); |
|
61 | 61 | |
62 | - if ($this->module === null) { |
|
63 | - FlashMessages::addMessage( |
|
64 | - I18N::translate('The attached module could not be found.'), |
|
65 | - 'danger' |
|
66 | - ); |
|
67 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
68 | - } |
|
62 | + if ($this->module === null) { |
|
63 | + FlashMessages::addMessage( |
|
64 | + I18N::translate('The attached module could not be found.'), |
|
65 | + 'danger' |
|
66 | + ); |
|
67 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
68 | + } |
|
69 | 69 | |
70 | - $type = Validator::parsedBody($request)->isInArray(['table', 'map'])->string('view_type', ''); |
|
71 | - $description = Validator::parsedBody($request)->string('view_description', ''); |
|
72 | - $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
|
70 | + $type = Validator::parsedBody($request)->isInArray(['table', 'map'])->string('view_type', ''); |
|
71 | + $description = Validator::parsedBody($request)->string('view_description', ''); |
|
72 | + $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
|
73 | 73 | |
74 | - $analysis = null; |
|
75 | - try { |
|
76 | - $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
|
77 | - } catch (BindingResolutionException $ex) { |
|
78 | - } |
|
74 | + $analysis = null; |
|
75 | + try { |
|
76 | + $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
|
77 | + } catch (BindingResolutionException $ex) { |
|
78 | + } |
|
79 | 79 | |
80 | - if ($type === '' || $place_depth <= 0 || $analysis === null || !($analysis instanceof GeoAnalysisInterface)) { |
|
81 | - FlashMessages::addMessage( |
|
82 | - I18N::translate('The parameters for the new view are not valid.'), |
|
83 | - 'danger' |
|
84 | - ); |
|
85 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
86 | - } |
|
80 | + if ($type === '' || $place_depth <= 0 || $analysis === null || !($analysis instanceof GeoAnalysisInterface)) { |
|
81 | + FlashMessages::addMessage( |
|
82 | + I18N::translate('The parameters for the new view are not valid.'), |
|
83 | + 'danger' |
|
84 | + ); |
|
85 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
86 | + } |
|
87 | 87 | |
88 | - if ($type === 'map') { |
|
89 | - $new_view = new GeoAnalysisMap(0, $tree, true, $description, $analysis, $place_depth); |
|
90 | - } else { |
|
91 | - $new_view = new GeoAnalysisTable(0, $tree, true, $description, $analysis, $place_depth); |
|
92 | - } |
|
88 | + if ($type === 'map') { |
|
89 | + $new_view = new GeoAnalysisMap(0, $tree, true, $description, $analysis, $place_depth); |
|
90 | + } else { |
|
91 | + $new_view = new GeoAnalysisTable(0, $tree, true, $description, $analysis, $place_depth); |
|
92 | + } |
|
93 | 93 | |
94 | - $new_view_id = $this->geoview_data_service->insertGetId($new_view); |
|
95 | - if ($new_view_id > 0) { |
|
96 | - FlashMessages::addMessage( |
|
97 | - I18N::translate('The geographical dispersion analysis view has been successfully added.'), |
|
98 | - 'success' |
|
99 | - ); |
|
100 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
101 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.'); |
|
102 | - return Registry::responseFactory()->redirect( |
|
103 | - GeoAnalysisViewEditPage::class, |
|
104 | - ['tree' => $tree->name(), 'view_id' => $new_view_id ] |
|
105 | - ); |
|
106 | - } else { |
|
107 | - FlashMessages::addMessage( |
|
108 | - I18N::translate('An error occured while adding the geographical dispersion analysis view.'), |
|
109 | - 'danger' |
|
110 | - ); |
|
111 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
112 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : A new View could not be added. See error log.'); |
|
113 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
114 | - } |
|
115 | - } |
|
94 | + $new_view_id = $this->geoview_data_service->insertGetId($new_view); |
|
95 | + if ($new_view_id > 0) { |
|
96 | + FlashMessages::addMessage( |
|
97 | + I18N::translate('The geographical dispersion analysis view has been successfully added.'), |
|
98 | + 'success' |
|
99 | + ); |
|
100 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
101 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.'); |
|
102 | + return Registry::responseFactory()->redirect( |
|
103 | + GeoAnalysisViewEditPage::class, |
|
104 | + ['tree' => $tree->name(), 'view_id' => $new_view_id ] |
|
105 | + ); |
|
106 | + } else { |
|
107 | + FlashMessages::addMessage( |
|
108 | + I18N::translate('An error occured while adding the geographical dispersion analysis view.'), |
|
109 | + 'danger' |
|
110 | + ); |
|
111 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
112 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : A new View could not be added. See error log.'); |
|
113 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | } |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | 'success' |
99 | 99 | ); |
100 | 100 | //phpcs:ignore Generic.Files.LineLength.TooLong |
101 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $new_view_id . '” has been added.'); |
|
101 | + Log::addConfigurationLog('Module '.$this->module->title().' : View “'.$new_view_id.'” has been added.'); |
|
102 | 102 | return Registry::responseFactory()->redirect( |
103 | 103 | GeoAnalysisViewEditPage::class, |
104 | - ['tree' => $tree->name(), 'view_id' => $new_view_id ] |
|
104 | + ['tree' => $tree->name(), 'view_id' => $new_view_id] |
|
105 | 105 | ); |
106 | 106 | } else { |
107 | 107 | FlashMessages::addMessage( |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'danger' |
110 | 110 | ); |
111 | 111 | //phpcs:ignore Generic.Files.LineLength.TooLong |
112 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : A new View could not be added. See error log.'); |
|
112 | + Log::addConfigurationLog('Module '.$this->module->title().' : A new View could not be added. See error log.'); |
|
113 | 113 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
114 | 114 | } |
115 | 115 | } |
@@ -34,87 +34,87 @@ |
||
34 | 34 | */ |
35 | 35 | class GeoAnalysisViewEditAction implements RequestHandlerInterface |
36 | 36 | { |
37 | - private ?GeoDispersionModule $module; |
|
38 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor for GeoAnalysisViewEditAction Request Handler |
|
42 | - * |
|
43 | - * @param ModuleService $module_service |
|
44 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
45 | - */ |
|
46 | - public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
47 | - { |
|
48 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
49 | - $this->geoview_data_service = $geoview_data_service; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | - */ |
|
56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | - { |
|
58 | - $tree = Validator::attributes($request)->tree(); |
|
59 | - |
|
60 | - if ($this->module === null) { |
|
61 | - FlashMessages::addMessage( |
|
62 | - I18N::translate('The attached module could not be found.'), |
|
63 | - 'danger' |
|
64 | - ); |
|
65 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
70 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
71 | - |
|
72 | - $description = Validator::parsedBody($request)->string('view_description', ''); |
|
73 | - $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
|
74 | - $top_places = Validator::parsedBody($request)->integer('view_top_places', 0); |
|
75 | - |
|
76 | - $analysis = null; |
|
77 | - try { |
|
78 | - $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
|
79 | - } catch (BindingResolutionException $ex) { |
|
80 | - } |
|
81 | - |
|
82 | - if ( |
|
83 | - $view === null |
|
84 | - || $analysis === null || !($analysis instanceof GeoAnalysisInterface) |
|
85 | - || $place_depth <= 0 && $top_places < 0 |
|
86 | - ) { |
|
87 | - FlashMessages::addMessage( |
|
88 | - I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)), |
|
89 | - 'danger' |
|
90 | - ); |
|
91 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
92 | - } |
|
93 | - |
|
94 | - $new_view = $view |
|
95 | - ->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places) |
|
96 | - ->withGlobalSettingsUpdate($request); |
|
97 | - |
|
98 | - try { |
|
99 | - $this->geoview_data_service->update($new_view); |
|
100 | - FlashMessages::addMessage( |
|
101 | - I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
|
102 | - 'success' |
|
103 | - ); |
|
104 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
105 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
106 | - } catch (Throwable $ex) { |
|
107 | - FlashMessages::addMessage( |
|
108 | - I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
|
109 | - 'danger' |
|
110 | - ); |
|
111 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
112 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
113 | - } |
|
114 | - |
|
115 | - return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
116 | - 'tree' => $tree->name(), |
|
117 | - 'view_id' => $view->id() |
|
118 | - ]); |
|
119 | - } |
|
37 | + private ?GeoDispersionModule $module; |
|
38 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor for GeoAnalysisViewEditAction Request Handler |
|
42 | + * |
|
43 | + * @param ModuleService $module_service |
|
44 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
45 | + */ |
|
46 | + public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
47 | + { |
|
48 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
49 | + $this->geoview_data_service = $geoview_data_service; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | + */ |
|
56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | + { |
|
58 | + $tree = Validator::attributes($request)->tree(); |
|
59 | + |
|
60 | + if ($this->module === null) { |
|
61 | + FlashMessages::addMessage( |
|
62 | + I18N::translate('The attached module could not be found.'), |
|
63 | + 'danger' |
|
64 | + ); |
|
65 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
70 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
71 | + |
|
72 | + $description = Validator::parsedBody($request)->string('view_description', ''); |
|
73 | + $place_depth = Validator::parsedBody($request)->integer('view_depth', 1); |
|
74 | + $top_places = Validator::parsedBody($request)->integer('view_top_places', 0); |
|
75 | + |
|
76 | + $analysis = null; |
|
77 | + try { |
|
78 | + $analysis = app(Validator::parsedBody($request)->string('view_analysis', '')); |
|
79 | + } catch (BindingResolutionException $ex) { |
|
80 | + } |
|
81 | + |
|
82 | + if ( |
|
83 | + $view === null |
|
84 | + || $analysis === null || !($analysis instanceof GeoAnalysisInterface) |
|
85 | + || $place_depth <= 0 && $top_places < 0 |
|
86 | + ) { |
|
87 | + FlashMessages::addMessage( |
|
88 | + I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)), |
|
89 | + 'danger' |
|
90 | + ); |
|
91 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
92 | + } |
|
93 | + |
|
94 | + $new_view = $view |
|
95 | + ->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places) |
|
96 | + ->withGlobalSettingsUpdate($request); |
|
97 | + |
|
98 | + try { |
|
99 | + $this->geoview_data_service->update($new_view); |
|
100 | + FlashMessages::addMessage( |
|
101 | + I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
|
102 | + 'success' |
|
103 | + ); |
|
104 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
105 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
106 | + } catch (Throwable $ex) { |
|
107 | + FlashMessages::addMessage( |
|
108 | + I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
|
109 | + 'danger' |
|
110 | + ); |
|
111 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
112 | + Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
113 | + } |
|
114 | + |
|
115 | + return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
116 | + 'tree' => $tree->name(), |
|
117 | + 'view_id' => $view->id() |
|
118 | + ]); |
|
119 | + } |
|
120 | 120 | } |
@@ -102,14 +102,14 @@ |
||
102 | 102 | 'success' |
103 | 103 | ); |
104 | 104 | //phpcs:ignore Generic.Files.LineLength.TooLong |
105 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
105 | + Log::addConfigurationLog('Module '.$this->module->title().' : View “'.$view->id().'” has been updated.'); |
|
106 | 106 | } catch (Throwable $ex) { |
107 | 107 | FlashMessages::addMessage( |
108 | 108 | I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
109 | 109 | 'danger' |
110 | 110 | ); |
111 | 111 | //phpcs:ignore Generic.Files.LineLength.TooLong |
112 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
112 | + Log::addErrorLog('Module '.$this->module->title().' : Error when updating view “'.$view->id().'”: '.$ex->getMessage()); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
@@ -35,77 +35,77 @@ |
||
35 | 35 | */ |
36 | 36 | class MapAdapterDeleteInvalidAction implements RequestHandlerInterface |
37 | 37 | { |
38 | - private ?GeoDispersionModule $module; |
|
39 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
40 | - private MapAdapterDataService $mapadapter_data_service; |
|
38 | + private ?GeoDispersionModule $module; |
|
39 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
40 | + private MapAdapterDataService $mapadapter_data_service; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for MapAdapterDeleteInvalidAction Request Handler |
|
44 | - * |
|
45 | - * @param ModuleService $module_service |
|
46 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
47 | - * @param MapAdapterDataService $mapadapter_data_service |
|
48 | - */ |
|
49 | - public function __construct( |
|
50 | - ModuleService $module_service, |
|
51 | - GeoAnalysisViewDataService $geoview_data_service, |
|
52 | - MapAdapterDataService $mapadapter_data_service |
|
53 | - ) { |
|
54 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
55 | - $this->geoview_data_service = $geoview_data_service; |
|
56 | - $this->mapadapter_data_service = $mapadapter_data_service; |
|
57 | - } |
|
42 | + /** |
|
43 | + * Constructor for MapAdapterDeleteInvalidAction Request Handler |
|
44 | + * |
|
45 | + * @param ModuleService $module_service |
|
46 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
47 | + * @param MapAdapterDataService $mapadapter_data_service |
|
48 | + */ |
|
49 | + public function __construct( |
|
50 | + ModuleService $module_service, |
|
51 | + GeoAnalysisViewDataService $geoview_data_service, |
|
52 | + MapAdapterDataService $mapadapter_data_service |
|
53 | + ) { |
|
54 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
55 | + $this->geoview_data_service = $geoview_data_service; |
|
56 | + $this->mapadapter_data_service = $mapadapter_data_service; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
62 | - */ |
|
63 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
64 | - { |
|
65 | - $tree = Validator::attributes($request)->tree(); |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
62 | + */ |
|
63 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
64 | + { |
|
65 | + $tree = Validator::attributes($request)->tree(); |
|
66 | 66 | |
67 | - if ($this->module === null) { |
|
68 | - FlashMessages::addMessage( |
|
69 | - I18N::translate('The attached module could not be found.'), |
|
70 | - 'danger' |
|
71 | - ); |
|
72 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
73 | - } |
|
67 | + if ($this->module === null) { |
|
68 | + FlashMessages::addMessage( |
|
69 | + I18N::translate('The attached module could not be found.'), |
|
70 | + 'danger' |
|
71 | + ); |
|
72 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
73 | + } |
|
74 | 74 | |
75 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
76 | - $view = $this->geoview_data_service->find($tree, $view_id); |
|
75 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
76 | + $view = $this->geoview_data_service->find($tree, $view_id); |
|
77 | 77 | |
78 | - if ($view === null || !($view instanceof GeoAnalysisMap)) { |
|
79 | - FlashMessages::addMessage( |
|
80 | - I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)), |
|
81 | - 'danger' |
|
82 | - ); |
|
83 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
84 | - } |
|
78 | + if ($view === null || !($view instanceof GeoAnalysisMap)) { |
|
79 | + FlashMessages::addMessage( |
|
80 | + I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)), |
|
81 | + 'danger' |
|
82 | + ); |
|
83 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
84 | + } |
|
85 | 85 | |
86 | - /** @var \Illuminate\Support\Collection<int> $valid_map_adapters */ |
|
87 | - $valid_map_adapters = $this->mapadapter_data_service |
|
88 | - ->allForView($view) |
|
89 | - ->map(fn(GeoAnalysisMapAdapter $map_adapter): int => $map_adapter->id()); |
|
86 | + /** @var \Illuminate\Support\Collection<int> $valid_map_adapters */ |
|
87 | + $valid_map_adapters = $this->mapadapter_data_service |
|
88 | + ->allForView($view) |
|
89 | + ->map(fn(GeoAnalysisMapAdapter $map_adapter): int => $map_adapter->id()); |
|
90 | 90 | |
91 | - try { |
|
92 | - $this->mapadapter_data_service->deleteInvalid($view, $valid_map_adapters); |
|
93 | - FlashMessages::addMessage( |
|
94 | - I18N::translate('The invalid map configurations have been successfully deleted.'), |
|
95 | - 'success' |
|
96 | - ); |
|
97 | - } catch (Throwable $ex) { |
|
98 | - FlashMessages::addMessage( |
|
99 | - I18N::translate('An error occured while deleting the invalid map configurations.'), |
|
100 | - 'danger' |
|
101 | - ); |
|
102 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
103 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Error when deleting invalid map configurations: ' . $ex->getMessage()); |
|
104 | - } |
|
91 | + try { |
|
92 | + $this->mapadapter_data_service->deleteInvalid($view, $valid_map_adapters); |
|
93 | + FlashMessages::addMessage( |
|
94 | + I18N::translate('The invalid map configurations have been successfully deleted.'), |
|
95 | + 'success' |
|
96 | + ); |
|
97 | + } catch (Throwable $ex) { |
|
98 | + FlashMessages::addMessage( |
|
99 | + I18N::translate('An error occured while deleting the invalid map configurations.'), |
|
100 | + 'danger' |
|
101 | + ); |
|
102 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
103 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Error when deleting invalid map configurations: ' . $ex->getMessage()); |
|
104 | + } |
|
105 | 105 | |
106 | - return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
107 | - 'tree' => $tree->name(), |
|
108 | - 'view_id' => $view_id |
|
109 | - ]); |
|
110 | - } |
|
106 | + return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
|
107 | + 'tree' => $tree->name(), |
|
108 | + 'view_id' => $view_id |
|
109 | + ]); |
|
110 | + } |
|
111 | 111 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | 'danger' |
101 | 101 | ); |
102 | 102 | //phpcs:ignore Generic.Files.LineLength.TooLong |
103 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Error when deleting invalid map configurations: ' . $ex->getMessage()); |
|
103 | + Log::addConfigurationLog('Module '.$this->module->title().' : Error when deleting invalid map configurations: '.$ex->getMessage()); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [ |
@@ -31,64 +31,64 @@ |
||
31 | 31 | */ |
32 | 32 | class GeoAnalysisViewDeleteAction implements RequestHandlerInterface |
33 | 33 | { |
34 | - private ?GeoDispersionModule $module; |
|
35 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
34 | + private ?GeoDispersionModule $module; |
|
35 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for GeoAnalysisViewDeleteAction Request Handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
42 | - */ |
|
43 | - public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
44 | - { |
|
45 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
46 | - $this->geoview_data_service = $geoview_data_service; |
|
47 | - } |
|
37 | + /** |
|
38 | + * Constructor for GeoAnalysisViewDeleteAction Request Handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
42 | + */ |
|
43 | + public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
44 | + { |
|
45 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
46 | + $this->geoview_data_service = $geoview_data_service; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | - */ |
|
53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | - { |
|
55 | - $tree = Validator::attributes($request)->tree(); |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | + */ |
|
53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | + { |
|
55 | + $tree = Validator::attributes($request)->tree(); |
|
56 | 56 | |
57 | - if ($this->module === null) { |
|
58 | - FlashMessages::addMessage( |
|
59 | - I18N::translate('The attached module could not be found.'), |
|
60 | - 'danger' |
|
61 | - ); |
|
62 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
63 | - } |
|
57 | + if ($this->module === null) { |
|
58 | + FlashMessages::addMessage( |
|
59 | + I18N::translate('The attached module could not be found.'), |
|
60 | + 'danger' |
|
61 | + ); |
|
62 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
63 | + } |
|
64 | 64 | |
65 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
66 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
65 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
66 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
67 | 67 | |
68 | - if ($view === null) { |
|
69 | - FlashMessages::addMessage( |
|
70 | - I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)), |
|
71 | - 'danger' |
|
72 | - ); |
|
73 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
74 | - } |
|
68 | + if ($view === null) { |
|
69 | + FlashMessages::addMessage( |
|
70 | + I18N::translate('The view with ID “%s” does not exist.', I18N::number($view_id)), |
|
71 | + 'danger' |
|
72 | + ); |
|
73 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($this->geoview_data_service->delete($view) > 0) { |
|
77 | - FlashMessages::addMessage( |
|
78 | - I18N::translate('The geographical dispersion analysis view has been successfully deleted.'), |
|
79 | - 'success' |
|
80 | - ); |
|
81 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been deleted.'); |
|
83 | - } else { |
|
84 | - FlashMessages::addMessage( |
|
85 | - I18N::translate('An error occured while deleting the geographical dispersion analysis view.'), |
|
86 | - 'danger' |
|
87 | - ); |
|
88 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
89 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” could not be deleted. See error log.'); |
|
90 | - } |
|
76 | + if ($this->geoview_data_service->delete($view) > 0) { |
|
77 | + FlashMessages::addMessage( |
|
78 | + I18N::translate('The geographical dispersion analysis view has been successfully deleted.'), |
|
79 | + 'success' |
|
80 | + ); |
|
81 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been deleted.'); |
|
83 | + } else { |
|
84 | + FlashMessages::addMessage( |
|
85 | + I18N::translate('An error occured while deleting the geographical dispersion analysis view.'), |
|
86 | + 'danger' |
|
87 | + ); |
|
88 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
89 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” could not be deleted. See error log.'); |
|
90 | + } |
|
91 | 91 | |
92 | - return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
93 | - } |
|
92 | + return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
93 | + } |
|
94 | 94 | } |
@@ -79,14 +79,14 @@ |
||
79 | 79 | 'success' |
80 | 80 | ); |
81 | 81 | //phpcs:ignore Generic.Files.LineLength.TooLong |
82 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been deleted.'); |
|
82 | + Log::addConfigurationLog('Module '.$this->module->title().' : View “'.$view->id().'” has been deleted.'); |
|
83 | 83 | } else { |
84 | 84 | FlashMessages::addMessage( |
85 | 85 | I18N::translate('An error occured while deleting the geographical dispersion analysis view.'), |
86 | 86 | 'danger' |
87 | 87 | ); |
88 | 88 | //phpcs:ignore Generic.Files.LineLength.TooLong |
89 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” could not be deleted. See error log.'); |
|
89 | + Log::addConfigurationLog('Module '.$this->module->title().' : View “'.$view->id().'” could not be deleted. See error log.'); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]); |