From 4140ded5b3086eabd2dd1e89af2618144acf0215 Mon Sep 17 00:00:00 2001 From: Aerex Date: Mon, 28 Sep 2020 23:48:55 -0500 Subject: [PATCH] fix: Generalized import cal events not from source storages --- lib/Plugin.php | 10 +++++++--- lib/StorageManager.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Plugin.php b/lib/Plugin.php index 4d01e91..d6450b1 100644 --- a/lib/Plugin.php +++ b/lib/Plugin.php @@ -51,8 +51,12 @@ class Plugin extends ServerPlugin { } private function getDisplayName($path) { - $node = $this->server->tree->getNodeForPath($path); - $propFind = new PropFind($path, []); + // Remove filepath + $urlParts = explode('/', $path); + $calendarUrl = implode('/', array_slice($urlParts, 0, count($urlParts)-1)); + + $node = $this->server->tree->getNodeForPath($calendarUrl); + $propFind = new PropFind($calendarUrl, []); $properties = $this->server->getPropertiesByNode($propFind, $node); return $properties['d:displayname'] ?? ''; @@ -138,7 +142,7 @@ class Plugin extends ServerPlugin { $vCal = \Sabre\VObject\Reader::read($body); $displayname = $this->getDisplayName($request->getPath()); try { - if (!stristr($vCal->PRODID, 'taskwarrior')) { + if (!$this->storageManager->fromStorageSource($vCal)) { $this->storageManager->import($vCal, $displayname); } } catch(BadRequest $e){ diff --git a/lib/StorageManager.php b/lib/StorageManager.php index 7930276..d70eac4 100644 --- a/lib/StorageManager.php +++ b/lib/StorageManager.php @@ -22,6 +22,18 @@ class StorageManager { $this->configs = $configs; } + public function fromStorageSource(Calendar $calendar) { + if (!isset($this->configs)) { + throw new \Exception('StorageManager was not initialize or configs are not defined'); + } + foreach ($this->configs['storages'] as $storage => $value) { + if (stristr($calendar->PRODID, $storage)) { + return true; + } + } + return false; + } + public function getStorages() { return $this->storages; }