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 +171 -118 9.2.15.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,144 +6,197 @@
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;
11 +use Activitypub\Scheduler\Comment;
12 +use Activitypub\Scheduler\Post;
13 +use WP_CLI;
14 +use WP_CLI_Command;
22 15
23 16 /**
24 - * ActivityPub CLI command registry.
17 + * WP-CLI commands.
25 18 *
26 - * Registers all ActivityPub CLI subcommands with WP-CLI.
27 - *
28 19 * @package Activitypub
29 20 */
30 -class Cli {
21 +class Cli extends WP_CLI_Command {
31 22
32 23 /**
33 - * Register all ActivityPub CLI commands.
24 + * Remove the entire blog from the Fediverse.
34 25 *
35 - * This method registers the main 'activitypub' command namespace and all its
36 - * subcommands for managing ActivityPub functionality via WP-CLI.
26 + * ## EXAMPLES
37 27 *
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]
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
50 34 */
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 - );
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 + }
60 38
61 - \WP_CLI::add_command(
62 - 'activitypub post',
63 - Post_Command::class,
64 - array(
65 - 'shortdesc' => 'Manage ActivityPub posts (delete or update).',
66 - )
67 - );
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] );
68 65
69 - \WP_CLI::add_command(
70 - 'activitypub comment',
71 - Comment_Command::class,
72 - array(
73 - 'shortdesc' => 'Manage ActivityPub comments (delete or update).',
74 - )
75 - );
66 + if ( ! $post ) {
67 + WP_CLI::error( 'Post not found.' );
68 + }
76 69
77 - \WP_CLI::add_command(
78 - 'activitypub actor',
79 - Actor_Command::class,
80 - array(
81 - 'shortdesc' => 'Manage ActivityPub actors (delete or update).',
82 - )
83 - );
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 + }
84 84
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 - );
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] );
92 111
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 - );
112 + if ( ! $comment ) {
113 + WP_CLI::error( 'Comment not found.' );
114 + }
100 115
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 - );
116 + if ( was_comment_received( $comment ) ) {
117 + WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
118 + }
108 119
109 - \WP_CLI::add_command(
110 - 'activitypub follow',
111 - Follow_Command::class,
112 - array(
113 - 'shortdesc' => 'Follow a remote ActivityPub user.',
114 - )
115 - );
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 + }
116 134
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 - );
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 + }
124 157
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 - );
158 + $outbox_item_id = get_post( $outbox_item_id );
159 + if ( ! $outbox_item_id ) {
160 + WP_CLI::error( 'Activity not found.' );
161 + }
132 162
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 - );
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 + }
140 169
141 - \WP_CLI::add_command(
142 - 'activitypub blurhash',
143 - Blurhash_Command::class,
144 - array(
145 - 'shortdesc' => 'Backfill Blurhash placeholders for image attachments.',
146 - )
147 - );
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.' );
148 201 }
149 202 }