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 #2222

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

[4.1] Fix Image Size Check with scheduler #2222

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

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#36653 Here are the upstream changes:

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>
tecpromotion added a commit to tecpromotion/joomla that referenced this issue Jan 15, 2022
tecpromotion added a commit to tecpromotion/joomla that referenced this issue Jan 15, 2022
@tecpromotion tecpromotion added this to the 4.1.0.v1 milestone Jan 15, 2022
zero-24 added a commit that referenced this issue Jan 15, 2022
* add new files and new strings

* fix #2157

* fix #2160

* fix #2158

* fix #2159

* fix #2161

* fix #2170

add two new strings

* fix #2171

* fix #2172

* fix #2173

* add translation plg_task_checkfiles

* add translation plg_task_demotask

* translation part 1

* fix #2179

* fix #2175

* fix #2196

* fix #2195

* just happy new year head

* translation plg_system_schedulerunner

* translation plg_system_tasknotification

* translation plg_task_requests

* language style

* translation plg_task_sitestatus

* translation plg_actionlog_joomla

* sounds better

* sounds nicer

* Update administrator/language/de-DE/plg_system_tasknotification.ini

thanks @zero-24

Co-authored-by: Tobias Zulauf <[email protected]>

* fix output

* language style

* fix #2220

* add new strings #2222

* fix #2222

* Update administrator/language/de-DE/com_scheduler.ini

Co-authored-by: Tobias Zulauf <[email protected]>

Co-authored-by: Tobias Zulauf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants