MailtemplateDispatch finished
This commit is contained in:
51
scripts/mailtemplate-dispatch.php
Normal file
51
scripts/mailtemplate-dispatch.php
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/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();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user