|
1
|
|
|
<?php |
|
2
|
|
|
namespace TYPO3\CMS\Scheduler\Example; |
|
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
|
|
|
|
|
17
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
18
|
|
|
use Symfony\Component\Mime\Address; |
|
19
|
|
|
use TYPO3\CMS\Core\Core\Environment; |
|
20
|
|
|
use TYPO3\CMS\Core\Mail\FluidEmail; |
|
21
|
|
|
use TYPO3\CMS\Core\Mail\Mailer; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
23
|
|
|
use TYPO3\CMS\Fluid\View\TemplatePaths; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Provides testing procedures |
|
27
|
|
|
* @internal This class is an example is not considered part of the Public TYPO3 API. |
|
28
|
|
|
*/ |
|
29
|
|
|
class TestTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* An email address to be used during the process |
|
33
|
|
|
* |
|
34
|
|
|
* @var string $email |
|
35
|
|
|
*/ |
|
36
|
|
|
public $email; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Function executed from the Scheduler. |
|
40
|
|
|
* Sends an email |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
public function execute() |
|
45
|
|
|
{ |
|
46
|
|
|
if (!empty($this->email)) { |
|
47
|
|
|
// If an email address is defined, send a message to it |
|
48
|
|
|
$this->logger->info('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: Test email sent to "' . $this->email . '"'); |
|
49
|
|
|
|
|
50
|
|
|
$templateConfiguration = $GLOBALS['TYPO3_CONF_VARS']['MAIL']; |
|
51
|
|
|
$templateConfiguration['templateRootPaths'][20] = 'EXT:scheduler/Resources/Private/Templates/Email/'; |
|
52
|
|
|
|
|
53
|
|
|
if (Environment::isCli()) { |
|
54
|
|
|
$calledBy = 'CLI module dispatcher'; |
|
55
|
|
|
$site = '-'; |
|
56
|
|
|
} else { |
|
57
|
|
|
$calledBy = 'TYPO3 backend'; |
|
58
|
|
|
$site = GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); |
|
59
|
|
|
} |
|
60
|
|
|
$email = GeneralUtility::makeInstance( |
|
61
|
|
|
FluidEmail::class, |
|
62
|
|
|
GeneralUtility::makeInstance(TemplatePaths::class, $templateConfiguration) |
|
63
|
|
|
); |
|
64
|
|
|
$email |
|
65
|
|
|
->to($this->email) |
|
66
|
|
|
->subject('SCHEDULER TEST-TASK') |
|
67
|
|
|
->from(new Address($this->email, 'SCHEDULER TEST-TASK')) |
|
68
|
|
|
->setTemplate('TestTask') |
|
69
|
|
|
->assignMultiple( |
|
70
|
|
|
[ |
|
71
|
|
|
'data' => [ |
|
72
|
|
|
'uid' => $this->taskUid, |
|
73
|
|
|
'site' => $site, |
|
74
|
|
|
'calledBy' => $calledBy, |
|
75
|
|
|
'tstamp' => time(), |
|
76
|
|
|
'maxLifetime' => $this->scheduler->extConf['maxLifetime'], |
|
77
|
|
|
], |
|
78
|
|
|
'exec' => $this->getExecution() |
|
79
|
|
|
] |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) { |
|
83
|
|
|
$email->setRequest($GLOBALS['TYPO3_REQUEST']); |
|
84
|
|
|
} |
|
85
|
|
|
GeneralUtility::makeInstance(Mailer::class)->send($email); |
|
86
|
|
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
// No email defined, just log the task |
|
89
|
|
|
$this->logger->warning('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: No email address given'); |
|
90
|
|
|
|
|
91
|
|
|
return false; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* This method returns the destination mail address as additional information |
|
96
|
|
|
* |
|
97
|
|
|
* @return string Information to display |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getAdditionalInformation() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->getLanguageService()->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:label.email') . ': ' . $this->email; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|