Commit 37525e30 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1261234: cron job for reseting VERP values

behatnotneeded
Change-Id: Ic549b35dac2d4c069005adba15f721229671294e
parent 56681937
......@@ -242,6 +242,12 @@ $cfg->bounceprefix = 'AAA-';
*/
//$cfg->bouncedomain = '';
/**
* @global number $cfg->bounces_resetdays number of days before reseting the
* emailsent and emailbounced values for each email
*/
$cfg->bounces_resetdays = 30;
/**
* @global string $cfg->imapserver The imap server to check for bounced emails
* @global int $cfg->imapport The port for the imap server
......
......@@ -1104,5 +1104,17 @@ function xmldb_core_upgrade($oldversion=0) {
create_table($table);
}
if ($oldversion < 2018122700) {
// Every day, check if the bounce count needs to be reset
$cron = new StdClass;
$cron->callfunction = 'cron_email_reset_rebounce';
$cron->minute = rand(0, 59);
$cron->hour = rand(0, 23);
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
return $status;
}
......@@ -4706,6 +4706,40 @@ function cron_event_log_expire() {
}
}
function cron_email_reset_rebounce() {
$bounces_handle = get_config('bounces_handle');
$bounces_resetdays = get_config('bounces_resetdays');
if ($bounces_handle && isset($bounces_resetdays) && ($bounces_resetdays > 0)) {
// if this is the first time running the cron, initialise the interaction_config value
$lastbouncereset = get_field('notification_config', 'value', 'plugin', 'email', 'field', 'lastbouncereset');
if ($lastbouncereset) {
$newtime = strtotime('+' . $bounces_resetdays . ' days', $lastbouncereset);
if ($newtime < time()) {
// get all artefact_internal_profile_email records and set mailsbounced to 0
$sql = "UPDATE {artefact_internal_profile_email}
SET mailssent = 0, mailsbounced = 0";
execute_sql($sql);
$pluginrecord = new StdClass;
$pluginrecord->plugin = 'email';
$pluginrecord->field = 'lastbouncereset';
$pluginrecord->value = time();
$whereobj = (object)array(
'plugin' => 'email',
'field' => 'lastbouncereset',
);
update_record('notification_config', $pluginrecord, $whereobj);
}
}
else {
$pluginrecord = new StdClass;
$pluginrecord->plugin = 'email';
$pluginrecord->field = 'lastbouncereset';
$pluginrecord->value = time();
insert_record('notification_config', $pluginrecord);
}
}
}
function build_portfolio_search_html(&$data) {
global $THEME;
$artefacttypes = get_records_assoc('artefact_installed_type');
......
......@@ -1048,6 +1048,7 @@ function core_install_firstcoredata_defaults() {
'check_imap_for_bounces' => array('*', '*', '*', '*', '*'),
'cron_event_log_expire' => array('7', '23', '*', '*', '*'),
'watchlist_process_notifications' => array('*', '*', '*', '*', '*'),
'cron_email_reset_rebounce' => array(rand(0, 59), rand(0, 23), '*', '*', '*'),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new stdClass();
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2018100101;
$config->version = 2018122700;
$config->series = '19.04';
$config->release = '19.04dev';
$config->minupgradefrom = 2017031605;
......
......@@ -27,6 +27,7 @@ Scenario: Clicking ID's (Bug 1428456)
Then I should see "Buck Mulligan"
And I reload the page
And I wait "1" seconds
And I scroll to the top
And I follow "Text"
And I press "Add"
And I set the following fields to these values:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment