Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Added VersionNotFoundException #107

Merged
merged 7 commits into from
Mar 9, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/DocumentManagerInterface.php
Original file line number Diff line number Diff line change
@@ -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 = []);
16 changes: 16 additions & 0 deletions lib/Exception/VersionNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Component\DocumentManager\Exception;

class VersionNotFoundException extends DocumentManagerException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to not have such a small exception, but a parameterized one. So that it can be used like throw new VersionNotFoundException($document, $version), and it generates the message on its own.

{
}
21 changes: 15 additions & 6 deletions lib/Subscriber/Behavior/VersionSubscriber.php
Original file line number Diff line number Diff line change
@@ -14,13 +14,15 @@
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;
use Sulu\Component\DocumentManager\Event\PersistEvent;
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());
}
}