/** * if we are using a theming system, invoke theme, else just print the * content * * @param string $content the content that will be themed * @param boolean $print are we displaying to the screen or bypassing theming? * @param boolean $maintenance for maintenance mode * * @return void prints content on stdout * @access public */ function theme(&$content, $print = FALSE, $maintenance = FALSE) { $ret = FALSE; // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function // but the parts should be copied into cleaner subclass implementations $config = CRM_Core_Config::singleton(); if ($config->userSystem->is_drupal && function_exists('theme') && !$print) { if ($maintenance) { drupal_set_breadcrumb(''); drupal_maintenance_theme(); if ($region = CRM_Core_Region::instance('html-header', FALSE)) { CRM_Utils_System::addHTMLHead($region->render('')); } print theme('maintenance_page', array('content' => $content)); exit; } $ret = TRUE; // TODO: Figure out why D7 returns but everyone else prints } $out = $content; $config =& CRM_Core_Config::singleton(); if (!$print && $config->userFramework == 'WordPress') { if (is_admin()) { require_once ABSPATH . 'wp-admin/admin-header.php'; } else { // FIX ME: we need to figure out to replace civicrm content on the frontend pages } } if ($ret) { return $out; } else { print $out; } }
/** * if we are using a theming system, invoke theme, else just print the * content * * @param string $type name of theme object/file * @param string $content the content that will be themed * @param array $args the args for the themeing function if any * @param boolean $print are we displaying to the screen or bypassing theming? * @param boolean $ret should we echo or return output * @param boolean $maintenance for maintenance mode * * @return void prints content on stdout * @access public */ function theme($type, &$content, $args = NULL, $print = FALSE, $ret = FALSE, $maintenance = FALSE) { // TODO: Split up; this was copied verbatim from CiviCRM 4.0's multi-UF theming function // but the parts should be copied into cleaner subclass implementations if (function_exists('theme') && !$print) { if ($maintenance) { drupal_set_breadcrumb(''); drupal_maintenance_theme(); print theme('maintenance_page', array('content' => $content)); exit; } $out = $content; $ret = TRUE; } else { $out = $content; } $config =& CRM_Core_Config::singleton(); if (!$print && $config->userFramework == 'WordPress') { if (is_admin()) { require_once ABSPATH . 'wp-admin/admin-header.php'; } else { // FIX ME: we need to figure out to replace civicrm content on the frontend pages } } if ($ret) { return $out; } else { print $out; } }
/** * Tests that the maintenance theme initializes the theme and its base themes. */ public function testMaintenanceTheme() { $this->setSetting('maintenance_theme', 'seven'); // Get the maintenance theme loaded. drupal_maintenance_theme(); // Do we have an active theme? $this->assertTrue(\Drupal::theme()->hasActiveTheme()); $active_theme = \Drupal::theme()->getActiveTheme(); $this->assertEquals('seven', $active_theme->getName()); $base_themes = $active_theme->getBaseThemes(); $base_theme_names = array_keys($base_themes); $this->assertSame(['classy', 'stable'], $base_theme_names); // Ensure Classy has the correct base themes and amount of base themes. $classy_base_themes = $base_themes['classy']->getBaseThemes(); $classy_base_theme_names = array_keys($classy_base_themes); $this->assertSame(['stable'], $classy_base_theme_names); }
/** * if we are using a theming system, invoke theme, else just print the * content * * @param string $type name of theme object/file * @param string $content the content that will be themed * @param array $args the args for the themeing function if any * @param boolean $print are we displaying to the screen or bypassing theming? * @param boolean $ret should we echo or return output * @param boolean $maintenance for maintenance mode * * @return void prints content on stdout * @access public */ function theme($type, &$content, $args = NULL, $print = FALSE, $ret = FALSE, $maintenance = FALSE) { // TODO: Simplify; this was copied verbatim from CiviCRM 3.4's multi-UF theming function, but that's more complex than necessary if (function_exists('theme') && !$print) { if ($maintenance) { drupal_set_breadcrumb(''); drupal_maintenance_theme(); } $out = theme($type, $content, $args); } else { $out = $content; } if ($ret) { return $out; } else { print $out; } }
/** * If we are using a theming system, invoke theme, else just print the * content * * @param string $content * The content that will be themed. * @param bool $print * Are we displaying to the screen or bypassing theming?. * @param bool $maintenance * For maintenance mode. * * @return void * prints content on stdout */ public function theme(&$content, $print = FALSE, $maintenance = FALSE) { // TODO: Simplify; this was copied verbatim from CiviCRM 3.4's multi-UF theming function, but that's more complex than necessary if (function_exists('theme') && !$print) { if ($maintenance) { drupal_set_breadcrumb(''); drupal_maintenance_theme(); } // Arg 3 for D6 theme() is "show_blocks". Previously, we passed // through a badly named variable ("$args") which was almost always // TRUE (except on fatal error screen). However, this feature is // non-functional on D6 default themes, was purposefully removed from // D7, has no analog in other our other CMS's, and clutters the code. // Hard-wiring to TRUE should be OK. $out = theme('page', $content, TRUE); } else { $out = $content; } print $out; }
/** * The Drupal installation happens in a series of steps. We begin by verifying * that the current environment meets our minimum requirements. We then go * on to verify that settings.php is properly configured. From there we * connect to the configured database and verify that it meets our minimum * requirements. Finally we can allow the user to select an installation * profile and complete the installation process. * * @param $phase * The installation phase we should proceed to. */ function install_main() { require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // The user agent header is used to pass a database prefix in the request when // running tests. However, for security reasons, it is imperative that no // installation be permitted using such a prefix. if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); exit; } // This must go after drupal_bootstrap(), which unsets globals! global $profile, $install_locale, $conf; require_once './modules/system/system.install'; require_once './includes/file.inc'; // Ensure correct page headers are sent (e.g. caching) drupal_page_header(); // Set up $language, so t() caller functions will still work. drupal_init_language(); // Load module basics (needed for hook invokes). include_once './includes/module.inc'; $module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; module_list(TRUE, FALSE, FALSE, $module_list); drupal_load('module', 'system'); drupal_load('module', 'filter'); // Install profile chosen, set the global immediately. // This needs to be done before the theme cache gets // initialized in drupal_maintenance_theme(). if (!empty($_GET['profile'])) { $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']); } // Set up theme system for the maintenance page. drupal_maintenance_theme(); // Check existing settings.php. $verify = install_verify_settings(); if ($verify) { // Since we have a database connection, we use the normal cache system. // This is important, as the installer calls into the Drupal system for // the clean URL checks, so we should maintain the cache properly. require_once './includes/cache.inc'; $conf['cache_inc'] = './includes/cache.inc'; // Establish a connection to the database. require_once './includes/database.inc'; db_set_active(); // Check if Drupal is installed. $task = install_verify_drupal(); if ($task == 'done') { install_already_done_error(); } } else { // Since no persistent storage is available yet, and functions that check // for cached data will fail, we temporarily replace the normal cache // system with a stubbed-out version that short-circuits the actual // caching process and avoids any errors. require_once './includes/cache-install.inc'; $conf['cache_inc'] = './includes/cache-install.inc'; $task = NULL; } // No profile was passed in GET, ask the user. if (empty($_GET['profile'])) { if ($profile = install_select_profile()) { install_goto("install.php?profile={$profile}"); } else { install_no_profile_error(); } } // Load the profile. require_once "./profiles/{$profile}/{$profile}.profile"; // Locale selection if (!empty($_GET['locale'])) { $install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']); } elseif (($install_locale = install_select_locale($profile)) !== FALSE) { install_goto("install.php?profile={$profile}&locale={$install_locale}"); } // Tasks come after the database is set up if (!$task) { global $db_url; if (!$verify && !empty($db_url)) { // Do not install over a configured settings.php. install_already_done_error(); } // Check the installation requirements for Drupal and this profile. install_check_requirements($profile, $verify); // Verify existence of all required modules. $modules = drupal_verify_profile($profile, $install_locale); // If any error messages are set now, it means a requirement problem. $messages = drupal_set_message(); if (!empty($messages['error'])) { install_task_list('requirements'); drupal_set_title(st('Requirements problem')); print theme('install_page', ''); exit; } // Change the settings.php information if verification failed earlier. // Note: will trigger a redirect if database credentials change. if (!$verify) { install_change_settings($profile, $install_locale); } // Install system.module. drupal_install_system(); // Save the list of other modules to install for the 'profile-install' // task. variable_set() can be used now that system.module is installed // and drupal is bootstrapped. variable_set('install_profile_modules', array_diff($modules, array('system'))); } // The database is set up, turn to further tasks. install_tasks($profile, $task); }
/** * Installs Atrium instead of Drupal * * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language, $profile, $install_locale; // $language (Drupal 6). // Store necessary current values before switching to prefixed database. $this->originalPrefix = $db_prefix; $this->originalLanguage = clone $language; $clean_url_original = variable_get('clean_url', 0); // Must reset locale here, since schema calls t(). (Drupal 6) if (module_exists('locale')) { $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); locale(NULL, NULL, TRUE); } // Generate temporary prefixed database to ensure that tests have a clean starting point. // $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); $db_prefix = 'simpletest' . mt_rand(1000, 1000000); $install_locale = $this->install_locale; $profile = $this->install_profile; // include_once DRUPAL_ROOT . '/includes/install.inc'; include_once './includes/install.inc'; drupal_install_system(); // $this->preloadRegistry(); // Set up theme system for the maintenance page. // Otherwise we have trouble: https://ds.openatrium.com/dsi/node/18426#comment-38118 // @todo simpletest module patch drupal_maintenance_theme(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); // $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args)); $modules = array_unique(array_merge(drupal_verify_profile($this->install_profile, $this->install_locale), $args)); // drupal_install_modules($modules, TRUE); drupal_install_modules($modules); // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); if ($this->install_profile == 'openatrium') { // Download and import translation if needed if ($this->install_locale != 'en') { $this->installLanguage($this->install_locale); } // Install more modules $modules = _openatrium_atrium_modules(); drupal_install_modules($modules); // Configure intranet // $profile_tasks = $this->install_profile . '_profile_tasks'; _openatrium_intranet_configure(); _openatrium_intranet_configure_check(); variable_set('atrium_install', 1); // Clear views cache before rebuilding menu tree. Requires patch // [patch_here] to Views, as new modules have been included and // default views need to be re-detected. module_exists('views') ? views_get_all_views(TRUE) : TRUE; menu_rebuild(); } _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); user_access(NULL, NULL, TRUE); // Drupal 6. // Log in with a clean $user. $this->originalUser = $user; // drupal_save_session(FALSE); // $user = user_load(1); session_save_session(FALSE); $user = user_load(array('uid' => 1)); // Restore necessary variables. variable_set('install_profile', $this->install_profile); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Use temporary files directory with the same prefix as database. $this->originalFileDirectory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); $directory = file_directory_path(); // Create the files directory. file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); set_time_limit($this->timeLimit); }
$module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; module_list(TRUE, FALSE, $module_list); drupal_load('module', 'system'); drupal_load('module', 'filter'); // Set up $language, since the installer components require it. drupal_init_language(); // Set up theme system for the maintenance page. drupal_maintenance_theme(); // Check the update requirements for Drupal. update_check_requirements(); // Redirect to the update information page if all requirements were met. install_goto('update.php?op=info'); } drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_maintenance_theme(); // Turn error reporting back on. From now on, only fatal errors (which are // not passed through the error handler) will cause a message to be printed. ini_set('display_errors', TRUE); // Only proceed with updates if the user is allowed to run them. if ($update_access_allowed) { include_once DRUPAL_ROOT . '/includes/install.inc'; include_once DRUPAL_ROOT . '/includes/batch.inc'; drupal_load_updates(); update_fix_d7_requirements(); update_fix_compatibility(); $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : ''; switch ($op) { // update.php ops case 'selection': if (isset($_GET['token']) && $_GET['token'] == drupal_get_token('update')) {
/** * Page to check installation requirements and report any errors. */ function install_check_requirements($profile) { $requirements = drupal_check_profile($profile); $severity = drupal_requirements_severity($requirements); // If there are issues, report them. if ($severity == REQUIREMENT_ERROR) { drupal_maintenance_theme(); foreach ($requirements as $requirement) { if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) { drupal_set_message($requirement['description'] . ' (' . st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) . ')', 'error'); } } drupal_set_title(st('Incompatible environment')); print theme('install_page', ''); exit; } }
/** * Begin an installation request, modifying the installation state as needed. * * This function performs commands that must run at the beginning of every page * request. It throws an exception if the installation should not proceed. * * @param $install_state * An array of information about the current installation state. This is * modified with information gleaned from the beginning of the page request. */ function install_begin_request(&$install_state) { // Allow command line scripts to override server variables used by Drupal. require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; if (!$install_state['interactive']) { drupal_override_server_variables($install_state['server']); } // The user agent header is used to pass a database prefix in the request when // running tests. However, for security reasons, it is imperative that no // installation be permitted using such a prefix. if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); exit; } drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // This must go after drupal_bootstrap(), which unsets globals! global $conf; require_once DRUPAL_ROOT . '/modules/system/system.install'; require_once DRUPAL_ROOT . '/includes/common.inc'; require_once DRUPAL_ROOT . '/includes/file.inc'; require_once DRUPAL_ROOT . '/includes/path.inc'; // Set up $language, so t() caller functions will still work. drupal_language_initialize(); // Load module basics (needed for hook invokes). include_once DRUPAL_ROOT . '/includes/module.inc'; include_once DRUPAL_ROOT . '/includes/session.inc'; include_once DRUPAL_ROOT . '/includes/entity.inc'; $module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; $module_list['user']['filename'] = 'modules/user/user.module'; module_list(TRUE, FALSE, FALSE, $module_list); drupal_load('module', 'system'); drupal_load('module', 'filter'); drupal_load('module', 'user'); // Load the cache infrastructure with the Fake Cache. Switch to the database cache // later if possible. require_once DRUPAL_ROOT . '/includes/cache.inc'; require_once DRUPAL_ROOT . '/includes/cache-install.inc'; $conf['cache_inc'] = 'includes/cache.inc'; $conf['cache_default_class'] = 'DrupalFakeCache'; // Prepare for themed output, if necessary. We need to run this at the // beginning of the page request to avoid a different theme accidentally // getting set. if ($install_state['interactive']) { drupal_maintenance_theme(); } // Check existing settings.php. $install_state['settings_verified'] = install_verify_settings(); if ($install_state['settings_verified']) { // Since we have a database connection, we use the normal cache system. // This is important, as the installer calls into the Drupal system for // the clean URL checks, so we should maintain the cache properly. unset($conf['cache_default_class']); // Initialize the database system. Note that the connection // won't be initialized until it is actually requested. require_once DRUPAL_ROOT . '/includes/database/database.inc'; // Verify the last completed task in the database, if there is one. $task = install_verify_completed_task(); } else { $task = NULL; // Since previous versions of Drupal stored database connection information // in the 'db_url' variable, we should never let an installation proceed if // this variable is defined and the settings file was not verified above // (otherwise we risk installing over an existing site whose settings file // has not yet been updated). if (!empty($GLOBALS['db_url'])) { throw new Exception(install_already_done_error()); } } // Modify the installation state as appropriate. $install_state['completed_task'] = $task; $install_state['database_tables_exist'] = !empty($task); // Add any installation parameters passed in via the URL. $install_state['parameters'] += $_GET; // Validate certain core settings that are used throughout the installation. if (!empty($install_state['parameters']['profile'])) { $install_state['parameters']['profile'] = preg_replace('/[^a-zA-Z_0-9]/', '', $install_state['parameters']['profile']); } if (!empty($install_state['parameters']['locale'])) { $install_state['parameters']['locale'] = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $install_state['parameters']['locale']); } }
/** * Returns the site maintenance page if the site is offline. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event * The event to process. */ public function onKernelRequestMaintenance(GetResponseEvent $event) { $route_match = RouteMatch::createFromRequest($event->getRequest()); if ($this->maintenanceMode->applies($route_match)) { // Don't cache maintenance mode pages. \Drupal::service('page_cache_kill_switch')->trigger(); if (!$this->maintenanceMode->exempt($this->account)) { // Deliver the 503 page if the site is in maintenance mode and the // logged in user is not allowed to bypass it. drupal_maintenance_theme(); $content = Xss::filterAdmin(SafeMarkup::format($this->config->get('system.maintenance')->get('message'), array('@site' => $this->config->get('system.site')->get('name')))); $output = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $content], $this->t('Site under maintenance'), 'maintenance_page'); $response = new Response($output, 503); $event->setResponse($response); } else { // Display a message if the logged in user has access to the site in // maintenance mode. However, suppress it on the maintenance mode // settings page. if ($route_match->getRouteName() != 'system.site_maintenance_mode') { if ($this->account->hasPermission('administer site configuration')) { $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE); } else { $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE); } } } } }
/** * if we are using a theming system, invoke theme, else just print the * content * * @param string $type name of theme object/file * @param string $content the content that will be themed * @param array $args the args for the themeing function if any * @param boolean $print are we displaying to the screen or bypassing theming? * @param boolean $ret should we echo or return output * @param boolean $maintenance for maintenance mode * * @return void prints content on stdout * @access public */ function theme($type, &$content, $args = null, $print = false, $ret = false, $maintenance = false) { if (function_exists('theme') && !$print) { if ($maintenance) { drupal_set_breadcrumb(''); drupal_maintenance_theme(); } $out = theme($type, $content, $args); } else { $out = $content; } if ($ret) { return $out; } else { print $out; } }
/** * Returns the site maintenance page if the site is offline. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event * The event to process. */ public function onKernelRequestMaintenance(GetResponseEvent $event) { $request = $event->getRequest(); $route_match = RouteMatch::createFromRequest($request); if ($this->maintenanceMode->applies($route_match)) { // Don't cache maintenance mode pages. \Drupal::service('page_cache_kill_switch')->trigger(); if (!$this->maintenanceMode->exempt($this->account)) { // Deliver the 503 page if the site is in maintenance mode and the // logged in user is not allowed to bypass it. // If the request format is not 'html' then show default maintenance // mode page else show a text/plain page with maintenance message. if ($request->getRequestFormat() !== 'html') { $response = new Response($this->getSiteMaintenanceMessage(), 503, array('Content-Type' => 'text/plain')); $event->setResponse($response); return; } drupal_maintenance_theme(); $response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $this->getSiteMaintenanceMessage()], $this->t('Site under maintenance'), 'maintenance_page'); $response->setStatusCode(503); $event->setResponse($response); } else { // Display a message if the logged in user has access to the site in // maintenance mode. However, suppress it on the maintenance mode // settings page. if ($route_match->getRouteName() != 'system.site_maintenance_mode') { if ($this->account->hasPermission('administer site configuration')) { $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href=":url">Go online.</a>', array(':url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE); } else { $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE); } } } } }
/** * Returns the site maintenance page if the site is offline. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event * The event to process. */ public function onKernelRequestMaintenance(GetResponseEvent $event) { $route_match = RouteMatch::createFromRequest($event->getRequest()); if ($this->maintenanceMode->applies($route_match)) { if (!$this->maintenanceMode->exempt($this->account)) { // Deliver the 503 page if the site is in maintenance mode and the // logged in user is not allowed to bypass it. drupal_maintenance_theme(); $content = Xss::filterAdmin(String::format($this->config->get('system.maintenance')->get('message'), array('@site' => $this->config->get('system.site')->get('name')))); // @todo Break the dependency on DefaultHtmlPageRenderer, see: // https://www.drupal.org/node/2295609 $content = DefaultHtmlPageRenderer::renderPage($content, $this->t('Site under maintenance')); $response = new Response('Service unavailable', 503); $response->setContent($content); $event->setResponse($response); } else { // Display a message if the logged in user has access to the site in // maintenance mode. However, suppress it on the maintenance mode // settings page. if ($route_match->getRouteName() != 'system.site_maintenance_mode') { if ($this->account->hasPermission('administer site configuration')) { $this->drupalSetMessage($this->t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => $this->urlGenerator->generate('system.site_maintenance_mode'))), 'status', FALSE); } else { $this->drupalSetMessage($this->t('Operating in maintenance mode.'), 'status', FALSE); } } } } }
/** * Log a PHP error or exception, display an error page in fatal cases. * * @param $error * An array with the following keys: %type, %message, %function, %file, %line. * @param $fatal * TRUE if the error is fatal. */ function _error_log($error, $fatal = FALSE) { print_r($error); return; // Initialize a maintenance theme if the boostrap was not complete. // Do it early because drupal_set_message() triggers a drupal_theme_initialize(). if ($fatal && drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL) { unset($GLOBALS['theme']); if (!defined('MAINTENANCE_MODE')) { define('MAINTENANCE_MODE', 'error'); } drupal_maintenance_theme(); } // When running inside the testing framework, we relay the errors // to the tested site by the way of HTTP headers. if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^simpletest\\d+;/", $_SERVER['HTTP_USER_AGENT']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) { // $number does not use drupal_static as it should not be reset // as it uniquely identifies each PHP error. static $number = 0; $assertion = array($error['%message'], $error['%type'], array('function' => $error['%function'], 'file' => $error['%file'], 'line' => $error['%line'])); header('X-Drupal-Assertion-' . $number . ': ' . rawurlencode(serialize($assertion))); $number++; } try { watchdog('php', '%type: %message in %function (line %line of %file).', $error, $error['severity_level']); } catch (Exception $e) { // Ignore any additional watchdog exception, as that probably means // that the database was not initialized correctly. } if ($fatal) { drupal_add_http_header('500 Service unavailable (with message)'); } if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { if ($fatal) { // When called from JavaScript, simply output the error message. print t('%type: %message in %function (line %line of %file).', $error); exit; } } else { // Display the message if the current error reporting level allows this type // of message to be displayed, and unconditionnaly in update.php. $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL); $display_error = $error_level == ERROR_REPORTING_DISPLAY_ALL || $error_level == ERROR_REPORTING_DISPLAY_SOME && $error['%type'] != 'Notice'; if ($display_error || defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') { $class = 'error'; // If error type is 'User notice' then treat it as debug information // instead of an error message, see dd(). if ($error['%type'] == 'User notice') { $error['%type'] = 'Debug'; $class = 'status'; } drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), $class); } if ($fatal) { drupal_set_title(t('Error')); // We fallback to a maintenance page at this point, because the page generation // itself can generate errors. print theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.'))); exit; } } }
/** * The Drupal installation happens in a series of steps. We begin by verifying * that the current environment meets our minimum requirements. We then go * on to verify that settings.php is properly configured. From there we * connect to the configured database and verify that it meets our minimum * requirements. Finally we can allow the user to select an installation * profile and complete the installation process. * * @param $phase * The installation phase we should proceed to. */ function install_main() { require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); // The user agent header is used to pass a database prefix in the request when // running tests. However, for security reasons, it is imperative that no // installation be permitted using such a prefix. if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); exit; } // This must go after drupal_bootstrap(), which unsets globals! global $profile, $install_locale, $conf; require_once DRUPAL_ROOT . '/modules/system/system.install'; require_once DRUPAL_ROOT . '/includes/file.inc'; // Ensure correct page headers are sent (e.g. caching) drupal_page_header(); // Set up $language, so t() caller functions will still work. drupal_init_language(); // Load module basics (needed for hook invokes). include_once DRUPAL_ROOT . '/includes/module.inc'; $module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; module_list(TRUE, FALSE, FALSE, $module_list); drupal_load('module', 'system'); drupal_load('module', 'filter'); // Load the cache infrastructure using a "fake" cache implementation that // does not attempt to write to the database. We need this during the initial // part of the installer because the database is not available yet. We // continue to use it even when the database does become available, in order // to preserve consistency between interactive and command-line installations // (the latter complete in one page request and therefore are forced to // continue using the cache implementation they started with) and also // because any data put in the cache during the installer is inherently // suspect, due to the fact that Drupal is not fully set up yet. require_once DRUPAL_ROOT . '/includes/cache-install.inc'; $conf['cache_inc'] = './includes/cache-install.inc'; // Install profile chosen, set the global immediately. // This needs to be done before the theme cache gets // initialized in drupal_maintenance_theme(). if (!empty($_GET['profile'])) { $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']); } // Set up theme system for the maintenance page. drupal_maintenance_theme(); // Check existing settings.php. $verify = install_verify_settings(); if ($verify) { // Establish a connection to the database. require_once DRUPAL_ROOT . '/includes/database.inc'; db_set_active(); // Check if Drupal is installed. $task = install_verify_drupal(); if ($task == 'done') { install_already_done_error(); } } else { $task = NULL; } // No profile was passed in GET, ask the user. if (empty($_GET['profile'])) { if ($profile = install_select_profile()) { install_goto("install.php?profile={$profile}"); } else { install_no_profile_error(); } } // Load the profile. require_once DRUPAL_ROOT . "/profiles/{$profile}/{$profile}.profile"; // Locale selection if (!empty($_GET['locale'])) { $install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']); } elseif (($install_locale = install_select_locale($profile)) !== FALSE) { install_goto("install.php?profile={$profile}&locale={$install_locale}"); } // Tasks come after the database is set up if (!$task) { global $db_url; if (!$verify && !empty($db_url)) { // Do not install over a configured settings.php. install_already_done_error(); } // Check the installation requirements for Drupal and this profile. install_check_requirements($profile, $verify); // Verify existence of all required modules. $modules = drupal_verify_profile($profile, $install_locale); // If any error messages are set now, it means a requirement problem. $messages = drupal_set_message(); if (!empty($messages['error'])) { install_task_list('requirements'); drupal_set_title(st('Requirements problem')); print theme('install_page', ''); exit; } // Change the settings.php information if verification failed earlier. // Note: will trigger a redirect if database credentials change. if (!$verify) { install_change_settings($profile, $install_locale); } // The default lock implementation uses a database table, // so we cannot use it for install, but we still need // the API functions available. require_once './includes/lock-install.inc'; $conf['lock_inc'] = './includes/lock-install.inc'; lock_init(); // Install system.module. drupal_install_system(); // Ensure that all of Drupal's standard directories have appropriate // .htaccess files. These directories will have already been created by // this point in the installer, since Drupal creates them during the // install_check_requirements() task. Note that we cannot create them any // earlier than this, since the code below relies on system.module in order // to work. file_create_htaccess(file_directory_path()); file_create_htaccess(file_directory_temp()); // Save the list of other modules to install for the 'profile-install' // task. variable_set() can be used now that system.module is installed // and drupal is bootstrapped. variable_set('install_profile_modules', array_diff($modules, array('system'))); } // The database is set up, turn to further tasks. install_tasks($profile, $task); }