Commit ff0fa37f authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Make schedulable commands field identifiers unique

The scheduler module contains a special task,
which allows to select schedulable symfony
commands.

The corresponding field provider therefore
adds the commands' configured arguments
and options. Due to insufficient prefixing, it
was not possible to display arguments and
options with the same name. Additionally,
using "action" as name always overwrote
the "select schedulable commands" field.

This is now resolved by adding proper prefixes.

Resolves: #97691
Releases: main, 11.5
Change-Id: I0e2c958fc699065cad6c53c0876e2c9ef14fc1f6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74745


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Torben Hansen's avatarTorben Hansen <derhansen@gmail.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Torben Hansen's avatarTorben Hansen <derhansen@gmail.com>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent f0ef135d
Pipeline #27638 passed with stages
in 16 minutes and 6 seconds
......@@ -72,8 +72,9 @@ class ExecuteSchedulableCommandAdditionalFieldProvider implements AdditionalFiel
$this->task->setScheduler();
}
$fields = [];
$fields['action'] = $this->getActionField();
$fields = [
'schedulableCommands' => $this->getSchedulableCommandsField(),
];
if ($this->task !== null && isset($this->schedulableCommands[$this->task->getCommandIdentifier()])) {
$command = $this->schedulableCommands[$this->task->getCommandIdentifier()];
......@@ -239,7 +240,7 @@ class ExecuteSchedulableCommandAdditionalFieldProvider implements AdditionalFiel
*
* @return array
*/
protected function getActionField(): array
protected function getSchedulableCommandsField(): array
{
$currentlySelectedCommand = $this->task !== null ? $this->task->getCommandIdentifier() : '';
$options = [];
......@@ -274,7 +275,7 @@ class ExecuteSchedulableCommandAdditionalFieldProvider implements AdditionalFiel
$value = implode(',', $value);
}
$fields[$name] = [
$fields['arguments_' . $name] = [
'code' => $this->renderArgumentField($argument, (string)$value),
'label' => $this->getArgumentLabel($argument),
];
......@@ -307,7 +308,7 @@ class ExecuteSchedulableCommandAdditionalFieldProvider implements AdditionalFiel
$value = implode(',', $value);
}
$fields[$name] = [
$fields['options_' . $name] = [
'code' => $this->renderOptionField($option, (bool)$enabled, (string)$value),
'label' => $this->getOptionLabel($option),
];
......@@ -348,6 +349,7 @@ class ExecuteSchedulableCommandAdditionalFieldProvider implements AdditionalFiel
$selectTag = new TagBuilder();
$selectTag->setTagName('select');
$selectTag->forceClosingTag(true);
$selectTag->addAttribute('id', 'schedulableCommands');
$selectTag->addAttribute('class', 'form-select');
$selectTag->addAttribute('name', 'tx_scheduler[task_executeschedulablecommand][command]');
......
<?php
declare(strict_types=1);
/*
* 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!
*/
namespace TYPO3\CMS\Scheduler\Tests\Unit\Task;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Console\CommandRegistry;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Execution;
use TYPO3\CMS\Scheduler\Scheduler;
use TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class ExecuteSchedulableCommandAdditionalFieldProviderTest extends UnitTestCase
{
use ProphecyTrait;
protected bool $resetSingletonInstances = true;
/**
* @test
*/
public function argumentsAndOptionsWithSameNameAreAdded(): void
{
$GLOBALS['BE_USER'] = new BackendUserAuthentication();
$languageServiceProphecy = $this->prophesize(LanguageService::class);
$languageServiceProphecy->sL(Argument::cetera())->willReturn('');
$GLOBALS['LANG'] = $languageServiceProphecy->reveal();
$mockScheduler = $this->getAccessibleMock(Scheduler::class, ['saveTask'], [], '', false);
GeneralUtility::setSingletonInstance(Scheduler::class, $mockScheduler);
$mockScheduler->method('saveTask')->willReturn(false);
GeneralUtility::addInstance(Execution::class, $this->prophesize(Execution::class)->reveal());
$command = new class() extends Command {
protected function configure(): void
{
$this
->setName('some:test:command')
->setDescription('Some test command')
->addArgument('action')
->addOption('action');
}
};
$commandRegistryProphecy = $this->prophesize(CommandRegistry::class);
$commandRegistryProphecy->getSchedulableCommands()->willReturn(
(static function () use ($command) { yield $command->getName() => $command; })()
);
GeneralUtility::setSingletonInstance(CommandRegistry::class, $commandRegistryProphecy->reveal());
$task = GeneralUtility::makeInstance(ExecuteSchedulableCommandTask::class);
$task->setCommandIdentifier('some:test:command');
$task->setDescription('Some test command');
$task->setArguments(['action' => '']);
$task->setOptions(['action' => false]);
$subject = new ExecuteSchedulableCommandAdditionalFieldProvider();
$taskInfo = [];
$fields = $subject->getAdditionalFields(
$taskInfo,
$task,
$this->prophesize(SchedulerModuleController::class)->reveal()
);
self::assertCount(4, $fields);
self::assertTrue(isset($fields['schedulableCommands'], $fields['description'], $fields['arguments_action'], $fields['options_action']));
}
}
Supports Markdown
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