| @@ -4,15 +4,18 @@ | ||
| 4 | 4 | |
| 5 | 5 | use FluentBooking\Framework\Foundation\Application; |
| 6 | 6 | use FluentBooking\App\Hooks\Handlers\ActivationHandler; |
| 7 | 7 | use FluentBooking\App\Hooks\Handlers\DeactivationHandler; |
| 8 | +use FluentBooking\Database\DBMigrator; | |
| 8 | 9 | |
| 9 | 10 | return function ($file) { |
| 10 | 11 | |
| 11 | 12 | $app = new Application($file); |
| 12 | 13 | |
| 13 | - register_activation_hook($file, function () use ($app) { | |
| 14 | - ($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); | |
| 15 | 18 | }); |
| 16 | 19 | |
| 17 | 20 | register_deactivation_hook($file, function () use ($app) { |
| 18 | 21 | ($app->make(DeactivationHandler::class))->handle(); |
| @@ -21,6 +24,34 @@ | ||
| 21 | 24 | require_once(FLUENT_BOOKING_DIR . 'boot/action_scheduler_loader.php'); |
| 22 | 25 | |
| 23 | 26 | add_action('plugins_loaded', function () use ($app) { |
| 24 | 27 | do_action('fluent_booking/loaded', $app); |
| 28 | + | |
| 29 | + $currentDBVersion = get_option('fluent_booking_db_version'); | |
| 30 | + | |
| 31 | + if (!$currentDBVersion || version_compare($currentDBVersion, FLUENT_BOOKING_DB_VERSION, '<')) { | |
| 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 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + if (defined('FLUENT_BOOKING_PRO_VERSION') && version_compare(FLUENT_BOOKING_MIN_PRO_VERSION, FLUENT_BOOKING_PRO_VERSION, '>')) { | |
| 47 | + if (!current_user_can('manage_options')) { | |
| 48 | + return; | |
| 49 | + } | |
| 50 | + add_filter('fluent_booking/dashboard_notices', function ($notices) { | |
| 51 | + $updateUrl = admin_url('plugins.php?s=fluent-booking&plugin_status=all&fluent-booking-pro-check-update=' . time()); | |
| 52 | + $notices[] = '<div class="error">' . esc_html__('FluentBookingPro plugin needs to be updated to the latest version.', 'fluent-booking') . ' <a href="' . esc_url($updateUrl) . '">' . esc_html__('Click here to update', 'fluent-booking') . '</a></div>'; | |
| 53 | + return $notices; | |
| 54 | + }); | |
| 55 | + } | |
| 25 | 56 | }); |
| 26 | 57 | }; |