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

Commit

Permalink
added publish method to document manager
Browse files Browse the repository at this point in the history
  • Loading branch information
danrot committed Jul 5, 2016
1 parent b4a4368 commit b404294
Show file tree
Hide file tree
Showing 28 changed files with 886 additions and 377 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG for Sulu
* ENHANCEMENT #89 Extracted LocalizedTitleBehavior from TitleBehavior
* BUGFIX #90 Added missing check in handleChangeParent method of ParentSubscriber
* BUGFIX #88 Introduced mandatory locale in document-registry
* FEATURE #81 Added publish method to DocumentManager
* BUGFIX #85 Fixed get locale for proxy

* 0.6.1 (2016-06-01)
Expand Down
13 changes: 11 additions & 2 deletions lib/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,21 @@ public function copy($document, $destPath)
/**
* {@inheritdoc}
*/
public function reorder($document, $destId, $after = false)
public function reorder($document, $destId)
{
$event = new Event\ReorderEvent($document, $destId, $after);
$event = new Event\ReorderEvent($document, $destId);
$this->eventDispatcher->dispatch(Events::REORDER, $event);
}

/**
* {@inheritdoc}
*/
public function publish($document, $locale)
{
$event = new Event\PublishEvent($document, $locale);
$this->eventDispatcher->dispatch(Events::PUBLISH, $event);
}

/**
* {@inheritdoc}
*/
Expand Down
13 changes: 10 additions & 3 deletions lib/DocumentManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function remove($document);
* Move the PHPCR node to which the document is mapped to be a child of the node at the given path or UUID.
*
* @param object $document
* @param string $destId Path or UUID
* @param string $destId The path of the new parent.
*/
public function move($document, $destId);

Expand All @@ -79,9 +79,16 @@ public function copy($document, $destPath);
*
* @param object $document
* @param string $destId
* @param bool $after
*/
public function reorder($document, $destId, $after = false);
public function reorder($document, $destId);

/**
* Publishes a document to the public workspace.
*
* @param object $document
* @param string $locale
*/
public function publish($document, $locale);

/**
* Refresh the given document with the persisted state of the node.
Expand Down
28 changes: 21 additions & 7 deletions lib/Event/CopyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,40 @@

namespace Sulu\Component\DocumentManager\Event;

use PHPCR\NodeInterface;

class CopyEvent extends MoveEvent
{
/**
* @var string
* @var NodeInterface
*/
private $copiedPath;
private $copiedNode;

/**
* @return string
* @return string|null
*/
public function getCopiedPath()
{
return $this->copiedPath;
if (!$this->copiedNode) {
return;
}

return $this->copiedNode->getPath();
}

/**
* @return NodeInterface
*/
public function getCopiedNode()
{
return $this->copiedNode;
}

/**
* @param string $copiedPath
* @param NodeInterface $copiedNode
*/
public function setCopiedPath($copiedPath)
public function setCopiedNode($copiedNode)
{
$this->copiedPath = $copiedPath;
$this->copiedNode = $copiedNode;
}
}
37 changes: 37 additions & 0 deletions lib/Event/PublishEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Event;

use PHPCR\NodeInterface;

class PublishEvent extends AbstractMappingEvent
{
/**
* @param object $document
* @param string $locale
*/
public function __construct($document, $locale)
{
$this->document = $document;
$this->locale = $locale;
}

/**
* Sets the node this event should operate on.
*
* @param NodeInterface $node
*/
public function setNode(NodeInterface $node)
{
$this->node = $node;
}
}
22 changes: 3 additions & 19 deletions lib/Event/ReorderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,14 @@ class ReorderEvent extends AbstractMappingEvent
*/
private $destId;

/**
* @var bool
*/
private $after;

/**
* @param object $document
* @param string $destId
* @param bool $after
*/
public function __construct($document, $destId, $after)
public function __construct($document, $destId)
{
$this->document = $document;
$this->destId = $destId;
$this->after = $after;
}

/**
Expand All @@ -43,10 +36,9 @@ public function __construct($document, $destId, $after)
public function getDebugMessage()
{
return sprintf(
'%s did:%s after:%s',
'%s did:%s',
parent::getDebugMessage(),
$this->destId ?: '<no dest>',
$this->after ? 'true' : 'false'
$this->destId ?: '<no dest>'
);
}

Expand All @@ -58,14 +50,6 @@ public function getDestId()
return $this->destId;
}

/**
* @return bool
*/
public function getAfter()
{
return $this->after;
}

/**
* @param NodeInterface $node
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class Events
*/
const REORDER = 'sulu_document_manager.reorder';

/**
* Fired when the document manager publish method is called.
*/
const PUBLISH = 'sulu_document_manager.publish';

/**
* Fired when the document manager requests that are flush to persistent storage happen.
*/
Expand Down
101 changes: 101 additions & 0 deletions lib/NodeHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?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;

use PHPCR\NodeInterface;
use PHPCR\SessionInterface;
use PHPCR\Util\PathHelper;
use PHPCR\Util\UUIDHelper;
use Sulu\Component\DocumentManager\Exception\DocumentManagerException;

/**
* The NodeHelper takes a node and some additional arguments to execute certain actions based on the passed node,
* especially on the session of the passed Node.
*/
class NodeHelper implements NodeHelperInterface
{
/**
* {@inheritdoc}
*/
public function move(NodeInterface $node, $parentUuid, $destinationName = null)
{
if (!$destinationName) {
$destinationName = $node->getName();
}

$session = $node->getSession();
$parentPath = $this->normalizePath($session, $parentUuid);
$session->move($node->getPath(), $parentPath . '/' . $destinationName);
}

/**
* {@inheritdoc}
*/
public function copy(NodeInterface $node, $parentUuid, $destinationName = null)
{
if (!$destinationName) {
$destinationName = $node->getName();
}

$session = $node->getSession();
$parentPath = $this->normalizePath($session, $parentUuid);
$destinationPath = $parentPath . '/' . $destinationName;
$session->getWorkspace()->copy($node->getPath(), $destinationPath);

return $destinationPath;
}

/**
* {@inheritdoc}
*/
public function reorder(NodeInterface $node, $destinationUuid)
{
$session = $node->getSession();
$parentNode = $node->getParent();

if (!$destinationUuid) {
$parentNode->orderBefore($node->getName(), null);

return;
}

$siblingPath = $session->getNodeByIdentifier($destinationUuid)->getPath();

if (PathHelper::getParentPath($siblingPath) !== $parentNode->getPath()) {
throw new DocumentManagerException(
sprintf(
'Cannot reorder documents which are not sibilings. Trying to reorder "%s" to "%s".',
$node->getPath(),
$siblingPath
)
);
}

$parentNode->orderBefore($node->getName(), PathHelper::getNodeName($siblingPath));
}

/**
* Returns the path based on the given UUID.
*
* @param SessionInterface $session
* @param string $identifier
*
* @return string
*/
private function normalizePath(SessionInterface $session, $identifier)
{
if (!UUIDHelper::isUUID($identifier)) {
return $identifier;
}

return $session->getNodeByIdentifier($identifier)->getPath();
}
}
54 changes: 54 additions & 0 deletions lib/NodeHelperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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;

use PHPCR\NodeInterface;
use Sulu\Component\DocumentManager\Exception\DocumentManagerException;

/**
* The NodeHelperInterface describes action being executable on a node.
*/
interface NodeHelperInterface
{
/**
* Move the given node to the given parent node. Additionally a new name can also be passed.
*
* @param NodeInterface $node
* @param string $parentUuid
* @param null $destinationName
*/
public function move(NodeInterface $node, $parentUuid, $destinationName = null);

/**
* Copies the given node to the given parent node. Additionally a new name can also be passed.
*
* @param NodeInterface $node
* @param string $parentUuid
* @param null $destinationName
*
* @return string The path of the new node
*/
public function copy(NodeInterface $node, $parentUuid, $destinationName = null);

/**
* Reorders the given node before the given UUID. Throws an exception if the given node and the node identified by
* the passed UUID are not siblings, since the operation would not be a simple reordering anymore.
*
* If the node should be passed to the last position null should be passed as destinationUuid.
*
* @param NodeInterface $node
* @param string|null $destinationUuid
*
* @throws DocumentManagerException
*/
public function reorder(NodeInterface $node, $destinationUuid);
}
4 changes: 4 additions & 0 deletions lib/NodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function remove($identifier)
* @param string $srcId
* @param string $destId
* @param string $name
*
* @deprecated Use NodeHelper::move instead
*/
public function move($srcId, $destId, $name)
{
Expand All @@ -117,6 +119,8 @@ public function move($srcId, $destId, $name)
* @param string $name
*
* @return string
*
* @deprecated Use NodeHelper::copy instead
*/
public function copy($srcId, $destId, $name)
{
Expand Down
1 change: 0 additions & 1 deletion lib/Subscriber/Behavior/Mapping/ParentSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function __construct(
ProxyFactory $proxyFactory,
DocumentInspector $inspector,
DocumentManagerInterface $documentManager

) {
$this->proxyFactory = $proxyFactory;
$this->inspector = $inspector;
Expand Down
Loading

0 comments on commit b404294

Please sign in to comment.