[TASK] Improve code for IpAnonymization task and fix a typo 42/56942/3
authorMarkus Klein <markus.klein@typo3.org>
Sat, 12 May 2018 18:02:16 +0000 (20:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 13 May 2018 07:59:30 +0000 (09:59 +0200)
Resolves: #84986
Releases: master
Change-Id: Icd4a55386b6f17b0ba96872e213278998c6015f1
Reviewed-on: https://review.typo3.org/56942
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/scheduler/Classes/Task/IpAnonymizationTask.php

index bd5ef8b..b6063a8 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-
+declare(strict_types = 1);
 namespace TYPO3\CMS\Scheduler\Task;
 
 /*
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Scheduler\Task;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\IpAnonymizationUtility;
@@ -36,7 +37,7 @@ class IpAnonymizationTask extends AbstractTask
     public $numberOfDays = 180;
 
     /**
-     * @var int mask level
+     * @var int mask level see \TYPO3\CMS\Core\Utility\IpAnonymizationUtility::anonymizeIp
      */
     public $mask = 2;
 
@@ -53,18 +54,11 @@ class IpAnonymizationTask extends AbstractTask
      */
     public function execute()
     {
-        $tableConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][self::class]['options']['tables'];
-        $tableHandled = false;
-        foreach ($tableConfigurations as $tableName => $configuration) {
-            if ($tableName === $this->table) {
-                $this->handleTable($tableName, $configuration);
-                $tableHandled = true;
-            }
-        }
-
-        if (!$tableHandled) {
+        $configuration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][self::class]['options']['tables'][$this->table] ?? [];
+        if (empty($configuration)) {
             throw new \RuntimeException(self::class . ' misconfiguration: ' . $this->table . ' does not exist in configuration', 1524502548);
         }
+        $this->handleTable($this->table, $configuration);
         return true;
     }
 
@@ -90,7 +84,7 @@ class IpAnonymizationTask extends AbstractTask
         }
         $deleteTimestamp = strtotime('-' . $this->numberOfDays . 'days');
         if ($deleteTimestamp === false) {
-            throw new \RuntimeException(self::class . ' misconfiguration: number of days could not be calculcated for table ' . $table, 1524526354);
+            throw new \RuntimeException(self::class . ' misconfiguration: number of days could not be calculated for table ' . $table, 1524526354);
         }
         try {
             $result = $queryBuilder