PluginProbe
ActivityPub / 5.5.0
ActivityPub v5.5.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.5.0, at includes/class-cli.php

235 lines 5.1 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 use Activitypub\Scheduler\Comment;
12 use Activitypub\Scheduler\Post;
13 use WP_CLI;
14 use WP_CLI_Command;
15
16 /**
17 * WP-CLI commands.
18 *
19 * @package Activitypub
20 */
21 class Cli extends WP_CLI_Command {
22
23 /**
24 * Remove the entire blog from the Fediverse.
25 *
26 * ## EXAMPLES
27 *
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
34 */
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 }
38
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] );
65
66 if ( ! $post ) {
67 WP_CLI::error( 'Post not found.' );
68 }
69
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
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] );
111
112 if ( ! $comment ) {
113 WP_CLI::error( 'Comment not found.' );
114 }
115
116 if ( was_comment_received( $comment ) ) {
117 WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' );
118 }
119
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 }
134
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 }
157
158 $outbox_item_id = get_post( $outbox_item_id );
159 if ( ! $outbox_item_id ) {
160 WP_CLI::error( 'Activity not found.' );
161 }
162
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 }
169
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.' );
201 }
202
203 /**
204 * Move the blog to a new URL.
205 *
206 * ## OPTIONS
207 *
208 * <from>
209 * The current URL of the blog.
210 *
211 * <to>
212 * The new URL of the blog.
213 *
214 * ## EXAMPLES
215 *
216 * $ wp activitypub move https://example.com/ https://newsite.com/
217 *
218 * @synopsis <from> <to>
219 *
220 * @param array $args The arguments.
221 */
222 public function move( $args ) {
223 $from = $args[0];
224 $to = $args[1];
225
226 $outbox_item_id = Move::account( $from, $to );
227
228 if ( is_wp_error( $outbox_item_id ) ) {
229 WP_CLI::error( $outbox_item_id->get_error_message() );
230 } else {
231 WP_CLI::success( 'Moved Scheduled.' );
232 }
233 }
234 }
235