scripts in de database
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// last execution: 2021-12-27 03:40:02
|
||||
$par_test_mode=false;
|
||||
|
||||
// Initialiseren
|
||||
|
||||
logAdd(log);
|
||||
|
||||
$testmode = $par_test_mode;
|
||||
|
||||
$set_status = 'Pending';
|
||||
$year = datetime\year(datetime\now()) + 1;
|
||||
$year = string\concatenate('', $year);
|
||||
|
||||
// Uitvoeren
|
||||
|
||||
logAdd(log, 'info', 'Klaarzetten Mass Email in Campagne "Visitatie aankondigingen"');
|
||||
logAdd(log, 'info', 'Aankondiging voor visitaties voor jaar: ', $year);
|
||||
|
||||
$targetlist_id = record\findOne('TargetList', 'createdAt', 'desc', 'name=', 'Te visiteren leden');
|
||||
ifThenElse($targetlist_id,
|
||||
logAdd(log, 'info', 'Distributielijst "Te visiteren leden": ', $targetlist_id);
|
||||
$campaign_id = record\findOne('Campaign', 'createdAt', 'desc', 'name=', 'Visitatie aankondigingen');
|
||||
ifThenElse($campaign_id,
|
||||
logAdd(log, 'info', 'Campagne "Visitatie aankondigingen": ', $campaign_id);
|
||||
$email_templ_id = record\findOne('EmailTemplate', 'createdAt', 'desc', 'name=', 'Visitatie aankondiging');
|
||||
ifThenElse($email_templ_id,
|
||||
logAdd(log, 'info', 'Email template "Visitatie aankondiging": ', $email_templ_id);
|
||||
|
||||
// Muteren email template
|
||||
$templates = record\fetchManyHash('EmailTemplate', 'subject, body', 'createdAt', 'desc', 'id=', $email_templ_id);
|
||||
$templ = array\at($templates, 0);
|
||||
$templmail = configGet('visitatie-email-template-aankondiging');
|
||||
$subject = hash\get($templ, 'subject');
|
||||
//$body = hash\get($templ, 'body');
|
||||
$body = $templmail;
|
||||
|
||||
$m0 = string\match($subject, '/[2][0-9]{3}/');
|
||||
$m1 = "{{visitatiejaar}}";
|
||||
//$m1 = string\match($body, '/[2][0-9]{3}/');
|
||||
|
||||
//logAdd(log, 'info', 'Subject: ', $subject, ' m0: ', $m0);
|
||||
//logAdd(log, 'info', 'Body: ', $body, ' m1: ', $m1);
|
||||
|
||||
ifThen($m0,
|
||||
$subject = string\replace($subject, $m0, $year);
|
||||
//logAdd(log, 'info', 'New subject: ', $subject);
|
||||
);
|
||||
ifThen($m1,
|
||||
$body = string\replace($body, $m1, $year);
|
||||
//logAdd(log, 'info', 'New body: ', $body);
|
||||
);
|
||||
|
||||
record\update('EmailTemplate', $email_templ_id, 'subject', $subject, 'body', $body);
|
||||
|
||||
// Aanmaken mass email record
|
||||
$rec_name = string\concatenate('Visitatie aankondiging ', $year);
|
||||
$status = $set_status;
|
||||
$startAt = datetime\now();
|
||||
ifThenElse($testmode,
|
||||
logAdd(log, 'warning', 'Test mode - mass email scheduled for today');
|
||||
,
|
||||
$startAt = datetime\closest(datetime\now(), 'date', 28);
|
||||
)
|
||||
|
||||
logAdd(log, 'info', 'startAt: ', datetime\format($startAt, 'Europe/Amsterdam', 'DD/MM/YYYY HH:mm'));
|
||||
|
||||
$mass_email_id = record\create('MassEmail', 'name', $rec_name, 'status', $status, 'startAt', $startAt);
|
||||
record\relate('MassEmail', $mass_email_id, 'campaign', $campaign_id);
|
||||
record\relate('MassEmail', $mass_email_id, 'targetLists', $targetlist_id);
|
||||
record\relate('MassEmail', $mass_email_id, 'emailTemplate', $email_templ_id);
|
||||
,
|
||||
logAdd(log, 'error', 'Email template "Visitatie aankondiging" niet gevonden');
|
||||
)
|
||||
,
|
||||
logAdd(log, 'error', 'Campagne "Visitatie aankondigingen" niet gevonden');
|
||||
);
|
||||
,
|
||||
logAdd(log, 'error', 'Distributielijst "Te visiteren leden" niet gevonden');
|
||||
);
|
||||
Reference in New Issue
Block a user