Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Running FilesystemSyncTask and having Subsites module results in unusable URLSegments in sitetree #35

Closed
sminnee opened this Issue · 3 comments

4 participants

@sminnee
Owner

From http://open.silverstripe.org/ticket/6264

I've just done a fresh install to confirm, but it appears that if running the latest subsites trunk as of this date, and 2.4.3. Then running FilesystemSyncTask?, the duplicate URLSegments in Sitetree (for each subsite) are deemed conflicts and rewritten.

For example, subsite 2 'home' URLSegment becomes 'home-2' instead of 'home' which makes the subsite unreachable.

@bilekt3

I have made deed digging in to the core and I found, that there is problem in function validURLSegment in file SiteTree.php

file filesystem/Filesystem.php call snippet:

// Update the image tracking of all pages
if(class_exists('Subsite')) Subsite::$disable_subsite_filter = true;
foreach(DataObject::get("SiteTree") as $page) {
    // syncLinkTracking is called by SiteTree::onBeforeWrite()
    $page->write();
}
if(class_exists('Subsite')) Subsite::$disable_subsite_filter = false; 

But in function validURLSegment() in file SiteTree.php (wrapped with previous code) is called snippet:

$existingPage = DataObject::get_one(
    'SiteTree', 
    "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
);

if ($existingPage) {
    return false;
} 

Problem is caused because different subsites could have same URLSegment but in previous code Subsite will return all SiteTrees from database.

To fix described issue problem You need to modify code to:

if (class_exists("Subsite")) {
    $previousState = Subsite::$disable_subsite_filter;
    Subsite::$disable_subsite_filter = false;
}

$existingPage = DataObject::get_one(
    'SiteTree', 
    "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
);

if (class_exists("Subsite")) {
    Subsite::$disable_subsite_filter = $previousState;
}

if ($existingPage) {
    return false;
} 

Seem work for me. Please comment if you see problem.

Tomas

@sminnee
Owner

Seems reasonable to me. The coupling of core to the Subsite module isn't particularly nice, but I can't see any other fix that wouldn't necessitate a huge refactoring.

Can you submit as a pull request to core?

@cloph

still a problem with 3.1, so a pull request/patch would indeed be nice :-)

@halkyon halkyon closed this
@bilekt3 bilekt3 referenced this issue in silverstripe/silverstripe-framework
Closed

Fixed problem with Looking for new files with Subsite module enabled #787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.