Skip to content

Commit 7ce8b10

Browse files
committed
$isNewSite
Better fix for #16752
1 parent 68bb559 commit 7ce8b10

5 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/base/Element.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,8 @@ public function attributes(): array
23222322
$names['propagating'],
23232323
$names['propagateAll'],
23242324
$names['newSiteIds'],
2325+
$names['isNewForSite'],
2326+
$names['isNewSite'],
23252327
$names['resaving'],
23262328
$names['duplicateOf'],
23272329
$names['mergingCanonicalChanges'],

src/base/ElementTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ trait ElementTrait
189189
*/
190190
public bool $isNewForSite = false;
191191

192+
/**
193+
* @var bool Whether this is for a newly-created site.
194+
* @since 4.14.9
195+
*/
196+
public bool $isNewSite = false;
197+
192198
/**
193199
* @var bool Whether the element is being resaved by a ResaveElement job or a `resave` console command.
194200
* @since 3.1.22

src/fields/BaseRelationField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ public function normalizeValue(mixed $value, ?ElementInterface $element = null):
587587
$value instanceof ElementQueryInterface &&
588588
$element?->propagating &&
589589
$element->isNewForSite &&
590+
!$element->isNewSite &&
590591
!$this->targetSiteId &&
591592
!$this->showSiteMenu
592593
) {

src/queue/jobs/PropagateElements.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class PropagateElements extends BaseBatchedJob
4141
*/
4242
public array|int|null $siteId = null;
4343

44+
/**
45+
* @var bool Whether this is for a newly-added site.
46+
* @since 4.14.9
47+
*/
48+
public bool $isNewSite = false;
49+
4450
/**
4551
* @inheritdoc
4652
*/
@@ -81,6 +87,7 @@ protected function processItem(mixed $item): void
8187
/** @var ElementInterface $item */
8288
$item->setScenario(Element::SCENARIO_ESSENTIALS);
8389
$item->newSiteIds = [];
90+
$item->isNewSite = $this->isNewSite;
8491
$supportedSiteIds = array_map(fn($siteInfo) => $siteInfo['siteId'], ElementHelper::supportedSitesForElement($item));
8592
$elementSiteIds = $this->siteId !== null ? array_intersect($this->siteId, $supportedSiteIds) : $supportedSiteIds;
8693
$elementsService = Craft::$app->getElements();

src/services/Sites.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,10 @@ public function handleChangedSite(ConfigEvent $event): void
820820
// (skip entries because they only support specific sites)
821821
// (skip Matrix blocks because they will be re-saved when their owners are re-saved).
822822
$elementTypes = [
823+
GlobalSet::class,
823824
Asset::class,
824825
Category::class,
825826
Tag::class,
826-
GlobalSet::class,
827827
];
828828

829829
foreach ($elementTypes as $elementType) {
@@ -833,6 +833,7 @@ public function handleChangedSite(ConfigEvent $event): void
833833
'siteId' => $oldPrimarySiteId,
834834
],
835835
'siteId' => $site->id,
836+
'isNewSite' => true,
836837
]));
837838
}
838839
}

0 commit comments

Comments
 (0)