locomotivecms / mounter

Mount in memory any LocomotiveCMS site, from a template on the filesystem, a zip file or even an online engine
MIT License
13 stars 33 forks source link

slug => is already taken redux #23

Open Iteratix opened 10 years ago

Iteratix commented 10 years ago

This issue is still affecting our Wagon/Engine installs, using latest code.

Duplicate #16, but #16 is marked as closed and solved, but it is not for us. Also, comments in #16 indicate this is same for others.

Also, in locomotivecms/engine#804 others commented that it is not working for them either.

felix-last commented 10 years ago

We have the same issue. Always been deleting the templatized pages before pushing.

mariosant commented 10 years ago

I confirm that, we are having the same issue for snippets too!

LouisSayers commented 10 years ago

I'm seeing the same thing for handles as well as slugs :(

LouisSayers commented 10 years ago

K, I traced the problem for pages to PagesWriter#prepare. The problem can be summed up as follows:

self.pages                         # {handle: slug}
attributes['fullpage']             # slug
self.pages[attributes['fullpage']] # fail

So I'm guessing the appropriate thing is to instead have attributes['handle'] - but I'm not sure exactly what 'fullpage' is supposed to represent? and not sure if everything gets given a default handle?

For now I've implemented the inverse of the above comment to make my own system work:

 def prepare
        super
        self.new_pages, self.remote_translations = [], {}

        pages_by_slug = {} #added
        self.pages.map { |key,value| pages_by_slug[value.slug] = value } #added

        # set the unique identifier to each local page
        self.get(:pages, nil, true).each do |attributes|
          require 'pry';binding.pry
          page = pages_by_slug[attributes['fullpath'].dasherize] #modified to use pages_by_slug
          self.remote_translations[attributes['fullpath']] = attributes['translated_in']
          page._id = attributes['id'] if page
        end

        # assign the parent_id and the content_type_id to all the pages
        self.pages.values.each do |page|
          next if page.index_or_404?

          page.parent_id = page.parent._id
        end
      end