CodersCare / l10nmgr

GNU General Public License v3.0
0 stars 9 forks source link

Localizationteam\L10nmgr\Task\L10nmgrFileGarbageCollection::execute() must be of the type bool, int returned #17

Closed mohammad-sarwar closed 1 year ago

mohammad-sarwar commented 1 year ago

Hello,

we currently got the problem that we get a TypeError when we execute the file garbage collection scheduler task. After some debugging we found that error comes with the new version 11.0. Specifically in l10nmgr/Classes/Task/L10nmgrFileGarbageCollection.php:3 =>

declare(strict_types=1);

As the types are checked strictly now the execute() function throws the mentioned error:

    /**
     * Removes old files, called by the Scheduler.
     *
     * @return bool TRUE if task run was successful
     * @throws Exception
     */
    public function execute(): bool
    {
        // There is no file ctime on windows, so this task disables itself if OS = win
        if (Environment::isWindows()) {
            throw new Exception('This task is not reliable on Windows OS', 1323272367);
        }
        // Calculate a reference timestamp, based on age of files to delete
        $seconds = (60 * 60 * 24 * $this->age);
        $timestamp = (($GLOBALS['EXEC_TIME'] ?? 0) - $seconds);
        // Loop on all target directories
        $globalResult = true;
        foreach (self::$targetDirectories as $directory) {
            $result = $this->cleanUpDirectory($directory, $timestamp);
            $globalResult &= $result;
        }
        // Return the global result, which is a success only if all directories could be cleaned up without problem
        return $globalResult;
    }

$globalResult &= $result; is using a bitwise operator. So we always get an Integer as value here and not the declared bool as return value.

We patched the extension currently by casting $gobalResult as a bool. That might not be the best solution and it would be awesome if you could provide a solution/fix for this.

Patch:

Index: Classes/Task/L10nmgrFileGarbageCollection.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/public/typo3conf/ext/l10nmgr/Classes/Task/L10nmgrFileGarbageCollection.php b/public/typo3conf/ext/l10nmgr/Classes/Task/L10nmgrFileGarbageCollection.php
--- a/Classes/Task/L10nmgrFileGarbageCollection.php
+++ b/Classes/Task/L10nmgrFileGarbageCollection.php (date 1687431622089)
@@ -81,7 +81,7 @@
             $globalResult &= $result;
         }
         // Return the global result, which is a success only if all directories could be cleaned up without problem
-        return $globalResult;
+        return (bool)$globalResult;
     }

     /**

Thank you!

Our site is running with TYPO3 10 and PHP 7.4

Kind regards Mo

Konafets commented 1 year ago

Hi @mohammad-sarwar,

~please make sure, that you use version 10.2.1 of localizationteam/l10nmgr. Version 11 is not compatible with TYPO3 v10.~

mohammad-sarwar commented 1 year ago

But it says it's compatible in the composer.json, ext_emconf.php and on https://extensions.typo3.org/extension/l10nmgr 😅 That's why updated it in the first place. But okay good to know thank you.

Konafets commented 1 year ago

I was a bit too fast with my answer. You are right: v11 is supposed to work with TYPO3 v10 and the bitwise operator returns 0 or 1 as integer but not as a boolean.