chore: Removed trailing spaces and cleaned up code
This commit is contained in:
		| @@ -14,7 +14,7 @@ use Sabre\DAV\ServerPlugin; | ||||
| use Sabre\DAV\Server; | ||||
|  | ||||
| /** | ||||
|  * The plugin to interact with Baikal and external storages  | ||||
|  * The plugin to interact with Baikal and external storages | ||||
|  * | ||||
|  */ | ||||
| class Plugin extends ServerPlugin { | ||||
| @@ -34,10 +34,10 @@ class Plugin extends ServerPlugin { | ||||
|     protected $storageManager; | ||||
|  | ||||
|     /** | ||||
|      * @var $rawconfigs  | ||||
|      * @var $rawconfigs | ||||
|      */ | ||||
|     protected $rawConfigs; | ||||
|      | ||||
|  | ||||
|     /** | ||||
|      * Creates the Storage plugin | ||||
|      * | ||||
| @@ -47,11 +47,12 @@ class Plugin extends ServerPlugin { | ||||
|     function __construct($configFile){ | ||||
|       $this->rawConfigs = $this->buildConfigurations($configFile); | ||||
|       $this->storageManager = new StorageManager($this->rawConfigs); | ||||
|       $this->logger = new Logger($this->rawConfigs, 'BaikalStorage'); | ||||
|       $this->initializeStorages($this->rawConfigs); | ||||
|     } | ||||
|  | ||||
|     private function getDisplayName($path) { | ||||
|       // Remove filepath (e.g Remove xxxx.ics from calendars/collection_name/xxxx.ics) | ||||
|       // Remove filepath | ||||
|       $urlParts = explode('/', $path); | ||||
|       $calendarUrl = implode('/', array_slice($urlParts, 0, sizeof($urlParts)-1)); | ||||
|  | ||||
| @@ -72,9 +73,9 @@ class Plugin extends ServerPlugin { | ||||
|      */ | ||||
|  | ||||
|     public function initializeStorages($configs) { | ||||
|         $taskwarrior = new Taskwarrior(new Console(['rc.verbose=nothing',  | ||||
|         $taskwarrior = new Taskwarrior(new Console(['rc.verbose=nothing', | ||||
|                 'rc.hooks=off', 'rc.confirmation=no']),  $configs, new Logger($configs, 'Taskwarrior')); | ||||
|       $this->storageManager->addStorage(Taskwarrior::NAME, $taskwarrior);  | ||||
|       $this->storageManager->addStorage(Taskwarrior::NAME, $taskwarrior); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -104,7 +105,7 @@ class Plugin extends ServerPlugin { | ||||
|     /** | ||||
|      * This method is called before any HTTP method handler. | ||||
|      * | ||||
|      * This method intercepts any GET, DELETE, PUT and PROPFIND.  | ||||
|      * This method intercepts any GET, DELETE, PUT and PROPFIND. | ||||
|      * | ||||
|      * @param RequestInterface  $request | ||||
|      * @param ResponseInterface $response | ||||
| @@ -118,7 +119,7 @@ class Plugin extends ServerPlugin { | ||||
|             case 'PUT': | ||||
|                 $this->httpPut($request, $response); | ||||
|                 break; | ||||
|             case 'POST':  | ||||
|             case 'POST': | ||||
|                 $this->httpPost($request, $response); | ||||
|                 break; | ||||
|             case 'DELETE': | ||||
| @@ -163,7 +164,7 @@ class Plugin extends ServerPlugin { | ||||
|         $body = $request->getBodyAsString(); | ||||
|         if (isset($postVars['baikalStorage']))  { | ||||
|           foreach ($this->storageManager->getStorages() as $storage) { | ||||
|             if ($storage::NAME == $postVars['baikalStorage']  | ||||
|             if ($storage::NAME == $postVars['baikalStorage'] | ||||
|               && $postVars['baikalStorageAction'] == 'saveConfigs') { | ||||
|               $updateStorageConfigs = $storage->updateConfigs($postVars); | ||||
|               $this->rawConfigs['storages'][$postVars['baikalStorage']] = $updateStorageConfigs; | ||||
| @@ -184,7 +185,7 @@ class Plugin extends ServerPlugin { | ||||
|         $response->setStatus(302); | ||||
|         $request->setBody($body); | ||||
|  | ||||
|     }  | ||||
|     } | ||||
|     /** | ||||
|      * This method handles the DELETE method. | ||||
|      * | ||||
| @@ -214,7 +215,7 @@ class Plugin extends ServerPlugin { | ||||
|  | ||||
|     } | ||||
|  | ||||
|      | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Generates the 'general' configuration section | ||||
| @@ -225,7 +226,7 @@ class Plugin extends ServerPlugin { | ||||
|       $configuredLogLevel = ''; | ||||
|       $logFilePath = ''; | ||||
|       if (isset($this->rawConfigs['general']) | ||||
|         && isset($this->rawConfigs['general']['logger'])  | ||||
|         && isset($this->rawConfigs['general']['logger']) | ||||
|         && $this->rawConfigs['general']['logger']['enabled']) { | ||||
|         $configuredLogLevel = $this->rawConfigs['general']['logger']['level']; | ||||
|         $logFilePath = $this->rawConfigs['general']['logger']['file']; | ||||
| @@ -307,4 +308,3 @@ class Plugin extends ServerPlugin { | ||||
|  | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -10,8 +10,8 @@ class StorageManager { | ||||
|    * @var Storage[] | ||||
|    */ | ||||
|  | ||||
|   private $storages = [];  | ||||
|      | ||||
|   private $storages = []; | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * @var array() | ||||
| @@ -19,7 +19,11 @@ class StorageManager { | ||||
|   private $configs; | ||||
|  | ||||
|   public function __construct($configs){ | ||||
|     $this->configs = $configs;  | ||||
|     $this->configs = $configs; | ||||
|   } | ||||
|  | ||||
|   public function getStorages() { | ||||
|     return $this->storages; | ||||
|   } | ||||
|  | ||||
|   public function fromStorageSource(Calendar $calendar) { | ||||
| @@ -34,21 +38,18 @@ class StorageManager { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   public function getStorages() { | ||||
|     return $this->storages; | ||||
|   }  | ||||
|  | ||||
|   public function getConfigs() { | ||||
|     return $this->configs; | ||||
|   } | ||||
|  | ||||
|   public function addStorage($name, $storage) { | ||||
|    $this->storages[$name] = $storage;  | ||||
|    $this->storages[$name] = $storage; | ||||
|   } | ||||
|  | ||||
|   public function import(Calendar $calendar, string $displayname) { | ||||
|     if (!isset($this->configs)) { | ||||
|       throw new \Exception('StorageManger was not initialize or configs are not defined');  | ||||
|       throw new \Exception('StorageManger was not initialize or configs are not defined'); | ||||
|     } | ||||
|     foreach ($this->configs['storages'] as $key => $value) { | ||||
|       $storage = $this->storages[$key]; | ||||
| @@ -61,7 +62,7 @@ class StorageManager { | ||||
|  | ||||
|   public function remove($uid) { | ||||
|     if (!isset($this->configs)) { | ||||
|       throw new \Exception('StorageManger was not initialize or configs are not defined');  | ||||
|       throw new \Exception('StorageManger was not initialize or configs are not defined'); | ||||
|     } | ||||
|     foreach ($this->configs['storages'] as $key => $value) { | ||||
|       $storage = $this->storages[$key]; | ||||
| @@ -72,4 +73,3 @@ class StorageManager { | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -11,4 +11,3 @@ interface IStorage { | ||||
|  public function getConfigBrowser(); | ||||
|  public function updateConfigs($postData); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ class Taskwarrior implements IStorage { | ||||
|   public function __construct($console, $configs, $logger) { | ||||
|     $this->console = $console; | ||||
|     $this->configs = $configs['storages']['taskwarrior']; | ||||
|     $this->logger = $logger;  | ||||
|     $this->logger = $logger; | ||||
|   } | ||||
|  | ||||
|   public function getConfigBrowser() { | ||||
| @@ -54,7 +54,7 @@ class Taskwarrior implements IStorage { | ||||
|  | ||||
|   public function refresh() { | ||||
|     $this->logger->info('Syncing taskwarrior tasks...'); | ||||
|     $this->console->execute('task', ['sync'], null,  | ||||
|     $this->console->execute('task', ['sync'], null, | ||||
|       ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); | ||||
|       $this->tasks = json_decode($this->console->execute('task', ['export'], null, | ||||
|         ['TASKRC' => $this->configs['taskrc'], 'TASKDATA' => $this->configs['taskdata']]), true); | ||||
| @@ -75,7 +75,7 @@ class Taskwarrior implements IStorage { | ||||
|  | ||||
|     if (isset($vtodo->SUMMARY)){ | ||||
|       $task['description'] = (string)$vtodo->SUMMARY; | ||||
|     }  | ||||
|     } | ||||
|  | ||||
|     if (isset($vtodo->DESCRIPTION)) { | ||||
|       $annotations = []; | ||||
| @@ -98,7 +98,7 @@ class Taskwarrior implements IStorage { | ||||
|     } | ||||
|     if (!isset($task['entry'])){ | ||||
|       $task['entry'] = $vtodo->DTSTAMP->getDateTime()->format(\DateTime::ISO8601); | ||||
|     }  | ||||
|     } | ||||
|  | ||||
|     if (isset($vtodo->DTSTART)) { | ||||
|       $task['start'] = $vtodo->DTSTART->getDateTime()->format(\DateTime::ISO8601); | ||||
| @@ -179,6 +179,7 @@ class Taskwarrior implements IStorage { | ||||
|       if (!isset($c->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->refresh(); | ||||
|       $task = $this->vObjectToTask($c->VTODO, $displayname); | ||||
| @@ -186,7 +187,7 @@ class Taskwarrior implements IStorage { | ||||
|       $this->logger->info( | ||||
|         sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], json_encode($task)) | ||||
|       ); | ||||
|       $output = $this->console->execute('task', ['import'], $task,  | ||||
|       $output = $this->console->execute('task', ['import'], $task, | ||||
|         ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); | ||||
|       $this->refresh(); | ||||
|       $this->logger->info($output); | ||||
| @@ -201,16 +202,17 @@ class Taskwarrior implements IStorage { | ||||
|       $this->logger->info(sprintf('Deleting iCal %s from taskwarrior', $uid)); | ||||
|       $this->refresh(); | ||||
|       if (!array_key_exists((string)$uid, $this->tasks)) { | ||||
|         $this->logger->warn(sprintf('Could not find task %s to be remove. Skipping', (string)$uid));  | ||||
|         $this->logger->warn(sprintf('Could not find task %s to be remove. Skipping', (string)$uid)); | ||||
|         return; | ||||
|       } | ||||
|       $task = $this->tasks[(string)$uid]; | ||||
|       if (isset($task) && $task['status'] !== 'deleted') { | ||||
|         $this->logger->info(sprintf('Deleting iCal %s from taskwarrior', $uid)); | ||||
|         $uuid = $task['uuid']; | ||||
|         $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) | ||||
|         ); | ||||
|         $output = $this->console->execute('task', ['delete', (string)$uuid], null,  | ||||
|         $output = $this->console->execute('task', ['delete', (string)$uuid], null, | ||||
|           ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]); | ||||
|         $this->logger->info($output); | ||||
|         $this->refresh(); | ||||
| @@ -225,6 +227,5 @@ class Taskwarrior implements IStorage { | ||||
|       $this->logger->error($e->getTraceAsString()); | ||||
|       throw $e; | ||||
|     } | ||||
|  | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user