-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
Resolves #2330
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace craft\migrations; | ||
|
||
use Craft; | ||
use craft\db\Migration; | ||
|
||
/** | ||
* m180122_213433_propagate_entries_setting migration. | ||
*/ | ||
class m180122_213433_propagate_entries_setting extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->addColumn('{{%sections}}', 'propagateEntries', $this->boolean()->defaultValue(true)->notNull()); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m180122_213433_propagate_entries_setting cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,17 +392,23 @@ public function saveSection(Section $section, bool $runValidation = true): bool | |
'handle', | ||
'type', | ||
'enableVersioning', | ||
'propagateEntries', | ||
])); | ||
} else { | ||
$sectionRecord = new SectionRecord(); | ||
} | ||
|
||
// Main section settings | ||
if ($section->type !== Section::TYPE_CHANNEL) { | ||
$section->propagateEntries = false; | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
brandonkelly
Author
Member
|
||
/** @var SectionRecord $sectionRecord */ | ||
$sectionRecord->name = $section->name; | ||
$sectionRecord->handle = $section->handle; | ||
$sectionRecord->type = $section->type; | ||
$sectionRecord->enableVersioning = (bool)$section->enableVersioning; | ||
$sectionRecord->propagateEntries = (bool)$section->propagateEntries; | ||
|
||
// Get the site settings | ||
$allSiteSettings = $section->getSiteSettings(); | ||
|
@@ -553,21 +559,42 @@ public function saveSection(Section $section, bool $runValidation = true): bool | |
// ----------------------------------------------------------------- | ||
|
||
if (!$isNewSection) { | ||
// Find a site that the section was already enabled in, and still is | ||
$oldSiteIds = array_keys($allOldSiteSettingsRecords); | ||
$newSiteIds = array_keys($section->getSiteSettings()); | ||
$persistentSiteIds = array_intersect($newSiteIds, $oldSiteIds); | ||
|
||
Craft::$app->getQueue()->push(new ResaveElements([ | ||
'description' => Craft::t('app', 'Resaving {section} entries', ['section' => $section->name]), | ||
'elementType' => Entry::class, | ||
'criteria' => [ | ||
'siteId' => $persistentSiteIds[0], | ||
'sectionId' => $section->id, | ||
'status' => null, | ||
'enabledForSite' => false, | ||
] | ||
])); | ||
if ($section->propagateEntries) { | ||
// Find a site that the section was already enabled in, and still is | ||
$oldSiteIds = array_keys($allOldSiteSettingsRecords); | ||
$newSiteIds = array_keys($allSiteSettings); | ||
$persistentSiteIds = array_intersect($newSiteIds, $oldSiteIds); | ||
|
||
Craft::$app->getQueue()->push(new ResaveElements([ | ||
'description' => Craft::t('app', 'Resaving {section} entries', [ | ||
'section' => $section->name, | ||
]), | ||
'elementType' => Entry::class, | ||
'criteria' => [ | ||
'siteId' => $persistentSiteIds[0], | ||
'sectionId' => $section->id, | ||
'status' => null, | ||
'enabledForSite' => false, | ||
] | ||
])); | ||
} else { | ||
// Resave entries for each site | ||
foreach ($allSiteSettings as $siteId => $siteSettings) { | ||
Craft::$app->getQueue()->push(new ResaveElements([ | ||
'description' => Craft::t('app', 'Resaving {section} entries ({site})', [ | ||
'section' => $section->name, | ||
'site' => $siteSettings->getSite()->name, | ||
]), | ||
'elementType' => Entry::class, | ||
'criteria' => [ | ||
'siteId' => $siteId, | ||
'sectionId' => $section->id, | ||
'status' => null, | ||
'enabledForSite' => false, | ||
] | ||
])); | ||
} | ||
} | ||
} | ||
|
||
$transaction->commit(); | ||
|
@@ -879,19 +906,42 @@ public function saveEntryType(EntryType $entryType, bool $runValidation = true): | |
if (!$isNewEntryType) { | ||
// Re-save the entries of this type | ||
$section = $entryType->getSection(); | ||
$siteIds = array_keys($section->getSiteSettings()); | ||
|
||
Craft::$app->getQueue()->push(new ResaveElements([ | ||
'description' => Craft::t('app', 'Resaving {type} entries', ['type' => $entryType->name]), | ||
'elementType' => Entry::class, | ||
'criteria' => [ | ||
'siteId' => $siteIds[0], | ||
'sectionId' => $section->id, | ||
'typeId' => $entryType->id, | ||
'status' => null, | ||
'enabledForSite' => false, | ||
] | ||
])); | ||
$allSiteSettings = $section->getSiteSettings(); | ||
|
||
if ($section->propagateEntries) { | ||
$siteIds = array_keys($allSiteSettings); | ||
|
||
Craft::$app->getQueue()->push(new ResaveElements([ | ||
'description' => Craft::t('app', 'Resaving {type} entries', [ | ||
'type' => $entryType->name, | ||
]), | ||
'elementType' => Entry::class, | ||
'criteria' => [ | ||
'siteId' => $siteIds[0], | ||
'sectionId' => $section->id, | ||
'typeId' => $entryType->id, | ||
'status' => null, | ||
'enabledForSite' => false, | ||
] | ||
])); | ||
} else { | ||
foreach ($allSiteSettings as $siteId => $siteSettings) { | ||
Craft::$app->getQueue()->push(new ResaveElements([ | ||
'description' => Craft::t('app', 'Resaving {type} entries ({site})', [ | ||
'type' => $entryType->name, | ||
'site' => $siteSettings->getSite()->name, | ||
]), | ||
'elementType' => Entry::class, | ||
'criteria' => [ | ||
'siteId' => $siteId, | ||
'sectionId' => $section->id, | ||
'typeId' => $entryType->id, | ||
'status' => null, | ||
'enabledForSite' => false, | ||
] | ||
])); | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
|
@@ -1026,6 +1076,7 @@ private function _createSectionQuery(): Query | |
'sections.handle', | ||
'sections.type', | ||
'sections.enableVersioning', | ||
'sections.propagateEntries', | ||
'structures.maxLevels', | ||
]) | ||
->leftJoin('{{%structures}} structures', '[[structures.id]] = [[sections.structureId]]') | ||
|
I'm thinking we still need to be able to propagate a single in the
admin/settings/sections
context or there could only be one of any given single accross all sites as opposed to each site having it's own "Home" or "About" page. I've implemented a temporary workaround here by commenting out$section->propagateEntries = false;
above and adding the below code in Sections.php so that each of my sites can have it's own set of singles.Otherwise, for me using the current latest on development, i'm unable to create a single on more than one site (also i'm manually setting the propagate flag in the DB so it will propagate in the settings context).