first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Scheduler\Example;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a task that sleeps for some time
|
||||
* This is useful for testing parallel executions
|
||||
* @internal This class is an example is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class SleepTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
|
||||
{
|
||||
/**
|
||||
* Number of seconds the task should be sleeping for
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $sleepTime = 10;
|
||||
|
||||
/**
|
||||
* Function executed from the Scheduler.
|
||||
* Goes to sleep ;-)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$time = 10;
|
||||
if (!empty($this->sleepTime)) {
|
||||
$time = $this->sleepTime;
|
||||
}
|
||||
sleep($time);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the sleep duration as additional information
|
||||
*
|
||||
* @return string Information to display
|
||||
*/
|
||||
public function getAdditionalInformation()
|
||||
{
|
||||
return $GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.sleepTime') . ': ' . $this->sleepTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Scheduler\Example;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
||||
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
|
||||
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
|
||||
use TYPO3\CMS\Scheduler\Task\AbstractTask;
|
||||
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
|
||||
|
||||
/**
|
||||
* Additional fields provider class for usage with the Scheduler's sleep task
|
||||
* @internal This class is an example is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class SleepTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvider
|
||||
{
|
||||
/**
|
||||
* This method is used to define new fields for adding or editing a task
|
||||
* In this case, it adds an sleep time field
|
||||
*
|
||||
* @param array $taskInfo Reference to the array containing the info used in the add/edit form
|
||||
* @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
|
||||
* @param SchedulerModuleController $schedulerModule 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, SchedulerModuleController $schedulerModule)
|
||||
{
|
||||
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
|
||||
|
||||
// Initialize extra field value
|
||||
if (empty($taskInfo['sleepTime'])) {
|
||||
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
|
||||
// In case of new task and if field is empty, set default sleep time
|
||||
$taskInfo['sleepTime'] = 30;
|
||||
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
|
||||
// In case of edit, set to internal value if no data was submitted already
|
||||
$taskInfo['sleepTime'] = $task->sleepTime;
|
||||
} else {
|
||||
// Otherwise set an empty value, as it will not be used anyway
|
||||
$taskInfo['sleepTime'] = '';
|
||||
}
|
||||
}
|
||||
// Write the code for the field
|
||||
$fieldID = 'task_sleepTime';
|
||||
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[sleepTime]" id="' . $fieldID . '" value="' . $taskInfo['sleepTime'] . '" size="10">';
|
||||
$additionalFields = [];
|
||||
$additionalFields[$fieldID] = [
|
||||
'code' => $fieldCode,
|
||||
'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.sleepTime',
|
||||
'cshKey' => '_MOD_system_txschedulerM1',
|
||||
'cshLabel' => $fieldID
|
||||
];
|
||||
return $additionalFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks any additional data that is relevant to the specific task
|
||||
* If the task class is not relevant, the method is expected to return TRUE
|
||||
*
|
||||
* @param array $submittedData Reference to the array containing the data submitted by the user
|
||||
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
|
||||
* @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
|
||||
*/
|
||||
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
|
||||
{
|
||||
$submittedData['sleepTime'] = (int)$submittedData['sleepTime'];
|
||||
if ($submittedData['sleepTime'] < 0) {
|
||||
$this->addMessage($GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidSleepTime'), FlashMessage::ERROR);
|
||||
$result = false;
|
||||
} else {
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to save any additional input into the current task object
|
||||
* if the task class matches
|
||||
*
|
||||
* @param array $submittedData Array containing the data submitted by the user
|
||||
* @param AbstractTask $task Reference to the current task object
|
||||
*/
|
||||
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
|
||||
{
|
||||
$task->sleepTime = $submittedData['sleepTime'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Scheduler\Example;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Provides testing procedures
|
||||
* @internal This class is an example is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class TestTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
|
||||
{
|
||||
/**
|
||||
* An email address to be used during the process
|
||||
*
|
||||
* @var string $email
|
||||
*/
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* Function executed from the Scheduler.
|
||||
* Sends an email
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$success = false;
|
||||
if (!empty($this->email)) {
|
||||
// If an email address is defined, send a message to it
|
||||
$this->logger->info('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: Test email sent to "' . $this->email . '"');
|
||||
// Get execution information
|
||||
$exec = $this->getExecution();
|
||||
// Get call method
|
||||
if (Environment::isCli()) {
|
||||
$calledBy = 'CLI module dispatcher';
|
||||
$site = '-';
|
||||
} else {
|
||||
$calledBy = 'TYPO3 backend';
|
||||
$site = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
|
||||
}
|
||||
$start = $exec->getStart();
|
||||
$end = $exec->getEnd();
|
||||
$interval = $exec->getInterval();
|
||||
$multiple = $exec->getMultiple();
|
||||
$cronCmd = $exec->getCronCmd();
|
||||
$mailBody = 'SCHEDULER TEST-TASK' . LF . '- - - - - - - - - - - - - - - -' . LF . 'UID: ' . $this->taskUid . LF . 'Sitename: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . LF . 'Site: ' . $site . LF . 'Called by: ' . $calledBy . LF . 'tstamp: ' . date('Y-m-d H:i:s') . ' [' . time() . ']' . LF . 'maxLifetime: ' . $this->scheduler->extConf['maxLifetime'] . LF . 'start: ' . date('Y-m-d H:i:s', $start) . ' [' . $start . ']' . LF . 'end: ' . (empty($end) ? '-' : date('Y-m-d H:i:s', $end) . ' [' . $end . ']') . LF . 'interval: ' . $interval . LF . 'multiple: ' . ($multiple ? 'yes' : 'no') . LF . 'cronCmd: ' . ($cronCmd ? $cronCmd : 'not used');
|
||||
// Prepare mailer and send the mail
|
||||
try {
|
||||
/** @var \TYPO3\CMS\Core\Mail\MailMessage $mailer */
|
||||
$mailer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
|
||||
$mailer->setFrom([$this->email => 'SCHEDULER TEST-TASK']);
|
||||
$mailer->setReplyTo([$this->email => 'SCHEDULER TEST-TASK']);
|
||||
$mailer->setSubject('SCHEDULER TEST-TASK');
|
||||
$mailer->setBody($mailBody);
|
||||
$mailer->setTo($this->email);
|
||||
$mailsSend = $mailer->send();
|
||||
$success = $mailsSend > 0;
|
||||
} catch (\Exception $e) {
|
||||
throw new \TYPO3\CMS\Core\Exception($e->getMessage(), 1476048416);
|
||||
}
|
||||
} else {
|
||||
// No email defined, just log the task
|
||||
$this->logger->warning('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: No email address given');
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the destination mail address as additional information
|
||||
*
|
||||
* @return string Information to display
|
||||
*/
|
||||
public function getAdditionalInformation()
|
||||
{
|
||||
return $GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email') . ': ' . $this->email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Scheduler\Example;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
||||
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
|
||||
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
|
||||
use TYPO3\CMS\Scheduler\Task\AbstractTask;
|
||||
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
|
||||
|
||||
/**
|
||||
* Additional fields provider class for usage with the Scheduler's test task
|
||||
* @internal This class is an example is not considered part of the Public TYPO3 API.
|
||||
*/
|
||||
class TestTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvider
|
||||
{
|
||||
/**
|
||||
* This method is used to define new fields for adding or editing a task
|
||||
* In this case, it adds an email field
|
||||
*
|
||||
* @param array $taskInfo Reference to the array containing the info used in the add/edit form
|
||||
* @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
|
||||
* @param SchedulerModuleController $schedulerModule 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, SchedulerModuleController $schedulerModule)
|
||||
{
|
||||
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
|
||||
|
||||
// Initialize extra field value
|
||||
if (empty($taskInfo['email'])) {
|
||||
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
|
||||
// In case of new task and if field is empty, set default email address
|
||||
$taskInfo['email'] = $GLOBALS['BE_USER']->user['email'];
|
||||
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
|
||||
// In case of edit, and editing a test task, set to internal value if not data was submitted already
|
||||
$taskInfo['email'] = $task->email;
|
||||
} else {
|
||||
// Otherwise set an empty value, as it will not be used anyway
|
||||
$taskInfo['email'] = '';
|
||||
}
|
||||
}
|
||||
// Write the code for the field
|
||||
$fieldID = 'task_email';
|
||||
$fieldCode = '<input type="text" class="form-control" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['email']) . '" size="30">';
|
||||
$additionalFields = [];
|
||||
$additionalFields[$fieldID] = [
|
||||
'code' => $fieldCode,
|
||||
'label' => 'LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email',
|
||||
'cshKey' => '_MOD_system_txschedulerM1',
|
||||
'cshLabel' => $fieldID
|
||||
];
|
||||
return $additionalFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks any additional data that is relevant to the specific task
|
||||
* If the task class is not relevant, the method is expected to return TRUE
|
||||
*
|
||||
* @param array $submittedData Reference to the array containing the data submitted by the user
|
||||
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
|
||||
* @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
|
||||
*/
|
||||
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
|
||||
{
|
||||
$submittedData['email'] = trim($submittedData['email']);
|
||||
if (empty($submittedData['email'])) {
|
||||
$this->addMessage(
|
||||
$GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.noEmail'),
|
||||
FlashMessage::ERROR
|
||||
);
|
||||
$result = false;
|
||||
} else {
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to save any additional input into the current task object
|
||||
* if the task class matches
|
||||
*
|
||||
* @param array $submittedData Array containing the data submitted by the user
|
||||
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
|
||||
*/
|
||||
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
|
||||
{
|
||||
$task->email = $submittedData['email'];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user