Fixed bug #13625: Scheduler: tx_scheduler_TestTask fails to execute successfully...
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / examples / class.tx_scheduler_testtask.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Markus Friedrich (markus.friedrich@dkd.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 require_once(PATH_t3lib . 'class.t3lib_htmlmail.php');
26
27 /**
28 * Class "tx_scheduler_TestTask" provides testing procedures
29 *
30 * @author Markus Friedrich <markus.friedrich@dkd.de>
31 * @package TYPO3
32 * @subpackage tx_scheduler
33 *
34 * $Id$
35 */
36 class tx_scheduler_TestTask extends tx_scheduler_Task {
37
38 /**
39 * An email address to be used during the process
40 *
41 * @var string $email
42 */
43 var $email;
44
45 /**
46 * Function executed from the Scheduler.
47 * Sends an email
48 *
49 * @return void
50 */
51 public function execute() {
52 $success = false;
53
54 if (!empty($this->email)) {
55 // If an email address is defined, send a message to it
56
57 // NOTE: the TYPO3_DLOG constant is not used in this case, as this is a test task
58 // and debugging is its main purpose anyway
59 t3lib_div::devLog('[tx_scheduler_TestTask]: Test email sent to "' . $this->email . '"', 'scheduler', 0);
60
61 // Get execution information
62 $exec = $this->getExecution();
63
64 // Get call method
65 if (basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
66 $calledBy = 'CLI module dispatcher';
67 $site = '-';
68 } else {
69 $calledBy = 'TYPO3 backend';
70 $site = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
71 }
72
73 $start = $exec->getStart();
74 $end = $exec->getEnd();
75 $interval = $exec->getInterval();
76 $multiple = $exec->getMultiple();
77 $cronCmd = $exec->getCronCmd();
78 $mailBody =
79 'SCHEDULER TEST-TASK' . chr(10)
80 . '- - - - - - - - - - - - - - - -' . chr(10)
81 . 'UID: ' . $this->taskUid . chr(10)
82 . 'Sitename: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . chr(10)
83 . 'Site: ' . $site . chr(10)
84 . 'Called by: ' . $calledBy . chr(10)
85 . 'tstamp: ' . date('Y-m-d H:i:s') . ' [' . time() . ']' . chr(10)
86 . 'maxLifetime: ' . $this->scheduler->extConf['maxLifetime'] . chr(10)
87 . 'start: ' . date('Y-m-d H:i:s', $start) . ' [' . $start . ']' . chr(10)
88 . 'end: ' . ((empty($end)) ? '-' : (date('Y-m-d H:i:s', $end) . ' [' . $end . ']')) . chr(10)
89 . 'interval: ' . $interval . chr(10)
90 . 'multiple: ' . ($multiple ? 'yes' : 'no') . chr(10)
91 . 'cronCmd: ' . ($cronCmd ? $cronCmd : 'not used');
92
93 // Prepare mailer and send the mail
94 $mailer = t3lib_div::makeInstance('t3lib_htmlmail');
95 $mailer->start();
96 $mailer->from_email = $this->email;
97 $mailer->from_name = 'SCHEDULER TEST-TASK';
98 $mailer->replyto_email = $this->email;
99 $mailer->replyto_name = 'SCHEDULER TEST-TASK';
100 $mailer->subject = 'SCHEDULER TEST-TASK';
101 $mailer->setPlain($mailer->encodeMsg($mailBody));
102 $mailer->setRecipient($this->email);
103 $mailer->setHeaders();
104 $mailer->setContent();
105 $success = $mailer->sendtheMail();
106 } else {
107 // No email defined, just log the task
108 t3lib_div::devLog('[tx_scheduler_TestTask]: No email address given', 'scheduler', 2);
109 }
110
111 return $success;
112 }
113
114 /**
115 * This method returns the destination mail address as additional information
116 *
117 * @return string Information to display
118 */
119 public function getAdditionalInformation() {
120 return $GLOBALS['LANG']->sL('LLL:EXT:scheduler/mod1/locallang.xml:label.email') . ': ' . $this->email;
121 }
122 }
123
124 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/scheduler/examples/class.tx_scheduler_testtask.php']) {
125 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/scheduler/examples/class.tx_scheduler_testtask.php']);
126 }
127
128 ?>