Skip to content

Commit

Permalink
Merge pull request #1251 from Elorfin/master
Browse files Browse the repository at this point in the history
add an option in CopyEvent to choose if we want to publish or not the copied resource
  • Loading branch information
ngodfraind committed Jul 10, 2015
2 parents 9d58202 + 3427b80 commit 18be07b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Event/CopyResourceEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
}
}

/**
Expand Down Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions Manager/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand Down

0 comments on commit 18be07b

Please sign in to comment.