| @@ -20,9 +20,13 @@ | ||
| 20 | 20 | |
| 21 | 21 | add_action('plugins_loaded', function () use ($file) { |
| 22 | 22 | $application = new Application($file); |
| 23 | 23 | |
| 24 | - \FluentSupport\Database\DBMigrator::maybeMigrateDBChanges(); | |
| 24 | + $currentDbVersion = get_option('fluent_support_db_version'); | |
| 25 | + if (!$currentDbVersion || version_compare($currentDbVersion, FLUENT_SUPPORT_DB_VERSION, '<')) { | |
| 26 | + \FluentSupport\Database\DBMigrator::run(); | |
| 27 | + update_option('fluent_support_db_version', FLUENT_SUPPORT_DB_VERSION, 'no'); | |
| 28 | + } | |
| 25 | 29 | |
| 26 | 30 | do_action('fluent_support_loaded', $application); |
| 27 | 31 | do_action('fluent_support_addons_loaded', $application); |
| 28 | 32 | |
| @@ -42,40 +46,16 @@ | ||
| 42 | 46 | if (!wp_next_scheduled('fluent_support_weekly_tasks')) { |
| 43 | 47 | wp_schedule_event(time(), 'weekly', 'fluent_support_weekly_tasks'); |
| 44 | 48 | } |
| 45 | 49 | |
| 46 | - global $wpdb; | |
| 47 | - $table = esc_sql($wpdb->prefix . 'fs_tickets'); | |
| 48 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $table is sanitized via esc_sql(); no user input. | |
| 49 | - $column_exists = $wpdb->get_var("SHOW COLUMNS FROM `{$table}` LIKE 'serial_number'"); | |
| 50 | - if ($column_exists) { | |
| 51 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 52 | - $has_null = $wpdb->get_var("SELECT id FROM `{$table}` WHERE `serial_number` IS NULL LIMIT 1"); | |
| 53 | - if ($has_null) { | |
| 54 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 55 | - $wpdb->query("UPDATE `{$table}` SET `serial_number` = `id` WHERE `serial_number` IS NULL"); | |
| 56 | - } | |
| 57 | - } | |
| 58 | - | |
| 59 | 50 | /* |
| 60 | 51 | * The below schedule is powered by Action Scheduler by WooCommerce |
| 61 | - * It will run every 30 minutes. Only schedule it while something is | |
| 62 | - * actually listening (currently only Fluent Support Pro's storage | |
| 63 | - * token refresh / email piping retry) — otherwise it fires with no | |
| 64 | - * callback to run. Any future free-tier listener added via | |
| 65 | - * add_action('fluent_support_half_hourly', ...) makes this schedule | |
| 66 | - * itself automatically, with no change needed here. | |
| 52 | + * It will run every 30 minutes. | |
| 67 | 53 | */ |
| 68 | - $hasListener = has_action('fluent_support_half_hourly'); | |
| 69 | - $nextRun = as_next_scheduled_action('fluent_support_half_hourly', [], 'fluent-support'); | |
| 54 | + if (false === as_next_scheduled_action('fluent_support_half_hourly')) { | |
| 55 | + as_schedule_recurring_action(time(), 1800, 'fluent_support_half_hourly', [], 'fluent-support', true); | |
| 56 | + } | |
| 70 | 57 | |
| 71 | - if ($hasListener) { | |
| 72 | - if (false === $nextRun) { | |
| 73 | - as_schedule_recurring_action(time(), 1800, 'fluent_support_half_hourly', [], 'fluent-support', true); | |
| 74 | - } | |
| 75 | - } elseif (false !== $nextRun) { | |
| 76 | - as_unschedule_all_actions('fluent_support_half_hourly', [], 'fluent-support'); | |
| 77 | - } | |
| 78 | 58 | }); |
| 79 | 59 | |
| 80 | 60 | }); |
| 81 | 61 | }; |