| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP-CLI file. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub; |
| 9 |
|
| 10 |
use WP_CLI; |
| 11 |
use WP_CLI_Command; |
| 12 |
use Activitypub\Scheduler\Post; |
| 13 |
use Activitypub\Scheduler\Comment; |
| 14 |
|
| 15 |
/** |
| 16 |
* WP-CLI commands. |
| 17 |
* |
| 18 |
* @package Activitypub |
| 19 |
*/ |
| 20 |
class Cli extends WP_CLI_Command { |
| 21 |
|
| 22 |
/** |
| 23 |
* Remove the entire blog from the Fediverse. |
| 24 |
* |
| 25 |
* ## EXAMPLES |
| 26 |
* |
| 27 |
* $ wp activitypub self-destruct |
| 28 |
* |
| 29 |
* @param array|null $args The arguments. |
| 30 |
* @param array|null $assoc_args The associative arguments. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function self_destruct( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 35 |
WP_CLI::warning( 'Self-Destructing is not implemented yet.' ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Delete or Update a Post, Page, Custom Post Type or Attachment. |
| 40 |
* |
| 41 |
* ## OPTIONS |
| 42 |
* |
| 43 |
* <action> |
| 44 |
* : The action to perform. Either `delete` or `update`. |
| 45 |
* --- |
| 46 |
* options: |
| 47 |
* - delete |
| 48 |
* - update |
| 49 |
* --- |
| 50 |
* |
| 51 |
* <id> |
| 52 |
* : The id of the Post, Page, Custom Post Type or Attachment. |
| 53 |
* |
| 54 |
* ## EXAMPLES |
| 55 |
* |
| 56 |
* $ wp activitypub post delete 1 |
| 57 |
* |
| 58 |
* @synopsis <action> <id> |
| 59 |
* |
| 60 |
* @param array $args The arguments. |
| 61 |
*/ |
| 62 |
public function post( $args ) { |
| 63 |
$post = get_post( $args[1] ); |
| 64 |
|
| 65 |
if ( ! $post ) { |
| 66 |
WP_CLI::error( 'Post not found.' ); |
| 67 |
} |
| 68 |
|
| 69 |
switch ( $args[0] ) { |
| 70 |
case 'delete': |
| 71 |
WP_CLI::confirm( 'Do you really want to delete the (Custom) Post with the ID: ' . $args[1] ); |
| 72 |
Post::schedule_post_activity( 'trash', 'publish', $post ); |
| 73 |
WP_CLI::success( '"Delete" activity is queued.' ); |
| 74 |
break; |
| 75 |
case 'update': |
| 76 |
Post::schedule_post_activity( 'publish', 'publish', $post ); |
| 77 |
WP_CLI::success( '"Update" activity is queued.' ); |
| 78 |
break; |
| 79 |
default: |
| 80 |
WP_CLI::error( 'Unknown action.' ); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Delete or Update a Comment. |
| 86 |
* |
| 87 |
* ## OPTIONS |
| 88 |
* |
| 89 |
* <action> |
| 90 |
* : The action to perform. Either `delete` or `update`. |
| 91 |
* --- |
| 92 |
* options: |
| 93 |
* - delete |
| 94 |
* - update |
| 95 |
* --- |
| 96 |
* |
| 97 |
* <id> |
| 98 |
* : The id of the Comment. |
| 99 |
* |
| 100 |
* ## EXAMPLES |
| 101 |
* |
| 102 |
* $ wp activitypub comment delete 1 |
| 103 |
* |
| 104 |
* @synopsis <action> <id> |
| 105 |
* |
| 106 |
* @param array $args The arguments. |
| 107 |
*/ |
| 108 |
public function comment( $args ) { |
| 109 |
$comment = get_comment( $args[1] ); |
| 110 |
|
| 111 |
if ( ! $comment ) { |
| 112 |
WP_CLI::error( 'Comment not found.' ); |
| 113 |
} |
| 114 |
|
| 115 |
if ( was_comment_received( $comment ) ) { |
| 116 |
WP_CLI::error( 'This comment was received via ActivityPub and cannot be deleted or updated.' ); |
| 117 |
} |
| 118 |
|
| 119 |
switch ( $args[0] ) { |
| 120 |
case 'delete': |
| 121 |
WP_CLI::confirm( 'Do you really want to delete the Comment with the ID: ' . $args[1] ); |
| 122 |
Comment::schedule_comment_activity( 'trash', 'approved', $comment ); |
| 123 |
WP_CLI::success( '"Delete" activity is queued.' ); |
| 124 |
break; |
| 125 |
case 'update': |
| 126 |
Comment::schedule_comment_activity( 'approved', 'approved', $comment ); |
| 127 |
WP_CLI::success( '"Update" activity is queued.' ); |
| 128 |
break; |
| 129 |
default: |
| 130 |
WP_CLI::error( 'Unknown action.' ); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|