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) {
|
private function getDisplayName($path) {
|
||||||
$node = $this->server->tree->getNodeForPath($path);
|
// Remove filepath
|
||||||
$propFind = new PropFind($path, []);
|
$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);
|
$properties = $this->server->getPropertiesByNode($propFind, $node);
|
||||||
return $properties['d:displayname'] ?? '';
|
return $properties['d:displayname'] ?? '';
|
||||||
|
|
||||||
@ -138,7 +142,7 @@ class Plugin extends ServerPlugin {
|
|||||||
$vCal = \Sabre\VObject\Reader::read($body);
|
$vCal = \Sabre\VObject\Reader::read($body);
|
||||||
$displayname = $this->getDisplayName($request->getPath());
|
$displayname = $this->getDisplayName($request->getPath());
|
||||||
try {
|
try {
|
||||||
if (!stristr($vCal->PRODID, 'taskwarrior')) {
|
if (!$this->storageManager->fromStorageSource($vCal)) {
|
||||||
$this->storageManager->import($vCal, $displayname);
|
$this->storageManager->import($vCal, $displayname);
|
||||||
}
|
}
|
||||||
} catch(BadRequest $e){
|
} catch(BadRequest $e){
|
||||||
|
@ -22,6 +22,18 @@ class StorageManager {
|
|||||||
$this->configs = $configs;
|
$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() {
|
public function getStorages() {
|
||||||
return $this->storages;
|
return $this->storages;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user