[!!!][FEATURE] Added deleted field for scheduler task 56/51656/7
authorPascal Rinker <dj-pasi@freenet.de>
Mon, 13 Feb 2017 12:57:30 +0000 (13:57 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 3 Nov 2017 17:45:02 +0000 (18:45 +0100)
Add a deleted flag to database table "tx_scheduler_task".
Any task execution will also consider this field.

Resolves: #79777
Releases: master
Change-Id: I9f96ae9b255042ebf4ba3c812726cbf5ba4fa41c
Reviewed-on: https://review.typo3.org/51656
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Sommer <markus.sommer@typo3.org>
Tested-by: Markus Sommer <markus.sommer@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Breaking-79777-AddedDeletedColumnForSchedulerTasks.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-79777-AddedDeletedColumnForSchedulerTasks.rst [new file with mode: 0644]
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/Classes/Scheduler.php
typo3/sysext/scheduler/ext_tables.sql

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-79777-AddedDeletedColumnForSchedulerTasks.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-79777-AddedDeletedColumnForSchedulerTasks.rst
new file mode 100644 (file)
index 0000000..d98313e
--- /dev/null
@@ -0,0 +1,32 @@
+.. include:: ../../Includes.txt
+
+=================================================================
+Breaking: #79777 - EXT:scheduler - Deleted column for tasks added
+=================================================================
+
+See :issue:`79777`
+
+Description
+===========
+
+Instead of deleting the record directly in the database, a a "deleted" column was added for ``tx_scheduler_task``
+in a way to have developers / admins revive a task later-on.
+
+
+Impact
+======
+
+It is not possible to remove a task completely using the delete button in the scheduler module.
+
+Instead the "deleted" column will be set to 1 and the task won't show up in the backend module, and cannot
+be called via CLI anymore.
+
+
+Affected Installations
+======================
+
+If an extension is accessing the database table ``tx_scheduler_task`` directly, an additional `deleted=0` check
+needs to be added.
+
+
+.. index:: Backend, CLI, NotScanned
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-79777-AddedDeletedColumnForSchedulerTasks.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-79777-AddedDeletedColumnForSchedulerTasks.rst
new file mode 100644 (file)
index 0000000..ad56ca7
--- /dev/null
@@ -0,0 +1,15 @@
+.. include:: ../../Includes.txt
+
+================================================================
+Feature: #79777 - EXT:scheduler - Deleted column for tasks added
+================================================================
+
+See :issue:`79777`
+
+Description
+===========
+
+A reference to a previously deleted task is now kept in the database with a deleted=1 flag, in order to check
+historic calls on scheduler tasks.
+
+.. index:: Backend, NotScanned
index 1fc5649..f64bae8 100644 (file)
@@ -430,17 +430,11 @@ class SchedulerModuleController
                 }
             }
         } catch (\UnexpectedValueException $e) {
-            // The task could not be unserialized properly, simply delete the database record
-            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_scheduler_task');
-            $result = $queryBuilder->delete('tx_scheduler_task')
-                ->where(
-                    $queryBuilder->expr()->eq(
-                        'uid',
-                        $queryBuilder->createNamedParameter($this->submittedData['uid'], \PDO::PARAM_INT)
-                    )
-                )
-                ->execute();
-
+            // The task could not be unserialized properly, simply update the database record
+            $taskUid = (int)$this->submittedData['uid'];
+            $result = GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getConnectionForTable('tx_scheduler_task')
+                ->update('tx_scheduler_task', ['deleted' => 1], ['uid' => $taskUid]);
             if ($result) {
                 $this->addMessage($this->getLanguageService()->getLL('msg.deleteSuccess'));
             } else {
@@ -920,6 +914,9 @@ class SchedulerModuleController
                 'g',
                 $queryBuilder->expr()->eq('t.task_group', $queryBuilder->quoteIdentifier('g.uid'))
             )
+            ->where(
+                $queryBuilder->expr()->eq('t.deleted', 0)
+            )
             ->orderBy('g.sorting')
             ->execute();
 
index 5d42e14..e8428f8 100644 (file)
@@ -226,7 +226,7 @@ class Scheduler implements \TYPO3\CMS\Core\SingletonInterface
         if (!empty($taskUid)) {
             $result = GeneralUtility::makeInstance(ConnectionPool::class)
                 ->getConnectionForTable('tx_scheduler_task')
-                ->delete('tx_scheduler_task', ['uid' => $taskUid]);
+                ->update('tx_scheduler_task', ['deleted' => 1], ['uid' => $taskUid]);
         } else {
             $result = false;
         }
@@ -384,30 +384,28 @@ class Scheduler implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function fetchTasksWithCondition($where, $includeDisabledTasks = false)
     {
+        $tasks = [];
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable('tx_scheduler_task');
 
-        $constraints = [];
-        $tasks = [];
+        $queryBuilder
+            ->select('serialized_task_object')
+            ->from('tx_scheduler_task')
+            ->where(
+                $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
+            );
 
         if (!$includeDisabledTasks) {
-            $constraints[] = $queryBuilder->expr()->eq(
-                'disable',
-                $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
+            $queryBuilder->andWhere(
+                $queryBuilder->expr()->eq('disable', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
             );
-        } else {
-            $constraints[] = '1=1';
         }
 
         if (!empty($where)) {
-            $constraints[] = QueryHelper::stripLogicalOperatorPrefix($where);
+            $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($where));
         }
 
-        $result = $queryBuilder->select('serialized_task_object')
-            ->from('tx_scheduler_task')
-            ->where(...$constraints)
-            ->execute();
-
+        $result = $queryBuilder->execute();
         while ($row = $result->fetch()) {
             /** @var Task\AbstractTask $task */
             $task = unserialize($row['serialized_task_object']);
index cfe39c6..f0b26f9 100644 (file)
@@ -5,6 +5,7 @@ CREATE TABLE tx_scheduler_task (
        uid int(11) unsigned NOT NULL auto_increment,
        crdate int(11) unsigned DEFAULT '0' NOT NULL,
        disable tinyint(4) unsigned DEFAULT '0' NOT NULL,
+       deleted tinyint(4) unsigned DEFAULT '0' NOT NULL,
        description text,
        nextexecution int(11) unsigned DEFAULT '0' NOT NULL,
        lastexecution_time int(11) unsigned DEFAULT '0' NOT NULL,