Commit 0f8869ac authored by Thomas Löffler's avatar Thomas Löffler

[TASK] Removes registration for tasks and abstract task

parent 01c279c9
Pipeline #505 passed with stages
in 2 minutes and 37 seconds
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract additional field provider
*/
abstract class Tx_TerFe2_Task_AbstractAdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider
{
/**
* @var array
*/
protected $values = array();
/**
* @var boolean
*/
protected $editMode = FALSE;
/**
* @var array
*/
protected $structure = array();
/**
* @var string
*/
protected $languageFile = 'EXT:ter_fe2/Resources/Private/Language/locallang_db.xml';
/**
* @var string
*/
protected $labelPrefix = 'tx_terfe2_task_';
/**
* Add some input fields to configure the task
*
* @param array $taskInfo Reference to the array containing the info used in the add/edit form
* @param object $task When editing, reference to the current task object. Null when adding.
* @param tx_scheduler_Module $parentObject Reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
*/
public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject)
{
if (!empty($task)) {
$this->values = get_object_vars($task);
}
if (!empty($parentObject->CMD)) {
$this->editMode = ($parentObject->CMD === 'edit');
}
$this->addInputField('elementsPerRun', 10);
$this->addInputField('clearCachePages', 0);
$this->addDateField('forceLastRun', '');
$this->addInputField('forceOffset', '');
$this->addInputField('ignoreEmptyUntil', '');
$this->addAdditionalFields();
return $this->structure;
}
/**
* Add some input fields to configure the task
*
* @return void
*/
abstract protected function addAdditionalFields();
/**
* Saves given values into task object
*
* @param array $submittedData Contains data submitted by the user
* @param tx_scheduler_Task $task Reference to the current task object
* @return void
*/
public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task)
{
if (!empty($task)) {
$attributes = get_object_vars($task);
foreach ($attributes as $key => $value) {
if (isset($submittedData[$key])) {
$task->$key = $submittedData[$key];
}
}
}
}
/**
* Checks the given values
*
* @param array $submittedData Reference to the array containing the data submitted by the user
* @param tx_scheduler_Module $parentObject Reference to the calling object (Scheduler's BE module)
* @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
*/
public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $parentObject)
{
if (!$this->checkAdditionalFields($submittedData)) {
return FALSE;
}
if (empty($submittedData['elementsPerRun']) || !is_numeric($submittedData['elementsPerRun'])) {
return FALSE;
}
if (!empty($submittedData['forceLastRun']) && !is_string($submittedData['forceLastRun'])) {
return FALSE;
}
if (!empty($submittedData['forceOffset']) && !is_numeric($submittedData['forceOffset'])) {
return FALSE;
}
return TRUE;
}
/**
* Checks the given values
*
* @param array $submittedData Submitted user data
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData)
{
return TRUE;
}
/**
* Adds the structure of an input field
*
* @param string $fieldName Name of the field
* @param mixed $defaultValue Default value of the field
* @return void
*/
protected function addInputField($fieldName, $defaultValue = '')
{
if ($this->editMode && isset($this->values[$fieldName])) {
$defaultValue = $this->values[$fieldName];
}
$this->structure[$fieldName] = array(
'code' => '<input type="text" name="tx_scheduler[' . $fieldName . ']" value="' . htmlspecialchars($defaultValue) . '" />',
'label' => 'LLL:' . $this->languageFile . ':' . $this->labelPrefix . $fieldName,
);
}
/**
* Adds the structure of a select field
*
* @param string $fieldName Name of the field
* @param array $options Select options
* @param mixed $defaultValue Default value of the field
* @return void
*/
protected function addSelectField($fieldName, array $options, $defaultValue = '')
{
if ($this->editMode && isset($this->values[$fieldName])) {
$defaultValue = $this->values[$fieldName];
}
$html = array('<option></option>');
foreach ($options as $key => $option) {
$selected = ($key === $defaultValue ? ' selected="selected"' : '');
if ($key !== $option) {
$option = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($option, '');
}
$html[] = '<option value="' . htmlspecialchars($key) . '"' . $selected . '>' . htmlspecialchars($option) . '</option>';
}
$this->structure[$fieldName] = array(
'code' => '<select name="tx_scheduler[' . $fieldName . ']">' . implode(PHP_EOL, $html) . '</select>',
'label' => 'LLL:' . $this->languageFile . ':' . $this->labelPrefix . $fieldName,
);
}
/**
* Adds the structure of a checkbox field
*
* @param string $fieldName Name of the field
* @param mixed $defaultValue Default value of the field
* @return void
*/
protected function addCheckboxField($fieldName, $defaultValue = FALSE)
{
if ($this->editMode && isset($this->values[$fieldName])) {
$defaultValue = (bool)$this->values[$fieldName];
}
$this->structure[$fieldName] = array(
'code' => '<input type="checkbox" name="tx_scheduler[' . $fieldName . ']"' . ($defaultValue ? ' checked="checked"' : '') . ' />',
'label' => 'LLL:' . $this->languageFile . ':' . $this->labelPrefix . $fieldName,
);
}
/**
* Adds the structure of a date field
*
* @param string $fieldName Name of the field
* @param mixed $defaultValue Default value of the field
* @return void
*/
protected function addDateField($fieldName, $defaultValue = '')
{
if ($this->editMode && isset($this->values[$fieldName])) {
$defaultValue = $this->values[$fieldName];
}
$icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon(
'actions-edit-pick-date',
array(
'style' => 'cursor:pointer;',
'id' => 'picker-tceforms-datetimefield-' . $fieldName,
)
);
$this->structure[$fieldName] = array(
'code' => '<input type="text" name="tx_scheduler[' . $fieldName . ']" id="tceforms-datetimefield-' . $fieldName . '" value="' . htmlspecialchars($defaultValue) . '" />' . $icon,
'label' => 'LLL:' . $this->languageFile . ':' . $this->labelPrefix . $fieldName,
);
}
}
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract task
*/
abstract class Tx_TerFe2_Task_AbstractTask extends tx_scheduler_Task
{
/**
* @var integer
*/
public $elementsPerRun = 100;
/**
* @var string
*/
public $clearCachePages = 0;
/**
* @var string
*/
public $forceLastRun = '';
/**
* @var integer
*/
public $forceOffset = NULL;
/**
* @var integer
*/
public $ignoreEmptyUntil = NULL;
/**
* @var array
*/
protected $setup;
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
*/
protected $configurationManager;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected $objectManager;
/**
* @var Tx_TerFe2_Persistence_Registry
*/
protected $registry;
/**
* Public method, usually called by scheduler
*
* @return boolean TRUE on success
*/
public function execute()
{
// Load object manager
$this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
// Configuration is required to be loaded in object manager for persistence mapping
$this->setup = Tx_TerFe2_Utility_TypoScript::getSetup('plugin.tx_terfe2');
$this->configurationManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
$this->configurationManager->setConfiguration($this->setup);
// Load registry
$this->registry = $this->objectManager->get('Tx_TerFe2_Persistence_Registry');
$this->registry->setName(get_class($this));
// Initialize task
$this->initializeTask();
// Get process information
// temporary fix to get a consitent state on preview.typo3.org
$lastRun = 0;//(int) $this->registry->get('lastRun');
$offset = (int)$this->registry->get('offset');
$count = (int)$this->elementsPerRun;
// Force values
if (!empty($this->forceLastRun)) {
$lastRun = Tx_TerFe2_Utility_Datetime::getTimestampFromDate($this->forceLastRun);
}
if (is_numeric($this->forceOffset)) {
$offset = (int)$this->forceOffset;
}
// Run task
$result = $this->executeTask($lastRun, $offset, $count);
// Add new values to registry
if (!empty($result) || (!empty($this->ignoreEmptyUntil) && $offset < (int)$this->ignoreEmptyUntil)) {
$offset += $count;
} else {
$offset = 0;
}
$this->registry->add('lastRun', $GLOBALS['EXEC_TIME']);
$this->registry->add('offset', $offset);
// Clear page cache
if (!empty($result) && !empty($this->clearCachePages)) {
$this->clearPageCache($this->clearCachePages);
}
return TRUE;
}
/**
* Initialize task, override in concrete task
*
* @return void
*/
public function initializeTask()
{
}
/**
* Execute the task, implement in concrete task
*
* @param integer $lastRun Timestamp of the last run
* @param integer $offset Starting point
* @param integer $count Element count to process at once
* @return boolean TRUE on success
*/
abstract protected function executeTask($lastRun, $offset, $count);
/**
* Clear cache of given pages
*
* @param string $pages List of page ids
* @return void
*/
protected function clearPageCache($pages)
{
if (!empty($pages)) {
$pages = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $pages, TRUE);
/** @var \TYPO3\CMS\Extbase\Service\CacheService $cacheService */
$cacheService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Service\CacheService::class);
$cacheService->clearPageCache($pages);
}
}
/**
* Returns additional information
*
* @return string
*/
public function getAdditionalInformation()
{
// Load registry
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
$registry = $objectManager->get('Tx_TerFe2_Persistence_Registry');
$registry->setName(get_class($this));
// Get process information
$lastRun = (int)$registry->get('lastRun');
$offset = (int)$registry->get('offset');
return 'Offset: ' . $offset . ' ';
}
}
......@@ -58,37 +58,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$_EXTKEY]['extensionProviders']['soap'
),
);
// Register create zip archives task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_CreateExtensionFilesTask'] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_createextensionfilestask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_createextensionfilestask.description',
'additionalFields' => 'tx_terfe2_task_createextensionfilestaskadditionalfieldprovider',
);
// Register extension list update task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_UpdateExtensionListTask'] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_updateextensionlisttask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_updateextensionlisttask.description',
'additionalFields' => 'tx_terfe2_task_updateextensionlisttaskadditionalfieldprovider',
);
// Register update downloads task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_UpdateDetailsTask'] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_updatedetailstask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_updatedetailstask.description',
'additionalFields' => 'tx_terfe2_task_updatedetailstaskadditionalfieldprovider',
);
// Register download counter task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_DownloadCounterTask'] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_downloadcountertask.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_db.xml:tx_terfe2_task_downloadcountertask.description',
);
// Register import from queue task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_TerFe2_Task_ImportExtensionsFromQueueTask'] = array(
'extension' => $_EXTKEY,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment