| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * WP-CLI commands registration. | |
| 3 | + * WP-CLI file. | |
| 4 | 4 | * |
| 5 | 5 | * @package Activitypub |
| 6 | 6 | */ |
| 7 | 7 | |
| @@ -6,131 +6,126 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Activitypub; |
| 9 | 9 | |
| 10 | +use WP_CLI; | |
| 11 | +use WP_CLI_Command; | |
| 12 | + | |
| 10 | 13 | /** |
| 11 | - * ActivityPub CLI command registry. | |
| 14 | + * WP-CLI commands. | |
| 12 | 15 | * |
| 13 | - * Registers all ActivityPub CLI subcommands with WP-CLI. | |
| 14 | - * | |
| 15 | 16 | * @package Activitypub |
| 16 | 17 | */ |
| 17 | -class Cli { | |
| 18 | +class Cli extends WP_CLI_Command { | |
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | - * Register all ActivityPub CLI commands. | |
| 21 | + * Remove the entire blog from the Fediverse. | |
| 21 | 22 | * |
| 22 | - * This method registers the main 'activitypub' command namespace and all its | |
| 23 | - * subcommands for managing ActivityPub functionality via WP-CLI. | |
| 23 | + * ## EXAMPLES | |
| 24 | 24 | * |
| 25 | - * Available commands: | |
| 26 | - * - wp activitypub post <delete|update> <id> | |
| 27 | - * - wp activitypub comment <delete|update> <id> | |
| 28 | - * - wp activitypub actor <delete|update> <id> | |
| 29 | - * - wp activitypub outbox <undo|reschedule> <id> | |
| 30 | - * - wp activitypub cache <clear|status> [--type=<type>] | |
| 31 | - * - wp activitypub self-destruct [--status] [--yes] | |
| 32 | - * - wp activitypub move <from> <to> | |
| 33 | - * - wp activitypub follow <remote_user> | |
| 34 | - * - wp activitypub stats <collect|compile|send> | |
| 35 | - * - wp activitypub fetch <url> | |
| 36 | - * - wp activitypub blurhash backfill [--dry-run] [--limit=<n>] [--force] | |
| 25 | + * $ wp activitypub self-destruct | |
| 26 | + * | |
| 27 | + * @param array|null $args The arguments. | |
| 28 | + * @param array|null $assoc_args The associative arguments. | |
| 29 | + * | |
| 30 | + * @return void | |
| 37 | 31 | */ |
| 38 | - public static function register() { | |
| 39 | - // Register parent command with version subcommand. | |
| 40 | - \WP_CLI::add_command( | |
| 41 | - 'activitypub', | |
| 42 | - '\Activitypub\Cli\Command', | |
| 43 | - array( | |
| 44 | - 'shortdesc' => 'Manage ActivityPub plugin functionality and federation.', | |
| 45 | - ) | |
| 46 | - ); | |
| 32 | + public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 33 | + WP_CLI::warning( 'Self-Destructing is not implemented yet.' ); | |
| 34 | + } | |
| 47 | 35 | |
| 48 | - \WP_CLI::add_command( | |
| 49 | - 'activitypub post', | |
| 50 | - '\Activitypub\Cli\Post_Command', | |
| 51 | - array( | |
| 52 | - 'shortdesc' => 'Manage ActivityPub posts (delete or update).', | |
| 53 | - ) | |
| 54 | - ); | |
| 36 | + /** | |
| 37 | + * Delete or Update a Post, Page, Custom Post Type or Attachment. | |
| 38 | + * | |
| 39 | + * ## OPTIONS | |
| 40 | + * | |
| 41 | + * <action> | |
| 42 | + * : The action to perform. Either `delete` or `update`. | |
| 43 | + * --- | |
| 44 | + * options: | |
| 45 | + * - delete | |
| 46 | + * - update | |
| 47 | + * --- | |
| 48 | + * | |
| 49 | + * <id> | |
| 50 | + * : The id of the Post, Page, Custom Post Type or Attachment. | |
| 51 | + * | |
| 52 | + * ## EXAMPLES | |
| 53 | + * | |
| 54 | + * $ wp activitypub post delete 1 | |
| 55 | + * | |
| 56 | + * @synopsis <action> <id> | |
| 57 | + * | |
| 58 | + * @param array $args The arguments. | |
| 59 | + */ | |
| 60 | + public function post( $args ) { | |
| 61 | + $post = get_post( $args[1] ); | |
| 55 | 62 | |
| 56 | - \WP_CLI::add_command( | |
| 57 | - 'activitypub comment', | |
| 58 | - '\Activitypub\Cli\Comment_Command', | |
| 59 | - array( | |
| 60 | - 'shortdesc' => 'Manage ActivityPub comments (delete or update).', | |
| 61 | - ) | |
| 62 | - ); | |
| 63 | + if ( ! $post ) { | |
| 64 | + WP_CLI::error( 'Post not found.' ); | |
| 65 | + } | |
| 63 | 66 | |
| 64 | - \WP_CLI::add_command( | |
| 65 | - 'activitypub actor', | |
| 66 | - '\Activitypub\Cli\Actor_Command', | |
| 67 | - array( | |
| 68 | - 'shortdesc' => 'Manage ActivityPub actors (delete or update).', | |
| 69 | - ) | |
| 70 | - ); | |
| 67 | + switch ( $args[0] ) { | |
| 68 | + case 'delete': | |
| 69 | + WP_CLI::confirm( 'Do you really want to delete the (Custom) Post with the ID: ' . $args[1] ); | |
| 70 | + Scheduler::schedule_post_activity( 'trash', 'publish', $args[1] ); | |
| 71 | + WP_CLI::success( '"Delete" activity is queued.' ); | |
| 72 | + break; | |
| 73 | + case 'update': | |
| 74 | + Scheduler::schedule_post_activity( 'publish', 'publish', $args[1] ); | |
| 75 | + WP_CLI::success( '"Update" activity is queued.' ); | |
| 76 | + break; | |
| 77 | + default: | |
| 78 | + WP_CLI::error( 'Unknown action.' ); | |
| 79 | + } | |
| 80 | + } | |
| 71 | 81 | |
| 72 | - \WP_CLI::add_command( | |
| 73 | - 'activitypub outbox', | |
| 74 | - '\Activitypub\Cli\Outbox_Command', | |
| 75 | - array( | |
| 76 | - 'shortdesc' => 'Manage ActivityPub outbox items (undo or reschedule).', | |
| 77 | - ) | |
| 78 | - ); | |
| 82 | + /** | |
| 83 | + * Delete or Update a Comment. | |
| 84 | + * | |
| 85 | + * ## OPTIONS | |
| 86 | + * | |
| 87 | + * <action> | |
| 88 | + * : The action to perform. Either `delete` or `update`. | |
| 89 | + * --- | |
| 90 | + * options: | |
| 91 | + * - delete | |
| 92 | + * - update | |
| 93 | + * --- | |
| 94 | + * | |
| 95 | + * <id> | |
| 96 | + * : The id of the Comment. | |
| 97 | + * | |
| 98 | + * ## EXAMPLES | |
| 99 | + * | |
| 100 | + * $ wp activitypub comment delete 1 | |
| 101 | + * | |
| 102 | + * @synopsis <action> <id> | |
| 103 | + * | |
| 104 | + * @param array $args The arguments. | |
| 105 | + */ | |
| 106 | + public function comment( $args ) { | |
| 107 | + $comment = get_comment( $args[1] ); | |
| 79 | 108 | |
| 80 | - \WP_CLI::add_command( | |
| 81 | - 'activitypub self-destruct', | |
| 82 | - '\Activitypub\Cli\Self_Destruct_Command', | |
| 83 | - array( | |
| 84 | - 'shortdesc' => 'Remove the entire blog from the Fediverse.', | |
| 85 | - ) | |
| 86 | - ); | |
| 109 | + if ( ! $comment ) { | |
| 110 | + WP_CLI::error( 'Comment not found.' ); | |
| 111 | + } | |
| 87 | 112 | |
| 88 | - \WP_CLI::add_command( | |
| 89 | - 'activitypub move', | |
| 90 | - '\Activitypub\Cli\Move_Command', | |
| 91 | - array( | |
| 92 | - 'shortdesc' => 'Move the blog to a new URL.', | |
| 93 | - ) | |
| 94 | - ); | |
| 113 | + if ( was_comment_received( $comment ) ) { | |
| 114 | + WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' ); | |
| 115 | + } | |
| 95 | 116 | |
| 96 | - \WP_CLI::add_command( | |
| 97 | - 'activitypub follow', | |
| 98 | - '\Activitypub\Cli\Follow_Command', | |
| 99 | - array( | |
| 100 | - 'shortdesc' => 'Follow a remote ActivityPub user.', | |
| 101 | - ) | |
| 102 | - ); | |
| 103 | - | |
| 104 | - \WP_CLI::add_command( | |
| 105 | - 'activitypub cache', | |
| 106 | - '\Activitypub\Cli\Cache_Command', | |
| 107 | - array( | |
| 108 | - 'shortdesc' => 'Manage remote media cache (clear or show status).', | |
| 109 | - ) | |
| 110 | - ); | |
| 111 | - | |
| 112 | - \WP_CLI::add_command( | |
| 113 | - 'activitypub fetch', | |
| 114 | - '\Activitypub\Cli\Fetch_Command', | |
| 115 | - array( | |
| 116 | - 'shortdesc' => 'Fetch a remote URL with a signed ActivityPub request.', | |
| 117 | - ) | |
| 118 | - ); | |
| 119 | - | |
| 120 | - \WP_CLI::add_command( | |
| 121 | - 'activitypub stats', | |
| 122 | - '\Activitypub\Cli\Stats_Command', | |
| 123 | - array( | |
| 124 | - 'shortdesc' => 'Manage ActivityPub statistics (collect, compile or send).', | |
| 125 | - ) | |
| 126 | - ); | |
| 127 | - | |
| 128 | - \WP_CLI::add_command( | |
| 129 | - 'activitypub blurhash', | |
| 130 | - '\Activitypub\Cli\Blurhash_Command', | |
| 131 | - array( | |
| 132 | - 'shortdesc' => 'Backfill Blurhash placeholders for image attachments.', | |
| 133 | - ) | |
| 134 | - ); | |
| 117 | + switch ( $args[0] ) { | |
| 118 | + case 'delete': | |
| 119 | + WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[1] ); | |
| 120 | + Scheduler::schedule_comment_activity( 'trash', 'approved', $args[1] ); | |
| 121 | + WP_CLI::success( '"Delete" activity is queued.' ); | |
| 122 | + break; | |
| 123 | + case 'update': | |
| 124 | + Scheduler::schedule_comment_activity( 'approved', 'approved', $args[1] ); | |
| 125 | + WP_CLI::success( '"Update" activity is queued.' ); | |
| 126 | + break; | |
| 127 | + default: | |
| 128 | + WP_CLI::error( 'Unknown action.' ); | |
| 129 | + } | |
| 135 | 130 | } |
| 136 | 131 | } |