Skip to content

Commit

Permalink
Merge pull request #1334 from craftcms/bugfix/1310-check-if-element-s…
Browse files Browse the repository at this point in the history
…tatus-changed

check if element enabled(forSite) attribute(s) changed
  • Loading branch information
angrybrad committed Jun 26, 2023
2 parents fe05e80 + 41fb24c commit fa10631
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/helpers/DataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/services/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit fa10631

Please sign in to comment.