@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration0 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // This migration has been superseded by migration 1. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // This migration has been superseded by migration 1. |
|
32 | + } |
|
33 | 33 | } |
@@ -25,46 +25,46 @@ |
||
25 | 25 | */ |
26 | 26 | class MapDefinitionsService |
27 | 27 | { |
28 | - private ModuleService $module_service; |
|
28 | + private ModuleService $module_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for MapDefinitionsService |
|
32 | - * |
|
33 | - * @param ModuleService $module_service |
|
34 | - */ |
|
35 | - public function __construct(ModuleService $module_service) |
|
36 | - { |
|
37 | - $this->module_service = $module_service; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor for MapDefinitionsService |
|
32 | + * |
|
33 | + * @param ModuleService $module_service |
|
34 | + */ |
|
35 | + public function __construct(ModuleService $module_service) |
|
36 | + { |
|
37 | + $this->module_service = $module_service; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Find a map definition by ID. |
|
42 | - * |
|
43 | - * @param string $id |
|
44 | - * @return MapDefinitionInterface|NULL |
|
45 | - */ |
|
46 | - public function find(string $id): ?MapDefinitionInterface |
|
47 | - { |
|
48 | - return $this->all()->get($id); |
|
49 | - } |
|
40 | + /** |
|
41 | + * Find a map definition by ID. |
|
42 | + * |
|
43 | + * @param string $id |
|
44 | + * @return MapDefinitionInterface|NULL |
|
45 | + */ |
|
46 | + public function find(string $id): ?MapDefinitionInterface |
|
47 | + { |
|
48 | + return $this->all()->get($id); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Get all map definitions available. |
|
53 | - * |
|
54 | - * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
55 | - * and the result is cached} |
|
56 | - * |
|
57 | - * @param bool $include_disabled |
|
58 | - * @return Collection<string, MapDefinitionInterface> |
|
59 | - */ |
|
60 | - public function all(bool $include_disabled = false): Collection |
|
61 | - { |
|
62 | - return Registry::cache()->array()->remember( |
|
63 | - 'maj-geodisp-maps-all', |
|
64 | - fn() => $this->module_service |
|
65 | - ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66 | - ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67 | - ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68 | - ); |
|
69 | - } |
|
51 | + /** |
|
52 | + * Get all map definitions available. |
|
53 | + * |
|
54 | + * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
55 | + * and the result is cached} |
|
56 | + * |
|
57 | + * @param bool $include_disabled |
|
58 | + * @return Collection<string, MapDefinitionInterface> |
|
59 | + */ |
|
60 | + public function all(bool $include_disabled = false): Collection |
|
61 | + { |
|
62 | + return Registry::cache()->array()->remember( |
|
63 | + 'maj-geodisp-maps-all', |
|
64 | + fn() => $this->module_service |
|
65 | + ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66 | + ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67 | + ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | fn() => $this->module_service |
65 | 65 | ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
66 | 66 | ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
67 | - ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
67 | + ->mapWithKeys(fn(MapDefinitionInterface $map) => [$map->id() => $map]) |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | } |
@@ -21,102 +21,102 @@ |
||
21 | 21 | */ |
22 | 22 | class PlacesReferenceTableService |
23 | 23 | { |
24 | - /** |
|
25 | - * Mapping format placeholder tags => table column names |
|
26 | - * @var array<string, string> |
|
27 | - */ |
|
28 | - private const COLUMN_MAPPING = [ |
|
29 | - 'name' => 'majgr_place_name', |
|
30 | - 'id' => 'majgr_place_admin_id', |
|
31 | - 'zip' => 'majgr_place_zip', |
|
32 | - 'gov' => 'majgr_place_gov_id', |
|
33 | - 'mls' => 'majgr_place_mls_id' |
|
34 | - ]; |
|
24 | + /** |
|
25 | + * Mapping format placeholder tags => table column names |
|
26 | + * @var array<string, string> |
|
27 | + */ |
|
28 | + private const COLUMN_MAPPING = [ |
|
29 | + 'name' => 'majgr_place_name', |
|
30 | + 'id' => 'majgr_place_admin_id', |
|
31 | + 'zip' => 'majgr_place_zip', |
|
32 | + 'gov' => 'majgr_place_gov_id', |
|
33 | + 'mls' => 'majgr_place_mls_id' |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the formatted target mapping value of a place defined by a source format. |
|
38 | - * |
|
39 | - * @param string $source |
|
40 | - * @param string $source_format |
|
41 | - * @param string $target_format |
|
42 | - * @return string|NULL |
|
43 | - */ |
|
44 | - public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | - { |
|
46 | - // Extract parts for the WHERE clause |
|
47 | - $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | - $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | - if ($source_parts === false) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $source_parts = array_map(function (string $part): string { |
|
53 | - if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | - return $this->columnName($column_id[1]); |
|
55 | - } |
|
56 | - return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | - }, array_filter($source_parts)); |
|
58 | - $source_parts[] = "'%'"; |
|
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
36 | + /** |
|
37 | + * Get the formatted target mapping value of a place defined by a source format. |
|
38 | + * |
|
39 | + * @param string $source |
|
40 | + * @param string $source_format |
|
41 | + * @param string $target_format |
|
42 | + * @return string|NULL |
|
43 | + */ |
|
44 | + public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | + { |
|
46 | + // Extract parts for the WHERE clause |
|
47 | + $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | + $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | + if ($source_parts === false) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $source_parts = array_map(function (string $part): string { |
|
53 | + if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | + return $this->columnName($column_id[1]); |
|
55 | + } |
|
56 | + return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | + }, array_filter($source_parts)); |
|
58 | + $source_parts[] = "'%'"; |
|
59 | + $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
60 | 60 | |
61 | - // Extract columns used in target |
|
62 | - $columns = []; |
|
63 | - if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | - $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | - } |
|
61 | + // Extract columns used in target |
|
62 | + $columns = []; |
|
63 | + if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | + $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | + } |
|
66 | 66 | |
67 | - // Get the mapping |
|
68 | - $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | - ->select($columns) |
|
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | - ->get(); |
|
67 | + // Get the mapping |
|
68 | + $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | + ->select($columns) |
|
70 | + ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | + ->get(); |
|
72 | 72 | |
73 | - // Format the output ID |
|
74 | - if ($rows->count() === 0) { |
|
75 | - return null; |
|
76 | - } |
|
73 | + // Format the output ID |
|
74 | + if ($rows->count() === 0) { |
|
75 | + return null; |
|
76 | + } |
|
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
79 | - if (count($columns_select) === 0) { |
|
80 | - return $target_format; |
|
81 | - } |
|
78 | + $mapping = (array) $rows->first(); |
|
79 | + if (count($columns_select) === 0) { |
|
80 | + return $target_format; |
|
81 | + } |
|
82 | 82 | |
83 | - return str_replace( |
|
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | - array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | - $target_format |
|
87 | - ); |
|
88 | - } |
|
83 | + return str_replace( |
|
84 | + array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | + array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | + $target_format |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get the column name for a format placeholder tag |
|
92 | - * |
|
93 | - * @param string $placeholder |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - private function columnName(string $placeholder): string |
|
97 | - { |
|
98 | - return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | - } |
|
90 | + /** |
|
91 | + * Get the column name for a format placeholder tag |
|
92 | + * |
|
93 | + * @param string $placeholder |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + private function columnName(string $placeholder): string |
|
97 | + { |
|
98 | + return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the placeholder tag for a column_name |
|
103 | - * |
|
104 | - * @param string $column_name |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - private function tagName(string $column_name): string |
|
108 | - { |
|
109 | - return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | - } |
|
101 | + /** |
|
102 | + * Get the placeholder tag for a column_name |
|
103 | + * |
|
104 | + * @param string $column_name |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + private function tagName(string $column_name): string |
|
108 | + { |
|
109 | + return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Sanitize string for use in a SQL query. |
|
114 | - * |
|
115 | - * @param string $string |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - private function sanitizeString(string $string): string |
|
119 | - { |
|
120 | - return DB::connection()->getPdo()->quote($string); |
|
121 | - } |
|
112 | + /** |
|
113 | + * Sanitize string for use in a SQL query. |
|
114 | + * |
|
115 | + * @param string $string |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + private function sanitizeString(string $string): string |
|
119 | + { |
|
120 | + return DB::connection()->getPdo()->quote($string); |
|
121 | + } |
|
122 | 122 | } |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | if ($source_parts === false) { |
50 | 50 | return null; |
51 | 51 | } |
52 | - $source_parts = array_map(function (string $part): string { |
|
52 | + $source_parts = array_map(function(string $part): string { |
|
53 | 53 | if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
54 | 54 | return $this->columnName($column_id[1]); |
55 | 55 | } |
56 | 56 | return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
57 | 57 | }, array_filter($source_parts)); |
58 | 58 | $source_parts[] = "'%'"; |
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
59 | + $concat_statement = 'CONCAT('.implode(', ', $source_parts).')'; |
|
60 | 60 | |
61 | 61 | // Extract columns used in target |
62 | 62 | $columns = []; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | // Get the mapping |
68 | 68 | $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
69 | 69 | ->select($columns) |
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
70 | + ->whereRaw($this->sanitizeString($source)." LIKE ".$concat_statement) |
|
71 | 71 | ->get(); |
72 | 72 | |
73 | 73 | // Format the output ID |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | return null; |
76 | 76 | } |
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
78 | + $mapping = (array)$rows->first(); |
|
79 | 79 | if (count($columns_select) === 0) { |
80 | 80 | return $target_format; |
81 | 81 | } |
82 | 82 | |
83 | 83 | return str_replace( |
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
84 | + array_map(fn($tag) => '{'.$tag.'}', $columns_select[1]), |
|
85 | 85 | array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
86 | 86 | $target_format |
87 | 87 | ); |
@@ -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 | /** |
@@ -26,211 +26,211 @@ |
||
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 | - * Create a copy of the view with new properties. |
|
72 | - * |
|
73 | - * @param bool $enabled |
|
74 | - * @param string $description |
|
75 | - * @param GeoAnalysisInterface $geoanalysis |
|
76 | - * @param int $depth |
|
77 | - * @param int $detailed_top_places |
|
78 | - * @param bool $use_flags |
|
79 | - * @return self |
|
80 | - */ |
|
81 | - public function with( |
|
82 | - bool $enabled, |
|
83 | - string $description, |
|
84 | - GeoAnalysisInterface $geoanalysis, |
|
85 | - int $depth, |
|
86 | - int $detailed_top_places = 0, |
|
87 | - bool $use_flags = false |
|
88 | - ): self { |
|
89 | - $new = clone $this; |
|
90 | - $new->enabled = $enabled; |
|
91 | - $new->description = $description; |
|
92 | - $new->geoanalysis = $geoanalysis; |
|
93 | - $new->depth = $depth; |
|
94 | - $new->detailed_top_places = $detailed_top_places; |
|
95 | - $new->use_flags = $use_flags; |
|
96 | - return $new; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Get the view ID |
|
101 | - * |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function id(): int |
|
105 | - { |
|
106 | - return $this->id; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get the view type for display |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - abstract public function type(): string; |
|
115 | - |
|
116 | - /** |
|
117 | - * Get the icon for the view type |
|
118 | - * |
|
119 | - * @param ModuleInterface $module |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - abstract public function icon(ModuleInterface $module): string; |
|
123 | - |
|
124 | - /** |
|
125 | - * Return the content of the global settings section of the config page |
|
126 | - * |
|
127 | - * @param ModuleInterface $module |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - abstract public function globalSettingsContent(ModuleInterface $module): string; |
|
131 | - |
|
132 | - /** |
|
133 | - * Return a view with global settings updated according to the view rules |
|
134 | - * |
|
135 | - * @param ServerRequestInterface $request |
|
136 | - * @return self |
|
137 | - */ |
|
138 | - abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self; |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns the content of the view global tab |
|
142 | - * |
|
143 | - * @param ModuleInterface $module |
|
144 | - * @param GeoAnalysisResult $result |
|
145 | - * @param array $params |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - abstract public function globalTabContent( |
|
149 | - ModuleInterface $module, |
|
150 | - GeoAnalysisResult $result, |
|
151 | - array $params |
|
152 | - ): string; |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the content of the view detailed tab |
|
156 | - * |
|
157 | - * @param ModuleInterface $module |
|
158 | - * @param Collection $results |
|
159 | - * @param array $params |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
163 | - { |
|
164 | - return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get the tree to which the view belongs |
|
169 | - * |
|
170 | - * @return Tree |
|
171 | - */ |
|
172 | - public function tree(): Tree |
|
173 | - { |
|
174 | - return $this->tree; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Get the description of the view |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function description(): string |
|
183 | - { |
|
184 | - return $this->description; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Get whether the view is enabled |
|
189 | - * |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - public function isEnabled(): bool |
|
193 | - { |
|
194 | - return $this->enabled; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Get the geographical dispersion analysis for the view |
|
199 | - * |
|
200 | - * @return GeoAnalysisInterface |
|
201 | - */ |
|
202 | - public function analysis(): GeoAnalysisInterface |
|
203 | - { |
|
204 | - return $this->geoanalysis; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get the place hierarchy depth for the view |
|
209 | - * |
|
210 | - * @return int |
|
211 | - */ |
|
212 | - public function placesDepth(): int |
|
213 | - { |
|
214 | - return $this->depth; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Get the number of places to display in the detailed tab |
|
219 | - * |
|
220 | - * @return int |
|
221 | - */ |
|
222 | - public function numberTopPlaces(): int |
|
223 | - { |
|
224 | - return $this->detailed_top_places; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Get whether flags should be used in the detailed tab |
|
229 | - * |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public function useFlags(): bool |
|
233 | - { |
|
234 | - return $this->use_flags; |
|
235 | - } |
|
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 | + * Create a copy of the view with new properties. |
|
72 | + * |
|
73 | + * @param bool $enabled |
|
74 | + * @param string $description |
|
75 | + * @param GeoAnalysisInterface $geoanalysis |
|
76 | + * @param int $depth |
|
77 | + * @param int $detailed_top_places |
|
78 | + * @param bool $use_flags |
|
79 | + * @return self |
|
80 | + */ |
|
81 | + public function with( |
|
82 | + bool $enabled, |
|
83 | + string $description, |
|
84 | + GeoAnalysisInterface $geoanalysis, |
|
85 | + int $depth, |
|
86 | + int $detailed_top_places = 0, |
|
87 | + bool $use_flags = false |
|
88 | + ): self { |
|
89 | + $new = clone $this; |
|
90 | + $new->enabled = $enabled; |
|
91 | + $new->description = $description; |
|
92 | + $new->geoanalysis = $geoanalysis; |
|
93 | + $new->depth = $depth; |
|
94 | + $new->detailed_top_places = $detailed_top_places; |
|
95 | + $new->use_flags = $use_flags; |
|
96 | + return $new; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Get the view ID |
|
101 | + * |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function id(): int |
|
105 | + { |
|
106 | + return $this->id; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get the view type for display |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + abstract public function type(): string; |
|
115 | + |
|
116 | + /** |
|
117 | + * Get the icon for the view type |
|
118 | + * |
|
119 | + * @param ModuleInterface $module |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + abstract public function icon(ModuleInterface $module): string; |
|
123 | + |
|
124 | + /** |
|
125 | + * Return the content of the global settings section of the config page |
|
126 | + * |
|
127 | + * @param ModuleInterface $module |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + abstract public function globalSettingsContent(ModuleInterface $module): string; |
|
131 | + |
|
132 | + /** |
|
133 | + * Return a view with global settings updated according to the view rules |
|
134 | + * |
|
135 | + * @param ServerRequestInterface $request |
|
136 | + * @return self |
|
137 | + */ |
|
138 | + abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self; |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns the content of the view global tab |
|
142 | + * |
|
143 | + * @param ModuleInterface $module |
|
144 | + * @param GeoAnalysisResult $result |
|
145 | + * @param array $params |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + abstract public function globalTabContent( |
|
149 | + ModuleInterface $module, |
|
150 | + GeoAnalysisResult $result, |
|
151 | + array $params |
|
152 | + ): string; |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the content of the view detailed tab |
|
156 | + * |
|
157 | + * @param ModuleInterface $module |
|
158 | + * @param Collection $results |
|
159 | + * @param array $params |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
163 | + { |
|
164 | + return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get the tree to which the view belongs |
|
169 | + * |
|
170 | + * @return Tree |
|
171 | + */ |
|
172 | + public function tree(): Tree |
|
173 | + { |
|
174 | + return $this->tree; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Get the description of the view |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function description(): string |
|
183 | + { |
|
184 | + return $this->description; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Get whether the view is enabled |
|
189 | + * |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + public function isEnabled(): bool |
|
193 | + { |
|
194 | + return $this->enabled; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Get the geographical dispersion analysis for the view |
|
199 | + * |
|
200 | + * @return GeoAnalysisInterface |
|
201 | + */ |
|
202 | + public function analysis(): GeoAnalysisInterface |
|
203 | + { |
|
204 | + return $this->geoanalysis; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get the place hierarchy depth for the view |
|
209 | + * |
|
210 | + * @return int |
|
211 | + */ |
|
212 | + public function placesDepth(): int |
|
213 | + { |
|
214 | + return $this->depth; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Get the number of places to display in the detailed tab |
|
219 | + * |
|
220 | + * @return int |
|
221 | + */ |
|
222 | + public function numberTopPlaces(): int |
|
223 | + { |
|
224 | + return $this->detailed_top_places; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Get whether flags should be used in the detailed tab |
|
229 | + * |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public function useFlags(): bool |
|
233 | + { |
|
234 | + return $this->use_flags; |
|
235 | + } |
|
236 | 236 | } |
@@ -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; |
@@ -30,75 +30,75 @@ |
||
30 | 30 | class TaskStatusAction implements RequestHandlerInterface |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * @var AdminTasksModule|null $module |
|
35 | - */ |
|
36 | - private $module; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var TaskScheduleService $taskschedules_service |
|
40 | - */ |
|
41 | - private $taskschedules_service; |
|
42 | - |
|
43 | - /** |
|
44 | - * Constructor for TaskStatusAction Request Handler |
|
45 | - * |
|
46 | - * @param ModuleService $module_service |
|
47 | - * @param TaskScheduleService $taskschedules_service |
|
48 | - */ |
|
49 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
50 | - { |
|
51 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
52 | - $this->taskschedules_service = $taskschedules_service; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
58 | - */ |
|
59 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | - { |
|
61 | - $admin_config_route = route(AdminConfigPage::class); |
|
62 | - |
|
63 | - if ($this->module === null) { |
|
64 | - FlashMessages::addMessage( |
|
65 | - I18N::translate('The attached module could not be found.'), |
|
66 | - 'danger' |
|
67 | - ); |
|
68 | - return redirect($admin_config_route); |
|
69 | - } |
|
70 | - |
|
71 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
72 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
73 | - |
|
74 | - $admin_config_route = route(AdminConfigPage::class); |
|
75 | - |
|
76 | - if ($task_schedule === null) { |
|
77 | - FlashMessages::addMessage( |
|
78 | - I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
79 | - 'danger' |
|
80 | - ); |
|
81 | - return redirect($admin_config_route); |
|
82 | - } |
|
83 | - |
|
84 | - ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
85 | - |
|
86 | - if ($this->taskschedules_service->update($task_schedule) > 0) { |
|
87 | - FlashMessages::addMessage( |
|
88 | - I18N::translate('The scheduled task has been successfully updated'), |
|
89 | - 'success' |
|
90 | - ); |
|
91 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
92 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
93 | - } else { |
|
94 | - FlashMessages::addMessage( |
|
95 | - I18N::translate('An error occured while updating the scheduled task'), |
|
96 | - 'danger' |
|
97 | - ); |
|
98 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
99 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
100 | - } |
|
101 | - |
|
102 | - return redirect($admin_config_route); |
|
103 | - } |
|
33 | + /** |
|
34 | + * @var AdminTasksModule|null $module |
|
35 | + */ |
|
36 | + private $module; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var TaskScheduleService $taskschedules_service |
|
40 | + */ |
|
41 | + private $taskschedules_service; |
|
42 | + |
|
43 | + /** |
|
44 | + * Constructor for TaskStatusAction Request Handler |
|
45 | + * |
|
46 | + * @param ModuleService $module_service |
|
47 | + * @param TaskScheduleService $taskschedules_service |
|
48 | + */ |
|
49 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
50 | + { |
|
51 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
52 | + $this->taskschedules_service = $taskschedules_service; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
58 | + */ |
|
59 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | + { |
|
61 | + $admin_config_route = route(AdminConfigPage::class); |
|
62 | + |
|
63 | + if ($this->module === null) { |
|
64 | + FlashMessages::addMessage( |
|
65 | + I18N::translate('The attached module could not be found.'), |
|
66 | + 'danger' |
|
67 | + ); |
|
68 | + return redirect($admin_config_route); |
|
69 | + } |
|
70 | + |
|
71 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
72 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
73 | + |
|
74 | + $admin_config_route = route(AdminConfigPage::class); |
|
75 | + |
|
76 | + if ($task_schedule === null) { |
|
77 | + FlashMessages::addMessage( |
|
78 | + I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
79 | + 'danger' |
|
80 | + ); |
|
81 | + return redirect($admin_config_route); |
|
82 | + } |
|
83 | + |
|
84 | + ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
85 | + |
|
86 | + if ($this->taskschedules_service->update($task_schedule) > 0) { |
|
87 | + FlashMessages::addMessage( |
|
88 | + I18N::translate('The scheduled task has been successfully updated'), |
|
89 | + 'success' |
|
90 | + ); |
|
91 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
92 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
93 | + } else { |
|
94 | + FlashMessages::addMessage( |
|
95 | + I18N::translate('An error occured while updating the scheduled task'), |
|
96 | + 'danger' |
|
97 | + ); |
|
98 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
99 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
100 | + } |
|
101 | + |
|
102 | + return redirect($admin_config_route); |
|
103 | + } |
|
104 | 104 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | return redirect($admin_config_route); |
69 | 69 | } |
70 | 70 | |
71 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
71 | + $task_sched_id = (int)$request->getAttribute('task'); |
|
72 | 72 | $task_schedule = $this->taskschedules_service->find($task_sched_id); |
73 | 73 | |
74 | 74 | $admin_config_route = route(AdminConfigPage::class); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | return redirect($admin_config_route); |
82 | 82 | } |
83 | 83 | |
84 | - ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
84 | + ((bool)$request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
85 | 85 | |
86 | 86 | if ($this->taskschedules_service->update($task_schedule) > 0) { |
87 | 87 | FlashMessages::addMessage( |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | 'success' |
90 | 90 | ); |
91 | 91 | //phpcs:ignore Generic.Files.LineLength.TooLong |
92 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
92 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” has been updated.'); |
|
93 | 93 | } else { |
94 | 94 | FlashMessages::addMessage( |
95 | 95 | I18N::translate('An error occured while updating the scheduled task'), |
96 | 96 | 'danger' |
97 | 97 | ); |
98 | 98 | //phpcs:ignore Generic.Files.LineLength.TooLong |
99 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
99 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” could not be updated. See error log.'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | return redirect($admin_config_route); |
@@ -39,188 +39,188 @@ |
||
39 | 39 | */ |
40 | 40 | class HealthCheckEmailTask implements TaskInterface, ConfigurableTaskInterface |
41 | 41 | { |
42 | - /** |
|
43 | - * Name of the Tree preference to check if the task is enabled for that tree |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var AdminTasksModule|null $module |
|
50 | - */ |
|
51 | - private $module; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var HealthCheckService $healthcheck_service; |
|
55 | - */ |
|
56 | - private $healthcheck_service; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var EmailService $email_service; |
|
60 | - */ |
|
61 | - private $email_service; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var UserService $user_service |
|
65 | - */ |
|
66 | - private $user_service; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var TreeService $tree_service |
|
70 | - */ |
|
71 | - private $tree_service; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var UpgradeService $upgrade_service |
|
75 | - */ |
|
76 | - private $upgrade_service; |
|
77 | - |
|
78 | - /** |
|
79 | - * Constructor for HealthCheckTask |
|
80 | - * |
|
81 | - * @param ModuleService $module_service |
|
82 | - * @param HealthCheckService $healthcheck_service |
|
83 | - * @param EmailService $email_service |
|
84 | - * @param UserService $user_service |
|
85 | - * @param TreeService $tree_service |
|
86 | - * @param UpgradeService $upgrade_service |
|
87 | - */ |
|
88 | - public function __construct( |
|
89 | - ModuleService $module_service, |
|
90 | - HealthCheckService $healthcheck_service, |
|
91 | - EmailService $email_service, |
|
92 | - UserService $user_service, |
|
93 | - TreeService $tree_service, |
|
94 | - UpgradeService $upgrade_service |
|
95 | - ) { |
|
96 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
97 | - $this->healthcheck_service = $healthcheck_service; |
|
98 | - $this->email_service = $email_service; |
|
99 | - $this->user_service = $user_service; |
|
100 | - $this->tree_service = $tree_service; |
|
101 | - $this->upgrade_service = $upgrade_service; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * {@inheritDoc} |
|
107 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::name() |
|
108 | - */ |
|
109 | - public function name(): string |
|
110 | - { |
|
111 | - return I18N::translate('Healthcheck Email'); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * {@inheritDoc} |
|
116 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::defaultFrequency() |
|
117 | - */ |
|
118 | - public function defaultFrequency(): int |
|
119 | - { |
|
120 | - return 10080; // = 1 week = 7 * 24 * 60 min |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * {@inheritDoc} |
|
125 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::run() |
|
126 | - */ |
|
127 | - public function run(TaskSchedule $task_schedule): bool |
|
128 | - { |
|
129 | - if ($this->module === null) { |
|
130 | - return false; |
|
131 | - } |
|
132 | - |
|
133 | - $res = true; |
|
134 | - |
|
135 | - // Compute the number of days to compute |
|
136 | - $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
|
137 | - //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
138 | - $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
|
139 | - $nb_days = (int) $interval->ceilDay()->totalDays; |
|
140 | - |
|
141 | - $view_params_site = [ |
|
142 | - 'nb_days' => $nb_days, |
|
143 | - 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
144 | - 'latest_version' => $this->upgrade_service->latestVersion(), |
|
145 | - 'download_url' => $this->upgrade_service->downloadUrl(), |
|
146 | - 'all_users' => $this->user_service->all(), |
|
147 | - 'unapproved' => $this->user_service->unapproved(), |
|
148 | - 'unverified' => $this->user_service->unverified(), |
|
149 | - ]; |
|
150 | - |
|
151 | - foreach ($this->tree_service->all() as $tree) { |
|
152 | - /** @var Tree $tree */ |
|
153 | - |
|
154 | - if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
155 | - continue; |
|
156 | - } |
|
157 | - |
|
158 | - $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
159 | - if ($webmaster === null) { |
|
160 | - continue; |
|
161 | - } |
|
162 | - I18N::init($webmaster->getPreference('language')); |
|
163 | - |
|
164 | - $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
165 | - $nb_errors = $error_logs->sum('nblogs'); |
|
166 | - |
|
167 | - $view_params = array_merge($view_params_site, [ |
|
168 | - 'tree' => $tree, |
|
169 | - 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
170 | - 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
171 | - 'error_logs' => $error_logs, |
|
172 | - 'nb_errors' => $nb_errors |
|
173 | - ]); |
|
174 | - |
|
175 | - $res = $res && $this->email_service->send( |
|
176 | - new TreeUser($tree), |
|
177 | - $webmaster, |
|
178 | - new NoReplyUser(), |
|
179 | - I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
180 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
181 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - return $res; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * {@inheritDoc} |
|
190 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::configView() |
|
191 | - */ |
|
192 | - public function configView(ServerRequestInterface $request): string |
|
193 | - { |
|
194 | - return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
195 | - 'all_trees' => $this->tree_service->all() |
|
196 | - ]); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * {@inheritDoc} |
|
201 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::updateConfig() |
|
202 | - */ |
|
203 | - public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
204 | - { |
|
205 | - try { |
|
206 | - $params = (array) $request->getParsedBody(); |
|
207 | - |
|
208 | - foreach ($this->tree_service->all() as $tree) { |
|
209 | - if (Auth::isManager($tree)) { |
|
210 | - $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false); |
|
211 | - $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
212 | - } |
|
213 | - } |
|
214 | - return true; |
|
215 | - } catch (Throwable $ex) { |
|
216 | - Log::addErrorLog( |
|
217 | - sprintf( |
|
218 | - 'Error while updating the Task schedule "%s". Exception: %s', |
|
219 | - $task_schedule->id(), |
|
220 | - $ex->getMessage() |
|
221 | - ) |
|
222 | - ); |
|
223 | - } |
|
224 | - return false; |
|
225 | - } |
|
42 | + /** |
|
43 | + * Name of the Tree preference to check if the task is enabled for that tree |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var AdminTasksModule|null $module |
|
50 | + */ |
|
51 | + private $module; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var HealthCheckService $healthcheck_service; |
|
55 | + */ |
|
56 | + private $healthcheck_service; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var EmailService $email_service; |
|
60 | + */ |
|
61 | + private $email_service; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var UserService $user_service |
|
65 | + */ |
|
66 | + private $user_service; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var TreeService $tree_service |
|
70 | + */ |
|
71 | + private $tree_service; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var UpgradeService $upgrade_service |
|
75 | + */ |
|
76 | + private $upgrade_service; |
|
77 | + |
|
78 | + /** |
|
79 | + * Constructor for HealthCheckTask |
|
80 | + * |
|
81 | + * @param ModuleService $module_service |
|
82 | + * @param HealthCheckService $healthcheck_service |
|
83 | + * @param EmailService $email_service |
|
84 | + * @param UserService $user_service |
|
85 | + * @param TreeService $tree_service |
|
86 | + * @param UpgradeService $upgrade_service |
|
87 | + */ |
|
88 | + public function __construct( |
|
89 | + ModuleService $module_service, |
|
90 | + HealthCheckService $healthcheck_service, |
|
91 | + EmailService $email_service, |
|
92 | + UserService $user_service, |
|
93 | + TreeService $tree_service, |
|
94 | + UpgradeService $upgrade_service |
|
95 | + ) { |
|
96 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
97 | + $this->healthcheck_service = $healthcheck_service; |
|
98 | + $this->email_service = $email_service; |
|
99 | + $this->user_service = $user_service; |
|
100 | + $this->tree_service = $tree_service; |
|
101 | + $this->upgrade_service = $upgrade_service; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * {@inheritDoc} |
|
107 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::name() |
|
108 | + */ |
|
109 | + public function name(): string |
|
110 | + { |
|
111 | + return I18N::translate('Healthcheck Email'); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * {@inheritDoc} |
|
116 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::defaultFrequency() |
|
117 | + */ |
|
118 | + public function defaultFrequency(): int |
|
119 | + { |
|
120 | + return 10080; // = 1 week = 7 * 24 * 60 min |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * {@inheritDoc} |
|
125 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::run() |
|
126 | + */ |
|
127 | + public function run(TaskSchedule $task_schedule): bool |
|
128 | + { |
|
129 | + if ($this->module === null) { |
|
130 | + return false; |
|
131 | + } |
|
132 | + |
|
133 | + $res = true; |
|
134 | + |
|
135 | + // Compute the number of days to compute |
|
136 | + $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
|
137 | + //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
138 | + $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
|
139 | + $nb_days = (int) $interval->ceilDay()->totalDays; |
|
140 | + |
|
141 | + $view_params_site = [ |
|
142 | + 'nb_days' => $nb_days, |
|
143 | + 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
144 | + 'latest_version' => $this->upgrade_service->latestVersion(), |
|
145 | + 'download_url' => $this->upgrade_service->downloadUrl(), |
|
146 | + 'all_users' => $this->user_service->all(), |
|
147 | + 'unapproved' => $this->user_service->unapproved(), |
|
148 | + 'unverified' => $this->user_service->unverified(), |
|
149 | + ]; |
|
150 | + |
|
151 | + foreach ($this->tree_service->all() as $tree) { |
|
152 | + /** @var Tree $tree */ |
|
153 | + |
|
154 | + if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
155 | + continue; |
|
156 | + } |
|
157 | + |
|
158 | + $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
159 | + if ($webmaster === null) { |
|
160 | + continue; |
|
161 | + } |
|
162 | + I18N::init($webmaster->getPreference('language')); |
|
163 | + |
|
164 | + $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
165 | + $nb_errors = $error_logs->sum('nblogs'); |
|
166 | + |
|
167 | + $view_params = array_merge($view_params_site, [ |
|
168 | + 'tree' => $tree, |
|
169 | + 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
170 | + 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
171 | + 'error_logs' => $error_logs, |
|
172 | + 'nb_errors' => $nb_errors |
|
173 | + ]); |
|
174 | + |
|
175 | + $res = $res && $this->email_service->send( |
|
176 | + new TreeUser($tree), |
|
177 | + $webmaster, |
|
178 | + new NoReplyUser(), |
|
179 | + I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
180 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
181 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + return $res; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * {@inheritDoc} |
|
190 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::configView() |
|
191 | + */ |
|
192 | + public function configView(ServerRequestInterface $request): string |
|
193 | + { |
|
194 | + return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
195 | + 'all_trees' => $this->tree_service->all() |
|
196 | + ]); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * {@inheritDoc} |
|
201 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::updateConfig() |
|
202 | + */ |
|
203 | + public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
204 | + { |
|
205 | + try { |
|
206 | + $params = (array) $request->getParsedBody(); |
|
207 | + |
|
208 | + foreach ($this->tree_service->all() as $tree) { |
|
209 | + if (Auth::isManager($tree)) { |
|
210 | + $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false); |
|
211 | + $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
212 | + } |
|
213 | + } |
|
214 | + return true; |
|
215 | + } catch (Throwable $ex) { |
|
216 | + Log::addErrorLog( |
|
217 | + sprintf( |
|
218 | + 'Error while updating the Task schedule "%s". Exception: %s', |
|
219 | + $task_schedule->id(), |
|
220 | + $ex->getMessage() |
|
221 | + ) |
|
222 | + ); |
|
223 | + } |
|
224 | + return false; |
|
225 | + } |
|
226 | 226 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
137 | 137 | //@phpcs:ignore Generic.Files.LineLength.TooLong |
138 | 138 | $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
139 | - $nb_days = (int) $interval->ceilDay()->totalDays; |
|
139 | + $nb_days = (int)$interval->ceilDay()->totalDays; |
|
140 | 140 | |
141 | 141 | $view_params_site = [ |
142 | 142 | 'nb_days' => $nb_days, |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | continue; |
156 | 156 | } |
157 | 157 | |
158 | - $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
158 | + $webmaster = $this->user_service->find((int)$tree->getPreference('WEBMASTER_USER_ID')); |
|
159 | 159 | if ($webmaster === null) { |
160 | 160 | continue; |
161 | 161 | } |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | new TreeUser($tree), |
177 | 177 | $webmaster, |
178 | 178 | new NoReplyUser(), |
179 | - I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
180 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
181 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
179 | + I18N::translate('Health Check Report').' - '.I18N::translate('Tree %s', $tree->name()), |
|
180 | + view($this->module->name().'::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
181 | + view($this->module->name().'::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
182 | 182 | ); |
183 | 183 | } |
184 | 184 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function configView(ServerRequestInterface $request): string |
193 | 193 | { |
194 | - return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
194 | + return $this->module === null ? '' : view($this->module->name().'::tasks/healthcheck/config', [ |
|
195 | 195 | 'all_trees' => $this->tree_service->all() |
196 | 196 | ]); |
197 | 197 | } |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
204 | 204 | { |
205 | 205 | try { |
206 | - $params = (array) $request->getParsedBody(); |
|
206 | + $params = (array)$request->getParsedBody(); |
|
207 | 207 | |
208 | 208 | foreach ($this->tree_service->all() as $tree) { |
209 | 209 | if (Auth::isManager($tree)) { |
210 | - $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false); |
|
210 | + $tree_enabled = (bool)($params['HEALTHCHECK_ENABLED_'.$tree->id()] ?? false); |
|
211 | 211 | $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
212 | 212 | } |
213 | 213 | } |