diff --git a/composer.json b/composer.json index 8901860..5c596e4 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,6 @@ "require": { "php": ">=5.5", "sabre/dav": "~3.1.2", - "jms/serializer": "2.0.0-RC1", - "jms/metadata": "^2.0@RC", - "aerex/taskwarrior": "^3.0", "sabre/vobject": "^4.0", "easycorp/easy-log-handler": "^1.0" }, diff --git a/composer.lock b/composer.lock index 4df4bb6..6e1e47c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2dbe239080807aae57bee30b874cf94c", + "content-hash": "227e2d4091133d951637324bc455c602", "packages": [ { "name": "aerex/taskwarrior", @@ -58,6 +58,37 @@ ], "time": "2018-10-28T17:53:34+00:00" }, + { + "name": "container-interop/container-interop", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", + "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", + "shasum": "" + }, + "require": { + "psr/container": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "homepage": "https://github.com/container-interop/container-interop", + "time": "2017-02-14T19:40:03+00:00" + }, { "name": "doctrine/annotations", "version": "v1.6.0", @@ -1136,16 +1167,16 @@ }, { "name": "jms/metadata", - "version": "2.0.0-RC1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/schmittjoh/metadata.git", - "reference": "38021d33d9c54b135284abffe6dd8246c9b16863" + "reference": "e918c3a65105f73b74d94a0837b9f7d611d5bf0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/38021d33d9c54b135284abffe6dd8246c9b16863", - "reference": "38021d33d9c54b135284abffe6dd8246c9b16863", + "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/e918c3a65105f73b74d94a0837b9f7d611d5bf0c", + "reference": "e918c3a65105f73b74d94a0837b9f7d611d5bf0c", "shasum": "" }, "require": { @@ -1189,7 +1220,7 @@ "xml", "yaml" ], - "time": "2018-10-17T06:41:44+00:00" + "time": "2018-11-09T13:57:43+00:00" }, { "name": "jms/serializer", @@ -1277,16 +1308,16 @@ }, { "name": "monolog/monolog", - "version": "1.23.0", + "version": "1.24.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" + "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", - "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", + "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", "shasum": "" }, "require": { @@ -1351,20 +1382,20 @@ "logging", "psr-3" ], - "time": "2017-06-19T01:22:40+00:00" + "time": "2018-11-05T09:00:11+00:00" }, { "name": "nesbot/carbon", - "version": "1.34.0", + "version": "1.34.1", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "1dbd3cb01c5645f3e7deda7aa46ef780d95fcc33" + "reference": "19201b87f7dba2a7cbf1cccdf0e1da13c04ee9c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/1dbd3cb01c5645f3e7deda7aa46ef780d95fcc33", - "reference": "1dbd3cb01c5645f3e7deda7aa46ef780d95fcc33", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/19201b87f7dba2a7cbf1cccdf0e1da13c04ee9c9", + "reference": "19201b87f7dba2a7cbf1cccdf0e1da13c04ee9c9", "shasum": "" }, "require": { @@ -1406,7 +1437,7 @@ "datetime", "time" ], - "time": "2018-09-20T19:36:25+00:00" + "time": "2018-11-08T13:33:47+00:00" }, { "name": "ocramius/proxy-manager", @@ -1521,6 +1552,55 @@ ], "time": "2015-07-25T16:39:46+00:00" }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, { "name": "psr/log", "version": "1.0.2", @@ -1974,16 +2054,16 @@ }, { "name": "symfony/filesystem", - "version": "v2.8.46", + "version": "v2.8.47", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "91f194c5ec8d2ad5ce417a218ce3c46909e92f4d" + "reference": "56a92481a4969b234b1647b1fd1170281e80e2ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/91f194c5ec8d2ad5ce417a218ce3c46909e92f4d", - "reference": "91f194c5ec8d2ad5ce417a218ce3c46909e92f4d", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/56a92481a4969b234b1647b1fd1170281e80e2ca", + "reference": "56a92481a4969b234b1647b1fd1170281e80e2ca", "shasum": "" }, "require": { @@ -2020,11 +2100,11 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2018-09-24T08:04:37+00:00" + "time": "2018-10-02T03:12:00+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.9.0", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -2082,16 +2162,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.9.0", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", - "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", "shasum": "" }, "require": { @@ -2137,20 +2217,20 @@ "portable", "shim" ], - "time": "2018-08-06T14:22:27+00:00" + "time": "2018-09-21T13:07:52+00:00" }, { "name": "symfony/process", - "version": "v2.8.46", + "version": "v2.8.47", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "f09e21b7c5aba06c47bbfad9cbcf13ac7f0db0a6" + "reference": "a15cb61190c6fe37168600922e82295eb5e5449b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/f09e21b7c5aba06c47bbfad9cbcf13ac7f0db0a6", - "reference": "f09e21b7c5aba06c47bbfad9cbcf13ac7f0db0a6", + "url": "https://api.github.com/repos/symfony/process/zipball/a15cb61190c6fe37168600922e82295eb5e5449b", + "reference": "a15cb61190c6fe37168600922e82295eb5e5449b", "shasum": "" }, "require": { @@ -2186,20 +2266,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-09-06T17:11:15+00:00" + "time": "2018-10-05T07:35:28+00:00" }, { "name": "symfony/translation", - "version": "v4.1.6", + "version": "v4.1.7", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "9f0b61e339160a466ebcde167a6c5521c810e304" + "reference": "aa04dc1c75b7d3da7bd7003104cd0cfc5dff635c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/9f0b61e339160a466ebcde167a6c5521c810e304", - "reference": "9f0b61e339160a466ebcde167a6c5521c810e304", + "url": "https://api.github.com/repos/symfony/translation/zipball/aa04dc1c75b7d3da7bd7003104cd0cfc5dff635c", + "reference": "aa04dc1c75b7d3da7bd7003104cd0cfc5dff635c", "shasum": "" }, "require": { @@ -2255,11 +2335,11 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2018-10-02T16:36:10+00:00" + "time": "2018-10-28T18:38:52+00:00" }, { "name": "symfony/yaml", - "version": "v4.1.6", + "version": "v4.1.7", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", @@ -2517,6 +2597,123 @@ "zf2" ], "time": "2018-04-25T15:33:34+00:00" + }, + { + "name": "zendframework/zend-stdlib", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-stdlib.git", + "reference": "66536006722aff9e62d1b331025089b7ec71c065" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-stdlib/zipball/66536006722aff9e62d1b331025089b7ec71c065", + "reference": "66536006722aff9e62d1b331025089b7ec71c065", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpbench/phpbench": "^0.13", + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev", + "dev-develop": "3.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Stdlib\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "SPL extensions, array utilities, error handlers, and more", + "keywords": [ + "ZendFramework", + "stdlib", + "zf" + ], + "time": "2018-08-28T21:34:05+00:00" + }, + { + "name": "zendframework/zend-validator", + "version": "2.10.2", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-validator.git", + "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", + "reference": "38109ed7d8e46cfa71bccbe7e6ca80cdd035f8c9", + "shasum": "" + }, + "require": { + "container-interop/container-interop": "^1.1", + "php": "^5.6 || ^7.0", + "zendframework/zend-stdlib": "^2.7.6 || ^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "zendframework/zend-cache": "^2.6.1", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-config": "^2.6", + "zendframework/zend-db": "^2.7", + "zendframework/zend-filter": "^2.6", + "zendframework/zend-http": "^2.5.4", + "zendframework/zend-i18n": "^2.6", + "zendframework/zend-math": "^2.6", + "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", + "zendframework/zend-session": "^2.8", + "zendframework/zend-uri": "^2.5" + }, + "suggest": { + "zendframework/zend-db": "Zend\\Db component, required by the (No)RecordExists validator", + "zendframework/zend-filter": "Zend\\Filter component, required by the Digits validator", + "zendframework/zend-i18n": "Zend\\I18n component to allow translation of validation error messages", + "zendframework/zend-i18n-resources": "Translations of validator messages", + "zendframework/zend-math": "Zend\\Math component, required by the Csrf validator", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains", + "zendframework/zend-session": "Zend\\Session component, ^2.8; required by the Csrf validator", + "zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.10.x-dev", + "dev-develop": "2.11.x-dev" + }, + "zf": { + "component": "Zend\\Validator", + "config-provider": "Zend\\Validator\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Zend\\Validator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "provides a set of commonly needed validators", + "homepage": "https://github.com/zendframework/zend-validator", + "keywords": [ + "validator", + "zf2" + ], + "time": "2018-02-01T17:05:33+00:00" } ], "packages-dev": [ diff --git a/src/CalendarProcessor.php b/src/CalendarProcessor.php new file mode 100644 index 0000000..696d28b --- /dev/null +++ b/src/CalendarProcessor.php @@ -0,0 +1,43 @@ +taskwarriorManager = $taskwarriorManager; + } + + public function importTask(VTodo $Todo){ + + if($this->taskwarriorManager->exists($Todo->UID)){ + $this->taskwarriorManager->updateTask($Todo); + } + + + try { + $this->taskwarriorManager->addTask($Todo); + + } catch(Exception $e){ + echo $e->getMessage(); + throw $e; + } + + } + + public function export(){ + echo "Not yet implemented"; + } + +} + + +?> diff --git a/src/Config.php b/src/Config.php index 731c9c7..13cbff7 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,6 +1,6 @@ twCalManager = $TWCalManager; } else { - $this->twCalManager = new iCalEventProcessor(); + $this->twCalManager = new CalendarProcessor(); } } @@ -100,7 +100,7 @@ class Plugin extends ServerPlugin { * * @param VCalendar $vCal parsed calendar object */ - function processCalendarEventForTaskwarrior(Document $vCal){ + function processCalendarEventForTaskwarrior(VCalendar $vCal){ try { $this->twCalManager->importTask($vCal->VTODO); } catch(BadRequest $e){ diff --git a/src/Processors/CalendarComponetInterface.php b/src/Processors/CalendarComponetInterface.php deleted file mode 100644 index c22e5a2..0000000 --- a/src/Processors/CalendarComponetInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - diff --git a/src/Processors/ToDo.php b/src/Processors/ToDo.php deleted file mode 100644 index 52d4fa9..0000000 --- a/src/Processors/ToDo.php +++ /dev/null @@ -1,21 +0,0 @@ - diff --git a/src/Task.php b/src/Task.php deleted file mode 100644 index 01b312f..0000000 --- a/src/Task.php +++ /dev/null @@ -1,29 +0,0 @@ -DESCRIPTION) && isset($ToDoComponent->SUMMARY)){ - $description = $summary; - } else if(!isset($ToDoComponent->DESCRIPTION) && !isset($ToDoComponent->SUMMARY)){ - throw new Exception("Task must have a description or summary"); - } - } - - public - -} diff --git a/src/Taskwarrior/Commands/IStrategy.php b/src/Taskwarrior/Commands/IStrategy.php new file mode 100644 index 0000000..020ca18 --- /dev/null +++ b/src/Taskwarrior/Commands/IStrategy.php @@ -0,0 +1,10 @@ + diff --git a/src/Taskwarrior/Commands/TodoStrategy.php b/src/Taskwarrior/Commands/TodoStrategy.php new file mode 100644 index 0000000..64a035e --- /dev/null +++ b/src/Taskwarrior/Commands/TodoStrategy.php @@ -0,0 +1,62 @@ +config = $config; + $this->cmd[] = $this->config->taskBin(); + } + + public function add(Task $task){ + $this->cmd[] = 'add'; + + if($task->getDescription() != null){ + $this->cmd[] = sprintf('"%s"', $task->getDescription()); + } + + if($task->getCategories() != null){ + $categories = implode(' +', $task->getCategories()); + $this->cmd[] = $categories; + } + + if($task->getDue() != null){ + $this->cmd[] = $task->getDue('Y-m-dTH:i:s'); + } + + if($task->getRecurrence() != null){ + $rrule = $task->getRecurrence()->getParts(); + $this->cmd[] = sprintf('recur:%s', $rrule['FREQ']); + if(isset($rrule['UNTIL'])){ + $this->cmd[] = sprintf('until:%s', $rrule['UNTIL']); + } + + } + + if($task->getStatus() != null){ + $this->cmd[] = sprintf('status:%s', $task->getStatus()); + } + + return $this->executeCommand($cmd); + } + + + + + private function executeCommand($command){ + + + $cmdString = implode(' ', $command); + $process = new Process($cmdString); + + $process->run(); + + if(!$process->isSuccessful()){ + throw new TaskwarriorCommandLineException($process); + } + + return $process->getOutput(); + + } + +} diff --git a/src/Taskwarrior/Task.php b/src/Taskwarrior/Task.php new file mode 100644 index 0000000..eb6ff2b --- /dev/null +++ b/src/Taskwarrior/Task.php @@ -0,0 +1,264 @@ +") + */ + private $tags; + + /** + * @var float + * + * @JMS\Type("float") + */ + private $urgency; + + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $entry; + + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $start; + + /** + * @var string + * + * @JMS\Type("Recurring") + */ + private $recur; + + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $until; + + /** + * @var Annotation[] + * + * @JMS\Type("array") + */ + private $annotations = []; + + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $modified; + + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $end; + + /** + * @var string + * + * @JMS\Type("string") + */ + private $status; + + /** + * @var Task[]|ArrayCollection + * + * @JMS\Type("Depends") + */ + private $depends; + + public function __construct($UUID=null){ + $validator = new Uuid(); + + if(!isset($UUID)){ + $this->uuid = uniqid(); + } else if(isset($UUID) && !$validator->isValid($UUID)){ + throw new Exception(sprintf('%s is not a valid uuid', $UUID)); + } + + $this->uuid = $UUID; + + + } + + +/** + * + * {@inheritDoc} + * + * If description is not available attempt to summary, otherwise throw Exception + */ +public function setDescription(VTodo $component){ + if(!isset($component->DESCRIPTION) && isset($component->SUMMARY)){ + $this->description = $component->SUMMARY; + } else if(!isset($component->DESCRIPTION) && !isset($component->SUMMARY)){ + throw new Exception("Task must have a description or summary"); + } else { + $this->description = $component->DESCRIPTION; + } + +} + +public function getDescription(){ + return $this->description; +} + +public function setEntryTime(VTodo $document){ + + if(isset($document->DTSTAMP)){ + $this->entry = new Carbon($document->DTSTAMP->getDateTime()->format(\DateTime::W3C)); + } else { + throw new Exception('Task must have a entry time'); + } + +} + +public function getEntryTime(){ + return $this->entry; +} + +public function setStartTime(VTodo $document){ + if(isset($document->DTSTART)){ + $this->start = new Carbon($document->DTSTART->getDateTime()->format(\DateTime::W3C)); + } +} + +public function getStartTime(){ + return $this->start; + +} + +public function setModifiedTime(VTodo $document){ + if(isset($document->{'LAST-MODIFIED'})){ + $this->modified = new Carbon($document->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C)); + } +} + +public function getModifiedTime(){ + return $this->modified; +} + +public function setDue(VTodo $document){ + + if(isset($document->DUE)){ + $this->due = new Carbon($document->DUE->getDateTime()->format(\DateTime::W3C)); + } +} +public function getDue(){ + return $this->due; +} + +public function setStopTime(VTodo $document){ + if(isset($document->DTEND)){ + $this->end = new Carbon($document->DTEND->getDateTime()->format(\DateTime::W3C)); + } +} + +public function getStopTime(){ + return $this->end; +} + +public function setCategories(VTodo $document){ + if(isset($document->CATEGORIES)){ + $this->tags = explode(',', (string)$document->CATEGORIES); + } +} + +public function getCategories(){ + return $this->tags; +} + +public function setStatus(VTodo $document){ + if(isset($document->STATUS)){ + switch((string)$document->STATUS){ + case 'NEEDS-ACTION': + $this->status = 'pending'; + break; + case 'COMPLETED': + $this->status = 'completed'; + break; + case 'CANCELED': + $this->status = 'deleted'; + break; + } + } +} + +public function setRecurrence(VTodo $document){ + if(isset($document->RRULE)){ + $this->recur = $document->RRULE; + } +} + +public function getStatus(){ + return $this->status; +} + + + + + +} diff --git a/src/Taskwarrior/Taskwarrior.php b/src/Taskwarrior/Taskwarrior.php new file mode 100644 index 0000000..b7873fc --- /dev/null +++ b/src/Taskwarrior/Taskwarrior.php @@ -0,0 +1,66 @@ +config = new TaskwarriorConfig(); + } + $this->config = $config; + } + + public function setStrategy(IStrategy $strategy){ + $this->strategy = $strategy; + } + + public function createTask($uuid){ + $task = new Task($uuid); + return $task; + } + + + public function add($task){ + $this->strategy($task); + } + +} + + +?> diff --git a/src/Taskwarrior/TaskwarriorManager.php b/src/Taskwarrior/TaskwarriorManager.php new file mode 100644 index 0000000..fd2dd08 --- /dev/null +++ b/src/Taskwarrior/TaskwarriorManager.php @@ -0,0 +1,158 @@ +taskwarrior->createTask($document->UID); + + $task->setDescription($document); + + $task->setEntry($document); + + $task->setStartTime($document); + + $task->setModifiedTime($document); + + $task->setStopTime($document); + + $task->setDue($document); + + $task->setCategories($document); + + $task->setStatus($document); + + $task->setRecurrence($document); + + return $this->taskwarrior->add($task); + + } + + public function updateTask(VTodo $document){ + + $task = $this->taskwarrior->get($document->UID); + + $task->setDescription($document); + + $task->setEntry($document); + + $task->setStartTime($document); + + $task->setModifiedTime($document); + + $task->setStopTime($document); + + $task->setDue($document); + + $task->setCategories($document); + + $task->setStatus($document); + + $task->setRecurrence($document); + + $updatedTask = $this->taskwarrior->modify($task); + + return $upatedTask; + } + + + function setEntryTime($entry){ + } + + function exists($UUID){} + + function setEndTime($end){} + function setModifiedTime($modifiedTime){} + function setSummary($description){ + if(!isset($description)){ + return; + } + $this->taskWarriorJSON[self::DESCRIPTION] = $description; + } + + function setStartTime($startTime){} + function setCategories($categories){ + if(!isset($categories)){ + return; + } + + if(!is_array($catergories)){ + return; + } + + $this->taskWarriorJSON[self::CATEGORIES] = $categories; + } + + + + public function taskExists($taskUuid){ + $taskIsInCache = isset($this->cachedTasks[$taskUuid]); + + if($taskIsInCache){ + return true; + } + + $jsonArray = $this->taskwarrior->export($taskUuid); + $taskWithUuidExists = count($jsonArray) > 0; + + return $taskWithUuidExists; + + } + + public function save(){ + + } + public function build(){ + + } + /** + * @param Task $task + * @param string $attr + * @param mixed $value + */ + public function setValue(Task $task, $attr, $value) + { + $refClass = new \ReflectionClass(Task::class); + $refProp = $refClass->getProperty($attr); + $refProp->setAccessible(true); + $refProp->setValue($task, $value); + } + + + function setDescription($description){} + function parseiCalDateTime($iCalDateTime){} + function convertToStringArray($categories){} +} + +?> diff --git a/src/TaskwarriorManager.php b/src/TaskwarriorManager.php deleted file mode 100644 index a0ad3db..0000000 --- a/src/TaskwarriorManager.php +++ /dev/null @@ -1,112 +0,0 @@ -setValue($task, $ICAL_UID, $UUID); - return $task; - } - - public function export(){ - - } - - - - function setEntryTime($entry){ - } - - function exists($UUID){} - - function setEndTime($end){} - function setModifiedTime($modifiedTime){} - function setSummary($description){ - if(!isset($description)){ - return; - } - $this->taskWarriorJSON[self::DESCRIPTION] = $description; - } - - function setStartTime($startTime){} - function setCategories($categories){ - if(!isset($categories)){ - return; - } - - if(!is_array($catergories)){ - return; - } - - $this->taskWarriorJSON[self::CATEGORIES] = $categories; - } - - - - public function taskExists($taskUuid){ - $taskIsInCache = isset($this->cachedTasks[$taskUuid]); - - if($taskIsInCache){ - return true; - } - - $jsonArray = $this->taskwarrior->export($taskUuid); - $taskWithUuidExists = count($jsonArray) > 0; - - return $taskWithUuidExists; - - } - - public function save(){ - - } - public function build(){ - - } - /** - * @param Task $task - * @param string $attr - * @param mixed $value - */ - public function setValue(Task $task, $attr, $value) - { - $refClass = new \ReflectionClass(Task::class); - $refProp = $refClass->getProperty($attr); - $refProp->setAccessible(true); - $refProp->setValue($task, $value); - } - - - function setDescription($description){} - function parseiCalDateTime($iCalDateTime){} - function convertToStringArray($categories){} - function setDueDate($dueDate){} -} - -?> diff --git a/src/Validators/TaskwarriorProps.php b/src/Validators/TaskwarriorProps.php deleted file mode 100644 index d9daa14..0000000 --- a/src/Validators/TaskwarriorProps.php +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/src/iCalEventProcessor.php b/src/iCalEventProcessor.php deleted file mode 100644 index 9f0c7b0..0000000 --- a/src/iCalEventProcessor.php +++ /dev/null @@ -1,159 +0,0 @@ -taskConfig = $taskConfig; - } else { - $this->taskConfig = new Config(); - } - - $this->taskwarrior = $this->taskConfig->getTaskwarriorInstance(); - $this->logger = $this->taskConfig->getLogger(); - } - - - public function importTask(VTodo $ToDoComponent = null){ - - echo $ToDoComponent->serialize(); - if(!isset($ToDoComponent)){ - $this->logger->error("vCal ToDo component is not defined"); - throw new Exception("vCal Todo component is not defined"); - } - - - if($this->taskwarrior->exists($ToDoComponent->UID)){ - $this->taskwarrior->updateTask($ToDoComponent); - $this->logger->error("Updating task " . (string)$ToDoComponent->UID); - } - - - try { - $task = $this->taskwarrior->createiCalTask($ToDoComponent->UID); - - // get description - if(!isset($ToDoComponent->DESCRIPTION) && isset($ToDoComponent->SUMMARY)){ - $description = $summary; - } else if(!isset($ToDoComponent->DESCRIPTION) && !isset($ToDoComponent->SUMMARY)){ - throw new Exception("Task must have a description or summary"); - } - - $task->setDescription($ToDoComponent->DESCRIPTION); - - - // get start time - if(!isset($ToDoComponent->DTSTAMP) && isset($ToDoComponent->DSTART)){ - $start = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTSTAMP); - $entry = $start; - } else if (!isset($ToDoComponent->DTSTAMP) && !isset($ToDoComponent->DSTART)){ - throw new Exception("Task must have an entry or start time"); - } else { - $entry = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTSTAMP); - } - - $this->taskwarrior->setValue($task, $this->taskwarrior::ENTRY, $entry); - - if(isset($ToDoComponent->DSTART)){ - $start = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DSTART); - $this->taskwarrior->setValue($task, $this->taskwarrior::START, $start); - } - - if(isset($ToDoComponent->{'LAST-MODIFIED'})){ - $modified = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->{'LAST-MODIFIED'}); - $this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified); - } - - if(isset($ToDoComponent->DTEND)){ - $end = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTEND); - $this->taskwarrior->setValue($task, $this->taskwarrior::MODIFIED, $modified); - } - - if(isset($ToDoComponent->DUE)){ - $due = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DUE); - $task->setDue($due); - } - - if(isset($ToDoComponent->DTEND)){ - $end = $this->taskwarrior->convertToCarbonDateTime($ToDoComponent->DTEND); - $this->taskwarrior->setValue($task, $this->taskwarrior::END, $end); - } - - if(isset($ToDoComponent->CATEGORIES)){ - $tags = $this->taskwarrior->convertToStringArray($ToDoComponent->CATEGORIES); - $task->setTags($tags); - } - - $this->taskwarrior->save($task); - - } catch(Exception $e){ - echo $e->getMessage(); - - $this->logger->error($e->message); - throw $e; - - } - - } - - - - - - - - - - - - -} - - - -?> diff --git a/tests/Processors/TodoTest.php b/tests/Processors/TodoTest.php new file mode 100644 index 0000000..01eada4 --- /dev/null +++ b/tests/Processors/TodoTest.php @@ -0,0 +1,59 @@ +mockTaskwarriorManager = $this->createMock(TaskwarriorManager::class); + + } + + function testImportAndAddTask(){ + $uuid = '9f353281-1051-4c45-92db-462f5d353c76'; + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + + $this->mockTaskwarriorManager->expects($this->once())->method('exists')->with($this->equalTo($uuid)) + ->willReturn(false); + + $this->mockTaskwarriorManager->expects($this->once())->method('addTask')->with($this->equalTo($mockVTodo)); + $todo = new ToDo($this->mockTaskwarriorManager); + $todo->import($mockVTodo); + + } + + function testImportAndUpdateTask(){ + $uuid = '9f353281-1051-4c45-92db-462f5d353c76'; + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + + $this->mockTaskwarriorManager->expects($this->once())->method('exists') + ->willReturn(true); + + + $this->mockTaskwarriorManager->expects($this->once())->method('updateTask'); + + $todo = new ToDo($this->mockTaskwarriorManager); + $todo->import($mockVTodo); + } + +} +?> + diff --git a/tests/TaskTest.php b/tests/TaskTest.php new file mode 100644 index 0000000..b4721df --- /dev/null +++ b/tests/TaskTest.php @@ -0,0 +1,173 @@ +add('VTODO', ['UID' => $uuid]); + + $mockVTodo->DESCRIPTION = $expectedDescription; + + + $todo = new Task(); + + $todo->setDescription($mockVTodo); + $actualDescription = $todo->getDescription(); + + $this->assertEquals($expectedDescription, $actualDescription); + } + public function testSetDescriptionUsingSummary(){ + $uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85'; + $expectedDescription = 'This is a description'; + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + + $mockVTodo->SUMMARY = $expectedDescription; + + + $todo = new Task(); + + $todo->setDescription($mockVTodo); + $actualDescription = $todo->getDescription(); + + $this->assertEquals($expectedDescription, $actualDescription); + } + + /** + * @expectedException Error + */ + public function testFailureSetDescription(){ + $uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85'; + $expectedDescription = 'This is a description'; + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + + $todo = new Task(); + + $todo->setDescription($mockVTodo); + $actualDescription = $todo->getDescription(); + + } + public function testSetEntryTime(){ + $uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85'; + $expectedEntryTime = new DateTime('2018-11-11'); + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + $expectedCarbonDate = new Carbon($expectedEntryTime->format('Y-m-d')); + $mockVTodo->DTSTAMP = $expectedEntryTime; + + $todo = new Task(); + + $todo->setEntryTime($mockVTodo); + $actualEntryTime = $todo->getEntryTime(); + + $this->assertEquals($expectedCarbonDate, $actualEntryTime); + } + public function testSetStartTime(){ + $uuid = 'f987aa59-9031-4a7b-9cf3-6bfa4dc44a85'; + $expectedStartTime = new DateTime('2018-11-11'); + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + $expectedCarbonDate = new Carbon($expectedStartTime->format('Y-m-d')); + $mockVTodo->DTSTART = $expectedStartTime; + + $todo = new Task(); + + $todo->setStartTime($mockVTodo); + $actualStartTime = $todo->getStartTime(); + + $this->assertEquals($expectedCarbonDate, $actualStartTime); + } + public function testSetModifiedTime(){ + $uuid = '182a6301-98e6-44df-97eb-8c7620f25b43'; + $expectedModifiedTime = new DateTime('2018-11-11'); + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + $expectedCarbonDate = new Carbon($expectedModifiedTime->format('Y-m-d')); + $mockVTodo->{'LAST-MODIFIED'} = $expectedModifiedTime; + + $todo = new Task(); + + $todo->setModifiedTime($mockVTodo); + $actualModifiedTime = $todo->getModifiedTime(); + + $this->assertEquals($expectedCarbonDate, $actualModifiedTime); + } + public function testSetDue(){ + $uuid = 'dde78b02-97d9-4e11-8603-e0fc14474c7c'; + $expectedDueTime = new DateTime('2018-11-11'); + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + $expectedCarbonDate = new Carbon($expectedDueTime->format('Y-m-d')); + $mockVTodo->DUE = $expectedDueTime; + + $todo = new Task(); + + $todo->setDue($mockVTodo); + $actualDue = $todo->getDue(); + + $this->assertEquals($expectedCarbonDate, $actualDue); + } + + public function testSetCategories(){ + + $uuid = '182a6301-98e6-44df-97eb-8c7620f25b43'; + $expectedCategories = array("home", "work"); + + $mockVCalendar = new VCalendar(); + $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); + $mockVTodo->CATEGORIES = $expectedCategories; + + $todo = new Task(); + + $todo->setCategories($mockVTodo); + $actualCategories = $todo->getCategories(); + + $this->assertEquals($expectedCategories, $actualCategories); + + } +} + diff --git a/tests/iCalEventProcessorTest.php b/tests/iCalEventProcessorTest.php deleted file mode 100644 index 2d62bf6..0000000 --- a/tests/iCalEventProcessorTest.php +++ /dev/null @@ -1,174 +0,0 @@ -mockTaskwarrior = $this->createMock(TaskwarriorManager::class); - $this->mockTask = $this->createMock(Task::class); - $this->mockTaskwarriorConfig = $this->createMock(Config::class); - $this->mockLogger = $this->createMock(Logger::class); - - } - - function testConstructorWithConfig() { - $this->mockTaskwarriorConfig->expects($this->once()) - ->method('getTaskwarriorInstance') - ->will($this->returnValue($this->mockTaskwarrior)); - - $this->taskCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); - - } - function testBuildToDoComponent(){ - $uuid = '9f353281-1051-4c45-92db-462f5d353c76'; - $startTime = new DateTime('2018-07-04'); - $endTime = new DateTime('2018-07-06'); - $modifiedTime = new DateTime('2018-08-05'); - $categories = array('home', 'test'); - $dueDate = new DateTime('2018-08-20'); - $description = 'This is a simple todo'; - - $mockVCalendar = new VCalendar(); - $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); - $mockVTodo->add('DSTAMP', $startTime); - $mockVTodo->add('DUE', $dueDate); - $mockVTodo->add('LAST-MODIFIED',$modifiedTime); - $mockVTodo->add('DSTART', $startTime); - $mockVTodo->add('DTEND', $endTime); - $mockVTodo->add('DESCRIPTION', $description); - $mockVTodo->add('CATEGORIES', $categories); - -// $this->mockTaskwarrior->expects($this->exactly(4)) -// ->method('parseiCalDateTime') -// ->will($this->onConsecutiveCalls($startTime, $startTime, $modifiedTime, $endTime)); - - $this->mockTaskwarrior->expects($this->once())->method('createTask')->with($this->equalTo($uuid)) - ->willReturn($this->mockTask); - $this->mockTask->expects($this->once())->method('setDue')->with($this->equalTo($dueDate)); - $this->mockTask->expects($this->once())->method('setDescription')->with($this->equalTo($description)); - $this->mockTaskwarrior->expects($this->once())->method('convertToStringArray')->with($this->equalTo($mockVTodo->CATEGORIES)) - ->willReturn($categories); - - $this->mockTask->expects($this->once())->method('setTags') - ->with($this->equalTo($categories)); - - $this->mockTaskwarrior->expects($this->exactly(4)) - ->method('setValue'); - - $this->mockLogger->expects($this->never())->method('error'); - - $this->mockTaskwarriorConfig - ->expects($this->once()) - ->method('getTaskwarriorInstance') - ->will($this->returnValue($this->mockTaskwarrior)); - - $this - ->mockTaskwarrior - ->expects($this->once()) - ->method('save'); - - $twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); - $twCalEvent->importTask($mockVTodo); - } - - /** - * @expectedException Sabre\DAV\Exception - * - * - */ - function testFailTaskNoComponentDefine(){ - - $this->mockTaskwarrior->expects($this->never())->method('createTask'); - $this->mockTaskwarrior->expects($this->never())->method('setEntryTime'); - $this->mockTaskwarrior->expects($this->never())->method('setEndTime'); - $this->mockTaskwarrior->expects($this->never())->method('setDueDate'); - $this->mockTaskwarrior->expects($this->never())->method('setSummary'); - $this->mockTaskwarrior->expects($this->never())->method('setCategories'); - $this->mockTaskwarrior->expects($this->never())->method('build'); - $this->mockTaskwarrior->expects($this->never())->method('save'); - $this->mockTaskwarrior->expects($this->never())->method('exists'); - - $this->mockTaskwarriorConfig->expects($this->once())->method('getTaskwarriorInstance') - ->willReturn($this->mockTaskwarrior); - - $this->mockLogger->expects($this->once())->method('error'); - - $this->mockTaskwarriorConfig->expects($this->once())->method('getLogger') - ->willReturn($this->mockLogger); - - $twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); - $twCalEvent->importTask(); - - } - - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - * - * - */ - - /* - function testFailTaskExists(){ - $uuid = '9f353281-1051-4c45-92db-462f5d353c76'; - - $mockVCalendar = new VCalendar(); - $mockVTodo = $mockVCalendar->add('VTODO', ['UID' => $uuid]); - $expectedErrorMessage = "already exists"; - - $this->mockTaskwarrior->expects($this->never())->method('createTask'); - $this->mockTaskwarrior->expects($this->never())->method('setEntryTime'); - $this->mockTaskwarrior->expects($this->never())->method('setEndTime'); - $this->mockTaskwarrior->expects($this->never())->method('setDueDate'); - $this->mockTaskwarrior->expects($this->never())->method('setSummary'); - $this->mockTaskwarrior->expects($this->never())->method('setCategories'); - $this->mockTaskwarrior->expects($this->never())->method('build'); - $this->mockTaskwarrior->expects($this->never())->method('save'); - - $this->mockTaskwarrior->expects($this->once())->method('exists') - ->willReturn(true); - - $this->mockTaskwarriorConfig->expects($this->once())->method('getTaskwarriorInstance') - ->willReturn($this->mockTaskwarrior); - - $this->mockLogger->expects($this->once())->method('error'); - - $this->mockTaskwarriorConfig->expects($this->once())->method('getLogger') - ->willReturn($this->mockLogger); - - $twCalEvent = new iCalEventProcessor($this->mockTaskwarriorConfig); - $twCalEvent->importTask($mockVTodo); - - } - */ - -} - - -?>