xperseguers / t3ext-image_autoresize

TYPO3 Extension image_autoresize. Simplify the way your editors may upload their images.
https://extensions.typo3.org/extension/image_autoresize
GNU General Public License v3.0
16 stars 22 forks source link

BUG: Execution of task failed with the following message: PHP Warning: Object of class TYPO3\CMS\Core\Type\ContextualFeedbackSeverity could not be converted to int in [...]/image_autoresize/Classes/Command/BatchResize.php line 231 #108

Closed bh-teufels closed 2 months ago

bh-teufels commented 4 months ago

BUG: Execution of task "4" failed with the following message: PHP Warning: Object of class TYPO3\CMS\Core\Type\ContextualFeedbackSeverity could not be converted to int in [...]/vendor/causal/image_autoresize/Classes/Command/BatchResize.php line 231

affected code:

if (version_compare((new Typo3Version())->getBranch(), '12.0', '>=')) {
    $severity = (int)$severity;
}

Debug: $severity =

TYPO3\CMS\Core\Type\ContextualFeedbackSeverityprototypeobject
   name => public 'WARNING' (7 chars)
   value => public 1 (integer)

caused by: Cast array to int not possible

environment: TYPO3 12.4.14 PHP 8.2.2 image_autoresize 2.4.1

xyng commented 2 months ago

Encountered the same problem. Possible patch:

Replace https://github.com/xperseguers/t3ext-image_autoresize/blob/0d59a886a16addc75cc74634957f909e2caa0498/Classes/Command/BatchResize.php#L229

With

$severity = is_int($severity) ? $severity : $severity->value;

Not sure if is_int is required.

Is the maintainer interested in a PR?

xperseguers commented 2 months ago

Is the maintainer interested in a PR?

of course :)

xperseguers commented 2 months ago

But the question would be to determine if $severity may actually get passed as integer value or not.

xyng commented 2 months ago

Thanks for your reply @xperseguers :-)

I think the callback is only called in the following file. There, for Typo3 >= 12, the enum is used. https://github.com/xperseguers/t3ext-image_autoresize/blob/0d59a886a16addc75cc74634957f909e2caa0498/Classes/Service/ImageResizer.php#L249

It's probably safe to assume $severity is of type ContextualFeedbackSeverity in this case. On the other hand, the variable is effectively of type mixed and safeguards like assert or is_int probably won't hurt performance in a way that matters.

In the end it's about preference. Which way do you prefer? I'm happy to send a pr for the option you like.

xperseguers commented 2 months ago

Since the code is really for TYPO3 v12 and the ext is supposed to be the only one invoking that method, or at least we should expect people using it to stick to proper typing, I prefer assuming it's the enum only so that we stop having "mixed" type asap.