Commit 4f3d290a authored by Thorsten Griebenow's avatar Thorsten Griebenow

Merge branch '74-remove-obsolete-tasks' into 'develop'

Resolve "Remove obsolete tasks"

Closes #74

See merge request !69
parents 48163d04 0f8869ac
Pipeline #512 passed with stages
in 5 minutes and 41 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 . ' ';
}
}
<?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!
******************************************************************/
/**
* Create zip archives from t3x files and generate images
*/
class Tx_TerFe2_Task_CreateExtensionFilesTask extends Tx_TerFe2_Task_AbstractTask
{
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
*/
protected $versionRepository;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
*/
protected $persistenceManager;
/**
* @var string
*/
protected $mediaRootPath = '';
/**
* @var array
*/
protected $imageSizes = array('small', 'large');
/**
* Initialize task
*
* @return void
*/
public function initializeTask()
{
$this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository');
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
if (empty($this->setup['settings.']['mediaRootPath'])) {
throw new Exception('Please configure "plugin.tx_terfe2.settings.mediaRootPath" in TypoScript setup');
}
$this->mediaRootPath = $this->setup['settings.']['mediaRootPath'];
}
/**
* Execute the 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
*/
protected function executeTask($lastRun, $offset, $count)
{
// Get all unprocessed versions
$versions = $this->versionRepository->findForMediaCreation($offset, $count);
if ($versions->count() === 0) {
return FALSE;
}
// Simulate working directory "htdocs", required for file_exists check
// in \TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions
$currentDir = getcwd();
chdir(PATH_site);
// Create ZIP file only for last version
$lastVersionOnly = !empty($this->setup['settings.']['onlyLatestVersionZip']);
foreach ($versions as $version) {
// Get media path for the extension
$extKey = $version->getExtension()->getExtKey();
$lastVersion = $version->getExtension()->getLastVersion();
$extensionMediaPath = Tx_TerFe2_Utility_File::getAbsoluteDirectory($this->mediaRootPath . $extKey);
// Create zip file
if (!$lastVersionOnly || ($lastVersion === $version)) {
$zipFile = $this->createZipFile($version, $extensionMediaPath);
if (!empty($zipFile)) {
$version->setZipFileSize(filesize($zipFile));
$version->setHasZipFile(TRUE);
}
}
// Create images
if ($this->createImages($version, $extensionMediaPath)) {
$version->setHasImages(TRUE);
}
$this->persistenceManager->persistAll();
}
// Revert working directory
chdir($currentDir);
return TRUE;
}
/**
* Create a zip file for given version
*
* @param Tx_TerFe2_Domain_Model_Version $version Path to t3x file
* @param string $extensionMediaPath Path to media files
* @return string Name of the zip file
*/
protected function createZipFile(Tx_TerFe2_Domain_Model_Version $version, $extensionMediaPath)
{
if (empty($extensionMediaPath)) {
return '';
}
$provider = $this->providerManager->getProvider($version->getExtensionProvider());
$t3xFileName = $provider->getFileUrl($version, 't3x');