function install_perform_install
Search API
7.x install.php | install_perform_install() |
6.x install.php | install_perform_install() |
4.x install.php | install_perform_install() |
5.x install.php | install_perform_install() |
Actually performs the installation of FlightPath
1 call to install_perform_install()
- install.php in ./
install.php - This is the initial installation file for FlightPath.
File
- ./
install.php, line 76 - This is the initial installation file for FlightPath.
Code
function install_perform_install() {
global $user;
if (!isset($user)) {
$user = new stdClass();
}
$user->id = 1; // set to admin during install
$db_name = trim($_POST ["db_name"]);
$db_host = trim($_POST ["db_host"]);
$db_port = trim($_POST ["db_port"]);
$db_user = trim($_POST ["db_user"]);
$db_pass = trim($_POST ["db_pass"]);
$admin_pass = trim($_POST ["admin_pass"]);
$admin_pass2 = trim($_POST ["admin_pass2"]);
$admin_name = trim($_POST ["admin_name"]);
if (strlen($admin_name) < 3) {
return install_display_db_form("<font color='red'>" . st("Please select another
username for Admin (ex: admin)
which is at least 3 characters long.") . "</font>");
}
if (strlen($admin_pass) < 5) {
return install_display_db_form("<font color='red'>" . st("Admin password must be at least 5 characters long.") . "</font>");
}
if ($admin_pass != $admin_pass2) {
return install_display_db_form("<font color='red'>" . st("You must enter the same Admin password for both the
'Admin Password' field and the 'Re-enter Password'
field.") . "</font>");
}
// Place into settings so our installation procedures will work.
$GLOBALS ["fp_system_settings"]["db_host"] = $db_host . ':' . $db_port;
$GLOBALS ["fp_system_settings"]["db_user"] = $db_user;
$GLOBALS ["fp_system_settings"]["db_pass"] = $db_pass;
$GLOBALS ["fp_system_settings"]["db_name"] = $db_name;
// Make sure admin information is OK.
// We will attempt to connect to this database. If we have any problems, we will go back to
// the form and inform the user.
if (!@mysql_connect($db_host . ':' . $db_port, $db_user, $db_pass)) {
return install_display_db_form("<font color='red'>" . st("Could not connect. Please check that you have
created the database already, and given the user all of the permissions
(except Grant). Then, make sure you typed the username and
password correctly.") . "</font>");
}
if (!@mysql_select_db($db_name)) {
return install_display_db_form("<font color='red'>" . st("Could not connect to the database name you specified.
Please check that you have
created the database already, and given the user all of the permissions
(except Grant). Possibly check that the database name is correct.") . "</font>");
}
///////////////////////////////
// If we have made it here, then we have been provided valid database credentials.
// Let's write out our settings.php file.
$settings_template = trim(install_get_settings_file_template());
// Add in our replacements
$settings_template = str_replace("%DB_HOST%", $db_host, $settings_template);
$settings_template = str_replace("%DB_PORT%", $db_port, $settings_template);
$settings_template = str_replace("%DB_NAME%", $db_name, $settings_template);
$settings_template = str_replace("%DB_USER%", $db_user, $settings_template);
$settings_template = str_replace("%DB_PASS%", $db_pass, $settings_template);
$settings_template = str_replace("%CRON_SECURITY_TOKEN%", md5(time()), $settings_template);
// Attempt to figure out the file_system_path based on __FILE__
$file_system_path = str_replace("install.php", "", __FILE__);
// Convert \ to / in the file system path.
$file_system_path = str_replace("\\", "/", $file_system_path);
// Get rid of the last character, which should be a / at this point.
$file_system_path = substr($file_system_path, 0, -1);
$settings_template = str_replace("%FILE_SYSTEM_PATH%", $file_system_path, $settings_template);
// Attempt to figure out the base URL.
$protocol = strpos(strtolower($_SERVER ['SERVER_PROTOCOL']), 'https') === FALSE ? 'http' : 'https';
$host = $_SERVER ['HTTP_HOST'];
$script = $_SERVER ['SCRIPT_NAME'];
$base_url = $protocol . "://" . $host . $script;
$base_url = str_replace("/install.php", "", $base_url);
$settings_template = str_replace("%BASE_URL%", $base_url, $settings_template);
// Figure out the base_path and add it in.
$base_path = str_replace($protocol . "://" . $host, "", $base_url);
$settings_template = str_replace("%BASE_PATH%", $base_path, $settings_template);
// Okay, we have completed all the changes to the settings template string, we can
// write it out to a file now.
if (!file_put_contents("custom/settings.php", $settings_template)) {
die("There was an error trying to write out the /custom/settings.php file. Please
make sure the /custom directory is writable to the webserver.");
}
///////////////////////////////////
// Okay, we have just written out our settings.php file.
// We now need to install our database. We will do this by
// running the system module's hook_install, as it contains all
// of our various tables needed to run FlightPath.
include_once ("modules/system/system.install");
$GLOBALS ["fp_die_mysql_errors"] = TRUE;
// call system_install() to perform our numerous DB table creations.
system_install();
// With db tables created, let's include our settings file so we can get some
// important GLOBAL variables set up.
include ("custom/settings.php");
// Re-establish DatabaseHandler object connection since we just re-loaded the settings file.
$temp_db = new DatabaseHandler();
// Add the admin user to the newly-created users table and the "faculty" table.
db_query("INSERT INTO users (user_id, user_name, cwid, password, is_faculty, f_name, l_name)
VALUES ('1', '?', '1', '?', '1', 'Admin', 'User') ", $admin_name, md5($admin_pass));
db_query("INSERT INTO faculty (cwid) VALUES ('1') ");
// Having made it here, we now need to call system_enable,
// which will in turn enable all of the other modules which
// we will need to have, as well as other database changes.
system_enable();
// Now that we have enabled all of the modules (and made other database changes)
// let's re-include the bootstrap file, which will re-init our GLOBAL settings,
// as well as load all of our new modules.
$skip_flightpath_settings = FALSE;
$skip_flightpath_modules = FALSE;
include ("bootstrap.inc");
// Re-establish DatabaseHandler object connection since we just re-loaded the settings file.
$temp_db = new DatabaseHandler();
/////////////////////////
// Now, we need to clear our caches and re-build the menu router.
fp_clear_cache();
// wipe out the SESSION to remove any extraneous messages.
session_destroy();
// Okay, now we are done!
// let's re-direct to a new page.
fp_goto("install-finished");
}