fixed async job was not removed, if facations was deactivated and only try to reschedule with increasing intervals for 2 days

This commit is contained in:
Ralf Becker 2014-07-22 12:52:10 +00:00
parent be405e847c
commit c07599aa27

View File

@ -507,6 +507,7 @@ class mail_sieve
elseif ($content['acc_id']) elseif ($content['acc_id'])
{ {
$this->account = emailadmin_account::read($content['acc_id']); $this->account = emailadmin_account::read($content['acc_id']);
$preserv['acc_id'] = $content['acc_id'];
} }
$icServer = $this->account->imapServer($this->is_admin_vac ? $account_id : false); $icServer = $this->account->imapServer($this->is_admin_vac ? $account_id : false);
@ -614,7 +615,8 @@ class mail_sieve
// schedule job to switch message on/off, if request and not already in past // schedule job to switch message on/off, if request and not already in past
else else
{ {
if ($newVacation['status'] == 'by_date' && $newVacation['end_date']+24*3600 > time()) if ($newVacation['status'] == 'by_date' && $newVacation['end_date']+24*3600 > time() ||
$vacRules && $vacRules['vacation']['status'] == 'by_date')
{ {
self::setAsyncJob($newVacation); self::setAsyncJob($newVacation);
} }
@ -694,19 +696,24 @@ class mail_sieve
$async->delete($async_id); $async->delete($async_id);
$end_date = $_vacation['end_date'] + 24*3600; // end-date is inclusive, so we have to add 24h $end_date = $_vacation['end_date'] + 24*3600; // end-date is inclusive, so we have to add 24h
if ($_vacation['status'] == 'by_date' && time() < $end_date && $_reschedule===false) if ($_vacation['status'] == 'by_date' && time() < $end_date && !$_reschedule)
{ {
$time = time() < $_vacation['start_date'] ? $_vacation['start_date'] : $end_date; $time = time() < $_vacation['start_date'] ? $_vacation['start_date'] : $end_date;
$async->set_timer($time,$async_id, 'mail_sieve::async_vacation', $_vacation, $_vacation['account_id']); $async->set_timer($time,$async_id, 'mail_sieve::async_vacation', $_vacation, $_vacation['account_id']);
} }
if ($_reschedule) if ($_reschedule)
{ {
$time = time() + 60*3; $_vacation['rescheduled'] = $_vacation['rescheduled'] ? 2*$_vacation['rescheduled'] : 5;
// only try to reschedule for 2 days max
if ($_vacation['rescheduled'] <= 2 * 24 * 60)
{
$time = time() + 60*($_vacation['rescheduled']);
unset($_vacation['next']); unset($_vacation['next']);
unset($_vacation['times']); unset($_vacation['times']);
$async->set_timer($time, $async_id, 'mail_sieve::async_vacation', $_vacation, $_vacation['account_id']); $async->set_timer($time, $async_id, 'mail_sieve::async_vacation', $_vacation, $_vacation['account_id']);
} }
} }
}
/** /**
* Callback for the async job to enable/disable the vacation message * Callback for the async job to enable/disable the vacation message
@ -728,6 +735,12 @@ class mail_sieve
$ret = $icServer->setVacationUser($_vacation['account_id'], null, $_vacation); $ret = $icServer->setVacationUser($_vacation['account_id'], null, $_vacation);
self::setAsyncJob($_vacation); self::setAsyncJob($_vacation);
} }
// if mail account no longer exists --> remove async job
catch (egw_exception_not_found $e)
{
$_vacation['status'] = 'off';
self::setAsyncJob($_vacation);
}
catch (Exception $e) { catch (Exception $e) {
error_log(__METHOD__.'('.array2string($_vacation).' failed '.$e->getMessage()); error_log(__METHOD__.'('.array2string($_vacation).' failed '.$e->getMessage());
self::setAsyncJob($_vacation, true); // reschedule self::setAsyncJob($_vacation, true); // reschedule