silverstripe / cwp

Common Web Platform (CWP) features module. We strongly recommend using it for all new CWP projects. Future features will be delivered here.
https://www.cwp.govt.nz
BSD 3-Clause "New" or "Revised" License
10 stars 26 forks source link

Related pages from CWP 1 (SS3) never publish in CWP2 (SS4) #221

Open matt-in-a-hat opened 5 years ago

matt-in-a-hat commented 5 years ago

If you have some pages that have related pages in SS3, once upgraded to SS4 those links do not show on live versions of the page, and there doesn't seem to be any way of publishing the links.

Since #177 we can add links and when the page is published the new links will show (e.g. with <% loop RelatedPages %>), but still the old related pages will not show on the front-end, even though they are showing in the gridfield in the CMS.

And due to #179 we cannot remove these links and re-add them in hopes this will put them in the right state to be published.

Tested going from cwp/cwp 1.9.1 270b719d

To cwp/cwp 2.3.1 ec6c13a1

matt-in-a-hat commented 5 years ago

Was able to fix this for our case with a migration task:

class PublishAllRelatedPages extends BuildTask
{
    protected $description = 'Migrates related pages from SS3 to SS4 by publishing all links.';

    public function run($request)
    {
        $records = Versioned::get_by_stage(RelatedPageLink::class, Versioned::DRAFT);
        echo "Updating {$records->count()} related page links... \n";
        foreach ($records as $record) {
            $record->writeToStage(Versioned::LIVE);
        }
        echo 'Done';
    }
}
robbieaverill commented 5 years ago

there doesn't seem to be any way of publishing the links.

This part sounds like a bug to me, since we have an $owns declaration on BasePage which should automatically publish the RelatedPagesThrough relations (RelatedPageLink instances) when the page is published.

phptek commented 5 years ago

@robbieaverill For sure it's a bug, but only for related pages on parent pages published prior to the "RelatedPagesThrough" patch. Vendors still need to come up woith a way of fixing "legacy" related pages, since ManyMany join tables didn't used to be Versioned (AFAIK)

phptek commented 5 years ago

@matt-in-a-hat Legend. Your BuildTask worked, and les invasive than my solution which was to TRUNCATE (Live/Versions table equivalents) and re-populate from Draft.

NightJar commented 1 year ago

I ran into a similar issue with CMS 4 upgrades, where any object that wasn't previously versioned that has had Versioned applied to it (like related pages) will entirely disappear from the site due to the root table being used for draft (as opposed to the _Live suffix table for live content).

I wrote a build task that has some in handy many times not just with CMS 4 upgrades through the years. This seems like too little too late, but it's still proving useful for me in 2023.

https://gist.github.com/NightJar/eb0565d6d3ad41a5c5e6fcbfe6a54f4b

It will publish any record that is versioned, but has no versions (_Versions suffix table). Versioned object have a version created when they are created - so the only way this happens is if Versioned is applied to pre-existing objects (previously "always live" in behaviour). The task uses singular publish and avoids owns as to not publish content that should not be published. As it goes through all objects, any relationships that are owned that have also had Versioned applied will be dealt with in time in, also in a singular fashion.