Bulk enable/duplicate entries for a new site #11357
-
We have a structure section with 300+ entries in one site and just added another site. The section’s propagation method is set to Duplicates in environment the new site was added inOn my computer, this created „duplicates“ (in lieau of a better word) of the old entries for the new site, so all 300+ entries are existing for both sites, in sync. I can then remove entries or add new entries but have an initial base to work with. Doesn’t duplicate when pushed via project-configWhen pushing the project-config changes to our staging server, this isn’t the case. The entries are only available for the old site. I would have to visit every entry’s detail view, pop open the site selection, and add them to the new site, in order to get the duplicated section data that we need. Console commands to the rescue?I tried using the bulk resave console commands:
… and variations of that, but get an exception PS: As an aside, from the docs I cannot really see what the correct status would be. What’s the difference between |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If the section’s Propagation Method was indeed set to “Let each entry choose which sites it should be saved to” at the time when the new site was added, this should not have happened. That setting leaves it up to each individual entry to choose which sites it should be saved to, and will never automatically propagate a bunch of entries to a new site.
If there’s a lightswitch, the entry exists in that site (regardless of whether it’s enabled or disabled); if there’s no lightswitch, the entry doesn’t exist at all for that site. It would not be possible to query the entry in that site even with If that’s not the behavior you’re after, maybe the simplest option here is to change your Propagation Method. If you want to keep the current method, you can add all of the existing entries to the new site using a PHP script: <?php
use craft\elements\Entry;
$newSiteId = 10;
$entries = Entry::find()
->section('pages')
->site('site_a')
->anyStatus()
->all();
foreach ($entries as $entry) {
/** @var Entry $entry */
$enabledForSite = [$entry->siteId => $entry->enabledForSite];
foreach ($entry->getLocalized()->all() as $localized) {
/** @var Entry $localized */
$enabledForSite[$localized->siteId => $localized->enabledForSite];
}
if (!isset($enabledForSite[$newSiteId])) {
$enabledForSite[$newSiteId] = true;
$entry->setEnabledForSite($enabledForSite);
Craft::$app->elements->saveElement($entry);
}
} (Replace |
Beta Was this translation helpful? Give feedback.
If the section’s Propagation Method was indeed set to “Let each entry choose which sites it should be saved to” at the time when the new site was added, this should not have happened. That setting leaves it up to each individual entry to choose which sites it should be saved to, and will never automatically propagate a bunch of entries to a new site.