Passed
Push — main ( f9aaf7...4197a4 )
by Jonathan
14:34
created
app/Module/Certificates/Factories/CertificateImageFactory.php 2 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -39,163 +39,163 @@
 block discarded – undo
39 39
  */
40 40
 class CertificateImageFactory extends ImageFactory implements ImageFactoryInterface
41 41
 {
42
-    /**
43
-     * @var CertificateFilesystemService $filesystem_service
44
-     */
45
-    private $filesystem_service;
46
-
47
-    /**
48
-     * Constructor for the Certificate Image Factory
49
-     *
50
-     * @param CertificateFilesystemService $filesystem_service
51
-     */
52
-    public function __construct(CertificateFilesystemService $filesystem_service)
53
-    {
54
-        $this->filesystem_service = $filesystem_service;
55
-    }
56
-
57
-    /**
58
-     * Check is a file MIME type is supported by the system.
59
-     *
60
-     * @param string $mime
61
-     * @return bool
62
-     */
63
-    public function isMimeTypeSupported(string $mime): bool
64
-    {
65
-        return array_key_exists($mime, self::INTERVENTION_FORMATS);
66
-    }
67
-
68
-    /**
69
-     * Create a full-size version of a certificate.
70
-     *
71
-     * @param Certificate $certificate
72
-     * @param bool $add_watermark
73
-     * @param Watermark $watermark
74
-     * @throws InvalidArgumentException
75
-     * @return ResponseInterface
76
-     */
77
-    public function certificateFileResponse(
78
-        Certificate $certificate,
79
-        bool $add_watermark = false,
80
-        Watermark $watermark = null
81
-    ): ResponseInterface {
82
-        $filesystem =  $this->filesystem_service->filesystem($certificate->tree());
83
-        $filename   = $certificate->path();
84
-
85
-        if (!$add_watermark) {
86
-            return $this->fileResponse($filesystem, $filename, false);
87
-        }
88
-
89
-        try {
90
-            $image = $this->imageManager()->make($filesystem->readStream($filename));
91
-            $image = $this->autorotateImage($image);
92
-
93
-            if ($watermark == null) {
94
-                throw new InvalidArgumentException('Watermark data not defined');
95
-            }
96
-
97
-            $width = $image->width();
98
-            $height = $image->height();
99
-
100
-            $watermark->adjustSize($width);
101
-            $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5);
102
-            $watermark_y = $watermark->size() * 12 + 1;
103
-
104
-            $font_definition = function (AbstractFont $font) use ($watermark): void {
105
-                $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf');
106
-                $font->color($watermark->color());
107
-                $font->size($watermark->size());
108
-                $font->valign('top');
109
-            };
110
-
111
-            for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) {
112
-                for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) {
113
-                    $image = $image->text($watermark->text(), $i, $j, $font_definition);
114
-                }
115
-            }
116
-
117
-            $format  = static::INTERVENTION_FORMATS[$image->mime()] ?? 'jpg';
118
-            $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY);
119
-            $data    = (string) $image->encode($format, $quality);
120
-
121
-            return $this->imageResponse($data, $image->mime(), '');
122
-        } catch (NotReadableException $ex) {
123
-            return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION))
124
-            ->withHeader('X-Image-Exception', $ex->getMessage());
125
-        } catch (FilesystemException | UnableToReadFile $ex) {
126
-            return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND);
127
-        } catch (Throwable $ex) {
128
-            return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR)
129
-            ->withHeader('X-Image-Exception', $ex->getMessage());
130
-        }
131
-    }
132
-
133
-    /**
134
-     * Does a full-sized certificate need a watermark?
135
-     *
136
-     * @param Certificate $certificate
137
-     * @param UserInterface $user
138
-     * @return bool
139
-     */
140
-    public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool
141
-    {
142
-        $tree = $certificate->tree();
143
-
144
-        return Auth::accessLevel($tree, $user) > $tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK');
145
-    }
146
-
147
-    /**
148
-     * Neutralise the methods associated with MediaFile.
149
-     */
150
-
151
-    /**
152
-     * {@inheritDoc}
153
-     * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse()
154
-     */
155
-    public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface
156
-    {
157
-        throw new BadMethodCallException("Invalid method for Certificates");
158
-    }
159
-
160
-    /**
161
-     * {@inheritDoc}
162
-     * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse()
163
-     */
164
-    public function mediaFileThumbnailResponse(
165
-        MediaFile $media_file,
166
-        int $width,
167
-        int $height,
168
-        string $fit,
169
-        bool $add_watermark
170
-    ): ResponseInterface {
171
-        throw new BadMethodCallException("Invalid method for Certificates");
172
-    }
173
-
174
-    /**
175
-     * {@inheritDoc}
176
-     * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark()
177
-     */
178
-    public function createWatermark(int $width, int $height, MediaFile $media_file): Image
179
-    {
180
-
181
-        throw new BadMethodCallException("Invalid method for Certificates");
182
-    }
183
-
184
-    /**
185
-     * {@inheritDoc}
186
-     * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark()
187
-     */
188
-    public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool
189
-    {
190
-        throw new BadMethodCallException("Invalid method for Certificates");
191
-    }
192
-
193
-    /**
194
-     * {@inheritDoc}
195
-     * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark()
196
-     */
197
-    public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool
198
-    {
199
-        throw new BadMethodCallException("Invalid method for Certificates");
200
-    }
42
+	/**
43
+	 * @var CertificateFilesystemService $filesystem_service
44
+	 */
45
+	private $filesystem_service;
46
+
47
+	/**
48
+	 * Constructor for the Certificate Image Factory
49
+	 *
50
+	 * @param CertificateFilesystemService $filesystem_service
51
+	 */
52
+	public function __construct(CertificateFilesystemService $filesystem_service)
53
+	{
54
+		$this->filesystem_service = $filesystem_service;
55
+	}
56
+
57
+	/**
58
+	 * Check is a file MIME type is supported by the system.
59
+	 *
60
+	 * @param string $mime
61
+	 * @return bool
62
+	 */
63
+	public function isMimeTypeSupported(string $mime): bool
64
+	{
65
+		return array_key_exists($mime, self::INTERVENTION_FORMATS);
66
+	}
67
+
68
+	/**
69
+	 * Create a full-size version of a certificate.
70
+	 *
71
+	 * @param Certificate $certificate
72
+	 * @param bool $add_watermark
73
+	 * @param Watermark $watermark
74
+	 * @throws InvalidArgumentException
75
+	 * @return ResponseInterface
76
+	 */
77
+	public function certificateFileResponse(
78
+		Certificate $certificate,
79
+		bool $add_watermark = false,
80
+		Watermark $watermark = null
81
+	): ResponseInterface {
82
+		$filesystem =  $this->filesystem_service->filesystem($certificate->tree());
83
+		$filename   = $certificate->path();
84
+
85
+		if (!$add_watermark) {
86
+			return $this->fileResponse($filesystem, $filename, false);
87
+		}
88
+
89
+		try {
90
+			$image = $this->imageManager()->make($filesystem->readStream($filename));
91
+			$image = $this->autorotateImage($image);
92
+
93
+			if ($watermark == null) {
94
+				throw new InvalidArgumentException('Watermark data not defined');
95
+			}
96
+
97
+			$width = $image->width();
98
+			$height = $image->height();
99
+
100
+			$watermark->adjustSize($width);
101
+			$watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5);
102
+			$watermark_y = $watermark->size() * 12 + 1;
103
+
104
+			$font_definition = function (AbstractFont $font) use ($watermark): void {
105
+				$font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf');
106
+				$font->color($watermark->color());
107
+				$font->size($watermark->size());
108
+				$font->valign('top');
109
+			};
110
+
111
+			for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) {
112
+				for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) {
113
+					$image = $image->text($watermark->text(), $i, $j, $font_definition);
114
+				}
115
+			}
116
+
117
+			$format  = static::INTERVENTION_FORMATS[$image->mime()] ?? 'jpg';
118
+			$quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY);
119
+			$data    = (string) $image->encode($format, $quality);
120
+
121
+			return $this->imageResponse($data, $image->mime(), '');
122
+		} catch (NotReadableException $ex) {
123
+			return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION))
124
+			->withHeader('X-Image-Exception', $ex->getMessage());
125
+		} catch (FilesystemException | UnableToReadFile $ex) {
126
+			return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND);
127
+		} catch (Throwable $ex) {
128
+			return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR)
129
+			->withHeader('X-Image-Exception', $ex->getMessage());
130
+		}
131
+	}
132
+
133
+	/**
134
+	 * Does a full-sized certificate need a watermark?
135
+	 *
136
+	 * @param Certificate $certificate
137
+	 * @param UserInterface $user
138
+	 * @return bool
139
+	 */
140
+	public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool
141
+	{
142
+		$tree = $certificate->tree();
143
+
144
+		return Auth::accessLevel($tree, $user) > $tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK');
145
+	}
146
+
147
+	/**
148
+	 * Neutralise the methods associated with MediaFile.
149
+	 */
150
+
151
+	/**
152
+	 * {@inheritDoc}
153
+	 * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse()
154
+	 */
155
+	public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface
156
+	{
157
+		throw new BadMethodCallException("Invalid method for Certificates");
158
+	}
159
+
160
+	/**
161
+	 * {@inheritDoc}
162
+	 * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse()
163
+	 */
164
+	public function mediaFileThumbnailResponse(
165
+		MediaFile $media_file,
166
+		int $width,
167
+		int $height,
168
+		string $fit,
169
+		bool $add_watermark
170
+	): ResponseInterface {
171
+		throw new BadMethodCallException("Invalid method for Certificates");
172
+	}
173
+
174
+	/**
175
+	 * {@inheritDoc}
176
+	 * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark()
177
+	 */
178
+	public function createWatermark(int $width, int $height, MediaFile $media_file): Image
179
+	{
180
+
181
+		throw new BadMethodCallException("Invalid method for Certificates");
182
+	}
183
+
184
+	/**
185
+	 * {@inheritDoc}
186
+	 * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark()
187
+	 */
188
+	public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool
189
+	{
190
+		throw new BadMethodCallException("Invalid method for Certificates");
191
+	}
192
+
193
+	/**
194
+	 * {@inheritDoc}
195
+	 * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark()
196
+	 */
197
+	public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool
198
+	{
199
+		throw new BadMethodCallException("Invalid method for Certificates");
200
+	}
201 201
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         bool $add_watermark = false,
80 80
         Watermark $watermark = null
81 81
     ): ResponseInterface {
82
-        $filesystem =  $this->filesystem_service->filesystem($certificate->tree());
82
+        $filesystem = $this->filesystem_service->filesystem($certificate->tree());
83 83
         $filename   = $certificate->path();
84 84
 
85 85
         if (!$add_watermark) {
@@ -98,34 +98,34 @@  discard block
 block discarded – undo
98 98
             $height = $image->height();
99 99
 
100 100
             $watermark->adjustSize($width);
101
-            $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5);
101
+            $watermark_x = (int)ceil($watermark->textLengthEstimate() * 1.5);
102 102
             $watermark_y = $watermark->size() * 12 + 1;
103 103
 
104
-            $font_definition = function (AbstractFont $font) use ($watermark): void {
105
-                $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf');
104
+            $font_definition = function(AbstractFont $font) use ($watermark): void {
105
+                $font->file(Webtrees::ROOT_DIR.'resources/fonts/DejaVuSans.ttf');
106 106
                 $font->color($watermark->color());
107 107
                 $font->size($watermark->size());
108 108
                 $font->valign('top');
109 109
             };
110 110
 
111
-            for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) {
112
-                for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) {
111
+            for ($i = min((int)ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) {
112
+                for ($j = min((int)ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) {
113 113
                     $image = $image->text($watermark->text(), $i, $j, $font_definition);
114 114
                 }
115 115
             }
116 116
 
117 117
             $format  = static::INTERVENTION_FORMATS[$image->mime()] ?? 'jpg';
118 118
             $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY);
119
-            $data    = (string) $image->encode($format, $quality);
119
+            $data    = (string)$image->encode($format, $quality);
120 120
 
121 121
             return $this->imageResponse($data, $image->mime(), '');
122 122
         } catch (NotReadableException $ex) {
123 123
             return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION))
124 124
             ->withHeader('X-Image-Exception', $ex->getMessage());
125 125
         } catch (FilesystemException | UnableToReadFile $ex) {
126
-            return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND);
126
+            return $this->replacementImageResponse((string)StatusCodeInterface::STATUS_NOT_FOUND);
127 127
         } catch (Throwable $ex) {
128
-            return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR)
128
+            return $this->replacementImageResponse((string)StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR)
129 129
             ->withHeader('X-Image-Exception', $ex->getMessage());
130 130
         }
131 131
     }
Please login to merge, or discard this patch.
app/Module/Certificates/Model/Watermark.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -19,112 +19,112 @@
 block discarded – undo
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 string 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 string 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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -125,6 +125,6 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
app/Module/Certificates/Model/Certificate.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -202,11 +202,11 @@
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -25,193 +25,193 @@
 block discarded – undo
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($path);
67
-        $this->city = $path_parts['dirname'];
68
-        $this->basename = $path_parts['basename'];
69
-        $this->filename = $path_parts['filename'];
70
-        $this->extension = strtolower($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
-            $day = $match['day'] ?? '';
77
-            $month_date = DateTime::createFromFormat('m', $match['month'] ?? '');
78
-            $month = $month_date !== false ? strtoupper($month_date->format('M')) : '';
79
-            $year = $match['year'] ?? '';
80
-
81
-            $this->date = new Date(sprintf('%s %s %s', $day, $month, $year));
82
-        } else {
83
-            $this->description = $this->filename;
84
-        }
85
-    }
86
-
87
-    /**
88
-     * Get the family tree of the certificate
89
-     *
90
-     * @return Tree
91
-     */
92
-    public function tree(): Tree
93
-    {
94
-        return $this->tree;
95
-    }
96
-
97
-    /**
98
-     * Get the path of the certificate in the file system.
99
-     *
100
-     * @return string
101
-     */
102
-    public function path(): string
103
-    {
104
-        return $this->path;
105
-    }
106
-
107
-    /**
108
-     * The the path of the certificate, in a Gedcom canonical form.
109
-     *
110
-     * @return string
111
-     */
112
-    public function gedcomPath(): string
113
-    {
114
-        return str_replace('\\', '/', $this->path);
115
-    }
116
-
117
-    /**
118
-     * Get the certificate name.
119
-     *
120
-     * @return string
121
-     */
122
-    public function name(): string
123
-    {
124
-        return $this->filename ?? '';
125
-    }
126
-
127
-    /**
128
-     * Get the certificate file name.
129
-     *
130
-     * @return string
131
-     */
132
-    public function filename(): string
133
-    {
134
-        return $this->basename ?? '';
135
-    }
136
-
137
-    /**
138
-     * Get the certificate's city (the first level folder).
139
-     *
140
-     * @return string
141
-     */
142
-    public function city(): string
143
-    {
144
-        return $this->city ?? '';
145
-    }
146
-
147
-    /**
148
-     * Get the certificate's date. Extracted from the file name.
149
-     *
150
-     * @return Date
151
-     */
152
-    public function date(): Date
153
-    {
154
-        return $this->date ?? new Date('');
155
-    }
156
-
157
-    /**
158
-     * Get the certificate's type. Extracted from the file name.
159
-     *
160
-     * @return string
161
-     */
162
-    public function type(): string
163
-    {
164
-        return $this->type ?? '';
165
-    }
166
-
167
-    /**
168
-     * Get the certificate's description.  Extracted from the file name.
169
-     * @return string
170
-     */
171
-    public function description(): string
172
-    {
173
-        return $this->description ?? '';
174
-    }
175
-
176
-    /**
177
-     * Get the certificate's description to be used for sorting.
178
-     * This is based on surnames (at least 3 letters) found in the file name.
179
-     *
180
-     * @return string
181
-     */
182
-    public function sortDescription(): string
183
-    {
184
-        $sort_prefix = '';
185
-        if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
186
-            $sort_prefix = implode('_', array_map(function ($match) {
187
-                return $match[1];
188
-            }, $matches)) . '_';
189
-        }
190
-        return $sort_prefix . $this->description();
191
-    }
192
-
193
-    /**
194
-     * Get the certificate's MIME type.
195
-     *
196
-     * @return string
197
-     */
198
-    public function mimeType(): string
199
-    {
200
-        return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE;
201
-    }
202
-
203
-    /**
204
-     * Get the base parameters to be used in url referencing the certificate.
205
-     *
206
-     * @param UrlObfuscatorService $url_obfuscator_service
207
-     * @return array{tree: string, cid: mixed}
208
-     */
209
-    public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array
210
-    {
211
-        $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
212
-        return [
213
-            'tree' => $this->tree->name(),
214
-            'cid' => $url_obfuscator_service->obfuscate($this->path)
215
-        ];
216
-    }
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($path);
67
+		$this->city = $path_parts['dirname'];
68
+		$this->basename = $path_parts['basename'];
69
+		$this->filename = $path_parts['filename'];
70
+		$this->extension = strtolower($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
+			$day = $match['day'] ?? '';
77
+			$month_date = DateTime::createFromFormat('m', $match['month'] ?? '');
78
+			$month = $month_date !== false ? strtoupper($month_date->format('M')) : '';
79
+			$year = $match['year'] ?? '';
80
+
81
+			$this->date = new Date(sprintf('%s %s %s', $day, $month, $year));
82
+		} else {
83
+			$this->description = $this->filename;
84
+		}
85
+	}
86
+
87
+	/**
88
+	 * Get the family tree of the certificate
89
+	 *
90
+	 * @return Tree
91
+	 */
92
+	public function tree(): Tree
93
+	{
94
+		return $this->tree;
95
+	}
96
+
97
+	/**
98
+	 * Get the path of the certificate in the file system.
99
+	 *
100
+	 * @return string
101
+	 */
102
+	public function path(): string
103
+	{
104
+		return $this->path;
105
+	}
106
+
107
+	/**
108
+	 * The the path of the certificate, in a Gedcom canonical form.
109
+	 *
110
+	 * @return string
111
+	 */
112
+	public function gedcomPath(): string
113
+	{
114
+		return str_replace('\\', '/', $this->path);
115
+	}
116
+
117
+	/**
118
+	 * Get the certificate name.
119
+	 *
120
+	 * @return string
121
+	 */
122
+	public function name(): string
123
+	{
124
+		return $this->filename ?? '';
125
+	}
126
+
127
+	/**
128
+	 * Get the certificate file name.
129
+	 *
130
+	 * @return string
131
+	 */
132
+	public function filename(): string
133
+	{
134
+		return $this->basename ?? '';
135
+	}
136
+
137
+	/**
138
+	 * Get the certificate's city (the first level folder).
139
+	 *
140
+	 * @return string
141
+	 */
142
+	public function city(): string
143
+	{
144
+		return $this->city ?? '';
145
+	}
146
+
147
+	/**
148
+	 * Get the certificate's date. Extracted from the file name.
149
+	 *
150
+	 * @return Date
151
+	 */
152
+	public function date(): Date
153
+	{
154
+		return $this->date ?? new Date('');
155
+	}
156
+
157
+	/**
158
+	 * Get the certificate's type. Extracted from the file name.
159
+	 *
160
+	 * @return string
161
+	 */
162
+	public function type(): string
163
+	{
164
+		return $this->type ?? '';
165
+	}
166
+
167
+	/**
168
+	 * Get the certificate's description.  Extracted from the file name.
169
+	 * @return string
170
+	 */
171
+	public function description(): string
172
+	{
173
+		return $this->description ?? '';
174
+	}
175
+
176
+	/**
177
+	 * Get the certificate's description to be used for sorting.
178
+	 * This is based on surnames (at least 3 letters) found in the file name.
179
+	 *
180
+	 * @return string
181
+	 */
182
+	public function sortDescription(): string
183
+	{
184
+		$sort_prefix = '';
185
+		if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) {
186
+			$sort_prefix = implode('_', array_map(function ($match) {
187
+				return $match[1];
188
+			}, $matches)) . '_';
189
+		}
190
+		return $sort_prefix . $this->description();
191
+	}
192
+
193
+	/**
194
+	 * Get the certificate's MIME type.
195
+	 *
196
+	 * @return string
197
+	 */
198
+	public function mimeType(): string
199
+	{
200
+		return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE;
201
+	}
202
+
203
+	/**
204
+	 * Get the base parameters to be used in url referencing the certificate.
205
+	 *
206
+	 * @param UrlObfuscatorService $url_obfuscator_service
207
+	 * @return array{tree: string, cid: mixed}
208
+	 */
209
+	public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array
210
+	{
211
+		$url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class);
212
+		return [
213
+			'tree' => $this->tree->name(),
214
+			'cid' => $url_obfuscator_service->obfuscate($this->path)
215
+		];
216
+	}
217 217
 }
Please login to merge, or discard this patch.
app/Module/Certificates/Elements/SourceCertificate.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -28,61 +28,61 @@
 block discarded – undo
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($value): string
60
-    {
61
-        return strtr($value, '\\', '/');
62
-    }
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical()
58
+	 */
59
+	public function canonical($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
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,11 +69,11 @@
 block discarded – undo
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,
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/TasksList.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -31,90 +31,90 @@
 block discarded – undo
31 31
  */
32 32
 class TasksList implements RequestHandlerInterface
33 33
 {
34
-    private ?AdminTasksModule $module;
35
-    private TaskScheduleService $taskschedules_service;
34
+	private ?AdminTasksModule $module;
35
+	private TaskScheduleService $taskschedules_service;
36 36
 
37
-    /**
38
-     * Constructor for TasksList Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     * @param TaskScheduleService $taskschedules_service
42
-     */
43
-    public function __construct(
44
-        ModuleService $module_service,
45
-        TaskScheduleService $taskschedules_service
46
-    ) {
47
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
48
-        $this->taskschedules_service = $taskschedules_service;
49
-    }
37
+	/**
38
+	 * Constructor for TasksList Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 * @param TaskScheduleService $taskschedules_service
42
+	 */
43
+	public function __construct(
44
+		ModuleService $module_service,
45
+		TaskScheduleService $taskschedules_service
46
+	) {
47
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
48
+		$this->taskschedules_service = $taskschedules_service;
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
-     */
55
-    public function handle(ServerRequestInterface $request): ResponseInterface
56
-    {
57
-        if ($this->module === null) {
58
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
-        }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
+	 */
55
+	public function handle(ServerRequestInterface $request): ResponseInterface
56
+	{
57
+		if ($this->module === null) {
58
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
+		}
60 60
 
61
-        $module = $this->module;
62
-        $module_name = $this->module->name();
63
-        return response(['data' => $this->taskschedules_service->all(true, true)
64
-            ->map(function (TaskSchedule $schedule) use ($module, $module_name): array {
65
-                $task = $this->taskschedules_service->findTask($schedule->taskId());
66
-                $task_name = $task !== null ? $task->name() : I18N::translate('Task not found');
61
+		$module = $this->module;
62
+		$module_name = $this->module->name();
63
+		return response(['data' => $this->taskschedules_service->all(true, true)
64
+			->map(function (TaskSchedule $schedule) use ($module, $module_name): array {
65
+				$task = $this->taskschedules_service->findTask($schedule->taskId());
66
+				$task_name = $task !== null ? $task->name() : I18N::translate('Task not found');
67 67
 
68
-                return [
69
-                    'edit' =>   view($module_name . '::admin/tasks-table-options', [
70
-                        'task_sched_id' => $schedule->id(),
71
-                        'task_sched_enabled' => $schedule->isEnabled(),
72
-                        'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]),
73
-                        'task_status_route' => route(TaskStatusAction::class, [
74
-                            'task' => $schedule->id(),
75
-                            'enable' => $schedule->isEnabled() ? 0 : 1
76
-                        ])
77
-                    ]),
78
-                    'status'    =>  [
79
-                        'display'   =>  view($module_name . '::components/yes-no-icons', [
80
-                            'yes' => $schedule->isEnabled()
81
-                        ]),
82
-                        'raw'       =>  $schedule->isEnabled() ? 1 : 0
83
-                    ],
84
-                    'task_name' =>  [
85
-                        'display'   =>  '<span dir="auto">' . e($task_name) . '</span>',
86
-                        'raw'       =>  $task_name
87
-                    ],
88
-                    'last_run'  =>  [
89
-                        'display'   =>  $schedule->lastRunTime()->unix() === 0 ?
90
-                            view('components/datetime', ['timestamp' => $schedule->lastRunTime()]) :
91
-                            view('components/datetime-diff', ['timestamp' => $schedule->lastRunTime()]),
92
-                        'raw'       =>  $schedule->lastRunTime()->unix()
93
-                    ],
94
-                    'last_result'   =>  [
95
-                        'display'   => view($module_name . '::components/yes-no-icons', [
96
-                            'yes' => $schedule->wasLastRunSuccess()
97
-                        ]),
98
-                        'raw'       =>  $schedule->wasLastRunSuccess() ? 1 : 0
99
-                    ],
100
-                    'frequency' =>  '<span dir="auto">' . e($schedule->frequency()->cascade()->forHumans()) . '</span>',
101
-                    'nb_occurrences'    =>  $schedule->remainingOccurences() > 0 ?
102
-                        I18N::number($schedule->remainingOccurences()) :
103
-                        I18N::translate('Unlimited'),
104
-                    'running'   =>  view($module_name . '::components/yes-no-icons', [
105
-                        'yes' => $schedule->isRunning(),
106
-                        'text_yes' => I18N::translate('Running'),
107
-                        'text_no' => I18N::translate('Not running')
108
-                    ]),
109
-                    'run'       =>  view($module_name . '::admin/tasks-table-run', [
110
-                        'task_sched_id' => $schedule->id(),
111
-                        'run_route' => route(TaskTrigger::class, [
112
-                            'task'  =>  $schedule->taskId(),
113
-                            'force' =>  $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN')
114
-                        ])
115
-                    ])
116
-                ];
117
-            })
118
-        ]);
119
-    }
68
+				return [
69
+					'edit' =>   view($module_name . '::admin/tasks-table-options', [
70
+						'task_sched_id' => $schedule->id(),
71
+						'task_sched_enabled' => $schedule->isEnabled(),
72
+						'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]),
73
+						'task_status_route' => route(TaskStatusAction::class, [
74
+							'task' => $schedule->id(),
75
+							'enable' => $schedule->isEnabled() ? 0 : 1
76
+						])
77
+					]),
78
+					'status'    =>  [
79
+						'display'   =>  view($module_name . '::components/yes-no-icons', [
80
+							'yes' => $schedule->isEnabled()
81
+						]),
82
+						'raw'       =>  $schedule->isEnabled() ? 1 : 0
83
+					],
84
+					'task_name' =>  [
85
+						'display'   =>  '<span dir="auto">' . e($task_name) . '</span>',
86
+						'raw'       =>  $task_name
87
+					],
88
+					'last_run'  =>  [
89
+						'display'   =>  $schedule->lastRunTime()->unix() === 0 ?
90
+							view('components/datetime', ['timestamp' => $schedule->lastRunTime()]) :
91
+							view('components/datetime-diff', ['timestamp' => $schedule->lastRunTime()]),
92
+						'raw'       =>  $schedule->lastRunTime()->unix()
93
+					],
94
+					'last_result'   =>  [
95
+						'display'   => view($module_name . '::components/yes-no-icons', [
96
+							'yes' => $schedule->wasLastRunSuccess()
97
+						]),
98
+						'raw'       =>  $schedule->wasLastRunSuccess() ? 1 : 0
99
+					],
100
+					'frequency' =>  '<span dir="auto">' . e($schedule->frequency()->cascade()->forHumans()) . '</span>',
101
+					'nb_occurrences'    =>  $schedule->remainingOccurences() > 0 ?
102
+						I18N::number($schedule->remainingOccurences()) :
103
+						I18N::translate('Unlimited'),
104
+					'running'   =>  view($module_name . '::components/yes-no-icons', [
105
+						'yes' => $schedule->isRunning(),
106
+						'text_yes' => I18N::translate('Running'),
107
+						'text_no' => I18N::translate('Not running')
108
+					]),
109
+					'run'       =>  view($module_name . '::admin/tasks-table-run', [
110
+						'task_sched_id' => $schedule->id(),
111
+						'run_route' => route(TaskTrigger::class, [
112
+							'task'  =>  $schedule->taskId(),
113
+							'force' =>  $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN')
114
+						])
115
+					])
116
+				];
117
+			})
118
+		]);
119
+	}
120 120
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -12 removed lines patch added patch discarded remove patch
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
         $module = $this->module;
62 62
         $module_name = $this->module->name();
63 63
         return response(['data' => $this->taskschedules_service->all(true, true)
64
-            ->map(function (TaskSchedule $schedule) use ($module, $module_name): array {
64
+            ->map(function(TaskSchedule $schedule) use ($module, $module_name): array {
65 65
                 $task = $this->taskschedules_service->findTask($schedule->taskId());
66 66
                 $task_name = $task !== null ? $task->name() : I18N::translate('Task not found');
67 67
 
68 68
                 return [
69
-                    'edit' =>   view($module_name . '::admin/tasks-table-options', [
69
+                    'edit' =>   view($module_name.'::admin/tasks-table-options', [
70 70
                         'task_sched_id' => $schedule->id(),
71 71
                         'task_sched_enabled' => $schedule->isEnabled(),
72 72
                         'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]),
@@ -76,37 +76,35 @@  discard block
 block discarded – undo
76 76
                         ])
77 77
                     ]),
78 78
                     'status'    =>  [
79
-                        'display'   =>  view($module_name . '::components/yes-no-icons', [
79
+                        'display'   =>  view($module_name.'::components/yes-no-icons', [
80 80
                             'yes' => $schedule->isEnabled()
81 81
                         ]),
82 82
                         'raw'       =>  $schedule->isEnabled() ? 1 : 0
83 83
                     ],
84 84
                     'task_name' =>  [
85
-                        'display'   =>  '<span dir="auto">' . e($task_name) . '</span>',
85
+                        'display'   =>  '<span dir="auto">'.e($task_name).'</span>',
86 86
                         'raw'       =>  $task_name
87 87
                     ],
88 88
                     'last_run'  =>  [
89 89
                         'display'   =>  $schedule->lastRunTime()->unix() === 0 ?
90
-                            view('components/datetime', ['timestamp' => $schedule->lastRunTime()]) :
91
-                            view('components/datetime-diff', ['timestamp' => $schedule->lastRunTime()]),
90
+                            view('components/datetime', ['timestamp' => $schedule->lastRunTime()]) : view('components/datetime-diff', ['timestamp' => $schedule->lastRunTime()]),
92 91
                         'raw'       =>  $schedule->lastRunTime()->unix()
93 92
                     ],
94 93
                     'last_result'   =>  [
95
-                        'display'   => view($module_name . '::components/yes-no-icons', [
94
+                        'display'   => view($module_name.'::components/yes-no-icons', [
96 95
                             'yes' => $schedule->wasLastRunSuccess()
97 96
                         ]),
98 97
                         'raw'       =>  $schedule->wasLastRunSuccess() ? 1 : 0
99 98
                     ],
100
-                    'frequency' =>  '<span dir="auto">' . e($schedule->frequency()->cascade()->forHumans()) . '</span>',
99
+                    'frequency' =>  '<span dir="auto">'.e($schedule->frequency()->cascade()->forHumans()).'</span>',
101 100
                     'nb_occurrences'    =>  $schedule->remainingOccurences() > 0 ?
102
-                        I18N::number($schedule->remainingOccurences()) :
103
-                        I18N::translate('Unlimited'),
104
-                    'running'   =>  view($module_name . '::components/yes-no-icons', [
101
+                        I18N::number($schedule->remainingOccurences()) : I18N::translate('Unlimited'),
102
+                    'running'   =>  view($module_name.'::components/yes-no-icons', [
105 103
                         'yes' => $schedule->isRunning(),
106 104
                         'text_yes' => I18N::translate('Running'),
107 105
                         'text_no' => I18N::translate('Not running')
108 106
                     ]),
109
-                    'run'       =>  view($module_name . '::admin/tasks-table-run', [
107
+                    'run'       =>  view($module_name.'::admin/tasks-table-run', [
110 108
                         'task_sched_id' => $schedule->id(),
111 109
                         'run_route' => route(TaskTrigger::class, [
112 110
                             'task'  =>  $schedule->taskId(),
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/TaskEditAction.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -33,151 +33,151 @@
 block discarded – undo
33 33
  */
34 34
 class TaskEditAction implements RequestHandlerInterface
35 35
 {
36
-    private ?AdminTasksModule $module;
37
-    private TaskScheduleService $taskschedules_service;
38
-
39
-    /**
40
-     * Constructor for TaskEditAction Request Handler
41
-     *
42
-     * @param ModuleService $module_service
43
-     * @param TaskScheduleService $taskschedules_service
44
-     */
45
-    public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service)
46
-    {
47
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
48
-        $this->taskschedules_service = $taskschedules_service;
49
-    }
50
-
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
-     */
55
-    public function handle(ServerRequestInterface $request): ResponseInterface
56
-    {
57
-        $admin_config_route = route(AdminConfigPage::class);
58
-
59
-        if ($this->module === null) {
60
-            FlashMessages::addMessage(
61
-                I18N::translate('The attached module could not be found.'),
62
-                'danger'
63
-            );
64
-            return redirect($admin_config_route);
65
-        }
66
-
67
-        $task_sched_id = (int) $request->getAttribute('task');
68
-        $task_schedule = $this->taskschedules_service->find($task_sched_id);
69
-
70
-        if ($task_schedule === null) {
71
-            FlashMessages::addMessage(
72
-                I18N::translate('The task shedule with ID “%s” does not exist.', I18N::number($task_sched_id)),
73
-                'danger'
74
-            );
75
-            return redirect($admin_config_route);
76
-        }
77
-
78
-        $success = $this->updateGeneralSettings($task_schedule, $request);
79
-        $success = $success && $this->updateSpecificSettings($task_schedule, $request);
80
-
81
-        if ($success) {
82
-            FlashMessages::addMessage(
83
-                I18N::translate('The scheduled task has been successfully updated.'),
84
-                'success'
85
-            );
86
-            //phpcs:ignore Generic.Files.LineLength.TooLong
87
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.');
88
-        }
89
-
90
-        return redirect($admin_config_route);
91
-    }
92
-
93
-    /**
94
-     * Update general settings for the task, based on the request parameters
95
-     *
96
-     * @param TaskSchedule $task_schedule
97
-     * @param ServerRequestInterface $request
98
-     * @return bool
99
-     */
100
-    private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool
101
-    {
102
-        if ($this->module === null) {
103
-            return false;
104
-        }
105
-
106
-        $params = (array) $request->getParsedBody();
107
-
108
-        $frequency = (int) $params['frequency'];
109
-        if ($frequency > 0) {
110
-            $task_schedule->setFrequency(CarbonInterval::minutes($frequency));
111
-        } else {
112
-            FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format.'), 'danger');
113
-        }
114
-
115
-        $is_limited = (bool) $params['is_limited'];
116
-        $nb_occur = (int) $params['nb_occur'];
117
-
118
-        if ($is_limited) {
119
-            if ($nb_occur > 0) {
120
-                $task_schedule->setRemainingOccurences($nb_occur);
121
-            } else {
122
-                FlashMessages::addMessage(
123
-                    I18N::translate('The number of remaining occurences is not in a valid format.'),
124
-                    'danger'
125
-                );
126
-            }
127
-        } else {
128
-            $task_schedule->setRemainingOccurences(0);
129
-        }
130
-
131
-        try {
132
-            $this->taskschedules_service->update($task_schedule);
133
-            return true;
134
-        } catch (Throwable $ex) {
135
-            Log::addErrorLog(
136
-                sprintf(
137
-                    'Error while updating the Task Schedule "%s". Exception: %s',
138
-                    $task_schedule->id(),
139
-                    $ex->getMessage()
140
-                )
141
-            );
142
-        }
143
-
144
-        FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task.'), 'danger');
145
-        //@phpcs:ignore Generic.Files.LineLength.TooLong
146
-        Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.');
147
-        return false;
148
-    }
149
-
150
-    /**
151
-     * Update general settings for the task, based on the request parameters
152
-     *
153
-     * @param TaskSchedule $task_schedule
154
-     * @param ServerRequestInterface $request
155
-     * @return bool
156
-     */
157
-    private function updateSpecificSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool
158
-    {
159
-        if ($this->module === null) {
160
-            return false;
161
-        }
162
-
163
-        $task = $this->taskschedules_service->findTask($task_schedule->taskId());
164
-        if ($task === null || !($task instanceof ConfigurableTaskInterface)) {
165
-            return true;
166
-        }
167
-
168
-        /** @var \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface&\MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface $task */
169
-        if (!$task->updateConfig($request, $task_schedule)) {
170
-            FlashMessages::addMessage(
171
-                I18N::translate(
172
-                    'An error occured while updating the specific settings of administrative task “%s”.',
173
-                    $task->name()
174
-                ),
175
-                'danger'
176
-            );
177
-            //phpcs:ignore Generic.Files.LineLength.TooLong
178
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.');
179
-        }
180
-
181
-        return true;
182
-    }
36
+	private ?AdminTasksModule $module;
37
+	private TaskScheduleService $taskschedules_service;
38
+
39
+	/**
40
+	 * Constructor for TaskEditAction Request Handler
41
+	 *
42
+	 * @param ModuleService $module_service
43
+	 * @param TaskScheduleService $taskschedules_service
44
+	 */
45
+	public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service)
46
+	{
47
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
48
+		$this->taskschedules_service = $taskschedules_service;
49
+	}
50
+
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
+	 */
55
+	public function handle(ServerRequestInterface $request): ResponseInterface
56
+	{
57
+		$admin_config_route = route(AdminConfigPage::class);
58
+
59
+		if ($this->module === null) {
60
+			FlashMessages::addMessage(
61
+				I18N::translate('The attached module could not be found.'),
62
+				'danger'
63
+			);
64
+			return redirect($admin_config_route);
65
+		}
66
+
67
+		$task_sched_id = (int) $request->getAttribute('task');
68
+		$task_schedule = $this->taskschedules_service->find($task_sched_id);
69
+
70
+		if ($task_schedule === null) {
71
+			FlashMessages::addMessage(
72
+				I18N::translate('The task shedule with ID “%s” does not exist.', I18N::number($task_sched_id)),
73
+				'danger'
74
+			);
75
+			return redirect($admin_config_route);
76
+		}
77
+
78
+		$success = $this->updateGeneralSettings($task_schedule, $request);
79
+		$success = $success && $this->updateSpecificSettings($task_schedule, $request);
80
+
81
+		if ($success) {
82
+			FlashMessages::addMessage(
83
+				I18N::translate('The scheduled task has been successfully updated.'),
84
+				'success'
85
+			);
86
+			//phpcs:ignore Generic.Files.LineLength.TooLong
87
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.');
88
+		}
89
+
90
+		return redirect($admin_config_route);
91
+	}
92
+
93
+	/**
94
+	 * Update general settings for the task, based on the request parameters
95
+	 *
96
+	 * @param TaskSchedule $task_schedule
97
+	 * @param ServerRequestInterface $request
98
+	 * @return bool
99
+	 */
100
+	private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool
101
+	{
102
+		if ($this->module === null) {
103
+			return false;
104
+		}
105
+
106
+		$params = (array) $request->getParsedBody();
107
+
108
+		$frequency = (int) $params['frequency'];
109
+		if ($frequency > 0) {
110
+			$task_schedule->setFrequency(CarbonInterval::minutes($frequency));
111
+		} else {
112
+			FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format.'), 'danger');
113
+		}
114
+
115
+		$is_limited = (bool) $params['is_limited'];
116
+		$nb_occur = (int) $params['nb_occur'];
117
+
118
+		if ($is_limited) {
119
+			if ($nb_occur > 0) {
120
+				$task_schedule->setRemainingOccurences($nb_occur);
121
+			} else {
122
+				FlashMessages::addMessage(
123
+					I18N::translate('The number of remaining occurences is not in a valid format.'),
124
+					'danger'
125
+				);
126
+			}
127
+		} else {
128
+			$task_schedule->setRemainingOccurences(0);
129
+		}
130
+
131
+		try {
132
+			$this->taskschedules_service->update($task_schedule);
133
+			return true;
134
+		} catch (Throwable $ex) {
135
+			Log::addErrorLog(
136
+				sprintf(
137
+					'Error while updating the Task Schedule "%s". Exception: %s',
138
+					$task_schedule->id(),
139
+					$ex->getMessage()
140
+				)
141
+			);
142
+		}
143
+
144
+		FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task.'), 'danger');
145
+		//@phpcs:ignore Generic.Files.LineLength.TooLong
146
+		Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.');
147
+		return false;
148
+	}
149
+
150
+	/**
151
+	 * Update general settings for the task, based on the request parameters
152
+	 *
153
+	 * @param TaskSchedule $task_schedule
154
+	 * @param ServerRequestInterface $request
155
+	 * @return bool
156
+	 */
157
+	private function updateSpecificSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool
158
+	{
159
+		if ($this->module === null) {
160
+			return false;
161
+		}
162
+
163
+		$task = $this->taskschedules_service->findTask($task_schedule->taskId());
164
+		if ($task === null || !($task instanceof ConfigurableTaskInterface)) {
165
+			return true;
166
+		}
167
+
168
+		/** @var \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface&\MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface $task */
169
+		if (!$task->updateConfig($request, $task_schedule)) {
170
+			FlashMessages::addMessage(
171
+				I18N::translate(
172
+					'An error occured while updating the specific settings of administrative task “%s”.',
173
+					$task->name()
174
+				),
175
+				'danger'
176
+			);
177
+			//phpcs:ignore Generic.Files.LineLength.TooLong
178
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.');
179
+		}
180
+
181
+		return true;
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             return redirect($admin_config_route);
65 65
         }
66 66
 
67
-        $task_sched_id = (int) $request->getAttribute('task');
67
+        $task_sched_id = (int)$request->getAttribute('task');
68 68
         $task_schedule = $this->taskschedules_service->find($task_sched_id);
69 69
 
70 70
         if ($task_schedule === null) {
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                 'success'
85 85
             );
86 86
             //phpcs:ignore Generic.Files.LineLength.TooLong
87
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.');
87
+            Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” has been updated.');
88 88
         }
89 89
 
90 90
         return redirect($admin_config_route);
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
             return false;
104 104
         }
105 105
 
106
-        $params = (array) $request->getParsedBody();
106
+        $params = (array)$request->getParsedBody();
107 107
 
108
-        $frequency = (int) $params['frequency'];
108
+        $frequency = (int)$params['frequency'];
109 109
         if ($frequency > 0) {
110 110
             $task_schedule->setFrequency(CarbonInterval::minutes($frequency));
111 111
         } else {
112 112
             FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format.'), 'danger');
113 113
         }
114 114
 
115
-        $is_limited = (bool) $params['is_limited'];
116
-        $nb_occur = (int) $params['nb_occur'];
115
+        $is_limited = (bool)$params['is_limited'];
116
+        $nb_occur = (int)$params['nb_occur'];
117 117
 
118 118
         if ($is_limited) {
119 119
             if ($nb_occur > 0) {
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
         FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task.'), 'danger');
145 145
         //@phpcs:ignore Generic.Files.LineLength.TooLong
146
-        Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.');
146
+        Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” could not be updated. See error log.');
147 147
         return false;
148 148
     }
149 149
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
                 'danger'
176 176
             );
177 177
             //phpcs:ignore Generic.Files.LineLength.TooLong
178
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.');
178
+            Log::addConfigurationLog('Module '.$this->module->title().' : AdminTask “'.$task->name().'” specific settings could not be updated. See error log.');
179 179
         }
180 180
 
181 181
         return true;
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/TaskStatusAction.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,68 +29,68 @@
 block discarded – undo
29 29
  */
30 30
 class TaskStatusAction implements RequestHandlerInterface
31 31
 {
32
-    private ?AdminTasksModule $module;
33
-    private TaskScheduleService $taskschedules_service;
32
+	private ?AdminTasksModule $module;
33
+	private TaskScheduleService $taskschedules_service;
34 34
 
35
-    /**
36
-     * Constructor for TaskStatusAction Request Handler
37
-     *
38
-     * @param ModuleService $module_service
39
-     * @param TaskScheduleService $taskschedules_service
40
-     */
41
-    public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service)
42
-    {
43
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
44
-        $this->taskschedules_service = $taskschedules_service;
45
-    }
35
+	/**
36
+	 * Constructor for TaskStatusAction Request Handler
37
+	 *
38
+	 * @param ModuleService $module_service
39
+	 * @param TaskScheduleService $taskschedules_service
40
+	 */
41
+	public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service)
42
+	{
43
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
44
+		$this->taskschedules_service = $taskschedules_service;
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
-     */
51
-    public function handle(ServerRequestInterface $request): ResponseInterface
52
-    {
53
-        $admin_config_route = route(AdminConfigPage::class);
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
+	 */
51
+	public function handle(ServerRequestInterface $request): ResponseInterface
52
+	{
53
+		$admin_config_route = route(AdminConfigPage::class);
54 54
 
55
-        if ($this->module === null) {
56
-            FlashMessages::addMessage(
57
-                I18N::translate('The attached module could not be found.'),
58
-                'danger'
59
-            );
60
-            return redirect($admin_config_route);
61
-        }
55
+		if ($this->module === null) {
56
+			FlashMessages::addMessage(
57
+				I18N::translate('The attached module could not be found.'),
58
+				'danger'
59
+			);
60
+			return redirect($admin_config_route);
61
+		}
62 62
 
63
-        $task_sched_id = (int) $request->getAttribute('task');
64
-        $task_schedule = $this->taskschedules_service->find($task_sched_id);
63
+		$task_sched_id = (int) $request->getAttribute('task');
64
+		$task_schedule = $this->taskschedules_service->find($task_sched_id);
65 65
 
66
-        $admin_config_route = route(AdminConfigPage::class);
66
+		$admin_config_route = route(AdminConfigPage::class);
67 67
 
68
-        if ($task_schedule === null) {
69
-            FlashMessages::addMessage(
70
-                I18N::translate('The task shedule with ID “%s” does not exist.', I18N::number($task_sched_id)),
71
-                'danger'
72
-            );
73
-            return redirect($admin_config_route);
74
-        }
68
+		if ($task_schedule === null) {
69
+			FlashMessages::addMessage(
70
+				I18N::translate('The task shedule with ID “%s” does not exist.', I18N::number($task_sched_id)),
71
+				'danger'
72
+			);
73
+			return redirect($admin_config_route);
74
+		}
75 75
 
76
-        ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable();
76
+		((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable();
77 77
 
78
-        if ($this->taskschedules_service->update($task_schedule) > 0) {
79
-            FlashMessages::addMessage(
80
-                I18N::translate('The scheduled task has been successfully updated.'),
81
-                'success'
82
-            );
83
-            //phpcs:ignore Generic.Files.LineLength.TooLong
84
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.');
85
-        } else {
86
-            FlashMessages::addMessage(
87
-                I18N::translate('An error occured while updating the scheduled task.'),
88
-                'danger'
89
-            );
90
-            //phpcs:ignore Generic.Files.LineLength.TooLong
91
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.');
92
-        }
78
+		if ($this->taskschedules_service->update($task_schedule) > 0) {
79
+			FlashMessages::addMessage(
80
+				I18N::translate('The scheduled task has been successfully updated.'),
81
+				'success'
82
+			);
83
+			//phpcs:ignore Generic.Files.LineLength.TooLong
84
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.');
85
+		} else {
86
+			FlashMessages::addMessage(
87
+				I18N::translate('An error occured while updating the scheduled task.'),
88
+				'danger'
89
+			);
90
+			//phpcs:ignore Generic.Files.LineLength.TooLong
91
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.');
92
+		}
93 93
 
94
-        return redirect($admin_config_route);
95
-    }
94
+		return redirect($admin_config_route);
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             return redirect($admin_config_route);
61 61
         }
62 62
 
63
-        $task_sched_id = (int) $request->getAttribute('task');
63
+        $task_sched_id = (int)$request->getAttribute('task');
64 64
         $task_schedule = $this->taskschedules_service->find($task_sched_id);
65 65
 
66 66
         $admin_config_route = route(AdminConfigPage::class);
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             return redirect($admin_config_route);
74 74
         }
75 75
 
76
-        ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable();
76
+        ((bool)$request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable();
77 77
 
78 78
         if ($this->taskschedules_service->update($task_schedule) > 0) {
79 79
             FlashMessages::addMessage(
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
                 'success'
82 82
             );
83 83
             //phpcs:ignore Generic.Files.LineLength.TooLong
84
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.');
84
+            Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” has been updated.');
85 85
         } else {
86 86
             FlashMessages::addMessage(
87 87
                 I18N::translate('An error occured while updating the scheduled task.'),
88 88
                 'danger'
89 89
             );
90 90
             //phpcs:ignore Generic.Files.LineLength.TooLong
91
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.');
91
+            Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” could not be updated. See error log.');
92 92
         }
93 93
 
94 94
         return redirect($admin_config_route);
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/AdminConfigPage.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -29,47 +29,47 @@
 block discarded – undo
29 29
  */
30 30
 class AdminConfigPage implements RequestHandlerInterface
31 31
 {
32
-    use ViewResponseTrait;
32
+	use ViewResponseTrait;
33 33
 
34
-    private ?AdminTasksModule $module;
35
-    private TokenService $token_service;
34
+	private ?AdminTasksModule $module;
35
+	private TokenService $token_service;
36 36
 
37
-    /**
38
-     * Constructor for Admin Config request handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service, TokenService $token_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
45
-        $this->token_service = $token_service;
46
-    }
37
+	/**
38
+	 * Constructor for Admin Config request handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service, TokenService $token_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
45
+		$this->token_service = $token_service;
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
51
-     */
52
-    public function handle(ServerRequestInterface $request): ResponseInterface
53
-    {
54
-        $this->layout = 'layouts/administration';
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
51
+	 */
52
+	public function handle(ServerRequestInterface $request): ResponseInterface
53
+	{
54
+		$this->layout = 'layouts/administration';
55 55
 
56
-        if ($this->module === null) {
57
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
58
-        }
56
+		if ($this->module === null) {
57
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
58
+		}
59 59
 
60
-        $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
61
-        if ($token === '') {
62
-            $token = $this->token_service->generateRandomToken();
63
-            $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
64
-        }
60
+		$token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
61
+		if ($token === '') {
62
+			$token = $this->token_service->generateRandomToken();
63
+			$this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
64
+		}
65 65
 
66
-        return $this->viewResponse($this->module->name() . '::admin/config', [
67
-            'title'             =>  $this->module->title(),
68
-            'trigger_token'     =>  $token,
69
-            'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
70
-            'new_token_route'   =>  route(TokenGenerate::class),
71
-            'tasks_data_route'  =>  route(TasksList::class),
72
-            'js_script_url'     =>  $this->module->assetUrl('js/admintasks.min.js')
73
-        ]);
74
-    }
66
+		return $this->viewResponse($this->module->name() . '::admin/config', [
67
+			'title'             =>  $this->module->title(),
68
+			'trigger_token'     =>  $token,
69
+			'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
70
+			'new_token_route'   =>  route(TokenGenerate::class),
71
+			'tasks_data_route'  =>  route(TasksList::class),
72
+			'js_script_url'     =>  $this->module->assetUrl('js/admintasks.min.js')
73
+		]);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
             $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token);
74 74
         }
75 75
         
76
-        return $this->viewResponse($this->module->name() . '::admin/config', [
76
+        return $this->viewResponse($this->module->name().'::admin/config', [
77 77
             'title'             =>  $this->module->title(),
78 78
             'trigger_token'     =>  $token,
79 79
             'trigger_route'     =>  route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']),
Please login to merge, or discard this patch.
app/Module/AdminTasks/Http/RequestHandlers/TaskTrigger.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,41 +28,41 @@
 block discarded – undo
28 28
  */
29 29
 class TaskTrigger implements RequestHandlerInterface
30 30
 {
31
-    private ?AdminTasksModule $module;
32
-    private TaskScheduleService $taskschedules_service;
31
+	private ?AdminTasksModule $module;
32
+	private TaskScheduleService $taskschedules_service;
33 33
 
34
-    /**
35
-     * Constructor for TaskTrigger request handler
36
-     * @param ModuleService $module_service
37
-     * @param TaskScheduleService $taskschedules_service
38
-     */
39
-    public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service)
40
-    {
41
-        $this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
42
-        $this->taskschedules_service = $taskschedules_service;
43
-    }
34
+	/**
35
+	 * Constructor for TaskTrigger request handler
36
+	 * @param ModuleService $module_service
37
+	 * @param TaskScheduleService $taskschedules_service
38
+	 */
39
+	public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service)
40
+	{
41
+		$this->module = $module_service->findByInterface(AdminTasksModule::class)->first();
42
+		$this->taskschedules_service = $taskschedules_service;
43
+	}
44 44
 
45
-    /**
46
-     * {@inheritDoc}
47
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
48
-     */
49
-    public function handle(ServerRequestInterface $request): ResponseInterface
50
-    {
51
-        if ($this->module === null) {
52
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
53
-        }
45
+	/**
46
+	 * {@inheritDoc}
47
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
48
+	 */
49
+	public function handle(ServerRequestInterface $request): ResponseInterface
50
+	{
51
+		if ($this->module === null) {
52
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
53
+		}
54 54
 
55
-        $task_id = $request->getAttribute('task');
56
-        $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
57
-        $force_token = $request->getQueryParams()['force'] ?? '';
58
-        $force = $token == $force_token;
55
+		$task_id = $request->getAttribute('task');
56
+		$token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN');
57
+		$force_token = $request->getQueryParams()['force'] ?? '';
58
+		$force = $token == $force_token;
59 59
 
60
-        $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id);
60
+		$task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id);
61 61
 
62
-        foreach ($task_schedules as $task_schedule) {
63
-            $this->taskschedules_service->run($task_schedule, $force);
64
-        }
62
+		foreach ($task_schedules as $task_schedule) {
63
+			$this->taskschedules_service->run($task_schedule, $force);
64
+		}
65 65
 
66
-        return response();
67
-    }
66
+		return response();
67
+	}
68 68
 }
Please login to merge, or discard this patch.