| @@ -16,24 +16,17 @@ | ||
| 16 | 16 | * Upgrades the configuration of charts, if required. |
| 17 | 17 | */ |
| 18 | 18 | public static function upgrade() { |
| 19 | 19 | $last_version = get_option( 'visualizer-upgraded', '0.0.0' ); |
| 20 | - $upgraded = false; | |
| 21 | 20 | |
| 22 | - if ( version_compare( $last_version, '3.4.3', '<' ) ) { | |
| 23 | - self::makeAllTableChartsTabular(); | |
| 24 | - $upgraded = true; | |
| 21 | + switch ( $last_version ) { | |
| 22 | + case '0.0.0': | |
| 23 | + self::makeAllTableChartsTabular(); | |
| 24 | + break; | |
| 25 | + default: | |
| 26 | + return; | |
| 25 | 27 | } |
| 26 | 28 | |
| 27 | - if ( wp_next_scheduled( 'visualizer_schedule_refresh_db' ) ) { | |
| 28 | - self::migrate_action_scheduler(); | |
| 29 | - $upgraded = true; | |
| 30 | - } | |
| 31 | - | |
| 32 | - if ( ! $upgraded ) { | |
| 33 | - return; | |
| 34 | - } | |
| 35 | - | |
| 36 | 29 | update_option( 'visualizer-upgraded', Visualizer_Plugin::VERSION ); |
| 37 | 30 | |
| 38 | 31 | // this will help in debugging to know which version this was upgraded from. |
| 39 | 32 | update_option( 'visualizer-upgraded-from', $last_version ); |
| @@ -77,43 +70,7 @@ | ||
| 77 | 70 | AND pm.meta_key = '" . Visualizer_Plugin::CF_CHART_TYPE . "' |
| 78 | 71 | AND pm.meta_value IN ( 'dataTable', 'table' )" |
| 79 | 72 | ); |
| 80 | 73 | // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared |
| 81 | - } | |
| 82 | 74 | |
| 83 | - /** | |
| 84 | - * Migrate recurring WP-Cron jobs to Action Scheduler. | |
| 85 | - */ | |
| 86 | - private static function migrate_action_scheduler(): void { | |
| 87 | - if ( ! function_exists( 'as_schedule_recurring_action' ) || ! function_exists( 'as_next_scheduled_action' ) ) { | |
| 88 | - return; | |
| 89 | - } | |
| 90 | - | |
| 91 | - $hook = 'visualizer_schedule_refresh_db'; | |
| 92 | - $group = 'visualizer'; | |
| 93 | - $interval_key = apply_filters( 'visualizer_chart_schedule_interval', 'visualizer_ten_minutes' ); | |
| 94 | - $interval = self::get_schedule_interval_seconds( $interval_key ); | |
| 95 | - $timestamp = strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; | |
| 96 | - | |
| 97 | - $next = as_next_scheduled_action( $hook, array(), $group ); | |
| 98 | - if ( false === $next ) { | |
| 99 | - as_schedule_recurring_action( $timestamp, $interval, $hook, array(), $group ); | |
| 100 | - } | |
| 101 | - | |
| 102 | - wp_clear_scheduled_hook( $hook ); | |
| 103 | - } | |
| 104 | - | |
| 105 | - /** | |
| 106 | - * Resolve a cron schedule key to seconds. | |
| 107 | - * | |
| 108 | - * @param string $interval_key Cron schedule key. | |
| 109 | - * @return int Interval in seconds. | |
| 110 | - */ | |
| 111 | - private static function get_schedule_interval_seconds( $interval_key ) { | |
| 112 | - $schedules = wp_get_schedules(); | |
| 113 | - if ( isset( $schedules[ $interval_key ]['interval'] ) ) { | |
| 114 | - return (int) $schedules[ $interval_key ]['interval']; | |
| 115 | - } | |
| 116 | - | |
| 117 | - return 600; | |
| 118 | 75 | } |
| 119 | 76 | } |