Automattic / newspack-custom-content-migrator

Custom migration tasks for launching and migrating Newspack sites on Atomic
5 stars 5 forks source link

Add a very basic time machine for posts #489

Closed naxoc closed 3 weeks ago

naxoc commented 6 months ago

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:

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.