Commit 8bf91fd2 authored by speedprogs_de's avatar speedprogs_de

added field to clear page cache after update to scheduler task, reset offset...

added field to clear page cache after update to scheduler task, reset offset if no more extensions were found

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51625 735d13b6-9817-0410-8766-e36946ffe9aa
parent 700a5d25
......@@ -90,7 +90,7 @@
foreach ($attributes as $key => $value) {
$propertyName = t3lib_div::underscoredToLowerCamelCase($key);
$protertyInfo = $classSchema->getProperty($propertyName);
if (empty($protertyInfo) || stripos($protertyInfo['type'], 'Tx_') !== FALSE) {
if (empty($protertyInfo) || stripos($protertyInfo['type'], 'Tx_') === 0) {
continue;
}
$value = $this->convertValue($value, $protertyInfo['type']);
......@@ -136,21 +136,16 @@
case 'int':
case 'integer':
return (int) $value;
break;
case 'float':
return (float) $value;
break;
case 'bool':
case 'boolean':
return (boolean) $value;
break;
case 'array':
return (array) $value;
break;
case 'string':
default:
return (string) $value;
break;
}
}
......
<?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!
******************************************************************/
/**
* Extension provider using local files
*/
class Tx_TerFe2_Object_ObjectBuilder implements t3lib_Singleton {
/**
* @var Tx_Extbase_Object_ObjectManager
*/
protected $objectManager;
/**
* @var Tx_Extbase_Reflection_Service
*/
protected $reflectionService;
/**
* @var Tx_Extbase_Persistence_Mapper_DataMapFactory
*/
protected $dataMapFactory;
/**
* @var Tx_Extbase_Persistence_Mapper_DataMapper
*/
protected $dataMapper;
/**
* @var Tx_Extbase_Persistence_Session
*/
protected $persistenceSession;
/**
* @var array
*/
protected $classSchemata;
/**
* @var array
*/
protected $objects;
/**
* Injects the reflection service
*
* @param Tx_Extbase_Reflection_Service $reflectionService
* @return void
*/
public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
$this->reflectionService = $reflectionService;
}
/**
* Injects the object manager
*
* @param Tx_Extbase_Object_ObjectManager $objectManager
* @return void
*/
public function injectObjectManager(Tx_Extbase_Object_ObjectManager $objectManager) {
$this->objectManager = $objectManager;
}
/**
* Injects the datamap factory
*
* @param Tx_Extbase_Persistence_Mapper_DataMapFactory $dataMapFactory
* @return void
*/
public function injectDataMapFactory(Tx_Extbase_Persistence_Mapper_DataMapFactory $dataMapFactory) {
$this->dataMapFactory = $dataMapFactory;
}
/**
* Injects the object storage
*
* @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
* @return void
*/
public function injectDataMapper(Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper) {
$this->dataMapper = $dataMapper;
}
/**
* Injects the persistence session
*
* @param Tx_Extbase_Persistence_Session $persistenceSession
* @return void
*/
public function injectPersistenceSession(Tx_Extbase_Persistence_Session $persistenceSession) {
$this->persistenceSession = $persistenceSession;
}
/**
* Create an object from given class and attributes
*
* @param string $className Name of the class
* @param string $identifier String to uniquely identify an object
* @param array $attributes Array of all class attributes
* @return Tx_Extbase_DomainObject_DomainObjectInterface Stored object
*/
public function create($className, $identifier, array $attributes) {
if (empty($className) || empty($identifier) || empty($attributes)) {
throw new Exception('No valid params given to create an object');
}
if (!empty($this->objects[$identifier])) {
return $this->objects[$identifier];
}
// Filter attributes
$classSchema = $this->getClassSchema($className);
foreach ($attributes as $key => $value) {
$propertyName = t3lib_div::underscoredToLowerCamelCase($key);
$proterty = $classSchema->getProperty($propertyName);
if (empty($proterty)) {
unset($attributes[$key]);
}
if (stripos($proterty['type'], 'Tx_') === 0) {
$attributes[$key] = $this->objectManager->get($proterty['type']);
}
}
// Build object
$object = reset($this->dataMapper->map($className, array($attributes)));
$this->objects[$identifier] = clone($object);
$this->persistenceSession->unregisterReconstitutedObject($object);
unset($object);
return $this->objects[$identifier];
}
/**
* Check if an object exists in storage
*
* @param string $identifier String to uniquely identify an object
* @return boolean TRUE if exists
*/
public function has($identifier) {
if (empty($identifier)) {
throw new Exception('No valid identifier given to check for an object');
}
return (!empty($this->objects[$identifier]));
}
/**
* Check if an stored object exists and has given class
*
* @param string $identifier String to uniquely identify an object
* @return boolean TRUE if exists
*/
public function hasClass($identifier, $className) {
if (empty($identifier) || empty($className)) {
throw new Exception('No valid identifier or class name given to check an object');
}
return ($this->getClass($identifier) === $className);
}
/**
* Return a stored object
*
* @param string $identifier String to uniquely identify an object
* @return Tx_Extbase_DomainObject_DomainObjectInterface Stored object
*/
public function get($identifier) {
if (empty($identifier)) {
throw new Exception('No valid identifier given to return an object');
}
if (!empty($this->objects[$identifier])) {
return $this->objects[$identifier];
}
return NULL;
}
/**
* Return the class of a stored object
*
* @param string $identifier String to uniquely identify an object
* @return string The class of a stored object
*/
public function getClass($identifier) {
if (empty($identifier)) {
throw new Exception('No valid identifier given to return an object class');
}
if (!empty($this->objects[$identifier])) {
return get_class($this->objects[$identifier]);
}
return '';
}
/**
* Returns all stored objects
*
* @return array All objects
*/
public function getAll() {
return $this->objects;
}
/**
* Remove a stored object
*
* @param string $identifier String to uniquely identify an object
* @return void
*/
public function remove($identifier) {
if (empty($identifier)) {
throw new Exception('No valid identifier given to remove an object');
}
unset($this->objects[$identifier]);
}
/**
* Remove all stored objects
*
* @return void
*/
public function removeAll() {
unset($this->objects);
}
/**
* Returns the schema of a class
*
* @param string $className Name of the class
* @return Tx_Extbase_Reflection_ClassSchema Class schema
*/
protected function getClassSchema($className) {
if (empty($className)) {
throw new Exception('No valid class name given to create a class schema');
}
if (empty($this->classSchemata[$className])) {
$this->classSchemata[$className] = $this->reflectionService->getClassSchema($className);
}
return $this->classSchemata[$className];
}
/**
* Convert value into correct type
*
* @param mixed $value Value to convert
* @param string $type Type of the conversation
* @return mixed Converted value
*/
protected function convertValue($value, $type) {
switch ($type) {
case 'int':
case 'integer':
return (int) $value;
break;
case 'float':
return (float) $value;
break;
case 'bool':
case 'boolean':
return (boolean) $value;
break;
case 'array':
return (array) $value;
break;
case 'string':
default:
return (string) $value;
break;
}
}
}
?>
\ No newline at end of file
......@@ -38,6 +38,11 @@
*/
public $providerName = 'extensionmanager';
/**
* @va string
*/
public $clearCachePages;
/**
* @var array
*/
......@@ -88,8 +93,8 @@
// Load object manager
$this->objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
// Load configuration manager and set extension setup
// required to be loaded in object manager for persistence mapping
// Load configuration manager and set extension setup,
// it is required to be loaded in object manager for persistence mapping
$configurationManager = $this->objectManager->get('Tx_Extbase_Configuration_ConfigurationManager');
$configurationManager->setConfiguration(Tx_TerFe2_Utility_TypoScript::getSetup('plugin.tx_terfe2'));
......@@ -98,6 +103,7 @@
// Load registry
$this->registry = $this->objectManager->get('Tx_TerFe2_Persistence_Registry');
$this->registry->setName(get_class($this) . '_' . $this->providerName);
// Load object builder
$this->objectBuilder = $this->objectManager->get('Tx_TerFe2_Object_ObjectBuilder');
......@@ -140,8 +146,14 @@
}
// Set new values to registry
$offset = (!empty($extensions) ? $offset + $count : 0);
$this->registry->add('lastRun', $GLOBALS['EXEC_TIME']);
$this->registry->add('offset', $offset + $count);
$this->registry->add('offset', $offset);
// Clear page cache
if (!empty($extensions) && !empty($this->clearCachePages)) {
$this->clearPageCache($this->clearCachePages);
}
return TRUE;
}
......@@ -160,6 +172,7 @@
if ($this->extensionRepository->countByExtKey($extensionRow['ext_key'])) {
$extension = $this->extensionRepository->findOneByExtKey($extensionRow['ext_key']);
} else {
// TODO: Remove this later, only existing extensions (created in FE) are allowed
$extension = $this->objectBuilder->create('Tx_TerFe2_Domain_Model_Extension', $extensionRow);
$extension->setLastUpload(new DateTime());
$extension->setLastMaintained(new DateTime());
......@@ -206,6 +219,18 @@
}
/**
* 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
*
......
......@@ -34,16 +34,22 @@
protected $defaultExtensionsPerRun = 10;
/**
* @var integer Default provider name
* @var string Default provider name
*/
protected $defaultProviderName = 'extensionmanager';
/**
* @var string Default clear cache pages
*/
protected $defaultClearCachePages = '';
/**
* @var array
*/
protected $fields = array(
'extensionsPerRun' => 'terfe2_updateExtensionList_extensionsPerRun',
'providerName' => 'terfe2_updateExtensionList_providerName',
'clearCachePages' => 'terfe2_updateExtensionList_clearCachePages',
);
......@@ -56,11 +62,14 @@
* @return array Array containing all the information pertaining to the additional fields
*/
public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $parentObject) {
// Initialize extensions per run field
if (!isset($taskInfo[$this->fields['extensionsPerRun']])) {
$taskInfo[$this->fields['extensionsPerRun']] = $this->defaultExtensionsPerRun;
if ($parentObject->CMD === 'edit') {
$taskInfo[$this->fields['extensionsPerRun']] = $task->extensionsPerRun;
// Initialize fields
foreach ($this->fields as $key => $value) {
if (!isset($taskInfo[$value])) {
$attribute = 'default' . ucfirst($key);
$taskInfo[$value] = $this->$attribute;
if ($parentObject->CMD === 'edit') {
$taskInfo[$value] = $task->$key;
}
}
}
......@@ -70,14 +79,6 @@
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang.xml:tx_terfe2_task_updateextensionlisttask.extensionsPerRun',
);
// Initialize provider name field
if (!isset($taskInfo[$this->fields['providerName']])) {
$taskInfo[$this->fields['providerName']] = $this->defaultProviderName;
if ($parentObject->CMD === 'edit') {
$taskInfo[$this->fields['providerName']] = $task->providerName;
}
}
// Add html structure for provider name field
$options = array();
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ter_fe2']['extensionProviders'])) {
......@@ -90,6 +91,12 @@
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang.xml:tx_terfe2_task_updateextensionlisttask.providerName',
);
// Add html structure for clear cache pages field
$additionalFields[$this->fields['clearCachePages']] = array(
'code' => '<input type="text" name="tx_scheduler[' . $this->fields['clearCachePages'] . ']" value="' . (int) $taskInfo[$this->fields['clearCachePages']] . '" />',
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang.xml:tx_terfe2_task_updateextensionlisttask.clearCachePages',
);
return $additionalFields;
}
......@@ -118,6 +125,7 @@
public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
$task->extensionsPerRun = (int) $submittedData[$this->fields['extensionsPerRun']];
$task->providerName = $submittedData[$this->fields['providerName']];
$task->clearCachePages = $submittedData[$this->fields['clearCachePages']];
}
......
......@@ -61,6 +61,7 @@
<label index="tx_terfe2_task_updateextensionlisttask.description">Get new extensions in ter directory</label>
<label index="tx_terfe2_task_updateextensionlisttask.extensionsPerRun">Count of extensions to process at once</label>
<label index="tx_terfe2_task_updateextensionlisttask.providerName">Fetch extensions from this source</label>
<label index="tx_terfe2_task_updateextensionlisttask.clearCachePages">Clear cache of these pages after update</label>
<label index="tx_terfe2_provider_extensionmanagerprovider.name">Local Extension Manager</label>
<label index="tx_terfe2_provider_fileprovider.name">Local Filesystem</label>
<label index="tx_terfe2_provider_soapprovider.name">SOAP Server</label>
......
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