@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | //How to update the database schema for this module |
52 | 52 | private const SCHEMA_TARGET_VERSION = 2; |
53 | 53 | private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
54 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
54 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * {@inheritDoc} |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function loadRoutes(Map $router): void |
93 | 93 | { |
94 | - $router->attach('', '', static function (Map $router): void { |
|
94 | + $router->attach('', '', static function(Map $router): void { |
|
95 | 95 | |
96 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
96 | + $router->attach('', '/module-maj/admintasks', static function(Map $router): void { |
|
97 | 97 | |
98 | - $router->attach('', '/admin', static function (Map $router): void { |
|
98 | + $router->attach('', '/admin', static function(Map $router): void { |
|
99 | 99 | |
100 | 100 | $router->extras([ |
101 | 101 | 'middleware' => [ |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | ]); |
105 | 105 | $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
106 | 106 | |
107 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
107 | + $router->attach('', '/tasks', static function(Map $router): void { |
|
108 | 108 | |
109 | 109 | $router->get(TasksList::class, '', TasksList::class); |
110 | 110 | $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function bodyContent(): string |
148 | 148 | { |
149 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
149 | + return view($this->name().'::snippet', ['url' => route(TaskTrigger::class)]); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -41,126 +41,126 @@ |
||
41 | 41 | * Allow for tasks to be run on a (nearly-)regular schedule |
42 | 42 | */ |
43 | 43 | class AdminTasksModule extends AbstractModule implements |
44 | - ModuleMyArtJaubInterface, |
|
45 | - ModuleConfigInterface, |
|
46 | - ModuleGlobalInterface, |
|
47 | - ModuleTasksProviderInterface |
|
44 | + ModuleMyArtJaubInterface, |
|
45 | + ModuleConfigInterface, |
|
46 | + ModuleGlobalInterface, |
|
47 | + ModuleTasksProviderInterface |
|
48 | 48 | { |
49 | - use ModuleMyArtJaubTrait { |
|
50 | - boot as traitBoot; |
|
51 | - } |
|
52 | - use ModuleConfigTrait; |
|
53 | - use ModuleGlobalTrait; |
|
54 | - |
|
55 | - //How to update the database schema for this module |
|
56 | - private const SCHEMA_TARGET_VERSION = 2; |
|
57 | - private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
58 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | - */ |
|
64 | - public function title(): string |
|
65 | - { |
|
66 | - return I18N::translate('Administration Tasks'); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | - */ |
|
73 | - public function description(): string |
|
74 | - { |
|
75 | - return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritDoc} |
|
80 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
81 | - */ |
|
82 | - public function boot(): void |
|
83 | - { |
|
84 | - $this->traitBoot(); |
|
85 | - app(MigrationService::class)->updateSchema( |
|
86 | - self::SCHEMA_MIGRATION_PREFIX, |
|
87 | - self::SCHEMA_SETTING_NAME, |
|
88 | - self::SCHEMA_TARGET_VERSION |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * {@inheritDoc} |
|
94 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
95 | - */ |
|
96 | - public function loadRoutes(Map $router): void |
|
97 | - { |
|
98 | - $router->attach('', '', static function (Map $router): void { |
|
99 | - |
|
100 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
101 | - |
|
102 | - $router->attach('', '/admin', static function (Map $router): void { |
|
103 | - |
|
104 | - $router->extras([ |
|
105 | - 'middleware' => [ |
|
106 | - AuthAdministrator::class, |
|
107 | - ], |
|
108 | - ]); |
|
109 | - $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
110 | - |
|
111 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
112 | - |
|
113 | - $router->get(TasksList::class, '', TasksList::class); |
|
114 | - $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
115 | - $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
116 | - $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
117 | - }); |
|
118 | - }); |
|
119 | - |
|
120 | - $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
121 | - ->allows(RequestMethodInterface::METHOD_POST); |
|
122 | - |
|
123 | - $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
124 | - ->extras(['middleware' => [AuthAdministrator::class]]); |
|
125 | - }); |
|
126 | - }); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * {@inheritDoc} |
|
131 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
132 | - */ |
|
133 | - public function customModuleVersion(): string |
|
134 | - { |
|
135 | - return '2.0.11-v.2'; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * {@inheritDoc} |
|
140 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
141 | - */ |
|
142 | - public function getConfigLink(): string |
|
143 | - { |
|
144 | - return route(AdminConfigPage::class); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * {@inheritDoc} |
|
149 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
150 | - */ |
|
151 | - public function bodyContent(): string |
|
152 | - { |
|
153 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * {@inheritDoc} |
|
158 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Contracts\ModuleTasksProviderInterface::listTasks() |
|
159 | - */ |
|
160 | - public function listTasks(): array |
|
161 | - { |
|
162 | - return [ |
|
163 | - 'maj-healthcheck' => HealthCheckEmailTask::class |
|
164 | - ]; |
|
165 | - } |
|
49 | + use ModuleMyArtJaubTrait { |
|
50 | + boot as traitBoot; |
|
51 | + } |
|
52 | + use ModuleConfigTrait; |
|
53 | + use ModuleGlobalTrait; |
|
54 | + |
|
55 | + //How to update the database schema for this module |
|
56 | + private const SCHEMA_TARGET_VERSION = 2; |
|
57 | + private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
58 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | + */ |
|
64 | + public function title(): string |
|
65 | + { |
|
66 | + return I18N::translate('Administration Tasks'); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | + */ |
|
73 | + public function description(): string |
|
74 | + { |
|
75 | + return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritDoc} |
|
80 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
81 | + */ |
|
82 | + public function boot(): void |
|
83 | + { |
|
84 | + $this->traitBoot(); |
|
85 | + app(MigrationService::class)->updateSchema( |
|
86 | + self::SCHEMA_MIGRATION_PREFIX, |
|
87 | + self::SCHEMA_SETTING_NAME, |
|
88 | + self::SCHEMA_TARGET_VERSION |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * {@inheritDoc} |
|
94 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
95 | + */ |
|
96 | + public function loadRoutes(Map $router): void |
|
97 | + { |
|
98 | + $router->attach('', '', static function (Map $router): void { |
|
99 | + |
|
100 | + $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
101 | + |
|
102 | + $router->attach('', '/admin', static function (Map $router): void { |
|
103 | + |
|
104 | + $router->extras([ |
|
105 | + 'middleware' => [ |
|
106 | + AuthAdministrator::class, |
|
107 | + ], |
|
108 | + ]); |
|
109 | + $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
110 | + |
|
111 | + $router->attach('', '/tasks', static function (Map $router): void { |
|
112 | + |
|
113 | + $router->get(TasksList::class, '', TasksList::class); |
|
114 | + $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
115 | + $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
116 | + $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
117 | + }); |
|
118 | + }); |
|
119 | + |
|
120 | + $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
121 | + ->allows(RequestMethodInterface::METHOD_POST); |
|
122 | + |
|
123 | + $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
124 | + ->extras(['middleware' => [AuthAdministrator::class]]); |
|
125 | + }); |
|
126 | + }); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * {@inheritDoc} |
|
131 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
132 | + */ |
|
133 | + public function customModuleVersion(): string |
|
134 | + { |
|
135 | + return '2.0.11-v.2'; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * {@inheritDoc} |
|
140 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
141 | + */ |
|
142 | + public function getConfigLink(): string |
|
143 | + { |
|
144 | + return route(AdminConfigPage::class); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * {@inheritDoc} |
|
149 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
150 | + */ |
|
151 | + public function bodyContent(): string |
|
152 | + { |
|
153 | + return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * {@inheritDoc} |
|
158 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Contracts\ModuleTasksProviderInterface::listTasks() |
|
159 | + */ |
|
160 | + public function listTasks(): array |
|
161 | + { |
|
162 | + return [ |
|
163 | + 'maj-healthcheck' => HealthCheckEmailTask::class |
|
164 | + ]; |
|
165 | + } |
|
166 | 166 | } |
@@ -25,290 +25,290 @@ |
||
25 | 25 | class TaskSchedule |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Task Schedule ID |
|
30 | - * @var int $id |
|
31 | - */ |
|
32 | - private $id; |
|
33 | - |
|
34 | - /** |
|
35 | - * Task schedule status |
|
36 | - * @var bool $enabled |
|
37 | - */ |
|
38 | - private $enabled; |
|
39 | - |
|
40 | - /** |
|
41 | - * ID of the task attached to schedule |
|
42 | - * @var string $task_id |
|
43 | - */ |
|
44 | - private $task_id; |
|
45 | - |
|
46 | - /** |
|
47 | - * Last updated date |
|
48 | - * @var Carbon $last_run |
|
49 | - */ |
|
50 | - private $last_run; |
|
51 | - |
|
52 | - /** |
|
53 | - * Last run result |
|
54 | - * @var bool $last_result |
|
55 | - */ |
|
56 | - private $last_result; |
|
57 | - |
|
58 | - /** |
|
59 | - * Task run frequency |
|
60 | - * @var CarbonInterval $frequency |
|
61 | - */ |
|
62 | - private $frequency; |
|
63 | - |
|
64 | - /** |
|
65 | - * Task remaining runs |
|
66 | - * @var int $nb_occurrences |
|
67 | - */ |
|
68 | - private $nb_occurrences; |
|
69 | - |
|
70 | - /** |
|
71 | - * Current running status of the task |
|
72 | - * @var bool $is_running |
|
73 | - */ |
|
74 | - private $is_running; |
|
75 | - |
|
76 | - /** |
|
77 | - * Constructor for TaskSchedule |
|
78 | - * |
|
79 | - * @param int $id Schedule ID |
|
80 | - * @param string $task_id Task ID |
|
81 | - * @param bool $enabled Is the schedule enabled |
|
82 | - * @param Carbon $last_run Last successful run date/time |
|
83 | - * @param bool $last_result Result of the last run |
|
84 | - * @param CarbonInterval $frequency Schedule frequency |
|
85 | - * @param int $nb_occurrences Number of remaining occurrences to be run |
|
86 | - * @param bool $is_running Is the task currently running |
|
87 | - */ |
|
88 | - public function __construct( |
|
89 | - int $id, |
|
90 | - string $task_id, |
|
91 | - bool $enabled, |
|
92 | - Carbon $last_run, |
|
93 | - bool $last_result, |
|
94 | - CarbonInterval $frequency, |
|
95 | - int $nb_occurrences, |
|
96 | - bool $is_running |
|
97 | - ) { |
|
98 | - $this->id = $id; |
|
99 | - $this->task_id = $task_id; |
|
100 | - $this->enabled = $enabled; |
|
101 | - $this->last_run = $last_run; |
|
102 | - $this->last_result = $last_result; |
|
103 | - $this->frequency = $frequency; |
|
104 | - $this->nb_occurrences = $nb_occurrences; |
|
105 | - $this->is_running = $is_running; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Get the schedule ID. |
|
110 | - * |
|
111 | - * @return int |
|
112 | - */ |
|
113 | - public function id(): int |
|
114 | - { |
|
115 | - return $this->id; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Get the task ID. |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function taskId(): string |
|
124 | - { |
|
125 | - return $this->task_id; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns whether the schedule is enabled |
|
130 | - * |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function isEnabled(): bool |
|
134 | - { |
|
135 | - return $this->enabled; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Enable the schedule |
|
140 | - * |
|
141 | - * @return self |
|
142 | - */ |
|
143 | - public function enable(): self |
|
144 | - { |
|
145 | - $this->enabled = true; |
|
146 | - return $this; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Disable the schedule |
|
151 | - * |
|
152 | - * @return self |
|
153 | - */ |
|
154 | - public function disable(): self |
|
155 | - { |
|
156 | - $this->enabled = false; |
|
157 | - return $this; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Get the frequency of the schedule |
|
162 | - * |
|
163 | - * @return CarbonInterval |
|
164 | - */ |
|
165 | - public function frequency(): CarbonInterval |
|
166 | - { |
|
167 | - return $this->frequency; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Set the frequency of the schedule |
|
172 | - * |
|
173 | - * @param CarbonInterval $frequency |
|
174 | - * @return self |
|
175 | - */ |
|
176 | - public function setFrequency(CarbonInterval $frequency): self |
|
177 | - { |
|
178 | - $this->frequency = $frequency; |
|
179 | - return $this; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Get the date/time of the last successful run. |
|
184 | - * |
|
185 | - * @return Carbon |
|
186 | - */ |
|
187 | - public function lastRunTime(): Carbon |
|
188 | - { |
|
189 | - return $this->last_run; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Set the last successful run date/time |
|
194 | - * |
|
195 | - * @param Carbon $last_run |
|
196 | - * @return self |
|
197 | - */ |
|
198 | - public function setLastRunTime(Carbon $last_run): self |
|
199 | - { |
|
200 | - $this->last_run = $last_run; |
|
201 | - return $this; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns whether the last run was successful |
|
206 | - * |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function wasLastRunSuccess(): bool |
|
210 | - { |
|
211 | - return $this->last_result; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Set the last run result |
|
216 | - * |
|
217 | - * @param bool $last_result |
|
218 | - * @return self |
|
219 | - */ |
|
220 | - public function setLastResult(bool $last_result): self |
|
221 | - { |
|
222 | - $this->last_result = $last_result; |
|
223 | - return $this; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Get the number of remaining of occurrences of task runs. |
|
228 | - * Returns 0 if the tasks must be run indefinitely. |
|
229 | - * |
|
230 | - * @return int |
|
231 | - */ |
|
232 | - public function remainingOccurences(): int |
|
233 | - { |
|
234 | - return $this->nb_occurrences; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Decrements the number of remaining occurences by 1. |
|
239 | - * The task will be disabled when the number reaches 0. |
|
240 | - * |
|
241 | - * @return self |
|
242 | - */ |
|
243 | - public function decrementRemainingOccurences(): self |
|
244 | - { |
|
245 | - if ($this->nb_occurrences > 0) { |
|
246 | - $this->nb_occurrences--; |
|
247 | - if ($this->nb_occurrences == 0) { |
|
248 | - $this->disable(); |
|
249 | - } |
|
250 | - } |
|
251 | - return $this; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Set the number of remaining occurences of task runs. |
|
256 | - * |
|
257 | - * @param int $nb_occurrences |
|
258 | - * @return self |
|
259 | - */ |
|
260 | - public function setRemainingOccurences(int $nb_occurrences): self |
|
261 | - { |
|
262 | - $this->nb_occurrences = $nb_occurrences; |
|
263 | - return $this; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Returns whether the task is running |
|
268 | - * @return bool |
|
269 | - */ |
|
270 | - public function isRunning(): bool |
|
271 | - { |
|
272 | - return $this->is_running; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Informs the schedule that the task is going to run |
|
277 | - * |
|
278 | - * @return self |
|
279 | - */ |
|
280 | - public function startRunning(): self |
|
281 | - { |
|
282 | - $this->is_running = true; |
|
283 | - return $this; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Informs the schedule that the task has stopped running. |
|
288 | - * @return self |
|
289 | - */ |
|
290 | - public function stopRunning(): self |
|
291 | - { |
|
292 | - $this->is_running = false; |
|
293 | - return $this; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the schedule details as an associate array |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function toArray(): array |
|
302 | - { |
|
303 | - return [ |
|
304 | - 'id' => $this->id, |
|
305 | - 'task_id' => $this->task_id, |
|
306 | - 'enabled' => $this->enabled, |
|
307 | - 'last_run' => $this->last_run, |
|
308 | - 'last_result' => $this->last_result, |
|
309 | - 'frequency' => $this->frequency, |
|
310 | - 'nb_occurrences' => $this->nb_occurrences, |
|
311 | - 'is_running' => $this->is_running |
|
312 | - ]; |
|
313 | - } |
|
28 | + /** |
|
29 | + * Task Schedule ID |
|
30 | + * @var int $id |
|
31 | + */ |
|
32 | + private $id; |
|
33 | + |
|
34 | + /** |
|
35 | + * Task schedule status |
|
36 | + * @var bool $enabled |
|
37 | + */ |
|
38 | + private $enabled; |
|
39 | + |
|
40 | + /** |
|
41 | + * ID of the task attached to schedule |
|
42 | + * @var string $task_id |
|
43 | + */ |
|
44 | + private $task_id; |
|
45 | + |
|
46 | + /** |
|
47 | + * Last updated date |
|
48 | + * @var Carbon $last_run |
|
49 | + */ |
|
50 | + private $last_run; |
|
51 | + |
|
52 | + /** |
|
53 | + * Last run result |
|
54 | + * @var bool $last_result |
|
55 | + */ |
|
56 | + private $last_result; |
|
57 | + |
|
58 | + /** |
|
59 | + * Task run frequency |
|
60 | + * @var CarbonInterval $frequency |
|
61 | + */ |
|
62 | + private $frequency; |
|
63 | + |
|
64 | + /** |
|
65 | + * Task remaining runs |
|
66 | + * @var int $nb_occurrences |
|
67 | + */ |
|
68 | + private $nb_occurrences; |
|
69 | + |
|
70 | + /** |
|
71 | + * Current running status of the task |
|
72 | + * @var bool $is_running |
|
73 | + */ |
|
74 | + private $is_running; |
|
75 | + |
|
76 | + /** |
|
77 | + * Constructor for TaskSchedule |
|
78 | + * |
|
79 | + * @param int $id Schedule ID |
|
80 | + * @param string $task_id Task ID |
|
81 | + * @param bool $enabled Is the schedule enabled |
|
82 | + * @param Carbon $last_run Last successful run date/time |
|
83 | + * @param bool $last_result Result of the last run |
|
84 | + * @param CarbonInterval $frequency Schedule frequency |
|
85 | + * @param int $nb_occurrences Number of remaining occurrences to be run |
|
86 | + * @param bool $is_running Is the task currently running |
|
87 | + */ |
|
88 | + public function __construct( |
|
89 | + int $id, |
|
90 | + string $task_id, |
|
91 | + bool $enabled, |
|
92 | + Carbon $last_run, |
|
93 | + bool $last_result, |
|
94 | + CarbonInterval $frequency, |
|
95 | + int $nb_occurrences, |
|
96 | + bool $is_running |
|
97 | + ) { |
|
98 | + $this->id = $id; |
|
99 | + $this->task_id = $task_id; |
|
100 | + $this->enabled = $enabled; |
|
101 | + $this->last_run = $last_run; |
|
102 | + $this->last_result = $last_result; |
|
103 | + $this->frequency = $frequency; |
|
104 | + $this->nb_occurrences = $nb_occurrences; |
|
105 | + $this->is_running = $is_running; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Get the schedule ID. |
|
110 | + * |
|
111 | + * @return int |
|
112 | + */ |
|
113 | + public function id(): int |
|
114 | + { |
|
115 | + return $this->id; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Get the task ID. |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function taskId(): string |
|
124 | + { |
|
125 | + return $this->task_id; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns whether the schedule is enabled |
|
130 | + * |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function isEnabled(): bool |
|
134 | + { |
|
135 | + return $this->enabled; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Enable the schedule |
|
140 | + * |
|
141 | + * @return self |
|
142 | + */ |
|
143 | + public function enable(): self |
|
144 | + { |
|
145 | + $this->enabled = true; |
|
146 | + return $this; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Disable the schedule |
|
151 | + * |
|
152 | + * @return self |
|
153 | + */ |
|
154 | + public function disable(): self |
|
155 | + { |
|
156 | + $this->enabled = false; |
|
157 | + return $this; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Get the frequency of the schedule |
|
162 | + * |
|
163 | + * @return CarbonInterval |
|
164 | + */ |
|
165 | + public function frequency(): CarbonInterval |
|
166 | + { |
|
167 | + return $this->frequency; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Set the frequency of the schedule |
|
172 | + * |
|
173 | + * @param CarbonInterval $frequency |
|
174 | + * @return self |
|
175 | + */ |
|
176 | + public function setFrequency(CarbonInterval $frequency): self |
|
177 | + { |
|
178 | + $this->frequency = $frequency; |
|
179 | + return $this; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Get the date/time of the last successful run. |
|
184 | + * |
|
185 | + * @return Carbon |
|
186 | + */ |
|
187 | + public function lastRunTime(): Carbon |
|
188 | + { |
|
189 | + return $this->last_run; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Set the last successful run date/time |
|
194 | + * |
|
195 | + * @param Carbon $last_run |
|
196 | + * @return self |
|
197 | + */ |
|
198 | + public function setLastRunTime(Carbon $last_run): self |
|
199 | + { |
|
200 | + $this->last_run = $last_run; |
|
201 | + return $this; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns whether the last run was successful |
|
206 | + * |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function wasLastRunSuccess(): bool |
|
210 | + { |
|
211 | + return $this->last_result; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Set the last run result |
|
216 | + * |
|
217 | + * @param bool $last_result |
|
218 | + * @return self |
|
219 | + */ |
|
220 | + public function setLastResult(bool $last_result): self |
|
221 | + { |
|
222 | + $this->last_result = $last_result; |
|
223 | + return $this; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Get the number of remaining of occurrences of task runs. |
|
228 | + * Returns 0 if the tasks must be run indefinitely. |
|
229 | + * |
|
230 | + * @return int |
|
231 | + */ |
|
232 | + public function remainingOccurences(): int |
|
233 | + { |
|
234 | + return $this->nb_occurrences; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Decrements the number of remaining occurences by 1. |
|
239 | + * The task will be disabled when the number reaches 0. |
|
240 | + * |
|
241 | + * @return self |
|
242 | + */ |
|
243 | + public function decrementRemainingOccurences(): self |
|
244 | + { |
|
245 | + if ($this->nb_occurrences > 0) { |
|
246 | + $this->nb_occurrences--; |
|
247 | + if ($this->nb_occurrences == 0) { |
|
248 | + $this->disable(); |
|
249 | + } |
|
250 | + } |
|
251 | + return $this; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Set the number of remaining occurences of task runs. |
|
256 | + * |
|
257 | + * @param int $nb_occurrences |
|
258 | + * @return self |
|
259 | + */ |
|
260 | + public function setRemainingOccurences(int $nb_occurrences): self |
|
261 | + { |
|
262 | + $this->nb_occurrences = $nb_occurrences; |
|
263 | + return $this; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Returns whether the task is running |
|
268 | + * @return bool |
|
269 | + */ |
|
270 | + public function isRunning(): bool |
|
271 | + { |
|
272 | + return $this->is_running; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Informs the schedule that the task is going to run |
|
277 | + * |
|
278 | + * @return self |
|
279 | + */ |
|
280 | + public function startRunning(): self |
|
281 | + { |
|
282 | + $this->is_running = true; |
|
283 | + return $this; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Informs the schedule that the task has stopped running. |
|
288 | + * @return self |
|
289 | + */ |
|
290 | + public function stopRunning(): self |
|
291 | + { |
|
292 | + $this->is_running = false; |
|
293 | + return $this; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the schedule details as an associate array |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function toArray(): array |
|
302 | + { |
|
303 | + return [ |
|
304 | + 'id' => $this->id, |
|
305 | + 'task_id' => $this->task_id, |
|
306 | + 'enabled' => $this->enabled, |
|
307 | + 'last_run' => $this->last_run, |
|
308 | + 'last_result' => $this->last_result, |
|
309 | + 'frequency' => $this->frequency, |
|
310 | + 'nb_occurrences' => $this->nb_occurrences, |
|
311 | + 'is_running' => $this->is_running |
|
312 | + ]; |
|
313 | + } |
|
314 | 314 | } |
@@ -25,25 +25,25 @@ |
||
25 | 25 | class Migration1 implements MigrationInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
31 | - */ |
|
32 | - public function upgrade(): void |
|
33 | - { |
|
34 | - // Clean up previous admin tasks table if it exists |
|
35 | - DB::schema()->dropIfExists('maj_admintasks'); |
|
36 | - |
|
37 | - DB::schema()->create('maj_admintasks', static function (Blueprint $table): void { |
|
38 | - |
|
39 | - $table->increments('majat_id'); |
|
40 | - $table->string('majat_task_id', 32)->unique(); |
|
41 | - $table->enum('majat_status', ['enabled', 'disabled'])->default('disabled'); |
|
42 | - $table->dateTime('majat_last_run')->default(Carbon::createFromTimestampUTC(0)); |
|
43 | - $table->boolean('majat_last_result')->default(true); |
|
44 | - $table->integer('majat_frequency')->default(10080); |
|
45 | - $table->smallInteger('majat_nb_occur')->default(0); |
|
46 | - $table->boolean('majat_running')->default(false); |
|
47 | - }); |
|
48 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
31 | + */ |
|
32 | + public function upgrade(): void |
|
33 | + { |
|
34 | + // Clean up previous admin tasks table if it exists |
|
35 | + DB::schema()->dropIfExists('maj_admintasks'); |
|
36 | + |
|
37 | + DB::schema()->create('maj_admintasks', static function (Blueprint $table): void { |
|
38 | + |
|
39 | + $table->increments('majat_id'); |
|
40 | + $table->string('majat_task_id', 32)->unique(); |
|
41 | + $table->enum('majat_status', ['enabled', 'disabled'])->default('disabled'); |
|
42 | + $table->dateTime('majat_last_run')->default(Carbon::createFromTimestampUTC(0)); |
|
43 | + $table->boolean('majat_last_result')->default(true); |
|
44 | + $table->integer('majat_frequency')->default(10080); |
|
45 | + $table->smallInteger('majat_nb_occur')->default(0); |
|
46 | + $table->boolean('majat_running')->default(false); |
|
47 | + }); |
|
48 | + } |
|
49 | 49 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | // Clean up previous admin tasks table if it exists |
35 | 35 | DB::schema()->dropIfExists('maj_admintasks'); |
36 | 36 | |
37 | - DB::schema()->create('maj_admintasks', static function (Blueprint $table): void { |
|
37 | + DB::schema()->create('maj_admintasks', static function(Blueprint $table): void { |
|
38 | 38 | |
39 | 39 | $table->increments('majat_id'); |
40 | 40 | $table->string('majat_task_id', 32)->unique(); |
@@ -27,101 +27,101 @@ |
||
27 | 27 | */ |
28 | 28 | class HealthCheckService |
29 | 29 | { |
30 | - /** |
|
31 | - * Returns a query collating all gedcom records, for use in other queries |
|
32 | - * |
|
33 | - * @param Tree $tree |
|
34 | - * @return Builder |
|
35 | - */ |
|
36 | - private function allGedcomRecords(Tree $tree): Builder |
|
37 | - { |
|
38 | - return DB::table('individuals') |
|
39 | - ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id()) |
|
40 | - ->unionAll(DB::table('families') |
|
41 | - ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id())) |
|
42 | - ->unionAll(DB::table('sources') |
|
43 | - ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id())) |
|
44 | - ->unionAll(DB::table('media') |
|
45 | - ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id())) |
|
46 | - ->unionAll(DB::table('other') |
|
47 | - ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id())); |
|
48 | - } |
|
30 | + /** |
|
31 | + * Returns a query collating all gedcom records, for use in other queries |
|
32 | + * |
|
33 | + * @param Tree $tree |
|
34 | + * @return Builder |
|
35 | + */ |
|
36 | + private function allGedcomRecords(Tree $tree): Builder |
|
37 | + { |
|
38 | + return DB::table('individuals') |
|
39 | + ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id()) |
|
40 | + ->unionAll(DB::table('families') |
|
41 | + ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id())) |
|
42 | + ->unionAll(DB::table('sources') |
|
43 | + ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id())) |
|
44 | + ->unionAll(DB::table('media') |
|
45 | + ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id())) |
|
46 | + ->unionAll(DB::table('other') |
|
47 | + ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id())); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the count of gedcom records by type in a Tree, as a keyed Collection. |
|
52 | - * |
|
53 | - * Collection output: |
|
54 | - * - Key : gedcom record type |
|
55 | - * - Value: count of records |
|
56 | - * |
|
57 | - * @param Tree $tree |
|
58 | - * @return Collection |
|
59 | - */ |
|
60 | - public function countByRecordType(Tree $tree): Collection |
|
61 | - { |
|
62 | - return DB::query() |
|
63 | - ->fromSub($this->allGedcomRecords($tree), 'gedrecords') |
|
64 | - ->select('ged_type', new Expression('COUNT(ged_id) AS total')) |
|
65 | - ->groupBy('ged_type') |
|
66 | - ->pluck('total', 'ged_type'); |
|
67 | - } |
|
50 | + /** |
|
51 | + * Returns the count of gedcom records by type in a Tree, as a keyed Collection. |
|
52 | + * |
|
53 | + * Collection output: |
|
54 | + * - Key : gedcom record type |
|
55 | + * - Value: count of records |
|
56 | + * |
|
57 | + * @param Tree $tree |
|
58 | + * @return Collection |
|
59 | + */ |
|
60 | + public function countByRecordType(Tree $tree): Collection |
|
61 | + { |
|
62 | + return DB::query() |
|
63 | + ->fromSub($this->allGedcomRecords($tree), 'gedrecords') |
|
64 | + ->select('ged_type', new Expression('COUNT(ged_id) AS total')) |
|
65 | + ->groupBy('ged_type') |
|
66 | + ->pluck('total', 'ged_type'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection. |
|
71 | - * |
|
72 | - * Collection output: |
|
73 | - * - Key : gedcom record type |
|
74 | - * - Value: count of changes |
|
75 | - * |
|
76 | - * @param Tree $tree |
|
77 | - * @return Collection |
|
78 | - */ |
|
79 | - public function changesByRecordType(Tree $tree, int $nb_days): Collection |
|
80 | - { |
|
81 | - return DB::table('change') |
|
82 | - ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void { |
|
69 | + /** |
|
70 | + * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection. |
|
71 | + * |
|
72 | + * Collection output: |
|
73 | + * - Key : gedcom record type |
|
74 | + * - Value: count of changes |
|
75 | + * |
|
76 | + * @param Tree $tree |
|
77 | + * @return Collection |
|
78 | + */ |
|
79 | + public function changesByRecordType(Tree $tree, int $nb_days): Collection |
|
80 | + { |
|
81 | + return DB::table('change') |
|
82 | + ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void { |
|
83 | 83 | |
84 | - $join->on('change.xref', '=', 'gedrecords.ged_id') |
|
85 | - ->where('change.gedcom_id', '=', $tree->id()); |
|
86 | - }) |
|
87 | - ->select('ged_type AS type', new Expression('COUNT(change_id) AS count')) |
|
88 | - ->where('change.status', '', 'accepted') |
|
89 | - ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days)) |
|
90 | - ->groupBy('ged_type') |
|
91 | - ->pluck('total', 'ged_type'); |
|
92 | - } |
|
84 | + $join->on('change.xref', '=', 'gedrecords.ged_id') |
|
85 | + ->where('change.gedcom_id', '=', $tree->id()); |
|
86 | + }) |
|
87 | + ->select('ged_type AS type', new Expression('COUNT(change_id) AS count')) |
|
88 | + ->where('change.status', '', 'accepted') |
|
89 | + ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days)) |
|
90 | + ->groupBy('ged_type') |
|
91 | + ->pluck('total', 'ged_type'); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection. |
|
96 | - * |
|
97 | - * Collection output: |
|
98 | - * - Value: stdClass object |
|
99 | - * - log message: Error log message |
|
100 | - * - type: 'site' if no associated Tree, the Tree ID otherwise |
|
101 | - * - nblogs: The number of occurence of the same error message |
|
102 | - * - lastoccurred: Date/time of the last occurence of the error message |
|
103 | - * |
|
104 | - * @param Tree $tree |
|
105 | - * @param int $nb_days |
|
106 | - * @return Collection |
|
107 | - */ |
|
108 | - public function errorLogs(Tree $tree, int $nb_days): Collection |
|
109 | - { |
|
110 | - return DB::table('log') |
|
111 | - ->select( |
|
112 | - 'log_message', |
|
113 | - new Expression("IFNULL(gedcom_id, 'site') as type"), |
|
114 | - new Expression('COUNT(log_id) AS nblogs'), |
|
115 | - new Expression('MAX(log_time) AS lastoccurred') |
|
116 | - ) |
|
117 | - ->where('log_type', '=', 'error') |
|
118 | - ->where(function (Builder $query) use ($tree): void { |
|
119 | - $query->where('gedcom_id', '=', $tree->id()) |
|
120 | - ->orWhereNull('gedcom_id'); |
|
121 | - }) |
|
122 | - ->where('log_time', '>=', Carbon::now()->subDays($nb_days)) |
|
123 | - ->groupBy('log_message', 'gedcom_id') |
|
124 | - ->orderByDesc('lastoccurred') |
|
125 | - ->get(); |
|
126 | - } |
|
94 | + /** |
|
95 | + * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection. |
|
96 | + * |
|
97 | + * Collection output: |
|
98 | + * - Value: stdClass object |
|
99 | + * - log message: Error log message |
|
100 | + * - type: 'site' if no associated Tree, the Tree ID otherwise |
|
101 | + * - nblogs: The number of occurence of the same error message |
|
102 | + * - lastoccurred: Date/time of the last occurence of the error message |
|
103 | + * |
|
104 | + * @param Tree $tree |
|
105 | + * @param int $nb_days |
|
106 | + * @return Collection |
|
107 | + */ |
|
108 | + public function errorLogs(Tree $tree, int $nb_days): Collection |
|
109 | + { |
|
110 | + return DB::table('log') |
|
111 | + ->select( |
|
112 | + 'log_message', |
|
113 | + new Expression("IFNULL(gedcom_id, 'site') as type"), |
|
114 | + new Expression('COUNT(log_id) AS nblogs'), |
|
115 | + new Expression('MAX(log_time) AS lastoccurred') |
|
116 | + ) |
|
117 | + ->where('log_type', '=', 'error') |
|
118 | + ->where(function (Builder $query) use ($tree): void { |
|
119 | + $query->where('gedcom_id', '=', $tree->id()) |
|
120 | + ->orWhereNull('gedcom_id'); |
|
121 | + }) |
|
122 | + ->where('log_time', '>=', Carbon::now()->subDays($nb_days)) |
|
123 | + ->groupBy('log_message', 'gedcom_id') |
|
124 | + ->orderByDesc('lastoccurred') |
|
125 | + ->get(); |
|
126 | + } |
|
127 | 127 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function changesByRecordType(Tree $tree, int $nb_days): Collection |
80 | 80 | { |
81 | 81 | return DB::table('change') |
82 | - ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void { |
|
82 | + ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function(JoinClause $join) use ($tree): void { |
|
83 | 83 | |
84 | 84 | $join->on('change.xref', '=', 'gedrecords.ged_id') |
85 | 85 | ->where('change.gedcom_id', '=', $tree->id()); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | new Expression('MAX(log_time) AS lastoccurred') |
116 | 116 | ) |
117 | 117 | ->where('log_type', '=', 'error') |
118 | - ->where(function (Builder $query) use ($tree): void { |
|
118 | + ->where(function(Builder $query) use ($tree): void { |
|
119 | 119 | $query->where('gedcom_id', '=', $tree->id()) |
120 | 120 | ->orWhereNull('gedcom_id'); |
121 | 121 | }) |
@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration1 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // These migrations have been merged into migration 2. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // These migrations have been merged into migration 2. |
|
32 | + } |
|
33 | 33 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $tree = $request->getAttribute('tree'); |
61 | 61 | assert($tree instanceof Tree); |
62 | 62 | |
63 | - return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | + return response(view($this->module->name().'::modals/sosa-compute', [ |
|
64 | 64 | 'tree' => $tree, |
65 | 65 | 'xref' => $request->getAttribute('xref') |
66 | 66 | ])); |
@@ -28,40 +28,40 @@ |
||
28 | 28 | */ |
29 | 29 | class SosaComputeModal implements RequestHandlerInterface |
30 | 30 | { |
31 | - /** |
|
32 | - * @var SosaModule|null $module |
|
33 | - */ |
|
34 | - private $module; |
|
31 | + /** |
|
32 | + * @var SosaModule|null $module |
|
33 | + */ |
|
34 | + private $module; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for SosaComputeModal Request Handler |
|
38 | - * |
|
39 | - * @param ModuleService $module_service |
|
40 | - */ |
|
41 | - public function __construct(ModuleService $module_service) |
|
42 | - { |
|
43 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for SosaComputeModal Request Handler |
|
38 | + * |
|
39 | + * @param ModuleService $module_service |
|
40 | + */ |
|
41 | + public function __construct(ModuleService $module_service) |
|
42 | + { |
|
43 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | - */ |
|
50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | - { |
|
52 | - if ($this->module === null) { |
|
53 | - return response(view('modals/error', [ |
|
54 | - 'title' => I18N::translate('Error'), |
|
55 | - 'error' => I18N::translate('The attached module could not be found.') |
|
56 | - ])); |
|
57 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | + */ |
|
50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | + { |
|
52 | + if ($this->module === null) { |
|
53 | + return response(view('modals/error', [ |
|
54 | + 'title' => I18N::translate('Error'), |
|
55 | + 'error' => I18N::translate('The attached module could not be found.') |
|
56 | + ])); |
|
57 | + } |
|
58 | 58 | |
59 | - $tree = $request->getAttribute('tree'); |
|
60 | - assert($tree instanceof Tree); |
|
59 | + $tree = $request->getAttribute('tree'); |
|
60 | + assert($tree instanceof Tree); |
|
61 | 61 | |
62 | - return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | - 'tree' => $tree, |
|
64 | - 'xref' => $request->getAttribute('xref') |
|
65 | - ])); |
|
66 | - } |
|
62 | + return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | + 'tree' => $tree, |
|
64 | + 'xref' => $request->getAttribute('xref') |
|
65 | + ])); |
|
66 | + } |
|
67 | 67 | } |
@@ -31,61 +31,61 @@ |
||
31 | 31 | */ |
32 | 32 | class SosaComputeAction implements RequestHandlerInterface |
33 | 33 | { |
34 | - /** |
|
35 | - * @var UserService $user_service |
|
36 | - */ |
|
37 | - private $user_service; |
|
34 | + /** |
|
35 | + * @var UserService $user_service |
|
36 | + */ |
|
37 | + private $user_service; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor for SosaConfigAction Request Handler |
|
41 | - * |
|
42 | - * @param UserService $user_service |
|
43 | - */ |
|
44 | - public function __construct(UserService $user_service) |
|
45 | - { |
|
46 | - $this->user_service = $user_service; |
|
47 | - } |
|
39 | + /** |
|
40 | + * Constructor for SosaConfigAction Request Handler |
|
41 | + * |
|
42 | + * @param UserService $user_service |
|
43 | + */ |
|
44 | + public function __construct(UserService $user_service) |
|
45 | + { |
|
46 | + $this->user_service = $user_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 = $request->getAttribute('tree'); |
|
56 | - assert($tree instanceof Tree); |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | + */ |
|
53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | + { |
|
55 | + $tree = $request->getAttribute('tree'); |
|
56 | + assert($tree instanceof Tree); |
|
57 | 57 | |
58 | - $params = $request->getParsedBody(); |
|
59 | - assert(is_array($params)); |
|
58 | + $params = $request->getParsedBody(); |
|
59 | + assert(is_array($params)); |
|
60 | 60 | |
61 | - $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0); |
|
62 | - $partial_from = $params['partial_from'] ?? null; |
|
61 | + $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0); |
|
62 | + $partial_from = $params['partial_from'] ?? null; |
|
63 | 63 | |
64 | - if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
|
65 | - $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
64 | + if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
|
65 | + $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66 | 66 | |
67 | - /** @var SosaCalculatorService $sosa_calc_service */ |
|
68 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
67 | + /** @var SosaCalculatorService $sosa_calc_service */ |
|
68 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
69 | 69 | |
70 | - if ( |
|
71 | - $partial_from !== null && |
|
72 | - ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
73 | - ) { |
|
74 | - $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
75 | - } else { |
|
76 | - $res = $sosa_calc_service->computeAll(); |
|
77 | - } |
|
70 | + if ( |
|
71 | + $partial_from !== null && |
|
72 | + ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
73 | + ) { |
|
74 | + $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
75 | + } else { |
|
76 | + $res = $sosa_calc_service->computeAll(); |
|
77 | + } |
|
78 | 78 | |
79 | - return $res ? |
|
80 | - response('', 200) : |
|
81 | - response( |
|
82 | - I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
83 | - StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
84 | - ); |
|
85 | - } |
|
86 | - return response( |
|
87 | - I18N::translate('You do not have permission to modify the user.'), |
|
88 | - StatusCodeInterface::STATUS_FORBIDDEN |
|
89 | - ); |
|
90 | - } |
|
79 | + return $res ? |
|
80 | + response('', 200) : |
|
81 | + response( |
|
82 | + I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
83 | + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
84 | + ); |
|
85 | + } |
|
86 | + return response( |
|
87 | + I18N::translate('You do not have permission to modify the user.'), |
|
88 | + StatusCodeInterface::STATUS_FORBIDDEN |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | $params = $request->getParsedBody(); |
59 | 59 | assert(is_array($params)); |
60 | 60 | |
61 | - $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0); |
|
61 | + $user_id = (int)($params['user_id'] ?? Auth::id() ?? 0); |
|
62 | 62 | $partial_from = $params['partial_from'] ?? null; |
63 | 63 | |
64 | 64 | if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
65 | 65 | $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
66 | 66 | |
67 | 67 | /** @var SosaCalculatorService $sosa_calc_service */ |
68 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
68 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, ['tree' => $tree, 'user' => $user]); |
|
69 | 69 | |
70 | 70 | if ( |
71 | 71 | $partial_from !== null && |
@@ -77,8 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | return $res ? |
80 | - response('', 200) : |
|
81 | - response( |
|
80 | + response('', 200) : response( |
|
82 | 81 | I18N::translate('An error occurred while computing Sosa ancestors.'), |
83 | 82 | StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
84 | 83 | ); |
@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration0 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // These migrations have been merged into migration 2. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // These migrations have been merged into migration 2. |
|
32 | + } |
|
33 | 33 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | class Migration2 implements MigrationInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritDoc} |
|
29 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | - */ |
|
31 | - public function upgrade(): void |
|
32 | - { |
|
33 | - |
|
34 | - // Clean up previous sosa table if it exists |
|
35 | - DB::schema()->dropIfExists('maj_sosa'); |
|
36 | - |
|
37 | - DB::schema()->create('maj_sosa', static function (Blueprint $table): void { |
|
38 | - |
|
39 | - $table->integer('majs_gedcom_id'); |
|
40 | - $table->integer('majs_user_id')->default(-1); |
|
41 | - $table->bigInteger('majs_sosa')->unsigned(); // Allow to calculate sosa on 64 generations |
|
42 | - $table->string('majs_i_id', 20); |
|
43 | - $table->tinyInteger('majs_gen')->nullable(); |
|
44 | - $table->smallInteger('majs_birth_year')->nullable(); |
|
45 | - $table->smallInteger('majs_birth_year_est')->nullable(); |
|
46 | - $table->smallInteger('majs_death_year')->nullable(); |
|
47 | - $table->smallInteger('majs_death_year_est')->nullable(); |
|
48 | - |
|
49 | - $table->primary(['majs_gedcom_id', 'majs_user_id', 'majs_sosa']); |
|
50 | - |
|
51 | - $table->index(['majs_gedcom_id', 'majs_user_id']); |
|
52 | - $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_i_id']); |
|
53 | - $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_gen']); |
|
54 | - |
|
55 | - $table->foreign('majs_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
56 | - $table->foreign('majs_user_id')->references('user_id')->on('user')->onDelete('cascade'); |
|
57 | - }); |
|
58 | - } |
|
27 | + /** |
|
28 | + * {@inheritDoc} |
|
29 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | + */ |
|
31 | + public function upgrade(): void |
|
32 | + { |
|
33 | + |
|
34 | + // Clean up previous sosa table if it exists |
|
35 | + DB::schema()->dropIfExists('maj_sosa'); |
|
36 | + |
|
37 | + DB::schema()->create('maj_sosa', static function (Blueprint $table): void { |
|
38 | + |
|
39 | + $table->integer('majs_gedcom_id'); |
|
40 | + $table->integer('majs_user_id')->default(-1); |
|
41 | + $table->bigInteger('majs_sosa')->unsigned(); // Allow to calculate sosa on 64 generations |
|
42 | + $table->string('majs_i_id', 20); |
|
43 | + $table->tinyInteger('majs_gen')->nullable(); |
|
44 | + $table->smallInteger('majs_birth_year')->nullable(); |
|
45 | + $table->smallInteger('majs_birth_year_est')->nullable(); |
|
46 | + $table->smallInteger('majs_death_year')->nullable(); |
|
47 | + $table->smallInteger('majs_death_year_est')->nullable(); |
|
48 | + |
|
49 | + $table->primary(['majs_gedcom_id', 'majs_user_id', 'majs_sosa']); |
|
50 | + |
|
51 | + $table->index(['majs_gedcom_id', 'majs_user_id']); |
|
52 | + $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_i_id']); |
|
53 | + $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_gen']); |
|
54 | + |
|
55 | + $table->foreign('majs_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
56 | + $table->foreign('majs_user_id')->references('user_id')->on('user')->onDelete('cascade'); |
|
57 | + }); |
|
58 | + } |
|
59 | 59 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | // Clean up previous sosa table if it exists |
35 | 35 | DB::schema()->dropIfExists('maj_sosa'); |
36 | 36 | |
37 | - DB::schema()->create('maj_sosa', static function (Blueprint $table): void { |
|
37 | + DB::schema()->create('maj_sosa', static function(Blueprint $table): void { |
|
38 | 38 | |
39 | 39 | $table->integer('majs_gedcom_id'); |
40 | 40 | $table->integer('majs_user_id')->default(-1); |