Skip to content

Commit

Permalink
Scheduler integration
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/powermail/trunk@43181 735d13b6-9817-0410-8766-e36946ffe9aa
  • Loading branch information
wunschtacho committed Feb 6, 2011
1 parent fac0116 commit 741a0bf
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 65 deletions.
117 changes: 114 additions & 3 deletions cli/class.tx_powermail_scheduler.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,130 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 powermail development team (details on http://forge.typo3.org/projects/show/extension-powermail)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Plugin 'tx_powermail' for the 'powermail' extension.
*
* @author Alex Kellner ([email protected])
* @package TYPO3
* @subpackage tx_powermail_scheduler
*/

class tx_powermail_scheduler extends tx_scheduler_Task {

public $lang;

/**
* Function executed from the Scheduler.
*
* @return bool
*/
public function execute() {

require_once(t3lib_extMgm::extPath('lang', 'lang.php')); // include lang class
$LANG = t3lib_div::makeInstance('language');
$LANG->init('en');

if (intval($this->pid) === 0) {
$this->msg = 'No Page ID given!';
return false;
}

// tsconfig
$tmp_defaultconfig = array (
'time' => 86400, // default setting 1 day
'body' => 'See XLS file in attachment', // default body
'subject' => 'New powermail export email', // default subject
'email_receiver' => '', // default: no receiver mail
'email_receiver_cc' => '', // default: no cc mail
'email_sender' => '[email protected]', // default sender address
'sender' => 'powermail', // default sender name
'format' => 'email_csv', // export in format email_csv or email_html or email_xls
'attachedFilename' => '' // overwrite filename
);
$tmp_tsconfig = t3lib_BEfunc::getModTSconfig($this->pid, 'tx_powermail_cli'); // get whole tsconfig from backend
$tsconfig = array_merge((array) $tmp_defaultconfig, (array) $tmp_tsconfig['properties']['exportmail.']);

if (!t3lib_div::validEmail($tsconfig['email_receiver'])) { // if receiver email is set
$this->msg = 'Wrong receiver mail given!';
return false;
}

if (!t3lib_extMgm::isLoaded('phpexcel_library') && $tsconfig['format'] == 'email_xls') {
$this->msg = 'Please use csv or install extension phpexcel_library';
return false;
}

// Generate the xls file
$export = t3lib_div::makeInstance('tx_powermail_export');
$export->pid = $pid; // set page id
$export->startDateTime = (time() - $tsconfig['time']); // set starttime
$export->endDateTime = time(); // set endtime
$export->export = (stristr($tsconfig['format'], 'email_') ? $tsconfig['format'] : $this->tmp_defaultconfig['format']); // set
$export->LANG = $LANG;
if (!empty($tsconfig['attachedFilename'])) {
$export->overwriteFilename = $tsconfig['attachedFilename']; // overwrite filename with this
}
$export->main(); // generate file
$file = t3lib_div::getFileAbsFileName('typo3temp/' . $export->filename); // read filename

if (!empty($file)) { // if file is not empty
// Generate the mail
$htmlMail = t3lib_div::makeInstance('t3lib_htmlmail'); // New object: TYPO3 mail class
$htmlMail->start(); // start htmlmail
$htmlMail->recipient = $tsconfig['email_receiver']; // main receiver
$htmlMail->recipient_copy = $tsconfig['email_receiver_cc']; // cc
$htmlMail->subject = $tsconfig['subject']; // mail subject
$htmlMail->from_email = $tsconfig['email_sender']; // sender email
$htmlMail->from_name = $tsconfig['sender']; // sender name
$htmlMail->addAttachment($file); // add attachment
$htmlMail->addPlain($tsconfig['body']); // add plaintext
$htmlMail->setHTML($htmlMail->encodeMsg($tsconfig['body'])); // html format if active via constants
$htmlMail->setHeaders();
$htmlMail->setContent();
if ($htmlMail->sendTheMail()) {
$this->msg = 'Mail successfully sent';
} else {
$this->msg = 'Powermail Error in sending mail';
}

} else {
$content = 'There are no mails to export in the last ' . intval($tsconfig['time']) . ' seconds in pid ' . $this->pid;
}

return true;
}

mail('[email protected]', 'scheduler', 'scheduler');
return 'fehler';
/**
* Return message for backend
*
* @return bool
*/
public function getAdditionalInformation() {
return $this->msg;
}
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail/cli/class.tx_powermail_scheduler.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/powermail/cli/class.tx_powermail_scheduler.php']);
}
?>
55 changes: 0 additions & 55 deletions cli/class.tx_powermail_scheduler_addField.php

This file was deleted.

14 changes: 8 additions & 6 deletions ext_autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@

$powermailExtPath = t3lib_extMgm::extPath('powermail');

return array(
$arr = array(

/* ajax actions*/
'tx_powermail_action' => $powermailExtPath . 'mod1/class.tx_powermail_action.php',
'tx_powermail_action' => $powermailExtPath . 'mod1/class.tx_powermail_action.php',

/* ajax repositories */
'tx_powermail_repository' => $powermailExtPath . 'mod1/class.tx_powermail_repository.php',
'tx_powermail_export' => $powermailExtPath . 'mod1/class.tx_powermail_export.php',
'tx_powermail_repository' => $powermailExtPath . 'mod1/class.tx_powermail_repository.php',
'tx_powermail_export' => $powermailExtPath . 'mod1/class.tx_powermail_export.php',

/* div */
'tx_powermail_functions_div' => $powermailExtPath . 'lib/class.tx_powermail_functions_div.php',
'tx_powermail_functions_div' => $powermailExtPath . 'lib/class.tx_powermail_functions_div.php',

/* scheduler */
'tx_powermail_scheduler' => $powermailExtPath . 'cli/class.tx_powermail_scheduler.php',
'tx_powermail_scheduler_addField' => $powermailExtPath . 'cli/class.tx_powermail_scheduler_addField.php'
'tx_powermail_scheduler_addFields' => $powermailExtPath . 'cli/class.tx_powermail_scheduler_addFields.php'

);

return $arr;
?>
3 changes: 2 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
include_once(t3lib_extMgm::extPath('powermail') . 'lib/user_powermail_misc.php'); // Some powermail userFunc (Conditions if any further step)
include_once(t3lib_extMgm::extPath('powermail') . 'lib/user_checkT3jquery.php'); // Conditions for Check if t3jquery is loaded or not
include_once(t3lib_extMgm::extPath('powermail') . 'lib/user_checkT3jqueryCDNMode.php'); // Conditions for Check if t3jquery is in CDN Mode
include_once(t3lib_extMgm::extPath('powermail') . 'cli/class.tx_powermail_scheduler_addFields.php'); // Scheduler addFields class

t3lib_extMgm::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:powermail/pageTSconfig.txt">');

Expand All @@ -33,7 +34,7 @@
'extension' => 'powermail',
'title' => 'Automatic Export Mails',
'description' => 'Send your CSV or XLS exports via Email to a defined target',
'additionalFields' => 'tx_powermail_scheduler_addField'
'additionalFields' => 'tx_powermail_scheduler_addFields'
);

?>

0 comments on commit 741a0bf

Please sign in to comment.