Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.1] Fix Image Size Check with scheduler #117

Closed
joomlapl-bot opened this issue Jan 14, 2022 · 0 comments
Closed

[4.1] Fix Image Size Check with scheduler #117

joomlapl-bot opened this issue Jan 14, 2022 · 0 comments

Comments

@joomlapl-bot
Copy link
Collaborator

PR w związku ze zmianą oryginału joomla/joomla-cms#36653 Poniżej zmiany w oryginale:

Click to expand the diff!
diff --git a/administrator/language/en-GB/plg_task_checkfiles.ini b/administrator/language/en-GB/plg_task_checkfiles.ini
index 0cfe20d0a08e..cee47448cc90 100644
--- a/administrator/language/en-GB/plg_task_checkfiles.ini
+++ b/administrator/language/en-GB/plg_task_checkfiles.ini
@@ -5,12 +5,14 @@
 
 PLG_TASK_CHECK_FILES="Task - Check Files"
 PLG_TASK_CHECK_FILES_LABEL_DIMENSION_LIMIT="Limit (px)"
+PLG_TASK_CHECK_FILES_LABEL_MAXIMAGES="Maximum Images"
+PLG_TASK_CHECK_FILES_LABEL_MAXIMAGES_DESC="The maximum number of images to be processed in a single run. Setting this number too high may cause the task to timeout."
 PLG_TASK_CHECK_FILES_LABEL_DIRECTORY="Directory"
 PLG_TASK_CHECK_FILES_LABEL_IMAGE_DIMENSION="Dimension"
 PLG_TASK_CHECK_FILES_LOG_IMAGE_PATH_NA="Image path does exist!"
 PLG_TASK_CHECK_FILES_LOG_IMAGE_SAVE_FAIL="Failed to save image file"
 PLG_TASK_CHECK_FILES_LOG_RESIZE_FAIL="Failed to resize image due to an error in plugin logic..."
 PLG_TASK_CHECK_FILES_LOG_RESIZING_IMAGE="Found image of size %1$sx%2$s px; resizing to %3$sx%4$s px. File: %5$s"
-PLG_TASK_CHECK_FILES_TASK_IMAGE_SIZE_DESC="Check images, resize if larger than allowed."
+PLG_TASK_CHECK_FILES_TASK_IMAGE_SIZE_DESC="Check images, resize if larger than allowed. Attention: The original file will be overwritten!"
 PLG_TASK_CHECK_FILES_TASK_IMAGE_SIZE_TITLE="Image Size Check"
 PLG_TASK_CHECK_FILES_XML_DESCRIPTION="Offers task routines for checking for oversized files, and related actions if possible."
diff --git a/plugins/task/checkfiles/checkfiles.php b/plugins/task/checkfiles/checkfiles.php
index 44a77c1357ec..aab4d248b5ac 100644
--- a/plugins/task/checkfiles/checkfiles.php
+++ b/plugins/task/checkfiles/checkfiles.php
@@ -18,6 +18,7 @@
 use Joomla\Component\Scheduler\Administrator\Task\Status as TaskStatus;
 use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
 use Joomla\Event\SubscriberInterface;
+use Joomla\Filesystem\Path;
 
 /**
  * Task plugin with routines that offer checks on files.
@@ -77,9 +78,10 @@ protected function checkImages(ExecuteTaskEvent $event): int
 	{
 		$params = $event->getArgument('params');
 
-		$path      = JPATH_ROOT . '/images/' . $params->path;
+		$path      = Path::check(JPATH_ROOT . '/images/' . $params->path);
 		$dimension = $params->dimension;
 		$limit     = $params->limit;
+		$numImages = max(1, (int) $params->numImages ?? 1);
 
 		if (!Folder::exists($path))
 		{
@@ -112,7 +114,7 @@ protected function checkImages(ExecuteTaskEvent $event): int
 
 			try
 			{
-				$image->resize($newWidth, $newHeight);
+				$image->resize($newWidth, $newHeight, false);
 			}
 			catch (LogicException $e)
 			{
@@ -130,8 +132,13 @@ protected function checkImages(ExecuteTaskEvent $event): int
 				$this->logTask('PLG_TASK_CHECK_FILES_LOG_IMAGE_SAVE_FAIL', 'error');
 			}
 
-			// We do at most a single resize per execution
-			break;
+			--$numImages;
+
+			// We do a limited number of resize per execution
+			if ($numImages == 0)
+			{
+				break;
+			}
 		}
 
 		return TaskStatus::OK;
diff --git a/plugins/task/checkfiles/forms/image_size.xml b/plugins/task/checkfiles/forms/image_size.xml
index d4cd866bdc1e..4535ea69aebb 100644
--- a/plugins/task/checkfiles/forms/image_size.xml
+++ b/plugins/task/checkfiles/forms/image_size.xml
@@ -19,6 +19,7 @@
 				type="list"
 				label="PLG_TASK_CHECK_FILES_LABEL_IMAGE_DIMENSION"
 				required="true"
+				default="width"
 				>
 				<option value="width">JFIELD_MEDIA_WIDTH_LABEL</option>
 				<option value="height">JFIELD_MEDIA_HEIGHT_LABEL</option>
@@ -29,10 +30,21 @@
 				label="PLG_TASK_CHECK_FILES_LABEL_DIMENSION_LIMIT"
 				required="true"
 				default="1080"
-				min="100"
+				min="1"
 				step="1"
 				filter="int"
 			/>
+			<field
+				name="numImages"
+				type="number"
+				label="PLG_TASK_CHECK_FILES_LABEL_MAXIMAGES"
+				description="PLG_TASK_CHECK_FILES_LABEL_MAXIMAGES_DESC"
+				required="true"
+				min="1"
+				step="1"
+				default="1"
+				filter="int"
+			/>
 		</fieldset>
 	</fields>
 </form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants