meets_requirements() ) { deactivate_plugins( AKSMB_PLUGIN_BASENAME ); wp_die( esc_html( implode( ' ', $checker->failures() ) ), esc_html__( 'MarginBeacon activation failed', 'marginbeacon' ), array( 'back_link' => true ) ); } Capabilities::install(); if ( ! ( new Migrator() )->verify_schema() ) { deactivate_plugins( AKSMB_PLUGIN_BASENAME ); wp_die( esc_html__( 'MarginBeacon activation failed: database schema could not be installed or verified.', 'marginbeacon' ), esc_html__( 'MarginBeacon activation failed', 'marginbeacon' ), array( 'back_link' => true ) ); } if ( ! get_option( Constants::OPTION_ACTIVATION_GMT ) ) { update_option( Constants::OPTION_ACTIVATION_GMT, gmdate( 'Y-m-d H:i:s' ), true ); } if ( false === get_option( Constants::OPTION_SETTINGS, false ) ) { update_option( Constants::OPTION_SETTINGS, array( 'thresholds' => Constants::default_thresholds(), 'mode' => 'watch_only', 'disclaimer_accepted' => false, ), true ); } if ( false === get_option( Constants::OPTION_COST_SETTINGS, false ) ) { $woo_enabled = ( new CogsEnvironment() )->native_cogs_feature_enabled(); $source = $woo_enabled ? CanonicalCostSource::WOOCOMMERCE : CanonicalCostSource::MARGINBEACON; update_option( Constants::OPTION_COST_SETTINGS, array( 'canonical_cost_source' => $source, 'prefer_native_cogs' => CanonicalCostSource::WOOCOMMERCE === $source, 'global_assumed_cost' => null, 'global_assumed_cost_percent' => null, 'custom_meta_key' => '', 'fallback_enabled' => false, 'cogs_tax_basis' => 'exclusive', 'needs_cogs_correction' => false, ), true ); ( new CanonicalCostSource() )->ensure_bootstrapped( true ); } else { ( new CanonicalCostSource() )->ensure_bootstrapped( false ); } if ( false === get_option( Constants::OPTION_UNINSTALL_DELETE_DATA, false ) ) { update_option( Constants::OPTION_UNINSTALL_DELETE_DATA, 0, true ); } // Bounded background seed — never scan catalog on activation request. if ( function_exists( 'as_enqueue_async_action' ) ) { $action_id = as_enqueue_async_action( Constants::ACTION_SEED_PRICE_REVISIONS, array( 'batch' => 0 ), Constants::SCHEDULER_GROUP ); if ( ! SchedulerResult::is_enqueued( $action_id ) ) { update_option( 'aksmb_price_seed_continuation_failed', array( 'batch' => 0, 'at_gmt' => gmdate( 'Y-m-d H:i:s' ), 'error' => 'activation_enqueue_failed', ), false ); ( new OperationalEventsRepository() )->record( 'price_seed', 'activation', 'failed', 'continuation_failed', array( 'batch' => 0, 'phase' => 'activation', ), 'scheduler_enqueue_failed' ); } } flush_rewrite_rules( false ); } }