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;
 | 
					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 {
 | 
					class Plugin extends ServerPlugin {
 | 
				
			||||||
@@ -34,10 +34,10 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
    protected $storageManager;
 | 
					    protected $storageManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @var $rawconfigs 
 | 
					     * @var $rawconfigs
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $rawConfigs;
 | 
					    protected $rawConfigs;
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Creates the Storage plugin
 | 
					     * Creates the Storage plugin
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -47,11 +47,12 @@ 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 (e.g Remove xxxx.ics from calendars/collection_name/xxxx.ics)
 | 
					      // Remove filepath
 | 
				
			||||||
      $urlParts = explode('/', $path);
 | 
					      $urlParts = explode('/', $path);
 | 
				
			||||||
      $calendarUrl = implode('/', array_slice($urlParts, 0, sizeof($urlParts)-1));
 | 
					      $calendarUrl = implode('/', array_slice($urlParts, 0, sizeof($urlParts)-1));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -72,9 +73,9 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function initializeStorages($configs) {
 | 
					    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'));
 | 
					                '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 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 RequestInterface  $request
 | 
				
			||||||
     * @param ResponseInterface $response
 | 
					     * @param ResponseInterface $response
 | 
				
			||||||
@@ -118,7 +119,7 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
            case 'PUT':
 | 
					            case 'PUT':
 | 
				
			||||||
                $this->httpPut($request, $response);
 | 
					                $this->httpPut($request, $response);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case 'POST': 
 | 
					            case 'POST':
 | 
				
			||||||
                $this->httpPost($request, $response);
 | 
					                $this->httpPost($request, $response);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case 'DELETE':
 | 
					            case 'DELETE':
 | 
				
			||||||
@@ -163,7 +164,7 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
        $body = $request->getBodyAsString();
 | 
					        $body = $request->getBodyAsString();
 | 
				
			||||||
        if (isset($postVars['baikalStorage']))  {
 | 
					        if (isset($postVars['baikalStorage']))  {
 | 
				
			||||||
          foreach ($this->storageManager->getStorages() as $storage) {
 | 
					          foreach ($this->storageManager->getStorages() as $storage) {
 | 
				
			||||||
            if ($storage::NAME == $postVars['baikalStorage'] 
 | 
					            if ($storage::NAME == $postVars['baikalStorage']
 | 
				
			||||||
              && $postVars['baikalStorageAction'] == 'saveConfigs') {
 | 
					              && $postVars['baikalStorageAction'] == 'saveConfigs') {
 | 
				
			||||||
              $updateStorageConfigs = $storage->updateConfigs($postVars);
 | 
					              $updateStorageConfigs = $storage->updateConfigs($postVars);
 | 
				
			||||||
              $this->rawConfigs['storages'][$postVars['baikalStorage']] = $updateStorageConfigs;
 | 
					              $this->rawConfigs['storages'][$postVars['baikalStorage']] = $updateStorageConfigs;
 | 
				
			||||||
@@ -184,7 +185,7 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
        $response->setStatus(302);
 | 
					        $response->setStatus(302);
 | 
				
			||||||
        $request->setBody($body);
 | 
					        $request->setBody($body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } 
 | 
					    }
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method handles the DELETE method.
 | 
					     * This method handles the DELETE method.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -214,7 +215,7 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Generates the 'general' configuration section
 | 
					     * Generates the 'general' configuration section
 | 
				
			||||||
@@ -225,7 +226,7 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
      $configuredLogLevel = '';
 | 
					      $configuredLogLevel = '';
 | 
				
			||||||
      $logFilePath = '';
 | 
					      $logFilePath = '';
 | 
				
			||||||
      if (isset($this->rawConfigs['general'])
 | 
					      if (isset($this->rawConfigs['general'])
 | 
				
			||||||
        && isset($this->rawConfigs['general']['logger']) 
 | 
					        && isset($this->rawConfigs['general']['logger'])
 | 
				
			||||||
        && $this->rawConfigs['general']['logger']['enabled']) {
 | 
					        && $this->rawConfigs['general']['logger']['enabled']) {
 | 
				
			||||||
        $configuredLogLevel = $this->rawConfigs['general']['logger']['level'];
 | 
					        $configuredLogLevel = $this->rawConfigs['general']['logger']['level'];
 | 
				
			||||||
        $logFilePath = $this->rawConfigs['general']['logger']['file'];
 | 
					        $logFilePath = $this->rawConfigs['general']['logger']['file'];
 | 
				
			||||||
@@ -307,4 +308,3 @@ class Plugin extends ServerPlugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,8 +10,8 @@ class StorageManager {
 | 
				
			|||||||
   * @var Storage[]
 | 
					   * @var Storage[]
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private $storages = []; 
 | 
					  private $storages = [];
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * @var array()
 | 
					   * @var array()
 | 
				
			||||||
@@ -19,7 +19,11 @@ class StorageManager {
 | 
				
			|||||||
  private $configs;
 | 
					  private $configs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function __construct($configs){
 | 
					  public function __construct($configs){
 | 
				
			||||||
    $this->configs = $configs; 
 | 
					    $this->configs = $configs;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public function getStorages() {
 | 
				
			||||||
 | 
					    return $this->storages;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function fromStorageSource(Calendar $calendar) {
 | 
					  public function fromStorageSource(Calendar $calendar) {
 | 
				
			||||||
@@ -34,21 +38,18 @@ class StorageManager {
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function getStorages() {
 | 
					 | 
				
			||||||
    return $this->storages;
 | 
					 | 
				
			||||||
  } 
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function getConfigs() {
 | 
					  public function getConfigs() {
 | 
				
			||||||
    return $this->configs;
 | 
					    return $this->configs;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function addStorage($name, $storage) {
 | 
					  public function addStorage($name, $storage) {
 | 
				
			||||||
   $this->storages[$name] = $storage; 
 | 
					   $this->storages[$name] = $storage;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function import(Calendar $calendar, string $displayname) {
 | 
					  public function import(Calendar $calendar, string $displayname) {
 | 
				
			||||||
    if (!isset($this->configs)) {
 | 
					    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) {
 | 
					    foreach ($this->configs['storages'] as $key => $value) {
 | 
				
			||||||
      $storage = $this->storages[$key];
 | 
					      $storage = $this->storages[$key];
 | 
				
			||||||
@@ -61,7 +62,7 @@ class StorageManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  public function remove($uid) {
 | 
					  public function remove($uid) {
 | 
				
			||||||
    if (!isset($this->configs)) {
 | 
					    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) {
 | 
					    foreach ($this->configs['storages'] as $key => $value) {
 | 
				
			||||||
      $storage = $this->storages[$key];
 | 
					      $storage = $this->storages[$key];
 | 
				
			||||||
@@ -72,4 +73,3 @@ class StorageManager {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,4 +11,3 @@ interface IStorage {
 | 
				
			|||||||
 public function getConfigBrowser();
 | 
					 public function getConfigBrowser();
 | 
				
			||||||
 public function updateConfigs($postData);
 | 
					 public function updateConfigs($postData);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
  public function __construct($console, $configs, $logger) {
 | 
					  public function __construct($console, $configs, $logger) {
 | 
				
			||||||
    $this->console = $console;
 | 
					    $this->console = $console;
 | 
				
			||||||
    $this->configs = $configs['storages']['taskwarrior'];
 | 
					    $this->configs = $configs['storages']['taskwarrior'];
 | 
				
			||||||
    $this->logger = $logger; 
 | 
					    $this->logger = $logger;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public function getConfigBrowser() {
 | 
					  public function getConfigBrowser() {
 | 
				
			||||||
@@ -54,7 +54,7 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  public function refresh() {
 | 
					  public function refresh() {
 | 
				
			||||||
    $this->logger->info('Syncing taskwarrior tasks...');
 | 
					    $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']]);
 | 
					      ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
 | 
				
			||||||
      $this->tasks = json_decode($this->console->execute('task', ['export'], null,
 | 
					      $this->tasks = json_decode($this->console->execute('task', ['export'], null,
 | 
				
			||||||
        ['TASKRC' => $this->configs['taskrc'], 'TASKDATA' => $this->configs['taskdata']]), true);
 | 
					        ['TASKRC' => $this->configs['taskrc'], 'TASKDATA' => $this->configs['taskdata']]), true);
 | 
				
			||||||
@@ -75,7 +75,7 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (isset($vtodo->SUMMARY)){
 | 
					    if (isset($vtodo->SUMMARY)){
 | 
				
			||||||
      $task['description'] = (string)$vtodo->SUMMARY;
 | 
					      $task['description'] = (string)$vtodo->SUMMARY;
 | 
				
			||||||
    } 
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isset($vtodo->DESCRIPTION)) {
 | 
					    if (isset($vtodo->DESCRIPTION)) {
 | 
				
			||||||
      $annotations = [];
 | 
					      $annotations = [];
 | 
				
			||||||
@@ -98,7 +98,7 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!isset($task['entry'])){
 | 
					    if (!isset($task['entry'])){
 | 
				
			||||||
      $task['entry'] = $vtodo->DTSTAMP->getDateTime()->format(\DateTime::ISO8601);
 | 
					      $task['entry'] = $vtodo->DTSTAMP->getDateTime()->format(\DateTime::ISO8601);
 | 
				
			||||||
    } 
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isset($vtodo->DTSTART)) {
 | 
					    if (isset($vtodo->DTSTART)) {
 | 
				
			||||||
      $task['start'] = $vtodo->DTSTART->getDateTime()->format(\DateTime::ISO8601);
 | 
					      $task['start'] = $vtodo->DTSTART->getDateTime()->format(\DateTime::ISO8601);
 | 
				
			||||||
@@ -179,6 +179,7 @@ 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);
 | 
				
			||||||
@@ -186,7 +187,7 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
      $this->logger->info(
 | 
					      $this->logger->info(
 | 
				
			||||||
        sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], json_encode($task))
 | 
					        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']]);
 | 
					        ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
 | 
				
			||||||
      $this->refresh();
 | 
					      $this->refresh();
 | 
				
			||||||
      $this->logger->info($output);
 | 
					      $this->logger->info($output);
 | 
				
			||||||
@@ -201,16 +202,17 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
      $this->logger->info(sprintf('Deleting iCal %s from taskwarrior', $uid));
 | 
					      $this->logger->info(sprintf('Deleting iCal %s from taskwarrior', $uid));
 | 
				
			||||||
      $this->refresh();
 | 
					      $this->refresh();
 | 
				
			||||||
      if (!array_key_exists((string)$uid, $this->tasks)) {
 | 
					      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;
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      $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)
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        $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']]);
 | 
					          ['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
 | 
				
			||||||
        $this->logger->info($output);
 | 
					        $this->logger->info($output);
 | 
				
			||||||
        $this->refresh();
 | 
					        $this->refresh();
 | 
				
			||||||
@@ -225,6 +227,5 @@ class Taskwarrior implements IStorage {
 | 
				
			|||||||
      $this->logger->error($e->getTraceAsString());
 | 
					      $this->logger->error($e->getTraceAsString());
 | 
				
			||||||
      throw $e;
 | 
					      throw $e;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user