Automattic / newspack-custom-content-migrator

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

Add / Media Credit Plugin Migrator #462

Closed ronchambers closed 5 months ago

ronchambers commented 7 months ago

This PR adds a general command to migrate the Media Credit Plugin to native [caption] shortcodes and post meta _media_credit for use with the Newspack Plugin media credits.

Caution: (FIXED WITH https://github.com/Automattic/newspack-custom-content-migrator/pull/498) This command can cause data to be lost. Please perform a --dry-run and examine the final "Report" section for data differences that will be removed from the post content image captions. The Media Credit Plugin not only stores media credits in the post meta table using the _media_credit key, it also allows Admins to add custom credits on images directly in the post editor. In many cases these custom strings match the value in post meta, but many times they do not. The CLI command in this PR will attempt to save the custom string into the post meta if the post meta is blank, but in the cases where the post meta already exists and is different than the custom string, the custom strings are removed from the post content. The only way to capture these for Publisher review is to do a --dry-run and view the "Report" section at the end of the log output for "by-hand" review.

Caution: This command must be run prior to converting post content to Blocks, otherwise the block converter will be unable to properly remove the Media Credit Plugin's [media-credit] shortcode. This command will convert [media-credit] shortcodes to native [caption] shortcodes that the Block converter can properly convert.

Command: wp newspack-content-migrator migrate-media-credit-plugin

Output: MediaCreditPluginMigrator_cmd_migrate_media_credit_plugin.log

Options: --dry-run will provide a data loss "Report" at the end of the log. (Data loss is fixed with PR)

Future ideas:


ronchambers commented 6 months ago

@iuravic - feel free to review. I worked with Andrew on the first "caution/dry-run" issue already and I posted to Slack in regards to the second "caution". So I feel confident on the logic here, but if you see any issues within the code feel free to let me know :-)

ronchambers commented 6 months ago

Commit https://github.com/Automattic/newspack-custom-content-migrator/pull/462/commits/f328cfbf318e685fc2ac6beac71a1111bfa4aa05 FIXES an issue with how the Media Credit Plugin wrote [caption] shortcodes vs the way Newspack Content Converter changes these into image blocks. This fix will remove un-needed line breaks from the shortcodes that were causing block conversion issues.

Old/wrong with line break:

[caption ...]
<img...>[/caption]

New/fixed without line break:

[caption ...]<img...>[/caption]