diff --git a/CHANGELOG.md b/CHANGELOG.md index 05bfc437b52..35290e65870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 5 +## Unreleased + +- Fixed an error that could occur if a new element was saved recursively. ([#15517](https://github.com/craftcms/cms/issues/15517)) + ## 5.3.2 - 2024-08-10 - Added `craft\db\afterDown()`. diff --git a/src/services/Elements.php b/src/services/Elements.php index 8dacf1f4d63..bd52b70cbe6 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -1279,6 +1279,11 @@ public function saveElement( $duplicateOf = $element->duplicateOf; $element->duplicateOf = null; + // Force isNewForSite = false here, in case the element is getting saved recursively + // (see https://github.com/craftcms/cms/issues/15517) + $isNewForSite = $element->isNewForSite; + $element->isNewForSite = false; + $success = $this->_saveElementInternal( $element, $runValidation, @@ -1290,6 +1295,7 @@ public function saveElement( ); $element->duplicateOf = $duplicateOf; + $element->isNewForSite = $isNewForSite; return $success; }