Skip to content

Commit

Permalink
use static var instead of session - #399
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMosin committed Jan 31, 2023
1 parent 430f1d6 commit a9bccdc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 42 deletions.
5 changes: 1 addition & 4 deletions lib/Backend/BCSabreImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions lib/Backend/BackendUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
27 changes: 13 additions & 14 deletions lib/Backend/DavListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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");
}

Expand All @@ -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}},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions lib/Backend/HintVar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace OCA\Appointments\Backend;

class HintVar
{
public const APPT_NONE = 0;
public const APPT_BOOK = 1;
public const APPT_CONFIRM = 2;
public const APPT_CANCEL = 3;
public const APPT_SKIP = 4;
public const APPT_TYPE_CHANGE = 5;

/** @type int $hint */
private static $hint = self::APPT_NONE;

public static function setHint(int $hint)
{
self::$hint = $hint;
}

public static function getHint(): int
{
return self::$hint;
}
}
21 changes: 5 additions & 16 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OC\AppFramework\Middleware\Security\Exceptions\NotLoggedInException;
use OCA\Appointments\Backend\BackendManager;
use OCA\Appointments\Backend\BackendUtils;
use OCA\Appointments\Backend\HintVar;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\NotFoundResponse;
Expand Down Expand Up @@ -358,10 +359,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_CONFIRM);
HintVar::setHint(HintVar::APPT_CONFIRM);

list($sts, $date_time, $attendeeName) = $this->bc->confirmAttendee($userId, $cal_id, $uri);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit a9bccdc

Please sign in to comment.