current_time( 'mysql', true ), 'message' => $message ] ); } /** Remember when Scholar was last fetched completely (queue order of the next full sync). */ public static function mark_scholar_synced( int $member_id ): void { update_post_meta( $member_id, self::SYNCED_META, time() ); } /** @return array{at:string,message:string}|null */ public static function scholar_error( int $member_id ): ?array { $err = get_post_meta( $member_id, self::ERROR_META, true ); return ( is_array( $err ) && ! empty( $err['message'] ) ) ? $err : null; } /** Recompute the publication count; drop a citation figure that isn't Scholar's. */ public static function refresh( int $member_id ): void { global $wpdb; $rel_table = $wpdb->prefix . 'academiccrew_member_publications'; $pub_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$rel_table} WHERE member_id = %d", $member_id ) ); update_post_meta( $member_id, '_acc_pub_count', $pub_count ); // Keep the last Scholar figures (a failed fetch must not blank them), but // only while the member still has a Scholar profile. if ( '' === (string) get_post_meta( $member_id, '_acc_scholar_id', true ) ) { self::clear_citations( $member_id ); delete_post_meta( $member_id, '_acc_h_index' ); delete_post_meta( $member_id, self::ERROR_META ); } elseif ( self::SOURCE_SCHOLAR !== get_post_meta( $member_id, '_acc_citation_source', true ) ) { self::clear_citations( $member_id ); } } public static function clear_citations( int $member_id ): void { delete_post_meta( $member_id, '_acc_citation_count' ); delete_post_meta( $member_id, '_acc_citation_source' ); } /** Store the Scholar profile totals (ignored when Scholar returned nothing). */ public static function set_scholar( int $member_id, int $citations, int $h_index ): void { if ( $citations > 0 ) { update_post_meta( $member_id, '_acc_citation_count', $citations ); update_post_meta( $member_id, '_acc_citation_source', self::SOURCE_SCHOLAR ); } if ( $h_index > 0 ) { update_post_meta( $member_id, '_acc_h_index', $h_index ); } } /** Where the citation total links to, or '' when it is a local sum. */ public static function citation_url( int $member_id ): string { $scholar_id = (string) get_post_meta( $member_id, '_acc_scholar_id', true ); if ( $scholar_id === '' || self::SOURCE_SCHOLAR !== get_post_meta( $member_id, '_acc_citation_source', true ) ) { return ''; } return 'https://scholar.google.com/citations?user=' . rawurlencode( $scholar_id ) . '&hl=en'; } }