=== added file 'includes/install.mysql.inc' --- /dev/null +++ includes/install.mysql.inc @@ -0,0 +1,195 @@ + $data) { + switch ($requirement) { + case 'version': + drupal_verify_version_mysql($data); + break; + } + } +} + +/** + * Check if MySQL is available. + * + * @return + * TRUE/FALSE + */ +function mysql_is_available() { + if (function_exists('mysql_connect')) { + return TRUE; + } + return FALSE; +} + +/** + * Check if we can connect to MySQL. + * + * @return + * TRUE/FALSE + */ +function drupal_test_mysql($url) { + if (!mysql_is_available()) { + drupal_set_message('PHP MySQL support not enabled.', 'error'); + } + + $url = parse_url($url); + + // Decode url-encoded information in the db connection string + $url['user'] = urldecode($url['user']); + $url['pass'] = urldecode($url['pass']); + $url['host'] = urldecode($url['host']); + $url['path'] = urldecode($url['path']); + + // Allow for non-standard MySQL port. + if (isset($url['port'])) { + $url['host'] = $url['host'] .':'. $url['port']; + } + + if ($connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2)) { + // Test selecting the database + if (!mysql_select_db(substr($url['path'], 1))) { + drupal_set_message('We were able to connect to the MySQL database server (which means your username and password are valid) but not able to select your database. MySQL reports the following message: '. mysql_error() .'
'. $query .'" and MySQL reported the following error: "'. $error .'".', 'error');
+ $err = TRUE;
+ }
+ else {
+ $success[] = 'INSERT';
+ }
+
+ // Test UPDATE
+ $query = 'UPDATE drupal_install_test SET id = 2;';
+ $result = mysql_query("$query");
+ if ($error = mysql_error()) {
+ drupal_set_message('We were unable to update a value in a test table on your MySQL database server. We tried updating a value with the command "'. $query .'" and MySQL reported the following error: "'. $error .'".', 'error');
+ $err = TRUE;
+ }
+ else {
+ $success[] = 'UPDATE';
+ }
+
+ // Test LOCK
+ $query = 'LOCK TABLES drupal_install_test WRITE;';
+ $result = mysql_query("$query");
+ if ($error = mysql_error()) {
+ drupal_set_message('We were unable to lock a test table on your MySQL database server. We tried locking a table with the command "'. $query .'" and MySQL reported the following error: "'. $error .'".', 'error');
+ $err = TRUE;
+ }
+ else {
+ $success[] = 'LOCK';
+ }
+
+ // Test UNLOCK
+ $query = 'UNLOCK TABLES;';
+ $result = mysql_query("$query");
+ if ($error = mysql_error()) {
+ drupal_set_message('We were unable to unlock a test table on your MySQL database server. We tried unlocking a table with the command "'. $query .'" and MySQL reported the following error: "'. $error .'".', 'error');
+ $err = TRUE;
+ }
+ else {
+ $success[] = 'UNLOCK';
+ }
+
+ // Test DELETE
+ $query = 'DELETE FROM drupal_install_test;';
+ $result = mysql_query("$query");
+ if ($error = mysql_error()) {
+ drupal_set_message('We were unable to delete a value from a test table on your MySQL database server. We tried deleting a value with the command "'. $query .'" and MySQL reported the following error: "'. $error .'".', 'error');
+ $err = TRUE;
+ }
+ else {
+ $success[] = 'DELETE';
+ }
+
+ // Test DROP
+ $query = 'DROP TABLE drupal_install_test;';
+ $result = mysql_query("$query");
+ if ($error = mysql_error()) {
+ drupal_set_message('We were unable to drop a test table from your MySQL database server. We tried dropping a table with the command "'. $query .'" and MySQL reported the following error: "'. $error .'".', 'error');
+ $err = TRUE;
+ }
+ else {
+ $success[] = 'DROP';
+ }
+
+ if ($err) {
+ drupal_set_message('In order for Drupal to work and to proceed with the installation process you must resolve all MySQL permission issues reported above. We were able to verify that we have permission for the following MySQL commands: '. implode($success, ', ') .'. For more help with configuring your MySQL database server, see the Installation and upgrading handbook. If you are unsure what any of this means you should probably contact your hosting provider.', 'error');
+ return FALSE;
+ }
+
+ mysql_close($connection);
+ return TRUE;
+ }
+ else {
+ drupal_set_message('Failure to connect to your MySQL database server. MySQL reports the following message: '. mysql_error() .'settings.php have been made, so you should now remove write permissions to this file. Failure to remove write permissions to this file is a security risk.',
+ 'message_type' => 'error'
+ );
+
+ return $requirements;
+}
+
+?>
=== added directory 'profiles'
=== added file 'profiles/default.profile'
--- /dev/null
+++ profiles/default.profile
@@ -0,0 +1,22 @@
+ 'Drupal',
+ 'description' => 'Select this profile to enable some basic Drupal functionality and the default theme.');
+}
+
+?>
=== modified file 'includes/database.mysql.inc'
--- includes/database.mysql.inc
+++ includes/database.mysql.inc
@@ -51,6 +51,12 @@ function db_connect($url) {
// (matched) rows, not the number of affected rows.
$connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
if (!$connection) {
+ global $install;
+ $install = TRUE;
+ include_once './includes/install.inc';
+ if (!_profile_installed()) {
+ _install_goto('install.php');
+ }
drupal_maintenance_theme();
drupal_set_title('Unable to connect to database server');
print theme('maintenance_page', 'This either means that the username and password information in your settings.php file is incorrect or we can\'t contact the MySQL database server. This could mean your hosting provider\'s database server is down.
This either means that the username and password information in your settings.php file is incorrect or we can\'t contact the MySQL database server through the mysqli libraries. This could also mean your hosting provider\'s database server is down.
The errors above must be resolved before you can install Drupal. Find additional information about Drupal\'s minimum system requirements here.
'); + exit; + } + break; + + // Select an installation profile. + case INSTALL_BOOTSTRAP_PROFILES: + if (_profile_installed() || $_GET['profile']) + continue; + if ($profile = drupal_select_profile()) { + _install_goto("install.php?profile=$profile"); + } + _install_no_profile_error(); + break; + + // Configure settings.php. + case INSTALL_BOOTSTRAP_SETTINGS: + if (_profile_installed()) + continue; + install_verify_settings(); + break; + + // Establish a connection to the database. + case INSTALL_BOOTSTRAP_DATABASE: + if (_profile_installed()) + continue; + install_verify_db(); + if (_install_errors()) { + drupal_maintenance_theme(); + drupal_set_title('Database configuration'); + print theme('install_page', drupal_install_settings_form()); + exit; + } + db_set_active(); + break; + + // Perform actual installation defined in the profile. + case INSTALL_PROFILES: + if (_profile_installed()) + continue; + $profile = $_GET['profile']; + drupal_install_profile($profile); + drupal_install_profile_post($profile); + // We must reload settings.php, it has been rewritten. + _install_goto('install.php'); + break; + + // Perform any special configuration defined by the profile. + case INSTALL_CONFIGURE: + drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + drupal_install_configure(); + _install_goto('install.php?installed=TRUE'); + break; + + } +} + +/** + * Check if there are any errors at this point in the installation process. + * + * @return + * An array of errors, if any. + */ +function _install_errors() { + $messages = drupal_set_message(); + return $messages['error']; +} + +function _install_include_settings_php() { + global $installed_profile, $base_url, $db_prefix, $db_url, $db_type, $active_db; + + require_once './includes/bootstrap.inc'; + include_once './'. conf_path() .'/settings.php'; + +} + +/** + * Test for the existence of $profile in settings.php. + * + * @return + * TRUE/FALSE if $profile exists. + */ +function _profile_installed() { + global $installed_profile; + _install_include_settings_php(); + + if ($installed_profile) { + return $installed_profile; + } + else { + return FALSE; + } +} + +/** + * Send the user to a different installer page. This issues an on-site HTTP + * redirect. Messages (and errors) are erased. + * + * @param $path + * An installer path. + */ +function _install_goto($path) { + header ('Location: '. $path); + exit(); +} + +/** + * Loads the profile definition, extracting the profile's defined name. + * + * @return + * The name defined in the profile's _profile_details() hook. + */ +function _install_profile_name() { + global $profile; + static $name = NULL; + + if (!isset($name)) { + $profile = $profile ? $profile : $_GET['profile']; + if (!$profile && !($profile = _profile_installed())) { + _install_goto('install.php'); + } + require_once "./profiles/$profile.profile"; + // load profile details + $function = $profile .'_profile_details'; + if (function_exists($function)) { + $details = $function(); + } + $name = isset($details['name']) ? $details['name'] : 'Drupal'; + } + + return $name; +} + +/** + * Auto detect the base_url with PHP predefined variables. + * + * @param $file + * The name of the file calling this function so we can strip it out of + * the URI when generating the base_url. + * + * @return + * The auto-detected $base_url that should be configured in settings.php + */ +function drupal_detect_baseurl($file = 'install.php') { + global $profile; + if (!$profile) { + $profile = $_GET['profile']; + } + $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://'; + $host = $_SERVER['SERVER_NAME']; + $port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'. $_SERVER['SERVER_PORT']); + $uri = str_replace("?profile=$profile", '', $_SERVER['REQUEST_URI']); + $dir = str_replace("/$file", '', $uri); + + return "$proto$host$port$dir"; +} + +/** + * Detect all databases supported by Drupal that are compiled into the current + * PHP installation. + * + * @return + * An array of database types compiled into PHP. + */ +function drupal_detect_database_types() { + $databases = array(); + + if (file_exists('./includes/install.mysql.inc')) { + include_once './includes/install.mysql.inc'; + if (mysql_is_available()) { + $databases['mysql'] = 'mysql'; + } + } + if (file_exists('./includes/install.mysqli.inc')) { + include_once './includes/install.mysqli.inc'; + if (mysqli_is_available()) { + $databases['mysqli'] = 'mysqli'; + } + } + if (file_exists('./includes/install.pgsql.inc')) { + include_once './includes/install.pgsql.inc'; + if (pgsql_is_available()) { + $databases['pgsql'] = 'pgsql'; + } + } + + return $databases; +} + +/** + * Verifies that we are able to connect to the defined database, and that we + * have sufficient permissions. + * + * @return + * TRUE/FALSE if we have sufficient permissions. + */ +function install_verify_db() { + global $db_url, $db_type; + + require_once './includes/database.inc'; + + $function = 'drupal_test_'. $db_type; + if (function_exists("$function")) { + return $function($db_url); + } + else { + drupal_set_message(strtr('Installation error: function "%function" does not exist.', array('%function' => $function)), 'error'); + } + return FALSE; +} + +/** + * Read settings.php into a buffer line by line, changing values specified in + * $settings array, then over-writing the old settings.php file. + * + * @param $settings + * An array of settings that need to be updated. + */ +function drupal_rewrite_settings($settings = array(), $prefix = '') { + $settings_file = './'. conf_path() .'/'. $prefix . 'settings.php'; + + $keys = array(); + foreach ($settings as $setting => $data) { + $keys[] = $setting; + } + + $buffer = NULL; + if ($fp = @fopen($settings_file, 'r+')) { + // Step line by line through settings.php + while (!feof($fp)) { + $line = fgets($fp); + // Check for constants + if (substr($line, 0, 7) == 'define(') { + preg_match('/define\(\s*[\'"]([A-Z_-]+)[\'"]\s*,(.*?)\);/', $line, $variable); + if (in_array($variable[1], $keys)) { + $setting = $settings[$variable[1]]; + $buffer .= str_replace($variable[2], " '". $setting['value'] ."'", $line); + unset($settings[$variable[1]]); + unset($settings[$variable[2]]); + } + else { + $buffer .= $line; + } + } + // Check for variables + elseif (substr($line, 0, 1) == '$') { + preg_match('/\$(.*) /U', $line, $variable); + if (in_array($variable[1], $keys)) { + // Write new value to settings.php in the following format: + // $'setting' = 'value'; // 'comment' + $setting = $settings[$variable[1]]; + $buffer .= '$'. $variable[1] ." = '". $setting['value'] ."';". ($setting['comment'] ? ' // '. $setting['comment'] ."\n" : "\n"); + unset($settings[$variable[1]]); + } + else { + $buffer .= $line; + } + } + else { + $buffer .= $line; + } + } + fclose($fp); + + // Add required settings that were missing from settings.php + foreach ($settings as $setting => $data) { + if ($data['required']) { + $buffer .= "\$$setting = '". $data['value'] ."';\n"; + } + } + + $fp = fopen($settings_file, 'w'); + if ($fp && fwrite($fp, $buffer) === FALSE) { + drupal_set_message("Failed to modify $settings_file, please verify the file permissions.", 'error'); + } + } + else { + drupal_set_message("Failed to open $settings_file, please verify the file permissions.", 'error'); + } +} + +/** + * Verify settings.php, rewriting if necessary. + */ +function install_verify_settings() { + global $db_url, $db_prefix, $db_type, $profile; + $settings_file = './'. conf_path() .'/settings.php'; + + if (isset($_POST['save'])) { + $settings['db_url'] = array( + 'value' => $_POST['db_type'] .'://'. $_POST['db_user'] .($_POST['db_pass'] ? ':'. $_POST['db_pass'] : '') .'@'. ($_POST['db_host'] ? $_POST['db_host'] : 'localhost') .'/'. $_POST['db_path'], + 'required' => TRUE, + ); + if (isset($_POST['db_prefix']) && eregi('[^A-Za-z0-9_]+', $_POST['db_prefix'])) { + drupal_set_message('You database prefix you have entered,'. $_POST['db_prefix'] .', is invalid. The database prefix can only contain alphanumeric characters and underscores.', 'error');
+ }
+ $settings['db_prefix'] = array(
+ 'value' => $_POST['db_prefix'],
+ 'required' => TRUE,
+ );
+ drupal_rewrite_settings($settings);
+ }
+
+ include $settings_file;
+
+ // Verify database settings
+ $db_type = substr($db_url, 0, strpos($db_url, '://'));
+ $databases = drupal_detect_database_types();
+ if (!in_array($db_type, $databases)) {
+ drupal_set_message("In your $settings_file file you have configured Drupal to use a $db_type database server, however your PHP installation currently does not support this database type.", 'error');
+ }
+ $url = parse_url($db_url);
+ $db_user = urldecode($url['user']);
+ $db_pass = urldecode($url['pass']);
+ if ($db_user == 'username' && $db_pass == 'password') {
+ if (isset($_POST['save'])) {
+ drupal_set_message(strtr('You have configured %drupal to use the default username and password. This is not allowed for security reasons.', array('%drupal' => _install_profile_name())), 'error');
+ }
+ else {
+ drupal_maintenance_theme();
+ drupal_set_title('Database configuration');
+ print theme('install_page', strtr('Please fill out the following information to configure your %drupal site.
', array('%drupal' => _install_profile_name())). drupal_install_settings_form()); + exit; + } + } +} + +/** + * Displays a simple for to configure settings.php. This form is displayed + * before core Drupal code is bootstrapped, so we have to manually create the + * form, unable to use the Forms API. + * + * @return + * A form for modifying settings.php. + */ +function drupal_install_settings_form() { + global $profile, $db_url, $db_type, $db_prefix; + if (!$profile) { + $profile = $_GET['profile']; + } + $url = parse_url($db_url); + $db_user = urldecode($url['user']); + $db_pass = urldecode($url['pass']); + $db_host = urldecode($url['host']); + $db_path = ltrim(urldecode($url['path']), '/'); + + include_once './includes/form.inc'; + include_once './modules/filter.module'; + + // Database type + $element = array( + '#type' => 'select', + '#title' => 'Database type', + '#value' => $_POST['db_type'], + '#name' => 'db_type', + '#required' => TRUE, + '#options' => drupal_detect_database_types(), + '#description' => strtr('Select the type of database you would like to use with your %drupal installation. If you do not find your preferred database type listed here, verify that the database type is supported by Drupal then confirm that it is properly installed and accessible from PHP. Only properly installed databases that are accessible from PHP and recognized by %drupal are displayed in this menu.', array('%drupal' => _install_profile_name())), + '#parents' => array() + ); + $form .= theme('select', $element); + + // Database username + $element = array( + '#type' => 'textfield', + '#title' => 'Database username', + '#value' => $db_user, + '#name' => 'db_user', + '#size' => 45, + '#maxlength' => 45, + '#required' => TRUE, + '#description' => strtr('The database username that your %drupal installation will use to connect to your database server.', array('%drupal' => _install_profile_name())), + '#parents' => array() + ); + $form .= theme('textfield', $element); + + // Database username + $element = array( + '#type' => 'textfield', + '#title' => 'Database password', + '#value' => $db_pass, + '#name' => 'db_pass', + '#size' => 45, + '#maxlength' => 45, + '#required' => TRUE, + '#description' => strtr('The database username that your %drupal installation will use to connect to your database server.', array('%drupal' => _install_profile_name())), + '#parents' => array() + ); + $form .= theme('textfield', $element); + + // Database name + $element = array( + '#type' => 'textfield', + '#title' => 'Database name', + '#value' => $db_path, + '#name' => 'db_path', + '#size' => 45, + '#maxlength' => 45, + '#required' => TRUE, + '#description' => strtr('The name of the database where %drupal can install its database tables.', array('%drupal' => _install_profile_name())), + '#parents' => array() + ); + $form .= theme('textfield', $element); + + // Database host + $element = array( + '#type' => 'textfield', + '#title' => 'Database host', + '#value' => $db_host, + '#name' => 'db_host', + '#size' => 45, + '#maxlength' => 45, + '#required' => TRUE, + '#description' => strtr('The hostname or IP address of your database server. If your database server is on the same machine as you are installing %drupal, you should probably enter "localhost".', array('%drupal' => _install_profile_name())), + '#parents' => array() + ); + $form .= theme('textfield', $element); + + // Database prefix + $element = array( + '#type' => 'textfield', + '#title' => 'Database prefix', + '#value' => $db_prefix, + '#name' => 'db_prefix', + '#size' => 45, + '#maxlength' => 45, + '#required' => FALSE, + '#description' => 'Optionally set a prefix for all database table names. If a prefix is specified, all table names will be prepended with this value. Only alphanumeric characters and the underscore are allowed. If you do not wish to use a prefix, leave this field empty. If you wish to only prefix specific tables, you will need to manually edit yoursettings.php configuration file.',
+ '#parents' => array()
+ );
+ $form .= theme('textfield', $element);
+
+ $element = array(
+ '#type' => 'submit',
+ '#name' => 'save',
+ '#value' => 'Save configuration',
+ );
+ $form .= theme('submit', $element);
+
+ $element = array(
+ '#action' => "install.php?profile=$profile",
+ '#method' => 'post',
+ '#children' => $form
+ );
+ return theme('form', $element);
+
+ return "';
+}
+
+/**
+ * Find all .profile's and allow admin to select which to install.
+ *
+ * @return
+ * The selected profile.
+ */
+function drupal_select_profile() {
+ include_once './includes/file.inc';
+ include_once './includes/form.inc';
+
+ $profiles = file_scan_directory('./profiles', '\.profile$', array('.', '..', 'CVS'), 0, TRUE, 'name', 0);
+ // Don't need to choose profile if only one available
+ if (sizeof($profiles) == 1) {
+ $profile = array_pop($profiles);
+ require_once $profile->filename;
+ return $profile->name;
+ }
+ elseif (sizeof($profiles) > 1) {
+ drupal_maintenance_theme();
+ $form = '';
+ foreach ($profiles as $profile) {
+ include_once($profile->filename);
+ if ($_POST['profile'] == "$profile->name") {
+ return "$profile->name";
+ }
+ // load profile details
+ $function = $profile->name .'_profile_details';
+ if (function_exists($function)) {
+ $details = $function();
+ }
+
+ // If set, used defined name. Otherwise use file name.
+ $name = isset($details['name']) ? $details['name'] : $profile->name;
+
+ // Build a quick form. We can't use the core forms api because we
+ // aren't able to bootstrap Drupal yet.
+ $element = array(
+ '#type' => 'radio',
+ '#name' => 'profile',
+ '#value' => 'default',
+ '#return_value' => "$profile->name",
+ '#title' => "$name",
+ '#description' => $details['description'],
+ '#parents' => array()
+ );
+ $group = theme('radio', $element);
+
+ $element = array(
+ '#value' => $group,
+ );
+ $form .= theme('fieldset', $element);
+
+ }
+ $element = array(
+ '#type' => 'submit',
+ '#name' => 'save',
+ '#value' => 'Save configuration',
+ );
+ $form .= theme('submit', $element);
+
+ drupal_set_title('Select an installation profile');
+ print theme('install_page', '');
+ exit;
+ }
+ else {
+ return NULL;
+ }
+}
+
+/**
+ * Provide module .installs and profiles a chance to request any additional
+ * configuration. Configuration is performed using the core Forms API,
+ * through the use of _install_configure(), _install_configure_validate(), and
+ * _install_configure_submit() hooks.
+ */
+function drupal_install_configure() {
+ global $installed_profile, $installs;
+ require_once "./profiles/$installed_profile.profile";
+
+ $form = array();
+ drupal_set_title('Configuration');
+
+ $modules = $installed_profile .'_profile_modules';
+ $module_list = $modules();
+ $installs = drupal_get_install_files($module_list);
+ foreach ($installs as $install) {
+ require_once $install->filename;
+ $install_configure = $install->name .'_install_configure';
+ if (function_exists("$install_configure")) {
+ $install_configure($form);
+ }
+ }
+
+ $install_configure = $installed_profile .'_install_configure';
+ if (function_exists("$install_configure")) {
+ $install_configure($form);
+ }
+
+ if ($form != array()) {
+ drupal_maintenance_theme();
+ $form['submit'] = array('#type' => 'submit',
+ '#value' => 'Submit');
+
+ print theme('install_page', drupal_get_form('drupal_install_configure_form', $form));
+ exit;
+ }
+}
+
+/**
+ * Calls _install_configure_validate hook where exists in .install and .profile
+ * files. Treat like the standard forms API _validate hook. Note that the
+ * .profile is called last, so it can modify anything done by module .install
+ * files.
+ *
+ * @param $form_id
+ * @param $edit
+ */
+function drupal_install_configure_form_validate($form_id, $edit, $form) {
+ global $profile, $installs;
+
+ foreach ($installs as $install) {
+ require_once $install->filename;
+ $install_configure_validate = $install->name .'_install_configure_validate';
+ if (function_exists("$install_configure_validate")) {
+ $install_configure_validate($form_id, $edit, $form);
+ }
+ }
+
+ $install_configure_validate = $profile .'_install_configure_validate';
+ if (function_exists("$install_configure_validate")) {
+ $install_configure_validate($form_id, $edit);
+ }
+
+}
+
+/**
+ * Calls _install_configure_submit hook where exists in .install and .profile
+ * files. Treat like the standard forms API _submit hook. Note that the
+ * .profile is called last, so it can modify anything done by module .install
+ * files.
+ *
+ * @param $form_id
+ * @param $edit
+ */
+function drupal_install_configure_form_submit($form_id, $edit) {
+ global $profile, $installs;
+
+ foreach ($installs as $install) {
+ require_once $install->filename;
+ $install_configure_submit = $install->name .'_install_configure_submit';
+ if (function_exists("$install_configure_submit")) {
+ $install_configure_submit($form_id, $edit);
+ }
+ }
+
+ $install_configure_submit = $profile .'_install_configure_submit';
+ if (function_exists("$install_configure_submit")) {
+ $install_configure_submit($form_id, $edit);
+ }
+
+ _install_goto('install.php?installed=TRUE');
+}
+
+/**
+ * Merge table creation scripts. If the same table is defined multiple times,
+ * use the latest version of the schema.
+ */
+function _merge_tables($tables_old, $tables_new) {
+ foreach ($tables_new as $new => $data) {
+ if (isset($tables_old["$new"])) {
+ if ($tables_old["$new"]['schema'] < $data['schema']) {
+ $tables_old["$new"] = $data;
+ }
+ }
+ else {
+ $tables_old["$new"] = $data;
+ }
+ }
+ return $tables_old;
+}
+
+/**
+ * Get list of all .install files.
+ *
+ * @param $module_list
+ * An array of modules to search for their .install files.
+ */
+function drupal_get_install_files($module_list = array()) {
+ $installs = array();
+ foreach ($module_list as $module) {
+ $installs = array_merge($installs, file_scan_directory('./modules', "^$module.install$", array('.', '..', 'CVS'), 0, TRUE, 'name', 0));
+ }
+ return $installs;
+}
+
+/**
+ * An error page to display when there are no profiles available.
+ */
+function _install_no_profile_error() {
+ drupal_maintenance_theme();
+ drupal_set_title('No profiles available');
+ print theme('install_page', 'We were unable to find any installer profiles. Installer profiles tell us what modules to enable, and what schema to install in the database. A profile is necessary to continue with the installation process.
'); + exit; +} + +/** + * Installed profile. + * + * @param profile + * Name of profile to install. + */ +function drupal_install_profile($profile) { + global $db_type; + + include './includes/module.inc'; + include './includes/file.inc'; + + $profile_file = "./profiles/$profile.profile"; + + if (!isset($profile) || !file_exists($profile_file)) { + _install_no_profile_error(); + } + + require_once($profile_file); + + // Get a list of modules required by this profile + $function = $profile .'_profile_modules'; + $module_list = $function(); + + // Verify that all required modules exist + $modules = array(); + foreach ($module_list as $current) { + $module = file_scan_directory('./modules', "^$current.module$", array('.', '..', 'CVS'), 0, TRUE, 'name', 0); + if (empty($module)) { + drupal_set_message("The $current module is required but was not found. Please move the file $current.module into the modules subdirectory.", 'error'); + } + else { + $modules = array_merge($modules, $module); + } + } + + // Get a list of all .install files + $installs = drupal_get_install_files($module_list); + + // Verify the _requirements_pre for this profile and all its modules + $requirements = array(); + $function = $profile .'_requirements_pre'; + if (function_exists("$function")) { + $requirements = $function(); + } + foreach ($installs as $install) { + require_once $install->filename; + $function = $install->name .'_requirements_pre'; + if (function_exists("$function")) { + $function(); + } + } + if (_install_errors()) { + drupal_maintenance_theme(); + drupal_set_title('Verify your install environment'); + print theme('install_page', 'The errors above must be resolved before you can install Drupal. Find additional information about Drupal\'s minimum system requirements here.
'); + exit; + } + + // Install schemas for profile and all its modules + $function = $profile .'_install'; + if (function_exists($function)) { + $function(); + } + + foreach ($installs as $install) { + module_invoke($install->name, 'install'); + } + + // Enable the modules required by the profile + db_query("DELETE FROM {system} WHERE type = 'module'"); + foreach ($modules as $module) { + switch ($db_type) { + case 'mysql': + case 'mysqli': + db_query("INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES('". $module->filename ."', '". $module->name ."', 'module', '', 1, 0, 0, 0)"); + break; + case 'pgsql': + break; + } + } + + // Update settings.php to show that the installer has already been run + $settings = array(); + $settings['installed_profile'] = array( + 'value' => $profile, + 'required' => TRUE + ); + drupal_rewrite_settings($settings); +} + +/** + * Execute the _requirements_post hook in module installs and profiles. + * + * @param $profile + */ +function drupal_install_profile_post($profile = NULL) { + if (!isset($profile)) { + // Nothing to do, exit + return; + } + require_once "./profiles/$profile.profile"; + require_once "./includes/file.inc"; + + // Get a list of modules required by this profile + $function = $profile .'_profile_modules'; + $module_list = $function(); + + // Get a list of all .install files + $installs = drupal_get_install_files($module_list); + + // Verify the _requirements_post for this profile and all its modules + $requirements = array(); + $function = $profile .'_requirements_post'; + if (function_exists("$function")) { + $requirements = $function(); + } + foreach ($installs as $install) { + require_once $install->filename; + $function = $install->name .'_requirements_post'; + if (function_exists("$function")) { + $requirements = _merge_requirements($requirements, $function()); + } + } + drupal_verify_install($requirements); +} + +/** + * Page displayed when the installation is complete. Called from install.php. + */ +function drupal_install_complete() { + global $base_url; + + if (!_profile_installed()) { + // The installer hasn't run before, start at the beginning. + _install_goto('install.php'); + } + + require_once './includes/bootstrap.inc'; + drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + drupal_maintenance_theme(); + drupal_set_title(strtr('%drupal installation complete', array('%drupal' => _install_profile_name()))); + print theme('maintenance_page', strtr('Congratulations, %drupal has been successfully installed. Please review any warnings or errors that you might see above before continuing on to your new website.', array('%drupal' => _install_profile_name(), '%path' => "$base_url"))); +} + +/** + * Call the appropriate installation function. If the function is not + * available, attempt to load the appropriate include file then try again. + * + * @param $requirements + * An array of requirements. + */ +function drupal_verify_install($requirements = array()) { + foreach ($requirements as $type => $data) { + $function = "drupal_verify_install_$type"; + if (function_exists("$function")) { + $function($data); + } + else { + switch ($type) { + case 'mysql': + case 'mysqli': + case 'pgsql': + // The include files for all available database types have already + // been included. Thus, we are not using this database type and this + // requirement does not apply to the current installation. + continue; + case 'apache': + default: + $include = './includes/install.'. $type .'.inc'; + if (file_exists($include)) { + require_once($include); + if (function_exists("$function")) { + $function($data); + } + else { + drupal_set_message(strtr('Installation error: function "%function" does not exist.', array('%function' => $function)), 'error'); + } + } + else { + drupal_set_message(strtr('Installation error: unable to find file "%file", function "%function" does not exist.', array('%file' => $include, '%function' => $function)), 'error'); + } + } + } + } +} + +/** + * Some php.ini options are written in shorthand (ie 1K instead of 1024 bytes). + * This function converts php.ini shorthand into bytes. + * + * @param $shorthand + * A memory string in php.ini shorthand notation (ie 1K, 8M, 10G) + * + * @return + * The shorthand value converted to bytes. + */ +function drupal_shorthand_to_bytes($shorthand) { + static $map = array('g' => 1024 * 1024 * 1024, 'm' => 1024 * 1024, 'k' => 1024); + $result = trim($shorthand); + $modifier = strtolower($result[strlen($result) - 1]); + return isset($map[$modifier]) $map[$modifier] * $result : $result; +} + +/** + * Verify that the installed version of PHP meets our minimum requirements. + * + * @param version + * the version of PHP to verify. Needs to be at least 4.1.0 + * @return + * TRUE if the installed version is equal or or bigger + */ +function drupal_verify_version_php($version) { + // version_compare() was added in PHP 4.1. + return function_exists('version_compare') && version_compare(phpversion(), $version, '>='); +} + +/** + * Verify the state of the specified file. + * + * @param $file + * the file to check for. If it's %settings.php then the actual settings.php will be checked + * @param $mask + * An optional bitmask created from various FILE_* constants. + * @param $message_type + * The type of message to create, can be error or status. Passed on to drupal_set_message as second parameter. + * @param $type + * The type of file. Can be file (default), dir, or link. + * @return + * TRUE on success or FALSE on failure. A messsage is set for the latter. + */ +function drupal_verify_install_file($file, $mask = NULL, $message_type = 'error', $type = 'file') { + if ($file == '%settings.php') + $file = './'. conf_path() .'/settings.php'; + } + + // Check for files that shouldn't be there + if (isset($mask) && ($mask & FILE_NOT_EXIST) && file_exists($file)) { + return FALSE; + } + // Verfiy that the file is the type of file it is supposed to be + if (isset($type) && file_exists($file)) { + $check = 'is_'. $type; + if (!function_exists($check) || !$check($file)) { + drupal_set_message(strtr('%file exists but is not a %type.', array('%type' => $type, '%file' => $file)), $message_type); + return FALSE; + } + } + + // Verify file permissions + if (isset($mask)) { + $filetype = ($filetype == 'dir') ? 'Directory' : ucfirst($type); + $masks = array(FILE_EXIST, FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_EXIST, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE); + foreach ($masks as $current_mask) { + if ($mask & $current_mask) { + switch ($mask) { + case FILE_EXIST: + if (!file_exists($file)) { + if ($filetype == 'Directory') { + drupal_install_mkdir($file, $mask); + } + if (!file_exists($file)) { + drupal_set_message(strtr('%type %file does not exist.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + } + break; + case FILE_READABLE: + if (!is_readable($file) && !drupal_install_fix_file($file, $mask)) { + drupal_set_message(strtr('%type %file is not readable.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + break; + case FILE_WRITABLE: + if (!is_writable($file) && !drupal_install_fix_file($file, $mask)) { + drupal_set_message(strtr('%type %file is not writable.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + break; + case FILE_EXECUTABLE: + if (!is_executable($file) && !drupal_install_fix_file($file, $mask)) { + drupal_set_message(strtr('%type %file is not executable.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + break; + case FILE_NOT_READABLE: + if (is_readable($file) && !drupal_install_fix_file($file, $mask)) { + drupal_set_message(strtr('%type %file is readable but should not be.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + break; + case FILE_NOT_WRITABLE: + if (is_writable($file) && !drupal_install_fix_file($file, $mask)) { + drupal_set_message(strtr('%type %file is writable but should not be.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + break; + case FILE_NOT_EXECUTABLE: + if (is_executable($file) && !drupal_install_fix_file($file, $mask)) { + drupal_set_message(strtr('%type %file is executable but should not be.', array('%type' => $filetype, '%file' => $file)), $message_type); + return FALSE; + } + break; + } + } + } + } +} + +/** + * Create a directory with specified permissions. + * + * @param file + * The name of the directory to create; + * @param mask + * The permissions of the directory to create. + * + * @return + * TRUE/FALSE whether or not the directory was successfully created. + */ +function drupal_install_mkdir($file, $mask) { + $mod = 0; + $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE); + foreach ($masks as $m) { + if ($mask & $m) { + switch ($m) { + case FILE_READABLE: + $mod += 444; + break; + case FILE_WRITABLE: + $mod += 222; + break; + case FILE_EXECUTABLE: + $mod += 111; + break; + } + } + } + + if (@mkdir($file, intval("0$mod", 8))) { + drupal_set_message("Automatically created directory $file.", 'status'); + return TRUE; + } + else { + drupal_set_message("Failed to automatically create directory $file, insufficient privileges.", 'status'); + } +} + +/** + * Attempt to fix file permissions. + * + * @param $file + * The name of the file with permissions to fix. + * @param $mask + * The desired permissions for the file. + * + * @return + * TRUE/FALSE whether or not we were able to fix the file's permissions. + */ +function drupal_install_fix_file($file, $mask) { + $mod = substr(sprintf('%o', fileperms($file)), -4); + $prefix = substr($mod, 0, 1); + $mod = substr($mod, 1 ,4); + $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE); + foreach ($masks as $m) { + if ($mask & $m) { + switch ($m) { + case FILE_READABLE: + if (!is_readable($file)) { + $mod += 444; + } + break; + case FILE_WRITABLE: + if (!is_writable($file)) { + $mod += 222; + } + break; + case FILE_EXECUTABLE: + if (!is_executable($file)) { + $mod += 111; + } + break; + case FILE_NOT_READABLE: + if (is_readable($file)) { + $mod -= 444; + } + break; + case FILE_NOT_WRITABLE: + if (is_writable($file)) { + $mod -= 222; + } + break; + case FILE_NOT_EXECUTABLE: + if (is_executable($file)) { + $mod -= 111; + } + break; + } + } + } + + if (@chmod($file, intval("$prefix$mod", 8))) { + drupal_set_message("Automatically fixed the permissions of file $file.", 'status'); + return TRUE; + } + else { + drupal_set_message("Failed to automatically fix permissions of file $file, insufficient privileges.", 'status'); + return FALSE; + } +} + +/** + * Verify that a function exists. + * + * @param $requirements + * An array with some or all of the following directives: + * 'message' = message to display if the function does not exist. + * 'message_type' = message type (ie, 'error', 'status') + */ +function drupal_verify_install_function($requirements = array()) { + foreach ($requirements as $function => $data) { + if (!function_exists("$function")) { + $message_type = $data['message_type'] ? $data['message_type'] : 'status'; + drupal_set_message($data['message'], $message_type); + } + } +} + +?> === modified file 'includes/theme.inc' --- includes/theme.inc +++ includes/theme.inc @@ -453,17 +453,62 @@ function theme_maintenance_page($content return $output; } +function theme_install_page($content) { + drupal_set_header('Content-Type: text/html; charset=utf-8'); + theme('add_style', 'misc/maintenance.css'); + drupal_set_html_head(''); + $output = "\n"; + $output .= ''; + $output .= '
'; + $output .= '