From 5c59f778aaf63b46f53be59eff6f1d7e6a0b5ffb Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Thu, 9 Mar 2017 08:33:18 +0100 Subject: [PATCH 1/7] Added VersionNotFoundException --- lib/DocumentManagerInterface.php | 2 ++ lib/Exception/VersionNotFoundException.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 lib/Exception/VersionNotFoundException.php diff --git a/lib/DocumentManagerInterface.php b/lib/DocumentManagerInterface.php index cab5adb..eba593b 100644 --- a/lib/DocumentManagerInterface.php +++ b/lib/DocumentManagerInterface.php @@ -115,6 +115,8 @@ public function removeDraft($document, $locale); * @param string $version The UUID of the version to restore * @param array $options * + * @throws Exception\VersionNotFoundException + * * @return mixed */ public function restore($document, $locale, $version, array $options = []); diff --git a/lib/Exception/VersionNotFoundException.php b/lib/Exception/VersionNotFoundException.php new file mode 100644 index 0000000..e9b2dfc --- /dev/null +++ b/lib/Exception/VersionNotFoundException.php @@ -0,0 +1,16 @@ + Date: Thu, 9 Mar 2017 09:12:00 +0100 Subject: [PATCH 2/7] Use exception --- lib/Subscriber/Behavior/VersionSubscriber.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/Subscriber/Behavior/VersionSubscriber.php b/lib/Subscriber/Behavior/VersionSubscriber.php index b44b7d6..558fd30 100644 --- a/lib/Subscriber/Behavior/VersionSubscriber.php +++ b/lib/Subscriber/Behavior/VersionSubscriber.php @@ -14,6 +14,7 @@ use Jackalope\Version\VersionManager; use PHPCR\NodeInterface; use PHPCR\SessionInterface; +use PHPCR\Version\VersionException; use Sulu\Component\DocumentManager\Behavior\VersionBehavior; use Sulu\Component\DocumentManager\Event\AbstractMappingEvent; use Sulu\Component\DocumentManager\Event\HydrateEvent; @@ -21,6 +22,7 @@ use Sulu\Component\DocumentManager\Event\PublishEvent; use Sulu\Component\DocumentManager\Event\RestoreEvent; use Sulu\Component\DocumentManager\Events; +use Sulu\Component\DocumentManager\Exception\VersionNotFoundException; use Sulu\Component\DocumentManager\PropertyEncoder; use Sulu\Component\DocumentManager\Version; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -208,6 +210,8 @@ public function applyVersionOperations() * Restore the properties of the old version. * * @param RestoreEvent $event + * + * @throws VersionNotFoundException */ public function restoreProperties(RestoreEvent $event) { @@ -229,14 +233,19 @@ public function restoreProperties(RestoreEvent $event) } } - $version = $this->versionManager->getVersionHistory($node->getPath())->getVersion($event->getVersion()); - $frozenNode = $version->getFrozenNode(); + try { + $version = $this->versionManager->getVersionHistory($node->getPath())->getVersion($event->getVersion()); + + $frozenNode = $version->getFrozenNode(); - // set all the properties from the saved version to the node - foreach ($frozenNode->getPropertiesValues() as $name => $value) { - if ($this->isRestoreProperty($name, $contentPropertyPrefix, $systemPropertyPrefix)) { - $node->setProperty($name, $value); + // set all the properties from the saved version to the node + foreach ($frozenNode->getPropertiesValues() as $name => $value) { + if ($this->isRestoreProperty($name, $contentPropertyPrefix, $systemPropertyPrefix)) { + $node->setProperty($name, $value); + } } + } catch (VersionException $exception) { + throw new VersionNotFoundException($exception->getMessage(), $exception->getCode()); } } From cab9631fc5cf7325e7ea56e2540d703cadd63612 Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Thu, 9 Mar 2017 09:29:21 +0100 Subject: [PATCH 3/7] Added CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db43dd3..5ea3bcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ CHANGELOG for Sulu ================== +* dev-develop + * ENHANCEMENT #107 Added VersionNotFoundException + * 0.9.0-RC1 * FEATURE #105 Fixed changed times for both workspaces * FEATURE #97 Added versioning functionalities From 4dc64aa63cc22f0847524f89cce9a99b8bc361f3 Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Thu, 9 Mar 2017 09:29:48 +0100 Subject: [PATCH 4/7] Corrected entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ea3bcd..216c27d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ CHANGELOG for Sulu ================== -* dev-develop +* dev-master * ENHANCEMENT #107 Added VersionNotFoundException * 0.9.0-RC1 From 439fc41df9d981dacb19716a0ee4a3d0817e22be Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Thu, 9 Mar 2017 09:31:16 +0100 Subject: [PATCH 5/7] Corrected headline --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 216c27d..b86d839 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -CHANGELOG for Sulu -================== +CHANGELOG for Sulu Document Manager +=================================== * dev-master * ENHANCEMENT #107 Added VersionNotFoundException From f88860cb62d4431c3b488919319dbaa303c181c5 Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Thu, 9 Mar 2017 09:42:52 +0100 Subject: [PATCH 6/7] Use of document and version in exception --- lib/Exception/InvalidLocaleException.php | 3 ++ .../NodeNameAlreadyExistsException.php | 3 ++ lib/Exception/VersionNotFoundException.php | 42 +++++++++++++++++++ lib/Subscriber/Behavior/VersionSubscriber.php | 9 +++- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/Exception/InvalidLocaleException.php b/lib/Exception/InvalidLocaleException.php index ec13f6a..74c23cc 100644 --- a/lib/Exception/InvalidLocaleException.php +++ b/lib/Exception/InvalidLocaleException.php @@ -21,6 +21,9 @@ class InvalidLocaleException extends \InvalidArgumentException */ private $locale; + /** + * @param string $locale + */ public function __construct($locale) { parent::__construct(sprintf('Invalid locale "%s"', $locale)); diff --git a/lib/Exception/NodeNameAlreadyExistsException.php b/lib/Exception/NodeNameAlreadyExistsException.php index 6c7cd92..6165cf5 100644 --- a/lib/Exception/NodeNameAlreadyExistsException.php +++ b/lib/Exception/NodeNameAlreadyExistsException.php @@ -21,6 +21,9 @@ class NodeNameAlreadyExistsException extends DocumentManagerException */ private $nodeName; + /** + * @param string $nodeName + */ public function __construct($nodeName) { parent::__construct( diff --git a/lib/Exception/VersionNotFoundException.php b/lib/Exception/VersionNotFoundException.php index e9b2dfc..17158ac 100644 --- a/lib/Exception/VersionNotFoundException.php +++ b/lib/Exception/VersionNotFoundException.php @@ -13,4 +13,46 @@ class VersionNotFoundException extends DocumentManagerException { + /** + * @var object + */ + private $document; + + /** + * @var int + */ + private $version; + + /** + * @param object $document + * @param string $version + */ + public function __construct($document, $version) + { + parent::__construct( + sprintf('Version "%s" for document "%" not found', $version, $document->getUuid()) + ); + $this->document = $document; + $this->version = $version; + } + + /** + * The document, which was tried to restore. + * + * @return object + */ + public function getDocument() + { + return $this->document; + } + + /** + * The version, which was tried to restore. + * + * @return string + */ + public function getVersion() + { + return $this->version; + } } diff --git a/lib/Subscriber/Behavior/VersionSubscriber.php b/lib/Subscriber/Behavior/VersionSubscriber.php index 558fd30..472bb72 100644 --- a/lib/Subscriber/Behavior/VersionSubscriber.php +++ b/lib/Subscriber/Behavior/VersionSubscriber.php @@ -245,10 +245,17 @@ public function restoreProperties(RestoreEvent $event) } } } catch (VersionException $exception) { - throw new VersionNotFoundException($exception->getMessage(), $exception->getCode()); + throw new VersionNotFoundException($node, $event->getVersion()); } } + /** + * @param string $propertyName + * @param string $contentPrefix + * @param string $systemPrefix + * + * @return bool + */ private function isRestoreProperty($propertyName, $contentPrefix, $systemPrefix) { // return all localized and non-translatable properties From 0ff1741235a802efc3fe792e453d8f5184227176 Mon Sep 17 00:00:00 2001 From: Patrick Hopfner Date: Thu, 9 Mar 2017 09:59:59 +0100 Subject: [PATCH 7/7] Use of document --- lib/Exception/VersionNotFoundException.php | 2 +- lib/Subscriber/Behavior/VersionSubscriber.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Exception/VersionNotFoundException.php b/lib/Exception/VersionNotFoundException.php index 17158ac..99861ff 100644 --- a/lib/Exception/VersionNotFoundException.php +++ b/lib/Exception/VersionNotFoundException.php @@ -30,7 +30,7 @@ class VersionNotFoundException extends DocumentManagerException public function __construct($document, $version) { parent::__construct( - sprintf('Version "%s" for document "%" not found', $version, $document->getUuid()) + sprintf('Version "%s" for document "%s" not found', $version, $document->getUuid()) ); $this->document = $document; $this->version = $version; diff --git a/lib/Subscriber/Behavior/VersionSubscriber.php b/lib/Subscriber/Behavior/VersionSubscriber.php index 472bb72..3e611d3 100644 --- a/lib/Subscriber/Behavior/VersionSubscriber.php +++ b/lib/Subscriber/Behavior/VersionSubscriber.php @@ -245,7 +245,7 @@ public function restoreProperties(RestoreEvent $event) } } } catch (VersionException $exception) { - throw new VersionNotFoundException($node, $event->getVersion()); + throw new VersionNotFoundException($event->getDocument(), $event->getVersion()); } }