Sync: CLI: First pass at adding sync CLI commands#5933
Conversation
class.jetpack-cli.php
Outdated
| } | ||
|
|
||
| public function sync( $args, $assoc_args ) { | ||
| if ( ! Jetpack::is_active() ) { |
There was a problem hiding this comment.
I think it would be great to check if other conditions for sync are meet. See sync_allowed method in https://github.com/Automattic/jetpack/blob/master/sync/class.jetpack-sync-actions.php#L91
class.jetpack-cli.php
Outdated
|
|
||
| switch ( $action ) { | ||
| case 'status': | ||
| require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; |
There was a problem hiding this comment.
Could we reuse some of the sync status endpoint code by calling from it directly. Since it almost looks identical?
There was a problem hiding this comment.
For the status command, I think we could easily make that happen. We'd need to refactor a bit to handle the wp jetpack sync queue and wp jetpack sync start commands though.
|
I really like this and can see how sites would use this when they do batch operations to make sure things are in sync. |
class.jetpack-cli.php
Outdated
There was a problem hiding this comment.
Let's add some documentation to this command, so that wp jetpack sync --help will be helpful :)
If you follow the syntax of one of the other commands, you should get a nice helpful message back
class.jetpack-cli.php
Outdated
There was a problem hiding this comment.
just ! empty() will suffice for checking the variable. Won't throw a notice if not defined.
3b601fb to
c6a4e38
Compare
| 'full_queue_next_sync' => ( $sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ), | ||
| ) | ||
| ); | ||
| return Jetpack_Sync_Actions::get_sync_status(); |
|
Great work @ebinnion I think is ready to merge. I am just not sure about the syntax for |
|
Good point. The reason I created a separate command for the queue, sync_queue instead of sync, is that we could benefit from the robust validation of WP Cli thorough the |
sync/class.jetpack-sync-actions.php
Outdated
| } | ||
|
|
||
| static function get_sync_status() { | ||
| require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php'; |
There was a problem hiding this comment.
These first few lines could be written as:
self::initialize_sender();
$queue = self::$sender->get_sync_queue();
//...|
4.5 0525012 |
Changelog: add #5867 Changelog: add #5874 Changelog: add #5905 Changelog: add #5906 Changelog: add #5931 Changelog: add #5933 Changelog: add #5934 Bring over 4.4.2 changelog from branch-4.4 @see 18012a3 Changelog: add #5976, #5978, #5983 Changelog: add #5917 Changelog: add #5832 Changelog: add 4.4.2 release post link. CHangelog: add #5457 Changelog: add #5487 Changelog: add #5708 Changelog: add #5879 Changelog: add #5932 Changelog: add #5963 Changelog: add #5968 Changelog: add #5996 Changelog: add #5998 Changelog: add #5999 Changelog: add #6012 Changelog: add #6013 Changelog: add #6014 Changelog: add #6015 Changelog: add #6023 Changelog: add #6024 Changelog: add #6030 Changelog: add #5465 CHangelog: add #6063 Changelog: add #6025 Changelog: add #5974 Changelog: add #6059 Changelog: add #6046 Changelog: add #5418 Changelog: move things around and add missing information. Changelog: add #5565 Changelog: add #6087 Changelog: add #6095 Readme: add @tyxla to the list of contributors. Improved changelog for your readability and enjoyment updated the release date finalizing the changelog with a few more edits
| $items = $queue->peek( 100 ); | ||
|
|
||
| if ( empty( $items ) ) { | ||
| WP_CLI::log( sprintf( __( 'Nothing is in the %s queue', 'jetpack' ), $queue_name ) ); |
There was a problem hiding this comment.
Please don't create translatable strings like that. incremental and full can be integrated like that in English but this doesn't work for other languages, also translators need to know what the placeholder is (hint: translators: comment :) ). A string that works for a construct like you were using: Nothing is in the queue: %s
For our ATAT work on WP.com, it is necessary that we have the ability to script a full sync. This PR introduces a handful of commands that should be useful to @seanosh for ATAT work.
Here are the commands to test:
wp jetpack sync statusPOST /sites/$site/syncwp jetpack sync statuson your site to make sure that the status updateswp jetpack sync startGET /sites/$site/sync/statusa few times and verify that the status changeswp jetpack sync start --modules=functionsGET /sites/$site/sync/statusand verify that functions is the only thing inconfigproperty.wp jetpack sync_queue incremental peekNothing is in the sync queuewp jetpack sync sync_queue full peekPOST /sites/$site/syncwp jetpack sync sync_queue full peekand you should see things in the queue