‪TYPO3CMS  10.4
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 Psr\Http\Message\ServerRequestInterface;
19 use Symfony\Component\Mime\Address;
26 
32 {
38  public ‪$email;
39 
46  public function ‪execute()
47  {
48  if (!empty($this->email)) {
49  // If an email address is defined, send a message to it
50  $this->logger->info('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: Test email sent to "' . $this->email . '"');
51 
52  $templateConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
53  $templateConfiguration['templateRootPaths'][20] = 'EXT:scheduler/Resources/Private/Templates/Email/';
54 
55  if (‪Environment::isCli()) {
56  $calledBy = 'CLI module dispatcher';
57  $site = '-';
58  } else {
59  $calledBy = 'TYPO3 backend';
60  $site = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
61  }
62  ‪$email = GeneralUtility::makeInstance(
63  FluidEmail::class,
64  GeneralUtility::makeInstance(TemplatePaths::class, $templateConfiguration)
65  );
66  $fromAddress = !empty(‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'])
67  ? ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']
69  ‪$email
70  ->to($this->email)
71  ->subject('SCHEDULER TEST-TASK')
72  ->from(new Address($fromAddress, 'SCHEDULER TEST-TASK'))
73  ->setTemplate('TestTask')
74  ->assignMultiple(
75  [
76  'data' => [
77  'uid' => $this->taskUid,
78  'site' => $site,
79  'calledBy' => $calledBy,
80  'tstamp' => time(),
81  'maxLifetime' => $this->scheduler->extConf['maxLifetime'],
82  ],
83  'exec' => $this->getExecution()
84  ]
85  );
86 
87  if (‪$GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
88  ‪$email->setRequest(‪$GLOBALS['TYPO3_REQUEST']);
89  }
90  GeneralUtility::makeInstance(Mailer::class)->send(‪$email);
91  return true;
92  }
93  // No email defined, just log the task
94  $this->logger->warning('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: No email address given');
95 
96  return false;
97  }
98 
104  public function ‪getAdditionalInformation()
105  {
106  return $this->‪getLanguageService()->‪sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email') . ': ' . ‪$this->email;
107  }
108 }
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:35
‪TYPO3\CMS\Scheduler\Example
Definition: SleepTask.php:16
‪TYPO3\CMS\Scheduler\Example\TestTask\$email
‪string $email
Definition: TestTask.php:37
‪TYPO3\CMS\Scheduler\Example\TestTask
Definition: TestTask.php:32
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Scheduler\Task\AbstractTask\getLanguageService
‪LanguageService null getLanguageService()
Definition: AbstractTask.php:605
‪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:38
‪TYPO3\CMS\Scheduler\Example\TestTask\getAdditionalInformation
‪string getAdditionalInformation()
Definition: TestTask.php:103
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:154
‪TYPO3\CMS\Scheduler\Example\TestTask\execute
‪bool execute()
Definition: TestTask.php:45