Zum Inhalt springen

CommandController + settings

Erstellt am 30. März 2014 · 3 Antworten · letzte Antwort am 7. November 2014

Tags: TYPO3 6.x, Frage

metan ·

Hi,

ich versuche nun das ganze Wochenende die Settings einer Extension in den Scheduler/CommandController einzulesen.
Egal was ich im Internet gefunden habe, es funktioniert einfach nicht.
Ob
#112042
oder
http://forge.typo3.org/projects/typo3v4-mvc/wiki/CommandControllerInSchedulerTask
oder
http://www.derhansen.de/2012/06/zugriff-auf-extbase-extension.html

Was habe ich gemacht:
In der
ext_localconf.php

/**
 * Scheduler
 * Setting up scripts that can be run from the cli_dispatch.phpsh script.
 */
if (TYPO3_MODE === 'BE') {
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'sh\Sh\Command\ShDivCommandController';
}

in der ext_table.php

if (TYPO3_MODE === 'BE') {
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY, 'constants', '<INCLUDE_TYPOSCRIPT: source=FILE:EXT:sh/Configuration/TypoScript/constants.txt>');
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY, 'setup', '<INCLUDE_TYPOSCRIPT: source=FILE:EXT:sh/Configuration/TypoScript/setup.txt>');
}

In der setup.txt steht

module.tx_sh{
    settings < plugin.tx_sh.settings
    persistence < plugin.tx_sh.persistence
    view < plugin.tx_sh.view
    view {
        templateRootPath = {$module.tx_sh.view.templateRootPath}
        partialRootPath = {$module.tx_sh.view.partialRootPath}
        layoutRootPath = {$module.tx_sh.view.layoutRootPath}
    }
}

Der CommandContoller

<?php

namespace sh\Sh\Command;

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

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

    /**
     * Create once a day the static conf file
     *
     * @param none
     * @return void
     */
    public function testCommand() {
        echo 'settings...';
        $this->settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'sh', 'Sh');
    }
}
?>

Ich bin für jede Hilfe dankbar.

Grüße
metan

metan ·

Ja, allerdings etwas umständlich.
Ich schreibe mir einmal täglich die gesamte config in einen json-String und schreibe die Datei in das selbe Verzeichnis wie die config selbst.
Wenn sie benötigt wird, Datei laden, json2array und da ist sie ;-)

//Create once day the configuration file for include in special situations
        $configFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('xxx') . 'Configuration/TypoScript/xxx_constants_json.php';
        if (file_exists($configFile)) {
            $timeFile = filectime($configFile);
            if (date('d.m.y', time()) != date('d.m.y', $timeFile)) {
                $settings = \xxx\xxx\Service\ShLibDivService::getExtensionSettings();
                $handle = fopen($configFile, 'w');
                fwrite($handle, '<?php' . "\n");
                fwrite($handle, "if (!defined('TYPO3_MODE')) { die('Access denied.'); }" . "\n");
                fwrite($handle, '$config = \'' . json_encode($settings) . '\';' . "\n");
                fwrite($handle, '?>');
                fclose($handle);
            }
        }
        //If file does not exists create is also
        else {
            $settings = \xxx\xxx\Service\ShLibDivService::getExtensionSettings();
            $handle = fopen($configFile, 'w');
            fwrite($handle, '<?php' . "\n");
            fwrite($handle, "if (!defined('TYPO3_MODE')) { die('Access denied.'); }" . "\n");
            fwrite($handle, '$config = \'' . json_encode($settings) . '\';' . "\n");
            fwrite($handle, '?>');
            fclose($handle);
        }
    /**
     * function getExtensionSettings
     *
     * @param string $version gets the different versions for the settings
     * @return array
     */
    public function getExtensionSettings($version = '') {
        $settings = GeneralUtility::makeInstance('Tx_Extbase_Configuration_FrontendConfigurationManager')->getTypoScriptSetup();

        /* if ($full == false) {
          return $settings['plugin.']['tx_xxx.']['settings.']['xxx.'];
          } else {
          return $settings['plugin.']['tx_xxx.'];
          } */

        switch ($version) {
            case 'file':
                $configFile = \t3lib_extmgm::extPath('xxx') . 'Configuration/TypoScript/sh_constants_json.php';
                include($configFile);
                return json_decode($config, true);
                break;
            case 'long':
                return GeneralUtility::removeDotsFromTS($settings['plugin.']['tx_xxx.']);
                break;
            default:
                return GeneralUtility::removeDotsFromTS($settings['plugin.']['tx_xxx.']['settings.']['xxx.']);
                break;
        }
    }