Zum Inhalt springen

directmail per cronjob

Erstellt am 17. Dezember 2007 · 12 Antworten · letzte Antwort am 14. Dezember 2008

Tags: Direct Mail, Server & Hosting, Frage

wurgli ·
#!/usr/bin/php -q
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
*  (c) 2004-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
*  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.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  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!
***************************************************************/
/**
 * Cron stack for sending mails
 *
 * @author		Kasper Skaarhoj <kasperYYYY@typo3.com>
 * @author		Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
 *
 * @package 	TYPO3
 * @subpackage 	tx_directmail
 * @version		$Id: dmailerd.phpcron 7107 2007-10-26 10:04:10Z tkahler $
 *
 */
error_reporting (E_ALL ^ E_NOTICE);
if ($_SERVER['PHP_SELF']) {
	if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_SERVER['PHP_SELF'])));
} else {
	if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_ENV['_'])));
}
if (!defined('PATH_site')) define('PATH_site', dirname(dirname(dirname(dirname(dirname(dirname(PATH_thisScript)))))).'/');
if (!defined('PATH_t3lib')) if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
define('PATH_typo3conf', PATH_site.'typo3conf/');
define('TYPO3_mainDir', 'typo3/');
if (!defined('PATH_typo3')) define('PATH_typo3', PATH_site.TYPO3_mainDir);
if (!defined('PATH_tslib')) {
	if (@is_dir(PATH_site.'typo3/sysext/cms/tslib/')) {
		define('PATH_tslib', PATH_site.'typo3/sysext/cms/tslib/');
	} elseif (@is_dir(PATH_site.'tslib/')) {
		define('PATH_tslib', PATH_site.'tslib/');
	}
}
define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
define('TYPO3_MODE', 'BE');

#require_once(PATH_t3lib.'class.t3lib_div.php');
#require_once(PATH_t3lib.'class.t3lib_extmgm.php');
#require_once(PATH_t3lib.'config_default.php');
require_once('/home/websites/www.domain.at/t3lib/class.t3lib_div.php');
require_once('/home/websites/www.domain.at/t3lib/class.t3lib_extmgm.php');
require_once('/home/websites/www.domain.at/t3lib/config_default.php');
require_once('/home/websites/www.domain.at/typo3conf/localconf.php');

/**
 * added some auth library. Might be needed by other extension
 */
require_once(PATH_t3lib.'class.t3lib_userauth.php');
require_once(PATH_t3lib.'class.t3lib_userauthgroup.php');
require_once(PATH_t3lib.'class.t3lib_beuserauth.php');

if (!defined ('TYPO3_db'))  die ('The configuration file was not included.');
if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS']))      die('You cannot set the GLOBALS-array from outside this script.');

	// Check if cronjob is already running:
if (@file_exists (PATH_site.'typo3temp/tx_directmail_cron.lock')) {
		// If the lock is not older than 1 day, skip index creation:
	if (filemtime (PATH_site.'typo3temp/tx_directmail_cron.lock') > (time() - (60*60*24))) {
		die('TYPO3 Direct Mail Cron: Aborting, another process is already running!'.chr(10));
	} else {
		echo('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...'.chr(10));
	}
}

$lockfile = PATH_site.'typo3temp/tx_directmail_cron.lock';
touch ($lockfile);

	// Connect to the database
require_once(PATH_t3lib.'class.t3lib_db.php');
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
$result = $TYPO3_DB->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
if (!$result)	{
	unlink ($lockfile);
	die("Couldn't connect to database at ".TYPO3_db_host);
}
$TYPO3_DB->sql_select_db(TYPO3_db);

// ****************************************************
// Include tables customization (tables + ext_tables)
// ****************************************************
include (TYPO3_tables_script ? PATH_typo3conf.TYPO3_tables_script : PATH_t3lib.'stddb/tables.php');
	// Extension additions
if ($TYPO3_LOADED_EXT['_CACHEFILE'])    {
	include (PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php');
} else {
	include (PATH_t3lib.'stddb/load_ext_tables.php');
}
	// extScript
if (TYPO3_extTableDef_script)   {
	include (PATH_typo3conf.TYPO3_extTableDef_script);
}

#require_once(PATH_t3lib.'class.t3lib_cs.php');
require_once('/home/websites/www.domain.at/t3lib/class.t3lib_cs.php');
require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
require_once(t3lib_extMgm::extPath('direct_mail').'res/scripts/class.dmailer.php');

$htmlmail = t3lib_div::makeInstance('dmailer');
$htmlmail->start();
$htmlmail->runcron();

unlink ($lockfile);

?>
sala ·

Habe nun eine Teil-Lösung gefunden:

In dmailerd.phpcron Zeile 46 auskommentieren
/*if (!defined('PATH_site')) define('PATH_site', dirname(dirname
(dirname(dirname(dirname(dirname(PATH_thisScript)))))).'/');*/

und den Pfad zum Root-Verzeichis definieren, in meinem Falle:
define('PATH_site','../../../../../../html/');

Die Newsletter werden nun versendet, bekomme aber trotzdem folgende Fehlermeldung:

<br />
<b>Warning</b>:  loadtca(../../../../../../public_html/typo3conf/../../../../../../public_html/typo3/sysext/cms/tbl_tt_content.php) [<a href='function.loadtca'>function.loadtca</a>]: failed to open stream: No such file or directory in <b>/home/footstepch/public_html/t3lib/class.t3lib_div.php</b> on line <b>3789</b><br />
<br />
<b>Warning</b>:  loadtca(../../../../../../public_html/typo3conf/../../../../../../public_html/typo3/sysext/cms/tbl_tt_content.php) [<a href='function.loadtca'>function.loadtca</a>]: failed to open stream: No such file or directory in <b>/home/footstepch/public_html/t3lib/class.t3lib_div.php</b> on line <b>3789</b><br />
<br />
<b>Warning</b>:  loadtca() [<a href='function.include'>function.include</a>]: Failed opening '../../../../../../public_html/typo3conf/../../../../../../public_html/typo3/sysext/cms/tbl_tt_content.php' for inclusion (include_path='.:/usr/local/lib/php') in <b>/home/footstepch/public_html/t3lib/class.t3lib_div.php</b> on line <b>3789</b><br />
<br />

weiß jemand Rat?

Gianni ·

Ich denke, es liegt daran, dass eine Pfadangabe nicht stimmt. Hab gerade die .phpcron verglichen. Meines sieht genau gleich aus.

Ich würde ein php-File drausmachen und via browser aufrufen und die Pfade überprüfen:

if (@file_exists (PATH_site.'typo3temp/tx_directmail_cron.lock')) {
die("ok gefunden");
}

Sonst fällt mir nix ein, sorry.

Gruss Gianni

sala ·

Habs nun via Browser aufgerufen.

Folgende Fehlermeldung kommt:
Warning: main(//t3lib/class.t3lib_div.php) [function.main]: failed to open stream: No such file or directory in /home/footstepch/public_html/typo3conf/ext/direct_mail/res/scripts/dmailerd.php on line 61

Fatal error: main() [function.require]: Failed opening required '//t3lib/class.t3lib_div.php' (include_path='.:/usr/local/lib/php') in /home/footstepch/public_html/typo3conf/ext/direct_mail/res/scripts/dmailerd.php on line 61

Denke mal das hier
//t3lib/class.t3lib_div.php
ein "/" am Anfang zu viel ist!?

Nur wo bekomme ich diesen weg?

Gianni ·

Was ist bei dir die Zeile 61?

Diese:

require_once(PATH_t3lib.'class.t3lib_div.php');

Gib mal die Variable PATH_t3lib aus:

die(PATH_t3lib.'class.t3lib_div.php');
require_once(PATH_t3lib.'class.t3lib_div.php');

Was kommt raus?

sala ·

Folgendes kommt raus:

//t3lib/class.t3lib_div.php

#!/usr/bin/php -q
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
*  (c) 2004-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
*  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.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  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!
***************************************************************/
/**
 * Cron stack for sending mails
 *
 * @author		Kasper Skaarhoj <kasperYYYY@typo3.com>
 * @author		Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
 *
 * @package 	TYPO3
 * @subpackage 	tx_directmail
 * @version		$Id: dmailerd.phpcron 7107 2007-10-26 10:04:10Z tkahler $
 *
 */
error_reporting (E_ALL ^ E_NOTICE);
if ($_SERVER['PHP_SELF']) {
	if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_SERVER['PHP_SELF'])));
} else {
	if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_ENV['_'])));
}
if (!defined('PATH_site')) define('PATH_site', dirname(dirname(dirname(dirname(dirname(dirname(PATH_thisScript)))))).'/');
if (!defined('PATH_t3lib')) if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
define('PATH_typo3conf', PATH_site.'typo3conf/');
define('TYPO3_mainDir', 'typo3/');
if (!defined('PATH_typo3')) define('PATH_typo3', PATH_site.TYPO3_mainDir);
if (!defined('PATH_tslib')) {
	if (@is_dir(PATH_site.'typo3/sysext/cms/tslib/')) {
		define('PATH_tslib', PATH_site.'typo3/sysext/cms/tslib/');
	} elseif (@is_dir(PATH_site.'tslib/')) {
		define('PATH_tslib', PATH_site.'tslib/');
	}
}
define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
define('TYPO3_MODE', 'BE');

die(PATH_t3lib.'class.t3lib_div.php');
require_once(PATH_t3lib.'class.t3lib_div.php'); 
require_once(PATH_t3lib.'class.t3lib_extmgm.php');
require_once(PATH_t3lib.'config_default.php');
require_once(PATH_typo3conf.'localconf.php');

/**
 * added some auth library. Might be needed by other extension
 */
require_once(PATH_t3lib.'class.t3lib_userauth.php');
require_once(PATH_t3lib.'class.t3lib_userauthgroup.php');
require_once(PATH_t3lib.'class.t3lib_beuserauth.php');

if (!defined ('TYPO3_db'))  die ('The configuration file was not included.');
if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS']))      die('You cannot set the GLOBALS-array from outside this script.');

	// Check if cronjob is already running:
if (@file_exists (PATH_site.'typo3temp/tx_directmail_cron.lock')) {
		// If the lock is not older than 1 day, skip index creation:
	if (filemtime (PATH_site.'typo3temp/tx_directmail_cron.lock') > (time() - (60*60*24))) {
		die('TYPO3 Direct Mail Cron: Aborting, another process is already running!'.chr(10));
	} else {
		echo('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...'.chr(10));
	}
}

$lockfile = PATH_site.'typo3temp/tx_directmail_cron.lock';
touch ($lockfile);

	// Connect to the database
require_once(PATH_t3lib.'class.t3lib_db.php');
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
$result = $TYPO3_DB->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password);
if (!$result)	{
	unlink ($lockfile);
	die("Couldn't connect to database at ".TYPO3_db_host);
}
$TYPO3_DB->sql_select_db(TYPO3_db);

// ****************************************************
// Include tables customization (tables + ext_tables)
// ****************************************************
include (TYPO3_tables_script ? PATH_typo3conf.TYPO3_tables_script : PATH_t3lib.'stddb/tables.php');
	// Extension additions
if ($TYPO3_LOADED_EXT['_CACHEFILE'])    {
	include (PATH_typo3conf.$TYPO3_LOADED_EXT['_CACHEFILE'].'_ext_tables.php');
} else {
	include (PATH_t3lib.'stddb/load_ext_tables.php');
}
	// extScript
if (TYPO3_extTableDef_script)   {
	include (PATH_typo3conf.TYPO3_extTableDef_script);
}

require_once(PATH_t3lib.'class.t3lib_cs.php');
require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
require_once(t3lib_extMgm::extPath('direct_mail').'res/scripts/class.dmailer.php');

$htmlmail = t3lib_div::makeInstance('dmailer');
$htmlmail->start();
$htmlmail->runcron();

unlink ($lockfile);

?>
sala ·

Wenn ich nun die Zeilen 72-74 auch anpasse, bleibt bei deiner Lösung immer noch das Problem:
localconf.php is not found!

sala ·

Nach langen hin und her probieren, habe ich nun eine Lösung gefunden!

In der dmailerd.phpcron die zeilen 41 - 46 löschen.

if ($_SERVER['PHP_SELF']) {
	if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_SERVER['PHP_SELF'])));
} else {
	if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', $_ENV['_'])));
}
if (!defined('PATH_site')) define('PATH_site', dirname(dirname(dirname(dirname(dirname(dirname(PATH_thisScript)))))).'/');

und durch diese ersetzen

define('PATH_typo3', '/home/musterdomainat/public_html/typo3/');
define('PATH_site', '/home/musterdomainat/public_html/');

der pfad muß natürlich an eure Gegebenheiten angepaßt sein.