Compare commits

..

4 Commits

9 changed files with 54 additions and 69 deletions

View File

@ -12,7 +12,7 @@ composer require aerex/baikal-storage-plugin
You can use the CLI to help you generate a config file or use the example configuration provided in the project. Make sure the file is *writable* by your webserver (e.g Apache, Nginx). You can use the CLI to help you generate a config file or use the example configuration provided in the project. Make sure the file is *writable* by your webserver (e.g Apache, Nginx).
### Use the CLI ### Use the CLI
Run the command `./vendor/bin/baikalstorage` and follow the instructions Run the command `./vendor/baikalstorage` and follow the instructions
### Manual ### Manual
Copy the `example-config.yaml` file and rename it to `config.yaml`. Copy the `example-config.yaml` file and rename it to `config.yaml`.

View File

@ -12,22 +12,22 @@
"repositories": [ "repositories": [
{ {
"type": "vcs", "type": "vcs",
"url": "https://github.com/Aerex/baikal-storage-plugin" "url": "https://git.aerex.me/Aerex/baikal-storage-plugin"
} }
], ],
"bin": [ "bin": [
"bin/baikalstorage" "bin/baikalstorage"
], ],
"require": { "require": {
"php" : "^7.2 || ^8.0", "php": ">=5.5",
"sabre/dav" : "~4.3.0", "sabre/dav" : "~4.1.0",
"sabre/vobject": "^4.2.1", "sabre/vobject": "^4.0",
"nesbot/carbon": "^2.0.0", "nesbot/carbon": "^2.0.0",
"laminas/laminas-validator": "^2.13", "laminas/laminas-validator": "^2.13",
"laminas/laminas-stdlib": "^3.2", "laminas/laminas-stdlib": "^3.2",
"psr/container": "^1.0", "psr/container": "^1.0",
"symfony/config": "3.4|^4.0|^5.0", "symfony/config": "3.4",
"symfony/process": "^3.4|^4.0|^5.0", "symfony/process": "^3.4",
"monolog/monolog": "^2.0", "monolog/monolog": "^2.0",
"symfony/yaml": "~3.0|~4.0", "symfony/yaml": "~3.0|~4.0",
"symfony/console": "^3.4|^4.0|^5.0" "symfony/console": "^3.4|^4.0|^5.0"

View File

@ -22,12 +22,7 @@ class CreateConfigFileCommand extends Command {
public function addtaskwarriorConfig() { public function addtaskwarriorConfig() {
$configs = []; $configs = [];
$taskrcQuestion = new Question('Where is the location for the taskrc file?'); $filePath = $this->io->askQuestion(new Question('Where is the location for the taskrc file?'));
$self = $this;
$taskrcQuestion->setAutocompleterCallback(function(string $input) use ($self) {
return $self->autocompleteFilePathCallback($input);
});
$filePath = $this->io->askQuestion($taskrcQuestion);
$taskrcFilePath = $filePath . '/.taskrc'; $taskrcFilePath = $filePath . '/.taskrc';
if (!file_exists($taskrcFilePath)) { if (!file_exists($taskrcFilePath)) {
throw new \RuntimeException("The taskrc file at $taskrcFilePath does not exist"); throw new \RuntimeException("The taskrc file at $taskrcFilePath does not exist");
@ -75,10 +70,7 @@ class CreateConfigFileCommand extends Command {
// TODO: move create config file code block to function // TODO: move create config file code block to function
$question = new Question('Where to create `config.yaml` configuration file?'); $question = new Question('Where to create `config.yaml` configuration file?');
$self = $this; $question->setAutocompleterCallback($this->autocompleteFilePathCallback);
$question->setAutocompleterCallback(function(string $input) use ($self) {
return $self->autocompleteFilePathCallback($input);
});
$filePath = $this->io->askQuestion($question); $filePath = $this->io->askQuestion($question);
try { try {
@ -133,14 +125,7 @@ class CreateConfigFileCommand extends Command {
$this->configs['general'] = []; $this->configs['general'] = [];
if ($this->io->confirm('Enable logging?')) { if ($this->io->confirm('Enable logging?')) {
$this->configs['general']['logger'] = []; $this->configs['general']['logger'] = [];
$logFilePath = $this->io->askQuestion(new Question('Where to create log file?'));
$logFileQuestion = new Question('Where to create log file?');
$self = $this;
$logFileQuestion->setAutocompleterCallback(function(string $input) use ($self) {
return $self->autocompleteFilePathCallback($input);
});
$logFilePath = $this->io->askQuestion($logFileQuestion);
$this->configs['general']['logger']['file'] = $this->verifyAndCreateFile($logFilePath, CreateConfigFileCommand::$LOGGER_FILE_NAME); $this->configs['general']['logger']['file'] = $this->verifyAndCreateFile($logFilePath, CreateConfigFileCommand::$LOGGER_FILE_NAME);
$logLevelChoiceQuestion = new ChoiceQuestion('Log level (defaults to ERROR)', array_keys(Monolog::getLevels()), 4); $logLevelChoiceQuestion = new ChoiceQuestion('Log level (defaults to ERROR)', array_keys(Monolog::getLevels()), 4);

View File

@ -21,9 +21,9 @@ class ConfigBuilder implements ConfigurationInterface {
} }
public function getConfigTreeBuilder() { public function getConfigTreeBuilder() {
$treeBuilder = new TreeBuilder('configs', 'array'); $treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->getRootNode(); $rootNode = $treeBuilder->root('configs');
$ref = $rootNode->children() $ref = $rootNode->children()
->arrayNode('general') ->arrayNode('general')
->children() ->children()
->arrayNode('logger') ->arrayNode('logger')

View File

@ -47,12 +47,11 @@ class Plugin extends ServerPlugin {
function __construct($configFile){ function __construct($configFile){
$this->rawConfigs = $this->buildConfigurations($configFile); $this->rawConfigs = $this->buildConfigurations($configFile);
$this->storageManager = new StorageManager($this->rawConfigs); $this->storageManager = new StorageManager($this->rawConfigs);
$this->logger = new Logger($this->rawConfigs, 'BaikalStorage');
$this->initializeStorages($this->rawConfigs); $this->initializeStorages($this->rawConfigs);
} }
private function getDisplayName($path) { private function getDisplayName($path) {
// Remove filepath // Remove filepath (e.g Remove xxxx.ics from calendars/collection_name/xxxx.ics)
$urlParts = explode('/', $path); $urlParts = explode('/', $path);
$calendarUrl = implode('/', array_slice($urlParts, 0, sizeof($urlParts)-1)); $calendarUrl = implode('/', array_slice($urlParts, 0, sizeof($urlParts)-1));
@ -308,3 +307,4 @@ class Plugin extends ServerPlugin {
} }
} }

View File

@ -22,10 +22,6 @@ class StorageManager {
$this->configs = $configs; $this->configs = $configs;
} }
public function getStorages() {
return $this->storages;
}
public function fromStorageSource(Calendar $calendar) { public function fromStorageSource(Calendar $calendar) {
if (!isset($this->configs)) { if (!isset($this->configs)) {
throw new \Exception('StorageManager was not initialize or configs are not defined'); throw new \Exception('StorageManager was not initialize or configs are not defined');
@ -38,6 +34,9 @@ class StorageManager {
return false; return false;
} }
public function getStorages() {
return $this->storages;
}
public function getConfigs() { public function getConfigs() {
return $this->configs; return $this->configs;
@ -73,3 +72,4 @@ class StorageManager {
} }
} }
} }

View File

@ -11,3 +11,4 @@ interface IStorage {
public function getConfigBrowser(); public function getConfigBrowser();
public function updateConfigs($postData); public function updateConfigs($postData);
} }

View File

@ -179,7 +179,6 @@ class Taskwarrior implements IStorage {
if (!isset($c->VTODO)){ if (!isset($c->VTODO)){
throw new \Exception('Calendar event does not contain VTODO'); throw new \Exception('Calendar event does not contain VTODO');
} }
$this->logger->info(sprintf('Executing on calendar %s', $displayname));
$this->logger->info(json_encode($c->jsonSerialize())); $this->logger->info(json_encode($c->jsonSerialize()));
$this->refresh(); $this->refresh();
$task = $this->vObjectToTask($c->VTODO, $displayname); $task = $this->vObjectToTask($c->VTODO, $displayname);
@ -207,7 +206,6 @@ class Taskwarrior implements IStorage {
} }
$task = $this->tasks[(string)$uid]; $task = $this->tasks[(string)$uid];
if (isset($task) && $task['status'] !== 'deleted') { if (isset($task) && $task['status'] !== 'deleted') {
$this->logger->info(sprintf('Deleting iCal %s from taskwarrior', $uid));
$uuid = $task['uuid']; $uuid = $task['uuid'];
$this->logger->info( $this->logger->info(
sprintf('Executing TASKRC = %s TASKDATA = %s task delete %s', $this->configs['taskrc'], $this->configs['taskdata'], $uuid) sprintf('Executing TASKRC = %s TASKDATA = %s task delete %s', $this->configs['taskrc'], $this->configs['taskdata'], $uuid)
@ -227,5 +225,6 @@ class Taskwarrior implements IStorage {
$this->logger->error($e->getTraceAsString()); $this->logger->error($e->getTraceAsString());
throw $e; throw $e;
} }
} }
} }