[TASK] Deprecate \TYPO3\CMS\Core\Utility\MailUtility::mail()
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Example / TestTask.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Example;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2008-2013 Markus Friedrich (markus.friedrich@dkd.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Class "tx_scheduler_TestTask" provides testing procedures
28 *
29 * @author Markus Friedrich <markus.friedrich@dkd.de>
30 */
31 class TestTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
32
33 /**
34 * An email address to be used during the process
35 *
36 * @var string $email
37 * @todo Define visibility
38 */
39 public $email;
40
41 /**
42 * Function executed from the Scheduler.
43 * Sends an email
44 *
45 * @return boolean
46 */
47 public function execute() {
48 $success = FALSE;
49 if (!empty($this->email)) {
50 // If an email address is defined, send a message to it
51 // NOTE: the TYPO3_DLOG constant is not used in this case, as this is a test task
52 // and debugging is its main purpose anyway
53 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: Test email sent to "' . $this->email . '"', 'scheduler', 0);
54 // Get execution information
55 $exec = $this->getExecution();
56 // Get call method
57 if (basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
58 $calledBy = 'CLI module dispatcher';
59 $site = '-';
60 } else {
61 $calledBy = 'TYPO3 backend';
62 $site = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
63 }
64 $start = $exec->getStart();
65 $end = $exec->getEnd();
66 $interval = $exec->getInterval();
67 $multiple = $exec->getMultiple();
68 $cronCmd = $exec->getCronCmd();
69 $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');
70 // Prepare mailer and send the mail
71 try {
72 /** @var $mailer \TYPO3\CMS\Core\Mail\MailMessage */
73 $mailer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
74 $mailer->setFrom(array($this->email => 'SCHEDULER TEST-TASK'));
75 $mailer->setReplyTo(array($this->email => 'SCHEDULER TEST-TASK'));
76 $mailer->setSubject('SCHEDULER TEST-TASK');
77 $mailer->setBody($mailBody);
78 $mailer->setTo($this->email);
79 $mailsSend = $mailer->send();
80 $success = $mailsSend > 0;
81 } catch (\Exception $e) {
82 throw new \TYPO3\CMS\Core\Exception($e->getMessage());
83 }
84 } else {
85 // No email defined, just log the task
86 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[TYPO3\\CMS\\Scheduler\\Example\\TestTask]: No email address given', 'scheduler', 2);
87 }
88 return $success;
89 }
90
91 /**
92 * This method returns the destination mail address as additional information
93 *
94 * @return string Information to display
95 */
96 public function getAdditionalInformation() {
97 return $GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xml:label.email') . ': ' . $this->email;
98 }
99
100 }
101
102
103 ?>