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

TYPO3 11+php 8 : error in scheduler task #71

Closed dogawaf closed 1 year ago

dogawaf commented 1 year ago

Hello

On TYPO3 11+php 8, a warning is triggered, and crash the scheduler task in cli mode. This is caused by the undefined TYPO3_REQUEST in $_GLOBALS.

Fix proposal (don't know if they works in other setups)

ImageResizer.php
@@ -448,7 +460,8 @@
      */
     protected function localize(string $input): string
     {
-        if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
+        if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof \Psr\Http\Message\ServerRequestInterface
+            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
             $output = is_object($GLOBALS['TSFE']) ? $GLOBALS['TSFE']->sL($input) : $input;
         } else {
             $output = $GLOBALS['LANG']->sL($input);
Classes/Task/BatchResizeTask.php
@@ -151,7 +151,9 @@
         // actually resizing the image while uploading, not during a batch processing (it's simply "too late").
         $backendUser = null;

-        if (!ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() || PHP_SAPI === 'cli') {
+        if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof \Psr\Http\Message\ServerRequestInterface
+            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
+        || Environment::isCli()) {
             $callbackNotification = [$this, 'syslog'];
         } else {
             $callbackNotification = [$this, 'notify'];
xperseguers commented 1 year ago

This was fixed in the mean time.

I still will use Environment::isCli() instead of PHP_SAPI as it's more clean.