commandControllers

Scheduler Task

Was vormals die CLI Skripte waren die per Cron ausgeführt werden, ist nun als Scheduler Task in TYPO3 möglich. Hier wird der CommandController vorgestellt, der wesentlich besser als die tx_scheduler_Task ist, da hier der volle Kontext verfügbar ist.

Registrieren

Zunächst den Controller in der ext_localconf.php registrieren:

# Scheduler
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'RSYS\Rsyscrewing\Command\ImportCommandController';

Controller anlegen

Der Code für den Controller sieht so aus:

class ImportCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {

    /**
     * @var TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
     * @injectå
     */
    protected $configurationManager;

    /**
     * The settings.
     * @var array
     */
    protected $settings = array();

    /**
     * Initialize the controller.
    */
    protected function initializeCommand() {
        // get settings
        $this->settings = $this->configurationManager->getConfiguration(
            \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
            'Rsyscrewing', 'Main'
        );        
    }

    /**
     *  Import Command
     *
     * @param string $name
     * @return void
     */
    public function ImportCommand($name) {
       
        // get settings
        $this->initializeCommand();
    
        // here is the processing
        echo "SETTINGS:";
        print_r($this->settings);
    }
}
?>

Zugriff auf Typoscript

Im initializeCommand wird das TS der Extension (settings) ausgelesen. Damit das funktioniert ist aber einiges zu beachten.

Plugin

Das Plugin ist folgendermaßen konfiguriert:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'RSYS.' . $_EXTKEY,
    'Main',
    array(
        'Request' => 'list, show',
    ),
    // non-cacheable actions
    array(
        'Request' => '',
    )
);

Obwol der Pluginname hier RSYS.Rsyscrewing ist, muss bei getConfiguration der Name ohne das RSYS. verwendet werden.

TS Einbindung

Das TS muss im Root der Website eingebunden werden.

TS Setup

Das plugin settings muss zu module settings umkopiert werden

plugin.tx_rsyscrewing.settings.import.filename = {$plugin.tx_rsyscrewing.settings.import.filename
}
module.tx_rsyscrewing.settings < plugin.tx_rsyscrewing.settings

Cache

Wenn man z.B. nach dem Import den Cache löschen will geht das mit:

// clear cache
$GLOBALS['typo3CacheManager']->flushCaches();

Erstellt: 08/2014| Geändert: 03/2023