Add a very basic time machine for posts #489
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
PostTimeMachine
that you would call from your migration command to record a "snapshot" of a post that you are about to do something to.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:
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.