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

Bulk Migration Support via WP CLI #70

Merged
merged 13 commits into from
Jul 8, 2022
Merged

Conversation

dsawardekar
Copy link
Collaborator

@dsawardekar dsawardekar commented Jun 24, 2022

Description of the Change

This PR adds support for bulk migration of classic editor posts to Gutenberg Blocks. The implementation provides a WP CLI command to start and monitor the progress of the migration. When started the CLI outputs a link that must be opened in a browser window. The browser window will convert classic editor content to blocks and then move on to the next post, and so forth until all posts are converted. Posts that are already converted to blocks are skipped.

The following screencast shows this in action.

bulk_migration_demo

Closes #56

Verification Process

To verify this you need a WordPress database with classic editor content. Then run the WP CLI as follows. The CLI will output a URL that needs to be opened in the Browser. (You should be logged in to the WordPress before hand.)

$ wp convert-to-blocks start

I've tested this on a recent production migration with <1000 posts. Larger migrations are also possible but will take longer to complete.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Added - WP CLI based bulk migration support

Credits

Props @dsawardekar

@dsawardekar
Copy link
Collaborator Author

cc @jeffpaul @gthayer

@dsawardekar dsawardekar changed the title Feature/wp cli migration agent Bulk Migration Support via WP CLI Jun 24, 2022
@dsawardekar dsawardekar requested a review from jeffpaul June 24, 2022 10:19
'post_type' => $post_type,
'post_status' => 'publish',
'fields' => 'ids',
'posts_per_page' => -1,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would need to be updated to be a paginated loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsawardekar if you agree on ^ this, mind a quick update to make that update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gthayer @jeffpaul We do need the posts_per_page=-1 here because of the way this has to be structured. The WP CLI seeds the loop with the ids query and runs only once when the WP CLI command is started. Once the agent link is opened, the loop runs entirely in the browser via redirects.

@jeffpaul jeffpaul added this to the 1.1.0 milestone Jun 24, 2022
@jeffpaul jeffpaul requested review from a team, faisal-alvi and dkotter and removed request for a team and jeffpaul June 24, 2022 15:09
@jeffpaul
Copy link
Member

@dkotter @faisal-alvi looking to one of you to give this a review from the OSP perspective, please and thanks!

Copy link
Member

@faisal-alvi faisal-alvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, it worked:

image

But I have noticed a couple of things:

  1. It also runs through the posts which do not have classic editor content. Would be very efficient in performance and time savior if we only loop through the classic editor posts.
  2. If the post is empty, the 'Classic Editor' mark remains as is, even after the migration is completed. For example, please see the post "test2" below:

image

image

Also, ran the phpcs check and found the following errors in multiple places, so just pointing here:

  • Short array syntax is not allowed.
  • Parameter comment must end with a full stop, exclamation marks, or question marks.

A question: can we pass a CPT slug in the CLI command to convert its posts?

And, just a few minor suggestions are posted below.

includes/ConvertToBlocks/MigrationAgent.php Outdated Show resolved Hide resolved
$progress_bar->tick();

$prev_progress = 0;
$ticks = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor alignment required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

assets/js/editor/editor.js Show resolved Hide resolved
@dsawardekar
Copy link
Collaborator Author

@faisal-alvi I ran composer lint-fix and pushed the changes to this branch. The alignment issue was the only thing I saw when running composer lint on my local. After fixing that, I do not see any other linter warnings.

➜ convert-to-blocks (feature/wp-cli-migration-agent) ✔ composer lint
> phpcs .
➜ convert-to-blocks (feature/wp-cli-migration-agent) ✔ 

RE: Empty posts showing as CE after conversion

The only way to accurately check if a post has blocks is to check its post_content for the Gutenberg preamble, <!-- wp. An empty post has nothing to convert and hence is treated as CE content even after conversion.

The PR has the --only WP CLI flag which takes a comma delimited list of post ids. That could be used to customize which post_ids to convert if such flexibility is needed. Maybe it could be a filter hook that overrides the post ids lookup. Lets get user feedback to understand typical usage.

cc @jeffpaul

faisal-alvi
faisal-alvi previously approved these changes Jul 6, 2022
Co-authored-by: Faisal Alvi <faisalalvi33@gmail.com>
@dkotter dkotter merged commit 2ffb5dc into develop Jul 8, 2022
@dkotter dkotter deleted the feature/wp-cli-migration-agent branch July 8, 2022 15:51
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.

Bulk conversion
5 participants