From 41fb24ca9dca3c03eec477982065534535a872b2 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 20 Jun 2023 08:48:15 +0100 Subject: [PATCH] check if element enabled(forSite) attribute(s) changed --- src/helpers/DataHelper.php | 3 +++ src/services/Process.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helpers/DataHelper.php b/src/helpers/DataHelper.php index e3960a1e..7f2a7a51 100644 --- a/src/helpers/DataHelper.php +++ b/src/helpers/DataHelper.php @@ -242,6 +242,9 @@ public static function compareElementContent($content, $element) $fields = $element->getSerializedFieldValues(); $attributes = $element->attributes; + if (isset($attributes['enabled'])) { + $attributes['enabledForSite'] = $element->getEnabledForSite(); + } foreach ($content as $key => $newValue) { $existingValue = Hash::get($fields, $key); diff --git a/src/services/Process.php b/src/services/Process.php index 909548d8..bb86ab72 100644 --- a/src/services/Process.php +++ b/src/services/Process.php @@ -372,6 +372,7 @@ public function processFeed($step, $feed, &$processedElementIds, $feedData = nul // Set the attributes for the element $element->setAttributes($attributeData, false); + $contentData = []; if (isset($attributeData['enabled'])) { // Set the site-specific status as well, but retain all other site statuses $enabledForSite = []; @@ -387,6 +388,8 @@ public function processFeed($step, $feed, &$processedElementIds, $feedData = nul // Set the global status to true if it's enabled for *any* sites, or if already enabled. $element->enabled = in_array(true, $enabledForSite) || $element->enabled; $element->setEnabledForSite($enabledForSite); + $contentData['enabled'] = $element->enabled; + $contentData['enabledForSite'] = $element->getEnabledForSite($element->siteId); } // Then, do the same for custom fields. Again, this should be done after populating the element attributes @@ -424,7 +427,7 @@ public function processFeed($step, $feed, &$processedElementIds, $feedData = nul } // We need to keep these separate to apply to the element but required when matching against existing elements - $contentData = $attributeData + $fieldData; + $contentData += $attributeData + $fieldData; // // It's time to actually save the element!