JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[4.1] Fix Image Size Check with scheduler #117

Closed joomlapl-bot closed 2 years ago

joomlapl-bot commented 2 years ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/36653 Poniżej zmiany w oryginale:

Click to expand the diff! ```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" > @@ -29,10 +30,21 @@ label="PLG_TASK_CHECK_FILES_LABEL_DIMENSION_LIMIT" required="true" default="1080" - min="100" + min="1" step="1" filter="int" /> + ```