From a9bccdc8d58d2fb2d2821436af86e2eb3e0fcb78 Mon Sep 17 00:00:00 2001 From: Sergey Mosin Date: Mon, 30 Jan 2023 22:17:28 -0500 Subject: [PATCH] use static var instead of session - #399 --- lib/Backend/BCSabreImpl.php | 5 +---- lib/Backend/BackendUtils.php | 8 -------- lib/Backend/DavListener.php | 27 +++++++++++++-------------- lib/Backend/HintVar.php | 26 ++++++++++++++++++++++++++ lib/Controller/PageController.php | 21 +++++---------------- 5 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 lib/Backend/HintVar.php diff --git a/lib/Backend/BCSabreImpl.php b/lib/Backend/BCSabreImpl.php index b6c7cf73..e6f75fe1 100644 --- a/lib/Backend/BCSabreImpl.php +++ b/lib/Backend/BCSabreImpl.php @@ -81,10 +81,7 @@ function queryRangePast($calIds, $end, $only_empty, $delete) { if ($delete) { // let's make easier for the DavListener... - $ses = \OC::$server->getSession(); - $ses->set( - BackendUtils::APPT_SES_KEY_HINT, - BackendUtils::APPT_SES_SKIP); + HintVar::setHint(HintVar::APPT_SKIP); // Cleanup hash table if ($only_empty === false) { diff --git a/lib/Backend/BackendUtils.php b/lib/Backend/BackendUtils.php index f30194f8..06bb453d 100644 --- a/lib/Backend/BackendUtils.php +++ b/lib/Backend/BackendUtils.php @@ -35,14 +35,6 @@ class BackendUtils const FLOAT_TIME_FORMAT = "Ymd.His"; - public const APPT_SES_KEY_HINT = "appointment_hint"; - - public const APPT_SES_BOOK = "0"; - public const APPT_SES_CONFIRM = "1"; - public const APPT_SES_CANCEL = "2"; - public const APPT_SES_SKIP = "3"; - public const APPT_SES_TYPE_CHANGE = "4"; - public const KEY_USE_DEF_EMAIL = 'useDefaultEmail'; public const KEY_LIMIT_TO_GROUPS = 'limitToGroups'; public const KEY_EMAIL_FIX = 'emailFixOpt'; diff --git a/lib/Backend/DavListener.php b/lib/Backend/DavListener.php index 7d6ca80f..cca77b6e 100644 --- a/lib/Backend/DavListener.php +++ b/lib/Backend/DavListener.php @@ -360,10 +360,9 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) // \OC::$server->getLogger()->error('DL Debug: M1'); - $ses = \OC::$server->getSession(); - $hint = $ses->get(BackendUtils::APPT_SES_KEY_HINT); - if ($hint === BackendUtils::APPT_SES_SKIP - || ($isDelete && $hint === BackendUtils::APPT_SES_CONFIRM) // <-- booking in to a different calendar NOT deleting + $hint = HintVar::getHint(); + if ($hint === HintVar::APPT_SKIP + || ($isDelete && $hint === HintVar::APPT_CONFIRM) // <-- booking in to a different calendar NOT deleting ) { // no need for email return; @@ -474,7 +473,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $att = $utils->getAttendee($evt); if ($att === null - || ($hint === null + || ($hint === HintVar::APPT_NONE && ($att->parameters['PARTSTAT']->getValue() === 'DECLINED' || ($hash_ch === null && !$isDelete) || $utils->isApptCancelled($hash, $evt) === true @@ -536,7 +535,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $ext_event_type = -1; - if ($hint === BackendUtils::APPT_SES_BOOK) { + if ($hint === HintVar::APPT_BOOK) { // Just booked, send email to the attendee requesting confirmation... // TRANSLATORS Subject for email, Ex: {{Organization Name}} Appointment (action needed) @@ -567,7 +566,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $om_prefix = $this->l10N->t("Appointment pending"); } - } elseif ($hint === BackendUtils::APPT_SES_CONFIRM) { + } elseif ($hint === HintVar::APPT_CONFIRM) { // Confirm link in the email is clicked ... // ... or the email validation step is skipped @@ -617,10 +616,10 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $ext_event_type = 0; - } elseif ($hint === BackendUtils::APPT_SES_CANCEL || $isDelete) { + } elseif ($hint === HintVar::APPT_CANCEL || $isDelete) { // Canceled or deleted - if ($hint !== null) { + if ($hint !== HintVar::APPT_NONE) { // Cancelled by the attendee (via the email link) // TRANSLATORS Subject for email, Ex: {{Organization Name}} Appointment is Canceled @@ -637,7 +636,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $tmpl->addBodyText($this->l10N->t('Your %1$s appointment scheduled for %2$s is now canceled.', [$org_name, $date_time])); $is_cancelled = true; - if ($eml_settings[BackendUtils::EML_MCNCL] && $hint !== null) { + if ($eml_settings[BackendUtils::EML_MCNCL] && $hint !== HintVar::APPT_NONE) { $om_prefix = $this->l10N->t("Appointment canceled"); } @@ -651,7 +650,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $ext_event_type = 1; - } elseif ($hint === BackendUtils::APPT_SES_TYPE_CHANGE) { + } elseif ($hint === HintVar::APPT_TYPE_CHANGE) { $tmpl->setSubject($this->l10N->t("%s Appointment update", [$org_name])); // TRANSLATORS First line of email, Ex: Dear {{Customer Name}}, @@ -689,7 +688,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $ext_event_type = 3; - } elseif ($hint === null) { + } elseif ($hint === HintVar::APPT_NONE) { // Organizer or External Action (something changed...) // TRANSLATORS Subject for email, Ex: {{Organization Name}} appointment status update @@ -815,7 +814,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $utz_info = $evt->{BackendUtils::TZI_PROP}->getValue()[0]; // .ics attachment - if ($hint !== BackendUtils::APPT_SES_BOOK + if ($hint !== HintVar::APPT_BOOK && $eml_settings[BackendUtils::EML_ICS] === true && $no_ics === false) { @@ -845,7 +844,7 @@ private function handler(array $objectData, array $calendarData, bool $isDelete) $method = 'CANCEL'; if ($isDelete) { // Set proper info, otherwise the .ics file is bad - if ($hint === null) { + if ($hint === HintVar::APPT_NONE) { // Organizer deleted the appointment $evt->STATUS->setValue('CANCELLED'); } else { diff --git a/lib/Backend/HintVar.php b/lib/Backend/HintVar.php new file mode 100644 index 00000000..3065bc49 --- /dev/null +++ b/lib/Backend/HintVar.php @@ -0,0 +1,26 @@ +getSession(); - $ses->set( - BackendUtils::APPT_SES_KEY_HINT, - BackendUtils::APPT_SES_CONFIRM); + HintVar::setHint(HintVar::APPT_CONFIRM); list($sts, $date_time, $attendeeName) = $this->bc->confirmAttendee($userId, $cal_id, $uri); @@ -462,10 +460,7 @@ public function cncf($embed = false) if ($take_action) { // Emails are handled by the DavListener... set the Hint - $ses = \OC::$server->getSession(); - $ses->set( - BackendUtils::APPT_SES_KEY_HINT, - BackendUtils::APPT_SES_CANCEL); + HintVar::setHint(HintVar::APPT_CANCEL); $cls = $this->utils->getUserSettings( BackendUtils::KEY_CLS, $userId); @@ -518,10 +513,7 @@ public function cncf($embed = false) // Appointment type change (Talk integration) // Set hint for dav listener - $ses = \OC::$server->getSession(); - $ses->set( - BackendUtils::APPT_SES_KEY_HINT, - BackendUtils::APPT_SES_TYPE_CHANGE); + HintVar::setHint(HintVar::APPT_TYPE_CHANGE); $cId = $cal_id; $data = $this->bc->getObjectData($cal_id, $uri); @@ -885,10 +877,7 @@ public function showFormPost($userId, $pageId, $embed = false): RedirectResponse // Emails are handled by the DavListener... // ... set the Hint and Confirm/Cancel buttons info - $ses = \OC::$server->getSession(); - $ses->set( - BackendUtils::APPT_SES_KEY_HINT, - ($skip_evs ? BackendUtils::APPT_SES_SKIP : BackendUtils::APPT_SES_BOOK)); + HintVar::setHint($skip_evs ? HintVar::APPT_SKIP : HintVar::APPT_BOOK); $post['_page_id'] = $pageId; $post['_embed'] = $embed === true ? "1" : "0";