@@ -125,6 +125,6 @@ |
||
125 | 125 | */ |
126 | 126 | private function stringLengthEstimate(int $text_length, int $font_size): int |
127 | 127 | { |
128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
128 | + return $text_length * (int)ceil(($font_size + 2) * 0.5); |
|
129 | 129 | } |
130 | 130 | } |
@@ -19,112 +19,112 @@ |
||
19 | 19 | */ |
20 | 20 | class Watermark |
21 | 21 | { |
22 | - /** |
|
23 | - * Default font color for watermarks |
|
24 | - * @var string DEFAULT_COLOR |
|
25 | - * */ |
|
26 | - public const DEFAULT_COLOR = '#4D6DF3'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Default maximum font size for watermarks |
|
30 | - * @var int DEFAULT_SIZE |
|
31 | - * */ |
|
32 | - public const DEFAULT_SIZE = 18; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $text |
|
36 | - */ |
|
37 | - private $text; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string $color; |
|
41 | - */ |
|
42 | - private $color; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @var int $size |
|
47 | - */ |
|
48 | - private $size; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for Watermark data class |
|
52 | - * |
|
53 | - * @param string $text |
|
54 | - * @param string $color |
|
55 | - * @param int $size |
|
56 | - */ |
|
57 | - public function __construct(string $text, string $color, int $size) |
|
58 | - { |
|
59 | - $this->text = $text; |
|
60 | - $this->color = $color; |
|
61 | - $this->size = $size; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Get the watermark text. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function text(): string |
|
70 | - { |
|
71 | - return $this->text; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the watermark font color. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function color(): string |
|
80 | - { |
|
81 | - return $this->color; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get the watermark maximum font size. |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public function size(): int |
|
89 | - { |
|
90 | - return $this->size; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Return an estimate of the size in pixels of the watermark text length. |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function textLengthEstimate(): int |
|
99 | - { |
|
100 | - return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Decrease the font size if necessary, based on the image width. |
|
105 | - * |
|
106 | - * @param int $width |
|
107 | - */ |
|
108 | - public function adjustSize(int $width): void |
|
109 | - { |
|
110 | - $len = mb_strlen($this->text); |
|
111 | - while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
112 | - $this->size--; |
|
113 | - if ($this->size === 2) { |
|
114 | - return; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Return an estimate of the size in pixels of a text in a specified font size. |
|
121 | - * |
|
122 | - * @param int $text_length |
|
123 | - * @param int $font_size |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - private function stringLengthEstimate(int $text_length, int $font_size): int |
|
127 | - { |
|
128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
129 | - } |
|
22 | + /** |
|
23 | + * Default font color for watermarks |
|
24 | + * @var string DEFAULT_COLOR |
|
25 | + * */ |
|
26 | + public const DEFAULT_COLOR = '#4D6DF3'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Default maximum font size for watermarks |
|
30 | + * @var int DEFAULT_SIZE |
|
31 | + * */ |
|
32 | + public const DEFAULT_SIZE = 18; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $text |
|
36 | + */ |
|
37 | + private $text; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string $color; |
|
41 | + */ |
|
42 | + private $color; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @var int $size |
|
47 | + */ |
|
48 | + private $size; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for Watermark data class |
|
52 | + * |
|
53 | + * @param string $text |
|
54 | + * @param string $color |
|
55 | + * @param int $size |
|
56 | + */ |
|
57 | + public function __construct(string $text, string $color, int $size) |
|
58 | + { |
|
59 | + $this->text = $text; |
|
60 | + $this->color = $color; |
|
61 | + $this->size = $size; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Get the watermark text. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function text(): string |
|
70 | + { |
|
71 | + return $this->text; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the watermark font color. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function color(): string |
|
80 | + { |
|
81 | + return $this->color; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get the watermark maximum font size. |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public function size(): int |
|
89 | + { |
|
90 | + return $this->size; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Return an estimate of the size in pixels of the watermark text length. |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function textLengthEstimate(): int |
|
99 | + { |
|
100 | + return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Decrease the font size if necessary, based on the image width. |
|
105 | + * |
|
106 | + * @param int $width |
|
107 | + */ |
|
108 | + public function adjustSize(int $width): void |
|
109 | + { |
|
110 | + $len = mb_strlen($this->text); |
|
111 | + while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
112 | + $this->size--; |
|
113 | + if ($this->size === 2) { |
|
114 | + return; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Return an estimate of the size in pixels of a text in a specified font size. |
|
121 | + * |
|
122 | + * @param int $text_length |
|
123 | + * @param int $font_size |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + private function stringLengthEstimate(int $text_length, int $font_size): int |
|
127 | + { |
|
128 | + return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
129 | + } |
|
130 | 130 | } |
@@ -202,11 +202,11 @@ |
||
202 | 202 | { |
203 | 203 | $sort_prefix = ''; |
204 | 204 | if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
205 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
205 | + $sort_prefix = implode('_', array_map(function($match) { |
|
206 | 206 | return $match[1]; |
207 | - }, $matches)) . '_'; |
|
207 | + }, $matches)).'_'; |
|
208 | 208 | } |
209 | - return $sort_prefix . $this->description(); |
|
209 | + return $sort_prefix.$this->description(); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -25,191 +25,191 @@ |
||
25 | 25 | */ |
26 | 26 | class Certificate |
27 | 27 | { |
28 | - /** |
|
29 | - * Pattern to extract information from a file name. |
|
30 | - * Specific to the author's workflow. |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | - |
|
35 | - private Tree $tree; |
|
36 | - private string $path; |
|
37 | - private ?string $city = null; |
|
38 | - private ?string $basename = null; |
|
39 | - private ?string $filename = null; |
|
40 | - private ?string $extension = null; |
|
41 | - private ?string $type = null; |
|
42 | - private ?string $description = null; |
|
43 | - private ?Date $date = null; |
|
44 | - |
|
45 | - /** |
|
46 | - * Contructor for Certificate |
|
47 | - * |
|
48 | - * @param Tree $tree |
|
49 | - * @param string $path |
|
50 | - */ |
|
51 | - public function __construct(Tree $tree, string $path) |
|
52 | - { |
|
53 | - $this->tree = $tree; |
|
54 | - $this->path = $path; |
|
55 | - $this->extractDataFromPath($path); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | - * Logic specific to the author. |
|
61 | - * |
|
62 | - * @param string $path |
|
63 | - */ |
|
64 | - protected function extractDataFromPath(string $path): void |
|
65 | - { |
|
66 | - $path_parts = pathinfo($this->gedcomPath()); |
|
67 | - $this->city = $path_parts['dirname'] ?? ''; |
|
68 | - $this->basename = $path_parts['basename']; |
|
69 | - $this->filename = $path_parts['filename']; |
|
70 | - $this->extension = strtoupper($path_parts['extension'] ?? ''); |
|
71 | - |
|
72 | - if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | - $this->type = $match['type']; |
|
74 | - $this->description = $match['descr']; |
|
75 | - |
|
76 | - $month_date = DateTime::createFromFormat('m', $match['month']); |
|
77 | - $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
78 | - |
|
79 | - $this->date = new Date(sprintf('%s %s %s', $match['day'], $month, $match['year'])); |
|
80 | - } else { |
|
81 | - $this->description = $this->filename; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Get the family tree of the certificate |
|
87 | - * |
|
88 | - * @return Tree |
|
89 | - */ |
|
90 | - public function tree(): Tree |
|
91 | - { |
|
92 | - return $this->tree; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the path of the certificate in the file system. |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function path(): string |
|
101 | - { |
|
102 | - return $this->path; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * The the path of the certificate, in a Gedcom canonical form. |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function gedcomPath(): string |
|
111 | - { |
|
112 | - return str_replace('\\', '/', $this->path); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the certificate name. |
|
117 | - * |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function name(): string |
|
121 | - { |
|
122 | - return $this->filename ?? ''; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get the certificate file name. |
|
127 | - * |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function filename(): string |
|
131 | - { |
|
132 | - return $this->basename ?? ''; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Get the certificate's city (the first level folder). |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function city(): string |
|
141 | - { |
|
142 | - return $this->city ?? ''; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Get the certificate's date. Extracted from the file name. |
|
147 | - * |
|
148 | - * @return Date |
|
149 | - */ |
|
150 | - public function date(): Date |
|
151 | - { |
|
152 | - return $this->date ?? new Date(''); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Get the certificate's type. Extracted from the file name. |
|
157 | - * |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function type(): string |
|
161 | - { |
|
162 | - return $this->type ?? ''; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the certificate's description. Extracted from the file name. |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function description(): string |
|
170 | - { |
|
171 | - return $this->description ?? ''; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Get the certificate's description to be used for sorting. |
|
176 | - * This is based on surnames (at least 3 letters) found in the file name. |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function sortDescription(): string |
|
181 | - { |
|
182 | - $sort_prefix = ''; |
|
183 | - if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
184 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
185 | - return $match[1]; |
|
186 | - }, $matches)) . '_'; |
|
187 | - } |
|
188 | - return $sort_prefix . $this->description(); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the certificate's MIME type. |
|
193 | - * |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public function mimeType(): string |
|
197 | - { |
|
198 | - return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Get the base parameters to be used in url referencing the certificate. |
|
203 | - * |
|
204 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
205 | - * @return array{tree: string, cid: mixed} |
|
206 | - */ |
|
207 | - public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
208 | - { |
|
209 | - $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
210 | - return [ |
|
211 | - 'tree' => $this->tree->name(), |
|
212 | - 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
213 | - ]; |
|
214 | - } |
|
28 | + /** |
|
29 | + * Pattern to extract information from a file name. |
|
30 | + * Specific to the author's workflow. |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | + |
|
35 | + private Tree $tree; |
|
36 | + private string $path; |
|
37 | + private ?string $city = null; |
|
38 | + private ?string $basename = null; |
|
39 | + private ?string $filename = null; |
|
40 | + private ?string $extension = null; |
|
41 | + private ?string $type = null; |
|
42 | + private ?string $description = null; |
|
43 | + private ?Date $date = null; |
|
44 | + |
|
45 | + /** |
|
46 | + * Contructor for Certificate |
|
47 | + * |
|
48 | + * @param Tree $tree |
|
49 | + * @param string $path |
|
50 | + */ |
|
51 | + public function __construct(Tree $tree, string $path) |
|
52 | + { |
|
53 | + $this->tree = $tree; |
|
54 | + $this->path = $path; |
|
55 | + $this->extractDataFromPath($path); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | + * Logic specific to the author. |
|
61 | + * |
|
62 | + * @param string $path |
|
63 | + */ |
|
64 | + protected function extractDataFromPath(string $path): void |
|
65 | + { |
|
66 | + $path_parts = pathinfo($this->gedcomPath()); |
|
67 | + $this->city = $path_parts['dirname'] ?? ''; |
|
68 | + $this->basename = $path_parts['basename']; |
|
69 | + $this->filename = $path_parts['filename']; |
|
70 | + $this->extension = strtoupper($path_parts['extension'] ?? ''); |
|
71 | + |
|
72 | + if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | + $this->type = $match['type']; |
|
74 | + $this->description = $match['descr']; |
|
75 | + |
|
76 | + $month_date = DateTime::createFromFormat('m', $match['month']); |
|
77 | + $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
78 | + |
|
79 | + $this->date = new Date(sprintf('%s %s %s', $match['day'], $month, $match['year'])); |
|
80 | + } else { |
|
81 | + $this->description = $this->filename; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Get the family tree of the certificate |
|
87 | + * |
|
88 | + * @return Tree |
|
89 | + */ |
|
90 | + public function tree(): Tree |
|
91 | + { |
|
92 | + return $this->tree; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the path of the certificate in the file system. |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function path(): string |
|
101 | + { |
|
102 | + return $this->path; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * The the path of the certificate, in a Gedcom canonical form. |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function gedcomPath(): string |
|
111 | + { |
|
112 | + return str_replace('\\', '/', $this->path); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the certificate name. |
|
117 | + * |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function name(): string |
|
121 | + { |
|
122 | + return $this->filename ?? ''; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get the certificate file name. |
|
127 | + * |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function filename(): string |
|
131 | + { |
|
132 | + return $this->basename ?? ''; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Get the certificate's city (the first level folder). |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function city(): string |
|
141 | + { |
|
142 | + return $this->city ?? ''; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Get the certificate's date. Extracted from the file name. |
|
147 | + * |
|
148 | + * @return Date |
|
149 | + */ |
|
150 | + public function date(): Date |
|
151 | + { |
|
152 | + return $this->date ?? new Date(''); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Get the certificate's type. Extracted from the file name. |
|
157 | + * |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function type(): string |
|
161 | + { |
|
162 | + return $this->type ?? ''; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the certificate's description. Extracted from the file name. |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function description(): string |
|
170 | + { |
|
171 | + return $this->description ?? ''; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Get the certificate's description to be used for sorting. |
|
176 | + * This is based on surnames (at least 3 letters) found in the file name. |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function sortDescription(): string |
|
181 | + { |
|
182 | + $sort_prefix = ''; |
|
183 | + if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
184 | + $sort_prefix = implode('_', array_map(function ($match) { |
|
185 | + return $match[1]; |
|
186 | + }, $matches)) . '_'; |
|
187 | + } |
|
188 | + return $sort_prefix . $this->description(); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the certificate's MIME type. |
|
193 | + * |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public function mimeType(): string |
|
197 | + { |
|
198 | + return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Get the base parameters to be used in url referencing the certificate. |
|
203 | + * |
|
204 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
205 | + * @return array{tree: string, cid: mixed} |
|
206 | + */ |
|
207 | + public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
208 | + { |
|
209 | + $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
210 | + return [ |
|
211 | + 'tree' => $this->tree->name(), |
|
212 | + 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
213 | + ]; |
|
214 | + } |
|
215 | 215 | } |
@@ -69,11 +69,11 @@ |
||
69 | 69 | { |
70 | 70 | list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
71 | 71 | |
72 | - $cities = array_map(function (string $item): array { |
|
72 | + $cities = array_map(function(string $item): array { |
|
73 | 73 | return [$this->url_obfuscator_service->obfuscate($item), $item]; |
74 | 74 | }, $this->certif_filesystem->cities($tree)); |
75 | 75 | |
76 | - return view($this->module->name() . '::components/edit-certificate', [ |
|
76 | + return view($this->module->name().'::components/edit-certificate', [ |
|
77 | 77 | 'module_name' => $this->module->name(), |
78 | 78 | 'tree' => $tree, |
79 | 79 | 'id' => $id, |
@@ -28,61 +28,61 @@ |
||
28 | 28 | */ |
29 | 29 | class SourceCertificate extends AbstractElement |
30 | 30 | { |
31 | - protected CertificatesModule $module; |
|
32 | - protected CertificateFilesystemService $certif_filesystem; |
|
33 | - protected UrlObfuscatorService $url_obfuscator_service; |
|
31 | + protected CertificatesModule $module; |
|
32 | + protected CertificateFilesystemService $certif_filesystem; |
|
33 | + protected UrlObfuscatorService $url_obfuscator_service; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor for SourceCertificate element |
|
37 | - * |
|
38 | - * @param string $label |
|
39 | - * @param CertificatesModule $module |
|
40 | - * @param CertificateFilesystemService $certif_filesystem |
|
41 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - string $label, |
|
45 | - CertificatesModule $module, |
|
46 | - CertificateFilesystemService $certif_filesystem = null, |
|
47 | - UrlObfuscatorService $url_obfuscator_service = null |
|
48 | - ) { |
|
49 | - parent::__construct($label, null); |
|
50 | - $this->module = $module; |
|
51 | - $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
|
52 | - $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
53 | - } |
|
35 | + /** |
|
36 | + * Constructor for SourceCertificate element |
|
37 | + * |
|
38 | + * @param string $label |
|
39 | + * @param CertificatesModule $module |
|
40 | + * @param CertificateFilesystemService $certif_filesystem |
|
41 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + string $label, |
|
45 | + CertificatesModule $module, |
|
46 | + CertificateFilesystemService $certif_filesystem = null, |
|
47 | + UrlObfuscatorService $url_obfuscator_service = null |
|
48 | + ) { |
|
49 | + parent::__construct($label, null); |
|
50 | + $this->module = $module; |
|
51 | + $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
|
52 | + $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
58 | - */ |
|
59 | - public function canonical(string $value): string |
|
60 | - { |
|
61 | - return strtr($value, '\\', '/'); |
|
62 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
58 | + */ |
|
59 | + public function canonical(string $value): string |
|
60 | + { |
|
61 | + return strtr($value, '\\', '/'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
|
67 | - */ |
|
68 | - public function edit(string $id, string $name, string $value, Tree $tree): string |
|
69 | - { |
|
70 | - list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
|
67 | + */ |
|
68 | + public function edit(string $id, string $name, string $value, Tree $tree): string |
|
69 | + { |
|
70 | + list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
|
71 | 71 | |
72 | - $cities = array_map(function (string $item): array { |
|
73 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
74 | - }, $this->certif_filesystem->cities($tree)); |
|
72 | + $cities = array_map(function (string $item): array { |
|
73 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
74 | + }, $this->certif_filesystem->cities($tree)); |
|
75 | 75 | |
76 | - return view($this->module->name() . '::components/edit-certificate', [ |
|
77 | - 'module_name' => $this->module->name(), |
|
78 | - 'tree' => $tree, |
|
79 | - 'id' => $id, |
|
80 | - 'name' => $name, |
|
81 | - 'cities' => $cities, |
|
82 | - 'value' => $this->canonical($value), |
|
83 | - 'value_city' => $city, |
|
84 | - 'value_file' => $file, |
|
85 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
86 | - ]); |
|
87 | - } |
|
76 | + return view($this->module->name() . '::components/edit-certificate', [ |
|
77 | + 'module_name' => $this->module->name(), |
|
78 | + 'tree' => $tree, |
|
79 | + 'id' => $id, |
|
80 | + 'name' => $name, |
|
81 | + 'cities' => $cities, |
|
82 | + 'value' => $this->canonical($value), |
|
83 | + 'value_city' => $city, |
|
84 | + 'value_file' => $file, |
|
85 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
86 | + ]); |
|
87 | + } |
|
88 | 88 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | // Clean up previous admin tasks table if it exists |
35 | 35 | DB::schema()->dropIfExists('maj_admintasks'); |
36 | 36 | |
37 | - DB::schema()->create('maj_admintasks', static function (Blueprint $table): void { |
|
37 | + DB::schema()->create('maj_admintasks', static function(Blueprint $table): void { |
|
38 | 38 | |
39 | 39 | $table->increments('majat_id'); |
40 | 40 | $table->string('majat_task_id', 32)->unique(); |
@@ -25,31 +25,31 @@ |
||
25 | 25 | */ |
26 | 26 | class Migration1 implements MigrationInterface |
27 | 27 | { |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
31 | - */ |
|
32 | - public function upgrade(): void |
|
33 | - { |
|
34 | - $in_transaction = DB::connection()->getPdo()->inTransaction(); |
|
35 | - |
|
36 | - // Clean up previous admin tasks table if it exists |
|
37 | - DB::schema()->dropIfExists('maj_admintasks'); |
|
38 | - |
|
39 | - DB::schema()->create('maj_admintasks', static function (Blueprint $table): void { |
|
40 | - |
|
41 | - $table->increments('majat_id'); |
|
42 | - $table->string('majat_task_id', 32)->unique(); |
|
43 | - $table->enum('majat_status', ['enabled', 'disabled'])->default('disabled'); |
|
44 | - $table->dateTime('majat_last_run')->default(Carbon::createFromTimestampUTC(0)); |
|
45 | - $table->boolean('majat_last_result')->default(true); |
|
46 | - $table->integer('majat_frequency')->default(10080); |
|
47 | - $table->smallInteger('majat_nb_occur')->default(0); |
|
48 | - $table->boolean('majat_running')->default(false); |
|
49 | - }); |
|
50 | - |
|
51 | - if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) { |
|
52 | - DB::connection()->beginTransaction(); |
|
53 | - } |
|
54 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
31 | + */ |
|
32 | + public function upgrade(): void |
|
33 | + { |
|
34 | + $in_transaction = DB::connection()->getPdo()->inTransaction(); |
|
35 | + |
|
36 | + // Clean up previous admin tasks table if it exists |
|
37 | + DB::schema()->dropIfExists('maj_admintasks'); |
|
38 | + |
|
39 | + DB::schema()->create('maj_admintasks', static function (Blueprint $table): void { |
|
40 | + |
|
41 | + $table->increments('majat_id'); |
|
42 | + $table->string('majat_task_id', 32)->unique(); |
|
43 | + $table->enum('majat_status', ['enabled', 'disabled'])->default('disabled'); |
|
44 | + $table->dateTime('majat_last_run')->default(Carbon::createFromTimestampUTC(0)); |
|
45 | + $table->boolean('majat_last_result')->default(true); |
|
46 | + $table->integer('majat_frequency')->default(10080); |
|
47 | + $table->smallInteger('majat_nb_occur')->default(0); |
|
48 | + $table->boolean('majat_running')->default(false); |
|
49 | + }); |
|
50 | + |
|
51 | + if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) { |
|
52 | + DB::connection()->beginTransaction(); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
@@ -20,32 +20,32 @@ |
||
20 | 20 | */ |
21 | 21 | class TokenService |
22 | 22 | { |
23 | - /** |
|
24 | - * Returns a random-ish generated token of a given size |
|
25 | - * |
|
26 | - * @param int $length Length of the token, default to 32 |
|
27 | - * @return string Random token |
|
28 | - */ |
|
29 | - public function generateRandomToken(int $length = 32): string |
|
30 | - { |
|
31 | - $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
|
32 | - $len_chars = count($chars); |
|
33 | - $token = ''; |
|
34 | - |
|
35 | - for ($i = 0; $i < $length; $i++) { |
|
36 | - $token .= $chars[mt_rand(0, $len_chars - 1)]; |
|
37 | - } |
|
38 | - |
|
39 | - # Number of 32 char chunks |
|
40 | - $chunks = ceil(strlen($token) / 32); |
|
41 | - $md5token = ''; |
|
42 | - |
|
43 | - # Run each chunk through md5 |
|
44 | - for ($i = 1; $i <= $chunks; $i++) { |
|
45 | - $md5token .= md5(substr($token, $i * 32 - 32, 32)); |
|
46 | - } |
|
47 | - |
|
48 | - # Trim the token to the required length |
|
49 | - return substr($md5token, 0, $length); |
|
50 | - } |
|
23 | + /** |
|
24 | + * Returns a random-ish generated token of a given size |
|
25 | + * |
|
26 | + * @param int $length Length of the token, default to 32 |
|
27 | + * @return string Random token |
|
28 | + */ |
|
29 | + public function generateRandomToken(int $length = 32): string |
|
30 | + { |
|
31 | + $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
|
32 | + $len_chars = count($chars); |
|
33 | + $token = ''; |
|
34 | + |
|
35 | + for ($i = 0; $i < $length; $i++) { |
|
36 | + $token .= $chars[mt_rand(0, $len_chars - 1)]; |
|
37 | + } |
|
38 | + |
|
39 | + # Number of 32 char chunks |
|
40 | + $chunks = ceil(strlen($token) / 32); |
|
41 | + $md5token = ''; |
|
42 | + |
|
43 | + # Run each chunk through md5 |
|
44 | + for ($i = 1; $i <= $chunks; $i++) { |
|
45 | + $md5token .= md5(substr($token, $i * 32 - 32, 32)); |
|
46 | + } |
|
47 | + |
|
48 | + # Trim the token to the required length |
|
49 | + return substr($md5token, 0, $length); |
|
50 | + } |
|
51 | 51 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | public function changesByRecordType(Tree $tree, int $nb_days): Collection |
80 | 80 | { |
81 | 81 | return DB::table('change') |
82 | - ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void { |
|
82 | + ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function(JoinClause $join) use ($tree): void { |
|
83 | 83 | |
84 | 84 | $join->on('change.xref', '=', 'gedrecords.ged_id') |
85 | 85 | ->where('change.gedcom_id', '=', $tree->id()); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | new Expression('MAX(log_time) AS lastoccurred') |
116 | 116 | ) |
117 | 117 | ->where('log_type', '=', 'error') |
118 | - ->where(function (Builder $query) use ($tree): void { |
|
118 | + ->where(function(Builder $query) use ($tree): void { |
|
119 | 119 | $query->where('gedcom_id', '=', $tree->id()) |
120 | 120 | ->orWhereNull('gedcom_id'); |
121 | 121 | }) |
@@ -27,101 +27,101 @@ |
||
27 | 27 | */ |
28 | 28 | class HealthCheckService |
29 | 29 | { |
30 | - /** |
|
31 | - * Returns a query collating all gedcom records, for use in other queries |
|
32 | - * |
|
33 | - * @param Tree $tree |
|
34 | - * @return Builder |
|
35 | - */ |
|
36 | - private function allGedcomRecords(Tree $tree): Builder |
|
37 | - { |
|
38 | - return DB::table('individuals') |
|
39 | - ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id()) |
|
40 | - ->unionAll(DB::table('families') |
|
41 | - ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id())) |
|
42 | - ->unionAll(DB::table('sources') |
|
43 | - ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id())) |
|
44 | - ->unionAll(DB::table('media') |
|
45 | - ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id())) |
|
46 | - ->unionAll(DB::table('other') |
|
47 | - ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id())); |
|
48 | - } |
|
30 | + /** |
|
31 | + * Returns a query collating all gedcom records, for use in other queries |
|
32 | + * |
|
33 | + * @param Tree $tree |
|
34 | + * @return Builder |
|
35 | + */ |
|
36 | + private function allGedcomRecords(Tree $tree): Builder |
|
37 | + { |
|
38 | + return DB::table('individuals') |
|
39 | + ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id()) |
|
40 | + ->unionAll(DB::table('families') |
|
41 | + ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id())) |
|
42 | + ->unionAll(DB::table('sources') |
|
43 | + ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id())) |
|
44 | + ->unionAll(DB::table('media') |
|
45 | + ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id())) |
|
46 | + ->unionAll(DB::table('other') |
|
47 | + ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id())); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the count of gedcom records by type in a Tree, as a keyed Collection. |
|
52 | - * |
|
53 | - * Collection output: |
|
54 | - * - Key : gedcom record type |
|
55 | - * - Value: count of records |
|
56 | - * |
|
57 | - * @param Tree $tree |
|
58 | - * @return Collection<string, int> |
|
59 | - */ |
|
60 | - public function countByRecordType(Tree $tree): Collection |
|
61 | - { |
|
62 | - return DB::query() |
|
63 | - ->fromSub($this->allGedcomRecords($tree), 'gedrecords') |
|
64 | - ->select('ged_type', new Expression('COUNT(ged_id) AS total')) |
|
65 | - ->groupBy('ged_type') |
|
66 | - ->pluck('total', 'ged_type'); |
|
67 | - } |
|
50 | + /** |
|
51 | + * Returns the count of gedcom records by type in a Tree, as a keyed Collection. |
|
52 | + * |
|
53 | + * Collection output: |
|
54 | + * - Key : gedcom record type |
|
55 | + * - Value: count of records |
|
56 | + * |
|
57 | + * @param Tree $tree |
|
58 | + * @return Collection<string, int> |
|
59 | + */ |
|
60 | + public function countByRecordType(Tree $tree): Collection |
|
61 | + { |
|
62 | + return DB::query() |
|
63 | + ->fromSub($this->allGedcomRecords($tree), 'gedrecords') |
|
64 | + ->select('ged_type', new Expression('COUNT(ged_id) AS total')) |
|
65 | + ->groupBy('ged_type') |
|
66 | + ->pluck('total', 'ged_type'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection. |
|
71 | - * |
|
72 | - * Collection output: |
|
73 | - * - Key : gedcom record type |
|
74 | - * - Value: count of changes |
|
75 | - * |
|
76 | - * @param Tree $tree |
|
77 | - * @return Collection<string, int> |
|
78 | - */ |
|
79 | - public function changesByRecordType(Tree $tree, int $nb_days): Collection |
|
80 | - { |
|
81 | - return DB::table('change') |
|
82 | - ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void { |
|
69 | + /** |
|
70 | + * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection. |
|
71 | + * |
|
72 | + * Collection output: |
|
73 | + * - Key : gedcom record type |
|
74 | + * - Value: count of changes |
|
75 | + * |
|
76 | + * @param Tree $tree |
|
77 | + * @return Collection<string, int> |
|
78 | + */ |
|
79 | + public function changesByRecordType(Tree $tree, int $nb_days): Collection |
|
80 | + { |
|
81 | + return DB::table('change') |
|
82 | + ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void { |
|
83 | 83 | |
84 | - $join->on('change.xref', '=', 'gedrecords.ged_id') |
|
85 | - ->where('change.gedcom_id', '=', $tree->id()); |
|
86 | - }) |
|
87 | - ->select('ged_type AS type', new Expression('COUNT(change_id) AS count')) |
|
88 | - ->where('change.status', '', 'accepted') |
|
89 | - ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days)) |
|
90 | - ->groupBy('ged_type') |
|
91 | - ->pluck('total', 'ged_type'); |
|
92 | - } |
|
84 | + $join->on('change.xref', '=', 'gedrecords.ged_id') |
|
85 | + ->where('change.gedcom_id', '=', $tree->id()); |
|
86 | + }) |
|
87 | + ->select('ged_type AS type', new Expression('COUNT(change_id) AS count')) |
|
88 | + ->where('change.status', '', 'accepted') |
|
89 | + ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days)) |
|
90 | + ->groupBy('ged_type') |
|
91 | + ->pluck('total', 'ged_type'); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection. |
|
96 | - * |
|
97 | - * Collection output: |
|
98 | - * - Value: stdClass object |
|
99 | - * - log message: Error log message |
|
100 | - * - type: 'site' if no associated Tree, the Tree ID otherwise |
|
101 | - * - nblogs: The number of occurrence of the same error message |
|
102 | - * - lastoccurred: Date/time of the last occurrence of the error message |
|
103 | - * |
|
104 | - * @param Tree $tree |
|
105 | - * @param int $nb_days |
|
106 | - * @return Collection<\stdClass> |
|
107 | - */ |
|
108 | - public function errorLogs(Tree $tree, int $nb_days): Collection |
|
109 | - { |
|
110 | - return DB::table('log') |
|
111 | - ->select( |
|
112 | - 'log_message', |
|
113 | - new Expression("IFNULL(gedcom_id, 'site') as type"), |
|
114 | - new Expression('COUNT(log_id) AS nblogs'), |
|
115 | - new Expression('MAX(log_time) AS lastoccurred') |
|
116 | - ) |
|
117 | - ->where('log_type', '=', 'error') |
|
118 | - ->where(function (Builder $query) use ($tree): void { |
|
119 | - $query->where('gedcom_id', '=', $tree->id()) |
|
120 | - ->orWhereNull('gedcom_id'); |
|
121 | - }) |
|
122 | - ->where('log_time', '>=', Carbon::now()->subDays($nb_days)) |
|
123 | - ->groupBy('log_message', 'gedcom_id') |
|
124 | - ->orderByDesc('lastoccurred') |
|
125 | - ->get(); |
|
126 | - } |
|
94 | + /** |
|
95 | + * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection. |
|
96 | + * |
|
97 | + * Collection output: |
|
98 | + * - Value: stdClass object |
|
99 | + * - log message: Error log message |
|
100 | + * - type: 'site' if no associated Tree, the Tree ID otherwise |
|
101 | + * - nblogs: The number of occurrence of the same error message |
|
102 | + * - lastoccurred: Date/time of the last occurrence of the error message |
|
103 | + * |
|
104 | + * @param Tree $tree |
|
105 | + * @param int $nb_days |
|
106 | + * @return Collection<\stdClass> |
|
107 | + */ |
|
108 | + public function errorLogs(Tree $tree, int $nb_days): Collection |
|
109 | + { |
|
110 | + return DB::table('log') |
|
111 | + ->select( |
|
112 | + 'log_message', |
|
113 | + new Expression("IFNULL(gedcom_id, 'site') as type"), |
|
114 | + new Expression('COUNT(log_id) AS nblogs'), |
|
115 | + new Expression('MAX(log_time) AS lastoccurred') |
|
116 | + ) |
|
117 | + ->where('log_type', '=', 'error') |
|
118 | + ->where(function (Builder $query) use ($tree): void { |
|
119 | + $query->where('gedcom_id', '=', $tree->id()) |
|
120 | + ->orWhereNull('gedcom_id'); |
|
121 | + }) |
|
122 | + ->where('log_time', '>=', Carbon::now()->subDays($nb_days)) |
|
123 | + ->groupBy('log_message', 'gedcom_id') |
|
124 | + ->orderByDesc('lastoccurred') |
|
125 | + ->get(); |
|
126 | + } |
|
127 | 127 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | //How to update the database schema for this module |
56 | 56 | private const SCHEMA_TARGET_VERSION = 2; |
57 | 57 | private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
58 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
58 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * {@inheritDoc} |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function loadRoutes(Map $router): void |
97 | 97 | { |
98 | - $router->attach('', '', static function (Map $router): void { |
|
98 | + $router->attach('', '', static function(Map $router): void { |
|
99 | 99 | |
100 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
100 | + $router->attach('', '/module-maj/admintasks', static function(Map $router): void { |
|
101 | 101 | $router->tokens(['enable' => '[01]']); |
102 | 102 | |
103 | - $router->attach('', '/admin', static function (Map $router): void { |
|
103 | + $router->attach('', '/admin', static function(Map $router): void { |
|
104 | 104 | |
105 | 105 | $router->extras([ |
106 | 106 | 'middleware' => [ |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | ]); |
110 | 110 | $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
111 | 111 | |
112 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
112 | + $router->attach('', '/tasks', static function(Map $router): void { |
|
113 | 113 | |
114 | 114 | $router->get(TasksList::class, '', TasksList::class); |
115 | 115 | $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function bodyContent(): string |
153 | 153 | { |
154 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
154 | + return view($this->name().'::snippet', ['url' => route(TaskTrigger::class)]); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -41,127 +41,127 @@ |
||
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 | - $router->tokens(['enable' => '[01]']); |
|
102 | - |
|
103 | - $router->attach('', '/admin', static function (Map $router): void { |
|
104 | - |
|
105 | - $router->extras([ |
|
106 | - 'middleware' => [ |
|
107 | - AuthAdministrator::class, |
|
108 | - ], |
|
109 | - ]); |
|
110 | - $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
111 | - |
|
112 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
113 | - |
|
114 | - $router->get(TasksList::class, '', TasksList::class); |
|
115 | - $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
116 | - $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
117 | - $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
118 | - }); |
|
119 | - }); |
|
120 | - |
|
121 | - $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
122 | - ->allows(RequestMethodInterface::METHOD_POST); |
|
123 | - |
|
124 | - $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
125 | - ->extras(['middleware' => [AuthAdministrator::class]]); |
|
126 | - }); |
|
127 | - }); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * {@inheritDoc} |
|
132 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
133 | - */ |
|
134 | - public function customModuleVersion(): string |
|
135 | - { |
|
136 | - return '2.1.3-v.1'; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * {@inheritDoc} |
|
141 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
142 | - */ |
|
143 | - public function getConfigLink(): string |
|
144 | - { |
|
145 | - return route(AdminConfigPage::class); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * {@inheritDoc} |
|
150 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
151 | - */ |
|
152 | - public function bodyContent(): string |
|
153 | - { |
|
154 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * {@inheritDoc} |
|
159 | - * @see ModuleTasksProviderInterface::listTasks() |
|
160 | - */ |
|
161 | - public function listTasks(): array |
|
162 | - { |
|
163 | - return [ |
|
164 | - 'maj-healthcheck' => HealthCheckEmailTask::class |
|
165 | - ]; |
|
166 | - } |
|
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 | + $router->tokens(['enable' => '[01]']); |
|
102 | + |
|
103 | + $router->attach('', '/admin', static function (Map $router): void { |
|
104 | + |
|
105 | + $router->extras([ |
|
106 | + 'middleware' => [ |
|
107 | + AuthAdministrator::class, |
|
108 | + ], |
|
109 | + ]); |
|
110 | + $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
111 | + |
|
112 | + $router->attach('', '/tasks', static function (Map $router): void { |
|
113 | + |
|
114 | + $router->get(TasksList::class, '', TasksList::class); |
|
115 | + $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
116 | + $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
117 | + $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
118 | + }); |
|
119 | + }); |
|
120 | + |
|
121 | + $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
122 | + ->allows(RequestMethodInterface::METHOD_POST); |
|
123 | + |
|
124 | + $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
125 | + ->extras(['middleware' => [AuthAdministrator::class]]); |
|
126 | + }); |
|
127 | + }); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * {@inheritDoc} |
|
132 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
133 | + */ |
|
134 | + public function customModuleVersion(): string |
|
135 | + { |
|
136 | + return '2.1.3-v.1'; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * {@inheritDoc} |
|
141 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
142 | + */ |
|
143 | + public function getConfigLink(): string |
|
144 | + { |
|
145 | + return route(AdminConfigPage::class); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * {@inheritDoc} |
|
150 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
151 | + */ |
|
152 | + public function bodyContent(): string |
|
153 | + { |
|
154 | + return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * {@inheritDoc} |
|
159 | + * @see ModuleTasksProviderInterface::listTasks() |
|
160 | + */ |
|
161 | + public function listTasks(): array |
|
162 | + { |
|
163 | + return [ |
|
164 | + 'maj-healthcheck' => HealthCheckEmailTask::class |
|
165 | + ]; |
|
166 | + } |
|
167 | 167 | } |
@@ -28,15 +28,15 @@ discard block |
||
28 | 28 | */ |
29 | 29 | function hook(string $hook_interface, callable $apply, $default = null) |
30 | 30 | { |
31 | - try { |
|
32 | - $hook_collector = app(HookServiceInterface::class)->use($hook_interface); |
|
33 | - if ($hook_collector !== null) { |
|
34 | - return $apply($hook_collector); |
|
35 | - } |
|
36 | - } catch (BindingResolutionException $ex) { |
|
37 | - } |
|
31 | + try { |
|
32 | + $hook_collector = app(HookServiceInterface::class)->use($hook_interface); |
|
33 | + if ($hook_collector !== null) { |
|
34 | + return $apply($hook_collector); |
|
35 | + } |
|
36 | + } catch (BindingResolutionException $ex) { |
|
37 | + } |
|
38 | 38 | |
39 | - return $default; |
|
39 | + return $default; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,5 +48,5 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function columnIndex(int $initial_index, Collection $new_column_indexes): int |
50 | 50 | { |
51 | - return $initial_index + $new_column_indexes->filter(fn(int $i) => $i <= $initial_index)->count(); |
|
51 | + return $initial_index + $new_column_indexes->filter(fn(int $i) => $i <= $initial_index)->count(); |
|
52 | 52 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | */ |
58 | 58 | public function name(): string |
59 | 59 | { |
60 | - return $this->module->name() . '-' . |
|
60 | + return $this->module->name().'-'. |
|
61 | 61 | mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
62 | 62 | } |
63 | 63 |
@@ -27,77 +27,77 @@ |
||
27 | 27 | */ |
28 | 28 | abstract class AbstractHookCollector implements HookCollectorInterface, HookInterface |
29 | 29 | { |
30 | - /** @var Collection<int, array<THook>> $hooks */ |
|
31 | - protected Collection $hooks; |
|
30 | + /** @var Collection<int, array<THook>> $hooks */ |
|
31 | + protected Collection $hooks; |
|
32 | 32 | |
33 | - private ModuleInterface $module; |
|
33 | + private ModuleInterface $module; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor for AbstractHookCollector |
|
37 | - * |
|
38 | - * @param ModuleInterface $module |
|
39 | - */ |
|
40 | - public function __construct(ModuleInterface $module) |
|
41 | - { |
|
42 | - $this->hooks = new Collection(); |
|
43 | - $this->module = $module; |
|
44 | - } |
|
35 | + /** |
|
36 | + * Constructor for AbstractHookCollector |
|
37 | + * |
|
38 | + * @param ModuleInterface $module |
|
39 | + */ |
|
40 | + public function __construct(ModuleInterface $module) |
|
41 | + { |
|
42 | + $this->hooks = new Collection(); |
|
43 | + $this->module = $module; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
49 | - */ |
|
50 | - public function module(): ModuleInterface |
|
51 | - { |
|
52 | - return $this->module; |
|
53 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
49 | + */ |
|
50 | + public function module(): ModuleInterface |
|
51 | + { |
|
52 | + return $this->module; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name() |
|
58 | - */ |
|
59 | - public function name(): string |
|
60 | - { |
|
61 | - return $this->module->name() . '-' . |
|
62 | - mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
|
63 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name() |
|
58 | + */ |
|
59 | + public function name(): string |
|
60 | + { |
|
61 | + return $this->module->name() . '-' . |
|
62 | + mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * {@inheritDoc} |
|
67 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title() |
|
68 | - */ |
|
69 | - abstract public function title(): string; |
|
65 | + /** |
|
66 | + * {@inheritDoc} |
|
67 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title() |
|
68 | + */ |
|
69 | + abstract public function title(): string; |
|
70 | 70 | |
71 | - /** |
|
72 | - * {@inheritDoc} |
|
73 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description() |
|
74 | - */ |
|
75 | - abstract public function description(): string; |
|
71 | + /** |
|
72 | + * {@inheritDoc} |
|
73 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description() |
|
74 | + */ |
|
75 | + abstract public function description(): string; |
|
76 | 76 | |
77 | - /** |
|
78 | - * {@inheritDoc} |
|
79 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface() |
|
80 | - */ |
|
81 | - abstract public function hookInterface(): string; |
|
77 | + /** |
|
78 | + * {@inheritDoc} |
|
79 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface() |
|
80 | + */ |
|
81 | + abstract public function hookInterface(): string; |
|
82 | 82 | |
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register() |
|
86 | - */ |
|
87 | - public function register(HookInterface $hook_instance, int $order): void |
|
88 | - { |
|
89 | - $this->hooks->put($order, array_merge($this->hooks->get($order, []), [$hook_instance])); |
|
90 | - } |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register() |
|
86 | + */ |
|
87 | + public function register(HookInterface $hook_instance, int $order): void |
|
88 | + { |
|
89 | + $this->hooks->put($order, array_merge($this->hooks->get($order, []), [$hook_instance])); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * {@inheritDoc} |
|
94 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks() |
|
95 | - * |
|
96 | - * @return Collection<THook> |
|
97 | - */ |
|
98 | - public function hooks(): Collection |
|
99 | - { |
|
100 | - /** @var Collection<THook> */ |
|
101 | - return $this->hooks->sortKeys()->flatten(); |
|
102 | - } |
|
92 | + /** |
|
93 | + * {@inheritDoc} |
|
94 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks() |
|
95 | + * |
|
96 | + * @return Collection<THook> |
|
97 | + */ |
|
98 | + public function hooks(): Collection |
|
99 | + { |
|
100 | + /** @var Collection<THook> */ |
|
101 | + return $this->hooks->sortKeys()->flatten(); |
|
102 | + } |
|
103 | 103 | } |