Skip to content

Commit

Permalink
Removed outdated notice and update database functionality (738)
Browse files Browse the repository at this point in the history
  • Loading branch information
zahardev committed Sep 16, 2024
1 parent 8f75d4b commit e4d818d
Showing 1 changed file with 0 additions and 67 deletions.
67 changes: 0 additions & 67 deletions php/classes/class-ssp-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ public function bootstrap( $file, $version, $db_version ) {
// Get required episode IDs for stats
add_action( 'init', array( $this, 'load_episode_ids' ), 11 );

// Add admin notice to upgrade stats table
add_action( 'admin_notices', array( $this, 'maybe_notify_stats_update' ) );

// Anonymise the IP address details stored in the database
add_action( 'admin_init', array( $this, 'maybe_update_stats_data' ), 11 );

// Add stats meta box to episodes edit screen
add_action( 'ssp_meta_boxes', array( $this, 'post_meta_box' ), 10, 1 );

Expand Down Expand Up @@ -1284,65 +1278,4 @@ public function dashboard_widget_callback(){
echo $html;

}

/**
* Checks if the ssp_stats_ips_updated option is set, if not shows a message to the user.
*/
public function maybe_notify_stats_update(){
$ssp_stats_ips_updated = get_option( 'ssp_stats_ips_updated', 'no' );
if ( 'yes' === $ssp_stats_ips_updated ) {
return;
}
$data_upgrade_url = add_query_arg( array( 'upgrade_stats_table' => 'anonymise_ip' ) );
?>
<div class="notice notice-warning">
<p><?php _e( 'Seriously Simple Stats needs to perform an update to the stats database table. Click below to perform this one-time update.', 'seriously-simple-stats' ); ?></p>
<p><a href="<?php echo $data_upgrade_url ?>"><?php _e( 'Upgrade stats table.', 'seriously-simple-stats' ); ?></a></p>
</div>
<?php
}

/**
* Attempt to update the stats table
*/
public function maybe_update_stats_data(){

if ( ! isset( $_GET['upgrade_stats_table'] ) ) {
return;
}

$upgrade_stats_table = filter_var( $_GET['upgrade_stats_table'], FILTER_SANITIZE_STRING );
if ( ! 'anonymise_ip' === $upgrade_stats_table ) {
return;
}

global $wpdb;
$query = "UPDATE {$wpdb->prefix}ssp_stats SET ip_address = CONCAT( SUBSTRING_INDEX( ip_address, '.', 3 ) , '.0' )";
$affected_rows = $wpdb->query($query);

if (false === $affected_rows){
add_action( 'admin_notices', array( $this, 'update_stats_data_failed' ) );
}else {
update_option( 'ssp_stats_ips_updated', 'yes' );
add_action( 'admin_notices', array( $this, 'update_stats_data_succeeded' ) );
}

}

public function update_stats_data_failed(){
?>
<div class="notice notice-warning is-dismissible">
<p><?php _e( 'An error occurred updating the stats database table, please try again or contact support.', 'seriously-simple-stats' ); ?></p>
</div>
<?php
}

public function update_stats_data_succeeded(){
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Updating the stats database table completed successfully.', 'seriously-simple-stats' ); ?></p>
</div>
<?php
}

}

0 comments on commit e4d818d

Please sign in to comment.