Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
SCHEDULER & CLI 
Krystian Szymukowicz 
k.szymukowicz@sourcebroker.net
PRESENTATION ROADMAP 
WHAT IS SCHEDULER? 
SCHEDULER FOR USERS 
SCHEDULER FOR DEVELOPERS 
WHAT IS CLI? 
CLI FOR USERS 
CLI ...
SCHEDULER 
module to set up and monitor recurring things
WHY DO WE NEED SCHEDULER? 
• system extensions and user extensions do not have to 
repeat the code 
• TYPO3 installation i...
SCHEDULER 
USER/INTEGRATOR PERSPECTIVE
NOT INSTALLED BY DEFAULT
SETTING SCHEDULER MAIN CRONJOB 
EDIT USERS CRONTABS. 
When logged to ssh console as www-data user: 
crontab -e 
*/15 * * *...
SETTING SCHEDULER MAIN CRONJOB 
Different problems on limited ssh and shared hostings: 
• Fake cron to run just php script...
SETTING SCHEDULER MAIN CRONJOB 
General fake cron problem overcome: 
<php 
exec('/usr/local/php /var/www/workspace-typo3/p...
SETTING SCHEDULER MAIN CRONJOB 
Be ready to fight for Scheduler cron! 
Google for: 
"typo3 cli_dispatch.phpsh [hoster name...
SUCCESS
CRON FREQUENCY 
/etc/cron.d/ 
*/15 * * * * www-data php /var/www/workspace-typo3/projects/acme/typo3/cli_dispatch.phpsh sc...
SCHEDULER 
DEVELOPER PERSPECTIVE
SIMPLE EXT WITH SCHEDULER TASK 
! 
typo3conf/ext 
/Scheduler1 
https://github.com/t33k/scheduler1 
/Classes/Task/SimpleRep...
SIMPLE EXT WITH SCHEDULER TASK 
Register new extension: 
ext_conf.php 
<?php 
! 
$EM_CONF[$_EXTKEY] = array( 
'title' => '...
SIMPLE EXT WITH SCHEDULER TASK 
Register new scheduler task: 
ext_localconf.php 
<?php 
! 
$GLOBALS['TYPO3_CONF_VARS']['SC...
SIMPLE EXT WITH SCHEDULER TASK 
Class with task: 
Classes/Task/SampleTask.php 
<?php 
! 
namespace VScheduler1Task; 
class...
SIMPLE EXT WITH SCHEDULER TASK II 
https://github.com/t33k/scheduler2 
getAdditonalInformation() 
getProgress() 
implement...
SIMPLE EXT WITH SCHEDULER TASK II 
Classes/Task/SampleTask.php 
<?php 
! 
namespace VScheduler2Task; 
! 
class SampleTask ...
SIMPLE EXT WITH SCHEDULER TASK III 
Flash messages and debug: 
System flash messages 
Standard scheduler task info 
Genera...
SIMPLE EXT WITH SCHEDULER TASK III 
Classes/Task/SampleTask.php 
<?php 
! 
namespace VScheduler3Task; 
use TYPO3CMSCoreUti...
SIMPLE EXT WITH SCHEDULER TASK IV 
Additional field https://github.com/t33k/scheduler4
SIMPLE EXT WITH SCHEDULER TASK IV 
Additional field 
ext_localconf.php 
Classes/Task/SampleTaskAdditionalFieldProvider.php...
SIMPLE EXT WITH SCHEDULER TASK V 
Create new tasks automatically in FE and BE 
https://github.com/t33k/scheduler5 
Classes...
SIMPLE EXT WITH SCHEDULER TASK VII 
Autmaticaly disable task 
Classes/Task/SampleTask.php 
<?php 
! 
namespace VScheduler7...
THINGS TO REMEMBER 
Object is serialized once on creation of scheduler task so all 
future changes to methods or propertie...
CLI 
USER PERSPECTIVE
CLI 
Command Line Interface 
! 
One of SAPI the PHP interact with different env - here with 
shell. Others SAPI examples: ...
CLI Command Line Interface 
php typo3/cli_dispatch.phpsh
lowlevel_admin setBElock
lowlevel_cleaner [option] -r
lowlevel_refindex
extbase
CLI 
DEVELOPER PERSPECTIVE
EXTBASE COMMAND CENTER 
Backport from TYPO3 FLOW 
$ php cli_dispatch.phpsh extbase <command identifier> --argumentName=val...
ext_localconf.php 
<?php 
! 
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'VScheduler6Co...
php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:faqTitle 
All texts are taken from class comment / arguments !...
EXTBASE COMMAND CENTER 
ext_localconf.php 
<?php 
! 
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControll...
EXTBASE COMMAND CENTER
SCHEDULER/CLI 
INTERESTING EXTENSIONS
CLEARTYPO3CACHE 
$ php cli_dispatch.phpsh cleartypo3cache all 
$ php cli_dispatch.phpsh cleartypo3cache pages 
https://git...
CLEARTYPO3CACHE https://github.com/t33k/cleartypo3cache
T3DEPLOY 
https://github.com/AOEmedia/t3deploy 
Update only (more safe) 
php typo3/cli_dispatch.phpsh t3deploy database up...
THANK YOU! 
Krystian Szymukowicz 
k.szymukowicz@sourcebroker.net
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
TYPO3 Scheduler
Nächste SlideShare
Wird geladen in …5
×

TYPO3 Scheduler

TYPO3 Scheduler - presentations from typo3camp.pl

  • Als Erste(r) kommentieren

TYPO3 Scheduler

  1. 1. SCHEDULER & CLI Krystian Szymukowicz k.szymukowicz@sourcebroker.net
  2. 2. PRESENTATION ROADMAP WHAT IS SCHEDULER? SCHEDULER FOR USERS SCHEDULER FOR DEVELOPERS WHAT IS CLI? CLI FOR USERS CLI FOR DEVELOPER INTERESTING EXTENSIONS https://github.com/t33k/schedulerX Krystian Szymukowicz k.szymukowicz@sourcebroker.net
  3. 3. SCHEDULER module to set up and monitor recurring things
  4. 4. WHY DO WE NEED SCHEDULER? • system extensions and user extensions do not have to repeat the code • TYPO3 installation is better movable between hostings • gives overview of what scheduler jobs are there in system • gives overview of what jobs are currently active/running
  5. 5. SCHEDULER USER/INTEGRATOR PERSPECTIVE
  6. 6. NOT INSTALLED BY DEFAULT
  7. 7. SETTING SCHEDULER MAIN CRONJOB EDIT USERS CRONTABS. When logged to ssh console as www-data user: crontab -e */15 * * * * php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler When logged to ssh console as root then probably better is to: su www-data -c”crontab -e” */15 * * * * php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler EDIT SYSTEM WIDE CRONTABS. Go to /etc/cron.d/ and create file */15 * * * * www-data php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler
  8. 8. SETTING SCHEDULER MAIN CRONJOB Different problems on limited ssh and shared hostings: • Fake cron to run just php script by calling Apache (no CLI) • Different PHP version for CLI (works from BE not form CLI) • php_memory limit low for CLI (works from BE not form CLI) • No way to see errors from CLI on shared hostings.
  9. 9. SETTING SCHEDULER MAIN CRONJOB General fake cron problem overcome: <php exec('/usr/local/php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler'); <php exec('/usr/local/php-cgi /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler'); Different hosting - different variations • Hoster - ALL-INKL <php exec('php /var/www/workspace-typo3/projects/62/typo3/cli_dispatch.phpsh scheduler'); AddHandler php5-cgi .php .phpsh /cron/cron.php /cron/.htaccess /fileadmin/ /typo3/ /typo3conf /etc…
  10. 10. SETTING SCHEDULER MAIN CRONJOB Be ready to fight for Scheduler cron! Google for: "typo3 cli_dispatch.phpsh [hoster name]" Do not hesitate to ask hoster admin!
  11. 11. SUCCESS
  12. 12. CRON FREQUENCY /etc/cron.d/ */15 * * * * www-data php /var/www/workspace-typo3/projects/acme/typo3/cli_dispatch.phpsh scheduler 10:00 10:15 10:30 10:45 11:00 21-11-14 10:10 21-11-14 10:15 5 10 15 20 25 35 40 50 55 10:00 30 45 11:00 Task with id=2 will be late by 10 minutes
  13. 13. SCHEDULER DEVELOPER PERSPECTIVE
  14. 14. SIMPLE EXT WITH SCHEDULER TASK ! typo3conf/ext /Scheduler1 https://github.com/t33k/scheduler1 /Classes/Task/SimpleReportTask.php /ext_conf.php /ext_localconf.php
  15. 15. SIMPLE EXT WITH SCHEDULER TASK Register new extension: ext_conf.php <?php ! $EM_CONF[$_EXTKEY] = array( 'title' => 'Scheduler Test - The simplest extension with task', 'constraints' => array(), ); https://github.com/t33k/scheduler1
  16. 16. SIMPLE EXT WITH SCHEDULER TASK Register new scheduler task: ext_localconf.php <?php ! $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'] ['VScheduler1TaskSampleTask'] = array( 'extension' => $_EXTKEY, 'title' => 'The simplest task ever', 'description' => 'Task description' ); https://github.com/t33k/scheduler1
  17. 17. SIMPLE EXT WITH SCHEDULER TASK Class with task: Classes/Task/SampleTask.php <?php ! namespace VScheduler1Task; class SampleTask extends TYPO3CMSSchedulerTaskAbstractTask { ! public function execute() { $success = FALSE; … … return $success; } ! } https://github.com/t33k/scheduler1
  18. 18. SIMPLE EXT WITH SCHEDULER TASK II https://github.com/t33k/scheduler2 getAdditonalInformation() getProgress() implements TYPO3CMSSchedulerProgressProviderInterface()
  19. 19. SIMPLE EXT WITH SCHEDULER TASK II Classes/Task/SampleTask.php <?php ! namespace VScheduler2Task; ! class SampleTask extends TYPO3CMSSchedulerTaskAbstractTask implements TYPO3CMSSchedulerProgressProviderInterface { ! public $email = 'dr_who@universe.thr'; ! public function execute() { return TRUE; } ! public function getAdditionalInformation() { return 'Time now: ' . strftime('%H:%m:%S', time()) . ', Next exec time: ' . strftime('%x', $this->getNextDueExecution()) . ', Email: ' . $this->email; } ! public function getProgress(){ return rand(0,100); } ! } https://github.com/t33k/scheduler2
  20. 20. SIMPLE EXT WITH SCHEDULER TASK III Flash messages and debug: System flash messages Standard scheduler task info GeneralUtility::devLog(….. debug(ArrayUtility::convertObjectToArray($this));
  21. 21. SIMPLE EXT WITH SCHEDULER TASK III Classes/Task/SampleTask.php <?php ! namespace VScheduler3Task; use TYPO3CMSCoreUtilityGeneralUtility; use TYPO3CMSExtbaseUtilityArrayUtility; ! class SampleTask extends TYPO3CMSSchedulerTaskAbstractTask{ public function execute() { $flashMessageOk = GeneralUtility::makeInstance( 'TYPO3CMSCoreMessagingFlashMessage', 'Message to be passed', 'OK Example', TYPO3CMSCoreMessagingFlashMessage::OK); $defaultFlashMessageQueue = $this->getDefaultFlashMessageQueue(); $defaultFlashMessageQueue->enqueue($flashMessageOk); ! GeneralUtility::devLog('Message', 'scheduler3', 2, ArrayUtility::convertObjectToArray($this)); ! debug(ArrayUtility::convertObjectToArray($this)); return TRUE; } ! } https://github.com/t33k/scheduler3
  22. 22. SIMPLE EXT WITH SCHEDULER TASK IV Additional field https://github.com/t33k/scheduler4
  23. 23. SIMPLE EXT WITH SCHEDULER TASK IV Additional field ext_localconf.php Classes/Task/SampleTaskAdditionalFieldProvider.php ! class SampleTaskAdditionalFieldProvider implements TYPO3CMSSchedulerAdditionalFieldProviderInterface{ ! public function getAdditionalFields (array &$taskInfo, $task, TYPO3CMSSchedulerControllerSchedulerModuleController $parentObject) {…} ! public function validateAdditionalFields (array &$submittedData, TYPO3CMSSchedulerControllerSchedulerModuleController $parentObject) {…} ! public function saveAdditionalFields (array $submittedData, TYPO3CMSSchedulerTaskAbstractTask $task) {…} } https://github.com/t33k/scheduler4 <?php ! $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['VScheduler4TaskSampleTask'] = array( 'extension' => $_EXTKEY, 'title' => 'Scheduler4 test - example for new field', 'description' => 'How to add new field to scheduler task.', 'additionalFields' => 'VScheduler4TaskSampleTaskAdditionalFieldProvider' );
  24. 24. SIMPLE EXT WITH SCHEDULER TASK V Create new tasks automatically in FE and BE https://github.com/t33k/scheduler5 Classes/Task/SampleTask.php <?php ! namespace VScheduler5Task; use TYPO3CMSCoreUtilityGeneralUtility; ! class SampleTask extends TYPO3CMSSchedulerTaskAbstractTask { ! public function execute() { /** @var $newTask VScheduler5TaskSampleTask */ $newTask = GeneralUtility::makeInstance('VScheduler5TaskSampleTask'); $newTask->setDescription('Task description'); $newTask->setTaskGroup(0); $newTask->registerRecurringExecution($start = time(), $interval = 86400, $end = 0, $multiple = FALSE, $cron_cmd = ''); $newTask->email = 'test.drwho+' . rand(0,10) . '@gmail.com'; ! /** @var TYPO3CMSSchedulerScheduler $scheduler */ $scheduler = GeneralUtility::makeInstance("TYPO3CMSSchedulerScheduler"); $scheduler->addTask($newTask); ! return TRUE; } ! public function getAdditionalInformation() { return 'Email:' . $this->email; } ! }
  25. 25. SIMPLE EXT WITH SCHEDULER TASK VII Autmaticaly disable task Classes/Task/SampleTask.php <?php ! namespace VScheduler7Task; ! class SampleTask extends TYPO3CMSSchedulerTaskAbstractTask { ! public $counter = 10; ! public function execute() { $this->counter = $this->counter - 1; if ($this->counter === 0) { // $this->remove(); $this->setDisabled(TRUE); } $this->save(); return TRUE; } ! public function getAdditionalInformation() { return $this->counter; } ! }
  26. 26. THINGS TO REMEMBER Object is serialized once on creation of scheduler task so all future changes to methods or properties can lead to errors. The solution then is to delete the scheduler task and create new one.
  27. 27. CLI USER PERSPECTIVE
  28. 28. CLI Command Line Interface ! One of SAPI the PHP interact with different env - here with shell. Others SAPI examples: CGI, fpm , apache2handler CLI points: • No execution time limit by default. • No headers are send. • No path is changed while running by default
  29. 29. CLI Command Line Interface php typo3/cli_dispatch.phpsh
  30. 30. lowlevel_admin setBElock
  31. 31. lowlevel_cleaner [option] -r
  32. 32. lowlevel_refindex
  33. 33. extbase
  34. 34. CLI DEVELOPER PERSPECTIVE
  35. 35. EXTBASE COMMAND CENTER Backport from TYPO3 FLOW $ php cli_dispatch.phpsh extbase <command identifier> --argumentName=value $ php cli_dispatch.phpsh extbase scheduler6:sample:second --name=adam --number=12 --enabled This will call: —> extension scheduler6 —> class SampleCommandController —> method secondCommand typo3conf/ext/scheduler6/Classes/Command/SampleCommandController.php secondCommand($name, $number, $enabled = true)
  36. 36. ext_localconf.php <?php ! $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'VScheduler6Command SampleCommandController'; typo3conf/ext/scheduler6/Classes/Command/SampleCommandController.php /** * Class SampleCommandController * @package VScheduler6Command */ class SampleCommandController extends TYPO3CMSExtbaseMvcControllerCommandController { ! /** * Get Faq title for given uid * * This text goes into description of CLI * so you see when you will do php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:newsTitle. * Second line of description. * Third line of description. * * @param integer $faqUid Faq uid * @return void */ public function faqTitleCommand($faqUid) { $faqUid = intval($faqUid); if ($faqUid) { $faqRepository = $this->getFaqRepository(); $faq = $faqRepository->findByUid($faqUid); if(NULL !== $faq){ $this->outputLine($faq->getQuestion()); } } }
  37. 37. php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:faqTitle All texts are taken from class comment / arguments !!!
  38. 38. EXTBASE COMMAND CENTER ext_localconf.php <?php ! $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'VScheduler6Command SampleCommandController'; typo3conf/ext/scheduler6/Classes/Command/SampleCommandController.php /** * Class SampleCommandController * @package VScheduler6Command */ class SampleCommandController extends TYPO3CMSExtbaseMvcControllerCommandController { ! /** * Get Faq title for given uid * * This text goes into description of CLI * so you see when you will do php typo3/cli_dispatch.phpsh extbase help scheduler6:sample:newsTitle. * Second line of description. * Third line of description. * * @param integer $faqUid Faq uid * @return void */ public function faqTitleCommand($faqUid) { $faqUid = intval($faqUid); if ($faqUid) { $faqRepository = $this->getFaqRepository(); $faq = $faqRepository->findByUid($faqUid); if(NULL !== $faq){ $this->outputLine($faq->getQuestion()); } } }
  39. 39. EXTBASE COMMAND CENTER
  40. 40. SCHEDULER/CLI INTERESTING EXTENSIONS
  41. 41. CLEARTYPO3CACHE $ php cli_dispatch.phpsh cleartypo3cache all $ php cli_dispatch.phpsh cleartypo3cache pages https://github.com/t33k/cleartypo3cache $ php cli_dispatch.phpsh cleartypo3cache system Create BE user "_cli_cleartypo3cache" with TS settings options.clearCache.all=1 options.clearCache.pages=1 options.clearCache.system=1
  42. 42. CLEARTYPO3CACHE https://github.com/t33k/cleartypo3cache
  43. 43. T3DEPLOY https://github.com/AOEmedia/t3deploy Update only (more safe) php typo3/cli_dispatch.phpsh t3deploy database updateStructure --verbose --execute Remove also php typo3/cli_dispatch.phpsh t3deploy database updateStructure --remove --verbose --execute
  44. 44. THANK YOU! Krystian Szymukowicz k.szymukowicz@sourcebroker.net

×