@@ -27,52 +27,52 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class SosaIconHook implements RecordNameTextExtenderInterface |
| 29 | 29 | { |
| 30 | - private ModuleInterface $module; |
|
| 31 | - private SosaRecordsService $sosa_records_service; |
|
| 30 | + private ModuleInterface $module; |
|
| 31 | + private SosaRecordsService $sosa_records_service; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor for SosaIconHook |
|
| 35 | - * |
|
| 36 | - * @param ModuleInterface $module |
|
| 37 | - * @param SosaRecordsService $sosa_records_service |
|
| 38 | - */ |
|
| 39 | - public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service) |
|
| 40 | - { |
|
| 41 | - $this->module = $module; |
|
| 42 | - $this->sosa_records_service = $sosa_records_service; |
|
| 43 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor for SosaIconHook |
|
| 35 | + * |
|
| 36 | + * @param ModuleInterface $module |
|
| 37 | + * @param SosaRecordsService $sosa_records_service |
|
| 38 | + */ |
|
| 39 | + public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service) |
|
| 40 | + { |
|
| 41 | + $this->module = $module; |
|
| 42 | + $this->sosa_records_service = $sosa_records_service; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * {@inheritDoc} |
|
| 47 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 48 | - */ |
|
| 49 | - public function module(): ModuleInterface |
|
| 50 | - { |
|
| 51 | - return $this->module; |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * {@inheritDoc} |
|
| 47 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 48 | + */ |
|
| 49 | + public function module(): ModuleInterface |
|
| 50 | + { |
|
| 51 | + return $this->module; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * {@inheritDoc} |
|
| 56 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 57 | - */ |
|
| 58 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 59 | - { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 54 | + /** |
|
| 55 | + * {@inheritDoc} |
|
| 56 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 57 | + */ |
|
| 58 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 59 | + { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * {@inheritDoc} |
|
| 65 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 66 | - */ |
|
| 67 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 68 | - { |
|
| 69 | - $current_user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 70 | - if ( |
|
| 71 | - $record instanceof Individual && |
|
| 72 | - $this->sosa_records_service->isSosa($record->tree(), $current_user, $record) |
|
| 73 | - ) { |
|
| 74 | - return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
| 75 | - } |
|
| 76 | - return ''; |
|
| 77 | - } |
|
| 63 | + /** |
|
| 64 | + * {@inheritDoc} |
|
| 65 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 66 | + */ |
|
| 67 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 68 | + { |
|
| 69 | + $current_user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 70 | + if ( |
|
| 71 | + $record instanceof Individual && |
|
| 72 | + $this->sosa_records_service->isSosa($record->tree(), $current_user, $record) |
|
| 73 | + ) { |
|
| 74 | + return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
| 75 | + } |
|
| 76 | + return ''; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -41,165 +41,165 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class HealthCheckEmailTask implements TaskInterface, ConfigurableTaskInterface |
| 43 | 43 | { |
| 44 | - /** |
|
| 45 | - * Name of the Tree preference to check if the task is enabled for that tree |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
| 49 | - |
|
| 50 | - private ?AdminTasksModule $module; |
|
| 51 | - private HealthCheckService $healthcheck_service; |
|
| 52 | - private EmailService $email_service; |
|
| 53 | - private UserService $user_service; |
|
| 54 | - private TreeService $tree_service; |
|
| 55 | - private UpgradeService $upgrade_service; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Constructor for HealthCheckTask |
|
| 59 | - * |
|
| 60 | - * @param ModuleService $module_service |
|
| 61 | - * @param HealthCheckService $healthcheck_service |
|
| 62 | - * @param EmailService $email_service |
|
| 63 | - * @param UserService $user_service |
|
| 64 | - * @param TreeService $tree_service |
|
| 65 | - * @param UpgradeService $upgrade_service |
|
| 66 | - */ |
|
| 67 | - public function __construct( |
|
| 68 | - ModuleService $module_service, |
|
| 69 | - HealthCheckService $healthcheck_service, |
|
| 70 | - EmailService $email_service, |
|
| 71 | - UserService $user_service, |
|
| 72 | - TreeService $tree_service, |
|
| 73 | - UpgradeService $upgrade_service |
|
| 74 | - ) { |
|
| 75 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 76 | - $this->healthcheck_service = $healthcheck_service; |
|
| 77 | - $this->email_service = $email_service; |
|
| 78 | - $this->user_service = $user_service; |
|
| 79 | - $this->tree_service = $tree_service; |
|
| 80 | - $this->upgrade_service = $upgrade_service; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * {@inheritDoc} |
|
| 86 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::name() |
|
| 87 | - */ |
|
| 88 | - public function name(): string |
|
| 89 | - { |
|
| 90 | - return I18N::translate('Healthcheck Email'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * {@inheritDoc} |
|
| 95 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::defaultFrequency() |
|
| 96 | - */ |
|
| 97 | - public function defaultFrequency(): int |
|
| 98 | - { |
|
| 99 | - return 10080; // = 1 week = 7 * 24 * 60 min |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * {@inheritDoc} |
|
| 104 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::run() |
|
| 105 | - */ |
|
| 106 | - public function run(TaskSchedule $task_schedule): bool |
|
| 107 | - { |
|
| 108 | - if ($this->module === null) { |
|
| 109 | - return false; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $res = true; |
|
| 113 | - |
|
| 114 | - // Compute the number of days to compute |
|
| 115 | - $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(CarbonImmutable::now()); |
|
| 116 | - $interval_frequency = CarbonInterval::minutes($task_schedule->frequency()); |
|
| 117 | - $interval = $interval_lastrun->greaterThan($interval_frequency) ? $interval_lastrun : $interval_frequency; |
|
| 118 | - $nb_days = (int) $interval->ceilDay()->totalDays; |
|
| 119 | - |
|
| 120 | - $view_params_site = [ |
|
| 121 | - 'nb_days' => $nb_days, |
|
| 122 | - 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
| 123 | - 'latest_version' => $this->upgrade_service->latestVersion(), |
|
| 124 | - 'download_url' => $this->upgrade_service->downloadUrl(), |
|
| 125 | - 'all_users' => $this->user_service->all(), |
|
| 126 | - 'unapproved' => $this->user_service->unapproved(), |
|
| 127 | - 'unverified' => $this->user_service->unverified(), |
|
| 128 | - ]; |
|
| 129 | - |
|
| 130 | - foreach ($this->tree_service->all() as $tree) { |
|
| 131 | - /** @var Tree $tree */ |
|
| 132 | - |
|
| 133 | - if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
| 134 | - continue; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
| 138 | - if ($webmaster === null) { |
|
| 139 | - continue; |
|
| 140 | - } |
|
| 141 | - I18N::init($webmaster->getPreference('language')); |
|
| 142 | - |
|
| 143 | - $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
| 144 | - $nb_errors = $error_logs->sum('nblogs'); |
|
| 145 | - |
|
| 146 | - $view_params = $view_params_site + [ |
|
| 147 | - 'tree' => $tree, |
|
| 148 | - 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
| 149 | - 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
| 150 | - 'error_logs' => $error_logs, |
|
| 151 | - 'nb_errors' => $nb_errors |
|
| 152 | - ]; |
|
| 153 | - |
|
| 154 | - $res = $res && $this->email_service->send( |
|
| 155 | - new TreeUser($tree), |
|
| 156 | - $webmaster, |
|
| 157 | - new NoReplyUser(), |
|
| 158 | - I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
| 159 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
| 160 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $res; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * {@inheritDoc} |
|
| 169 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::configView() |
|
| 170 | - */ |
|
| 171 | - public function configView(ServerRequestInterface $request): string |
|
| 172 | - { |
|
| 173 | - return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
| 174 | - 'all_trees' => $this->tree_service->all() |
|
| 175 | - ]); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * {@inheritDoc} |
|
| 180 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::updateConfig() |
|
| 181 | - */ |
|
| 182 | - public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
| 183 | - { |
|
| 184 | - try { |
|
| 185 | - $validator = Validator::parsedBody($request); |
|
| 186 | - |
|
| 187 | - foreach ($this->tree_service->all() as $tree) { |
|
| 188 | - if (Auth::isManager($tree)) { |
|
| 189 | - $tree_enabled = $validator->boolean('HEALTHCHECK_ENABLED_' . $tree->id(), false); |
|
| 190 | - $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - return true; |
|
| 194 | - } catch (Throwable $ex) { |
|
| 195 | - Log::addErrorLog( |
|
| 196 | - sprintf( |
|
| 197 | - 'Error while updating the Task schedule "%s". Exception: %s', |
|
| 198 | - $task_schedule->id(), |
|
| 199 | - $ex->getMessage() |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 44 | + /** |
|
| 45 | + * Name of the Tree preference to check if the task is enabled for that tree |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
| 49 | + |
|
| 50 | + private ?AdminTasksModule $module; |
|
| 51 | + private HealthCheckService $healthcheck_service; |
|
| 52 | + private EmailService $email_service; |
|
| 53 | + private UserService $user_service; |
|
| 54 | + private TreeService $tree_service; |
|
| 55 | + private UpgradeService $upgrade_service; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Constructor for HealthCheckTask |
|
| 59 | + * |
|
| 60 | + * @param ModuleService $module_service |
|
| 61 | + * @param HealthCheckService $healthcheck_service |
|
| 62 | + * @param EmailService $email_service |
|
| 63 | + * @param UserService $user_service |
|
| 64 | + * @param TreeService $tree_service |
|
| 65 | + * @param UpgradeService $upgrade_service |
|
| 66 | + */ |
|
| 67 | + public function __construct( |
|
| 68 | + ModuleService $module_service, |
|
| 69 | + HealthCheckService $healthcheck_service, |
|
| 70 | + EmailService $email_service, |
|
| 71 | + UserService $user_service, |
|
| 72 | + TreeService $tree_service, |
|
| 73 | + UpgradeService $upgrade_service |
|
| 74 | + ) { |
|
| 75 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 76 | + $this->healthcheck_service = $healthcheck_service; |
|
| 77 | + $this->email_service = $email_service; |
|
| 78 | + $this->user_service = $user_service; |
|
| 79 | + $this->tree_service = $tree_service; |
|
| 80 | + $this->upgrade_service = $upgrade_service; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * {@inheritDoc} |
|
| 86 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::name() |
|
| 87 | + */ |
|
| 88 | + public function name(): string |
|
| 89 | + { |
|
| 90 | + return I18N::translate('Healthcheck Email'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * {@inheritDoc} |
|
| 95 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::defaultFrequency() |
|
| 96 | + */ |
|
| 97 | + public function defaultFrequency(): int |
|
| 98 | + { |
|
| 99 | + return 10080; // = 1 week = 7 * 24 * 60 min |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * {@inheritDoc} |
|
| 104 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::run() |
|
| 105 | + */ |
|
| 106 | + public function run(TaskSchedule $task_schedule): bool |
|
| 107 | + { |
|
| 108 | + if ($this->module === null) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $res = true; |
|
| 113 | + |
|
| 114 | + // Compute the number of days to compute |
|
| 115 | + $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(CarbonImmutable::now()); |
|
| 116 | + $interval_frequency = CarbonInterval::minutes($task_schedule->frequency()); |
|
| 117 | + $interval = $interval_lastrun->greaterThan($interval_frequency) ? $interval_lastrun : $interval_frequency; |
|
| 118 | + $nb_days = (int) $interval->ceilDay()->totalDays; |
|
| 119 | + |
|
| 120 | + $view_params_site = [ |
|
| 121 | + 'nb_days' => $nb_days, |
|
| 122 | + 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
| 123 | + 'latest_version' => $this->upgrade_service->latestVersion(), |
|
| 124 | + 'download_url' => $this->upgrade_service->downloadUrl(), |
|
| 125 | + 'all_users' => $this->user_service->all(), |
|
| 126 | + 'unapproved' => $this->user_service->unapproved(), |
|
| 127 | + 'unverified' => $this->user_service->unverified(), |
|
| 128 | + ]; |
|
| 129 | + |
|
| 130 | + foreach ($this->tree_service->all() as $tree) { |
|
| 131 | + /** @var Tree $tree */ |
|
| 132 | + |
|
| 133 | + if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
| 134 | + continue; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
| 138 | + if ($webmaster === null) { |
|
| 139 | + continue; |
|
| 140 | + } |
|
| 141 | + I18N::init($webmaster->getPreference('language')); |
|
| 142 | + |
|
| 143 | + $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
| 144 | + $nb_errors = $error_logs->sum('nblogs'); |
|
| 145 | + |
|
| 146 | + $view_params = $view_params_site + [ |
|
| 147 | + 'tree' => $tree, |
|
| 148 | + 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
| 149 | + 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
| 150 | + 'error_logs' => $error_logs, |
|
| 151 | + 'nb_errors' => $nb_errors |
|
| 152 | + ]; |
|
| 153 | + |
|
| 154 | + $res = $res && $this->email_service->send( |
|
| 155 | + new TreeUser($tree), |
|
| 156 | + $webmaster, |
|
| 157 | + new NoReplyUser(), |
|
| 158 | + I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
| 159 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
| 160 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $res; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * {@inheritDoc} |
|
| 169 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::configView() |
|
| 170 | + */ |
|
| 171 | + public function configView(ServerRequestInterface $request): string |
|
| 172 | + { |
|
| 173 | + return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
| 174 | + 'all_trees' => $this->tree_service->all() |
|
| 175 | + ]); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * {@inheritDoc} |
|
| 180 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::updateConfig() |
|
| 181 | + */ |
|
| 182 | + public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
| 183 | + { |
|
| 184 | + try { |
|
| 185 | + $validator = Validator::parsedBody($request); |
|
| 186 | + |
|
| 187 | + foreach ($this->tree_service->all() as $tree) { |
|
| 188 | + if (Auth::isManager($tree)) { |
|
| 189 | + $tree_enabled = $validator->boolean('HEALTHCHECK_ENABLED_' . $tree->id(), false); |
|
| 190 | + $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + return true; |
|
| 194 | + } catch (Throwable $ex) { |
|
| 195 | + Log::addErrorLog( |
|
| 196 | + sprintf( |
|
| 197 | + 'Error while updating the Task schedule "%s". Exception: %s', |
|
| 198 | + $task_schedule->id(), |
|
| 199 | + $ex->getMessage() |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | 205 | } |
@@ -32,92 +32,92 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class TasksList implements RequestHandlerInterface |
| 34 | 34 | { |
| 35 | - private ?AdminTasksModule $module; |
|
| 36 | - private TaskScheduleService $taskschedules_service; |
|
| 35 | + private ?AdminTasksModule $module; |
|
| 36 | + private TaskScheduleService $taskschedules_service; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor for TasksList Request Handler |
|
| 40 | - * |
|
| 41 | - * @param ModuleService $module_service |
|
| 42 | - * @param TaskScheduleService $taskschedules_service |
|
| 43 | - */ |
|
| 44 | - public function __construct( |
|
| 45 | - ModuleService $module_service, |
|
| 46 | - TaskScheduleService $taskschedules_service |
|
| 47 | - ) { |
|
| 48 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 49 | - $this->taskschedules_service = $taskschedules_service; |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor for TasksList Request Handler |
|
| 40 | + * |
|
| 41 | + * @param ModuleService $module_service |
|
| 42 | + * @param TaskScheduleService $taskschedules_service |
|
| 43 | + */ |
|
| 44 | + public function __construct( |
|
| 45 | + ModuleService $module_service, |
|
| 46 | + TaskScheduleService $taskschedules_service |
|
| 47 | + ) { |
|
| 48 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 49 | + $this->taskschedules_service = $taskschedules_service; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 55 | - */ |
|
| 56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 57 | - { |
|
| 58 | - if ($this->module === null) { |
|
| 59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 55 | + */ |
|
| 56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 57 | + { |
|
| 58 | + if ($this->module === null) { |
|
| 59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $module = $this->module; |
|
| 63 | - $module_name = $this->module->name(); |
|
| 64 | - return Registry::responseFactory()->response(['data' => $this->taskschedules_service->all(true, true) |
|
| 65 | - ->map(function (TaskSchedule $schedule) use ($module, $module_name): array { |
|
| 66 | - $task = $this->taskschedules_service->findTask($schedule->taskId()); |
|
| 67 | - $task_name = $task !== null ? $task->name() : I18N::translate('Task not found'); |
|
| 68 | - $last_run_timestamp = Registry::timestampFactory()->make($schedule->lastRunTime()->getTimestamp()); |
|
| 62 | + $module = $this->module; |
|
| 63 | + $module_name = $this->module->name(); |
|
| 64 | + return Registry::responseFactory()->response(['data' => $this->taskschedules_service->all(true, true) |
|
| 65 | + ->map(function (TaskSchedule $schedule) use ($module, $module_name): array { |
|
| 66 | + $task = $this->taskschedules_service->findTask($schedule->taskId()); |
|
| 67 | + $task_name = $task !== null ? $task->name() : I18N::translate('Task not found'); |
|
| 68 | + $last_run_timestamp = Registry::timestampFactory()->make($schedule->lastRunTime()->getTimestamp()); |
|
| 69 | 69 | |
| 70 | - return [ |
|
| 71 | - 'edit' => view($module_name . '::admin/tasks-table-options', [ |
|
| 72 | - 'task_sched_id' => $schedule->id(), |
|
| 73 | - 'task_sched_enabled' => $schedule->isEnabled(), |
|
| 74 | - 'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]), |
|
| 75 | - 'task_status_route' => route(TaskStatusAction::class, [ |
|
| 76 | - 'task' => $schedule->id(), |
|
| 77 | - 'enable' => $schedule->isEnabled() ? 0 : 1 |
|
| 78 | - ]) |
|
| 79 | - ]), |
|
| 80 | - 'status' => [ |
|
| 81 | - 'display' => view($module_name . '::components/yes-no-icons', [ |
|
| 82 | - 'yes' => $schedule->isEnabled() |
|
| 83 | - ]), |
|
| 84 | - 'raw' => $schedule->isEnabled() ? 1 : 0 |
|
| 85 | - ], |
|
| 86 | - 'task_name' => [ |
|
| 87 | - 'display' => '<bdi>' . e($task_name) . '</bdi>', |
|
| 88 | - 'raw' => $task_name |
|
| 89 | - ], |
|
| 90 | - 'last_run' => [ |
|
| 91 | - 'display' => $last_run_timestamp->timestamp() === 0 ? |
|
| 92 | - view('components/datetime', ['timestamp' => $last_run_timestamp]) : |
|
| 93 | - view('components/datetime-diff', ['timestamp' => $last_run_timestamp]), |
|
| 94 | - 'raw' => $schedule->lastRunTime()->getTimestamp() |
|
| 95 | - ], |
|
| 96 | - 'last_result' => [ |
|
| 97 | - 'display' => view($module_name . '::components/yes-no-icons', [ |
|
| 98 | - 'yes' => $schedule->wasLastRunSuccess() |
|
| 99 | - ]), |
|
| 100 | - 'raw' => $schedule->wasLastRunSuccess() ? 1 : 0 |
|
| 101 | - ], |
|
| 102 | - 'frequency' => |
|
| 103 | - '<bdi>' . e(CarbonInterval::minutes($schedule->frequency())->cascade()->forHumans()) . '</bdi>', |
|
| 104 | - 'nb_occurrences' => $schedule->remainingOccurrences() > 0 ? |
|
| 105 | - I18N::number($schedule->remainingOccurrences()) : |
|
| 106 | - I18N::translate('Unlimited'), |
|
| 107 | - 'running' => view($module_name . '::components/yes-no-icons', [ |
|
| 108 | - 'yes' => $schedule->isRunning(), |
|
| 109 | - 'text_yes' => I18N::translate('Running'), |
|
| 110 | - 'text_no' => I18N::translate('Not running') |
|
| 111 | - ]), |
|
| 112 | - 'run' => view($module_name . '::admin/tasks-table-run', [ |
|
| 113 | - 'task_sched_id' => $schedule->id(), |
|
| 114 | - 'run_route' => route(TaskTrigger::class, [ |
|
| 115 | - 'task' => $schedule->taskId(), |
|
| 116 | - 'force' => $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
|
| 117 | - ]) |
|
| 118 | - ]) |
|
| 119 | - ]; |
|
| 120 | - }) |
|
| 121 | - ]); |
|
| 122 | - } |
|
| 70 | + return [ |
|
| 71 | + 'edit' => view($module_name . '::admin/tasks-table-options', [ |
|
| 72 | + 'task_sched_id' => $schedule->id(), |
|
| 73 | + 'task_sched_enabled' => $schedule->isEnabled(), |
|
| 74 | + 'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]), |
|
| 75 | + 'task_status_route' => route(TaskStatusAction::class, [ |
|
| 76 | + 'task' => $schedule->id(), |
|
| 77 | + 'enable' => $schedule->isEnabled() ? 0 : 1 |
|
| 78 | + ]) |
|
| 79 | + ]), |
|
| 80 | + 'status' => [ |
|
| 81 | + 'display' => view($module_name . '::components/yes-no-icons', [ |
|
| 82 | + 'yes' => $schedule->isEnabled() |
|
| 83 | + ]), |
|
| 84 | + 'raw' => $schedule->isEnabled() ? 1 : 0 |
|
| 85 | + ], |
|
| 86 | + 'task_name' => [ |
|
| 87 | + 'display' => '<bdi>' . e($task_name) . '</bdi>', |
|
| 88 | + 'raw' => $task_name |
|
| 89 | + ], |
|
| 90 | + 'last_run' => [ |
|
| 91 | + 'display' => $last_run_timestamp->timestamp() === 0 ? |
|
| 92 | + view('components/datetime', ['timestamp' => $last_run_timestamp]) : |
|
| 93 | + view('components/datetime-diff', ['timestamp' => $last_run_timestamp]), |
|
| 94 | + 'raw' => $schedule->lastRunTime()->getTimestamp() |
|
| 95 | + ], |
|
| 96 | + 'last_result' => [ |
|
| 97 | + 'display' => view($module_name . '::components/yes-no-icons', [ |
|
| 98 | + 'yes' => $schedule->wasLastRunSuccess() |
|
| 99 | + ]), |
|
| 100 | + 'raw' => $schedule->wasLastRunSuccess() ? 1 : 0 |
|
| 101 | + ], |
|
| 102 | + 'frequency' => |
|
| 103 | + '<bdi>' . e(CarbonInterval::minutes($schedule->frequency())->cascade()->forHumans()) . '</bdi>', |
|
| 104 | + 'nb_occurrences' => $schedule->remainingOccurrences() > 0 ? |
|
| 105 | + I18N::number($schedule->remainingOccurrences()) : |
|
| 106 | + I18N::translate('Unlimited'), |
|
| 107 | + 'running' => view($module_name . '::components/yes-no-icons', [ |
|
| 108 | + 'yes' => $schedule->isRunning(), |
|
| 109 | + 'text_yes' => I18N::translate('Running'), |
|
| 110 | + 'text_no' => I18N::translate('Not running') |
|
| 111 | + ]), |
|
| 112 | + 'run' => view($module_name . '::admin/tasks-table-run', [ |
|
| 113 | + 'task_sched_id' => $schedule->id(), |
|
| 114 | + 'run_route' => route(TaskTrigger::class, [ |
|
| 115 | + 'task' => $schedule->taskId(), |
|
| 116 | + 'force' => $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
|
| 117 | + ]) |
|
| 118 | + ]) |
|
| 119 | + ]; |
|
| 120 | + }) |
|
| 121 | + ]); |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -30,41 +30,41 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class TaskTrigger implements RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - private ?AdminTasksModule $module; |
|
| 34 | - private TaskScheduleService $taskschedules_service; |
|
| 33 | + private ?AdminTasksModule $module; |
|
| 34 | + private TaskScheduleService $taskschedules_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for TaskTrigger request handler |
|
| 38 | - * @param ModuleService $module_service |
|
| 39 | - * @param TaskScheduleService $taskschedules_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 42 | - { |
|
| 43 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 44 | - $this->taskschedules_service = $taskschedules_service; |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for TaskTrigger request handler |
|
| 38 | + * @param ModuleService $module_service |
|
| 39 | + * @param TaskScheduleService $taskschedules_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 42 | + { |
|
| 43 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 44 | + $this->taskschedules_service = $taskschedules_service; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritDoc} |
|
| 49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 50 | - */ |
|
| 51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 52 | - { |
|
| 53 | - if ($this->module === null) { |
|
| 54 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritDoc} |
|
| 49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 50 | + */ |
|
| 51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 52 | + { |
|
| 53 | + if ($this->module === null) { |
|
| 54 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $task_id = Validator::attributes($request)->string('task', ''); |
|
| 58 | - $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 59 | - $force_token = Validator::queryParams($request)->string('force', ''); |
|
| 60 | - $force = $token !== '' && $token === $force_token; |
|
| 57 | + $task_id = Validator::attributes($request)->string('task', ''); |
|
| 58 | + $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 59 | + $force_token = Validator::queryParams($request)->string('force', ''); |
|
| 60 | + $force = $token !== '' && $token === $force_token; |
|
| 61 | 61 | |
| 62 | - $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
| 62 | + $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
| 63 | 63 | |
| 64 | - foreach ($task_schedules as $task_schedule) { |
|
| 65 | - $this->taskschedules_service->run($task_schedule, $force); |
|
| 66 | - } |
|
| 64 | + foreach ($task_schedules as $task_schedule) { |
|
| 65 | + $this->taskschedules_service->run($task_schedule, $force); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return Registry::responseFactory()->response(); |
|
| 69 | - } |
|
| 68 | + return Registry::responseFactory()->response(); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -30,34 +30,34 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class TokenGenerate implements RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - private ?AdminTasksModule $module; |
|
| 34 | - private TokenService $token_service; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Constructor for TokenGenerate request handler |
|
| 38 | - * |
|
| 39 | - * @param ModuleService $module_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(ModuleService $module_service, TokenService $token_service) |
|
| 42 | - { |
|
| 43 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 44 | - $this->token_service = $token_service; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * {@inheritDoc} |
|
| 49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 50 | - */ |
|
| 51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 52 | - { |
|
| 53 | - if ($this->module === null) { |
|
| 54 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $token = $this->token_service->generateRandomToken(); |
|
| 58 | - $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 59 | - Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 60 | - |
|
| 61 | - return Registry::responseFactory()->response(['token' => $token]); |
|
| 62 | - } |
|
| 33 | + private ?AdminTasksModule $module; |
|
| 34 | + private TokenService $token_service; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Constructor for TokenGenerate request handler |
|
| 38 | + * |
|
| 39 | + * @param ModuleService $module_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(ModuleService $module_service, TokenService $token_service) |
|
| 42 | + { |
|
| 43 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 44 | + $this->token_service = $token_service; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * {@inheritDoc} |
|
| 49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 50 | + */ |
|
| 51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 52 | + { |
|
| 53 | + if ($this->module === null) { |
|
| 54 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $token = $this->token_service->generateRandomToken(); |
|
| 58 | + $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 59 | + Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 60 | + |
|
| 61 | + return Registry::responseFactory()->response(['token' => $token]); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -29,47 +29,47 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class AdminConfigPage implements RequestHandlerInterface |
| 31 | 31 | { |
| 32 | - use ViewResponseTrait; |
|
| 32 | + use ViewResponseTrait; |
|
| 33 | 33 | |
| 34 | - private ?AdminTasksModule $module; |
|
| 35 | - private TokenService $token_service; |
|
| 34 | + private ?AdminTasksModule $module; |
|
| 35 | + private TokenService $token_service; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Constructor for Admin Config request handler |
|
| 39 | - * |
|
| 40 | - * @param ModuleService $module_service |
|
| 41 | - */ |
|
| 42 | - public function __construct(ModuleService $module_service, TokenService $token_service) |
|
| 43 | - { |
|
| 44 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 45 | - $this->token_service = $token_service; |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * Constructor for Admin Config request handler |
|
| 39 | + * |
|
| 40 | + * @param ModuleService $module_service |
|
| 41 | + */ |
|
| 42 | + public function __construct(ModuleService $module_service, TokenService $token_service) |
|
| 43 | + { |
|
| 44 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 45 | + $this->token_service = $token_service; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritDoc} |
|
| 50 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 51 | - */ |
|
| 52 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 53 | - { |
|
| 54 | - $this->layout = 'layouts/administration'; |
|
| 48 | + /** |
|
| 49 | + * {@inheritDoc} |
|
| 50 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 51 | + */ |
|
| 52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 53 | + { |
|
| 54 | + $this->layout = 'layouts/administration'; |
|
| 55 | 55 | |
| 56 | - if ($this->module === null) { |
|
| 57 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 58 | - } |
|
| 56 | + if ($this->module === null) { |
|
| 57 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 61 | - if ($token === '') { |
|
| 62 | - $token = $this->token_service->generateRandomToken(); |
|
| 63 | - $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 64 | - } |
|
| 60 | + $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 61 | + if ($token === '') { |
|
| 62 | + $token = $this->token_service->generateRandomToken(); |
|
| 63 | + $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 67 | - 'title' => $this->module->title(), |
|
| 68 | - 'trigger_token' => $token, |
|
| 69 | - 'trigger_route' => route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']), |
|
| 70 | - 'new_token_route' => route(TokenGenerate::class), |
|
| 71 | - 'tasks_data_route' => route(TasksList::class), |
|
| 72 | - 'js_script_url' => $this->module->assetUrl('js/admintasks.min.js') |
|
| 73 | - ]); |
|
| 74 | - } |
|
| 66 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 67 | + 'title' => $this->module->title(), |
|
| 68 | + 'trigger_token' => $token, |
|
| 69 | + 'trigger_route' => route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']), |
|
| 70 | + 'new_token_route' => route(TokenGenerate::class), |
|
| 71 | + 'tasks_data_route' => route(TasksList::class), |
|
| 72 | + 'js_script_url' => $this->module->assetUrl('js/admintasks.min.js') |
|
| 73 | + ]); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -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 | } |
@@ -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 | } |
@@ -30,51 +30,51 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class MapFeaturePropertyData implements RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - private MapDefinitionsService $map_definition_service; |
|
| 33 | + private MapDefinitionsService $map_definition_service; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for MapFeaturePropertyData Request Handler |
|
| 37 | - * |
|
| 38 | - * @param MapDefinitionsService $map_definition_service |
|
| 39 | - */ |
|
| 40 | - public function __construct( |
|
| 41 | - MapDefinitionsService $map_definition_service |
|
| 42 | - ) { |
|
| 43 | - $this->map_definition_service = $map_definition_service; |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for MapFeaturePropertyData Request Handler |
|
| 37 | + * |
|
| 38 | + * @param MapDefinitionsService $map_definition_service |
|
| 39 | + */ |
|
| 40 | + public function __construct( |
|
| 41 | + MapDefinitionsService $map_definition_service |
|
| 42 | + ) { |
|
| 43 | + $this->map_definition_service = $map_definition_service; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | - */ |
|
| 50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | - { |
|
| 52 | - $map_id = Validator::queryParams($request)->string( |
|
| 53 | - 'map_id', |
|
| 54 | - Validator::attributes($request)->string('map_id', '') |
|
| 55 | - ); |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | + */ |
|
| 50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | + { |
|
| 52 | + $map_id = Validator::queryParams($request)->string( |
|
| 53 | + 'map_id', |
|
| 54 | + Validator::attributes($request)->string('map_id', '') |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | - return Registry::responseFactory()->response(Registry::cache()->file()->remember( |
|
| 58 | - 'map-properties-' . $map_id, |
|
| 59 | - function () use ($map_id): array { |
|
| 60 | - $map = $this->map_definition_service->find($map_id); |
|
| 61 | - if ($map === null) { |
|
| 62 | - throw new HttpNotFoundException(I18N::translate('The map could not be found.')); |
|
| 63 | - } |
|
| 57 | + return Registry::responseFactory()->response(Registry::cache()->file()->remember( |
|
| 58 | + 'map-properties-' . $map_id, |
|
| 59 | + function () use ($map_id): array { |
|
| 60 | + $map = $this->map_definition_service->find($map_id); |
|
| 61 | + if ($map === null) { |
|
| 62 | + throw new HttpNotFoundException(I18N::translate('The map could not be found.')); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $features = []; |
|
| 66 | - collect($map->features()) |
|
| 67 | - ->map(fn(Feature $feature): ?stdClass => $feature->getProperties()) |
|
| 68 | - ->filter() |
|
| 69 | - ->map(fn(stdClass $properties): array => array_keys(get_object_vars($properties))) |
|
| 70 | - ->each(function (array $properties) use (&$features): void { |
|
| 71 | - $features = count($features) === 0 ? $properties : array_intersect($features, $properties); |
|
| 72 | - }); |
|
| 65 | + $features = []; |
|
| 66 | + collect($map->features()) |
|
| 67 | + ->map(fn(Feature $feature): ?stdClass => $feature->getProperties()) |
|
| 68 | + ->filter() |
|
| 69 | + ->map(fn(stdClass $properties): array => array_keys(get_object_vars($properties))) |
|
| 70 | + ->each(function (array $properties) use (&$features): void { |
|
| 71 | + $features = count($features) === 0 ? $properties : array_intersect($features, $properties); |
|
| 72 | + }); |
|
| 73 | 73 | |
| 74 | - usort($features, I18N::comparator()); |
|
| 75 | - return $features; |
|
| 76 | - }, |
|
| 77 | - 86400000 |
|
| 78 | - )); |
|
| 79 | - } |
|
| 74 | + usort($features, I18N::comparator()); |
|
| 75 | + return $features; |
|
| 76 | + }, |
|
| 77 | + 86400000 |
|
| 78 | + )); |
|
| 79 | + } |
|
| 80 | 80 | } |