createTables(); $this->migrateData(); ( new RoleManager() )->createRoles(); $this->scheduleBilling(); flush_rewrite_rules(); update_option( 'us_schedular_version', USC_VERSION ); } /** * Ensure the daily scheduled-billing scan is registered with WP-Cron. Runs on * activation and on every version-bump re-install, so an existing site that * predates the feature picks the event up on its next deploy. */ private function scheduleBilling(): void { if ( false === wp_next_scheduled( ScheduledBillingRunner::HOOK ) ) { wp_schedule_event( time(), 'daily', ScheduledBillingRunner::HOOK ); } } private function createTables(): void { global $wpdb; if ( ! $wpdb instanceof \wpdb ) { return; } $charset = $wpdb->get_charset_collate(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; foreach ( Schema::tables( $wpdb->prefix, $charset ) as $sql ) { dbDelta( $sql ); } } private function migrateData(): void { global $wpdb; if ( ! $wpdb instanceof \wpdb ) { return; } ( new AvailabilityRepository( $wpdb ) )->splitOversizedWindows(); // Guardian accounts introduced "who pays" / "who agreed" alongside "who the // student is". Every row written before then had them one and the same, so // point the new columns at the student rather than leaving them 0 — the // balance and acceptance lookups key on them directly. ( new PaymentRepository( $wpdb ) )->backfillPayerIds(); ( new CreditRepository( $wpdb ) )->backfillPayerIds(); ( new AcceptanceRepository( $wpdb ) )->backfillAcceptedBy(); } }