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 +201 -98 8.3.05.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,122 +6,225 @@
6 6 */
7 7
8 8 namespace Activitypub;
9 9
10 +use Activitypub\Collection\Outbox;
11 +
10 12 /**
11 - * ActivityPub CLI command registry.
13 + * WP-CLI commands.
12 14 *
13 - * Registers all ActivityPub CLI subcommands with WP-CLI.
14 - *
15 15 * @package Activitypub
16 16 */
17 -class Cli {
17 +class Cli extends \WP_CLI_Command {
18 18
19 19 /**
20 - * Register all ActivityPub CLI commands.
20 + * Remove the entire blog from the Fediverse.
21 21 *
22 - * This method registers the main 'activitypub' command namespace and all its
23 - * subcommands for managing ActivityPub functionality via WP-CLI.
22 + * ## EXAMPLES
24 23 *
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>
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
36 30 */
37 - public static function register() {
38 - // Register parent command with version subcommand.
39 - \WP_CLI::add_command(
40 - 'activitypub',
41 - '\Activitypub\Cli\Command',
42 - array(
43 - 'shortdesc' => 'Manage ActivityPub plugin functionality and federation.',
44 - )
45 - );
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 + }
46 34
47 - \WP_CLI::add_command(
48 - 'activitypub post',
49 - '\Activitypub\Cli\Post_Command',
50 - array(
51 - 'shortdesc' => 'Manage ActivityPub posts (delete or update).',
52 - )
53 - );
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] );
54 61
55 - \WP_CLI::add_command(
56 - 'activitypub comment',
57 - '\Activitypub\Cli\Comment_Command',
58 - array(
59 - 'shortdesc' => 'Manage ActivityPub comments (delete or update).',
60 - )
61 - );
62 + if ( ! $post ) {
63 + \WP_CLI::error( 'Post not found.' );
64 + }
62 65
63 - \WP_CLI::add_command(
64 - 'activitypub actor',
65 - '\Activitypub\Cli\Actor_Command',
66 - array(
67 - 'shortdesc' => 'Manage ActivityPub actors (delete or update).',
68 - )
69 - );
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 + }
70 80
71 - \WP_CLI::add_command(
72 - 'activitypub outbox',
73 - '\Activitypub\Cli\Outbox_Command',
74 - array(
75 - 'shortdesc' => 'Manage ActivityPub outbox items (undo or reschedule).',
76 - )
77 - );
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] );
78 107
79 - \WP_CLI::add_command(
80 - 'activitypub self-destruct',
81 - '\Activitypub\Cli\Self_Destruct_Command',
82 - array(
83 - 'shortdesc' => 'Remove the entire blog from the Fediverse.',
84 - )
85 - );
108 + if ( ! $comment ) {
109 + \WP_CLI::error( 'Comment not found.' );
110 + }
86 111
87 - \WP_CLI::add_command(
88 - 'activitypub move',
89 - '\Activitypub\Cli\Move_Command',
90 - array(
91 - 'shortdesc' => 'Move the blog to a new URL.',
92 - )
93 - );
112 + if ( was_comment_received( $comment ) ) {
113 + \WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
114 + }
94 115
95 - \WP_CLI::add_command(
96 - 'activitypub follow',
97 - '\Activitypub\Cli\Follow_Command',
98 - array(
99 - 'shortdesc' => 'Follow a remote ActivityPub user.',
100 - )
101 - );
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 + }
102 130
103 - \WP_CLI::add_command(
104 - 'activitypub cache',
105 - '\Activitypub\Cli\Cache_Command',
106 - array(
107 - 'shortdesc' => 'Manage remote media cache (clear or show status).',
108 - )
109 - );
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 + }
110 153
111 - \WP_CLI::add_command(
112 - 'activitypub fetch',
113 - '\Activitypub\Cli\Fetch_Command',
114 - array(
115 - 'shortdesc' => 'Fetch a remote URL with a signed ActivityPub request.',
116 - )
117 - );
154 + $outbox_item_id = get_post( $outbox_item_id );
155 + if ( ! $outbox_item_id ) {
156 + \WP_CLI::error( 'Activity not found.' );
157 + }
118 158
119 - \WP_CLI::add_command(
120 - 'activitypub stats',
121 - '\Activitypub\Cli\Stats_Command',
122 - array(
123 - 'shortdesc' => 'Manage ActivityPub statistics (collect, compile or send).',
124 - )
125 - );
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 + }
165 +
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 + }
126 229 }
127 230 }