comfy / comfortable-mexican-sofa

ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
MIT License
2.72k stars 638 forks source link

Fixtures losing target_page (redirect info) #300

Closed holli closed 11 years ago

holli commented 11 years ago

We are losing redirections after fixtures export import. I guess redirection is based on target_page so after initial check:

export: https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/fixtures.rb#L252 'target_page' => page.target_page.try(:slug),

import : https://github.com/comfy/comfortable-mexican-sofa/blob/master/lib/comfortable_mexican_sofa/fixtures.rb#L103 page.target_page = site.pages.find_by_full_path(attributes[:target_page])

This fails obviiously, try with oneliner in console

Cms::Page.find_by_full_path(Cms::Page.first.slug) => nil

So following would work

Cms::Page.find_by_slug(Cms::Page.first.slug)

Easiest would be to change line 103 to use find_by_slug. This would fix most of the cases.

But

To be sure, you would have to drive fixtures two times so that if the target_page is loaded after the page that has the reference, it will not be found. In most cases this would not matter, because db already has most of the pages. For total solution these target pages should be added to some kind of array and processed after everything has been imported.

GBH commented 11 years ago

Fixed. Will merge into master