Skip to content

Commit

Permalink
Stop running validation when duplicating elements
Browse files Browse the repository at this point in the history
Fixes #3320
  • Loading branch information
brandonkelly committed Sep 23, 2018
1 parent 6d7a711 commit 0d3728e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- `ancestors`, `descendants`, `nextSibling`, `parent`, and `prevSibling` are now reserved field handles.
- The `svg()` Twig function namespaces class names in addition to IDs now.

### Fixed
- Fixed a validation error that could occur when saving an entry as a new entry if the URI format didn’t contain a `{slug}` tag. ([#3320](https://github.com/craftcms/cms/issues/3320))

## 3.0.25 - 2018-09-18

### Added
Expand Down
7 changes: 2 additions & 5 deletions src/services/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,13 @@ public function duplicateElement(ElementInterface $element, array $newAttributes
/** @var Element $mainClone */
$mainClone = clone $element;
$mainClone->setAttributes($newAttributes);
$mainClone->setScenario(Element::SCENARIO_ESSENTIALS);
$mainClone->id = null;
$mainClone->contentId = null;

if (!$this->saveElement($mainClone, true, false)) {
if (!$this->saveElement($mainClone, false, false)) {
throw new InvalidElementException($mainClone, 'Element ' . $element->id . ' could not be duplicated for site ' . $element->siteId);
}

$mainClone->setScenario($element->getScenario());
foreach ($supportedSites as $siteInfo) {
if ($siteInfo['siteId'] != $element->siteId) {
$siteElement = $this->getElementById($element->id, get_class($element), $siteInfo['siteId']);
Expand All @@ -592,11 +590,10 @@ public function duplicateElement(ElementInterface $element, array $newAttributes
/** @var Element $siteClone */
$siteClone = clone $siteElement;
$siteClone->setAttributes($newAttributes);
$siteClone->setScenario(Element::SCENARIO_ESSENTIALS);
$siteClone->id = $mainClone->id;
$siteClone->contentId = null;

if (!$this->saveElement($siteClone, true, false)) {
if (!$this->saveElement($siteClone, false, false)) {
throw new InvalidElementException($siteClone, 'Element ' . $element->id . ' could not be duplicated for site ' . $siteInfo['siteId']);
}
}
Expand Down

0 comments on commit 0d3728e

Please sign in to comment.