From ef69a1a2f36c25c8447286b7e7472940ce18540d Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 29 Apr 2020 13:10:20 +0200 Subject: [PATCH] Changed: Now single ampel_id is checked, if it is active + better code . If parameter ampel_id is passed to the job, it will now get the ampel data only if it is active. . Clearer way of treating dauerampel in code. --- application/controllers/jobs/AmpelMail.php | 49 ++++++++-------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/application/controllers/jobs/AmpelMail.php b/application/controllers/jobs/AmpelMail.php index ba4bc7f9e..00c4303db 100644 --- a/application/controllers/jobs/AmpelMail.php +++ b/application/controllers/jobs/AmpelMail.php @@ -47,24 +47,13 @@ class AmpelMail extends CLI_Controller // if ampel_id is given, get this ampel only if (is_numeric($ampel_id)) { - $result = $this->AmpelModel->load($ampel_id); - - if (hasData($result)) - { - // check, if email is true - $result_active_ampeln = $result->retval[0]->email == 't' ? $result : success(array()); - } - else - { - $result_active_ampeln = success(array()); - } + $result_active_ampeln = $this->AmpelModel->active($ampel_id, true); } // else get all active ampeln else { // Get all notifications, that are not expired, not before vorlaufzeit AND email is true - // AND is NOT DAUERAMPEL (dauerampeln must be run by specific ampel_id) - $result_active_ampeln = $this->AmpelModel->active(true, false); + $result_active_ampeln = $this->AmpelModel->active(null, true); } // Stores users, description, deadline and system-link of notifications @@ -101,30 +90,26 @@ class AmpelMail extends CLI_Controller { $uid = $ampel_user->uid; - if (!$dauerampel) - { - // break if ampel was almost confirmed by the user - if($this->AmpelModel->isConfirmed($ampel_id, $uid)) - continue; - - // check if ampel is new (inserted within last week, as cronjob will run every week) - if ($now->diff($insert_date)->days <= 7) $new = true; - - //check if ampel is overdue - if ($now > $deadline) $overdue = true; - } + // break if ampel was almost confirmed by the user + if($this->AmpelModel->isConfirmed($ampel_id, $uid)) + continue; + /** - * if ampel is dauerampel - **/ - elseif ($dauerampel) + * check if ampel is new + * inserted within last week, as cronjob will run every week + * OR if ampel is dauerampel (cannot be overdued -> treat always as new) + * */ + if (($now->diff($insert_date)->days <= 7) || $dauerampel) { - /** - * treat dauerampel always as new - * NOTE: dauerampel stops, when benutzer not queried by benutzerselect anymore - **/ $new = true; } + // check if ampel is overdue + if (($now > $deadline) && !$dauerampel) + { + $overdue = true; + } + // if ampel is new if ($new) {