Skip to content

Commit

Permalink
fix(backfill): disregard current_page_url user metadata for reader_re…
Browse files Browse the repository at this point in the history
…gistration events
  • Loading branch information
adekbadek committed Feb 27, 2024
1 parent c44783d commit 58d0fba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions includes/cli/backfillers/class-reader-registered.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public function get_events() {

$events = [];

// Disregard `current_page_url` metadata when checking for duplicates of reader registrations.
// This metadata is unavailable for backfilled events, so it's not possible to check for duplicates with it.
add_filter(
'newspack_network_event_log_get_args',
function( $args ) {
if ( $args['action_name'] === 'reader_registered' && isset( $args['data'] ) ) {
$data = json_decode( $args['data'], true );
if ( isset( $data['metadata']['current_page_url'] ) ) {
unset( $data['metadata']['current_page_url'] );
}
$args['data'] = wp_json_encode( $data );
}
return $args;
}
);

foreach ( $users as $user ) {
$registration_method = get_user_meta( $user->ID, \Newspack\Reader_Activation::REGISTRATION_METHOD, true );
$user_data = [
Expand Down
1 change: 1 addition & 0 deletions includes/hub/stores/class-event-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function get( $args, $per_page = 10, $page = 1, $order = 'DESC' )

$query = $wpdb->prepare( "SELECT * FROM $table_name WHERE 1=1 [args] $order_string LIMIT %d OFFSET %d", $per_page, $offset ); //phpcs:ignore

$args = apply_filters( 'newspack_network_event_log_get_args', $args );
$query = str_replace( '[args]', self::build_where_clause( $args ), $query );

$db = $wpdb->get_results( $query ); //phpcs:ignore
Expand Down

0 comments on commit 58d0fba

Please sign in to comment.