TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MyVendor\MyExtension\Task;
|
||||
|
||||
use MyVendor\MyExtension\BusinessLogic;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Scheduler\Task\AbstractTask;
|
||||
|
||||
final class MyTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* MUST be implemented by all tasks
|
||||
*/
|
||||
public function execute(): bool
|
||||
{
|
||||
# Dependency injection cannot be used in scheduler tasks
|
||||
$businessLogic = GeneralUtility::makeInstance(BusinessLogic::class);
|
||||
return $businessLogic->run('arg1', 'arg2', '…');
|
||||
}
|
||||
|
||||
public function getAdditionalInformation()
|
||||
{
|
||||
$this->getLanguageService()->sL('LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myTaskInformation');
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MyVendor\MyExtension\Task;
|
||||
|
||||
use MyVendor\MyExtension\BusinessLogic;
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessageService;
|
||||
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Scheduler\Task\AbstractTask;
|
||||
|
||||
final class MyTask extends AbstractTask
|
||||
{
|
||||
protected string $myField = '';
|
||||
protected string $emailList = '';
|
||||
|
||||
public function execute(): bool
|
||||
{
|
||||
# Dependency injection cannot be used in scheduler tasks
|
||||
$businessLogic = GeneralUtility::makeInstance(BusinessLogic::class);
|
||||
return $businessLogic->run($this->myField, $this->emailList, '…');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set field values from associative array.
|
||||
*
|
||||
* @param array $parameters Values from TCA fields
|
||||
*/
|
||||
public function setTaskParameters(array $parameters): void
|
||||
{
|
||||
$this->myField = $parameters['my_extension_field'] ?? '';
|
||||
$this->emailList = $parameters['my_extension_email_list'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate task parameters.
|
||||
* Only implement this method for validation that cannot be handled by FormEngine.
|
||||
* Basic validation like 'required' should be done via TCA 'eval' configuration.
|
||||
*/
|
||||
public function validateTaskParameters(array $parameters): bool
|
||||
{
|
||||
$isValid = true;
|
||||
|
||||
// Example: Custom email validation (beyond basic 'required' check)
|
||||
$emailList = $parameters['my_extension_email_list'] ?? '';
|
||||
if (!empty($emailList)) {
|
||||
$emails = GeneralUtility::trimExplode(',', $emailList, true);
|
||||
foreach ($emails as $email) {
|
||||
if (!GeneralUtility::validEmail($email)) {
|
||||
GeneralUtility::makeInstance(FlashMessageService::class)
|
||||
->getMessageQueueByIdentifier()
|
||||
->addMessage(
|
||||
GeneralUtility::makeInstance(
|
||||
FlashMessage::class,
|
||||
'Invalid email address: ' . $email,
|
||||
'',
|
||||
ContextualFeedbackSeverity::ERROR
|
||||
)
|
||||
);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
public function getAdditionalInformation(): string
|
||||
{
|
||||
return sprintf(
|
||||
'Field: %s, Emails: %s',
|
||||
$this->myField,
|
||||
$this->emailList
|
||||
);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MyVendor\MyExtension\Task;
|
||||
|
||||
use MyVendor\MyExtension\BusinessLogic;
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessageService;
|
||||
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Scheduler\Task\AbstractTask;
|
||||
|
||||
final class MyTask extends AbstractTask
|
||||
{
|
||||
protected string $myField = '';
|
||||
protected string $emailList = '';
|
||||
|
||||
|
||||
public function execute(): bool
|
||||
{
|
||||
# Dependency injection cannot be used in scheduler tasks
|
||||
$businessLogic = GeneralUtility::makeInstance(BusinessLogic::class);
|
||||
return $businessLogic->run($this->myField, $this->emailList, '…');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current field values as associative array.
|
||||
* This method is called during migration from old serialized tasks
|
||||
* and when displaying task information.
|
||||
*/
|
||||
public function getTaskParameters(): array
|
||||
{
|
||||
return [
|
||||
'my_extension_field' => $this->myField,
|
||||
'my_extension_email_list' => $this->emailList,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Set field values from associative array.
|
||||
* This method handles both old and new parameter formats for migration.
|
||||
*
|
||||
* @param array $parameters Values from either old AdditionalFieldProvider or new TCA fields
|
||||
*/
|
||||
public function setTaskParameters(array $parameters): void
|
||||
{
|
||||
// Handle migration: check old parameter names first, then new TCA field names
|
||||
$this->myField = $parameters['myField'] ?? $parameters['my_extension_field'] ?? '';
|
||||
$this->emailList = $parameters['emailList'] ?? $parameters['my_extension_email_list'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate task parameters.
|
||||
* Only implement this method for validation that cannot be handled by FormEngine.
|
||||
* Basic validation like 'required' should be done via TCA 'eval' configuration.
|
||||
*/
|
||||
public function validateTaskParameters(array $parameters): bool
|
||||
{
|
||||
$isValid = true;
|
||||
|
||||
// Example: Custom email validation (beyond basic 'required' check)
|
||||
$emailList = $parameters['my_extension_email_list'] ?? '';
|
||||
if (!empty($emailList)) {
|
||||
$emails = GeneralUtility::trimExplode(',', $emailList, true);
|
||||
foreach ($emails as $email) {
|
||||
if (!GeneralUtility::validEmail($email)) {
|
||||
GeneralUtility::makeInstance(FlashMessageService::class)
|
||||
->getMessageQueueByIdentifier()
|
||||
->addMessage(
|
||||
GeneralUtility::makeInstance(
|
||||
FlashMessage::class,
|
||||
'Invalid email address: ' . $email,
|
||||
'',
|
||||
ContextualFeedbackSeverity::ERROR
|
||||
)
|
||||
);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
public function getAdditionalInformation(): string
|
||||
{
|
||||
$info = [];
|
||||
if ($this->myField !== '') {
|
||||
$info[] = 'Field: ' . $this->myField;
|
||||
}
|
||||
if ($this->emailList !== '') {
|
||||
$info[] = 'Emails: ' . $this->emailList;
|
||||
}
|
||||
return implode(', ', $info);
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use MyVendor\MyExtension\Task\MyTask;
|
||||
|
||||
if ((new \TYPO3\CMS\Core\Information\Typo3Version())->getMajorVersion() < 14) {
|
||||
// Todo: Remove when TYPO3 13 support is dropped
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][MyTask::class] = [
|
||||
'extension' => 'my_extension',
|
||||
'title' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myTask.title',
|
||||
'description' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myTask.description',
|
||||
'additionalFields' => \MyVendor\MyExtension\Task\MyTaskAdditionalFieldProvider::class,
|
||||
];
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
use MyVendor\MyExtension\Task\MyTask;
|
||||
|
||||
defined('TYPO3') or die();
|
||||
|
||||
if (isset($GLOBALS['TCA']['tx_scheduler_task'])) {
|
||||
// Add custom fields to the tx_scheduler_task table
|
||||
ExtensionManagementUtility::addTCAcolumns(
|
||||
'tx_scheduler_task',
|
||||
[
|
||||
'my_extension_field' => [
|
||||
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:field.label',
|
||||
'config' => [
|
||||
'type' => 'input',
|
||||
'size' => 30,
|
||||
'required' => true,
|
||||
'eval' => 'trim',
|
||||
'placeholder' => 'Enter value here...',
|
||||
],
|
||||
],
|
||||
'my_extension_email_list' => [
|
||||
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:emailList.label',
|
||||
'config' => [
|
||||
'type' => 'text',
|
||||
'rows' => 3,
|
||||
'required' => true,
|
||||
'placeholder' => 'admin@example.com',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Register the task type
|
||||
ExtensionManagementUtility::addRecordType(
|
||||
[
|
||||
'label' => 'Some title or LLL:EXT reference',
|
||||
'description' => 'Some description or LLL:EXT reference',
|
||||
'value' => MyTask::class,
|
||||
'icon' => 'mimetypes-x-tx_scheduler_task_group',
|
||||
'iconOverlay' => 'content-clock',
|
||||
'group' => 'my_extension',
|
||||
],
|
||||
'
|
||||
--div--;core.form.tabs:general,
|
||||
tasktype,
|
||||
task_group,
|
||||
description,
|
||||
my_extension_field,
|
||||
my_extension_email_list,
|
||||
--div--;core.form.tabs:timing,
|
||||
execution_details,
|
||||
nextexecution,
|
||||
--palette--;;lastexecution,
|
||||
--div--;core.form.tabs:access,
|
||||
disable,
|
||||
--div--;core.form.tabs:extended,',
|
||||
[],
|
||||
'',
|
||||
'tx_scheduler_task'
|
||||
);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use MyVendor\MyExtension\Task\MyTask;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
|
||||
defined('TYPO3') or die();
|
||||
|
||||
if (isset($GLOBALS['TCA']['tx_scheduler_task'])) {
|
||||
ExtensionManagementUtility::addRecordType(
|
||||
[
|
||||
'label' => 'My Custom Task',
|
||||
'description' => 'Description of what this task does',
|
||||
'value' => MyTask::class,
|
||||
'icon' => 'my-custom-icon',
|
||||
'iconOverlay' => 'content-clock',
|
||||
'group' => 'my_extension',
|
||||
],
|
||||
$GLOBALS['TCA']['tx_scheduler_task']['types']['0']['showitem'],
|
||||
[],
|
||||
'',
|
||||
'tx_scheduler_task'
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user