Skip to content

Commit 3cc821b

Browse files
authored
Refactor remote actor handling to Remote_Actors class (#2151)
1 parent 139a172 commit 3cc821b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1354
-1082
lines changed

build/followers/render.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Activitypub\Blocks;
99
use Activitypub\Collection\Actors;
1010
use Activitypub\Collection\Followers;
11+
use Activitypub\Collection\Remote_Actors;
1112

1213
use function Activitypub\is_activitypub_request;
1314
use function Activitypub\object_to_uri;
@@ -57,7 +58,7 @@
5758
* @return array
5859
*/
5960
function ( $follower ) {
60-
$actor = Actors::get_actor( $follower );
61+
$actor = Remote_Actors::get_actor( $follower );
6162
$username = $actor->get_preferred_username();
6263

6364
return array(

includes/class-activitypub.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Activitypub\Collection\Following;
1515
use Activitypub\Collection\Inbox;
1616
use Activitypub\Collection\Outbox;
17+
use Activitypub\Collection\Remote_Actors;
1718

1819
/**
1920
* ActivityPub Class.
@@ -476,7 +477,7 @@ public static function theme_compat() {
476477
*/
477478
public static function register_post_types() {
478479
\register_post_type(
479-
Actors::POST_TYPE,
480+
Remote_Actors::POST_TYPE,
480481
array(
481482
'labels' => array(
482483
'name' => _x( 'Followers', 'post_type plural name', 'activitypub' ),
@@ -494,7 +495,7 @@ public static function register_post_types() {
494495
);
495496

496497
\register_post_meta(
497-
Actors::POST_TYPE,
498+
Remote_Actors::POST_TYPE,
498499
'_activitypub_inbox',
499500
array(
500501
'type' => 'string',
@@ -504,7 +505,7 @@ public static function register_post_types() {
504505
);
505506

506507
\register_post_meta(
507-
Actors::POST_TYPE,
508+
Remote_Actors::POST_TYPE,
508509
'_activitypub_errors',
509510
array(
510511
'type' => 'string',
@@ -520,7 +521,7 @@ public static function register_post_types() {
520521
);
521522

522523
\register_post_meta(
523-
Actors::POST_TYPE,
524+
Remote_Actors::POST_TYPE,
524525
Followers::FOLLOWER_META_KEY,
525526
array(
526527
'type' => 'string',
@@ -813,7 +814,7 @@ public static function register_post_types() {
813814
*/
814815
public static function register_ap_actor_rest_field() {
815816
\register_rest_field(
816-
Actors::POST_TYPE,
817+
Remote_Actors::POST_TYPE,
817818
'activitypub_json',
818819
array(
819820
/**

includes/class-migration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace Activitypub;
99

10-
use Activitypub\Activity\Actor;
1110
use Activitypub\Collection\Actors;
1211
use Activitypub\Collection\Extra_Fields;
1312
use Activitypub\Collection\Followers;
1413
use Activitypub\Collection\Outbox;
14+
use Activitypub\Collection\Remote_Actors;
1515
use Activitypub\Transformer\Factory;
1616

1717
/**
@@ -502,7 +502,7 @@ public static function migrate_to_4_7_2() {
502502
global $wpdb;
503503
// phpcs:ignore WordPress.DB
504504
$followers = $wpdb->get_col(
505-
$wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", Actors::POST_TYPE )
505+
$wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", Remote_Actors::POST_TYPE )
506506
);
507507
foreach ( $followers as $id ) {
508508
clean_post_cache( $id );
@@ -986,7 +986,7 @@ public static function migrate_followers_to_ap_actor_cpt() {
986986

987987
$wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
988988
$wpdb->posts,
989-
array( 'post_type' => Actors::POST_TYPE ),
989+
array( 'post_type' => Remote_Actors::POST_TYPE ),
990990
array( 'post_type' => 'ap_follower' ),
991991
array( '%s' ),
992992
array( '%s' )

includes/class-sanitize.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Activitypub;
99

10-
use Activitypub\Collection\Actors;
10+
use Activitypub\Collection\Remote_Actors;
1111
use Activitypub\Model\Blog;
1212

1313
/**
@@ -66,7 +66,7 @@ public static function identifier_list( $value ) {
6666
}
6767

6868
$uri = \sanitize_url( $uri );
69-
$actor = Actors::fetch_remote_by_uri( $uri );
69+
$actor = Remote_Actors::fetch_by_uri( $uri );
7070
if ( \is_wp_error( $actor ) ) {
7171
$uris[] = $uri;
7272
} else {

includes/class-scheduler.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Activitypub\Activity\Base_Object;
1212
use Activitypub\Collection\Actors;
1313
use Activitypub\Collection\Outbox;
14+
use Activitypub\Collection\Remote_Actors;
1415
use Activitypub\Scheduler\Actor;
1516
use Activitypub\Scheduler\Comment;
1617
use Activitypub\Scheduler\Post;
@@ -156,19 +157,19 @@ public static function update_remote_actors() {
156157
* @param int $number The number of remote Actors to update.
157158
*/
158159
$number = apply_filters( 'activitypub_update_remote_actors_number', $number );
159-
$actors = Actors::get_outdated( $number );
160+
$actors = Remote_Actors::get_outdated( $number );
160161

161162
foreach ( $actors as $actor ) {
162163
$meta = get_remote_metadata_by_actor( $actor->guid, false );
163164

164165
if ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) {
165-
Actors::add_error( $actor->ID, 'Failed to fetch or parse metadata' );
166+
Remote_Actors::add_error( $actor->ID, 'Failed to fetch or parse metadata' );
166167
} else {
167-
$id = Actors::upsert( $meta );
168+
$id = Remote_Actors::upsert( $meta );
168169
if ( \is_wp_error( $id ) ) {
169170
continue;
170171
}
171-
Actors::clear_errors( $id );
172+
Remote_Actors::clear_errors( $id );
172173
}
173174
}
174175
}
@@ -189,26 +190,26 @@ public static function cleanup_remote_actors() {
189190
* @param int $number The number of remote Actors to clean up.
190191
*/
191192
$number = apply_filters( 'activitypub_cleanup_remote_actors_number', $number );
192-
$actors = Actors::get_faulty( $number );
193+
$actors = Remote_Actors::get_faulty( $number );
193194

194195
foreach ( $actors as $actor ) {
195196
$meta = get_remote_metadata_by_actor( $actor->guid, false );
196197

197198
if ( Tombstone::exists( $meta ) ) {
198199
\wp_delete_post( $actor->ID );
199200
} elseif ( empty( $meta ) || ! is_array( $meta ) || \is_wp_error( $meta ) ) {
200-
if ( Actors::count_errors( $actor->ID ) >= 5 ) {
201+
if ( Remote_Actors::count_errors( $actor->ID ) >= 5 ) {
201202
\wp_schedule_single_event( \time(), 'activitypub_delete_actor_interactions', array( $actor->guid ) );
202203
\wp_delete_post( $actor->ID );
203204
} else {
204-
Actors::add_error( $actor->ID, $meta );
205+
Remote_Actors::add_error( $actor->ID, $meta );
205206
}
206207
} else {
207-
$id = Actors::upsert( $meta );
208+
$id = Remote_Actors::upsert( $meta );
208209
if ( \is_wp_error( $id ) ) {
209-
Actors::add_error( $actor->ID, $id );
210+
Remote_Actors::add_error( $actor->ID, $id );
210211
} else {
211-
Actors::clear_errors( $actor->ID );
212+
Remote_Actors::clear_errors( $actor->ID );
212213
}
213214
}
214215
}

includes/class-signature.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Activitypub;
99

1010
use Activitypub\Collection\Actors;
11+
use Activitypub\Collection\Remote_Actors;
1112
use Activitypub\Signature\Http_Message_Signature;
1213
use Activitypub\Signature\Http_Signature_Draft;
1314

@@ -236,16 +237,16 @@ public static function get_keypair_for( $user_id ) {
236237
/**
237238
* Get public key from key_id.
238239
*
239-
* @deprecated 7.0.0 Use {@see Actors::get_remote_key()}.
240+
* @deprecated unreleased Use {@see Remote_Actors::get_public_key()}.
240241
*
241242
* @param string $key_id The URL to the public key.
242243
*
243244
* @return resource|\WP_Error The public key resource or WP_Error.
244245
*/
245246
public static function get_remote_key( $key_id ) {
246-
\_deprecated_function( __METHOD__, '7.0.0', 'Activitypub\Collection\Actors::get_remote_key()' );
247+
\_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Remote_Actors::get_public_key()' );
247248

248-
return Actors::get_remote_key( $key_id );
249+
return Remote_Actors::get_public_key( $key_id );
249250
}
250251

251252
/**

includes/class-webfinger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Activitypub\Activity\Actor;
1111
use Activitypub\Collection\Actors;
12+
use Activitypub\Collection\Remote_Actors;
1213

1314
/**
1415
* ActivityPub WebFinger Class.
@@ -308,7 +309,7 @@ public static function generate_cache_key( $uri ) {
308309
*/
309310
public static function guess( $actor_or_uri ) {
310311
if ( ! $actor_or_uri instanceof Actor ) {
311-
$actor = Actors::fetch_remote_by_uri( $actor_or_uri );
312+
$actor = Remote_Actors::fetch_by_uri( $actor_or_uri );
312313
if ( \is_wp_error( $actor ) ) {
313314
return extract_name_from_uri( $actor_or_uri ) . '@' . \wp_parse_url( $actor_or_uri, PHP_URL_HOST );
314315
}

0 commit comments

Comments
 (0)