academy_version = get_option( 'academy_version' ); $self->save_main_settings(); Database::create_initial_custom_table(); self::record_missing_tables(); $self->add_role(); // if first time install then run below method if ( ! $self->academy_version ) { $self->create_initial_pages(); } // Save option table data $self->save_option(); Helper::flush_rewrite_rules(); } /** * Confirm the core tables were created. Any that are missing are recorded * so an administrator sees a notice and creation is retried in the admin. * * @return string[] Missing tables. */ public static function record_missing_tables() { $missing = Database::missing_core_tables(); if ( $missing ) { update_option( 'academy_missing_tables', $missing, false ); } else { delete_option( 'academy_missing_tables' ); } return $missing; } /** * Retry creating missing core tables (admin_init). */ public static function maybe_repair_tables() { if ( ! get_option( 'academy_missing_tables' ) || ! current_user_can( 'manage_options' ) ) { return; } Database::create_initial_custom_table(); self::record_missing_tables(); } /** * Tell administrators which tables could not be created. */ public static function missing_tables_notice() { $missing = get_option( 'academy_missing_tables' ); if ( empty( $missing ) || ! is_array( $missing ) || ! current_user_can( 'manage_options' ) ) { return; } printf( '

%s %s

', esc_html__( 'Academy LMS could not create these database tables. Please check that your database user can create tables, then reload this page:', 'academy' ), esc_html( implode( ', ', array_map( 'strval', $missing ) ) ) ); } public function save_main_settings() { Settings::save_settings(); } public function save_option() { // The installed versions are only recorded once every core table exists, // so a failed table creation is not remembered as a successful install. if ( ! get_option( 'academy_missing_tables' ) ) { if ( ! $this->academy_version ) { add_option( 'academy_version', ACADEMY_VERSION ); } if ( ! get_option( 'academy_db_version' ) ) { add_option( 'academy_db_version', ACADEMY_DB_VERSION ); } } if ( ! get_option( 'academy_first_install_time' ) ) { add_option( 'academy_first_install_time', Helper::get_time() ); } \Academy\Helper::flush_rewrite_rules(); update_option( 'academy_flash_role_management', true ); } public function add_role() { // student role Role::add_student_role(); // instructor role Role::add_instructor_role(); // guardian / parent role Role::add_guardian_role(); // manager role Role::add_manager_role(); // instructor role Role::add_existing_administrator_instructor_role(); } public function create_initial_pages() { Pages::regenerate_necessary_pages(); } }