‪TYPO3CMS  ‪main
TestTask.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Symfony\Component\Mime\Address;
25 
31 {
37  public ‪$email;
38 
45  public function ‪execute()
46  {
47  if (!empty($this->email)) {
48  // If an email address is defined, send a message to it
49  $this->logger->info('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: Test email sent to "{email}"', ['email' => $this->email]);
50 
51  $templateConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
52  $templateConfiguration['templateRootPaths'][20] = 'EXT:scheduler/Resources/Private/Templates/Email/';
53 
54  if (‪Environment::isCli()) {
55  $calledBy = 'CLI module dispatcher';
56  } else {
57  $calledBy = 'TYPO3 backend';
58  }
59  ‪$email = GeneralUtility::makeInstance(
60  FluidEmail::class,
61  GeneralUtility::makeInstance(TemplatePaths::class, $templateConfiguration)
62  );
63  $fromAddress = !empty(‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])
64  ? ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']
66  ‪$email
67  ->to($this->email)
68  ->subject('SCHEDULER TEST-TASK')
69  ->from(new Address($fromAddress, 'SCHEDULER TEST-TASK'))
70  ->setTemplate('TestTask')
71  ->assignMultiple(
72  [
73  'data' => [
74  'uid' => $this->taskUid,
75  'calledBy' => $calledBy,
76  'tstamp' => time(),
77  'maxLifetime' => $this->scheduler->extConf['maxLifetime'],
78  ],
79  'exec' => $this->getExecution(),
80  ]
81  );
82  GeneralUtility::makeInstance(Mailer::class)->send(‪$email);
83  return true;
84  }
85  // No email defined, just log the task
86  $this->logger->warning('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: No email address given');
87 
88  return false;
89  }
90 
96  public function ‪getAdditionalInformation()
97  {
98  return $this->‪getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email') . ': ' . ‪$this->email;
99  }
100 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪TYPO3\CMS\Scheduler\Example
Definition: SleepTask.php:16
‪TYPO3\CMS\Scheduler\Example\TestTask\$email
‪string $email
Definition: TestTask.php:36
‪TYPO3\CMS\Scheduler\Example\TestTask
Definition: TestTask.php:31
‪TYPO3\CMS\Scheduler\Task\AbstractTask\getLanguageService
‪getLanguageService()
Definition: AbstractTask.php:600
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Core\Mail\FluidEmail
Definition: FluidEmail.php:35
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:40
‪TYPO3\CMS\Scheduler\Example\TestTask\getAdditionalInformation
‪string getAdditionalInformation()
Definition: TestTask.php:95
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:160
‪TYPO3\CMS\Scheduler\Example\TestTask\execute
‪bool execute()
Definition: TestTask.php:44