[BUGFIX] Disabled empty number of days field in table garbage
authorKai Vogel <kai.vogel@speedprogs.de>
Tue, 21 Jun 2011 21:57:49 +0000 (23:57 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 23 Jun 2011 20:00:15 +0000 (22:00 +0200)
collection scheduler task

This patch reactivates the number of days field even if it is
empty if a default number is provided by the selected table.

Change-Id: I58afb4f9c9430802477fd93d8b387497e1dd698b
Resolves: #27632
Reviewed-on: http://review.typo3.org/2868
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/scheduler/res/tx_scheduler_be.js
typo3/sysext/scheduler/tasks/class.tx_scheduler_tablegarbagecollection.php
typo3/sysext/scheduler/tasks/class.tx_scheduler_tablegarbagecollection_additionalfieldprovider.php

index cd8d668..546d1da 100644 (file)
@@ -93,8 +93,17 @@ function actOnChangeSchedulerTableGarbageCollectionAllTables(theCheckbox) {
                Ext.fly('task_tableGarbageCollection_table').set({disabled: 'disabled'});
                Ext.fly('task_tableGarbageCollection_numberOfDays').set({disabled: 'disabled'});
        } else {
+                       // Get number of days for selected table
+               var numberOfDays = Ext.fly('task_tableGarbageCollection_numberOfDays').getValue();
+               if (numberOfDays < 1) {
+                       var selectedTable = Ext.fly('task_tableGarbageCollection_table').getValue();
+                       if (typeof(defaultNumberOfDays[selectedTable]) != 'undefined') {
+                               numberOfDays = defaultNumberOfDays[selectedTable];
+                       }
+               }
+
                Ext.fly('task_tableGarbageCollection_table').dom.removeAttribute('disabled');
-               if (Ext.fly('task_tableGarbageCollection_numberOfDays').getValue() > 0) {
+               if (numberOfDays > 0) {
                        Ext.fly('task_tableGarbageCollection_numberOfDays').dom.removeAttribute('disabled');
                }
        }
index 99dbda1..a68ac82 100644 (file)
@@ -84,16 +84,16 @@ class tx_scheduler_TableGarbageCollection extends tx_scheduler_Task {
         * @throws RuntimeException If table configuration is broken
         * @param string $table The table to handle
         * @param array $configuration Clean up configuration
-        * @return void
+        * @return boolean TRUE if cleanup was successful
         */
        protected function handleTable($table, array $configuration) {
-               if (isset($configuration['expireField'])) {
+               if (!empty($configuration['expireField'])) {
                        $field = $configuration['expireField'];
                        $dateLimit = $GLOBALS['EXEC_TIME'];
                                // If expire field value is 0, do not delete
                                // Expire field = 0 means no expiration
                        $where = $field . " <= '" . $dateLimit . "' AND " . $field . " > '0'";
-               } elseif (isset($configuration['dateField'])) {
+               } elseif (!empty($configuration['dateField'])) {
                        $field = $configuration['dateField'];
                        if (!$this->allTables) {
                                $deleteTimestamp = strtotime('-' . $this->numberOfDays . 'days');
index a72e28e..6ee1065 100644 (file)
 class tx_scheduler_TableGarbageCollection_AdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider {
 
        /**
+        * @var array Default number of days by table
+        */
+       protected $defaultNumberOfDays = array();
+
+       /**
         * Add addional fields
         *
         * @param array $taskInfo Reference to the array containing the info used in the add/edit form
@@ -40,6 +45,7 @@ class tx_scheduler_TableGarbageCollection_AdditionalFieldProvider implements tx_
         * @return array Array containing all the information pertaining to the additional fields
         */
        public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) {
+               $this->initDefaultNumberOfDays();
                $additionalFields['task_tableGarbageCollection_allTables'] = $this->getAllTablesAdditionalField($taskInfo, $task, $parentObject);
                $additionalFields['task_tableGarbageCollection_table'] = $this->getTableAdditionalField($taskInfo, $task, $parentObject);
                $additionalFields['task_tableGarbageCollection_numberOfDays'] = $this->getNumberOfDaysAdditionalField($taskInfo, $task, $parentObject);
@@ -48,6 +54,20 @@ class tx_scheduler_TableGarbageCollection_AdditionalFieldProvider implements tx_
        }
 
        /**
+        * Initialize the default number of days for all configured tables
+        * 
+        * @return void
+        */
+       protected function initDefaultNumberOfDays() {
+               $tableConfiguration = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_scheduler_TableGarbageCollection']['options']['tables'];
+               foreach ($tableConfiguration as $tableName => $configuration) {
+                       if (isset($configuration['expirePeriod'])) {
+                               $this->defaultNumberOfDays[$tableName] = $configuration['expirePeriod'];
+                       }
+               }
+       }
+
+       /**
         * Add a select field of available tables.
         *
         * @param array $taskInfo Reference to the array containing the info used in the add/edit form
@@ -99,25 +119,15 @@ class tx_scheduler_TableGarbageCollection_AdditionalFieldProvider implements tx_
                        $options[] = '<option value="" selected="selected"></option>';
                }
 
-               $defaultNumberOfDays = array();
                foreach ($tableConfiguration as $tableName => $configuration) {
                        if ($parentObject->CMD === 'add' && count($options) === 0) {
                                        // Select first table by default if adding a new task
                                $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
-                               if (isset($configuration['expirePeriod'])) {
-                                       $defaultNumberOfDays[$tableName] = $configuration['expirePeriod'];
-                               }
                        } elseif ($task->table === $tableName) {
                                        // Select currently selected table
                                $options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
-                               if (isset($configuration['expirePeriod'])) {
-                                       $defaultNumberOfDays[$tableName] = $task->numberOfDays;
-                               }
                        } else {
                                $options[] = '<option value="' . $tableName . '">' . $tableName . '</option>';
-                               if (isset($configuration['expirePeriod'])) {
-                                       $defaultNumberOfDays[$tableName] = $configuration['expirePeriod'];
-                               }
                        }
                }
 
@@ -137,7 +147,7 @@ class tx_scheduler_TableGarbageCollection_AdditionalFieldProvider implements tx_
                        '</select>';
                        // Add js array for default 'number of days' values
                $fieldHtml[] = '<script type="text/javascript">/*<![CDATA[*/<!--';
-               $fieldHtml[] = 'var defaultNumberOfDays = ' . json_encode($defaultNumberOfDays) . ';';
+               $fieldHtml[] = 'var defaultNumberOfDays = ' . json_encode($this->defaultNumberOfDays) . ';';
                $fieldHtml[] = '// -->/*]]>*/</script>';
 
                $fieldConfiguration = array(
@@ -168,7 +178,7 @@ class tx_scheduler_TableGarbageCollection_AdditionalFieldProvider implements tx_
                        } elseif ($parentObject->CMD === 'edit') {
                                        // In case of editing the task, set to currently selected value
                                $taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = $task->numberOfDays;
-                               if ($task->numberOfDays === 0) {
+                               if ($task->numberOfDays === 0 && !isset($this->defaultNumberOfDays[$task->table])) {
                                        $disabled = ' disabled="disabled"';
                                }
                        }