| @@ -10,10 +10,12 @@ | ||
| 10 | 10 | return function ($file) { |
| 11 | 11 | |
| 12 | 12 | $app = new Application($file); |
| 13 | 13 | |
| 14 | - register_activation_hook($file, function () use ($app) { | |
| 15 | - ($app->make(ActivationHandler::class))->handle(); | |
| 14 | + register_activation_hook($file, function ($network_wide = false) use ($app) { | |
| 15 | + // WordPress passes $network_wide; dropping it left every blog but the | |
| 16 | + // activating one unmigrated and unscheduled on a network activation. | |
| 17 | + ($app->make(ActivationHandler::class))->handle($network_wide); | |
| 16 | 18 | }); |
| 17 | 19 | |
| 18 | 20 | register_deactivation_hook($file, function () use ($app) { |
| 19 | 21 | ($app->make(DeactivationHandler::class))->handle(); |
| @@ -24,11 +26,22 @@ | ||
| 24 | 26 | add_action('plugins_loaded', function () use ($app) { |
| 25 | 27 | do_action('fluent_booking/loaded', $app); |
| 26 | 28 | |
| 27 | 29 | $currentDBVersion = get_option('fluent_booking_db_version'); |
| 30 | + | |
| 28 | 31 | if (!$currentDBVersion || version_compare($currentDBVersion, FLUENT_BOOKING_DB_VERSION, '<')) { |
| 29 | - update_option('fluent_booking_db_version', FLUENT_BOOKING_DB_VERSION, 'no'); | |
| 30 | - DBMigrator::run(); | |
| 32 | + // plugins_loaded, so every request during an upgrade reaches this. | |
| 33 | + if (!get_transient('fluent_booking_db_migration_lock')) { | |
| 34 | + set_transient('fluent_booking_db_migration_lock', 1, 5 * MINUTE_IN_SECONDS); | |
| 35 | + | |
| 36 | + DBMigrator::run(); | |
| 37 | + | |
| 38 | + // Stamped after the run: a failure mid-migration used to leave | |
| 39 | + // the version current against a schema that never changed. | |
| 40 | + update_option('fluent_booking_db_version', FLUENT_BOOKING_DB_VERSION, 'no'); | |
| 41 | + | |
| 42 | + delete_transient('fluent_booking_db_migration_lock'); | |
| 43 | + } | |
| 31 | 44 | } |
| 32 | 45 | |
| 33 | 46 | if (defined('FLUENT_BOOKING_PRO_VERSION') && version_compare(FLUENT_BOOKING_MIN_PRO_VERSION, FLUENT_BOOKING_PRO_VERSION, '>')) { |
| 34 | 47 | if (!current_user_can('manage_options')) { |