silverstripe / silverstripe-populate

Populate your database through YAML files
BSD 3-Clause "New" or "Revised" License
26 stars 24 forks source link

Subsites compatibility #18

Closed flashbackzoo closed 2 years ago

flashbackzoo commented 7 years ago

Hey,

I've run into an issue using populate with subsites.

Each subsite is able to have pages with the same URL segment, for example:

mainsite.com/home mysubsite.com/home

Populate handles URL segment collisions like the CMS does, by prefixing the page id, so you get home-2 on the subsite URL segment.

Here's a example populate.yml

Subsite:
  MySubsite:
    Title: 'My Subsite'
    Theme: 'mysubsite'

SubsiteDomain:
  MySubsiteDomain:
    Domain: 'mysubsite.com'
    Protocol: 'automatic'
    Subsite: =>Subsite.MySubsite

Page:
  Home:
    ParentID: 0
    ShowInMenus: false
    Title: 'Home'
    URLSegment: 'home'
  SubsiteHome:
    ParentID: 0
    ShowInMenus: false
    Title: 'Home'
    URLSegment: 'home'
   Subsite: =>Subsite.MySubsite

I'm currently working around this by creating an DataExtension on Populate and updating the records manually.

class PopulateExtension extends DataExtension
{
    public function onAfterPopulateRecords()
    {
        // Do stuff
    }
}

Is there a way I can populate pages across subsites without having to use the onAfterPopulateRecords hook?

Thanks

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/45188608-subsites-compatibility?utm_campaign=plugin&utm_content=tracker%2F668165&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F668165&utm_medium=issues&utm_source=github).
pitchandtone commented 7 years ago

Not as far as I know, I don't think we've used this module with subsites, so it probably needs to be extended include that kind of functionality.

wernerkrauss commented 3 years ago

You could avoid that when you switch subsites while adding objects.

This could be done in a new hook, e.g. "onBeforePopulateRecord" and switch back in "onAfterPopulateRecord"

Then URLSegmentFilter only gets the pages from the current subsite and can create unique urls per subsite.