| 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 |
|