Fix parser, to schedule using Event_Source object directly, not it's ID.
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 47s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 58s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 57s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 53s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 57s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 55s
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 47s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 58s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 57s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 53s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 57s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 55s
This commit is contained in:
parent
f225db0f1e
commit
1c5f428289
2 changed files with 31 additions and 33 deletions
|
@ -50,24 +50,24 @@ class Outbox_Parser {
|
|||
}
|
||||
|
||||
// Schedule the import of events via the outbox.
|
||||
return self::queue_importing_from_outbox( $outbox_url, $event_source->get_id(), 0 );
|
||||
return self::queue_importing_from_outbox( $outbox_url, $event_source, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import events from an outbox: OrderedCollection or OrderedCollectionPage.
|
||||
*
|
||||
* @param string $url The url of the current page or outbox.
|
||||
* @param string $actor The ActivityPub ID/URL of the actor that owns the outbox.
|
||||
* @param string $url The url of the current page or outbox.
|
||||
* @param Event_Source $event_source The event source that the outbox belongs to.
|
||||
* @return void
|
||||
*/
|
||||
public static function import_events_from_outbox( $url, $actor ) {
|
||||
public static function import_events_from_outbox( $url, $event_source ) {
|
||||
$outbox = self::fetch_outbox( $url );
|
||||
|
||||
if ( ! $outbox ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_count = self::get_import_count( $actor );
|
||||
$current_count = self::get_import_count( $event_source );
|
||||
|
||||
if ( $current_count >= self::MAX_EVENTS_TO_IMPORT ) {
|
||||
return;
|
||||
|
@ -77,12 +77,12 @@ class Outbox_Parser {
|
|||
if ( isset( $outbox['orderedItems'] ) && is_array( $outbox['orderedItems'] ) ) {
|
||||
$current_count += self::import_events_from_items(
|
||||
$outbox['orderedItems'],
|
||||
$actor,
|
||||
$event_source,
|
||||
self::MAX_EVENTS_TO_IMPORT - $current_count
|
||||
);
|
||||
}
|
||||
|
||||
self::update_import_count( $actor, $current_count );
|
||||
self::update_import_count( $event_source, $current_count );
|
||||
|
||||
// If the count is already exceeded abort here.
|
||||
if ( $current_count >= self::MAX_EVENTS_TO_IMPORT ) {
|
||||
|
@ -93,7 +93,7 @@ class Outbox_Parser {
|
|||
$pagination_url = self::get_pagination_url( $outbox );
|
||||
|
||||
if ( $pagination_url ) {
|
||||
self::queue_importing_from_outbox( $pagination_url, $actor );
|
||||
self::queue_importing_from_outbox( $pagination_url, $event_source );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ class Outbox_Parser {
|
|||
* @param int $max_items The maximum number of items to parse.
|
||||
* @return array Parsed events from the collection.
|
||||
*/
|
||||
private static function parse_items_for_events( $items, $max_items ) {
|
||||
private static function parse_outbox_items_for_events( $items, $max_items ) {
|
||||
$parsed_events = array();
|
||||
|
||||
foreach ( $items as $activity ) {
|
||||
|
@ -157,13 +157,13 @@ class Outbox_Parser {
|
|||
/**
|
||||
* Import events from the items of an outbox.
|
||||
*
|
||||
* @param array $items The items/orderedItems as an associative array.
|
||||
* @param string $actor The actor that owns the items.
|
||||
* @param int $limit The limit of how many events to save locally.
|
||||
* @param array $items The items/orderedItems as an associative array.
|
||||
* @param Event_Source $event_source The Event Source the items belong to.
|
||||
* @param int $limit The limit of how many events to save locally.
|
||||
* @return int The number of saved events (at least attempted).
|
||||
*/
|
||||
private static function import_events_from_items( $items, $actor, $limit = -1 ) {
|
||||
$events = self::parse_items_for_events( $items, $limit );
|
||||
private static function import_events_from_items( $items, $event_source, $limit = -1 ) {
|
||||
$events = self::parse_outbox_items_for_events( $items, $limit );
|
||||
|
||||
$transmogrifier = Setup::get_transmogrifier();
|
||||
|
||||
|
@ -174,7 +174,7 @@ class Outbox_Parser {
|
|||
$imported_count = 0;
|
||||
|
||||
foreach ( $events as $event ) {
|
||||
$transmogrifier->save( $event, $actor );
|
||||
$transmogrifier->save( $event, $event_source );
|
||||
++$imported_count;
|
||||
if ( $limit > 0 && $imported_count >= $limit ) {
|
||||
break;
|
||||
|
@ -187,14 +187,14 @@ class Outbox_Parser {
|
|||
/**
|
||||
* Schedule the import of events from an outbox OrderedCollection or OrderedCollectionPage.
|
||||
*
|
||||
* @param string $url The url of the current page or outbox.
|
||||
* @param string $actor The ActivityPub ID/URL of the actor that owns the outbox.
|
||||
* @param int $delay The delay of the current time in seconds.
|
||||
* @param string $url The url of the current page or outbox.
|
||||
* @param Event_Source $event_source The Event Source that owns the outbox.
|
||||
* @param int $delay The delay of the current time in seconds.
|
||||
* @return void
|
||||
*/
|
||||
private static function queue_importing_from_outbox( $url, $actor, $delay = 10 ) {
|
||||
private static function queue_importing_from_outbox( $url, $event_source, $delay = 10 ) {
|
||||
$hook = 'event_bridge_for_activitypub_import_events_from_outbox';
|
||||
$args = array( $url, $actor );
|
||||
$args = array( $url, $event_source );
|
||||
|
||||
if ( \wp_next_scheduled( $hook, $args ) ) {
|
||||
return;
|
||||
|
@ -206,24 +206,22 @@ class Outbox_Parser {
|
|||
/**
|
||||
* Get the current import count for the actor.
|
||||
*
|
||||
* @param string $actor The actor's ID/URL.
|
||||
* @param Event_Source $event_source The event source.
|
||||
* @return int The current count of imported events.
|
||||
*/
|
||||
private static function get_import_count( $actor ) {
|
||||
$post_id = Event_Source::get_by_id( $actor )->ID;
|
||||
return (int) \get_post_meta( $post_id, '_event_bridge_for_activitypub_event_count', true );
|
||||
private static function get_import_count( $event_source ) {
|
||||
return (int) \get_post_meta( $event_source->get__id(), '_event_bridge_for_activitypub_event_count', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the import count for the actor.
|
||||
* Update the import count for an event source..
|
||||
*
|
||||
* @param string $actor The actor's ID/URL.
|
||||
* @param int $count The new count of imported events.
|
||||
* @param Event_Source $event_source The event source.
|
||||
* @param int $count The new count of imported events.
|
||||
* @return void
|
||||
*/
|
||||
private static function update_import_count( $actor, $count ) {
|
||||
$post_id = Event_Source::get_by_id( $actor )->ID;
|
||||
\update_post_meta( $post_id, '_event_bridge_for_activitypub_event_count', $count );
|
||||
private static function update_import_count( $event_source, $count ) {
|
||||
\update_post_meta( $event_source->get__id(), '_event_bridge_for_activitypub_event_count', $count );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -139,10 +139,10 @@ class Test_Outbox_Parser extends \WP_UnitTestCase {
|
|||
// The function we want to test is private, so we need a Reflection class.
|
||||
$reflection = new \ReflectionClass( \Event_Bridge_For_ActivityPub\Outbox_Parser::class );
|
||||
|
||||
$method = $reflection->getMethod( 'import_events_from_items' );
|
||||
$method->setAccessible( true );
|
||||
$method = $reflection->getMethod( 'import_events_from_items' );
|
||||
$method->setAccessible( true );
|
||||
|
||||
$count = $method->invoke( null, $items, 'https://remote.example/@organizer' );
|
||||
$count = $method->invoke( null, $items, 'https://remote.example/@organizer' );
|
||||
|
||||
$this->assertEquals( 2, $count );
|
||||
|
||||
|
|
Loading…
Reference in a new issue