[BUGFIX] Do not use doctrine constraints without bind values 62/52362/3
authorChrister Vindberg <cvi@systime.dk>
Tue, 4 Apr 2017 10:59:17 +0000 (12:59 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 6 Apr 2017 05:15:58 +0000 (07:15 +0200)
Changed so doctrine constraints without the corresponding
bind values aren't passed around.

The $constraints variable defined in CleanerTask->cleanTable
is reused in CleanerTask->deleteFilesForTable, but without
the doctrine createNamedParameter bind variables, since the
querybuilder is recreated. This caused the task to fail.

Resolves: #80675
Releases: master
Change-Id: I2da9b33f884f51bf9d90a9d08841fb4491eedea2
Reviewed-on: https://review.typo3.org/52362
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Thomas Hohn <thomas@hohn.dk>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/recycler/Classes/Task/CleanerTask.php

index acbd078..1bec478 100644 (file)
@@ -79,7 +79,7 @@ class CleanerTask extends AbstractTask
                     $queryBuilder->createNamedParameter($dateBefore, \PDO::PARAM_INT)
                 );
             }
-            $this->checkFileResourceFieldsBeforeDeletion($tableName, $constraints);
+            $this->checkFileResourceFieldsBeforeDeletion($tableName);
             try {
                 $queryBuilder->delete($tableName)
                     ->where(...$constraints)
@@ -167,13 +167,12 @@ class CleanerTask extends AbstractTask
      * Checks if the table has fields for uploaded files and removes those files.
      *
      * @param string $table
-     * @param array $constraints
      */
-    protected function checkFileResourceFieldsBeforeDeletion($table, array $constraints)
+    protected function checkFileResourceFieldsBeforeDeletion($table)
     {
         $fieldList = $this->getFileResourceFields($table);
         if (!empty($fieldList)) {
-            $this->deleteFilesForTable($table, $constraints, $fieldList);
+            $this->deleteFilesForTable($table, $fieldList);
         }
     }
 
@@ -181,14 +180,28 @@ class CleanerTask extends AbstractTask
      * Removes all files from the given field list in the table.
      *
      * @param string $table
-     * @param array $constraints
      * @param array $fieldList
      */
-    protected function deleteFilesForTable($table, array $constraints, array $fieldList)
+    protected function deleteFilesForTable($table, array $fieldList)
     {
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
         $queryBuilder->getRestrictions()->removeAll();
 
+        $constraints = [
+            $queryBuilder->expr()->eq(
+                $GLOBALS['TCA'][$table]['ctrl']['delete'],
+                $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
+            )
+        ];
+
+        if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) {
+            $dateBefore = $this->getPeriodAsTimestamp();
+            $constraints[] = $queryBuilder->expr()->lt(
+                $GLOBALS['TCA'][$table]['ctrl']['tstamp'],
+                $queryBuilder->createNamedParameter($dateBefore, \PDO::PARAM_INT)
+            );
+        }
+
         $result = $queryBuilder
             ->select(...$fieldList)
             ->from($table)