/** * Installs a site using $CFG->dataroot and $CFG->dbprefix * As we are setting up the behat test environment, these settings * are replaced by $CFG->behat_dataroot and $CFG->behat_dbprefix * * @throws SystemException * @return void */ public static function install_site() { if (!defined('BEHAT_UTIL')) { throw new SystemException('This method can be only used by Behat CLI tool'); } if (table_exists(new XMLDBTable('config'))) { behat_error(BEHAT_EXITCODE_INSTALLED); } // New dataroot. self::reset_dataroot(); // Determine what we will install $upgrades = check_upgrades(); $upgrades['firstcoredata'] = true; $upgrades['localpreinst'] = true; $upgrades['lastcoredata'] = true; $upgrades['localpostinst'] = true; upgrade_mahara($upgrades); $userobj = new User(); $userobj = $userobj->find_by_username('admin'); $userobj->email = self::$sitedefaultinfo['admin']['email']; $userobj->commit(); // Password changes should be performed by the authfactory $authobj = AuthFactory::create($userobj->authinstance); $authobj->change_password($userobj, self::$sitedefaultinfo['admin']['password'], true); // Set site name set_config('sitename', self::$sitedefaultinfo['sitename']); // We need to keep the installed dataroot artefact files. // So each time we reset the dataroot before running a test, the default files are still installed. self::save_original_data_files(); // Disable some settings that are not wanted on test sites. set_config('sendemail', false); // Keeps the current version of database and dataroot. self::store_versions_hash(); // Stores the database contents for fast reset. self::store_database_state(); }
$settings->options = $options; $settings->info = get_string('cliinstallerdescription', 'admin'); $cli->setup($settings); // Check whether we need to do anything if (table_exists(new XMLDBTable('config'))) { cli::cli_exit(get_string('maharainstalled', 'admin'), false); } // Check initial password and e-mail address before we install try { $adminpassword = $cli->get_cli_param('adminpassword'); $adminemail = $cli->get_cli_param('adminemail'); } catch (ParameterException $e) { cli::cli_exit($e->getMessage(), true); } // Determine what we will install $upgrades = check_upgrades(); $upgrades['firstcoredata'] = true; $upgrades['localpreinst'] = true; $upgrades['lastcoredata'] = true; $upgrades['localpostinst'] = true; // Actually perform the installation log_info(get_string('cliinstallingmahara', 'admin')); upgrade_mahara($upgrades); // Set initial password and e-mail address $userobj = new User(); $userobj = $userobj->find_by_username('admin'); $userobj->email = $adminemail; $userobj->commit(); // Password changes should be performed by the authfactory $authobj = AuthFactory::create($userobj->authinstance); $authobj->change_password($userobj, $adminpassword, true);