PluginProbe
ActivityPub / 8.0.1
ActivityPub v8.0.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
activitypub / includes / cli / class-outbox-command.php

class-outbox-command.php in ActivityPub 8.0.1, at includes/cli/class-outbox-command.php

101 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Outbox CLI Command.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Cli;
9
10 use Activitypub\Collection\Outbox;
11
12 /**
13 * Manage ActivityPub outbox items.
14 *
15 * @package Activitypub
16 */
17 class Outbox_Command extends \WP_CLI_Command {
18
19 /**
20 * Undo an activity that was sent to the Fediverse.
21 *
22 * Creates an Undo activity for a previously sent activity, effectively
23 * reversing its effect on federated instances.
24 *
25 * ## OPTIONS
26 *
27 * <id>
28 * : The ID or URL of the outbox item to undo.
29 *
30 * ## EXAMPLES
31 *
32 * # Undo outbox item by ID
33 * $ wp activitypub outbox undo 123
34 *
35 * # Undo outbox item by URL
36 * $ wp activitypub outbox undo "https://example.com/?post_type=ap_outbox&p=123"
37 *
38 * @subcommand undo
39 *
40 * @param array $args The positional arguments.
41 * @param array $assoc_args The associative arguments (unused).
42 */
43 public function undo( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44 $outbox_item_id = $args[0];
45 if ( ! is_numeric( $outbox_item_id ) ) {
46 $outbox_item_id = \url_to_postid( $outbox_item_id );
47 }
48
49 $outbox_item = \get_post( $outbox_item_id );
50 if ( ! $outbox_item ) {
51 \WP_CLI::error( 'Activity not found.' );
52 }
53
54 $undo_id = Outbox::undo( $outbox_item );
55 if ( ! $undo_id ) {
56 \WP_CLI::error( 'Failed to undo activity.' );
57 }
58 \WP_CLI::success( 'Undo activity scheduled.' );
59 }
60
61 /**
62 * Re-schedule an activity that was sent to the Fediverse before.
63 *
64 * Useful for retrying failed deliveries or resending activities to
65 * followers.
66 *
67 * ## OPTIONS
68 *
69 * <id>
70 * : The ID or URL of the outbox item to reschedule.
71 *
72 * ## EXAMPLES
73 *
74 * # Reschedule outbox item by ID
75 * $ wp activitypub outbox reschedule 123
76 *
77 * # Reschedule outbox item by URL
78 * $ wp activitypub outbox reschedule "https://example.com/?post_type=ap_outbox&p=123"
79 *
80 * @subcommand reschedule
81 *
82 * @param array $args The positional arguments.
83 * @param array $assoc_args The associative arguments (unused).
84 */
85 public function reschedule( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
86 $outbox_item_id = $args[0];
87 if ( ! is_numeric( $outbox_item_id ) ) {
88 $outbox_item_id = \url_to_postid( $outbox_item_id );
89 }
90
91 $outbox_item = \get_post( $outbox_item_id );
92 if ( ! $outbox_item ) {
93 \WP_CLI::error( 'Activity not found.' );
94 }
95
96 Outbox::reschedule( $outbox_item );
97
98 \WP_CLI::success( 'Rescheduled activity.' );
99 }
100 }
101