mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #1886 from halkyon/filesystem_sync_subsites
BUG Fixing Filesystem::sync breaking subsite pages with same URLSegments
This commit is contained in:
commit
d5bcbbd66a
@ -180,14 +180,32 @@ class Filesystem extends Object {
|
|||||||
// Update the image tracking of all pages
|
// Update the image tracking of all pages
|
||||||
if($syncLinkTracking) {
|
if($syncLinkTracking) {
|
||||||
if(class_exists('SiteTree')) {
|
if(class_exists('SiteTree')) {
|
||||||
if(class_exists('Subsite')) $origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
|
||||||
if(class_exists('Subsite')) Subsite::$disable_subsite_filter = true;
|
// if subsites exist, go through each subsite and sync each subsite's pages.
|
||||||
foreach(DataObject::get("SiteTree") as $page) {
|
// disabling the filter doesn't work reliably, because writing pages that share
|
||||||
|
// the same URLSegment between subsites will break, e.g. "home" between two
|
||||||
|
// sites will modify one of them to "home-2", thinking it's a duplicate. The
|
||||||
|
// check before a write is done in SiteTree::validURLSegment()
|
||||||
|
if(class_exists('Subsite')) {
|
||||||
|
// loop through each subsite ID, changing the subsite, then query it's pages
|
||||||
|
foreach(Subsite::get()->getIDList() as $id) {
|
||||||
|
Subsite::changeSubsite($id);
|
||||||
|
foreach(SiteTree::get() as $page) {
|
||||||
|
// syncLinkTracking is called by SiteTree::onBeforeWrite().
|
||||||
|
// Call it without affecting the page version, as this is an internal change.
|
||||||
|
$page->writeWithoutVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// change back to the main site so the foreach below works
|
||||||
|
Subsite::changeSubsite(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(SiteTree::get() as $page) {
|
||||||
// syncLinkTracking is called by SiteTree::onBeforeWrite().
|
// syncLinkTracking is called by SiteTree::onBeforeWrite().
|
||||||
// Call it without affecting the page version, as this is an internal change.
|
// Call it without affecting the page version, as this is an internal change.
|
||||||
$page->writeWithoutVersion();
|
$page->writeWithoutVersion();
|
||||||
}
|
}
|
||||||
if(class_exists('Subsite')) Subsite::disable_subsite_filter($origDisableSubsiteFilter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user