prefix . 'avc_page_visit_history'; $user_locations = $wpdb->prefix . 'apvc_user_locations'; $old_records = $wpdb->get_results( 'SELECT * FROM '.$history_table.' LEFT JOIN '.$user_locations.' ON '.$history_table.'.id = '.$user_locations.'.ent_id' ); $data = array(); $index = 0; foreach( $old_records as $record ){ $data[$index]['rawData']['type'] = 'singular'; $data[$index]['rawData']['singular_id'] = absint( $record->article_id ); $data[$index]['rawData']['author_id'] = get_post_field( 'post_author', $record->article_id ); $data[$index]['user_device']['device_type'] = $record->device_type; $data[$index]['user_device']['device_os'] = $record->operating_system; $data[$index]['user_device']['device_browser'] = $record->browser_full_name; $data[$index]['user_device']['device_browser_ver'] = $record->browser_version; $data[$index]['referrer_url'] = $record->http_referer; $data[$index]['ip_address'] = $record->ip_address; $data[$index]['user_agent'] = $record->browser_full_name.' '.$record->browser_version; $data[$index]['campaign'] = array(); $date = DateTime::createFromFormat('Y-m-d H:i:s', $record->date ); $data[$index]['viewed_at'] = $date->format( 'Y-m-d H:i:s' ); $data[$index]['signature'] = md5( APVC_Salt::request_payload_salt() . json_encode( $data[$index]['rawData'] ) ); $ip_address = $record->ip_address; $user_agent = $data[$index]['user_agent']; $user_device = $data[$index]['user_device']; $visitor = new APVC_Visitor( $ip_address, $user_agent ); $signature = md5( APVC_Salt::request_payload_salt() . json_encode( $data[$index]['rawData'] ) ); $campaign = array(); if ( $signature === $data[$index]['signature'] ) { new APVC_Register_View( $data[$index]['rawData'], $data[$index]['referrer_url'], $visitor, $campaign, $date->format( 'Y-m-d H:i:s' ), $user_device ); } $index++; } $table = $wpdb->prefix . 'postmeta'; $wpdb->delete( $table, array( 'meta_key' => 'post_starting_count' ) ); update_option( 'apvc_migration_process_bulk', 'completed' ); } }