Files
thetool/scripts/mailtemplate-dispatch.php
2025-01-14 22:41:14 +01:00

51 lines
1.5 KiB
PHP

#!/usr/bin/php
<?php
//require 'vendor/autoload.php';
require("../config/config.php");
define('FRONKDB_SQLDEBUG', false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR . "/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR . "/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR . "/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
define("INTERNAL_USER_ID", $me->id);
define("INTERNAL_USER_USERNAME", $me->username);
define("MFBASE_BYPASS_LOGIN", true);
/*$dispatch = new MailtemplateDispatch(1);
$emails = $dispatch->getRecipients(true);
echo "empfänger emails: ".count($emails)."\n";
//$dispatch->sendToRecipients("fronk@fronk.at");
*/
foreach(MailtemplateDispatch::search(["send_finish" => null, "send_lock" => null]) as $dispatch) {
// check tosend date
if(!$dispatch->tosend_date || $dispatch->tosend_date > date('U')) continue;
// get notification again from DB in case send_lock was set
$dispatch = new MailtemplateDispatch($dispatch->id);
if($dispatch->send_lock) continue;
// first of all set send lock and start date
$mypid = getmypid();
if(!$dispatch->send_start) {
$dispatch->send_start = date("U");
}
$dispatch->send_lock = ($mypid) ? $mypid : 1;
$dispatch->save();
$dispatch->sendToRecipients();
// get Dispatch from DB again and update send lock and finish date
$dispatch = new MailtemplateDispatch($dispatch->id);
$dispatch->send_finish = date('U');
$dispatch->send_lock = null;
$dispatch->save();
}