This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added publish method to document manager
- Loading branch information
Showing
28 changed files
with
886 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.