PluginProbe
ActivityPub / 5.3.1
ActivityPub v5.3.1
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-cli.php +172 -106 9.0.05.3.1 View file →
@@ -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,197 @@
6 6 */
7 7
8 8 namespace Activitypub;
9 9
10 +use Activitypub\Collection\Outbox;
11 +use Activitypub\Scheduler\Comment;
12 +use Activitypub\Scheduler\Post;
13 +use WP_CLI;
14 +use WP_CLI_Command;
15 +
10 16 /**
11 - * ActivityPub CLI command registry.
17 + * WP-CLI commands.
12 18 *
13 - * Registers all ActivityPub CLI subcommands with WP-CLI.
14 - *
15 19 * @package Activitypub
16 20 */
17 -class Cli {
21 +class Cli extends WP_CLI_Command {
18 22
19 23 /**
20 - * Register all ActivityPub CLI commands.
24 + * Remove the entire blog from the Fediverse.
21 25 *
22 - * This method registers the main 'activitypub' command namespace and all its
23 - * subcommands for managing ActivityPub functionality via WP-CLI.
26 + * ## EXAMPLES
24 27 *
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]
28 + * $ wp activitypub self-destruct
29 + *
30 + * @param array|null $args The arguments.
31 + * @param array|null $assoc_args The associative arguments.
32 + *
33 + * @return void
37 34 */
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 - );
35 + public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
36 + WP_CLI::warning( 'Self-Destructing is not implemented yet.' );
37 + }
47 38
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 - );
39 + /**
40 + * Delete or Update a Post, Page, Custom Post Type or Attachment.
41 + *
42 + * ## OPTIONS
43 + *
44 + * <action>
45 + * : The action to perform. Either `delete` or `update`.
46 + * ---
47 + * options:
48 + * - delete
49 + * - update
50 + * ---
51 + *
52 + * <id>
53 + * : The id of the Post, Page, Custom Post Type or Attachment.
54 + *
55 + * ## EXAMPLES
56 + *
57 + * $ wp activitypub post delete 1
58 + *
59 + * @synopsis <action> <id>
60 + *
61 + * @param array $args The arguments.
62 + */
63 + public function post( $args ) {
64 + $post = get_post( $args[1] );
55 65
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 - );
66 + if ( ! $post ) {
67 + WP_CLI::error( 'Post not found.' );
68 + }
63 69
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 - );
70 + switch ( $args[0] ) {
71 + case 'delete':
72 + WP_CLI::confirm( 'Do you really want to delete the (Custom) Post with the ID: ' . $args[1] );
73 + Post::schedule_post_activity( 'trash', 'publish', $post );
74 + WP_CLI::success( '"Delete" activity is queued.' );
75 + break;
76 + case 'update':
77 + Post::schedule_post_activity( 'publish', 'publish', $post );
78 + WP_CLI::success( '"Update" activity is queued.' );
79 + break;
80 + default:
81 + WP_CLI::error( 'Unknown action.' );
82 + }
83 + }
71 84
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 - );
85 + /**
86 + * Delete or Update a Comment.
87 + *
88 + * ## OPTIONS
89 + *
90 + * <action>
91 + * : The action to perform. Either `delete` or `update`.
92 + * ---
93 + * options:
94 + * - delete
95 + * - update
96 + * ---
97 + *
98 + * <id>
99 + * : The id of the Comment.
100 + *
101 + * ## EXAMPLES
102 + *
103 + * $ wp activitypub comment delete 1
104 + *
105 + * @synopsis <action> <id>
106 + *
107 + * @param array $args The arguments.
108 + */
109 + public function comment( $args ) {
110 + $comment = get_comment( $args[1] );
79 111
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 - );
112 + if ( ! $comment ) {
113 + WP_CLI::error( 'Comment not found.' );
114 + }
87 115
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 - );
116 + if ( was_comment_received( $comment ) ) {
117 + WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
118 + }
95 119
96 - \WP_CLI::add_command(
97 - 'activitypub follow',
98 - '\Activitypub\Cli\Follow_Command',
99 - array(
100 - 'shortdesc' => 'Follow a remote ActivityPub user.',
101 - )
102 - );
120 + switch ( $args[0] ) {
121 + case 'delete':
122 + WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[1] );
123 + Comment::schedule_comment_activity( 'trash', 'approved', $comment );
124 + WP_CLI::success( '"Delete" activity is queued.' );
125 + break;
126 + case 'update':
127 + Comment::schedule_comment_activity( 'approved', 'approved', $comment );
128 + WP_CLI::success( '"Update" activity is queued.' );
129 + break;
130 + default:
131 + WP_CLI::error( 'Unknown action.' );
132 + }
133 + }
103 134
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 - );
135 + /**
136 + * Undo an activity that was sent to the Fediverse.
137 + *
138 + * ## OPTIONS
139 + *
140 + * <outbox_item_id>
141 + * The ID or URL of the outbox item to undo.
142 + *
143 + * ## EXAMPLES
144 + *
145 + * $ wp activitypub undo 123
146 + * $ wp activitypub undo "https://example.com/?post_type=ap_outbox&p=123"
147 + *
148 + * @synopsis <outbox_item_id>
149 + *
150 + * @param array $args The arguments.
151 + */
152 + public function undo( $args ) {
153 + $outbox_item_id = $args[0];
154 + if ( ! is_numeric( $outbox_item_id ) ) {
155 + $outbox_item_id = url_to_postid( $outbox_item_id );
156 + }
111 157
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 - );
158 + $outbox_item_id = get_post( $outbox_item_id );
159 + if ( ! $outbox_item_id ) {
160 + WP_CLI::error( 'Activity not found.' );
161 + }
119 162
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 - );
163 + $undo_id = Outbox::undo( $outbox_item_id );
164 + if ( ! $undo_id ) {
165 + WP_CLI::error( 'Failed to undo activity.' );
166 + }
167 + WP_CLI::success( 'Undo activity scheduled.' );
168 + }
127 169
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 - );
170 + /**
171 + * Re-Schedule an activity that was sent to the Fediverse before.
172 + *
173 + * ## OPTIONS
174 + *
175 + * <outbox_item_id>
176 + * The ID or URL of the outbox item to reschedule.
177 + *
178 + * ## EXAMPLES
179 + *
180 + * $ wp activitypub reschedule 123
181 + * $ wp activitypub reschedule "https://example.com/?post_type=ap_outbox&p=123"
182 + *
183 + * @synopsis <outbox_item_id>
184 + *
185 + * @param array $args The arguments.
186 + */
187 + public function reschedule( $args ) {
188 + $outbox_item_id = $args[0];
189 + if ( ! is_numeric( $outbox_item_id ) ) {
190 + $outbox_item_id = url_to_postid( $outbox_item_id );
191 + }
192 +
193 + $outbox_item_id = get_post( $outbox_item_id );
194 + if ( ! $outbox_item_id ) {
195 + WP_CLI::error( 'Activity not found.' );
196 + }
197 +
198 + Outbox::reschedule( $outbox_item_id );
199 +
200 + WP_CLI::success( 'Rescheduled activity.' );
135 201 }
136 202 }