Skip to content

Commit

Permalink
Fix pulling of reader_registered
Browse files Browse the repository at this point in the history
  • Loading branch information
leogermani committed Jun 2, 2023
1 parent e8f48a5 commit 2e431b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions includes/hub/class-pull-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public static function handle_pull( $request ) {
],
2
);

Debugger::log( count( $events ) . ' events found' );

$response_body = array_map(
function( $event ) {
Expand Down
8 changes: 4 additions & 4 deletions includes/incoming-events/class-abstract-incoming-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ abstract class Abstract_Incoming_Event {
/**
* Constructs a new Incoming Event
*
* @param string $site The origin site URL.
* @param array $data The data for this event.
* @param int $timestamp The timestamp for this event.
* @param string $site The origin site URL.
* @param array|object $data The data for this event.
* @param int $timestamp The timestamp for this event.
*/
public function __construct( $site, $data, $timestamp ) {
$this->site = $site;
$this->data = $data;
$this->data = (object) $data;
$this->timestamp = $timestamp;
}

Expand Down
6 changes: 6 additions & 0 deletions includes/incoming-events/class-reader-registered.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Newspack_Network\Incoming_Events;

use Newspack_Network\Debugger;
use Newspack_Network\Hub\Node;
use Newspack_Network\Hub\Stores\Event_Log;

Expand All @@ -22,12 +23,14 @@ class Reader_Registered extends Abstract_Incoming_Event {
*/
public function post_process() {
$email = $this->get_email();
Debugger::log( 'Processing reader_registered with email: ' . $email );
if ( ! $email ) {
return;
}
$existing_user = get_user_by( 'email', $email );

if ( $existing_user ) {
Debugger::log( 'User already exists' );
return;
}

Expand All @@ -41,9 +44,12 @@ public function post_process() {
);

if ( is_wp_error( $user_id ) ) {
Debugger::log( 'Error creating user: ' . $user_id->get_error_message() );
return $user_id;
}

Debugger::log( 'User created with ID: ' . $user_id );

add_user_meta( $user_id, 'newspack_remote_site', $this->get_site() );
add_user_meta( $user_id, 'newspack_remote_id', $this->data->user_id ?? '' );

Expand Down

0 comments on commit 2e431b4

Please sign in to comment.