@@ -20,27 +20,27 @@ |
||
| 20 | 20 | |
| 21 | 21 | class GeoAnalysisTable extends AbstractGeoAnalysisView |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * {@inheritDoc} |
|
| 25 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
| 26 | - */ |
|
| 27 | - public function icon(ModuleInterface $module): string |
|
| 28 | - { |
|
| 29 | - return view($module->name() . '::icons/view-table'); |
|
| 30 | - } |
|
| 23 | + /** |
|
| 24 | + * {@inheritDoc} |
|
| 25 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
| 26 | + */ |
|
| 27 | + public function icon(ModuleInterface $module): string |
|
| 28 | + { |
|
| 29 | + return view($module->name() . '::icons/view-table'); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * {@inheritDoc} |
|
| 34 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
| 35 | - */ |
|
| 36 | - public function globalTabContent( |
|
| 37 | - ModuleInterface $module, |
|
| 38 | - GeoAnalysisResult $result, |
|
| 39 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 40 | - array $params |
|
| 41 | - ): string { |
|
| 42 | - return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
| 43 | - 'result' => $result |
|
| 44 | - ]); |
|
| 45 | - } |
|
| 32 | + /** |
|
| 33 | + * {@inheritDoc} |
|
| 34 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
| 35 | + */ |
|
| 36 | + public function globalTabContent( |
|
| 37 | + ModuleInterface $module, |
|
| 38 | + GeoAnalysisResult $result, |
|
| 39 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 40 | + array $params |
|
| 41 | + ): string { |
|
| 42 | + return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
| 43 | + 'result' => $result |
|
| 44 | + ]); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function icon(ModuleInterface $module): string |
| 28 | 28 | { |
| 29 | - return view($module->name() . '::icons/view-table'); |
|
| 29 | + return view($module->name().'::icons/view-table'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | GeoAnalysisViewDataService $geoview_data_service, |
| 40 | 40 | array $params |
| 41 | 41 | ): string { |
| 42 | - return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
| 42 | + return view($module->name().'::geoanalysisview-tab-glb-table', $params + [ |
|
| 43 | 43 | 'result' => $result |
| 44 | 44 | ]); |
| 45 | 45 | } |
@@ -26,85 +26,85 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class GeoAnalysisMap extends AbstractGeoAnalysisView |
| 28 | 28 | { |
| 29 | - private ?MapColorsConfig $colors_config = null; |
|
| 29 | + private ?MapColorsConfig $colors_config = null; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * {@inheritDoc} |
|
| 33 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
| 34 | - */ |
|
| 35 | - public function icon(ModuleInterface $module): string |
|
| 36 | - { |
|
| 37 | - return view($module->name() . '::icons/view-map'); |
|
| 38 | - } |
|
| 31 | + /** |
|
| 32 | + * {@inheritDoc} |
|
| 33 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
| 34 | + */ |
|
| 35 | + public function icon(ModuleInterface $module): string |
|
| 36 | + { |
|
| 37 | + return view($module->name() . '::icons/view-map'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * {@inheritDoc} |
|
| 42 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
| 43 | - */ |
|
| 44 | - public function globalTabContent( |
|
| 45 | - ModuleInterface $module, |
|
| 46 | - GeoAnalysisResult $result, |
|
| 47 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 48 | - array $params |
|
| 49 | - ): string { |
|
| 50 | - $map_adapters = $geoview_data_service->mapAdapters($this); |
|
| 40 | + /** |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
| 43 | + */ |
|
| 44 | + public function globalTabContent( |
|
| 45 | + ModuleInterface $module, |
|
| 46 | + GeoAnalysisResult $result, |
|
| 47 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 48 | + array $params |
|
| 49 | + ): string { |
|
| 50 | + $map_adapters = $geoview_data_service->mapAdapters($this); |
|
| 51 | 51 | |
| 52 | - $adapter_result = null; |
|
| 53 | - foreach ($map_adapters as $map_adapter) { |
|
| 54 | - $adapter_result_tmp = $map_adapter->convert($result); |
|
| 55 | - $adapter_result = $adapter_result === null ? |
|
| 56 | - $adapter_result_tmp : |
|
| 57 | - $adapter_result->merge($adapter_result_tmp); |
|
| 58 | - } |
|
| 52 | + $adapter_result = null; |
|
| 53 | + foreach ($map_adapters as $map_adapter) { |
|
| 54 | + $adapter_result_tmp = $map_adapter->convert($result); |
|
| 55 | + $adapter_result = $adapter_result === null ? |
|
| 56 | + $adapter_result_tmp : |
|
| 57 | + $adapter_result->merge($adapter_result_tmp); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if ($adapter_result === null) { |
|
| 61 | - return view($module->name() . '::errors/tab-error', [ |
|
| 62 | - 'message' => I18N::translate('The map could not be loaded.'), |
|
| 63 | - ]); |
|
| 64 | - } |
|
| 60 | + if ($adapter_result === null) { |
|
| 61 | + return view($module->name() . '::errors/tab-error', [ |
|
| 62 | + 'message' => I18N::translate('The map could not be loaded.'), |
|
| 63 | + ]); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 67 | - $basemap_provider = [ |
|
| 68 | - 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
|
| 69 | - 'options' => [ |
|
| 70 | - 'attribution' => '<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap</a> contributors', |
|
| 71 | - 'max_zoom' => 19 |
|
| 72 | - ] |
|
| 73 | - ]; |
|
| 74 | - //phpcs:enable |
|
| 66 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 67 | + $basemap_provider = [ |
|
| 68 | + 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
|
| 69 | + 'options' => [ |
|
| 70 | + 'attribution' => '<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap</a> contributors', |
|
| 71 | + 'max_zoom' => 19 |
|
| 72 | + ] |
|
| 73 | + ]; |
|
| 74 | + //phpcs:enable |
|
| 75 | 75 | |
| 76 | - return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
| 77 | - 'result' => $adapter_result->geoAnalysisResult(), |
|
| 78 | - 'features' => $adapter_result->features(), |
|
| 79 | - 'colors' => $this->colors(), |
|
| 80 | - 'basemap_provider' => $basemap_provider |
|
| 81 | - ]); |
|
| 82 | - } |
|
| 76 | + return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
| 77 | + 'result' => $adapter_result->geoAnalysisResult(), |
|
| 78 | + 'features' => $adapter_result->features(), |
|
| 79 | + 'colors' => $this->colors(), |
|
| 80 | + 'basemap_provider' => $basemap_provider |
|
| 81 | + ]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Get the color scheme configuration for the map view |
|
| 86 | - * |
|
| 87 | - * @return MapColorsConfig |
|
| 88 | - */ |
|
| 89 | - public function colors(): MapColorsConfig |
|
| 90 | - { |
|
| 91 | - return $this->colors_config ?? new MapColorsConfig( |
|
| 92 | - new Rgb(245, 245, 245), |
|
| 93 | - new Rgb(213, 213, 213), |
|
| 94 | - new Rgb(4, 147, 171), |
|
| 95 | - new Rgb(255, 102, 0) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 84 | + /** |
|
| 85 | + * Get the color scheme configuration for the map view |
|
| 86 | + * |
|
| 87 | + * @return MapColorsConfig |
|
| 88 | + */ |
|
| 89 | + public function colors(): MapColorsConfig |
|
| 90 | + { |
|
| 91 | + return $this->colors_config ?? new MapColorsConfig( |
|
| 92 | + new Rgb(245, 245, 245), |
|
| 93 | + new Rgb(213, 213, 213), |
|
| 94 | + new Rgb(4, 147, 171), |
|
| 95 | + new Rgb(255, 102, 0) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Set the color scheme configuration for the map view |
|
| 101 | - * |
|
| 102 | - * @param MapColorsConfig $config |
|
| 103 | - * @return self |
|
| 104 | - */ |
|
| 105 | - public function setColors(?MapColorsConfig $config): self |
|
| 106 | - { |
|
| 107 | - $this->colors_config = $config; |
|
| 108 | - return $this; |
|
| 109 | - } |
|
| 99 | + /** |
|
| 100 | + * Set the color scheme configuration for the map view |
|
| 101 | + * |
|
| 102 | + * @param MapColorsConfig $config |
|
| 103 | + * @return self |
|
| 104 | + */ |
|
| 105 | + public function setColors(?MapColorsConfig $config): self |
|
| 106 | + { |
|
| 107 | + $this->colors_config = $config; |
|
| 108 | + return $this; |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function icon(ModuleInterface $module): string |
| 36 | 36 | { |
| 37 | - return view($module->name() . '::icons/view-map'); |
|
| 37 | + return view($module->name().'::icons/view-map'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -53,12 +53,11 @@ discard block |
||
| 53 | 53 | foreach ($map_adapters as $map_adapter) { |
| 54 | 54 | $adapter_result_tmp = $map_adapter->convert($result); |
| 55 | 55 | $adapter_result = $adapter_result === null ? |
| 56 | - $adapter_result_tmp : |
|
| 57 | - $adapter_result->merge($adapter_result_tmp); |
|
| 56 | + $adapter_result_tmp : $adapter_result->merge($adapter_result_tmp); |
|
| 58 | 57 | } |
| 59 | 58 | |
| 60 | 59 | if ($adapter_result === null) { |
| 61 | - return view($module->name() . '::errors/tab-error', [ |
|
| 60 | + return view($module->name().'::errors/tab-error', [ |
|
| 62 | 61 | 'message' => I18N::translate('The map could not be loaded.'), |
| 63 | 62 | ]); |
| 64 | 63 | } |
@@ -73,7 +72,7 @@ discard block |
||
| 73 | 72 | ]; |
| 74 | 73 | //phpcs:enable |
| 75 | 74 | |
| 76 | - return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
| 75 | + return view($module->name().'::geoanalysisview-tab-glb-map', $params + [ |
|
| 77 | 76 | 'result' => $adapter_result->geoAnalysisResult(), |
| 78 | 77 | 'features' => $adapter_result->features(), |
| 79 | 78 | 'colors' => $this->colors(), |
@@ -26,161 +26,161 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | abstract class AbstractGeoAnalysisView |
| 28 | 28 | { |
| 29 | - private int $id; |
|
| 30 | - private Tree $tree; |
|
| 31 | - private bool $enabled; |
|
| 32 | - private string $description; |
|
| 33 | - private GeoAnalysisInterface $geoanalysis; |
|
| 34 | - private int $depth; |
|
| 35 | - private int $detailed_top_places; |
|
| 36 | - private bool $use_flags; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Constructor for AbstractGeoAnalysisView |
|
| 40 | - * |
|
| 41 | - * @param int $id |
|
| 42 | - * @param Tree $tree |
|
| 43 | - * @param bool $enabled |
|
| 44 | - * @param string $description |
|
| 45 | - * @param GeoAnalysisInterface $geoanalysis |
|
| 46 | - * @param int $depth |
|
| 47 | - * @param int $detailed_top_places |
|
| 48 | - * @param bool $use_flags |
|
| 49 | - */ |
|
| 50 | - final public function __construct( |
|
| 51 | - int $id, |
|
| 52 | - Tree $tree, |
|
| 53 | - bool $enabled, |
|
| 54 | - string $description, |
|
| 55 | - GeoAnalysisInterface $geoanalysis, |
|
| 56 | - int $depth, |
|
| 57 | - int $detailed_top_places = 0, |
|
| 58 | - bool $use_flags = false |
|
| 59 | - ) { |
|
| 60 | - $this->id = $id; |
|
| 61 | - $this->tree = $tree; |
|
| 62 | - $this->enabled = $enabled; |
|
| 63 | - $this->description = $description; |
|
| 64 | - $this->geoanalysis = $geoanalysis; |
|
| 65 | - $this->depth = $depth; |
|
| 66 | - $this->detailed_top_places = $detailed_top_places; |
|
| 67 | - $this->use_flags = $use_flags; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Get the view ID |
|
| 72 | - * |
|
| 73 | - * @return int |
|
| 74 | - */ |
|
| 75 | - public function id(): int |
|
| 76 | - { |
|
| 77 | - return $this->id; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get the icon for the view type |
|
| 82 | - * |
|
| 83 | - * @param ModuleInterface $module |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - abstract public function icon(ModuleInterface $module): string; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the content of the view global tab |
|
| 90 | - * |
|
| 91 | - * @param ModuleInterface $module |
|
| 92 | - * @param GeoAnalysisResult $result |
|
| 93 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 94 | - * @param array $params |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - abstract public function globalTabContent( |
|
| 98 | - ModuleInterface $module, |
|
| 99 | - GeoAnalysisResult $result, |
|
| 100 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 101 | - array $params |
|
| 102 | - ): string; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Returns the content of the view detailed tab |
|
| 106 | - * |
|
| 107 | - * @param ModuleInterface $module |
|
| 108 | - * @param Collection $results |
|
| 109 | - * @param array $params |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
| 113 | - { |
|
| 114 | - return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Get the tree to which the view belongs |
|
| 119 | - * |
|
| 120 | - * @return Tree |
|
| 121 | - */ |
|
| 122 | - public function tree(): Tree |
|
| 123 | - { |
|
| 124 | - return $this->tree; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Get the description of the view |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function description(): string |
|
| 133 | - { |
|
| 134 | - return $this->description; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Get whether the view is enabled |
|
| 139 | - * |
|
| 140 | - * @return bool |
|
| 141 | - */ |
|
| 142 | - public function isEnabled(): bool |
|
| 143 | - { |
|
| 144 | - return $this->enabled; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Get the geographical dispersion analysis for the view |
|
| 149 | - * |
|
| 150 | - * @return GeoAnalysisInterface |
|
| 151 | - */ |
|
| 152 | - public function analysis(): GeoAnalysisInterface |
|
| 153 | - { |
|
| 154 | - return $this->geoanalysis; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Get the place hierarchy depth for the view |
|
| 159 | - * |
|
| 160 | - * @return int |
|
| 161 | - */ |
|
| 162 | - public function placesDepth(): int |
|
| 163 | - { |
|
| 164 | - return $this->depth; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Get the number of places to display in the detailed tab |
|
| 169 | - * |
|
| 170 | - * @return int |
|
| 171 | - */ |
|
| 172 | - public function numberTopPlaces(): int |
|
| 173 | - { |
|
| 174 | - return $this->detailed_top_places; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Get whether flags should be used in the detailed tab |
|
| 179 | - * |
|
| 180 | - * @return bool |
|
| 181 | - */ |
|
| 182 | - public function useFlags(): bool |
|
| 183 | - { |
|
| 184 | - return $this->use_flags; |
|
| 185 | - } |
|
| 29 | + private int $id; |
|
| 30 | + private Tree $tree; |
|
| 31 | + private bool $enabled; |
|
| 32 | + private string $description; |
|
| 33 | + private GeoAnalysisInterface $geoanalysis; |
|
| 34 | + private int $depth; |
|
| 35 | + private int $detailed_top_places; |
|
| 36 | + private bool $use_flags; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructor for AbstractGeoAnalysisView |
|
| 40 | + * |
|
| 41 | + * @param int $id |
|
| 42 | + * @param Tree $tree |
|
| 43 | + * @param bool $enabled |
|
| 44 | + * @param string $description |
|
| 45 | + * @param GeoAnalysisInterface $geoanalysis |
|
| 46 | + * @param int $depth |
|
| 47 | + * @param int $detailed_top_places |
|
| 48 | + * @param bool $use_flags |
|
| 49 | + */ |
|
| 50 | + final public function __construct( |
|
| 51 | + int $id, |
|
| 52 | + Tree $tree, |
|
| 53 | + bool $enabled, |
|
| 54 | + string $description, |
|
| 55 | + GeoAnalysisInterface $geoanalysis, |
|
| 56 | + int $depth, |
|
| 57 | + int $detailed_top_places = 0, |
|
| 58 | + bool $use_flags = false |
|
| 59 | + ) { |
|
| 60 | + $this->id = $id; |
|
| 61 | + $this->tree = $tree; |
|
| 62 | + $this->enabled = $enabled; |
|
| 63 | + $this->description = $description; |
|
| 64 | + $this->geoanalysis = $geoanalysis; |
|
| 65 | + $this->depth = $depth; |
|
| 66 | + $this->detailed_top_places = $detailed_top_places; |
|
| 67 | + $this->use_flags = $use_flags; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Get the view ID |
|
| 72 | + * |
|
| 73 | + * @return int |
|
| 74 | + */ |
|
| 75 | + public function id(): int |
|
| 76 | + { |
|
| 77 | + return $this->id; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get the icon for the view type |
|
| 82 | + * |
|
| 83 | + * @param ModuleInterface $module |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + abstract public function icon(ModuleInterface $module): string; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the content of the view global tab |
|
| 90 | + * |
|
| 91 | + * @param ModuleInterface $module |
|
| 92 | + * @param GeoAnalysisResult $result |
|
| 93 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 94 | + * @param array $params |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + abstract public function globalTabContent( |
|
| 98 | + ModuleInterface $module, |
|
| 99 | + GeoAnalysisResult $result, |
|
| 100 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 101 | + array $params |
|
| 102 | + ): string; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Returns the content of the view detailed tab |
|
| 106 | + * |
|
| 107 | + * @param ModuleInterface $module |
|
| 108 | + * @param Collection $results |
|
| 109 | + * @param array $params |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
| 113 | + { |
|
| 114 | + return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Get the tree to which the view belongs |
|
| 119 | + * |
|
| 120 | + * @return Tree |
|
| 121 | + */ |
|
| 122 | + public function tree(): Tree |
|
| 123 | + { |
|
| 124 | + return $this->tree; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Get the description of the view |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function description(): string |
|
| 133 | + { |
|
| 134 | + return $this->description; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Get whether the view is enabled |
|
| 139 | + * |
|
| 140 | + * @return bool |
|
| 141 | + */ |
|
| 142 | + public function isEnabled(): bool |
|
| 143 | + { |
|
| 144 | + return $this->enabled; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Get the geographical dispersion analysis for the view |
|
| 149 | + * |
|
| 150 | + * @return GeoAnalysisInterface |
|
| 151 | + */ |
|
| 152 | + public function analysis(): GeoAnalysisInterface |
|
| 153 | + { |
|
| 154 | + return $this->geoanalysis; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Get the place hierarchy depth for the view |
|
| 159 | + * |
|
| 160 | + * @return int |
|
| 161 | + */ |
|
| 162 | + public function placesDepth(): int |
|
| 163 | + { |
|
| 164 | + return $this->depth; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Get the number of places to display in the detailed tab |
|
| 169 | + * |
|
| 170 | + * @return int |
|
| 171 | + */ |
|
| 172 | + public function numberTopPlaces(): int |
|
| 173 | + { |
|
| 174 | + return $this->detailed_top_places; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Get whether flags should be used in the detailed tab |
|
| 179 | + * |
|
| 180 | + * @return bool |
|
| 181 | + */ |
|
| 182 | + public function useFlags(): bool |
|
| 183 | + { |
|
| 184 | + return $this->use_flags; |
|
| 185 | + } |
|
| 186 | 186 | } |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | */ |
| 112 | 112 | public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
| 113 | 113 | { |
| 114 | - return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
| 114 | + return view($module->name().'::geoanalysisview-tab-detailed', $params + ['results' => $results]); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -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 | } |
@@ -31,65 +31,65 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class TaskEditPage implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - use ViewResponseTrait; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var AdminTasksModule|null $module |
|
| 38 | - */ |
|
| 39 | - private $module; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var TaskScheduleService $taskschedules_service |
|
| 43 | - */ |
|
| 44 | - private $taskschedules_service; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Constructor for TaskEditPage Request Handler |
|
| 48 | - * |
|
| 49 | - * @param ModuleService $module_service |
|
| 50 | - * @param TaskScheduleService $taskschedules_service |
|
| 51 | - */ |
|
| 52 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 53 | - { |
|
| 54 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 55 | - $this->taskschedules_service = $taskschedules_service; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 61 | - */ |
|
| 62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 63 | - { |
|
| 64 | - $this->layout = 'layouts/administration'; |
|
| 65 | - |
|
| 66 | - if ($this->module === null) { |
|
| 67 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 71 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 72 | - |
|
| 73 | - if ($task_schedule === null) { |
|
| 74 | - throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
| 78 | - |
|
| 79 | - if ($task === null) { |
|
| 80 | - throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $has_task_config = $task instanceof ConfigurableTaskInterface; |
|
| 84 | - /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
| 85 | - |
|
| 86 | - return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
| 87 | - 'module' => $this->module, |
|
| 88 | - 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
| 89 | - 'task_schedule' => $task_schedule, |
|
| 90 | - 'task' => $task, |
|
| 91 | - 'has_task_config' => $has_task_config, |
|
| 92 | - 'task_config_view' => $has_task_config ? $task->configView($request) : '' |
|
| 93 | - ]); |
|
| 94 | - } |
|
| 34 | + use ViewResponseTrait; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var AdminTasksModule|null $module |
|
| 38 | + */ |
|
| 39 | + private $module; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var TaskScheduleService $taskschedules_service |
|
| 43 | + */ |
|
| 44 | + private $taskschedules_service; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Constructor for TaskEditPage Request Handler |
|
| 48 | + * |
|
| 49 | + * @param ModuleService $module_service |
|
| 50 | + * @param TaskScheduleService $taskschedules_service |
|
| 51 | + */ |
|
| 52 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 53 | + { |
|
| 54 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 55 | + $this->taskschedules_service = $taskschedules_service; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 61 | + */ |
|
| 62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 63 | + { |
|
| 64 | + $this->layout = 'layouts/administration'; |
|
| 65 | + |
|
| 66 | + if ($this->module === null) { |
|
| 67 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
| 71 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 72 | + |
|
| 73 | + if ($task_schedule === null) { |
|
| 74 | + throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
| 78 | + |
|
| 79 | + if ($task === null) { |
|
| 80 | + throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $has_task_config = $task instanceof ConfigurableTaskInterface; |
|
| 84 | + /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
| 85 | + |
|
| 86 | + return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
| 87 | + 'module' => $this->module, |
|
| 88 | + 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
| 89 | + 'task_schedule' => $task_schedule, |
|
| 90 | + 'task' => $task, |
|
| 91 | + 'has_task_config' => $has_task_config, |
|
| 92 | + 'task_config_view' => $has_task_config ? $task->configView($request) : '' |
|
| 93 | + ]); |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -29,35 +29,35 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class TokenGenerate implements RequestHandlerInterface |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @var AdminTasksModule|null $module |
|
| 34 | - */ |
|
| 35 | - private $module; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Constructor for TokenGenerate request handler |
|
| 39 | - * |
|
| 40 | - * @param ModuleService $module_service |
|
| 41 | - */ |
|
| 42 | - public function __construct(ModuleService $module_service) |
|
| 43 | - { |
|
| 44 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 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 = Functions::generateRandomToken(); |
|
| 58 | - $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 59 | - Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 60 | - |
|
| 61 | - return response(['token' => $token]); |
|
| 62 | - } |
|
| 32 | + /** |
|
| 33 | + * @var AdminTasksModule|null $module |
|
| 34 | + */ |
|
| 35 | + private $module; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Constructor for TokenGenerate request handler |
|
| 39 | + * |
|
| 40 | + * @param ModuleService $module_service |
|
| 41 | + */ |
|
| 42 | + public function __construct(ModuleService $module_service) |
|
| 43 | + { |
|
| 44 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 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 = Functions::generateRandomToken(); |
|
| 58 | + $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 59 | + Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 60 | + |
|
| 61 | + return response(['token' => $token]); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -31,113 +31,113 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class TasksList implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * @var AdminTasksModule|null $module |
|
| 36 | - */ |
|
| 37 | - private $module; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var TaskScheduleService $taskschedules_service |
|
| 41 | - */ |
|
| 42 | - private $taskschedules_service; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var DatatablesService $datatables_service |
|
| 46 | - */ |
|
| 47 | - private $datatables_service; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Constructor for TasksList Request Handler |
|
| 51 | - * |
|
| 52 | - * @param ModuleService $module_service |
|
| 53 | - * @param TaskScheduleService $taskschedules_service |
|
| 54 | - * @param DatatablesService $datatables_service |
|
| 55 | - */ |
|
| 56 | - public function __construct( |
|
| 57 | - ModuleService $module_service, |
|
| 58 | - TaskScheduleService $taskschedules_service, |
|
| 59 | - DatatablesService $datatables_service |
|
| 60 | - ) { |
|
| 61 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 62 | - $this->taskschedules_service = $taskschedules_service; |
|
| 63 | - $this->datatables_service = $datatables_service; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * {@inheritDoc} |
|
| 68 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 69 | - */ |
|
| 70 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 71 | - { |
|
| 72 | - if ($this->module === null) { |
|
| 73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $task_schedules = $this->taskschedules_service->all(true, true) |
|
| 77 | - ->map(function (TaskSchedule $value): array { |
|
| 78 | - |
|
| 79 | - $row = $value->toArray(); |
|
| 80 | - $task = $this->taskschedules_service->findTask($row['task_id']); |
|
| 81 | - $row['task_name'] = $task !== null ? $task->name() : I18N::translate('Task not found'); |
|
| 82 | - return $row; |
|
| 83 | - }); |
|
| 84 | - |
|
| 85 | - $search_columns = ['task_name']; |
|
| 86 | - $sort_columns = ['task_name', 'enabled', 'last_run']; |
|
| 87 | - |
|
| 88 | - $callback = function (array $row): array { |
|
| 89 | - if ($this->module === null) { |
|
| 90 | - return []; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $row['frequency']->setLocale(I18N::locale()->code()); |
|
| 94 | - |
|
| 95 | - $task_options_params = [ |
|
| 96 | - 'task_sched_id' => $row['id'], |
|
| 97 | - 'task_sched_enabled' => $row['enabled'], |
|
| 98 | - 'task_edit_route' => route(TaskEditPage::class, ['task' => $row['id']]), |
|
| 99 | - 'task_status_route' => route(TaskStatusAction::class, [ |
|
| 100 | - 'task' => $row['id'], |
|
| 101 | - 'enable' => $row['enabled'] ? 0 : 1 |
|
| 102 | - ]) |
|
| 103 | - ]; |
|
| 104 | - |
|
| 105 | - $task_run_params = [ |
|
| 106 | - 'task_sched_id' => $row['id'], |
|
| 107 | - 'run_route' => route(TaskTrigger::class, [ |
|
| 108 | - 'task' => $row['task_id'], |
|
| 109 | - 'force' => $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
|
| 110 | - ]) |
|
| 111 | - ]; |
|
| 112 | - |
|
| 113 | - $module_name = $this->module->name(); |
|
| 114 | - $datum = [ |
|
| 115 | - view($module_name . '::admin/tasks-table-options', $task_options_params), |
|
| 116 | - view($module_name . '::components/yes-no-icons', ['yes' => $row['enabled']]), |
|
| 117 | - '<span dir="auto">' . e($row['task_name']) . '</span>', |
|
| 118 | - $row['last_run']->unix() === 0 ? |
|
| 119 | - view('components/datetime', ['timestamp' => $row['last_run']]) : |
|
| 120 | - view('components/datetime-diff', ['timestamp' => $row['last_run']]), |
|
| 121 | - view($module_name . '::components/yes-no-icons', ['yes' => $row['last_result']]), |
|
| 122 | - '<span dir="auto">' . e($row['frequency']->cascade()->forHumans()) . '</span>', |
|
| 123 | - $row['nb_occurrences'] > 0 ? I18N::number($row['nb_occurrences']) : I18N::translate('Unlimited'), |
|
| 124 | - view($module_name . '::components/yes-no-icons', [ |
|
| 125 | - 'yes' => $row['is_running'], |
|
| 126 | - 'text_yes' => I18N::translate('Running'), |
|
| 127 | - 'text_no' => I18N::translate('Not running') |
|
| 128 | - ]), |
|
| 129 | - view($module_name . '::admin/tasks-table-run', $task_run_params) |
|
| 130 | - ]; |
|
| 131 | - |
|
| 132 | - return $datum; |
|
| 133 | - }; |
|
| 134 | - |
|
| 135 | - return $this->datatables_service->handleCollection( |
|
| 136 | - $request, |
|
| 137 | - $task_schedules, |
|
| 138 | - $search_columns, |
|
| 139 | - $sort_columns, |
|
| 140 | - $callback |
|
| 141 | - ); |
|
| 142 | - } |
|
| 34 | + /** |
|
| 35 | + * @var AdminTasksModule|null $module |
|
| 36 | + */ |
|
| 37 | + private $module; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var TaskScheduleService $taskschedules_service |
|
| 41 | + */ |
|
| 42 | + private $taskschedules_service; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var DatatablesService $datatables_service |
|
| 46 | + */ |
|
| 47 | + private $datatables_service; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Constructor for TasksList Request Handler |
|
| 51 | + * |
|
| 52 | + * @param ModuleService $module_service |
|
| 53 | + * @param TaskScheduleService $taskschedules_service |
|
| 54 | + * @param DatatablesService $datatables_service |
|
| 55 | + */ |
|
| 56 | + public function __construct( |
|
| 57 | + ModuleService $module_service, |
|
| 58 | + TaskScheduleService $taskschedules_service, |
|
| 59 | + DatatablesService $datatables_service |
|
| 60 | + ) { |
|
| 61 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 62 | + $this->taskschedules_service = $taskschedules_service; |
|
| 63 | + $this->datatables_service = $datatables_service; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * {@inheritDoc} |
|
| 68 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 69 | + */ |
|
| 70 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 71 | + { |
|
| 72 | + if ($this->module === null) { |
|
| 73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $task_schedules = $this->taskschedules_service->all(true, true) |
|
| 77 | + ->map(function (TaskSchedule $value): array { |
|
| 78 | + |
|
| 79 | + $row = $value->toArray(); |
|
| 80 | + $task = $this->taskschedules_service->findTask($row['task_id']); |
|
| 81 | + $row['task_name'] = $task !== null ? $task->name() : I18N::translate('Task not found'); |
|
| 82 | + return $row; |
|
| 83 | + }); |
|
| 84 | + |
|
| 85 | + $search_columns = ['task_name']; |
|
| 86 | + $sort_columns = ['task_name', 'enabled', 'last_run']; |
|
| 87 | + |
|
| 88 | + $callback = function (array $row): array { |
|
| 89 | + if ($this->module === null) { |
|
| 90 | + return []; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $row['frequency']->setLocale(I18N::locale()->code()); |
|
| 94 | + |
|
| 95 | + $task_options_params = [ |
|
| 96 | + 'task_sched_id' => $row['id'], |
|
| 97 | + 'task_sched_enabled' => $row['enabled'], |
|
| 98 | + 'task_edit_route' => route(TaskEditPage::class, ['task' => $row['id']]), |
|
| 99 | + 'task_status_route' => route(TaskStatusAction::class, [ |
|
| 100 | + 'task' => $row['id'], |
|
| 101 | + 'enable' => $row['enabled'] ? 0 : 1 |
|
| 102 | + ]) |
|
| 103 | + ]; |
|
| 104 | + |
|
| 105 | + $task_run_params = [ |
|
| 106 | + 'task_sched_id' => $row['id'], |
|
| 107 | + 'run_route' => route(TaskTrigger::class, [ |
|
| 108 | + 'task' => $row['task_id'], |
|
| 109 | + 'force' => $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
|
| 110 | + ]) |
|
| 111 | + ]; |
|
| 112 | + |
|
| 113 | + $module_name = $this->module->name(); |
|
| 114 | + $datum = [ |
|
| 115 | + view($module_name . '::admin/tasks-table-options', $task_options_params), |
|
| 116 | + view($module_name . '::components/yes-no-icons', ['yes' => $row['enabled']]), |
|
| 117 | + '<span dir="auto">' . e($row['task_name']) . '</span>', |
|
| 118 | + $row['last_run']->unix() === 0 ? |
|
| 119 | + view('components/datetime', ['timestamp' => $row['last_run']]) : |
|
| 120 | + view('components/datetime-diff', ['timestamp' => $row['last_run']]), |
|
| 121 | + view($module_name . '::components/yes-no-icons', ['yes' => $row['last_result']]), |
|
| 122 | + '<span dir="auto">' . e($row['frequency']->cascade()->forHumans()) . '</span>', |
|
| 123 | + $row['nb_occurrences'] > 0 ? I18N::number($row['nb_occurrences']) : I18N::translate('Unlimited'), |
|
| 124 | + view($module_name . '::components/yes-no-icons', [ |
|
| 125 | + 'yes' => $row['is_running'], |
|
| 126 | + 'text_yes' => I18N::translate('Running'), |
|
| 127 | + 'text_no' => I18N::translate('Not running') |
|
| 128 | + ]), |
|
| 129 | + view($module_name . '::admin/tasks-table-run', $task_run_params) |
|
| 130 | + ]; |
|
| 131 | + |
|
| 132 | + return $datum; |
|
| 133 | + }; |
|
| 134 | + |
|
| 135 | + return $this->datatables_service->handleCollection( |
|
| 136 | + $request, |
|
| 137 | + $task_schedules, |
|
| 138 | + $search_columns, |
|
| 139 | + $sort_columns, |
|
| 140 | + $callback |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $task_schedules = $this->taskschedules_service->all(true, true) |
| 77 | - ->map(function (TaskSchedule $value): array { |
|
| 77 | + ->map(function(TaskSchedule $value): array { |
|
| 78 | 78 | |
| 79 | 79 | $row = $value->toArray(); |
| 80 | 80 | $task = $this->taskschedules_service->findTask($row['task_id']); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $search_columns = ['task_name']; |
| 86 | 86 | $sort_columns = ['task_name', 'enabled', 'last_run']; |
| 87 | 87 | |
| 88 | - $callback = function (array $row): array { |
|
| 88 | + $callback = function(array $row): array { |
|
| 89 | 89 | if ($this->module === null) { |
| 90 | 90 | return []; |
| 91 | 91 | } |
@@ -112,21 +112,20 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | $module_name = $this->module->name(); |
| 114 | 114 | $datum = [ |
| 115 | - view($module_name . '::admin/tasks-table-options', $task_options_params), |
|
| 116 | - view($module_name . '::components/yes-no-icons', ['yes' => $row['enabled']]), |
|
| 117 | - '<span dir="auto">' . e($row['task_name']) . '</span>', |
|
| 115 | + view($module_name.'::admin/tasks-table-options', $task_options_params), |
|
| 116 | + view($module_name.'::components/yes-no-icons', ['yes' => $row['enabled']]), |
|
| 117 | + '<span dir="auto">'.e($row['task_name']).'</span>', |
|
| 118 | 118 | $row['last_run']->unix() === 0 ? |
| 119 | - view('components/datetime', ['timestamp' => $row['last_run']]) : |
|
| 120 | - view('components/datetime-diff', ['timestamp' => $row['last_run']]), |
|
| 121 | - view($module_name . '::components/yes-no-icons', ['yes' => $row['last_result']]), |
|
| 122 | - '<span dir="auto">' . e($row['frequency']->cascade()->forHumans()) . '</span>', |
|
| 119 | + view('components/datetime', ['timestamp' => $row['last_run']]) : view('components/datetime-diff', ['timestamp' => $row['last_run']]), |
|
| 120 | + view($module_name.'::components/yes-no-icons', ['yes' => $row['last_result']]), |
|
| 121 | + '<span dir="auto">'.e($row['frequency']->cascade()->forHumans()).'</span>', |
|
| 123 | 122 | $row['nb_occurrences'] > 0 ? I18N::number($row['nb_occurrences']) : I18N::translate('Unlimited'), |
| 124 | - view($module_name . '::components/yes-no-icons', [ |
|
| 123 | + view($module_name.'::components/yes-no-icons', [ |
|
| 125 | 124 | 'yes' => $row['is_running'], |
| 126 | 125 | 'text_yes' => I18N::translate('Running'), |
| 127 | 126 | 'text_no' => I18N::translate('Not running') |
| 128 | 127 | ]), |
| 129 | - view($module_name . '::admin/tasks-table-run', $task_run_params) |
|
| 128 | + view($module_name.'::admin/tasks-table-run', $task_run_params) |
|
| 130 | 129 | ]; |
| 131 | 130 | |
| 132 | 131 | return $datum; |
@@ -28,48 +28,48 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class TaskTrigger implements RequestHandlerInterface |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var AdminTasksModule|null $module |
|
| 33 | - */ |
|
| 34 | - private $module; |
|
| 31 | + /** |
|
| 32 | + * @var AdminTasksModule|null $module |
|
| 33 | + */ |
|
| 34 | + private $module; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var TaskScheduleService $taskschedules_service |
|
| 38 | - */ |
|
| 39 | - private $taskschedules_service; |
|
| 36 | + /** |
|
| 37 | + * @var TaskScheduleService $taskschedules_service |
|
| 38 | + */ |
|
| 39 | + private $taskschedules_service; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor for TaskTrigger request handler |
|
| 43 | - * @param ModuleService $module_service |
|
| 44 | - * @param TaskScheduleService $taskschedules_service |
|
| 45 | - */ |
|
| 46 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 47 | - { |
|
| 48 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 49 | - $this->taskschedules_service = $taskschedules_service; |
|
| 50 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor for TaskTrigger request handler |
|
| 43 | + * @param ModuleService $module_service |
|
| 44 | + * @param TaskScheduleService $taskschedules_service |
|
| 45 | + */ |
|
| 46 | + public function __construct(ModuleService $module_service, 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 | - $task_id = $request->getAttribute('task'); |
|
| 63 | - $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 64 | - $force_token = $request->getQueryParams()['force'] ?? ''; |
|
| 65 | - $force = $token == $force_token; |
|
| 62 | + $task_id = $request->getAttribute('task'); |
|
| 63 | + $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 64 | + $force_token = $request->getQueryParams()['force'] ?? ''; |
|
| 65 | + $force = $token == $force_token; |
|
| 66 | 66 | |
| 67 | - $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
| 67 | + $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
| 68 | 68 | |
| 69 | - foreach ($task_schedules as $task_schedule) { |
|
| 70 | - $this->taskschedules_service->run($task_schedule, $force); |
|
| 71 | - } |
|
| 69 | + foreach ($task_schedules as $task_schedule) { |
|
| 70 | + $this->taskschedules_service->run($task_schedule, $force); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return response(); |
|
| 74 | - } |
|
| 73 | + return response(); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -34,158 +34,158 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class TaskEditAction implements RequestHandlerInterface |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * @var AdminTasksModule|null $module |
|
| 39 | - */ |
|
| 40 | - private $module; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var TaskScheduleService $taskschedules_service |
|
| 44 | - */ |
|
| 45 | - private $taskschedules_service; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Constructor for TaskEditAction Request Handler |
|
| 49 | - * |
|
| 50 | - * @param ModuleService $module_service |
|
| 51 | - * @param TaskScheduleService $taskschedules_service |
|
| 52 | - */ |
|
| 53 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 54 | - { |
|
| 55 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 56 | - $this->taskschedules_service = $taskschedules_service; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 62 | - */ |
|
| 63 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 64 | - { |
|
| 65 | - $admin_config_route = route(AdminConfigPage::class); |
|
| 66 | - |
|
| 67 | - if ($this->module === null) { |
|
| 68 | - FlashMessages::addMessage( |
|
| 69 | - I18N::translate('The attached module could not be found.'), |
|
| 70 | - 'danger' |
|
| 71 | - ); |
|
| 72 | - return redirect($admin_config_route); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 76 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 77 | - |
|
| 78 | - if ($task_schedule === null) { |
|
| 79 | - FlashMessages::addMessage( |
|
| 80 | - I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
| 81 | - 'danger' |
|
| 82 | - ); |
|
| 83 | - return redirect($admin_config_route); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $success = $this->updateGeneralSettings($task_schedule, $request); |
|
| 87 | - $success = $success && $this->updateSpecificSettings($task_schedule, $request); |
|
| 88 | - |
|
| 89 | - if ($success) { |
|
| 90 | - FlashMessages::addMessage( |
|
| 91 | - I18N::translate('The scheduled task has been successfully updated'), |
|
| 92 | - 'success' |
|
| 93 | - ); |
|
| 94 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 95 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return redirect($admin_config_route); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Update general settings for the task, based on the request parameters |
|
| 103 | - * |
|
| 104 | - * @param TaskSchedule $task_schedule |
|
| 105 | - * @param ServerRequestInterface $request |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
| 109 | - { |
|
| 110 | - if ($this->module === null) { |
|
| 111 | - return false; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $params = (array) $request->getParsedBody(); |
|
| 115 | - |
|
| 116 | - $frequency = (int) $params['frequency']; |
|
| 117 | - if ($frequency > 0) { |
|
| 118 | - $task_schedule->setFrequency(CarbonInterval::minutes($frequency)); |
|
| 119 | - } else { |
|
| 120 | - FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format'), 'danger'); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $is_limited = (bool) $params['is_limited']; |
|
| 124 | - $nb_occur = (int) $params['nb_occur']; |
|
| 125 | - |
|
| 126 | - if ($is_limited) { |
|
| 127 | - if ($nb_occur > 0) { |
|
| 128 | - $task_schedule->setRemainingOccurences($nb_occur); |
|
| 129 | - } else { |
|
| 130 | - FlashMessages::addMessage( |
|
| 131 | - I18N::translate('The number of remaining occurences is not in a valid format'), |
|
| 132 | - 'danger' |
|
| 133 | - ); |
|
| 134 | - } |
|
| 135 | - } else { |
|
| 136 | - $task_schedule->setRemainingOccurences(0); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - try { |
|
| 140 | - $this->taskschedules_service->update($task_schedule); |
|
| 141 | - return true; |
|
| 142 | - } catch (Throwable $ex) { |
|
| 143 | - Log::addErrorLog( |
|
| 144 | - sprintf( |
|
| 145 | - 'Error while updating the Task Schedule "%s". Exception: %s', |
|
| 146 | - $task_schedule->id(), |
|
| 147 | - $ex->getMessage() |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task'), 'danger'); |
|
| 153 | - //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 154 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Update general settings for the task, based on the request parameters |
|
| 160 | - * |
|
| 161 | - * @param TaskSchedule $task_schedule |
|
| 162 | - * @param ServerRequestInterface $request |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - private function updateSpecificSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
| 166 | - { |
|
| 167 | - if ($this->module === null) { |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
| 172 | - if ($task === null || !($task instanceof ConfigurableTaskInterface)) { |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
| 177 | - if (!$task->updateConfig($request, $task_schedule)) { |
|
| 178 | - FlashMessages::addMessage( |
|
| 179 | - I18N::translate( |
|
| 180 | - 'An error occured while updating the specific settings of administrative task “%s”', |
|
| 181 | - $task->name() |
|
| 182 | - ), |
|
| 183 | - 'danger' |
|
| 184 | - ); |
|
| 185 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 186 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return true; |
|
| 190 | - } |
|
| 37 | + /** |
|
| 38 | + * @var AdminTasksModule|null $module |
|
| 39 | + */ |
|
| 40 | + private $module; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var TaskScheduleService $taskschedules_service |
|
| 44 | + */ |
|
| 45 | + private $taskschedules_service; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Constructor for TaskEditAction Request Handler |
|
| 49 | + * |
|
| 50 | + * @param ModuleService $module_service |
|
| 51 | + * @param TaskScheduleService $taskschedules_service |
|
| 52 | + */ |
|
| 53 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 54 | + { |
|
| 55 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 56 | + $this->taskschedules_service = $taskschedules_service; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 62 | + */ |
|
| 63 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 64 | + { |
|
| 65 | + $admin_config_route = route(AdminConfigPage::class); |
|
| 66 | + |
|
| 67 | + if ($this->module === null) { |
|
| 68 | + FlashMessages::addMessage( |
|
| 69 | + I18N::translate('The attached module could not be found.'), |
|
| 70 | + 'danger' |
|
| 71 | + ); |
|
| 72 | + return redirect($admin_config_route); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
| 76 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 77 | + |
|
| 78 | + if ($task_schedule === null) { |
|
| 79 | + FlashMessages::addMessage( |
|
| 80 | + I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
| 81 | + 'danger' |
|
| 82 | + ); |
|
| 83 | + return redirect($admin_config_route); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $success = $this->updateGeneralSettings($task_schedule, $request); |
|
| 87 | + $success = $success && $this->updateSpecificSettings($task_schedule, $request); |
|
| 88 | + |
|
| 89 | + if ($success) { |
|
| 90 | + FlashMessages::addMessage( |
|
| 91 | + I18N::translate('The scheduled task has been successfully updated'), |
|
| 92 | + 'success' |
|
| 93 | + ); |
|
| 94 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 95 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return redirect($admin_config_route); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Update general settings for the task, based on the request parameters |
|
| 103 | + * |
|
| 104 | + * @param TaskSchedule $task_schedule |
|
| 105 | + * @param ServerRequestInterface $request |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
| 109 | + { |
|
| 110 | + if ($this->module === null) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $params = (array) $request->getParsedBody(); |
|
| 115 | + |
|
| 116 | + $frequency = (int) $params['frequency']; |
|
| 117 | + if ($frequency > 0) { |
|
| 118 | + $task_schedule->setFrequency(CarbonInterval::minutes($frequency)); |
|
| 119 | + } else { |
|
| 120 | + FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format'), 'danger'); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $is_limited = (bool) $params['is_limited']; |
|
| 124 | + $nb_occur = (int) $params['nb_occur']; |
|
| 125 | + |
|
| 126 | + if ($is_limited) { |
|
| 127 | + if ($nb_occur > 0) { |
|
| 128 | + $task_schedule->setRemainingOccurences($nb_occur); |
|
| 129 | + } else { |
|
| 130 | + FlashMessages::addMessage( |
|
| 131 | + I18N::translate('The number of remaining occurences is not in a valid format'), |
|
| 132 | + 'danger' |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | + } else { |
|
| 136 | + $task_schedule->setRemainingOccurences(0); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + try { |
|
| 140 | + $this->taskschedules_service->update($task_schedule); |
|
| 141 | + return true; |
|
| 142 | + } catch (Throwable $ex) { |
|
| 143 | + Log::addErrorLog( |
|
| 144 | + sprintf( |
|
| 145 | + 'Error while updating the Task Schedule "%s". Exception: %s', |
|
| 146 | + $task_schedule->id(), |
|
| 147 | + $ex->getMessage() |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task'), 'danger'); |
|
| 153 | + //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 154 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Update general settings for the task, based on the request parameters |
|
| 160 | + * |
|
| 161 | + * @param TaskSchedule $task_schedule |
|
| 162 | + * @param ServerRequestInterface $request |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + private function updateSpecificSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
| 166 | + { |
|
| 167 | + if ($this->module === null) { |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
| 172 | + if ($task === null || !($task instanceof ConfigurableTaskInterface)) { |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
| 177 | + if (!$task->updateConfig($request, $task_schedule)) { |
|
| 178 | + FlashMessages::addMessage( |
|
| 179 | + I18N::translate( |
|
| 180 | + 'An error occured while updating the specific settings of administrative task “%s”', |
|
| 181 | + $task->name() |
|
| 182 | + ), |
|
| 183 | + 'danger' |
|
| 184 | + ); |
|
| 185 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 186 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return true; |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | return redirect($admin_config_route); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 75 | + $task_sched_id = (int)$request->getAttribute('task'); |
|
| 76 | 76 | $task_schedule = $this->taskschedules_service->find($task_sched_id); |
| 77 | 77 | |
| 78 | 78 | if ($task_schedule === null) { |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | 'success' |
| 93 | 93 | ); |
| 94 | 94 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 95 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 95 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” has been updated.'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return redirect($admin_config_route); |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | return false; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $params = (array) $request->getParsedBody(); |
|
| 114 | + $params = (array)$request->getParsedBody(); |
|
| 115 | 115 | |
| 116 | - $frequency = (int) $params['frequency']; |
|
| 116 | + $frequency = (int)$params['frequency']; |
|
| 117 | 117 | if ($frequency > 0) { |
| 118 | 118 | $task_schedule->setFrequency(CarbonInterval::minutes($frequency)); |
| 119 | 119 | } else { |
| 120 | 120 | FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format'), 'danger'); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $is_limited = (bool) $params['is_limited']; |
|
| 124 | - $nb_occur = (int) $params['nb_occur']; |
|
| 123 | + $is_limited = (bool)$params['is_limited']; |
|
| 124 | + $nb_occur = (int)$params['nb_occur']; |
|
| 125 | 125 | |
| 126 | 126 | if ($is_limited) { |
| 127 | 127 | if ($nb_occur > 0) { |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task'), 'danger'); |
| 153 | 153 | //@phpcs:ignore Generic.Files.LineLength.TooLong |
| 154 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
| 154 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” could not be updated. See error log.'); |
|
| 155 | 155 | return false; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | 'danger' |
| 184 | 184 | ); |
| 185 | 185 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 186 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
| 186 | + Log::addConfigurationLog('Module '.$this->module->title().' : AdminTask “'.$task->name().'” specific settings could not be updated. See error log.'); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | return true; |