diff --git a/Event/CopyResourceEvent.php b/Event/CopyResourceEvent.php index 1afe37c0c..1e9e4d29a 100644 --- a/Event/CopyResourceEvent.php +++ b/Event/CopyResourceEvent.php @@ -26,6 +26,12 @@ class CopyResourceEvent extends Event implements DataConveyorEventInterface private $copy; private $isPopulated = false; + /** + * If true the copy will be published + * @var bool + */ + private $publish = false; + /** * Constructor. * @@ -36,6 +42,11 @@ public function __construct(AbstractResource $resource, ResourceNode $parent) { $this->resource = $resource; $this->parent = $parent; + + // By default, use the same published state as the copied node + if ($this->resource->getResourceNode()) { + $this->publish = $this->resource->getResourceNode()->isPublished(); + } } /** @@ -82,4 +93,18 @@ public function isPopulated() { return $this->isPopulated; } + + /** + * Is the copied resource need to be published or not ? + * @return bool + */ + public function getPublish() + { + return $this->publish; + } + + public function setPublish($publish) + { + $this->publish = $publish; + } } diff --git a/Manager/ResourceManager.php b/Manager/ResourceManager.php index fa816537f..4d76c8dd6 100644 --- a/Manager/ResourceManager.php +++ b/Manager/ResourceManager.php @@ -772,6 +772,10 @@ public function copy( $copy = $event->getCopy(); $newNode = $this->copyNode($node, $parent, $user, $withRights, $rights, $index); + + // Set the published state + $newNode->setPublished($event->getPublish()); + $copy->setResourceNode($newNode); if ($node->getResourceType()->getName() == 'directory' &&