Skip to content

Commit d684af6

Browse files
[FEATURE] Add attribute AsNonSchedulableCommand for "schedulable" (#6271)
* [FEATURE] Add attribute AsNonSchedulableCommand for "schedulable" Resolves: TYPO3-Documentation/Changelog-To-Doc#1470 Releases: main * [TASK] Language check Releases: main --------- Co-authored-by: Sarah McCarthy <[email protected]>
1 parent 1fecb76 commit d684af6

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

Documentation/ApiOverview/CommandControllers/CustomCommands.rst

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,42 +99,48 @@ definition of your class as a tag :yaml:`console.command`:
9999
- name: console.command
100100
command: 'examples:dosomething'
101101
description: 'A command that does nothing and always succeeds.'
102+
// To hide it from the scheduler:
103+
schedulable: false
102104
# Also an alias for the command can be configured
103105
- name: console.command
104106
command: 'examples:dosomethingalias'
105107
alias: true
106108
107109
.. note::
108110
Despite using :file:`autoconfigure: true` the commands
109-
have to be explicitly defined in :file:`Configuration/Services.yaml`. It
110-
is recommended to always supply a description, otherwise there will be
111-
an empty space in the list of commands.
111+
have to be explicitly defined in :file:`Configuration/Services.yaml` or
112+
use the PHP attribute :php:`#[AsCommand]`.
112113

113114
.. _deactivating-the-command-in-scheduler:
114115
.. _schedulable:
115116

116117
Making a command non-schedulable
117118
================================
118119

119-
A command can be set as disabled for the scheduler by setting :yaml:`schedulable`
120-
to :yaml:`false`. This can only be done when registering the command via
121-
`tag <console-command-tutorial-registration-tag>`_ and not via attribute:
122-
123-
124-
.. code-block:: yaml
125-
:caption: packages/my_extension/Configuration/Services.yaml
126-
127-
services:
128-
# ...
120+
.. versionadded:: 14.0
121+
The PHP attribute :php:`#[AsNonSchedulableCommand]` has been introduced to
122+
mark a command as non-schedulable.
129123

130-
MyVendor\MyExtension\Command\DoSomethingCommand:
131-
tags:
132-
- name: console.command
133-
command: 'examples:dosomething'
134-
description: 'A command that does nothing and cannot be scheduled.'
135-
schedulable: false
124+
To provide support for both TYPO3 v14 and v13 continue to register your
125+
command in :file:`Services.yaml` (see
126+
`Tag console.command in the Services.yaml <https://docs.typo3.org/permalink/t3coreapi:console-command-tutorial-registration-tag>`_).
136127

128+
A command can be set as disabled for the scheduler by using the
129+
:php:`#[AsNonSchedulableCommand]` attribute:
137130

131+
.. code-block:: php
132+
:caption: EXT:my_extension/Classes/Commands/MyImportCommand.php
133+
134+
use Symfony\Component\Console\Attribute\AsCommand;
135+
use Symfony\Component\Console\Command\Command;
136+
use TYPO3\CMS\Core\Attribute\AsNonSchedulableCommand;
137+
138+
#[AsCommand('myextension:import', 'Import data from external source')]
139+
#[AsNonSchedulableCommand]
140+
final class MyImportCommand extends Command
141+
{
142+
// ...
143+
}
138144
139145
.. _writing-custom-symfony-console-command-context:
140146

Documentation/ApiOverview/CommandControllers/Tutorial.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ A command with parameters and arguments
7777
.. literalinclude:: _Tutorial/_CreateWizardCommand.php
7878
:caption: packages/my_extension/Classes/Command/SendFluidMailCommand.php
7979

80+
It uses attribute :php:`#[AsNonSchedulableCommand]` so that it can only be used
81+
from the console and not from the :guilabel:`Administration > Scheduler` module.
82+
8083
This command takes one argument :php:`wizardName` (optional) and one option (optional),
8184
which can be added on the command line:
8285

@@ -94,7 +97,6 @@ which can be added on the command line:
9497
9598
typo3/sysext/core/bin/typo3 examples:createwizard [-b] [wizardName]
9699
97-
98100
.. _console-command-tutorial-fluidmail:
99101

100102
Sending a FluidMail via command

Documentation/ApiOverview/CommandControllers/_Tutorial/_CreateWizardCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Console\Style\SymfonyStyle;
1414
use T3docs\Examples\Exception\InvalidWizardException;
15+
use TYPO3\CMS\Core\Attribute\AsNonSchedulableCommand;
1516

1617
#[AsCommand(
1718
name: 'myextension:createwizard',
1819
)]
20+
#[AsNonSchedulableCommand]
1921
final class CreateWizardCommand extends Command
2022
{
2123
protected function configure(): void

0 commit comments

Comments
 (0)