| @@ -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 | |
| @@ -59,16 +55,20 @@ | ||
| 59 | 55 | $wpdb->query("UPDATE `{$table}` SET `serial_number` = `id` WHERE `serial_number` IS NULL"); |
| 60 | 56 | } |
| 61 | 57 | } |
| 62 | 58 | |
| 63 | - /* | |
| 64 | - * The below schedule is powered by Action Scheduler by WooCommerce | |
| 65 | - * It will run every 30 minutes. | |
| 66 | - */ | |
| 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); | |
| 59 | + // Half-hourly Action Scheduler job. Only schedule it while something | |
| 60 | + // listens (currently only Pro), otherwise it fires with no callback. | |
| 61 | + $hasListener = has_action('fluent_support_half_hourly'); | |
| 62 | + $nextRun = as_next_scheduled_action('fluent_support_half_hourly', [], 'fluent-support'); | |
| 63 | + | |
| 64 | + if ($hasListener) { | |
| 65 | + if (false === $nextRun) { | |
| 66 | + as_schedule_recurring_action(time(), 1800, 'fluent_support_half_hourly', [], 'fluent-support', true); | |
| 67 | + } | |
| 68 | + } elseif (false !== $nextRun) { | |
| 69 | + as_unschedule_all_actions('fluent_support_half_hourly', [], 'fluent-support'); | |
| 69 | 70 | } |
| 70 | - | |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | 73 | }); |
| 74 | 74 | }; |