From 098a21945eec9f05e66514e14b183ccb9ca0058a Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Fri, 10 May 2024 14:32:21 +1000 Subject: [PATCH] Fixes multisite propagating to sites outside group --- src/Database/Traits/Multisite.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Database/Traits/Multisite.php b/src/Database/Traits/Multisite.php index 5c700b29b..4e20b2fa9 100644 --- a/src/Database/Traits/Multisite.php +++ b/src/Database/Traits/Multisite.php @@ -90,18 +90,20 @@ public function multisiteSaveComplete() Site::withGlobalContext(function() { $otherModels = $this->newOtherSiteQuery()->get(); - $otherSites = $otherModels->pluck('site_id')->all(); + $otherSites = $this->getMultisiteSyncSites(); // Propagate attributes to known records if ($this->propagatable) { - foreach ($otherModels as $model) { - $this->propagateToSite($model->site_id, $model); + foreach ($otherSites as $siteId) { + if ($model = $otherModels->where('site_id', $siteId)->first()) { + $this->propagateToSite($siteId, $model); + } } } // Sync non-existent records if ($this->isMultisiteSyncEnabled()) { - $missingSites = array_diff($this->getMultisiteSyncSites(), $otherSites); + $missingSites = array_diff($otherSites, $otherModels->pluck('site_id')->all()); foreach ($missingSites as $missingSite) { $this->propagateToSite($missingSite); }