Permalink
Browse files

Use typo3/cli_dispatch.phpsh for all CLI operations instead of outdat…

…ed manual way. #31562

This introduce a BREAKING CHANGE for crontab configuration, see user manual for latest instructions.


git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/newsletter/trunk@53935 735d13b6-9817-0410-8766-e36946ffe9aa
  • Loading branch information...
1 parent ec4e723 commit 6e265071d2f74073980ebff0a0759be9f860bffe @PowerKiKi PowerKiKi committed Nov 9, 2011
@@ -74,6 +74,52 @@ class tx_newsletter_bouncehandler
);
/**
+ * Fetch all email from Bounce Accounts and pipe each of them to cli/bounce.php
+ */
+ public static function fetchBouncedEmails()
+ {
+ global $TYPO3_DB, $TYPO3_CONF_VARS;
+
+ // Find all bounce accounts we need to check
+ $contents = '';
+ $servers = array();
+ $rs = $TYPO3_DB->sql_query("SELECT protocol, server, username, password FROM tx_newsletter_domain_model_bounceaccount
+ WHERE hidden = 0
+ AND deleted = 0");
+ while (list($protocol, $server, $username, $passwd) = $TYPO3_DB->sql_fetch_row($rs)) {
+ $contents .= "poll $server proto $protocol username \"$username\" password \"$passwd\"\n";
+ $servers[] = $server;
+ }
+
+ // Write a new fetchmailrc based on bounce accounts found
+ $fetchmailhome = PATH_site . 'uploads/tx_newsletter';
+ $fetchmailfile = "$fetchmailhome/fetchmailrc";
+ file_put_contents($fetchmailfile, $contents);
+ chmod($fetchmailfile, 0600);
+
+ // Find fetchmail itself
+ putenv("FETCHMAILHOME=$fetchmailhome");
+ $theconf = unserialize($TYPO3_CONF_VARS['EXT']['extConf']['newsletter']);
+ $fetchmail = $theconf['path_to_fetchmail'];
+
+ // Keep messages on server
+ if ($theconf['keep_messages']) {
+ $keep = '--keep ';
+ }
+
+ // Execute fetchtmail and ask him to pipe emails to our cli/bounce.php
+ $cli_dispatcher = PATH_typo3 . 'cli_dispatch.phpsh'; // This is supposed to be the absolute path of /typo3/cli_dispatch.phpsh
+ foreach ($servers as $server) {
+
+ $cmd = "$fetchmail -s $keep -m \"$cli_dispatcher newsletter_bounce\" $server";
+ echo $cmd . "\n";
+ //exec($cmd);
+ }
+
+ unlink($fetchmailfile);
+ }
+
+ /**
* Constructor for bounce handler
* @param string $mailsource
*/
@@ -34,18 +34,20 @@
*/
abstract class tx_newsletter_tools {
+ protected static $configuration;
+
/**
* Get a newsletter-conf-template parameter
*
* @param string Parameter key
* @return mixed Parameter value
*/
public static function confParam($key) {
- if (!is_array($GLOBALS['NEWSLETTER_CONF'])) {
- $GLOBALS['NEWSLETTER_CONF'] = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['newsletter']);
+ if (!is_array(self::$configuration)) {
+ self::$configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['newsletter']);
}
- return $GLOBALS['NEWSLETTER_CONF'][$key];
+ return self::$configuration[$key];
}
/**
@@ -156,12 +158,12 @@ public static function runSpoolOneAll($onlyTest = false) {
/* Get the machines hostname.. it can be supplied on the commandline, or we read the hostname.
This does absolutely only work on Unix machines without safe_mode */
- if ($_SERVER['argv'][1]) {
+ if (isset($_SERVER['argv'][1])) {
$hostname = $_SERVER['argv'][1];
} else {
$hostname = trim(exec('hostname'));
}
-
+
/* Try to detect if a spool is already running
If there is no records for the last 15 seconds, previous spool session is assumed to have ended.
If there are newer records, then stop here, and assume the running mailer will take care of it.
View
@@ -1,4 +1,3 @@
-#! /usr/bin/php -q
<?php
/***************************************************************
* Copyright notice
@@ -22,37 +21,20 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
-require_once('clirun.php');
+require_once(t3lib_extMgm::extPath('newsletter') . 'class.tx_newsletter_bouncehandler.php');
-/* Write a new fetchmailrc */
-$fetchmailhome = PATH_site.'uploads/tx_newsletter';
-$fetchmailfile = "$fetchmailhome/fetchmailrc";
-$servers = array();
-$rs = $TYPO3_DB->sql_query("SELECT protocol, server, username, password FROM tx_newsletter_domain_model_bounceaccount
- WHERE hidden = 0
- AND deleted = 0");
-while (list($protocol, $server, $username, $passwd) = $TYPO3_DB->sql_fetch_row($rs)) {
- $contents .= "poll $server proto $protocol username \"$username\" password \"$passwd\"\n";
- $servers[] = $server;
+// If nothing is piped to this script, we fetch bounce emails from servers (who will then be piped to this script)
+if (ftell(STDIN) === false)
+{
+ tx_newsletter_bouncehandler::fetchBouncedEmails();
}
-file_put_contents($fetchmailfile, $contents);
-
-chmod($fetchmailfile, 0600);
-
-putenv("FETCHMAILHOME=$fetchmailhome");
-
-$theconf = unserialize($TYPO3_CONF_VARS['EXT']['extConf']['newsletter']);
-$fetchmail = $theconf['path_to_fetchmail'];
-
-/* Keep messages on server */
-if ($theconf['keep_messages']) {
- $keep = '--keep ';
+// Else, an email was piped, we dispatch it to analyze its bounce level an take appropriate action
+else
+{
+ // Read piped email raw source
+ $content = file_get_contents('php://stdin');
+
+ $bounceHandler = new tx_newsletter_bouncehandler($content);
+ $bounceHandler->dispatch();
}
-
-
-foreach ($servers as $server) {
- exec($fetchmail.' -m '.dirname(__FILE__).'/readmail.php -s '.$keep.$server, $result);
-}
-
-unlink($fetchmailfile);
View
@@ -1,13 +0,0 @@
-<?php
-
-// DO NOT REMOVE OR CHANGE THESE 3 LINES:
-define('TYPO3_MOD_PATH', '../typo3conf/ext/newsletter/cli/');
-$BACK_PATH = '../../../../typo3/';
-$MCONF['name'] = '_CLI_newsletter';
-
-define('TYPO3_cliMode', TRUE);
-define('TYPO3_PROCEED_IF_NO_USER', TRUE);
-define('PATH_thisScript', __FILE__);
-
-require_once(dirname(PATH_thisScript).'/'.$BACK_PATH.'init.php');
-require_once(t3lib_extMgm::extPath('newsletter')."class.tx_newsletter_tools.php");
View
@@ -1,4 +1,3 @@
-#! /usr/bin/php -q
<?php
/***************************************************************
* Copyright notice
@@ -23,7 +22,5 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
-require_once('clirun.php');
-
tx_newsletter_tools::createAllSpool();
tx_newsletter_tools::runSpoolOneAll();
@@ -1,4 +1,3 @@
-#! /usr/bin/php -q
<?php
/***************************************************************
* Copyright notice
@@ -23,7 +22,5 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
-require_once('clirun.php');
-
tx_newsletter_tools::createAllSpool(true);
tx_newsletter_tools::runSpoolOneAll(true);
View
@@ -1,13 +0,0 @@
-#! /usr/bin/php -q
-<?php
-require_once('clirun.php');
-require_once(t3lib_extMgm::extPath('newsletter').'class.tx_newsletter_bouncehandler.php');
-
-$fd = fopen('php://stdin', 'r');
-while ($buffer = fread($fd, 8096)) {
- $content .= $buffer;
-}
-fclose($fd);
-
-$bounceHandler = new tx_newsletter_bouncehandler($content);
-$bounceHandler->dispatch();
@@ -1,4 +1,3 @@
-#! /usr/bin/php -q
<?php
/***************************************************************
* Copyright notice
@@ -23,8 +22,6 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
-require_once('clirun.php');
-
/***************** Send script ********************/
tx_newsletter_tools::createAllSpool();
@@ -22,7 +22,6 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
-require_once('clirun.php');
tx_newsletter_tools::runSpoolOneAll();
View
@@ -7,6 +7,14 @@
if (!isset($TYPO3_CONF_VARS['EXTCONF']['newsletter']['extraMailHeaders']['X-Precedence'])) $TYPO3_CONF_VARS['EXTCONF']['newsletter']['extraMailHeaders']['X-Precedence'] = 'bulk';
if (!isset($TYPO3_CONF_VARS['EXTCONF']['newsletter']['extraMailHeaders']['X-Provided-by'])) $TYPO3_CONF_VARS['EXTCONF']['newsletter']['extraMailHeaders']['X-Sponsored-by'] = 'http://www.casalogic.dk/ - Open Source Experts.';
+
+// Register keys for CLI
+$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['newsletter_mailer'] = array('EXT:newsletter/cli/mailer.php', '_CLI_newsletter');
+$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['newsletter_mailer_test_only'] = array('EXT:newsletter/cli/mailer_test_only.php', '_CLI_newsletter');
+$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['newsletter_spool_create'] = array('EXT:newsletter/cli/spool_create.php', '_CLI_newsletter');
+$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['newsletter_spool_run'] = array('EXT:newsletter/cli/spool_run.php', '_CLI_newsletter');
+$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['newsletter_bounce'] = array('EXT:newsletter/cli/bounce.php', '_CLI_newsletter');
+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_newsletter_NewsletterTask'] = array(
'extension' => $_EXTKEY,
'title' => 'Run Newsletter',

0 comments on commit 6e26507

Please sign in to comment.