‪TYPO3CMS  9.5
TestTask.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
25 {
31  public ‪$email;
32 
39  public function ‪execute()
40  {
41  $success = false;
42  if (!empty($this->email)) {
43  // If an email address is defined, send a message to it
44  $this->logger->info('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: Test email sent to "' . $this->email . '"');
45  // Get execution information
46  $exec = $this->‪getExecution();
47  // Get call method
48  if (‪Environment::isCli()) {
49  $calledBy = 'CLI module dispatcher';
50  $site = '-';
51  } else {
52  $calledBy = 'TYPO3 backend';
53  $site = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
54  }
55  $start = $exec->getStart();
56  $end = $exec->getEnd();
57  $interval = $exec->getInterval();
58  $multiple = $exec->getMultiple();
59  $cronCmd = $exec->getCronCmd();
60  $mailBody = 'SCHEDULER TEST-TASK' . LF . '- - - - - - - - - - - - - - - -' . LF . 'UID: ' . $this->taskUid . LF . 'Sitename: ' . ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . LF . 'Site: ' . $site . LF . 'Called by: ' . $calledBy . LF . 'tstamp: ' . date('Y-m-d H:i:s') . ' [' . time() . ']' . LF . 'maxLifetime: ' . $this->scheduler->extConf['maxLifetime'] . LF . 'start: ' . date('Y-m-d H:i:s', $start) . ' [' . $start . ']' . LF . 'end: ' . (empty($end) ? '-' : date('Y-m-d H:i:s', $end) . ' [' . $end . ']') . LF . 'interval: ' . $interval . LF . 'multiple: ' . ($multiple ? 'yes' : 'no') . LF . 'cronCmd: ' . ($cronCmd ? $cronCmd : 'not used');
61  // Prepare mailer and send the mail
62  try {
64  $mailer = GeneralUtility::makeInstance(\‪TYPO3\CMS\Core\Mail\MailMessage::class);
65  $mailer->setFrom([$this->email => 'SCHEDULER TEST-TASK']);
66  $mailer->setReplyTo([$this->email => 'SCHEDULER TEST-TASK']);
67  $mailer->setSubject('SCHEDULER TEST-TASK');
68  $mailer->setBody($mailBody);
69  $mailer->setTo($this->email);
70  $mailsSend = $mailer->send();
71  $success = $mailsSend > 0;
72  } catch (\Exception $e) {
73  throw new \TYPO3\CMS\Core\Exception($e->getMessage(), 1476048416);
74  }
75  } else {
76  // No email defined, just log the task
77  $this->logger->warning('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: No email address given');
78  }
79  return $success;
80  }
81 
87  public function ‪getAdditionalInformation()
88  {
89  return ‪$GLOBALS['LANG']->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email') . ': ' . ‪$this->email;
90  }
91 }
‪TYPO3\CMS\Scheduler\Example
Definition: SleepTask.php:2
‪TYPO3
‪TYPO3\CMS\Scheduler\Example\TestTask\$email
‪string $email
Definition: TestTask.php:30
‪TYPO3\CMS\Scheduler\Task\AbstractTask\getExecution
‪Execution getExecution()
Definition: AbstractTask.php:360
‪TYPO3\CMS\Scheduler\Example\TestTask
Definition: TestTask.php:25
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Scheduler\Example\TestTask\getAdditionalInformation
‪string getAdditionalInformation()
Definition: TestTask.php:86
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:127
‪TYPO3\CMS\Scheduler\Example\TestTask\execute
‪bool execute()
Definition: TestTask.php:38