| @@ -20,13 +20,9 @@ | ||
| 20 | 20 | |
| 21 | 21 | add_action('plugins_loaded', function () use ($file) { |
| 22 | 22 | $application = new Application($file); |
| 23 | 23 | |
| 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 | - } | |
| 24 | + \FluentSupport\Database\DBMigrator::maybeMigrateDBChanges(); | |
| 29 | 25 | |
| 30 | 26 | do_action('fluent_support_loaded', $application); |
| 31 | 27 | do_action('fluent_support_addons_loaded', $application); |
| 32 | 28 | |
| @@ -61,14 +57,25 @@ | ||
| 61 | 57 | } |
| 62 | 58 | |
| 63 | 59 | /* |
| 64 | 60 | * The below schedule is powered by Action Scheduler by WooCommerce |
| 65 | - * It will run every 30 minutes. | |
| 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. | |
| 66 | 67 | */ |
| 67 | - if (false === as_next_scheduled_action('fluent_support_half_hourly')) { | |
| 68 | - as_schedule_recurring_action(time(), 1800, 'fluent_support_half_hourly', [], 'fluent-support', true); | |
| 68 | + $hasListener = has_action('fluent_support_half_hourly'); | |
| 69 | + $nextRun = as_next_scheduled_action('fluent_support_half_hourly', [], 'fluent-support'); | |
| 70 | + | |
| 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'); | |
| 69 | 77 | } |
| 70 | - | |
| 71 | 78 | }); |
| 72 | 79 | |
| 73 | 80 | }); |
| 74 | 81 | }; |