From 862074ccfde83e513c59059e8dc2cbb29274479b Mon Sep 17 00:00:00 2001 From: Matthieu Renard Date: Wed, 6 Nov 2024 16:15:45 +0100 Subject: [PATCH 1/2] Fixed a bug with empty events When an event was empty (i.e. no object, no summary, almost nothing but an id, uid), the event parsing lead to a bug that would cause the application to fail loading the table of people or locations. This was mainly due to the start and end dates not being declared as possibly null when they should have been. I also cleaned up some code with array accesses that would spam a lot of errors in the Nextcloud logging because the offsets do not exist. I just used null-safe operators to set default values when this happens. --- lib/MyClass/MyEvent.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/MyClass/MyEvent.php b/lib/MyClass/MyEvent.php index e8c0609..c4a48e3 100755 --- a/lib/MyClass/MyEvent.php +++ b/lib/MyClass/MyEvent.php @@ -8,13 +8,13 @@ class MyEvent { - public String $id; - public String $summary; - public String $dtStart; - public String $dtEnd; - public String $place; - public String $place2; - public String $nextcloud_users; + public string $id; + public string $summary; + public ?string $dtStart; + public ?string $dtEnd; + public string $place; + public string $place2; + public string $nextcloud_users; public $quote; public bool $valid; @@ -31,12 +31,12 @@ public function __construct( $this->log = $logger; $this->myDb = $myDb; $this->id = $e['id']; - $this->dtStart = $e["objects"][0]["DTSTART"][0]?->modify('+ 1 minute')?->format('Y-m-d H:i:s'); - $this->dtEnd = $e["objects"][0]["DTEND"][0]?->modify('- 1 minute')?->format('Y-m-d H:i:s') ?? $this->dtStart; + $this->dtStart = ($e["objects"][0]["DTSTART"][0] ?? null)?->modify('+ 1 minute')?->format('Y-m-d H:i:s'); + $this->dtEnd = ($e["objects"][0]["DTEND"][0] ?? null)?->modify('- 1 minute')?->format('Y-m-d H:i:s') ?? $this->dtStart; $this->nextcloud_users = $this->getNameCalendar($this->id); - $this->summary = str_replace("@", "", $e["objects"][0]["SUMMARY"][0]); + $this->summary = str_replace("@", "", $e["objects"][0]["SUMMARY"][0] ?? ''); - $tmp = $this->extractData(",", 0, $e["objects"][0]["SUMMARY"][0]); + $tmp = $this->extractData(",", 0, $e["objects"][0]["SUMMARY"][0] ?? ''); if (!is_null($this->dtStart) && count($tmp) > 0) { $this->place = $tmp[0]; if (count($tmp) >= 2) { @@ -108,9 +108,12 @@ public function extractData($separator, $position, $data): array preg_match_all($re, strtolower($data), $matches, PREG_SET_ORDER, 0); try { - $cls = [$matches[0][1]]; - if (count($matches[0]) >= 4) { - array_push($cls, $matches[0][3]); + $cls = []; + if (isset($matches[0][1])) { + $cls[] = $matches[0][1]; + } + if (count($matches[0] ?? []) >= 4) { + $cls[] = $matches[0][3]; } } catch (\Throwable $th) { $cls = []; From aebcfcc9f1cb6002ec83ca0c1b53a24c7ca39031 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Wed, 6 Nov 2024 15:38:56 +0000 Subject: [PATCH 2/2] v0.0.37 --- appinfo/info.xml | 4 ++-- templates/navigation/index.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 414fc8e..477fcb7 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -4,7 +4,7 @@ Where am I ? - 0.0.36 + 0.0.37 agpl ADACIS Whereami @@ -12,7 +12,7 @@ organization https://github.com/Adacis/whereami/issues - + OCA\Whereami\Settings\WhereamiAdmin diff --git a/templates/navigation/index.php b/templates/navigation/index.php index 27ac4cf..474317d 100644 --- a/templates/navigation/index.php +++ b/templates/navigation/index.php @@ -1,5 +1,5 @@
    -
  • Where am I V 0.0.36
  • +
  • Where am I V 0.0.37