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 a very basic time machine for posts #489

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open

Conversation

naxoc
Copy link
Member

@naxoc naxoc commented Apr 18, 2024

This is a very first and naive stab at a "Time Machine" we can use to record revisions of a post and roll back to that revision if we need to.

The idea is that we update a .csv file with revision ids when we run a command, and should we need to roll content back, we can with this thingy.

There are two files:

  • The PostTimeMachine that you would call from your migration command to record a "snapshot" of a post that you are about to do something to.
  • The PostTimeMachineCommand that just has a command to restore revisions from a snapshot file.

A snapshot file is simply a csv file for now. It could look something like this:

ID,version_id,revision_url
41046,41950,https://some-site.local/wp-admin/revision.php?revision=41950
41047,41948,https://some-site.local/wp-admin/revision.php?revision=41948
9541,9541,https://some-site.local/wp-admin/post.php?post=9541&action=edit

The url is clickable and can maybe be of help with debugging. Note that it takes you to the revision snapshotted, but to compare with the latest you have to either click "Next" or "Compare any two revisions" to see the diff. I wish WP supported a url like https://some-site.local/wp-admin/revision.php?from=67180&to=current but it looks like no. Also note that the last one is an edit url. If a post has no existing revisions, this revisions url will not work. We could work around that with wrapping wp_update_post someday and then grab before and after.

How to test

Take a look at the command wp newspack-content-migrator post-time-machine-test (cmd_post_time_machine_test()). That is probably the best way to grok what is going on. That command we can remove later, but while we play around with this it's handy.


  • confirmed that PHPCS has been run

@naxoc naxoc requested a review from a team April 18, 2024 19:37
@naxoc naxoc self-assigned this Apr 18, 2024
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.

None yet

1 participant