[TYPO3-mvc] Using extbase in cron scripts / scheduler tasks
Axel Böswetter
evilbmp at gmail.com
Thu Sep 2 10:39:43 CEST 2010
Hi Steffen,
unfortunately I have to instantiate the TSFE for frontend-url generation
too. By now I don't need fluid templates in my scheduler, so I can skip the
tearUp and simply run the getter for the extbase configuration. But nice
to see, that we used nearly the same approach.
I created a initTSFE method for such matters. Here it is:
function initTSFE($pageUid = 1, $overrule = FALSE) {
// declare
$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
// begin
if (!is_object($GLOBALS['TT']) || $overrule === TRUE) {
$GLOBALS['TT'] = new t3lib_timeTrack;
$GLOBALS['TT']->start();
}
if ((!is_object($GLOBALS['TSFE']) || $overrule === TRUE) && is_int($pageUid))
{
// builds TSFE object
$GLOBALS['TSFE'] = new $temp_TSFEclassName($GLOBALS['TYPO3_CONF_VARS'],
$pageUid, $type=0, $no_cache=0, $cHash='', $jumpurl='', $MP='', $RDCT='');
// builds rootline
$GLOBALS['TSFE']->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
$rootLine = $GLOBALS['TSFE']->sys_page->getRootLine($pageUid);
// init template
$GLOBALS['TSFE']->tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext');
$GLOBALS['TSFE']->tmpl->tt_track = 0;// Do not log time-performance
information
$GLOBALS['TSFE']->tmpl->init();
// this generates the constants/config + hierarchy info for the
template.
$GLOBALS['TSFE']->tmpl->runThroughTemplates($rootLine, $start_template_uid=0);
$GLOBALS['TSFE']->tmpl->generateConfig();
$GLOBALS['TSFE']->tmpl->loaded=1;
// get config array and other init from pagegen
$GLOBALS['TSFE']->getConfigArray();
$GLOBALS['TSFE']->linkVars = ''.$GLOBALS['TSFE']->config['config']['linkVars'];
if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc_onlyP'])
{
foreach (t3lib_div::trimExplode(',',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc_onlyP'],1)
as $temp_p) {
$GLOBALS['TSFE']->pEncAllowedParamNames[$temp_p]=1;
}
}
// builds a cObj
$GLOBALS['TSFE']->newCObj();
}
}
Maybe you need it sometimes ;-) e.g. hooks, crons, ...
Regards,
Axel Böswetter
> Am 01.09.2010 17:22, schrieb Axel Böswetter:
>
>> So my solution for this problem is, that my scheduler extends the
>> extbase dispatcher. Now you are able to call the
>> initializeConfigurationManagerAndFrameworkConfiguration() method of
>> the dispatcher.
>>
> Hey I did something similiar, but I had to use frontend-url generation
> in fluid to... so i went a step further.
>
> I have an owen dispatcher which "tears up" the framework "and shuts it
> down" at the end. In fact I initialize parts of the TSFE so that I
> have full access to TypoScript and Linking Configuration.
>
> I just instanciate the dispatcher
> call tearUp
> do my scheduler processing (including fluid template rendering
> (emails))
>
> call tearDown
>
> and good is it. I currently hardcoded my root page uid, but that
> easily could be done as a scheduler extra field.
>
> class Tx_Rsmysherpasprojects_Service_Scheduler_ExtbaseMods_Dispatcher
> extends Tx_Extbase_Dispatcher {
>
> public function dispatchFrameworkForScheduler() {
> $GLOBALS['TT'] = new t3lib_timeTrackNull;
> $GLOBALS['TSFE'] = t3lib_div::makeInstance('tslib_fe',
> $GLOBALS['TYPO3_CONF_VARS'], 2, 0);
> $GLOBALS['TSFE']->sys_page =
> t3lib_div::makeInstance('t3lib_pageSelect');
> $GLOBALS['TSFE']->sys_page->init(TRUE);
> $GLOBALS['TSFE']->initTemplate();
> $GLOBALS['TSFE']->rootLine =
> $GLOBALS['TSFE']->sys_page->getRootLine(2, '');
> $GLOBALS['TSFE']->getConfigArray();
> $dummyConfiguration = array(
> 'userFunc' => 'tx_extbase_dispatcher->dispatch',
> 'pluginName' => 'pi1',
> 'extensionName' => 'Rsmysherpasprojects',
> 'controller' => 'Project',
> 'action' => 'index',
> 'switchableControllerActions.' => array(),
> 'settings' => '< plugin.tx_rsmysherpasprojects.settings',
> 'persistence' => '< plugin.tx_rsmysherpasprojects.persistence',
> 'view' => '< plugin.tx_rsmysherpasprojects.view',
> );
> $this->initializeConfigurationManagerAndFrameworkConfiguration($dummyC
> onfiguration);
> $requestBuilder =
> t3lib_div::makeInstance('Tx_Extbase_MVC_Web_RequestBuilder');
> $request =
> $requestBuilder->initialize(self::$extbaseFrameworkConfiguration);
> self::getPersistenceManager();
> self::$configurationManager->loadTypoScriptSetup();
> }
> public function tearDownFramework() {
> self::getPersistenceManager()->persistAll();
> self::$reflectionService->shutdown();
> unset($GLOBALS['TSFE']);
> unset($GLOBALS['TT']);
> }
> }
More information about the TYPO3-project-typo3v4mvc
mailing list