2020-05-03 16:41:59 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Aerex\BaikalStorage;
|
|
|
|
|
|
|
|
use Sabre\VObject\Component\VCalendar as Calendar;
|
|
|
|
|
|
|
|
class StorageManager {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Storage[]
|
|
|
|
*/
|
|
|
|
|
|
|
|
private $storages = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-12 23:56:22 -05:00
|
|
|
* @var array()
|
2020-05-03 16:41:59 -05:00
|
|
|
*/
|
|
|
|
private $configs;
|
|
|
|
|
2020-05-12 23:56:22 -05:00
|
|
|
public function __construct($configs){
|
|
|
|
$this->configs = $configs;
|
2020-05-03 16:41:59 -05:00
|
|
|
}
|
|
|
|
|
2020-09-28 23:48:55 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-03 16:41:59 -05:00
|
|
|
public function getStorages() {
|
|
|
|
return $this->storages;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getConfigs() {
|
|
|
|
return $this->configs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addStorage($name, $storage) {
|
|
|
|
$this->storages[$name] = $storage;
|
|
|
|
}
|
|
|
|
|
2020-09-18 22:15:12 -05:00
|
|
|
public function import(Calendar $calendar, string $displayname) {
|
2020-05-03 16:41:59 -05:00
|
|
|
if (!isset($this->configs)) {
|
|
|
|
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
|
|
|
}
|
2020-06-03 00:46:06 -05:00
|
|
|
foreach ($this->configs['storages'] as $key => $value) {
|
|
|
|
$storage = $this->storages[$key];
|
|
|
|
if (!isset($storage)){
|
|
|
|
throw new \Exception();
|
2020-05-03 16:41:59 -05:00
|
|
|
}
|
2020-09-18 22:15:12 -05:00
|
|
|
$storage->save($calendar, $displayname);
|
2020-05-03 16:41:59 -05:00
|
|
|
}
|
|
|
|
}
|
2020-06-27 00:56:44 -05:00
|
|
|
|
|
|
|
public function remove($uid) {
|
|
|
|
if (!isset($this->configs)) {
|
|
|
|
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
|
|
|
}
|
|
|
|
foreach ($this->configs['storages'] as $key => $value) {
|
|
|
|
$storage = $this->storages[$key];
|
|
|
|
if (!isset($storage)){
|
|
|
|
throw new \Exception();
|
|
|
|
}
|
|
|
|
$storage->remove($uid);
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 16:41:59 -05:00
|
|
|
}
|
2020-09-18 22:15:12 -05:00
|
|
|
|