PluginProbe
ActivityPub / 5.9.0
ActivityPub v5.9.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
activitypub / includes / class-cli.php

class-cli.php in ActivityPub 5.9.0, at includes/class-cli.php

231 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP-CLI file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub;
9
10 use Activitypub\Collection\Outbox;
11
12 /**
13 * WP-CLI commands.
14 *
15 * @package Activitypub
16 */
17 class Cli extends \WP_CLI_Command {
18
19 /**
20 * Remove the entire blog from the Fediverse.
21 *
22 * ## EXAMPLES
23 *
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
30 */
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 }
34
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] );
61
62 if ( ! $post ) {
63 \WP_CLI::error( 'Post not found.' );
64 }
65
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 }
80
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] );
107
108 if ( ! $comment ) {
109 \WP_CLI::error( 'Comment not found.' );
110 }
111
112 if ( was_comment_received( $comment ) ) {
113 \WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
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 }
130
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 }
153
154 $outbox_item_id = get_post( $outbox_item_id );
155 if ( ! $outbox_item_id ) {
156 \WP_CLI::error( 'Activity not found.' );
157 }
158
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 }
229 }
230 }
231