fix: Generalized import cal events not from source storages
This commit is contained in:
parent
0a01e6e905
commit
4140ded5b3
@ -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){
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user