You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 8中如何将Symfony控制台命令加入调度器任务?

Absolutely yes! You can integrate your Symfony console command into TYPO3 8's Scheduler—you just need a small wrapper class, since the Scheduler doesn’t natively execute Symfony commands directly. Here’s how to make it work:

Step 1: Build a Custom Scheduler Wrapper Task

Create a PHP class that extends TYPO3’s AbstractTask interface. This class will act as a bridge between the Scheduler and your Symfony command.

Here’s a working example tailored for TYPO3 8:

<?php
namespace YourVendor\YourExtension\Task;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use TYPO3\CMS\Core\Console\CommandRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\Task\AbstractTask;

class SymfonyCommandWrapperTask extends AbstractTask
{
    /**
     * Run the wrapped Symfony command
     *
     * @return bool Success status
     */
    public function execute()
    {
        try {
            // Fetch TYPO3's command registry to access your Symfony command
            $commandRegistry = GeneralUtility::makeInstance(CommandRegistry::class);
            $command = $commandRegistry->get('your:symfony:command'); // Replace with your actual command name

            // Set up input (add args/options here if your command needs them)
            $input = new ArrayInput([]);
            // Capture output for logging
            $output = new BufferedOutput();

            // Execute the command
            $exitCode = $command->run($input, $output);

            // Handle success/error cases
            if ($exitCode !== 0) {
                $this->addMessage(
                    sprintf('Command failed with code %d: %s', $exitCode, $output->fetch()),
                    \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
                );
                return false;
            }

            $this->addMessage(
                sprintf('Command ran successfully: %s', $output->fetch()),
                \TYPO3\CMS\Core\Messaging\AbstractMessage::OK
            );
            return true;
        } catch (\Exception $e) {
            $this->addMessage(
                sprintf('Error executing command: %s', $e->getMessage()),
                \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
            );
            return false;
        }
    }
}
Step 2: Register the Task with TYPO3

Tell TYPO3 about your new task by adding this to your extension’s ext_localconf.php:

<?php
if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][YourVendor\YourExtension\Task\SymfonyCommandWrapperTask::class] = [
    'extension' => 'your_extension_key', // Replace with your extension's key
    'title' => 'LLL:EXT:your_extension_key/Resources/Private/Language/locallang.xlf:symfonyCommandWrapper.title',
    'description' => 'LLL:EXT:your_extension_key/Resources/Private/Language/locallang.xlf:symfonyCommandWrapper.description',
    'additionalFields' => '' // Leave empty unless you need configurable input fields
];

Add matching language labels to your locallang.xlf file so the task has a user-friendly name/description in the TYPO3 backend.

Step 3: Set Up the Task in the Scheduler
  1. Log into your TYPO3 backend and navigate to the Scheduler module (under System)
  2. Click Add Task
  3. In the Class dropdown, select your custom wrapper task (it should appear with the title you defined)
  4. Configure the schedule frequency (hourly, daily, etc.) to fit your needs
  5. Save the task—you can test it immediately using the "Execute now" button to catch any issues
Key Tips
  • Ensure your Symfony command is properly registered in TYPO3’s command registry. If it’s part of your extension, this is typically handled via Services.yaml or ext_localconf.php depending on your setup.
  • If your command requires arguments/options, you can add configurable fields to the wrapper class (using the additionalFields option) so users can input values directly in the Scheduler backend.
  • Always test the task manually first to verify it runs as expected before relying on scheduled execution.

内容的提问来源于stack exchange,提问作者lisardo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 14:52:41