Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matt-in-a-hat opened this issue Jul 15, 2019 · 5 comments
Open

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

matt-in-a-hat opened this issue Jul 15, 2019 · 5 comments

Comments

@matt-in-a-hat
Copy link

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 270b719

To
cwp/cwp 2.3.1 ec6c13a

@matt-in-a-hat
Copy link
Author

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
Copy link
Contributor

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
Copy link

phptek commented Aug 7, 2019

@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
Copy link

phptek commented Aug 7, 2019

@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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants