Commit 9b0f69d0 authored by speedprogs_de's avatar speedprogs_de

added abstract task and field provider, added task to build zip archives from t3x files

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51701 735d13b6-9817-0410-8766-e36946ffe9aa
parent bc446217
<?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.xml';
/**
* 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) {
$this->values = get_object_vars($task);
$this->editMode = ($parentObject->CMD === 'edit');
$this->addInputField('elementsPerRun', 10);
$this->addInputField('clearCachePages', 0);
$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) {
$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) {
$result = $this->checkAdditionalFields($submittedData);
if (empty($result)) {
return FALSE;
}
return (!empty($submittedData['elementsPerRun']) && is_numeric($submittedData['elementsPerRun']));
}
/**
* 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 . ':tx_terfe2_task_' . $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 = Tx_Extbase_Utility_Localization::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 . ':tx_terfe2_task_' . $fieldName,
);
}
}
?>
\ No newline at end of file
<?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 = 10;
/**
* @var string
*/
public $clearCachePages = 0;
/**
* @var array
*/
protected $settings;
/**
* @var Tx_Extbase_Configuration_ConfigurationManager
*/
protected $configurationManager;
/**
* @var Tx_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 = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// Configuration is required to be loaded in object manager for persistence mapping
$this->settings = Tx_TerFe2_Utility_TypoScript::getSetup('plugin.tx_terfe2');
$this->configurationManager = $this->objectManager->get('Tx_Extbase_Configuration_ConfigurationManager');
$this->configurationManager->setConfiguration($this->settings);
// Load registry
$this->registry = $this->objectManager->get('Tx_TerFe2_Persistence_Registry');
$this->registry->setName(get_class($this));
// Initialize task
$this->initializeTask();
// Get process information
$lastRun = (int) $this->registry->get('lastRun');
$offset = (int) $this->registry->get('offset');
$count = (int) $this->elementsPerRun;
// Run task
$result = $this->executeTask($lastRun, $offset, $count);
// Add new values to registry
$offset = (!empty($result) ? $offset + $count : 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 = t3lib_div::intExplode(',', $pages, TRUE);
Tx_Extbase_Utility_Cache::clearPageCache($pages);
}
}
}
?>
\ No newline at end of file
<?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
*/
class Tx_TerFe2_Task_CreateZipArchivesTask extends Tx_TerFe2_Task_AbstractTask {
/**
* @var Tx_TerFe2_Domain_Repository_VersionRepository
*/
protected $versionRepository;
/**
* Initialize task
*
* @return void
*/
public function initializeTask() {
$this->versionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_VersionRepository');
}
/**
* 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) {
// TODO: Remove testing values
$lastRun = 1306920788;
$offset = 0;
// TODO: Implement functionality
return TRUE;
}
}
?>
\ No newline at end of file
<?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!
******************************************************************/
/**
* Additional field provider for the create zip archives task
*/
class Tx_TerFe2_Task_CreateZipArchivesTaskAdditionalFieldProvider extends Tx_TerFe2_Task_AbstractAdditionalFieldProvider {
/**
* Add some input fields to configure the task
*
* @return void
*/
protected function addAdditionalFields() {
// TODO: Implement functionality
}
/**
* Checks the given values
*
* @param array $submittedData Submitted user data
* @return boolean TRUE if validation was ok
*/
protected function checkAdditionalFields(array $submittedData) {
// TODO: Implement functionality
return TRUE;
}
}
?>
\ No newline at end of file
......@@ -26,48 +26,18 @@
/**
* Update extension list task
*/
class Tx_TerFe2_Task_UpdateExtensionListTask extends tx_scheduler_Task {
class Tx_TerFe2_Task_UpdateExtensionListTask extends Tx_TerFe2_Task_AbstractTask {
/**
* @var string
*/
public $providerName = 'extensionmanager';
/**
* @var integer
*/
public $extensionsPerRun = 10;
/**
* @va string
*/
public $clearCachePages;
/**
* @var array
*/
protected $settings;
/**
* @var Tx_Extbase_Configuration_ConfigurationManager
*/
protected $configurationManager;
/**
* @var Tx_Extbase_Object_ObjectManager
*/
protected $objectManager;
/**
* @var Tx_TerFe2_Provider_ProviderManager
*/
protected $providerManager;
/**
* @var Tx_TerFe2_Persistence_Registry
*/
protected $registry;
/**
* @var Tx_TerFe2_Object_ObjectBuilder
*/
......@@ -95,20 +65,11 @@
* @return void
*/
public function initializeTask() {
$this->objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// Configuration is required to be loaded in object manager for persistence mapping
$this->settings = Tx_TerFe2_Utility_TypoScript::getSetup('plugin.tx_terfe2');
$this->configurationManager = $this->objectManager->get('Tx_Extbase_Configuration_ConfigurationManager');
$this->configurationManager->setConfiguration($this->settings);
// Load default objects
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->registry = $this->objectManager->get('Tx_TerFe2_Persistence_Registry');
$this->objectBuilder = $this->objectManager->get('Tx_TerFe2_Object_ObjectBuilder');
$this->persistenceManager = $this->objectManager->get('Tx_Extbase_Persistence_Manager');
$this->providerManager = $this->objectManager->get('Tx_TerFe2_Provider_ProviderManager');
$this->objectBuilder = $this->objectManager->get('Tx_TerFe2_Object_ObjectBuilder');
$this->persistenceManager = $this->objectManager->get('Tx_Extbase_Persistence_Manager');
$this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionRepository');
$this->authorRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_AuthorRepository');
$this->authorRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_AuthorRepository');
// Set registry name to current provider name
$this->registry->setName(get_class($this) . '_' . $this->providerName);
......@@ -116,23 +77,19 @@
/**
* Public method, usually called by scheduler.
*
* 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
*/
public function execute() {
$this->initializeTask();
protected function executeTask($lastRun, $offset, $count) {
// Check storage page
if (!$this->storagePageConfigured()) {
throw new Exception('Please configure "plugin.tx_terfe2.persistence.storagePid" in TypoScript setup');
}
// Get process information
$lastRun = (int) $this->registry->get('lastRun');
$offset = (int) $this->registry->get('offset');
$count = (int) $this->extensionsPerRun;
// TODO: Remove testing values
$lastRun = 1306920788;
$offset = 0;
......@@ -148,17 +105,7 @@
}
}
// Add new values to registry
$offset = (!empty($extensions) ? $offset + $count : 0);
$this->registry->add('lastRun', $GLOBALS['EXEC_TIME']);
$this->registry->add('offset', $offset);
// Clear page cache
if (!empty($extensions) && !empty($this->clearCachePages)) {
$this->clearPageCache($this->clearCachePages);
}
return TRUE;
return !empty($extensions);
}
......@@ -241,18 +188,6 @@
}
/**
* Clear cache of given pages
*
* @param string $pages List of page ids
* @return void
*/
protected function clearPageCache($pages) {
$pages = t3lib_div::intExplode(',', $pages, TRUE);
Tx_Extbase_Utility_Cache::clearPageCache($pages);
}
/**
* Returns the name of selected extension provider
*
......
......@@ -26,130 +26,32 @@
/**
* Additional field provider for the update extension list task
*/
class Tx_TerFe2_Task_UpdateExtensionListTaskAdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider {
/**
* @var array
*/
protected $fields = array(
'providerName' => 'extensionmanager',
'extensionsPerRun' => 10,
'clearCachePages' => 0,
);
/**
* @var string
*/
protected $prefix = 'terfe2_updateExtensionList_';
class Tx_TerFe2_Task_UpdateExtensionListTaskAdditionalFieldProvider extends Tx_TerFe2_Task_AbstractAdditionalFieldProvider {
/**
* 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
* @return void
*/
public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) {
// Initialize fields
foreach ($this->fields as $key => $value) {
if (!isset($taskInfo[$value])) {
$taskInfo[$value] = $this->defaults[$key];
if ($parentObject->CMD === 'edit') {
$taskInfo[$value] = $this->fields[$key] = $task->$key;
}
}
}
// Get providers
protected function addAdditionalFields() {
$providers = array();
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ter_fe2']['extensionProviders'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ter_fe2']['extensionProviders'] as $key => $configuration) {
$providers[$key] = (!empty($configuration['title']) ? $configuration['title'] : $key);
}
}
// Build html structure
$fields = array();
$this->addSelect($fields, 'providerName', $providers);
$this->addField($fields, 'extensionsPerRun');
$this->addField($fields, 'clearCachePages');
return $fields;
$this->addSelectField('providerName', $providers, 'extensionmanager');
}
/**
* Checks the given values
*
* @param array $submittedData Reference to the array containing the data submitted by the user