wpengine / atlas-content-modeler

Content modeling plugin for WordPress
https://developers.wpengine.com/docs/atlas-content-modeler
GNU General Public License v2.0
165 stars 13 forks source link

Add 'wp acm model change-id' WP-CLI command to migrate model-ids #615

Closed nickcernis closed 2 years ago

nickcernis commented 2 years ago

Description

Adds a wp acm model change id [old-id] [new-id] WP-CLI command to help users change model IDs and migrate posts between the old and new ID.

I've written this in a way that the same logic will work outside of a WP-CLI context (used in this PR's tests without invoking WP-CLI, but also useful as a backup to support customers who don't/won't use WP-CLI). For example, save this file in /plugins/, then activate the plugin and you'll be able to change model IDs by visiting /wp-admin/plugins.php?acm_old_model_id=old&acm_new_model_id=new.

https://wpengine.atlassian.net/browse/MTKA-1615

Checklist

I have:

Testing

Includes tests.

To test manually:

  1. Create a model with a relationship field and a custom taxonomy.
  2. Add posts that relate to other posts and tag some with custom taxonomy terms.
  3. In WP-CLI, run wp acm model change-id [old-id] [new-id] where old-id is the model ID of your model. (Optionally skip the confirmation prompt with --yes.)

After you refresh your admin page in WordPress, the model you changed the ID for should still be accessible (it will have the same label, but your new model ID). Posts should still be present, with any relationships and taxonomy terms.

Screenshots

> wp acm model change-id type type
Error: New ID of ‘type’ is in use by another model.

x wp acm model change-id type bad!@model@name
Error: New model ID must only contain lowercase alphanumeric characters, underscores and hyphens.

x wp acm model change-id type 1badmodelname
Error: New model ID must not start with a number.

x wp acm model change-id type modelnamethatexceeds20characters
Error: New model ID must not exceed 20 characters.

x wp acm model change-id type author
Error: New ID of ‘author’ is reserved or in use by WordPress Core.

x wp acm model change-id type acf-field
Error: New ID of ‘acf-field’ is in use by a custom post type.

x wp acm model change-id type this-should-work
Change model ID from ‘type’ to ‘this-should-work’? [y/n] y
Model ID updated.
2 posts updated.
Success: Model ID changed from ‘type’ to ‘this-should-work’.

Documentation Changes

Extended existing CLI docs.