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

Add NCC trickery #487

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from
Open

Add NCC trickery #487

wants to merge 11 commits into from

Conversation

naxoc
Copy link
Member

@naxoc naxoc commented Apr 17, 2024

This adds support for args in the block encode/decode commands:

  [--post-id=<post-id>]
    The ID of the post to process.

  [--num-items=<num-items>]
    The number of posts to process.

  [--min-post-id=<min-post-id>]
    The minimum post ID to process.

  [--max-post-id=<max-post-id>]
    The maximum post ID to process.

  [--post-types=<post-types>]
    Comma-separated list of post types to process. Default is "post".

There is a new command that "nudges" posts to be picked up by the NCC - it just inserts a line break at the top of posts that start with <!-- that would otherwise not get picked up by the NCC.

How to test

  • Make sure the NCC is installed and activated
  • Run wp newspack-content-migrator transform-blocks-encode --num-items=50 . The output will tell you next steps. It's also logged to file.
  • To test the "nudger", run this for example: wp newspack-content-migrator transform-blocks-nudge --num-items=30 --post-types=post,page

  • confirmed that PHPCS has been run – yea, kinda!

@naxoc naxoc self-assigned this Apr 17, 2024
@naxoc naxoc requested a review from a team April 18, 2024 14:48
@naxoc naxoc mentioned this pull request May 9, 2024
1 task
Copy link
Collaborator

@eddiesshop eddiesshop left a comment

Choose a reason for hiding this comment

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

I didn't actually test, just a straight ol' code review.

@@ -68,59 +173,156 @@ public function cmd_blocks_decode( array $pos_args, array $assoc_args ): void {
'post_content' => $content,
]
);
WP_CLI::log( sprintf( 'Decoded blocks in %s', get_permalink( $post->ID ) ) );
$this->logger->log( $logfile, sprintf( 'Decoded blocks in ID %d %s', $post->ID, get_permalink( $post->ID ) ), Logger::SUCCESS );
Copy link
Collaborator

Choose a reason for hiding this comment

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

To prevent false positives, I think we should change this to $updated = wp_update_post(...); if ( $updated) { $this->logger->log(...); And only increment $decoded_posts_counter if $updated === true

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I've updated both places.

wp_update_post(
[
'ID' => $post->ID,
'post_content' => $content,
]
);
WP_CLI::log( sprintf( 'Encoded blocks in %s', get_permalink( $post->ID ) ) );
$this->logger->log( $logfile, sprintf( 'Encoded blocks in post ID %d %s', $post->ID, get_permalink( $post->ID ) ), Logger::SUCCESS );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to comment from above, it'd be good to only display this information, if in fact we can confirm that wp_update_post was truly successful.

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.

None yet

2 participants