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

Add Page Versions #2022

Merged
merged 41 commits into from
Mar 1, 2021
Merged

Add Page Versions #2022

merged 41 commits into from
Mar 1, 2021

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Feb 11, 2021

What is this pull request for?

Adds page versions in order to fix a fundamental issue we are having for a long time now:

Once a page is published all further changes to elements on that page are immediately public as well.

Although we have the "Publish" button this really never was a stable fix to that problem, since this relied on a cached version of that page that not always is guaranteed to exist.

This now is fixed by associating elements to a page version and moving the publication timestamps from the page to the page version model.

Every page has at least one draft version (a not published version) and - once published - a public version.

A page is considered public if the page has a public page version. Elements are always loaded from the public version of a page. The preview always shows the draft version and updates to elements are always only made on the draft version.

When publishing the page the currently visible elements are copied to the public version and never get touched again.

For now subsequent publishes will re-create the public version and does not - yet - store a version history. This way we do not create too many versions (and elements/contents/essences , etc.) that would needed to be cleaned up ans such.

There are lots of opportunities with this new layer, but we want to keep the impact as limited as possible right now.

For instance there is currently no change in the UI. What we consider a good thing for now.

So there is currently no version management or switching possible (say necessary), but this is lays the foundation for it.

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

TODO

  • Clicking an element in preview mode does not hightlight the element editor

@tvdeyen tvdeyen changed the title Page versions 2020 Add Page Versions Feb 11, 2021
@tvdeyen tvdeyen force-pushed the page-versions-2020 branch 2 times, most recently from bb8287c to 676ea3b Compare February 15, 2021 10:48
@tvdeyen tvdeyen added this to the 6.0 milestone Feb 15, 2021
@tvdeyen tvdeyen requested a review from mamhoff February 15, 2021 10:48
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow wow wow.

versions-todo.md Outdated Show resolved Hide resolved
app/models/alchemy/element.rb Show resolved Hide resolved
@tvdeyen tvdeyen force-pushed the page-versions-2020 branch 4 times, most recently from 11d483a to 04fae2a Compare February 16, 2021 12:21
@tvdeyen tvdeyen requested a review from mamhoff February 16, 2021 13:39
@tvdeyen tvdeyen self-assigned this Feb 16, 2021
While loading a page tree from the API include elements
from public page version.
and use the page version instead.
Instead of passing the page_id we use the page_version_id
to create, update and order elements in the Admin.
Only elements that have a public version should be returned
by the API.
It turned out that using .find_each messed with the order of elements during copy.
We want to make sure that we only have one published version
at a given time. Ideally we would also have a database constraint,
but for now this works fine.

Otherwise we would get duplicated elements on pages with several published versions.
Instead of the current page the ElementsFinder now uses
the given page version to load elements.

The render_elements and Page#find_elements methods use
the pages public_version by default, while supporting
to pass/set a custome page version instead.
Since we load the draft version elements in the elements window,
we need to load the pages draft version in the preview frame as
well.
In render_elements we use either a `@page_version` or the pages public
version to load elements from.
Instead of creating a new public version every time we publish a page,
we re-use the already published version and copy all elements over.

Creating a new one if no published version exists yet.

That way we are sure that we always only have one public version per page.
A page is considered public? if a public version exists and this is published.
Any page that does not have any published version is considered not public
These timestamps now live on the page version.

The values still exists on the table for historical reasons
and to make upgrades easer, but they are set to read only and
delegate to the public version.
Only use the assigned page version if there is no page
given via the `:from_page` option, so that elements are
loaded from a layout page is ensured even in the page
edit preview.
Always use the draft version of the page set or passed into
render_elements if we are in preview_mode.
@tvdeyen tvdeyen merged commit 1cd1c6d into AlchemyCMS:main Mar 1, 2021
@tvdeyen tvdeyen deleted the page-versions-2020 branch March 1, 2021 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants