Skip to content

Commit

Permalink
Send $siteElement by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 9, 2023
1 parent a727a13 commit 24b67d2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/services/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,8 @@ public function propagateElements(ElementQueryInterface $query, array|int $siteI
// Make sure the site element wasn't updated more recently than the main one
$siteElement = $this->getElementById($element->id, $elementType, $siteId);
if ($siteElement === null || $siteElement->dateUpdated < $element->dateUpdated) {
$this->_propagateElement($element, $supportedSites, $siteId, $siteElement ?? false);
$siteElement ??= false;
$this->_propagateElement($element, $supportedSites, $siteId, $siteElement);
}
}
}
Expand Down Expand Up @@ -3045,7 +3046,7 @@ public function propagateElement(
ElementInterface|false|null $siteElement = null,
): ElementInterface {
$supportedSites = ArrayHelper::index(ElementHelper::supportedSitesForElement($element), 'siteId');
$siteElement = $this->_propagateElement($element, $supportedSites, $siteId, $siteElement);
$this->_propagateElement($element, $supportedSites, $siteId, $siteElement);

// Clear caches
$this->invalidateCachesForElement($element);
Expand Down Expand Up @@ -3465,15 +3466,14 @@ private function _saveElementInternal(
* @param array $supportedSites The element’s supported site info, indexed by site ID
* @param int $siteId The site ID being propagated to
* @param ElementInterface|false|null $siteElement The element loaded for the propagated site
* @return ElementInterface The element in the target site
* @throws Exception if the element couldn't be propagated
*/
private function _propagateElement(
ElementInterface $element,
array $supportedSites,
int $siteId,
ElementInterface|false|null $siteElement = null,
): ElementInterface {
ElementInterface|false|null &$siteElement = null,
) {
// Make sure the element actually supports the site it's being saved in
if (!isset($supportedSites[$siteId])) {
throw new UnsupportedSiteException($element, $siteId, 'Attempting to propagate an element to an unsupported site.');
Expand Down Expand Up @@ -3573,8 +3573,6 @@ private function _propagateElement(
Craft::error($error);
throw new Exception('Couldn’t propagate element to other site.');
}

return $siteElement;
}

/**
Expand Down

0 comments on commit 24b67d2

Please sign in to comment.