infinitered / thesis-phoenix

A lightweight, bolt-on, intuitive content editing system for Elixir/Phoenix websites. Star this repo and follow along with our progress!
Other
646 stars 62 forks source link

Exception when trying to access the import/export/backup tray when current Page is not yet in db #128

Closed yulolimum closed 6 years ago

yulolimum commented 7 years ago

If you have a Page that hasn't yet been registered in the database, when you access the import/export tray you get an exception. We need another function to handle when the page is nil.

  def backups(page_slug) when is_binary(page_slug) do
    page = page(page_slug)
    backups(page.id)
  end

  def backups(page_id) when is_integer(page_id) do
    repo().all(
      from b in Backup,
      where: b.page_id == ^page_id,
      order_by: [desc: b.page_revision]
    )
  end
yulolimum commented 7 years ago

Some context: when you access that specific tray, we make a request to get all revisions for this specific page. We make this request every single time you hit that button. It is so that you don't have to refresh the page to see a list of updated revisions after you publish some changes.

yulolimum commented 7 years ago

We can just return empty array if page is nil.

yulolimum commented 6 years ago

Fixed in #133