PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.0
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 +199 -118 9.2.25.7.0 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,144 +6,225 @@
6 6 */
7 7
8 8 namespace Activitypub;
9 9
10 -use Activitypub\Cli\Actor_Command;
11 -use Activitypub\Cli\Blurhash_Command;
12 -use Activitypub\Cli\Cache_Command;
13 -use Activitypub\Cli\Command;
14 -use Activitypub\Cli\Comment_Command;
15 -use Activitypub\Cli\Fetch_Command;
16 -use Activitypub\Cli\Follow_Command;
17 -use Activitypub\Cli\Move_Command;
18 -use Activitypub\Cli\Outbox_Command;
19 -use Activitypub\Cli\Post_Command;
20 -use Activitypub\Cli\Self_Destruct_Command;
21 -use Activitypub\Cli\Stats_Command;
10 +use Activitypub\Collection\Outbox;
22 11
23 12 /**
24 - * ActivityPub CLI command registry.
13 + * WP-CLI commands.
25 14 *
26 - * Registers all ActivityPub CLI subcommands with WP-CLI.
27 - *
28 15 * @package Activitypub
29 16 */
30 -class Cli {
17 +class Cli extends \WP_CLI_Command {
31 18
32 19 /**
33 - * Register all ActivityPub CLI commands.
20 + * Remove the entire blog from the Fediverse.
34 21 *
35 - * This method registers the main 'activitypub' command namespace and all its
36 - * subcommands for managing ActivityPub functionality via WP-CLI.
22 + * ## EXAMPLES
37 23 *
38 - * Available commands:
39 - * - wp activitypub post <delete|update> <id>
40 - * - wp activitypub comment <delete|update> <id>
41 - * - wp activitypub actor <delete|update> <id>
42 - * - wp activitypub outbox <undo|reschedule> <id>
43 - * - wp activitypub cache <clear|status> [--type=<type>]
44 - * - wp activitypub self-destruct [--status] [--yes]
45 - * - wp activitypub move <from> <to>
46 - * - wp activitypub follow <remote_user>
47 - * - wp activitypub stats <collect|compile|send>
48 - * - wp activitypub fetch <url>
49 - * - wp activitypub blurhash backfill [--dry-run] [--limit=<n>] [--force]
24 + * $ wp activitypub self-destruct
25 + *
26 + * @param array|null $args The arguments.
27 + * @param array|null $assoc_args The associative arguments.
28 + *
29 + * @return void
50 30 */
51 - public static function register() {
52 - // Register parent command with version subcommand.
53 - \WP_CLI::add_command(
54 - 'activitypub',
55 - Command::class,
56 - array(
57 - 'shortdesc' => 'Manage ActivityPub plugin functionality and federation.',
58 - )
59 - );
31 + public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
32 + \WP_CLI::warning( 'Self-Destructing is not implemented yet.' );
33 + }
60 34
61 - \WP_CLI::add_command(
62 - 'activitypub post',
63 - Post_Command::class,
64 - array(
65 - 'shortdesc' => 'Manage ActivityPub posts (delete or update).',
66 - )
67 - );
35 + /**
36 + * Delete or Update a Post, Page, Custom Post Type or Attachment.
37 + *
38 + * ## OPTIONS
39 + *
40 + * <action>
41 + * : The action to perform. Either `delete` or `update`.
42 + * ---
43 + * options:
44 + * - delete
45 + * - update
46 + * ---
47 + *
48 + * <id>
49 + * : The id of the Post, Page, Custom Post Type or Attachment.
50 + *
51 + * ## EXAMPLES
52 + *
53 + * $ wp activitypub post delete 1
54 + *
55 + * @synopsis <action> <id>
56 + *
57 + * @param array $args The arguments.
58 + */
59 + public function post( $args ) {
60 + $post = get_post( $args[1] );
68 61
69 - \WP_CLI::add_command(
70 - 'activitypub comment',
71 - Comment_Command::class,
72 - array(
73 - 'shortdesc' => 'Manage ActivityPub comments (delete or update).',
74 - )
75 - );
62 + if ( ! $post ) {
63 + \WP_CLI::error( 'Post not found.' );
64 + }
76 65
77 - \WP_CLI::add_command(
78 - 'activitypub actor',
79 - Actor_Command::class,
80 - array(
81 - 'shortdesc' => 'Manage ActivityPub actors (delete or update).',
82 - )
83 - );
66 + switch ( $args[0] ) {
67 + case 'delete':
68 + \WP_CLI::confirm( 'Do you really want to delete the (Custom) Post with the ID: ' . $args[1] );
69 + add_to_outbox( $post, 'Delete', $post->post_author );
70 + \WP_CLI::success( '"Delete" activity is queued.' );
71 + break;
72 + case 'update':
73 + add_to_outbox( $post, 'Update', $post->post_author );
74 + \WP_CLI::success( '"Update" activity is queued.' );
75 + break;
76 + default:
77 + \WP_CLI::error( 'Unknown action.' );
78 + }
79 + }
84 80
85 - \WP_CLI::add_command(
86 - 'activitypub outbox',
87 - Outbox_Command::class,
88 - array(
89 - 'shortdesc' => 'Manage ActivityPub outbox items (undo or reschedule).',
90 - )
91 - );
81 + /**
82 + * Delete or Update a Comment.
83 + *
84 + * ## OPTIONS
85 + *
86 + * <action>
87 + * : The action to perform. Either `delete` or `update`.
88 + * ---
89 + * options:
90 + * - delete
91 + * - update
92 + * ---
93 + *
94 + * <id>
95 + * : The id of the Comment.
96 + *
97 + * ## EXAMPLES
98 + *
99 + * $ wp activitypub comment delete 1
100 + *
101 + * @synopsis <action> <id>
102 + *
103 + * @param array $args The arguments.
104 + */
105 + public function comment( $args ) {
106 + $comment = get_comment( $args[1] );
92 107
93 - \WP_CLI::add_command(
94 - 'activitypub self-destruct',
95 - Self_Destruct_Command::class,
96 - array(
97 - 'shortdesc' => 'Remove the entire blog from the Fediverse.',
98 - )
99 - );
108 + if ( ! $comment ) {
109 + \WP_CLI::error( 'Comment not found.' );
110 + }
100 111
101 - \WP_CLI::add_command(
102 - 'activitypub move',
103 - Move_Command::class,
104 - array(
105 - 'shortdesc' => 'Move the blog to a new URL.',
106 - )
107 - );
112 + if ( was_comment_received( $comment ) ) {
113 + \WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
114 + }
108 115
109 - \WP_CLI::add_command(
110 - 'activitypub follow',
111 - Follow_Command::class,
112 - array(
113 - 'shortdesc' => 'Follow a remote ActivityPub user.',
114 - )
115 - );
116 + switch ( $args[0] ) {
117 + case 'delete':
118 + \WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[1] );
119 + add_to_outbox( $comment, 'Delete', $comment->user_id );
120 + \WP_CLI::success( '"Delete" activity is queued.' );
121 + break;
122 + case 'update':
123 + add_to_outbox( $comment, 'Update', $comment->user_id );
124 + \WP_CLI::success( '"Update" activity is queued.' );
125 + break;
126 + default:
127 + \WP_CLI::error( 'Unknown action.' );
128 + }
129 + }
116 130
117 - \WP_CLI::add_command(
118 - 'activitypub cache',
119 - Cache_Command::class,
120 - array(
121 - 'shortdesc' => 'Manage remote media cache (clear or show status).',
122 - )
123 - );
131 + /**
132 + * Undo an activity that was sent to the Fediverse.
133 + *
134 + * ## OPTIONS
135 + *
136 + * <outbox_item_id>
137 + * The ID or URL of the outbox item to undo.
138 + *
139 + * ## EXAMPLES
140 + *
141 + * $ wp activitypub undo 123
142 + * $ wp activitypub undo "https://example.com/?post_type=ap_outbox&p=123"
143 + *
144 + * @synopsis <outbox_item_id>
145 + *
146 + * @param array $args The arguments.
147 + */
148 + public function undo( $args ) {
149 + $outbox_item_id = $args[0];
150 + if ( ! is_numeric( $outbox_item_id ) ) {
151 + $outbox_item_id = url_to_postid( $outbox_item_id );
152 + }
124 153
125 - \WP_CLI::add_command(
126 - 'activitypub fetch',
127 - Fetch_Command::class,
128 - array(
129 - 'shortdesc' => 'Fetch a remote URL with a signed ActivityPub request.',
130 - )
131 - );
154 + $outbox_item_id = get_post( $outbox_item_id );
155 + if ( ! $outbox_item_id ) {
156 + \WP_CLI::error( 'Activity not found.' );
157 + }
132 158
133 - \WP_CLI::add_command(
134 - 'activitypub stats',
135 - Stats_Command::class,
136 - array(
137 - 'shortdesc' => 'Manage ActivityPub statistics (collect, compile or send).',
138 - )
139 - );
159 + $undo_id = Outbox::undo( $outbox_item_id );
160 + if ( ! $undo_id ) {
161 + \WP_CLI::error( 'Failed to undo activity.' );
162 + }
163 + \WP_CLI::success( 'Undo activity scheduled.' );
164 + }
140 165
141 - \WP_CLI::add_command(
142 - 'activitypub blurhash',
143 - Blurhash_Command::class,
144 - array(
145 - 'shortdesc' => 'Backfill Blurhash placeholders for image attachments.',
146 - )
147 - );
166 + /**
167 + * Re-Schedule an activity that was sent to the Fediverse before.
168 + *
169 + * ## OPTIONS
170 + *
171 + * <outbox_item_id>
172 + * The ID or URL of the outbox item to reschedule.
173 + *
174 + * ## EXAMPLES
175 + *
176 + * $ wp activitypub reschedule 123
177 + * $ wp activitypub reschedule "https://example.com/?post_type=ap_outbox&p=123"
178 + *
179 + * @synopsis <outbox_item_id>
180 + *
181 + * @param array $args The arguments.
182 + */
183 + public function reschedule( $args ) {
184 + $outbox_item_id = $args[0];
185 + if ( ! is_numeric( $outbox_item_id ) ) {
186 + $outbox_item_id = url_to_postid( $outbox_item_id );
187 + }
188 +
189 + $outbox_item_id = get_post( $outbox_item_id );
190 + if ( ! $outbox_item_id ) {
191 + \WP_CLI::error( 'Activity not found.' );
192 + }
193 +
194 + Outbox::reschedule( $outbox_item_id );
195 +
196 + \WP_CLI::success( 'Rescheduled activity.' );
197 + }
198 +
199 + /**
200 + * Move the blog to a new URL.
201 + *
202 + * ## OPTIONS
203 + *
204 + * <from>
205 + * The current URL of the blog.
206 + *
207 + * <to>
208 + * The new URL of the blog.
209 + *
210 + * ## EXAMPLES
211 + *
212 + * $ wp activitypub move https://example.com/ https://newsite.com/
213 + *
214 + * @synopsis <from> <to>
215 + *
216 + * @param array $args The arguments.
217 + */
218 + public function move( $args ) {
219 + $from = $args[0];
220 + $to = $args[1];
221 +
222 + $outbox_item_id = Move::account( $from, $to );
223 +
224 + if ( is_wp_error( $outbox_item_id ) ) {
225 + \WP_CLI::error( $outbox_item_id->get_error_message() );
226 + } else {
227 + \WP_CLI::success( 'Move Scheduled.' );
228 + }
148 229 }
149 230 }