Commit 68433e2d authored by speedprogs_de's avatar speedprogs_de

cleared old templates to rewrite, added more fields to abstract scheduler...

cleared old templates to rewrite, added more fields to abstract scheduler field provider, added experimental cache persistence

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51846 735d13b6-9817-0410-8766-e36946ffe9aa
parent 067d3979
......@@ -113,13 +113,13 @@
/**
* Add value
* Set value
*
* @param string $key Name of the value
* @param mixed $value Value content
* @return void
*/
public function add($key, $value) {
public function set($key, $value) {
if (empty($key)) {
throw new Exception('Empty keys are not allowed');
}
......@@ -133,6 +133,18 @@
}
/**
* Add value
*
* @param string $key Name of the value
* @param mixed $value Value content
* @return void
*/
public function add($key, $value) {
$this->set($key, $value);
}
/**
* Add multiple values
*
......
<?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!
******************************************************************/
/**
* Utilities to manage cache content
*/
class Tx_TerFe2_Persistence_Cache extends Tx_TerFe2_Persistence_AbstractPersistence {
/**
* @var t3lib_cache_frontend_Frontend
*/
protected $cacheFrontend;
/**
* Load content
*
* @return void
*/
public function load() {
if (!$this->isLoaded()) {
$this->cacheFrontend = $this->getCacheFrontend($this->name);
$this->setIsLoaded(TRUE);
}
}
/**
* Save content
*
* @return void
*/
public function save() {
// Cache entries are stored immii
}
/**
* Set entry
*
* @param string $key Name of the entry
* @param mixed $entry Entry content
* @param array $tags Tags for the entry
* @param integer $lifetime Lifetime of this cache entry in seconds
* @return void
*/
public function set($key, $entry, array $tags = array(), $lifetime = NULL) {
$this->checkKey($tag);
if (!$this->isLoaded()) {
$this->load();
}
$entry = json_encode($entry);
$this->cacheFrontend->set($key, $entry, $tags, $lifetime);
}
/**
* Add entry
*
* @param string $key Name of the entry
* @param mixed $entry Entry content
* @param array $tags Tags for the entry
* @param integer $lifetime Lifetime of this cache entry in seconds
* @return void
*/
public function add($key, $entry, array $tags = array(), $lifetime = NULL) {
$this->set($key, $entry, $tags, $lifetime);
}
/**
* Add multiple entrys
*
* @param array $entries Key <-> Value (Tags) (Lifetime)
* @return void
*/
public function addMultiple(array $entries) {
foreach ($entries as $key => $entry) {
$value = (!empty($entry['value']) ? $entry['value'] : '');
$tags = (!empty($entry['tags']) ? $entry['tags'] : array());
$lifetime = (!empty($entry['lifetime']) ? $entry['lifetime'] : NULL);
$this->add($key, $value, $tags, $lifetime);
}
}
/**
* Check if content contains given key
*
* @param string $key Name of the entry
* @return boolean TRUE if exists
*/
public function has($key) {
if (!$this->isLoaded()) {
$this->load();
}
$this->checkKey($key);
return $this->cacheFrontend->has($key);
}
/**
* Get entry
*
* @param string $key Name of the entry
* @return mixed Entry content
*/
public function get($key) {
if (!$this->isLoaded()) {
$this->load();
}
$this->checkKey($key);
$this->cacheFrontend->get($key);
}
/**
* Get all values
*
* @return array Key <-> value pairs
*/
public function getAll() {
throw new Exception('Method "getAll" is not supported in cache persistence');
}
/**
* Get all entries by tag
*
* @param string $tag Tag of the entry
* @return array Key <-> Value pairs
*/
public function getAllByTag($tag) {
if (!$this->isLoaded()) {
$this->load();
}
$this->checkTag($tag);
$this->cacheFrontend->getByTag($tag);
}
/**
* Remove a entry
*
* @param string $key Name of the entry
* @return void
*/
public function remove($key) {
if (!$this->isLoaded()) {
$this->load();
}
$this->checkKey($key);
$this->cacheFrontend->remove($key);
}
/**
* Remove all entries
*
* @return void
*/
public function removeAll() {
if (!$this->isLoaded()) {
$this->load();
}
$this->cacheFrontend->flush();
}
/**
* Remove all entries
*
* @param string $tag Tag of the entry
* @return void
*/
public function removeAllByTag($tag) {
if (!$this->isLoaded()) {
$this->load();
}
$this->checkTag($tag);
$this->cacheFrontend->flushByTag($tag);
}
/**
* Returns an instance of the cache frontend
*
* @param string $name Name of the cache to load
* @return Instance of the cache frontend
*/
public function getCacheFrontend($name) {
if (empty($name)) {
throw new Exception('Can not load caching frontend without a name');
}
t3lib_cache::initializeCachingFramework();
try {
return $GLOBALS['typo3CacheManager']->getCache($name);
} catch (t3lib_cache_exception_NoSuchCache $exception) {
if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name])) {
throw new Exception('A caching frontend with name "' . $name . '" is not configured');
}
return $GLOBALS['typo3CacheFactory']->create(
$name,
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['frontend'],
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['backend'],
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['options']
);
}
}
/**
* Check key
*
* @param string $key Key to check
* @return boolean TRUE if success
*/
protected function checkKey($key) {
if (empty($key) || !is_string($key)) {
throw new Exception('Only non-empty keys of type "string" are allowed');
}
return TRUE;
}
/**
* Check tag
*
* @param string $tag Tag to check
* @return boolean TRUE if success
*/
protected function checkTag($tag) {
if (empty($tag) || !is_string($tag)) {
throw new Exception('Only non-empty tags of type "string" are allowed');
}
return TRUE;
}
}
?>
\ No newline at end of file
......@@ -44,6 +44,16 @@
public function save();
/**
* Set value
*
* @param string $key Name of the value
* @param mixed $value Value content
* @return void
*/
public function set($key, $value);
/**
* Add value
*
......
......@@ -63,6 +63,8 @@
$this->addInputField('elementsPerRun', 10);
$this->addInputField('clearCachePages', 0);
$this->addDateField('forceLastRun', '');
$this->addInputField('forceOffset', '');
$this->addAdditionalFields();
return $this->structure;
......@@ -102,11 +104,19 @@
* @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)) {
if (!$this->checkAdditionalFields($submittedData)) {
return FALSE;
}
return (!empty($submittedData['elementsPerRun']) && is_numeric($submittedData['elementsPerRun']));
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;
}
......@@ -168,5 +178,51 @@
);
}
/**
* 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 . ':tx_terfe2_task_' . $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 = t3lib_iconWorks::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 . ':tx_terfe2_task_' . $fieldName,
);
}
}
?>
\ No newline at end of file
......@@ -38,6 +38,16 @@
*/
public $clearCachePages = 0;
/**
* @var integer
*/
public $forceLastRun = 0;
/**
* @var integer
*/
public $forceOffset = 0;
/**
* @var array
*/
......@@ -82,8 +92,16 @@
// Get process information
$lastRun = (int) $this->registry->get('lastRun');
$offset = (int) $this->registry->get('offset');
$count = (int) $this->elementsPerRun;
$offset = (int) $this->registry->get('offset');
$count = (int) $this->elementsPerRun;
// Force values
if (!empty($this->forceLastRun)) {
$lastRun = Tx_TerFe2_Utility_Datetime::getTimestampFromString($this->forceLastRun);
}
if (!empty($this->forceOffset)) {
$offset = (int) $this->forceOffset;
}
// Run task
$result = $this->executeTask($lastRun, $offset, $count);
......
<?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!
******************************************************************/
/**
* Utilities to manage dates and time
*/
class Tx_TerFe2_Utility_Datetime {
/**
* @var string
*/
protected $dateTimeFormat = 'H:i d-m-Y';
/**
* Set date / time format
*
* @param string $format Format of date / time
* @return void
*/
public static function setDateTimeFormat($format) {
$this->dateTimeFormat = $format;
}
/**
* Convert date / time string to timestamp
*
* @param string $string Date / time
* @return integer Unix timestamp
*/
public static function getTimestampFromString($string) {
// Try with strtotime
$timestamp = strtotime($string);
// Try TYPO3 standard date / time input format
if ($timestamp === FALSE) {
$timestamp = DateTime::createFromFormat($this->dateTimeFormat, $string);
}
// Try configured date / time input format
if ($timestamp === FALSE) {
$format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
$timestamp = DateTime::createFromFormat($format, $string);
}
// Try US date / time input format
if ($timestamp === FALSE || !empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'])) {
$format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ' m-d-Y';
$timestamp = DateTime::createFromFormat($format, $string);
}
return (int) $timestamp;
}
}
?>
\ No newline at end of file
......@@ -62,6 +62,8 @@
<label index="tx_terfe2_task_elementsPerRun">Element count to process at once</label>
<label index="tx_terfe2_task_clearCachePages">Clear cache of these pages after run</label>
<label index="tx_terfe2_task_forceLastRun">Force last run time</label>
<label index="tx_terfe2_task_forceOffset">Force offset</label>
<label index="tx_terfe2_task_providerName">Fetch extensions from this source</label>
<label index="tx_terfe2_task_zipFilePath">Relative path to zip file diretory</label>
<label index="tx_terfe2_task_updateextensionlisttask.name">Get new extensions</label>
......
<div class="tx_terfe2">
<div class="tx_terfe2_messages">
<f:flashMessages />
</div>
<div class="tx_terfe2_content">
<div class="tx_terfe2_main">
<f:render section="main" />
</div>
<div class="tx_terfe2_additional">
<f:render partial="QuickMenu"/>
</div>
<br class="tx_terfe2_clear" />
</div>
</div>
\ No newline at end of file
<div class="tx_terfe2">
<div class="tx_terfe2_messages">
<f:flashMessages />
</div>
<div class="tx_terfe2_content">
<div class="tx_terfe2_main">
<f:render section="main" />
</div>
<div class="tx_terfe2_additional">
<f:render partial="QuickMenu"/><br />
<h2><f:translate key="header.random_authors"/></h2>
<f:render partial="AuthorMenu" arguments="{authors: randomAuthors}"/><br />
<h2><f:translate key="header.categories"/></h2>
<f:render partial="CategoryMenu" arguments="{categories: categories}"/><br />
<h2><f:translate key="header.tags"/></h2>
<f:render partial="TagCloud" arguments="{tags: tags}"/><br />
</div>
<br class="tx_terfe2_clear" />
</div>
</div>
\ No newline at end of file
<f:if condition="{authors}">
<f:then>
<f:for each="{authors}" as="author">
<div class="tx_terfe2_author">
<h3>{author.name}</h3>
<p><f:link.action controller="Author" action="edit" arguments="{author : author}"><f:translate key="edit"/></f:link.action></p>
<p><f:link.action controller="Author" action="delete" arguments="{author : author}"><f:translate key="delete"/></f:link.action></p>
</div>
</f:for>
</f:then>
<f:else>
<f:translate key="msg.no_entries_found"/>
</f:else>