Y-m-d' );
if ( ! AnalyticsDB::date_exists( $date, 'adsense' ) ) {
$missing_dates[] = $date;
}
}
if ( empty( $missing_dates ) ) {
$dates[] = [
'start_date' => $args['start_date'],
'end_date' => $args['end_date'],
];
return $dates;
}
// Request for one date range because its not large data to send individual request for each date.
$dates[] = [
'start_date' => $missing_dates[ count( $missing_dates ) - 1 ],
'end_date' => $missing_dates[0],
];
return $dates;
}
/**
* Get adsense data and save it into database.
*
* @param string $start_date The start date to fetch.
* @param string $end_date The end date to fetch.
*/
public function get_adsense_data( $start_date = '', $end_date = '' ) {
$rows = Adsense::get_adsense( $start_date, $end_date );
if ( empty( $rows ) ) {
return;
}
try {
DB::add_adsense( $rows );
} catch ( Exception $e ) {} // phpcs:ignore
}
/**
* Handlle analytics response.
*
* @param array $data API request and response data.
*/
public function handle_analytics_response( $data = [] ) {
if ( 200 !== $data['code'] ) {
return;
}
if ( isset( $data['formatted_response']['rows'] ) && ! empty( $data['formatted_response']['rows'] ) ) {
return;
}
$dates = get_option( 'rank_math_analytics_empty_dates', [] );
if ( ! $dates ) {
$dates = [];
}
$dates[] = $data['args']['dateRanges'][0]['startDate'];
$dates[] = $data['args']['dateRanges'][0]['endDate'];
$dates = array_unique( $dates );
update_option( 'rank_math_analytics_empty_dates', $dates );
}
/**
* Clear cache.
*/
public function clear_cache() {
global $wpdb;
// Delete all useless data from analytics data table.
$wpdb->get_results( "DELETE FROM {$wpdb->prefix}rank_math_analytics_ga WHERE page NOT IN ( SELECT page from {$wpdb->prefix}rank_math_analytics_objects )" );
}
/**
* Purge cache.
*
* @param object $table Table insance.
*/
public function purge_cache( $table ) {
$table->whereLike( 'option_name', 'losing_posts' )->delete();
$table->whereLike( 'option_name', 'winning_posts' )->delete();
$table->whereLike( 'option_name', 'losing_keywords' )->delete();
$table->whereLike( 'option_name', 'winning_keywords' )->delete();
$table->whereLike( 'option_name', 'tracked_keywords_summary' )->delete();
}
/**
* Delete analytics and adsense data by days.
*
* @param int $days Decide whether to delete all or delete 90 days data.
*/
public function delete_by_days( $days ) {
if ( -1 === $days ) {
if ( $this->analytics_connected ) {
DB::traffic()->truncate();
}
if ( $this->adsense_connected ) {
DB::adsense()->truncate();
}
return;
}
$start = date_i18n( 'Y-m-d H:i:s', strtotime( '-1 days' ) );
$end = date_i18n( 'Y-m-d H:i:s', strtotime( '-' . $days . ' days' ) );
if ( $this->analytics_connected ) {
DB::traffic()->whereBetween( 'created', [ $end, $start ] )->delete();
}
if ( $this->adsense_connected ) {
DB::adsense()->whereBetween( 'created', [ $end, $start ] )->delete();
}
}
/**
* Delete record for comparison.
*
* @param string $start Start date.
*/
public function delete_data_log( $start ) {
if ( $this->analytics_connected ) {
DB::traffic()->where( 'created', '<', $start )->delete();
}
if ( $this->adsense_connected ) {
DB::adsense()->where( 'created', '<', $start )->delete();
}
}
/**
* Check for missing dates.
*
* @param string $action Action to perform.
*/
private function check_for_missing_dates( $action ) {
$count = 1;
$hook = "get_{$action}_data";
$start = Helper::get_midnight( time() + DAY_IN_SECONDS );
$days = Helper::get_settings( 'general.console_caching_control', 90 );
for ( $current = 1; $current <= $days; $current++ ) {
$date = Helper::get_date( 'Y-m-d', $start - ( DAY_IN_SECONDS * $current ), false, true );
if ( AnalyticsDB::date_exists( $date, $action ) ) {
continue;
}
$count++;
as_schedule_single_action(
time() + ( 60 * ( $count / 2 ) ),
'rank_math/analytics/' . $hook,
[ $date ],
'rank-math'
);
}
// Clear cache.
if ( $count > 1 ) {
as_schedule_single_action(
time() + ( 60 * ( ( $count + 1 ) / 2 ) ),
'rank_math/analytics/clear_cache',
[],
'rank-math'
);
}
}
}
Fatal error: Uncaught Error: Class 'RankMathPro\Analytics\Workflow\Jobs' not found in /home/candoodesigncom/public_html/wp-content/plugins/seo-by-rank-math-pro/includes/modules/analytics/class-analytics.php:76
Stack trace:
#0 /home/candoodesigncom/public_html/wp-content/plugins/seo-by-rank-math-pro/rank-math-pro.php(355): RankMathPro\Analytics\Analytics->__construct()
#1 /home/candoodesigncom/public_html/wp-includes/class-wp-hook.php(324): RankMathPro->init('')
#2 /home/candoodesigncom/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#3 /home/candoodesigncom/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /home/candoodesigncom/public_html/wp-settings.php(555): do_action('plugins_loaded')
#5 /home/candoodesigncom/public_html/wp-config.php(100): require_once('/home/candoodes...')
#6 /home/candoodesigncom/public_html/wp-load.php(50): require_once('/home/candoodes...')
#7 /home/candoodesigncom/public_html/wp-blog-header.php(13): require_once('/home/candoodes...')
#8 /ho in /home/candoodesigncom/public_html/wp-content/plugins/seo-by-rank-math-pro/includes/modules/analytics/class-analytics.php on line 76