2010-02-17 04:19:51 +00:00
< ? php
2013-05-02 04:46:53 +00:00
use Drupal\Component\Utility\Crypt ;
2013-04-07 20:06:33 +00:00
use Drupal\Core\Config\FileStorage ;
2012-07-08 23:42:25 +00:00
use Drupal\Core\DrupalKernel ;
2013-06-28 16:11:57 +00:00
use Drupal\Core\CoreServiceProvider ;
2012-01-23 04:47:08 +00:00
use Drupal\Core\Database\Database ;
use Drupal\Core\Database\Install\TaskException ;
2012-08-26 17:01:29 +00:00
use Drupal\Core\Language\Language ;
2013-06-10 16:14:58 +00:00
use Drupal\Core\Language\LanguageManager ;
2013-06-10 11:33:55 +00:00
use Drupal\Core\StringTranslation\Translator\FileTranslation ;
2011-12-28 01:06:42 +00:00
2013-06-28 16:11:57 +00:00
use Drupal\Core\DependencyInjection\ContainerBuilder ;
2012-09-04 13:51:51 +00:00
use Symfony\Component\DependencyInjection\Reference ;
2012-04-01 01:08:15 +00:00
use Symfony\Component\HttpFoundation\Request ;
2012-04-15 18:36:07 +00:00
use Symfony\Component\HttpFoundation\Response ;
2012-04-01 01:08:15 +00:00
2013-02-04 14:53:17 +00:00
use Guzzle\Http\Exception\RequestException ;
2010-02-17 04:19:51 +00:00
/**
* @ file
* API functions for installing Drupal .
*/
/**
2012-08-31 15:56:36 +00:00
* Do not run the task during the current installation request .
2010-02-17 04:19:51 +00:00
*
* This can be used to skip running an installation task when certain
* conditions are met , even though the task may still show on the list of
* installation tasks presented to the user . For example , the Drupal installer
* uses this flag to skip over the database configuration form when valid
* database connection information is already available from settings . php . It
* also uses this flag to skip language import tasks when the installation is
* being performed in English .
*/
2011-11-29 09:56:53 +00:00
const INSTALL_TASK_SKIP = 1 ;
2010-02-17 04:19:51 +00:00
/**
2012-08-31 15:56:36 +00:00
* Run the task on each installation request that reaches it .
2010-02-17 04:19:51 +00:00
*
* This is primarily used by the Drupal installer for bootstrap - related tasks .
*/
2011-11-29 09:56:53 +00:00
const INSTALL_TASK_RUN_IF_REACHED = 2 ;
2010-02-17 04:19:51 +00:00
/**
2012-08-31 15:56:36 +00:00
* Run the task on each installation request until the database is set up .
2010-02-17 04:19:51 +00:00
*
* This is the default method for running tasks and should be used for most
* tasks that occur after the database is set up ; these tasks will then run
* once and be marked complete once they are successfully finished . For
* example , the Drupal installer uses this flag for the batch installation of
* modules on the new site , and also for the configuration form that collects
* basic site information and sets up the site maintenance account .
*/
2011-11-29 09:56:53 +00:00
const INSTALL_TASK_RUN_IF_NOT_COMPLETED = 3 ;
2010-02-17 04:19:51 +00:00
/**
2010-03-26 22:14:46 +00:00
* Installs Drupal either interactively or via an array of passed - in settings .
2010-02-17 04:19:51 +00:00
*
* The Drupal installation happens in a series of steps , which may be spread
* out over multiple page requests . Each request begins by trying to determine
* the last completed installation step ( also known as a " task " ), if one is
* available from a previous request . Control is then passed to the task
* handler , which processes the remaining tasks that need to be run until ( a )
* an error is thrown , ( b ) a new page needs to be displayed , or ( c ) the
* installation finishes ( whichever happens first ) .
*
* @ param $settings
* An optional array of installation settings . Leave this empty for a normal ,
* interactive , browser - based installation intended to occur over multiple
* page requests . Alternatively , if an array of settings is passed in , the
* installer will attempt to use it to perform the installation in a single
* page request ( optimized for the command line ) and not send any output
* intended for the web browser . See install_state_defaults () for a list of
* elements that are allowed to appear in this array .
*
* @ see install_state_defaults ()
*/
function install_drupal ( $settings = array ()) {
global $install_state ;
// Initialize the installation state with the settings that were passed in,
// as well as a boolean indicating whether or not this is an interactive
// installation.
$interactive = empty ( $settings );
$install_state = $settings + array ( 'interactive' => $interactive ) + install_state_defaults ();
try {
// Begin the page request. This adds information about the current state of
// the Drupal installation to the passed-in array.
install_begin_request ( $install_state );
// Based on the installation state, run the remaining tasks for this page
// request, and collect any output.
$output = install_run_tasks ( $install_state );
}
catch ( Exception $e ) {
// When an installation error occurs, either send the error to the web
// browser or pass on the exception so the calling script can use it.
if ( $install_state [ 'interactive' ]) {
install_display_output ( $e -> getMessage (), $install_state );
}
else {
throw $e ;
}
}
2012-09-24 21:08:10 +00:00
// After execution, all tasks might be complete, in which case
// $install_state['installation_finished'] is TRUE. In case the last task
// has been processed, remove the global $install_state, so other code can
// reliably check whether it is running during the installer.
// @see drupal_installation_attempted()
$state = $install_state ;
if ( ! empty ( $install_state [ 'installation_finished' ])) {
2012-09-25 03:15:15 +00:00
unset ( $GLOBALS [ 'install_state' ]);
2012-09-24 21:08:10 +00:00
}
2010-02-17 04:19:51 +00:00
// All available tasks for this page request are now complete. Interactive
// installations can send output to the browser or redirect the user to the
// next page.
2012-09-24 21:08:10 +00:00
if ( $state [ 'interactive' ]) {
if ( $state [ 'parameters_changed' ]) {
2010-02-17 04:19:51 +00:00
// Redirect to the correct page if the URL parameters have changed.
2012-09-24 21:08:10 +00:00
install_goto ( install_redirect_url ( $state ));
2010-02-17 04:19:51 +00:00
}
elseif ( isset ( $output )) {
// Display a page only if some output is available. Otherwise it is
// possible that we are printing a JSON page and theme output should
// not be shown.
2012-09-24 21:08:10 +00:00
install_display_output ( $output , $state );
2010-02-17 04:19:51 +00:00
}
}
}
/**
2010-03-26 22:14:46 +00:00
* Returns an array of default settings for the global installation state .
2010-02-17 04:19:51 +00:00
*
* The installation state is initialized with these settings at the beginning
* of each page request . They may evolve during the page request , but they are
* initialized again once the next request begins .
*
* Non - interactive Drupal installations can override some of these default
* settings by passing in an array to the installation script , most notably
* 'parameters' ( which contains one - time parameters such as 'profile' and
2011-11-25 06:22:29 +00:00
* 'langcode' that are normally passed in via the URL ) and 'forms' ( which can
2010-02-17 04:19:51 +00:00
* be used to programmatically submit forms during the installation ; the keys
* of each element indicate the name of the installation task that the form
* submission is for , and the values are used as the $form_state [ 'values' ]
* array that is passed on to the form submission via drupal_form_submit ()) .
*
* @ see drupal_form_submit ()
*/
function install_state_defaults () {
$defaults = array (
// The current task being processed.
'active_task' => NULL ,
// The last task that was completed during the previous installation
// request.
'completed_task' => NULL ,
2012-05-20 06:41:16 +00:00
// This becomes TRUE only when a valid config directory is created or
// detected.
'config_verified' => FALSE ,
2010-02-17 04:19:51 +00:00
// This becomes TRUE only when Drupal's system module is installed.
'database_tables_exist' => FALSE ,
2012-05-20 06:41:16 +00:00
// This becomes TRUE only when a valid database connection can be
// established.
'database_verified' => FALSE ,
2013-01-10 17:18:17 +00:00
// Whether a translation file for the selected language will be downloaded
// from the translation server.
'download_translation' => FALSE ,
2010-02-17 04:19:51 +00:00
// An array of forms to be programmatically submitted during the
// installation. The keys of each element indicate the name of the
// installation task that the form submission is for, and the values are
// used as the $form_state['values'] array that is passed on to the form
// submission via drupal_form_submit().
'forms' => array (),
// This becomes TRUE only at the end of the installation process, after
// all available tasks have been completed and Drupal is fully installed.
// It is used by the installer to store correct information in the database
// about the completed installation, as well as to inform theme functions
// that all tasks are finished (so that the task list can be displayed
// correctly).
'installation_finished' => FALSE ,
// Whether or not this installation is interactive. By default this will
// be set to FALSE if settings are passed in to install_drupal().
'interactive' => TRUE ,
// An array of parameters for the installation, pre-populated by the URL
// or by the settings passed in to install_drupal(). This is primarily
// used to store 'profile' (the name of the chosen installation profile)
2011-11-25 06:22:29 +00:00
// and 'langcode' (the code of the chosen installation language), since
2010-02-17 04:19:51 +00:00
// these settings need to persist from page request to page request before
// the database is available for storage.
'parameters' => array (),
// Whether or not the parameters have changed during the current page
// request. For interactive installations, this will trigger a page
// redirect.
'parameters_changed' => FALSE ,
// An array of information about the chosen installation profile. This will
2013-03-06 22:51:39 +00:00
// be filled in based on the profile's .info.yml file.
2010-02-17 04:19:51 +00:00
'profile_info' => array (),
// An array of available installation profiles.
'profiles' => array (),
// An array of server variables that will be substituted into the global
// $_SERVER array via drupal_override_server_variables(). Used by
// non-interactive installations only.
'server' => array (),
2013-01-10 17:18:17 +00:00
// The server URL where the interface translation files can be downloaded.
// Tokens in the pattern will be replaced by appropriate values for the
// required translation file.
'server_pattern' => 'http://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po' ,
2012-05-20 06:41:16 +00:00
// This becomes TRUE only when a valid settings.php file is written
// (containing both valid database connection information and a valid
// config directory).
2010-02-17 04:19:51 +00:00
'settings_verified' => FALSE ,
// Installation tasks can set this to TRUE to force the page request to
// end (even if there is no themable output), in the case of an interactive
// installation. This is needed only rarely; for example, it would be used
// by an installation task that prints JSON output rather than returning a
// themed page. The most common example of this is during batch processing,
// but the Drupal installer automatically takes care of setting this
// parameter properly in that case, so that individual installation tasks
// which implement the batch API do not need to set it themselves.
'stop_page_request' => FALSE ,
// Installation tasks can set this to TRUE to indicate that the task should
// be run again, even if it normally wouldn't be. This can be used, for
// example, if a single task needs to be spread out over multiple page
// requests, or if it needs to perform some validation before allowing
// itself to be marked complete. The most common examples of this are batch
// processing and form submissions, but the Drupal installer automatically
// takes care of setting this parameter properly in those cases, so that
// individual installation tasks which implement the batch API or form API
// do not need to set it themselves.
'task_not_complete' => FALSE ,
// A list of installation tasks which have already been performed during
// the current page request.
'tasks_performed' => array (),
2013-01-10 17:18:17 +00:00
// An array of translation files URIs available for the installation. Keyed
// by the translation language code.
'translations' => array (),
2010-02-17 04:19:51 +00:00
);
return $defaults ;
}
/**
2012-08-31 15:56:36 +00:00
* Begins an installation request , modifying the installation state as needed .
2010-02-17 04:19:51 +00:00
*
* 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 ) {
2010-05-29 08:02:58 +00:00
// Add any installation parameters passed in via the URL.
2012-09-24 21:08:10 +00:00
if ( $install_state [ 'interactive' ]) {
$install_state [ 'parameters' ] += $_GET ;
}
2010-05-29 08:02:58 +00:00
// 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' ]);
}
2011-11-25 06:22:29 +00:00
if ( ! empty ( $install_state [ 'parameters' ][ 'langcode' ])) {
$install_state [ 'parameters' ][ 'langcode' ] = preg_replace ( '/[^a-zA-Z_0-9\-]/' , '' , $install_state [ 'parameters' ][ 'langcode' ]);
2010-05-29 08:02:58 +00:00
}
2010-02-17 04:19:51 +00:00
// Allow command line scripts to override server variables used by Drupal.
2013-03-17 06:36:36 +00:00
require_once __DIR__ . '/bootstrap.inc' ;
2011-12-28 01:06:42 +00:00
2010-02-17 04:19:51 +00:00
if ( ! $install_state [ 'interactive' ]) {
drupal_override_server_variables ( $install_state [ 'server' ]);
}
2012-08-23 11:21:24 +00:00
// Initialize conf_path().
// This primes the site path to be used during installation. By not requiring
// settings.php, a bare site folder can be prepared in the /sites directory,
// which will be used for installing Drupal.
conf_path ( FALSE );
2010-02-17 04:19:51 +00:00
drupal_bootstrap ( DRUPAL_BOOTSTRAP_CONFIGURATION );
2013-06-02 10:54:03 +00:00
// If the hash salt leaks, it becomes possible to forge a valid testing user
// agent, install a new copy of Drupal, and take over the original site. To
// avoid this yet allow for automated testing of the installer, make sure
// there is also a special test-specific settings.php overriding conf_path().
// _drupal_load_test_overrides() sets the simpletest_conf_path in-memory
// setting in this case.
if ( $install_state [ 'interactive' ] && drupal_valid_test_ua () && ! settings () -> get ( 'simpletest_conf_path' )) {
header ( $_SERVER [ 'SERVER_PROTOCOL' ] . ' 403 Forbidden' );
exit ;
}
2012-04-01 01:08:15 +00:00
// A request object from the HTTPFoundation to tell us about the request.
$request = Request :: createFromGlobals ();
2010-02-17 04:19:51 +00:00
// This must go after drupal_bootstrap(), which unsets globals!
global $conf ;
2013-05-02 09:03:16 +00:00
// If we have a language selected and it is not yet saved in the system
// (eg. pre-database data screens we are unable to persistently store
// the default language), we should set language_default so the proper
// language is used to display installer pages as early as possible.
2013-06-29 10:56:53 +00:00
// The language list is stored in configuration and cannot be saved either
// until later in the process. Language negotiation bootstrapping needs
// the new default language to be in the list though, so inject it in.
if ( ! empty ( $install_state [ 'parameters' ][ 'langcode' ]) && language_default () -> id != $install_state [ 'parameters' ][ 'langcode' ]) {
$GLOBALS [ 'conf' ][ 'language_default' ] = array ( 'id' => $install_state [ 'parameters' ][ 'langcode' ]);
$languages = & drupal_static ( 'language_list' );
$languages [ $install_state [ 'parameters' ][ 'langcode' ]] = new Language ( $GLOBALS [ 'conf' ][ 'language_default' ]);
2013-05-02 09:03:16 +00:00
}
2013-05-09 09:25:10 +00:00
require_once __DIR__ . '/../modules/system/system.install' ;
require_once __DIR__ . '/common.inc' ;
require_once __DIR__ . '/file.inc' ;
require_once __DIR__ . '/install.inc' ;
require_once __DIR__ . '/schema.inc' ;
require_once __DIR__ . '/../../' . settings () -> get ( 'path_inc' , 'core/includes/path.inc' );
2010-02-17 04:19:51 +00:00
// Load module basics (needed for hook invokes).
2013-05-09 09:25:10 +00:00
include_once __DIR__ . '/module.inc' ;
include_once __DIR__ . '/session.inc' ;
require_once __DIR__ . '/entity.inc' ;
2010-02-17 04:19:51 +00:00
2012-09-04 13:51:51 +00:00
// Determine whether the configuration system is ready to operate.
$install_state [ 'config_verified' ] = install_verify_config_directory ( CONFIG_ACTIVE_DIRECTORY ) && install_verify_config_directory ( CONFIG_STAGING_DIRECTORY );
2013-06-17 13:35:07 +00:00
// Create a minimal container for t() to work.
// This container will be overriden but it needed for the very early
// installation process when database tasks run.
$container = new ContainerBuilder ();
// Register the translation services.
install_register_translation_service ( $container );
Drupal :: setContainer ( $container );
2012-11-29 20:55:21 +00:00
// Check existing settings.php.
$install_state [ 'database_verified' ] = install_verify_database_settings ();
$install_state [ 'settings_verified' ] = $install_state [ 'config_verified' ] && $install_state [ 'database_verified' ];
2012-09-04 13:51:51 +00:00
// If it is not, replace the configuration storage with the InstallStorage
// implementation, for the following reasons:
// - The first call into drupal_container() will try to set up the regular
// runtime configuration storage, using the CachedStorage by default. It
// calls config_get_config_directory() to retrieve the config directory to
// use, but that throws an exception, since $config_directories is not
// defined since there is no settings.php yet. If there is a prepared
// settings.php already, then the returned directory still cannot be used,
// because it does not necessarily exist. The installer ensures that it
// exists and is writeable in a later step.
// - The installer outputs maintenance theme pages and performs many other
// operations, which try to load configuration. Since there is no active
// configuration yet, and because the configuration system does not have a
// notion of default values at runtime, data is missing in many places. The
// lack of data does not trigger errors, but results in a broken user
// interface (e.g., missing page title, etc).
// - The actual configuration data to read during installation is essentially
// the default configuration provided by the installation profile and
// modules (most notably System module). The InstallStorage therefore reads
// from the default configuration directories of extensions.
2012-11-29 20:55:21 +00:00
// This override is reverted as soon as the config directory and the
// database has been set up successfully.
2012-09-04 13:51:51 +00:00
// @see drupal_install_config_directories()
2012-11-29 20:55:21 +00:00
// @see install_settings_form_submit()
if ( $install_state [ 'settings_verified' ]) {
2013-06-28 16:11:57 +00:00
$kernel = new DrupalKernel ( 'install' , drupal_classloader (), FALSE );
2012-11-29 20:55:21 +00:00
$kernel -> boot ();
2013-06-17 13:35:07 +00:00
$container = $kernel -> getContainer ();
// Add the file translation service to the container.
$container -> set ( 'string_translator.file_translation' , install_file_translation_service ());
$container -> get ( 'string_translation' ) -> addTranslator ( $container -> get ( 'string_translator.file_translation' ));
2012-11-29 20:55:21 +00:00
}
else {
2012-09-04 13:51:51 +00:00
// @todo Move into a proper Drupal\Core\DependencyInjection\InstallContainerBuilder.
$container = new ContainerBuilder ();
2012-12-26 18:20:15 +00:00
$container -> register ( 'event_dispatcher' , 'Symfony\Component\EventDispatcher\EventDispatcher' );
2012-09-04 13:51:51 +00:00
$container -> register ( 'config.storage' , 'Drupal\Core\Config\InstallStorage' );
2013-02-27 09:49:26 +00:00
$container -> register ( 'config.context.factory' , 'Drupal\Core\Config\Context\ConfigContextFactory' )
-> addArgument ( new Reference ( 'event_dispatcher' ));
$container -> register ( 'config.context' , 'Drupal\Core\Config\Context\ContextInterface' )
-> setFactoryService ( new Reference ( 'config.context.factory' ))
-> setFactoryMethod ( 'get' );
2012-09-04 13:51:51 +00:00
$container -> register ( 'config.factory' , 'Drupal\Core\Config\ConfigFactory' )
-> addArgument ( new Reference ( 'config.storage' ))
2013-02-27 09:49:26 +00:00
-> addArgument ( new Reference ( 'config.context' ));
2013-01-21 19:21:34 +00:00
2013-02-01 20:29:29 +00:00
// Register the 'language_manager' service.
2013-07-20 19:39:11 +00:00
$container
-> register ( 'language_manager' , 'Drupal\Core\Language\LanguageManager' )
-> addArgument ( NULL );
2013-06-10 11:33:55 +00:00
// Register the translation services.
2013-06-17 13:35:07 +00:00
install_register_translation_service ( $container );
2013-06-10 11:33:55 +00:00
Issue #512026 by Berdir, effulgentsia, sun, marcingy, Eric_A, xjm, katbailey, Damien Tournoud, alexpott, beejeebus, pillarsdotnet: Move () storage from cache to new state/key-value system.
2013-03-27 18:57:12 +00:00
foreach ( array ( 'bootstrap' , 'config' , 'cache' , 'menu' , 'page' , 'path' ) as $bin ) {
2013-03-22 09:36:55 +00:00
$container
-> register ( " cache. $bin " , 'Drupal\Core\Cache\MemoryBackend' )
-> addArgument ( $bin );
}
2013-02-01 20:29:29 +00:00
2013-01-11 11:14:30 +00:00
// The install process cannot use the database lock backend since the database
// is not fully up, so we use a null backend implementation during the
// installation process. This will also speed up the installation process.
// The site being installed will use the real lock backend when doing AJAX
// requests but, except for a WSOD, there is no chance for a a lock to stall
// (as opposed to the cache backend) so we can afford having a null
// implementation here.
$container -> register ( 'lock' , 'Drupal\Core\Lock\NullLockBackend' );
2013-01-21 19:21:34 +00:00
// Register a module handler for managing enabled modules.
$container
-> register ( 'module_handler' , 'Drupal\Core\Extension\ModuleHandler' );
2013-02-13 12:28:12 +00:00
// Register the Guzzle HTTP client for fetching translation files from a
// remote translation server such as localization.drupal.org.
$container -> register ( 'http_default_client' , 'Guzzle\Http\Client' )
-> addArgument ( NULL )
-> addArgument ( array (
'curl.CURLOPT_TIMEOUT' => 30.0 ,
'curl.CURLOPT_MAXREDIRS' => 3 ,
))
-> addMethodCall ( 'setUserAgent' , array ( 'Drupal (+http://drupal.org/)' ));
Issue #512026 by Berdir, effulgentsia, sun, marcingy, Eric_A, xjm, katbailey, Damien Tournoud, alexpott, beejeebus, pillarsdotnet: Move () storage from cache to new state/key-value system.
2013-03-27 18:57:12 +00:00
// Register the expirable key value store used by form cache.
$container
-> register ( 'keyvalue.expirable' , 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory' )
-> addArgument ( new Reference ( 'service_container' ));
$container
-> register ( 'keyvalue.expirable.null' , 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory' );
$conf [ 'keyvalue_expirable_default' ] = 'keyvalue.expirable.null' ;
2013-03-29 18:02:49 +00:00
// Register Twig template engine for use during install.
2013-06-28 16:11:57 +00:00
CoreServiceProvider :: registerTwig ( $container );
2013-03-29 18:02:49 +00:00
2013-06-06 08:14:16 +00:00
$container -> register ( 'url_generator' , 'Drupal\Core\Routing\NullGenerator' );
2013-07-04 08:38:19 +00:00
// Register the CSS and JavaScript asset collection renderers.
$container -> register ( 'asset.css.collection_renderer' , 'Drupal\Core\Asset\CssCollectionRenderer' );
$container -> register ( 'asset.js.collection_renderer' , 'Drupal\Core\Asset\JsCollectionRenderer' );
2012-09-04 13:51:51 +00:00
}
2013-07-06 14:59:24 +00:00
// Set the request in the kernel to the new created Request above
// so it is available to the rest of the installation process.
$container -> set ( 'request' , $request );
Drupal :: setContainer ( $container );
2012-09-04 13:51:51 +00:00
2010-02-17 04:19:51 +00:00
// Set up $language, so t() caller functions will still work.
2012-07-24 04:06:56 +00:00
drupal_language_initialize ();
2013-06-10 11:33:55 +00:00
// Add in installation language if present.
if ( isset ( $install_state [ 'parameters' ][ 'langcode' ])) {
Drupal :: translation () -> setDefaultLangcode ( $install_state [ 'parameters' ][ 'langcode' ]);
}
2010-02-17 04:19:51 +00:00
2013-05-09 09:25:10 +00:00
require_once __DIR__ . '/ajax.inc' ;
2013-01-21 19:21:34 +00:00
2013-06-05 01:58:17 +00:00
$module_handler = Drupal :: moduleHandler ();
2013-01-21 19:21:34 +00:00
if ( ! $module_handler -> moduleExists ( 'system' )) {
// Override the module list with a minimal set of modules.
$module_handler -> setModuleList ( array ( 'system' => 'core/modules/system/system.module' ));
}
$module_handler -> load ( 'system' );
2010-02-17 04:19:51 +00:00
2013-05-09 09:25:10 +00:00
require_once __DIR__ . '/cache.inc' ;
2010-02-17 04:19:51 +00:00
2010-09-14 21:42:05 +00:00
// Prepare for themed output. We need to run this at the beginning of the
// page request to avoid a different theme accidentally getting set. (We also
// need to run it even in the case of command-line installations, to prevent
// any code in the installer that happens to initialize the theme system from
// accessing the database before it is set up yet.)
drupal_maintenance_theme ();
2010-02-17 04:19:51 +00:00
2012-05-20 06:41:16 +00:00
if ( $install_state [ 'database_verified' ]) {
2010-02-17 04:19:51 +00:00
// Initialize the database system. Note that the connection
// won't be initialized until it is actually requested.
2013-05-09 09:25:10 +00:00
require_once __DIR__ . '/database.inc' ;
2010-02-17 04:19:51 +00:00
// Verify the last completed task in the database, if there is one.
$task = install_verify_completed_task ();
}
else {
$task = NULL ;
2013-02-09 02:11:05 +00:00
// Do not install over a configured settings.php.
if ( ! empty ( $GLOBALS [ 'databases' ])) {
2010-02-17 04:19:51 +00:00
throw new Exception ( install_already_done_error ());
}
}
2013-04-07 20:06:33 +00:00
// Ensure that the active configuration directory is empty before installation
// starts.
if ( $install_state [ 'config_verified' ] && empty ( $task )) {
$config = glob ( config_get_config_directory ( CONFIG_ACTIVE_DIRECTORY ) . '/*.' . FileStorage :: getFileExtension ());
if ( ! empty ( $config )) {
$task = NULL ;
throw new Exception ( install_already_done_error ());
}
}
2010-02-17 04:19:51 +00:00
// Modify the installation state as appropriate.
$install_state [ 'completed_task' ] = $task ;
$install_state [ 'database_tables_exist' ] = ! empty ( $task );
2011-11-25 06:22:29 +00:00
// Add the list of available profiles to the installation state.
2012-08-10 09:18:18 +00:00
$install_state [ 'profiles' ] += drupal_system_listing ( '/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.profile$/' , 'profiles' );
2010-02-17 04:19:51 +00:00
}
/**
2010-03-26 22:14:46 +00:00
* Runs all tasks for the current installation request .
2010-02-17 04:19:51 +00:00
*
* In the case of an interactive installation , all tasks will be attempted
* until one is reached that has output which needs to be displayed to the
* user , or until a page redirect is required . Otherwise , tasks will be
* attempted until the installation is finished .
*
* @ param $install_state
* An array of information about the current installation state . This is
* passed along to each task , so it can be modified if necessary .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* HTML output from the last completed task .
*/
function install_run_tasks ( & $install_state ) {
do {
// Obtain a list of tasks to perform. The list of tasks itself can be
// dynamic (e.g., some might be defined by the installation profile,
// which is not necessarily known until the earlier tasks have run),
// so we regenerate the remaining tasks based on the installation state,
// each time through the loop.
$tasks_to_perform = install_tasks_to_perform ( $install_state );
// Run the first task on the list.
reset ( $tasks_to_perform );
$task_name = key ( $tasks_to_perform );
$task = array_shift ( $tasks_to_perform );
$install_state [ 'active_task' ] = $task_name ;
$original_parameters = $install_state [ 'parameters' ];
$output = install_run_task ( $task , $install_state );
$install_state [ 'parameters_changed' ] = ( $install_state [ 'parameters' ] != $original_parameters );
// Store this task as having been performed during the current request,
// and save it to the database as completed, if we need to and if the
// database is in a state that allows us to do so. Also mark the
// installation as 'done' when we have run out of tasks.
if ( ! $install_state [ 'task_not_complete' ]) {
$install_state [ 'tasks_performed' ][] = $task_name ;
$install_state [ 'installation_finished' ] = empty ( $tasks_to_perform );
if ( $install_state [ 'database_tables_exist' ] && ( $task [ 'run' ] == INSTALL_TASK_RUN_IF_NOT_COMPLETED || $install_state [ 'installation_finished' ])) {
2012-11-04 09:53:56 +00:00
variable_set ( 'install_task' , $install_state [ 'installation_finished' ] ? 'done' : $task_name );
2010-02-17 04:19:51 +00:00
}
}
// Stop when there are no tasks left. In the case of an interactive
// installation, also stop if we have some output to send to the browser,
// the URL parameters have changed, or an end to the page request was
// specifically called for.
$finished = empty ( $tasks_to_perform ) || ( $install_state [ 'interactive' ] && ( isset ( $output ) || $install_state [ 'parameters_changed' ] || $install_state [ 'stop_page_request' ]));
} while ( ! $finished );
return $output ;
}
/**
2010-03-26 22:14:46 +00:00
* Runs an individual installation task .
2010-02-17 04:19:51 +00:00
*
* @ param $task
* An array of information about the task to be run .
* @ param $install_state
* An array of information about the current installation state . This is
* passed in by reference so that it can be modified by the task .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* The output of the task function , if there is any .
*/
function install_run_task ( $task , & $install_state ) {
$function = $task [ 'function' ];
if ( $task [ 'type' ] == 'form' ) {
2013-05-09 09:25:10 +00:00
require_once __DIR__ . '/form.inc' ;
2010-02-17 04:19:51 +00:00
if ( $install_state [ 'interactive' ]) {
// For interactive forms, build the form and ensure that it will not
// redirect, since the installer handles its own redirection only after
// marking the form submission task complete.
$form_state = array (
// We need to pass $install_state by reference in order for forms to
// modify it, since the form API will use it in call_user_func_array(),
// which requires that referenced variables be passed explicitly.
'build_info' => array ( 'args' => array ( & $install_state )),
'no_redirect' => TRUE ,
);
$form = drupal_build_form ( $function , $form_state );
// If a successful form submission did not occur, the form needs to be
// rendered, which means the task is not complete yet.
if ( empty ( $form_state [ 'executed' ])) {
$install_state [ 'task_not_complete' ] = TRUE ;
return drupal_render ( $form );
}
// Otherwise, return nothing so the next task will run in the same
// request.
return ;
}
else {
// For non-interactive forms, submit the form programmatically with the
// values taken from the installation state. Throw an exception if any
// errors were encountered.
2010-04-23 07:50:28 +00:00
$form_state = array (
'values' => ! empty ( $install_state [ 'forms' ][ $function ]) ? $install_state [ 'forms' ][ $function ] : array (),
// We need to pass $install_state by reference in order for forms to
// modify it, since the form API will use it in call_user_func_array(),
// which requires that referenced variables be passed explicitly.
'build_info' => array ( 'args' => array ( & $install_state )),
);
drupal_form_submit ( $function , $form_state );
2010-02-17 04:19:51 +00:00
$errors = form_get_errors ();
if ( ! empty ( $errors )) {
throw new Exception ( implode ( " \n " , $errors ));
}
}
}
elseif ( $task [ 'type' ] == 'batch' ) {
// Start a new batch based on the task function, if one is not running
// already.
2012-11-04 09:53:56 +00:00
$current_batch = variable_get ( 'install_current_batch' );
2010-02-17 04:19:51 +00:00
if ( ! $install_state [ 'interactive' ] || ! $current_batch ) {
$batch = $function ( $install_state );
if ( empty ( $batch )) {
// If the task did some processing and decided no batch was necessary,
// there is nothing more to do here.
return ;
}
batch_set ( $batch );
// For interactive batches, we need to store the fact that this batch
// task is currently running. Otherwise, we need to make sure the batch
// will complete in one page request.
if ( $install_state [ 'interactive' ]) {
2012-11-04 09:53:56 +00:00
variable_set ( 'install_current_batch' , $function );
2010-02-17 04:19:51 +00:00
}
else {
$batch =& batch_get ();
$batch [ 'progressive' ] = FALSE ;
}
// Process the batch. For progressive batches, this will redirect.
// Otherwise, the batch will complete.
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
$response = batch_process ( install_redirect_url ( $install_state ), install_full_redirect_url ( $install_state ));
if ( $response instanceof Response ) {
// Save $_SESSION data from batch.
drupal_session_commit ();
// Send the response.
$response -> send ();
exit ;
}
2010-02-17 04:19:51 +00:00
}
// If we are in the middle of processing this batch, keep sending back
// any output from the batch process, until the task is complete.
elseif ( $current_batch == $function ) {
2013-05-09 09:25:10 +00:00
include_once __DIR__ . '/batch.inc' ;
2010-02-17 04:19:51 +00:00
$output = _batch_page ();
2012-04-15 22:55:18 +00:00
// Because Batch API now returns a JSON response for intermediary steps,
2012-05-10 21:00:55 +00:00
// but the installer doesn't handle Response objects yet, just send the
// output here and emulate the old model.
// @todo Replace this when we refactor the installer to use a request-
// response workflow.
2012-04-15 18:36:07 +00:00
if ( $output instanceof Response ) {
$output -> send ();
2012-04-15 22:55:18 +00:00
$output = NULL ;
2012-04-15 18:36:07 +00:00
}
2010-02-17 04:19:51 +00:00
// The task is complete when we try to access the batch page and receive
// FALSE in return, since this means we are at a URL where we are no
// longer requesting a batch ID.
2012-04-15 22:55:18 +00:00
if ( $output === FALSE ) {
2010-02-17 04:19:51 +00:00
// Return nothing so the next task will run in the same request.
2012-11-04 09:53:56 +00:00
variable_del ( 'install_current_batch' );
2010-02-17 04:19:51 +00:00
return ;
}
else {
// We need to force the page request to end if the task is not
// complete, since the batch API sometimes prints JSON output
// rather than returning a themed page.
$install_state [ 'task_not_complete' ] = $install_state [ 'stop_page_request' ] = TRUE ;
return $output ;
}
}
}
else {
// For normal tasks, just return the function result, whatever it is.
return $function ( $install_state );
}
}
/**
2010-03-26 22:14:46 +00:00
* Returns a list of tasks to perform during the current installation request .
2010-02-17 04:19:51 +00:00
*
* Note that the list of tasks can change based on the installation state as
* the page request evolves ( for example , if an installation profile hasn ' t
* been selected yet , we don ' t yet know which profile tasks need to be run ) .
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* A list of tasks to be performed , with associated metadata .
*/
function install_tasks_to_perform ( $install_state ) {
// Start with a list of all currently available tasks.
$tasks = install_tasks ( $install_state );
foreach ( $tasks as $name => $task ) {
// Remove any tasks that were already performed or that never should run.
// Also, if we started this page request with an indication of the last
// task that was completed, skip that task and all those that come before
// it, unless they are marked as always needing to run.
if ( $task [ 'run' ] == INSTALL_TASK_SKIP || in_array ( $name , $install_state [ 'tasks_performed' ]) || ( ! empty ( $install_state [ 'completed_task' ]) && empty ( $completed_task_found ) && $task [ 'run' ] != INSTALL_TASK_RUN_IF_REACHED )) {
unset ( $tasks [ $name ]);
}
if ( ! empty ( $install_state [ 'completed_task' ]) && $name == $install_state [ 'completed_task' ]) {
$completed_task_found = TRUE ;
}
}
return $tasks ;
}
/**
2010-03-26 22:14:46 +00:00
* Returns a list of all tasks the installer currently knows about .
2010-02-17 04:19:51 +00:00
*
* This function will return tasks regardless of whether or not they are
* intended to run on the current page request . However , the list can change
* based on the installation state ( for example , if an installation profile
* hasn 't been selected yet, we don' t yet know which profile tasks will be
* available ) .
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* A list of tasks , with associated metadata .
*/
function install_tasks ( $install_state ) {
2013-01-10 17:18:17 +00:00
// Determine whether a translation file must be imported during the
// 'install_import_translations' task. Import when a non-English language is
// available and selected.
2011-11-25 06:22:29 +00:00
$needs_translations = count ( $install_state [ 'translations' ]) > 1 && ! empty ( $install_state [ 'parameters' ][ 'langcode' ]) && $install_state [ 'parameters' ][ 'langcode' ] != 'en' ;
2013-01-10 17:18:17 +00:00
// Determine whether a translation file must be downloaded during the
// 'install_download_translation' task. Download when a non-English language
// is selected, but no translation is yet in the translations directory.
$needs_download = isset ( $install_state [ 'parameters' ][ 'langcode' ]) && ! isset ( $install_state [ 'translations' ][ $install_state [ 'parameters' ][ 'langcode' ]]) && $install_state [ 'parameters' ][ 'langcode' ] != 'en' ;
2010-02-17 04:19:51 +00:00
2012-01-04 05:47:07 +00:00
// Start with the core installation tasks that run before handing control
2012-10-05 16:11:15 +00:00
// to the installation profile.
2010-02-17 04:19:51 +00:00
$tasks = array (
2011-11-25 06:22:29 +00:00
'install_select_language' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Choose language' ),
2011-11-25 06:22:29 +00:00
'run' => INSTALL_TASK_RUN_IF_REACHED ,
),
2013-01-10 17:18:17 +00:00
'install_download_translation' => array (
'run' => $needs_download ? INSTALL_TASK_RUN_IF_REACHED : INSTALL_TASK_SKIP ,
),
2010-02-17 04:19:51 +00:00
'install_select_profile' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Choose profile' ),
2010-02-17 04:19:51 +00:00
'display' => count ( $install_state [ 'profiles' ]) != 1 ,
'run' => INSTALL_TASK_RUN_IF_REACHED ,
),
'install_load_profile' => array (
'run' => INSTALL_TASK_RUN_IF_REACHED ,
),
'install_verify_requirements' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Verify requirements' ),
2010-02-17 04:19:51 +00:00
),
'install_settings_form' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Set up database' ),
2010-02-17 04:19:51 +00:00
'type' => 'form' ,
2012-05-20 06:41:16 +00:00
// Even though the form only allows the user to enter database settings,
// we still need to display it if settings.php is invalid in any way,
// since the form submit handler is where settings.php is rewritten.
2010-02-17 04:19:51 +00:00
'run' => $install_state [ 'settings_verified' ] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED ,
),
2012-05-20 06:41:16 +00:00
'install_base_system' => array (
2010-02-17 04:19:51 +00:00
),
'install_bootstrap_full' => array (
'run' => INSTALL_TASK_RUN_IF_REACHED ,
),
'install_profile_modules' => array (
2013-06-17 13:35:07 +00:00
'display_name' => count ( $install_state [ 'profiles' ]) == 1 ? t ( 'Install site' ) : t ( 'Installation profile' ),
2010-02-17 04:19:51 +00:00
'type' => 'batch' ,
),
2011-11-25 06:22:29 +00:00
'install_import_translations' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Set up translations' ),
2010-02-17 04:19:51 +00:00
'display' => $needs_translations ,
'type' => 'batch' ,
'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP ,
),
'install_configure_form' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Configure site' ),
2010-02-17 04:19:51 +00:00
'type' => 'form' ,
),
);
// Now add any tasks defined by the installation profile.
if ( ! empty ( $install_state [ 'parameters' ][ 'profile' ])) {
2011-11-08 13:12:52 +00:00
// Load the profile install file, because it is not always loaded when
// hook_install_tasks() is invoked (e.g. batch processing).
2012-08-10 09:18:18 +00:00
$profile = $install_state [ 'parameters' ][ 'profile' ];
$profile_install_file = dirname ( $install_state [ 'profiles' ][ $profile ] -> uri ) . '/' . $profile . '.install' ;
2011-11-08 13:12:52 +00:00
if ( file_exists ( $profile_install_file )) {
include_once $profile_install_file ;
}
2010-02-17 04:19:51 +00:00
$function = $install_state [ 'parameters' ][ 'profile' ] . '_install_tasks' ;
if ( function_exists ( $function )) {
$result = $function ( $install_state );
if ( is_array ( $result )) {
$tasks += $result ;
}
}
}
// Finish by adding the remaining core tasks.
$tasks += array (
2011-11-25 06:22:29 +00:00
'install_import_translations_remaining' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Finish translations' ),
2010-02-17 04:19:51 +00:00
'display' => $needs_translations ,
'type' => 'batch' ,
'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP ,
),
2013-04-23 07:19:41 +00:00
'install_update_configuration_translations' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Translate configuration' ),
2013-04-23 07:19:41 +00:00
'display' => $needs_translations ,
'type' => 'batch' ,
'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP ,
),
2010-02-17 04:19:51 +00:00
'install_finished' => array (
2013-06-17 13:35:07 +00:00
'display_name' => t ( 'Finished' ),
2010-02-17 04:19:51 +00:00
),
);
// Allow the installation profile to modify the full list of tasks.
if ( ! empty ( $install_state [ 'parameters' ][ 'profile' ])) {
2012-08-10 09:18:18 +00:00
$profile = $install_state [ 'parameters' ][ 'profile' ];
$profile_file = $install_state [ 'profiles' ][ $profile ] -> uri ;
2011-11-08 13:12:52 +00:00
if ( file_exists ( $profile_file )) {
2010-02-17 04:19:51 +00:00
include_once $profile_file ;
$function = $install_state [ 'parameters' ][ 'profile' ] . '_install_tasks_alter' ;
if ( function_exists ( $function )) {
$function ( $tasks , $install_state );
}
}
}
// Fill in default parameters for each task before returning the list.
foreach ( $tasks as $task_name => & $task ) {
$task += array (
'display_name' => NULL ,
'display' => ! empty ( $task [ 'display_name' ]),
'type' => 'normal' ,
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED ,
'function' => $task_name ,
);
}
return $tasks ;
}
/**
2010-03-26 22:14:46 +00:00
* Returns a list of tasks that should be displayed to the end user .
2010-02-17 04:19:51 +00:00
*
* The output of this function is a list suitable for sending to
* theme_task_list () .
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* A list of tasks , with keys equal to the machine - readable task name and
* values equal to the name that should be displayed .
*
* @ see theme_task_list ()
*/
function install_tasks_to_display ( $install_state ) {
$displayed_tasks = array ();
foreach ( install_tasks ( $install_state ) as $name => $task ) {
if ( $task [ 'display' ]) {
$displayed_tasks [ $name ] = $task [ 'display_name' ];
}
}
return $displayed_tasks ;
}
/**
2010-03-26 22:14:46 +00:00
* Returns the URL that should be redirected to during an installation request .
2010-02-17 04:19:51 +00:00
*
* The output of this function is suitable for sending to install_goto () .
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* The URL to redirect to .
*
* @ see install_full_redirect_url ()
*/
function install_redirect_url ( $install_state ) {
2011-10-31 04:05:57 +00:00
return 'core/install.php?' . drupal_http_build_query ( $install_state [ 'parameters' ]);
2010-02-17 04:19:51 +00:00
}
/**
2010-03-26 22:14:46 +00:00
* Returns the complete URL redirected to during an installation request .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* The complete URL to redirect to .
*
* @ see install_redirect_url ()
*/
function install_full_redirect_url ( $install_state ) {
global $base_url ;
return $base_url . '/' . install_redirect_url ( $install_state );
}
/**
2010-03-26 22:14:46 +00:00
* Displays themed installer output and ends the page request .
2010-02-17 04:19:51 +00:00
*
* Installation tasks should use drupal_set_title () to set the desired page
* title , but otherwise this function takes care of theming the overall page
* output during every step of the installation .
*
* @ param $output
* The content to display on the main part of the page .
* @ param $install_state
* An array of information about the current installation state .
*/
function install_display_output ( $output , $install_state ) {
drupal_page_header ();
2012-09-05 12:53:41 +00:00
// Prevent install.php from being indexed when installed in a sub folder.
// robots.txt rules are not read if the site is within domain.com/subfolder
// resulting in /subfolder/install.php being found through search engines.
// When settings.php is writeable this can be used via an external database
// leading a malicious user to gain php access to the server.
$noindex_meta_tag = array (
'#tag' => 'meta' ,
'#attributes' => array (
'name' => 'robots' ,
'content' => 'noindex, nofollow' ,
),
);
drupal_add_html_head ( $noindex_meta_tag , 'install_meta_robots' );
2010-02-17 04:19:51 +00:00
// Only show the task list if there is an active task; otherwise, the page
// request has ended before tasks have even been started, so there is nothing
// meaningful to show.
if ( isset ( $install_state [ 'active_task' ])) {
// Let the theming function know when every step of the installation has
// been completed.
$active_task = $install_state [ 'installation_finished' ] ? NULL : $install_state [ 'active_task' ];
2013-06-27 19:03:01 +00:00
drupal_add_region_content ( 'sidebar_first' , theme ( 'task_list' , array ( 'items' => install_tasks_to_display ( $install_state ), 'active' => $active_task , 'variant' => 'install' )));
2010-02-17 04:19:51 +00:00
}
2010-06-05 12:02:33 +00:00
print theme ( 'install_page' , array ( 'content' => $output ));
2010-02-17 04:19:51 +00:00
exit ;
}
/**
2012-08-31 15:56:36 +00:00
* Verifies the requirements for installing Drupal .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* A themed status report , or an exception if there are requirement errors .
*/
function install_verify_requirements ( & $install_state ) {
// Check the installation requirements for Drupal and this profile.
$requirements = install_check_requirements ( $install_state );
// Verify existence of all required modules.
$requirements += drupal_verify_profile ( $install_state );
2013-01-10 17:18:17 +00:00
return install_display_requirements ( $install_state , $requirements );
2010-02-17 04:19:51 +00:00
}
/**
2012-05-20 06:41:16 +00:00
* Installation task ; install the base functionality Drupal needs to bootstrap .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
*/
2012-05-20 06:41:16 +00:00
function install_base_system ( & $install_state ) {
2010-02-17 04:19:51 +00:00
// Install system.module.
drupal_install_system ();
2010-03-01 07:39:12 +00:00
2012-05-20 06:41:16 +00:00
// Call file_ensure_htaccess() to ensure that all of Drupal's standard
// directories (e.g., the public files directory and config directory) have
// appropriate .htaccess files. These directories will have already been
// created by this point in the installer, since Drupal creates them during
// the install_verify_requirements() task. Note that we cannot call
// file_ensure_access() any earlier than this, since it relies on
// system.module in order to work.
file_ensure_htaccess ();
2010-03-01 07:39:12 +00:00
// Enable the user module so that sessions can be recorded during the
// upcoming bootstrap step.
module_enable ( array ( 'user' ), FALSE );
2010-02-17 04:19:51 +00:00
// Save the list of other modules to install for the upcoming tasks.
2010-03-01 07:39:12 +00:00
// variable_set() can be used now that system.module is installed.
2010-02-17 04:19:51 +00:00
$modules = $install_state [ 'profile_info' ][ 'dependencies' ];
2012-10-05 16:11:15 +00:00
// The installation profile is also a module, which needs to be installed
2010-02-17 04:19:51 +00:00
// after all the dependencies have been installed.
$modules [] = drupal_get_profile ();
2013-06-05 14:24:40 +00:00
Drupal :: state () -> set ( 'install_profile_modules' , array_diff ( $modules , array ( 'system' )));
2010-02-17 04:19:51 +00:00
$install_state [ 'database_tables_exist' ] = TRUE ;
}
/**
2012-08-31 15:56:36 +00:00
* Verifies and returns the last installation task that was completed .
2010-02-17 04:19:51 +00:00
*
* @ return
* The last completed task , if there is one . An exception is thrown if Drupal
* is already installed .
*/
function install_verify_completed_task () {
2012-11-04 09:53:56 +00:00
try {
if ( $result = db_query ( " SELECT value FROM { variable} WHERE name = :name " , array ( 'name' => 'install_task' ))) {
$task = unserialize ( $result -> fetchField ());
}
}
// Do not trigger an error if the database query fails, since the database
// might not be set up yet.
catch ( Exception $e ) {
}
if ( isset ( $task )) {
2010-02-17 04:19:51 +00:00
if ( $task == 'done' ) {
throw new Exception ( install_already_done_error ());
}
return $task ;
}
}
/**
2012-05-20 06:41:16 +00:00
* Verifies that settings . php specifies a valid database connection .
2010-02-17 04:19:51 +00:00
*/
2012-05-20 06:41:16 +00:00
function install_verify_database_settings () {
2010-06-28 19:57:34 +00:00
global $databases ;
2012-10-05 15:52:57 +00:00
if ( ! empty ( $databases )) {
2010-02-17 04:19:51 +00:00
$database = $databases [ 'default' ][ 'default' ];
drupal_static_reset ( 'conf_path' );
$settings_file = './' . conf_path ( FALSE ) . '/settings.php' ;
$errors = install_database_errors ( $database , $settings_file );
if ( empty ( $errors )) {
return TRUE ;
}
}
return FALSE ;
}
/**
2012-08-31 15:56:36 +00:00
* Form constructor for a form to configure and rewrite settings . php .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2012-08-31 15:56:36 +00:00
* @ see install_settings_form_validate ()
* @ see install_settings_form_submit ()
2012-10-05 18:12:56 +00:00
* @ ingroup forms
2010-02-17 04:19:51 +00:00
*/
function install_settings_form ( $form , & $form_state , & $install_state ) {
2010-06-28 19:57:34 +00:00
global $databases ;
2010-02-17 04:19:51 +00:00
drupal_static_reset ( 'conf_path' );
$conf_path = './' . conf_path ( FALSE );
$settings_file = $conf_path . '/settings.php' ;
$database = isset ( $databases [ 'default' ][ 'default' ]) ? $databases [ 'default' ][ 'default' ] : array ();
2013-06-17 13:35:07 +00:00
drupal_set_title ( t ( 'Database configuration' ));
2010-02-17 04:19:51 +00:00
2010-11-29 02:55:57 +00:00
$drivers = drupal_get_database_types ();
2010-04-21 08:56:06 +00:00
$drivers_keys = array_keys ( $drivers );
2010-02-17 04:19:51 +00:00
2010-02-26 06:39:13 +00:00
$form [ 'driver' ] = array (
'#type' => 'radios' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Database type' ),
2010-02-26 06:39:13 +00:00
'#required' => TRUE ,
2010-04-21 08:56:06 +00:00
'#default_value' => ! empty ( $database [ 'driver' ]) ? $database [ 'driver' ] : current ( $drivers_keys ),
2013-06-17 13:35:07 +00:00
'#description' => t ( 'The type of database your @drupal data will be stored in.' , array ( '@drupal' => drupal_install_profile_distribution_name ())),
2010-02-26 06:39:13 +00:00
);
if ( count ( $drivers ) == 1 ) {
$form [ 'driver' ][ '#disabled' ] = TRUE ;
2013-06-17 13:35:07 +00:00
$form [ 'driver' ][ '#description' ] .= ' ' . t ( 'Your PHP configuration only supports a single database type, so it has been automatically selected.' );
2010-02-17 04:19:51 +00:00
}
2010-11-29 02:55:57 +00:00
// Add driver specific configuration options.
foreach ( $drivers as $key => $driver ) {
$form [ 'driver' ][ '#options' ][ $key ] = $driver -> name ();
$form [ 'settings' ][ $key ] = $driver -> getFormOptions ( $database );
2013-06-17 13:35:07 +00:00
$form [ 'settings' ][ $key ][ '#prefix' ] = '<h2 class="js-hide">' . t ( '@driver_name settings' , array ( '@driver_name' => $driver -> name ())) . '</h2>' ;
2010-11-29 02:55:57 +00:00
$form [ 'settings' ][ $key ][ '#type' ] = 'container' ;
$form [ 'settings' ][ $key ][ '#tree' ] = TRUE ;
$form [ 'settings' ][ $key ][ 'advanced_options' ][ '#parents' ] = array ( $key );
$form [ 'settings' ][ $key ][ '#states' ] = array (
'visible' => array (
':input[name=driver]' => array ( 'value' => $key ),
)
);
}
2010-02-17 04:19:51 +00:00
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-02-26 06:39:13 +00:00
$form [ 'actions' ][ 'save' ] = array (
'#type' => 'submit' ,
2013-06-17 13:35:07 +00:00
'#value' => t ( 'Save and continue' ),
2010-11-29 02:55:57 +00:00
'#limit_validation_errors' => array (
array ( 'driver' ),
array ( isset ( $form_state [ 'input' ][ 'driver' ]) ? $form_state [ 'input' ][ 'driver' ] : current ( $drivers_keys )),
),
'#submit' => array ( 'install_settings_form_submit' ),
2010-02-26 06:39:13 +00:00
);
$form [ 'errors' ] = array ();
$form [ 'settings_file' ] = array ( '#type' => 'value' , '#value' => $settings_file );
2010-02-17 04:19:51 +00:00
return $form ;
}
/**
2012-08-31 15:56:36 +00:00
* Form validation handler for install_settings_form () .
*
* @ see install_settings_form_submit ()
2010-02-17 04:19:51 +00:00
*/
function install_settings_form_validate ( $form , & $form_state ) {
2010-11-29 02:55:57 +00:00
$driver = $form_state [ 'values' ][ 'driver' ];
$database = $form_state [ 'values' ][ $driver ];
2013-06-02 10:54:03 +00:00
// When testing the interactive installer, copy the database password and
// the test prefix.
if ( $test_prefix = drupal_valid_test_ua ()) {
$database [ 'prefix' ] = $test_prefix ;
$database [ 'password' ] = $GLOBALS [ 'databases' ][ 'default' ][ 'default' ][ 'password' ];
}
2013-02-15 19:08:38 +00:00
$drivers = drupal_get_database_types ();
$reflection = new \ReflectionClass ( $drivers [ $driver ]);
$install_namespace = $reflection -> getNamespaceName ();
// Cut the trailing \Install from namespace.
$database [ 'namespace' ] = substr ( $install_namespace , 0 , strrpos ( $install_namespace , '\\' ));
2010-11-29 02:55:57 +00:00
$database [ 'driver' ] = $driver ;
2013-06-02 10:54:03 +00:00
// @todo PIFR uses 'db_prefix' instead of 'prefix'. Remove this when it gets
// fixed.
if ( ! $test_prefix ) {
$database [ 'prefix' ] = $database [ 'db_prefix' ];
}
2010-11-29 02:55:57 +00:00
unset ( $database [ 'db_prefix' ]);
2010-06-28 19:57:34 +00:00
2010-11-29 02:55:57 +00:00
$form_state [ 'storage' ][ 'database' ] = $database ;
$errors = install_database_errors ( $database , $form_state [ 'values' ][ 'settings_file' ]);
2010-02-17 04:19:51 +00:00
foreach ( $errors as $name => $message ) {
form_set_error ( $name , $message );
}
}
/**
2010-03-26 22:14:46 +00:00
* Checks a database connection and returns any errors .
2010-02-17 04:19:51 +00:00
*/
function install_database_errors ( $database , $settings_file ) {
global $databases ;
$errors = array ();
2010-03-26 22:14:46 +00:00
// Check database type.
2010-11-29 02:55:57 +00:00
$database_types = drupal_get_database_types ();
2010-02-17 04:19:51 +00:00
$driver = $database [ 'driver' ];
if ( ! isset ( $database_types [ $driver ])) {
2013-06-17 13:35:07 +00:00
$errors [ 'driver' ] = t ( " In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type. " , array ( '%settings_file' => $settings_file , '@drupal' => drupal_install_profile_distribution_name (), '%driver' => $driver ));
2010-02-17 04:19:51 +00:00
}
else {
2010-11-29 02:55:57 +00:00
// Run driver specific validation
$errors += $database_types [ $driver ] -> validateDatabaseSettings ( $database );
2010-02-17 04:19:51 +00:00
// Run tasks associated with the database type. Any errors are caught in the
2010-03-26 22:14:46 +00:00
// calling function.
2010-02-17 04:19:51 +00:00
$databases [ 'default' ][ 'default' ] = $database ;
// Just changing the global doesn't get the new information processed.
2012-05-20 06:41:16 +00:00
// We need to close any active connections and tell the Database class to
// re-parse $databases.
if ( Database :: isActiveConnection ()) {
Database :: closeConnection ();
}
2010-02-17 04:19:51 +00:00
Database :: parseConnectionInfo ();
try {
2010-11-29 02:55:57 +00:00
db_run_tasks ( $driver );
2010-02-17 04:19:51 +00:00
}
2011-12-28 01:06:42 +00:00
catch ( TaskException $e ) {
2010-02-17 04:19:51 +00:00
// These are generic errors, so we do not have any specific key of the
// database connection array to attach them to; therefore, we just put
// them in the error array with standard numeric keys.
2010-11-29 02:55:57 +00:00
$errors [ $driver . '][0' ] = $e -> getMessage ();
2010-02-17 04:19:51 +00:00
}
}
return $errors ;
}
/**
2012-08-31 15:56:36 +00:00
* Form submission handler for install_settings_form () .
*
* @ see install_settings_form_validate ()
2010-02-17 04:19:51 +00:00
*/
function install_settings_form_submit ( $form , & $form_state ) {
2012-07-18 10:01:11 +00:00
global $install_state ;
2010-02-17 04:19:51 +00:00
2010-03-26 22:14:46 +00:00
// Update global settings array and save.
2013-06-02 10:54:03 +00:00
$settings = array ();
$database = $form_state [ 'storage' ][ 'database' ];
// Ideally, there is no difference between the code executed by the
// automated test browser and an ordinary browser. However, the database
// settings need a different format and also need to skip the password
// when testing. The hash salt also needs to be skipped because the original
// salt is used to verify the validity of the automated test browser.
// Because of these, there's a little difference in the code following but
// it is small and self-contained.
if ( $test_prefix = drupal_valid_test_ua ()) {
foreach ( $form_state [ 'storage' ][ 'database' ] as $k => $v ) {
if ( $k != 'password' ) {
$settings [ 'databases' ][ 'default' ][ 'default' ][ $k ] = ( object ) array (
'value' => $v ,
'required' => TRUE ,
);
}
}
}
else {
$settings [ 'databases' ][ 'default' ][ 'default' ] = ( object ) array (
'value' => $database ,
'required' => TRUE ,
);
$settings [ 'drupal_hash_salt' ] = ( object ) array (
'value' => Crypt :: randomStringHashed ( 55 ),
'required' => TRUE ,
);
}
2012-01-08 01:29:22 +00:00
2010-02-17 04:19:51 +00:00
drupal_rewrite_settings ( $settings );
2012-02-16 21:08:44 +00:00
2012-08-30 17:30:12 +00:00
// Add the config directories to settings.php.
drupal_install_config_directories ();
2012-02-16 21:08:44 +00:00
2010-02-17 04:19:51 +00:00
// Indicate that the settings file has been verified, and check the database
// for the last completed task, now that we have a valid connection. This
// last step is important since we want to trigger an error if the new
// database already has Drupal installed.
$install_state [ 'settings_verified' ] = TRUE ;
2012-05-20 06:41:16 +00:00
$install_state [ 'config_verified' ] = TRUE ;
$install_state [ 'database_verified' ] = TRUE ;
2010-02-17 04:19:51 +00:00
$install_state [ 'completed_task' ] = install_verify_completed_task ();
}
/**
2012-08-31 15:56:36 +00:00
* Selects which profile to install .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state . The chosen
* profile will be added here , if it was not already selected previously , as
* will a list of all available profiles .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* For interactive installations , a form allowing the profile to be selected ,
* if the user has a choice that needs to be made . Otherwise , an exception is
* thrown if a profile cannot be chosen automatically .
*/
function install_select_profile ( & $install_state ) {
if ( empty ( $install_state [ 'parameters' ][ 'profile' ])) {
// Try to find a profile.
$profile = _install_select_profile ( $install_state [ 'profiles' ]);
if ( empty ( $profile )) {
// We still don't have a profile, so display a form for selecting one.
// Only do this in the case of interactive installations, since this is
// not a real form with submit handlers (the database isn't even set up
// yet), rather just a convenience method for setting parameters in the
// URL.
if ( $install_state [ 'interactive' ]) {
2013-05-09 09:25:10 +00:00
include_once __DIR__ . '/form.inc' ;
2013-06-17 13:35:07 +00:00
drupal_set_title ( t ( 'Select an installation profile' ));
2012-08-10 09:18:18 +00:00
$form = drupal_get_form ( 'install_select_profile_form' , $install_state );
2010-02-17 04:19:51 +00:00
return drupal_render ( $form );
}
else {
throw new Exception ( install_no_profile_error ());
}
}
else {
$install_state [ 'parameters' ][ 'profile' ] = $profile ;
}
}
}
/**
2012-10-19 07:49:18 +00:00
* Selects an installation profile .
*
* A profile will be selected if :
* - Only one profile is available ,
* - A profile was submitted through $_POST ,
* - Exactly one of the profiles is marked as " exclusive " .
* If multiple profiles are marked as " exclusive " then no profile will be
* selected .
*
* @ param array $profiles
* An associative array of profiles with the machine - readable names as keys .
*
* @ return
* The machine - readable name of the selected profile or NULL if no profile was
* selected .
2010-02-17 04:19:51 +00:00
*/
function _install_select_profile ( $profiles ) {
// Don't need to choose profile if only one available.
2012-08-10 09:18:18 +00:00
if ( count ( $profiles ) == 1 ) {
2010-02-17 04:19:51 +00:00
$profile = array_pop ( $profiles );
return $profile -> name ;
}
2012-08-10 09:18:18 +00:00
elseif ( ! empty ( $_POST [ 'profile' ]) && isset ( $profiles [ $_POST [ 'profile' ]])) {
return $profiles [ $_POST [ 'profile' ]] -> name ;
2010-02-17 04:19:51 +00:00
}
2012-10-19 07:49:18 +00:00
// Check for a profile marked as "exclusive" and ensure that only one
// profile is marked as such.
$exclusive_profile = NULL ;
foreach ( $profiles as $profile ) {
$profile_info = install_profile_info ( $profile -> name );
if ( ! empty ( $profile_info [ 'exclusive' ])) {
if ( empty ( $exclusive_profile )) {
$exclusive_profile = $profile -> name ;
}
else {
// We found a second "exclusive" profile. There's no way to choose
// between them, so we ignore the property.
return ;
}
}
}
return $exclusive_profile ;
2010-02-17 04:19:51 +00:00
}
/**
2012-08-31 15:56:36 +00:00
* Form constructor for the profile selection form .
2010-02-17 04:19:51 +00:00
*
2012-08-10 09:18:18 +00:00
* @ param array $install_state
* An array of information about the current installation state .
2012-10-05 18:12:56 +00:00
*
* @ ingroup forms
2010-02-17 04:19:51 +00:00
*/
2012-08-10 09:18:18 +00:00
function install_select_profile_form ( $form , & $form_state , $install_state ) {
2010-02-17 04:19:51 +00:00
$profiles = array ();
$names = array ();
2012-08-10 09:18:18 +00:00
foreach ( $install_state [ 'profiles' ] as $profile ) {
2010-02-17 04:19:51 +00:00
$details = install_profile_info ( $profile -> name );
2013-05-07 13:51:26 +00:00
// Skip this extension if its type is not profile.
if ( ! isset ( $details [ 'type' ]) || $details [ 'type' ] != 'profile' ) {
continue ;
}
2010-08-22 15:31:18 +00:00
// Don't show hidden profiles. This is used by to hide the testing profile,
// which only exists to speed up test runs.
if ( $details [ 'hidden' ] === TRUE ) {
continue ;
}
2010-02-17 04:19:51 +00:00
$profiles [ $profile -> name ] = $details ;
// Determine the name of the profile; default to file name if defined name
// is unspecified.
$name = isset ( $details [ 'name' ]) ? $details [ 'name' ] : $profile -> name ;
$names [ $profile -> name ] = $name ;
}
// Display radio buttons alphabetically by human-readable name, but always
// put the core profiles first (if they are present in the filesystem).
natcasesort ( $names );
if ( isset ( $names [ 'minimal' ])) {
// If the expert ("Minimal") core profile is present, put it in front of
// any non-core profiles rather than including it with them alphabetically,
// since the other profiles might be intended to group together in a
// particular way.
$names = array ( 'minimal' => $names [ 'minimal' ]) + $names ;
}
if ( isset ( $names [ 'standard' ])) {
// If the default ("Standard") core profile is present, put it at the very
// top of the list. This profile will have its radio button pre-selected,
// so we want it to always appear at the top.
$names = array ( 'standard' => $names [ 'standard' ]) + $names ;
}
2013-01-30 03:38:25 +00:00
// The profile name and description are extracted for translation from the
2013-06-17 13:35:07 +00:00
// .info file, so we can use t() on them even though they are dynamic data
2013-01-30 03:38:25 +00:00
// at this point.
$form [ 'profile' ] = array (
'#type' => 'radios' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Select an installation profile' ),
2013-01-30 03:38:25 +00:00
'#title_display' => 'invisible' ,
2013-06-17 13:35:07 +00:00
'#options' => array_map ( 't' , $names ),
2013-01-30 03:38:25 +00:00
'#default_value' => 'standard' ,
);
foreach ( array_keys ( $names ) as $profile ) {
2013-06-17 13:35:07 +00:00
$form [ 'profile' ][ $profile ][ '#description' ] = isset ( $profiles [ $profile ][ 'description' ]) ? t ( $profiles [ $profile ][ 'description' ]) : '' ;
2010-02-17 04:19:51 +00:00
}
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-02-17 04:19:51 +00:00
$form [ 'actions' ][ 'submit' ] = array (
'#type' => 'submit' ,
2013-06-17 13:35:07 +00:00
'#value' => t ( 'Save and continue' ),
2010-02-17 04:19:51 +00:00
);
return $form ;
}
/**
2012-08-31 15:56:36 +00:00
* Finds all . po files that are useful to the installer .
2012-10-05 18:12:56 +00:00
*
* @ return
2013-01-10 17:18:17 +00:00
* An associative array of file URIs keyed by language code . URIs as
* returned by file_scan_directory () .
2012-10-05 18:12:56 +00:00
*
* @ see file_scan_directory ()
2010-02-17 04:19:51 +00:00
*/
2011-11-25 06:22:29 +00:00
function install_find_translations () {
2013-01-10 17:18:17 +00:00
$translations = array ();
2013-06-17 13:35:07 +00:00
$files = Drupal :: service ( 'string_translator.file_translation' ) -> findTranslationFiles ();
2011-10-29 11:40:09 +00:00
// English does not need a translation file.
array_unshift ( $files , ( object ) array ( 'name' => 'en' ));
2013-01-10 17:18:17 +00:00
foreach ( $files as $uri => $file ) {
2011-10-29 11:40:09 +00:00
// Strip off the file name component before the language code.
2013-01-10 17:18:17 +00:00
$langcode = preg_replace ( '!^(.+\.)?([^\.]+)$!' , '\2' , $file -> name );
2011-12-22 11:26:12 +00:00
// Language codes cannot exceed 12 characters to fit into the {language}
2011-01-03 15:48:11 +00:00
// table.
2013-01-10 17:18:17 +00:00
if ( strlen ( $langcode ) <= 12 ) {
$translations [ $langcode ] = $uri ;
2011-01-03 15:48:11 +00:00
}
2010-12-28 18:17:27 +00:00
}
2013-01-10 17:18:17 +00:00
return $translations ;
2011-10-29 11:40:09 +00:00
}
/**
2013-06-10 11:33:55 +00:00
* Build a file translation service for installation .
2012-01-18 04:01:07 +00:00
*
2013-06-10 11:33:55 +00:00
* @ return Drupal\Core\StringTranslation\Translator\FileTranslation
* File translation service for the installer .
2011-10-29 11:40:09 +00:00
*/
2013-06-10 11:33:55 +00:00
function install_file_translation_service () {
static $translation ;
if ( ! isset ( $translation )) {
2013-06-17 13:35:07 +00:00
$translation = new FileTranslation ( install_translations_directory ());
Issue #1496480 by mrf, disasm, kbasarab, pfrenssen, cam8001, typhonius, Letharion, ACF, vijaycs85, heyrocker, Berdir, alexpott: Convert file system settings to the new configuration system.
2013-02-08 23:36:06 +00:00
}
2013-06-10 11:33:55 +00:00
return $translation ;
2010-02-17 04:19:51 +00:00
}
2013-06-17 13:35:07 +00:00
/**
* Finds the translations directory for the installation .
*
* @ return string
* The path to the installation directory .
*/
function install_translations_directory () {
if ( isset ( $GLOBALS [ 'conf' ][ 'locale.settings' ][ 'translation.path' ])) {
$directory = $GLOBALS [ 'conf' ][ 'locale.settings' ][ 'translation.path' ];
}
else {
$directory = conf_path () . '/files/translations' ;
}
return $directory ;
}
/**
* Build a file translation service for installation .
*
* @ param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* The container to append translation related services .
*/
function install_register_translation_service ( ContainerBuilder $container ) {
$container -> register ( 'string_translator.file_translation' , 'Drupal\Core\StringTranslation\Translator\FileTranslation' )
2013-06-28 16:30:21 +00:00
-> addArgument ( install_translations_directory ());
$container -> register ( 'string_translator.custom_strings' , 'Drupal\Core\StringTranslation\Translator\CustomStrings' );
$container -> register ( 'string_translation' , 'Drupal\Core\StringTranslation\TranslationManager' )
-> addMethodCall ( 'addTranslator' , array ( new Reference ( 'string_translator.file_translation' )))
-> addMethodCall ( 'addTranslator' , array ( new Reference ( 'string_translator.custom_strings' )));
2013-06-17 13:35:07 +00:00
}
2010-02-17 04:19:51 +00:00
/**
2012-08-31 15:56:36 +00:00
* Selects which language to use during installation .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state . The chosen
2011-11-25 06:22:29 +00:00
* langcode will be added here , if it was not already selected previously , as
* will a list of all available languages .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* For interactive installations , a form or other page output allowing the
2011-11-25 06:22:29 +00:00
* language to be selected or providing information about language selection ,
* if a language has not been chosen . Otherwise , an exception is thrown if a
* language cannot be chosen automatically .
2010-02-17 04:19:51 +00:00
*/
2011-11-25 06:22:29 +00:00
function install_select_language ( & $install_state ) {
2013-01-10 17:18:17 +00:00
// Find all available translation files.
2011-11-25 06:22:29 +00:00
$files = install_find_translations ();
$install_state [ 'translations' ] += $files ;
2013-01-10 17:18:17 +00:00
// If a valid language code is set, continue with the next installation step.
// When translations from the localization server are used, any language code
// is accepted because the standard language list is kept in sync with the
// langauges available at http://localize.drupal.org.
// When files from the translation directory are used, we only accept
// languages for which a file is available.
2011-11-25 06:22:29 +00:00
if ( ! empty ( $_POST [ 'langcode' ])) {
2013-06-10 16:14:58 +00:00
$standard_languages = LanguageManager :: getStandardLanguageList ();
2013-01-10 17:18:17 +00:00
$langcode = $_POST [ 'langcode' ];
if ( $langcode == 'en' || isset ( $files [ $langcode ]) || isset ( $standard_languages [ $langcode ])) {
$install_state [ 'parameters' ][ 'langcode' ] = $langcode ;
return ;
2010-02-17 04:19:51 +00:00
}
}
2011-11-25 06:22:29 +00:00
if ( empty ( $install_state [ 'parameters' ][ 'langcode' ])) {
2013-01-10 17:18:17 +00:00
// If we are performing an interactive installation, we display a form to
// select a right language. If no translation files were found in the
// translations directory, the form shows a list of standard languages. If
// translation files were found the form shows a select list of the
// corresponding languages to choose from.
if ( $install_state [ 'interactive' ]) {
2013-06-17 13:35:07 +00:00
drupal_set_title ( t ( 'Choose language' ));
2013-05-09 09:25:10 +00:00
include_once __DIR__ . '/form.inc' ;
2013-01-10 17:18:17 +00:00
$elements = drupal_get_form ( 'install_select_language_form' , count ( $files ) > 1 ? $files : array ());
return drupal_render ( $elements );
2010-02-17 04:19:51 +00:00
}
2013-01-10 17:18:17 +00:00
// If we are performing a non-interactive installation. If only one language
// (English) is available, assume the user knows what he is doing. Otherwise
// thow an error.
2010-02-17 04:19:51 +00:00
else {
2013-01-10 17:18:17 +00:00
if ( count ( $files ) == 1 ) {
2013-01-30 03:16:22 +00:00
$install_state [ 'parameters' ][ 'langcode' ] = current ( array_keys ( $files ));
2013-01-10 17:18:17 +00:00
return ;
2010-02-17 04:19:51 +00:00
}
else {
2013-06-18 04:44:52 +00:00
throw new Exception ( t ( 'Sorry, you must select a language to continue the installation.' ));
2010-02-17 04:19:51 +00:00
}
}
}
}
/**
2012-08-31 15:56:36 +00:00
* Form constructor for the language selection form .
2012-10-05 18:12:56 +00:00
*
2013-01-10 17:18:17 +00:00
* @ param array $files
* ( optional ) An associative array of file URIs keyed by language code as
* returned by file_scan_directory () . Defaults to all standard languages .
2012-10-05 18:12:56 +00:00
*
* @ see file_scan_directory ()
* @ ingroup forms
2010-02-17 04:19:51 +00:00
*/
2013-01-10 17:18:17 +00:00
function install_select_language_form ( $form , & $form_state , $files = array ()) {
2013-05-09 09:25:10 +00:00
include_once __DIR__ . '/../modules/language/language.module' ;
include_once __DIR__ . '/../modules/language/language.negotiation.inc' ;
2011-11-25 06:22:29 +00:00
2013-06-10 16:14:58 +00:00
$standard_languages = LanguageManager :: getStandardLanguageList ();
2011-11-25 06:22:29 +00:00
$select_options = array ();
2013-01-10 17:18:17 +00:00
$browser_options = array ();
// Build a select list with language names in native language for the user
// to choose from. And build a list of available languages for the browser
// to select the language default from.
if ( count ( $files )) {
// Select lists based on available language files.
foreach ( $files as $langcode => $uri ) {
$select_options [ $langcode ] = isset ( $standard_languages [ $langcode ]) ? $standard_languages [ $langcode ][ 1 ] : $langcode ;
$browser_options [ $langcode ] = new Language ( array (
2013-06-29 10:56:53 +00:00
'id' => $langcode ,
2013-01-10 17:18:17 +00:00
));
2010-02-17 04:19:51 +00:00
}
2013-01-10 17:18:17 +00:00
}
else {
// Select lists based on all standard languages.
foreach ( $standard_languages as $langcode => $language_names ) {
$select_options [ $langcode ] = $language_names [ 1 ];
$browser_options [ $langcode ] = new Language ( array (
2013-06-29 10:56:53 +00:00
'id' => $langcode ,
2013-01-10 17:18:17 +00:00
));
2011-11-25 06:22:29 +00:00
}
2010-02-17 04:19:51 +00:00
}
2011-11-25 06:22:29 +00:00
2013-01-10 17:18:17 +00:00
$browser_langcode = language_from_browser ( $browser_options );
2011-11-25 06:22:29 +00:00
$form [ 'langcode' ] = array (
'#type' => 'select' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Choose language' ),
2013-01-30 03:38:25 +00:00
'#title_display' => 'invisible' ,
2011-11-25 06:22:29 +00:00
'#options' => $select_options ,
// Use the browser detected language as default or English if nothing found.
'#default_value' => ! empty ( $browser_langcode ) ? $browser_langcode : 'en' ,
);
2013-01-10 17:18:17 +00:00
if ( empty ( $files )) {
2010-02-17 04:19:51 +00:00
$form [ 'help' ] = array (
2013-01-10 17:18:17 +00:00
'#markup' => '<p>Translations will be downloaded from the <a href="http://localize.drupal.org">Drupal Translation website</a>. ' .
2013-04-12 09:31:37 +00:00
'If you do not want this, select <em>English</em> and continue the installation. For more information, see the <a href="http://drupal.org/documentation/install">online handbook</a>.</p>' ,
2010-02-17 04:19:51 +00:00
);
}
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-02-17 04:19:51 +00:00
$form [ 'actions' ][ 'submit' ] = array (
'#type' => 'submit' ,
2013-06-17 13:35:07 +00:00
'#value' => t ( 'Save and continue' ),
2010-02-17 04:19:51 +00:00
);
return $form ;
}
2013-01-10 17:18:17 +00:00
/**
* Download a translation file for the selected langaguage .
*
* @ param array $install_state
* An array of information about the current installation state .
*
* @ return string
* A themed status report , or an exception if there are requirement errors .
* Upon successfull download the page is reloaded and no output is returned .
*/
function install_download_translation ( & $install_state ) {
// Check whether all conditions are met to download. Download the translation
// if possible.
$requirements = install_check_translations ( $install_state );
if ( $output = install_display_requirements ( $install_state , $requirements )) {
return $output ;
}
// The download was successfull, reload the page in the new lanagage.
install_goto ( install_redirect_url ( $install_state ));
}
/**
2013-02-04 14:53:17 +00:00
* Attempts to get a file using a HTTP request and to store it locally .
2013-01-10 17:18:17 +00:00
*
* @ param string $uri
* The URI of the file to grab .
* @ param string $destination
* Stream wrapper URI specifying where the file should be placed . If a
* directory path is provided , the file is saved into that directory under its
* original name . If the path contains a filename as well , that one will be
* used instead .
*
* @ return boolean
* TRUE on success , FALSE on failure .
*/
function install_retrieve_file ( $uri , $destination ) {
$parsed_url = parse_url ( $uri );
if ( is_dir ( drupal_realpath ( $destination ))) {
// Prevent URIs with triple slashes when gluing parts together.
$path = str_replace ( '///' , '//' , " $destination / " ) . drupal_basename ( $parsed_url [ 'path' ]);
}
else {
$path = $destination ;
}
2013-02-04 14:53:17 +00:00
try {
2013-04-03 08:44:04 +00:00
$request = Drupal :: httpClient () -> get ( $uri , array ( 'Accept' => 'text/plain' ));
2013-02-04 14:53:17 +00:00
$data = $request -> send () -> getBody ( TRUE );
if ( empty ( $data )) {
return FALSE ;
}
2013-01-10 17:18:17 +00:00
}
2013-02-04 14:53:17 +00:00
catch ( RequestException $e ) {
2013-01-10 17:18:17 +00:00
return FALSE ;
}
2013-02-04 14:53:17 +00:00
return file_put_contents ( $path , $data ) !== FALSE ;
2013-01-10 17:18:17 +00:00
}
/**
* Checks if the localization server can be contacted .
*
* @ param string $uri
* The URI to contact .
*
* @ return string
2013-02-04 14:53:17 +00:00
* TRUE if the URI was contacted successfully , FALSE if not .
2013-01-10 17:18:17 +00:00
*/
function install_check_localization_server ( $uri ) {
2013-02-04 14:53:17 +00:00
try {
2013-04-03 08:44:04 +00:00
$request = Drupal :: httpClient () -> head ( $uri );
2013-05-29 06:46:25 +00:00
$request -> send ();
2013-02-04 14:53:17 +00:00
return TRUE ;
}
catch ( RequestException $e ) {
return FALSE ;
}
2013-01-10 17:18:17 +00:00
}
/**
* Gets the core release version for localization .
*
* In case core has a development version we fall back to the latest stable
* release . e . g . 8.2 - dev falls back to 8.1 . 8.0 - dev falls back to 7.0 . Fallback
* is required because the localization server only provides translation files
* for stable releases .
*
* @ return array
* Associative array containing 'core' and 'version' of the release .
*/
function install_get_localization_release () {
if ( strpos ( VERSION , 'dev' )) {
list ( $version , ) = explode ( '-' , VERSION );
list ( $major , $minor ) = explode ( '.' , $version );
// Calculate the major and minor release numbers to fall back to.
// E.g. 8.0-dev falls back to 7.0 and 8.2-dev falls back to 8.1.
if ( $minor == 0 ) {
$major -- ;
}
else {
$minor -- ;
}
$release = " $major . $minor " ;
}
else {
$release = VERSION ;
}
return array (
'core' => " $major .x " ,
'version' => $release ,
);
}
2010-02-17 04:19:51 +00:00
/**
2010-03-26 22:14:46 +00:00
* Indicates that there are no profiles available .
2010-02-17 04:19:51 +00:00
*/
function install_no_profile_error () {
2013-06-18 04:44:52 +00:00
drupal_set_title ( t ( 'No profiles available' ));
2013-06-17 13:35:07 +00:00
return t ( 'We were unable to find any installation profiles. Installation 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.' );
2010-02-17 04:19:51 +00:00
}
/**
2010-03-26 22:14:46 +00:00
* Indicates that Drupal has already been installed .
2010-02-17 04:19:51 +00:00
*/
function install_already_done_error () {
global $base_url ;
2013-06-18 04:44:52 +00:00
drupal_set_title ( t ( 'Drupal already installed' ));
2013-06-17 13:35:07 +00:00
return t ( '<ul><li>To start over, you must empty your existing database, delete your active configuration, and copy <em>default.settings.php</em> over <em>settings.php</em>.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To locate your active configuration, view the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</em></li></li><li>To upgrade an existing installation, proceed to the <a href="@base-url/core/update.php">update script</a>.</li><li>View your <a href="@base-url">existing site</a>.</li></ul>' , array ( '@base-url' => $base_url ));
2010-02-17 04:19:51 +00:00
}
/**
2012-08-31 15:56:36 +00:00
* Loads information about the chosen profile during installation .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state . The loaded
* profile information will be added here , or an exception will be thrown if
* the profile cannot be loaded .
*/
function install_load_profile ( & $install_state ) {
2012-08-10 09:18:18 +00:00
$profile = $install_state [ 'parameters' ][ 'profile' ];
$profile_file = $install_state [ 'profiles' ][ $profile ] -> uri ;
2011-11-08 13:12:52 +00:00
if ( file_exists ( $profile_file )) {
2010-02-17 04:19:51 +00:00
include_once $profile_file ;
2011-11-25 06:22:29 +00:00
$install_state [ 'profile_info' ] = install_profile_info ( $install_state [ 'parameters' ][ 'profile' ], $install_state [ 'parameters' ][ 'langcode' ]);
2010-02-17 04:19:51 +00:00
}
else {
2013-06-18 04:44:52 +00:00
throw new Exception ( t ( 'Sorry, the profile you have chosen cannot be loaded.' ));
2010-02-17 04:19:51 +00:00
}
}
/**
2012-08-31 15:56:36 +00:00
* Performs a full bootstrap of Drupal during installation .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
*/
2013-03-22 09:36:55 +00:00
function install_bootstrap_full () {
2010-02-17 04:19:51 +00:00
drupal_bootstrap ( DRUPAL_BOOTSTRAP_FULL );
2013-06-29 16:26:55 +00:00
require_once DRUPAL_ROOT . '/' . settings () -> get ( 'session_inc' , 'core/includes/session.inc' );
drupal_session_initialize ();
2010-02-17 04:19:51 +00:00
}
/**
2012-08-31 15:56:36 +00:00
* Installs required modules via a batch process .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* The batch definition .
*/
function install_profile_modules ( & $install_state ) {
2013-06-05 14:24:40 +00:00
$modules = Drupal :: state () -> get ( 'install_profile_modules' ) ? : array ();
2010-02-17 04:19:51 +00:00
$files = system_rebuild_module_data ();
2013-06-05 14:24:40 +00:00
Drupal :: state () -> delete ( 'install_profile_modules' );
2010-06-25 12:35:14 +00:00
2010-09-01 01:24:05 +00:00
// Always install required modules first. Respect the dependencies between
// the modules.
$required = array ();
$non_required = array ();
// Although the profile module is marked as required, it needs to go after
// every dependency, including non-required ones. So clear its required
// flag for now to allow it to install late.
$files [ $install_state [ 'parameters' ][ 'profile' ]] -> info [ 'required' ] = FALSE ;
// Add modules that other modules depend on.
foreach ( $modules as $module ) {
if ( $files [ $module ] -> requires ) {
$modules = array_merge ( $modules , array_keys ( $files [ $module ] -> requires ));
}
}
$modules = array_unique ( $modules );
foreach ( $modules as $module ) {
if ( ! empty ( $files [ $module ] -> info [ 'required' ])) {
$required [ $module ] = $files [ $module ] -> sort ;
}
else {
$non_required [ $module ] = $files [ $module ] -> sort ;
}
2010-06-25 12:35:14 +00:00
}
2010-09-01 01:24:05 +00:00
arsort ( $required );
arsort ( $non_required );
2010-06-25 12:35:14 +00:00
2010-02-17 04:19:51 +00:00
$operations = array ();
2010-09-01 01:24:05 +00:00
foreach ( $required + $non_required as $module => $weight ) {
2010-02-17 04:19:51 +00:00
$operations [] = array ( '_install_module_batch' , array ( $module , $files [ $module ] -> info [ 'name' ]));
}
$batch = array (
'operations' => $operations ,
2013-06-17 13:35:07 +00:00
'title' => t ( 'Installing @drupal' , array ( '@drupal' => drupal_install_profile_distribution_name ())),
'error_message' => t ( 'The installation has encountered an error.' ),
2010-10-01 18:37:23 +00:00
'finished' => '_install_profile_modules_finished' ,
2010-02-17 04:19:51 +00:00
);
return $batch ;
}
/**
2012-08-31 15:56:36 +00:00
* Imports languages via a batch process during installation .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* The batch definition , if there are language files to import .
*/
2011-11-25 06:22:29 +00:00
function install_import_translations ( & $install_state ) {
2013-05-09 09:25:10 +00:00
include_once __DIR__ . '/../modules/locale/locale.bulk.inc' ;
2013-01-10 17:18:17 +00:00
$langcode = $install_state [ 'parameters' ][ 'langcode' ];
2013-06-10 16:14:58 +00:00
$standard_languages = LanguageManager :: getStandardLanguageList ();
2011-11-25 06:22:29 +00:00
if ( ! isset ( $standard_languages [ $langcode ])) {
2011-01-03 15:48:11 +00:00
// Drupal does not know about this language, so we prefill its values with
// our best guess. The user will be able to edit afterwards.
2012-08-26 17:01:29 +00:00
$language = new Language ( array (
2013-06-29 10:56:53 +00:00
'id' => $langcode ,
2011-11-25 06:22:29 +00:00
'name' => $langcode ,
2011-09-28 10:47:48 +00:00
'default' => TRUE ,
2012-08-26 17:01:29 +00:00
));
2011-12-22 11:26:12 +00:00
language_save ( $language );
2011-01-03 15:48:11 +00:00
}
else {
// A known predefined language, details will be filled in properly.
2012-08-26 17:01:29 +00:00
$language = new Language ( array (
2013-06-29 10:56:53 +00:00
'id' => $langcode ,
2011-09-28 10:47:48 +00:00
'default' => TRUE ,
2012-08-26 17:01:29 +00:00
));
2011-12-22 11:26:12 +00:00
language_save ( $language );
2011-01-03 15:48:11 +00:00
}
2013-01-10 17:18:17 +00:00
// If a non-English language was selected, remove English and import the
// translations.
2012-09-01 01:49:06 +00:00
if ( $langcode != 'en' ) {
language_delete ( 'en' );
2013-01-10 17:18:17 +00:00
// Set up a batch to import translations for the newly added language.
_install_prepare_import ();
module_load_include ( 'fetch.inc' , 'locale' );
if ( $batch = locale_translation_batch_fetch_build ( array (), array ( $langcode ))) {
return $batch ;
}
2010-02-17 04:19:51 +00:00
}
}
2013-01-10 17:18:17 +00:00
/**
* Tells the translation import process that Drupal core is installed .
*/
function _install_prepare_import () {
global $install_state ;
$release = install_get_localization_release ();
db_insert ( 'locale_project' )
-> fields ( array (
'name' => 'drupal' ,
'project_type' => 'module' ,
'core' => $release [ 'core' ],
'version' => $release [ 'version' ],
'server_pattern' => $install_state [ 'server_pattern' ],
'status' => 1 ,
))
-> execute ();
module_load_include ( 'compare.inc' , 'locale' );
locale_translation_check_projects_local ( array ( 'drupal' ), array ( $install_state [ 'parameters' ][ 'langcode' ]));
}
2010-02-17 04:19:51 +00:00
/**
2012-08-31 15:56:36 +00:00
* Form constructor for a form to configure the new site .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2012-08-31 15:56:36 +00:00
* @ see install_configure_form_validate ()
* @ see install_configure_form_submit ()
2012-10-05 18:12:56 +00:00
* @ ingroup forms
2010-02-17 04:19:51 +00:00
*/
2010-04-23 07:50:28 +00:00
function install_configure_form ( $form , & $form_state , & $install_state ) {
2013-06-17 13:35:07 +00:00
drupal_set_title ( t ( 'Configure site' ));
2010-02-17 04:19:51 +00:00
// Warn about settings.php permissions risk
2010-11-05 20:53:38 +00:00
$settings_dir = conf_path ();
2010-02-17 04:19:51 +00:00
$settings_file = $settings_dir . '/settings.php' ;
2010-12-04 01:54:37 +00:00
// Check that $_POST is empty so we only show this message when the form is
// first displayed, not on the next page after it is submitted. (We do not
// want to repeat it multiple times because it is a general warning that is
// not related to the rest of the installation process; it would also be
// especially out of place on the last page of the installer, where it would
// distract from the message that the Drupal installation has completed
// successfully.)
if ( empty ( $_POST ) && ( ! drupal_verify_install_file ( DRUPAL_ROOT . '/' . $settings_file , FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE ) || ! drupal_verify_install_file ( DRUPAL_ROOT . '/' . $settings_dir , FILE_NOT_WRITABLE , 'dir' ))) {
2013-06-17 13:35:07 +00:00
drupal_set_message ( t ( 'All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.' , array ( '%dir' => $settings_dir , '%file' => $settings_file , '@handbook_url' => 'http://drupal.org/server-permissions' )), 'warning' );
2010-02-17 04:19:51 +00:00
}
2012-08-30 19:24:38 +00:00
drupal_add_library ( 'system' , 'drupal.system' );
2010-02-17 04:19:51 +00:00
// Add JavaScript time zone detection.
2012-08-30 19:24:38 +00:00
drupal_add_library ( 'system' , 'drupal.timezone' );
2010-02-17 04:19:51 +00:00
// We add these strings as settings because JavaScript translation does not
2012-10-05 16:11:15 +00:00
// work during installation.
2010-02-17 04:19:51 +00:00
drupal_add_js ( array ( 'copyFieldValue' => array ( 'edit-site-mail' => array ( 'edit-account-mail' ))), 'setting' );
// Cache a fully-built schema. This is necessary for any invocation of
// index.php because: (1) setting cache table entries requires schema
// information, (2) that occurs during bootstrap before any module are
// loaded, so (3) if there is no cached schema, drupal_get_schema() will
// try to generate one but with no loaded modules will return nothing.
//
2012-04-29 15:16:27 +00:00
// @todo Move this to the 'install_finished' task?
2010-02-17 04:19:51 +00:00
drupal_get_schema ( NULL , TRUE );
// Return the form.
return _install_configure_form ( $form , $form_state , $install_state );
}
/**
2012-08-31 15:56:36 +00:00
* Finishes importing files at end of installation .
2010-02-17 04:19:51 +00:00
*
2013-01-10 17:18:17 +00:00
* If other projects besides Drupal core have been installed , their translation
* will be imported here .
*
2010-02-17 04:19:51 +00:00
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* The batch definition , if there are language files to import .
*/
2011-11-25 06:22:29 +00:00
function install_import_translations_remaining ( & $install_state ) {
2013-01-10 17:18:17 +00:00
module_load_include ( 'fetch.inc' , 'locale' );
module_load_include ( 'compare.inc' , 'locale' );
// Build a fresh list of installed projects. When more projects than core are
// installed, their translations will be downloaded (if required) and imported
// using a batch.
$projects = locale_translation_build_projects ();
if ( count ( $projects ) > 1 ) {
$options = _locale_translation_default_update_options ();
if ( $batch = locale_translation_batch_update_build ( array (), array ( $install_state [ 'parameters' ][ 'langcode' ]), $options )) {
return $batch ;
}
}
2010-02-17 04:19:51 +00:00
}
2013-04-23 07:19:41 +00:00
/**
* Creates configuration translations .
*
* @ param array $install_state
* An array of information about the current installation state .
*
* @ return array
* The batch definition , if there are configuration objects to update .
*
* @ see install_tasks ()
*/
function install_update_configuration_translations ( & $install_state ) {
Drupal :: moduleHandler () -> loadInclude ( 'locale' , 'bulk.inc' );
return locale_config_batch_update_components ( array (), array ( $install_state [ 'parameters' ][ 'langcode' ]));
}
2010-02-17 04:19:51 +00:00
/**
2012-08-31 15:56:36 +00:00
* Performs final installation steps and displays a 'finished' page .
2010-02-17 04:19:51 +00:00
*
* @ param $install_state
* An array of information about the current installation state .
2010-03-26 22:14:46 +00:00
*
2010-02-17 04:19:51 +00:00
* @ return
* A message informing the user that the installation is complete .
*/
function install_finished ( & $install_state ) {
2012-10-09 20:32:40 +00:00
$profile = drupal_get_profile ();
2010-02-17 04:19:51 +00:00
// Remember the profile which was used.
2012-10-09 20:32:40 +00:00
variable_set ( 'install_profile' , $profile );
2010-02-17 04:19:51 +00:00
2012-10-05 16:11:15 +00:00
// Installation profiles are always loaded last.
2012-10-09 20:32:40 +00:00
module_set_weight ( $profile , 1000 );
2010-02-17 04:19:51 +00:00
2012-05-03 15:09:39 +00:00
// Flush all caches to ensure that any full bootstraps during the installer
// do not leave stale cached data, and that any content types or other items
2012-10-05 16:11:15 +00:00
// registered by the installation profile are registered correctly.
2012-05-03 15:09:39 +00:00
drupal_flush_all_caches ();
2013-06-17 13:35:07 +00:00
drupal_set_title ( t ( '@drupal installation complete' , array ( '@drupal' => drupal_install_profile_distribution_name ())), PASS_THROUGH );
2012-05-03 15:09:39 +00:00
$messages = drupal_set_message ();
2013-06-17 13:35:07 +00:00
$output = '<p>' . t ( 'Congratulations, you installed @drupal!' , array ( '@drupal' => drupal_install_profile_distribution_name ())) . '</p>' ;
2013-06-06 08:14:16 +00:00
// Ensure the URL that is generated for the home page does not have 'install.php'
// in it.
$request = Request :: createFromGlobals ();
$generator = Drupal :: urlGenerator ();
$generator -> setBasePath ( str_replace ( '/core' , '' , $request -> getBasePath ()) . '/' );
$generator -> setScriptPath ( '' );
$url = $generator -> generateFromPath ( '' );
2013-06-17 13:35:07 +00:00
$output .= '<p>' . ( isset ( $messages [ 'error' ]) ? t ( 'Review the messages above before visiting <a href="@url">your new site</a>.' , array ( '@url' => $url )) : t ( '<a href="@url">Visit your new site</a>.' , array ( '@url' => $url ))) . '</p>' ;
2010-02-17 04:19:51 +00:00
// Run cron to populate update status tables (if available) so that users
// will be warned if they've installed an out of date Drupal version.
// Will also trigger indexing of profile-supplied content or feeds.
drupal_cron_run ();
2013-02-19 05:08:21 +00:00
// Save a snapshot of the intially installed configuration.
$active = drupal_container () -> get ( 'config.storage' );
$snapshot = drupal_container () -> get ( 'config.storage.snapshot' );
config_import_create_snapshot ( $active , $snapshot );
2010-02-17 04:19:51 +00:00
return $output ;
}
/**
* Batch callback for batch installation of modules .
*/
function _install_module_batch ( $module , $module_name , & $context ) {
2010-02-26 18:31:29 +00:00
// Install and enable the module right away, so that the module will be
2010-02-17 04:19:51 +00:00
// loaded by drupal_bootstrap in subsequent batch requests, and other
// modules possibly depending on it can safely perform their installation
// steps.
module_enable ( array ( $module ), FALSE );
$context [ 'results' ][] = $module ;
2013-06-17 13:35:07 +00:00
$context [ 'message' ] = t ( 'Installed %module module.' , array ( '%module' => $module_name ));
2010-02-17 04:19:51 +00:00
}
2010-10-01 18:37:23 +00:00
/**
* 'Finished' callback for module installation batch .
*/
function _install_profile_modules_finished ( $success , $results , $operations ) {
// Flush all caches to complete the module installation process. Subsequent
// installation tasks will now have full access to the profile's modules.
drupal_flush_all_caches ();
}
2013-01-10 17:18:17 +00:00
/**
* Checks installation requirements and reports any errors .
*/
function install_check_translations ( $install_state ) {
$requirements = array ();
$readable = FALSE ;
$writable = FALSE ;
Issue #1496480 by mrf, disasm, kbasarab, pfrenssen, cam8001, typhonius, Letharion, ACF, vijaycs85, heyrocker, Berdir, alexpott: Convert file system settings to the new configuration system.
2013-02-08 23:36:06 +00:00
// @todo: Make this configurable.
$files_directory = conf_path () . '/files' ;
$translations_directory = conf_path () . '/files/translations' ;
2013-01-10 17:18:17 +00:00
$translations_directory_exists = FALSE ;
$online = FALSE ;
// First attempt to create or make writable the files directory.
file_prepare_directory ( $files_directory , FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS );
// Then, attempt to create or make writable the translations directory.
file_prepare_directory ( $translations_directory , FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS );
// Get values so the requirements errors can be specific.
if ( drupal_verify_install_file ( $translations_directory , FILE_EXIST | FILE_WRITABLE , 'dir' )) {
$readable = is_readable ( $translations_directory );
$writable = is_writable ( $translations_directory );
$translations_directory_exists = TRUE ;
}
// Build URLs for the translation file and the translation server.
$release = install_get_localization_release ();
$langcode = $install_state [ 'parameters' ][ 'langcode' ];
$variables = array (
'%project' => 'drupal' ,
'%version' => $release [ 'version' ],
'%core' => $release [ 'core' ],
'%language' => $langcode ,
);
$translation_url = strtr ( $install_state [ 'server_pattern' ], $variables );
$elements = parse_url ( $translation_url );
$server_url = $elements [ 'scheme' ] . '://' . $elements [ 'host' ];
// Build the language name for display.
2013-06-10 16:14:58 +00:00
$languages = LanguageManager :: getStandardLanguageList ();
2013-01-10 17:18:17 +00:00
$language = isset ( $languages [ $langcode ]) ? $languages [ $langcode ][ 0 ] : $langcode ;
// Check if the desirered translation file is available and if the translation
// server can be reached, or in other words if we have an internet connection.
if ( $translation_available = install_check_localization_server ( $translation_url )) {
$online = TRUE ;
}
else {
2013-05-29 06:46:25 +00:00
if ( install_check_localization_server ( $server_url )) {
2013-01-10 17:18:17 +00:00
$online = TRUE ;
}
}
// If the translations directory does not exists, throw an error.
if ( ! $translations_directory_exists ) {
$requirements [ 'translations directory exists' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translations directory' ),
'value' => t ( 'The translations directory does not exist.' ),
2013-01-10 17:18:17 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The installer requires that you create a translations directory as part of the installation process. Create the directory %translations_directory . More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>.' , array ( '%translations_directory' => $translations_directory , '@install_txt' => base_path () . 'core/INSTALL.txt' )),
2013-01-10 17:18:17 +00:00
);
}
else {
$requirements [ 'translations directory exists' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translations directory' ),
2013-06-27 02:11:30 +00:00
'value' => t ( 'The directory %translations_directory exists.' , array ( '%translations_directory' => $translations_directory )),
2013-01-10 17:18:17 +00:00
);
// If the translations directory is not readable, throw an error.
if ( ! $readable ) {
$requirements [ 'translations directory readable' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translations directory' ),
'value' => t ( 'The translations directory is not readable.' ),
2013-01-10 17:18:17 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The installer requires read permissions to %translations_directory at all times. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.' , array ( '%translations_directory' => $translations_directory , '@handbook_url' => 'http://drupal.org/server-permissions' )),
2013-01-10 17:18:17 +00:00
);
}
// If translations directory is not writable, throw an error.
if ( ! $writable ) {
$requirements [ 'translations directory writable' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translations directory' ),
'value' => t ( 'The translations directory is not writable.' ),
2013-01-10 17:18:17 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The installer requires write permissions to %translations_directory during the installation process. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.' , array ( '%translations_directory' => $translations_directory , '@handbook_url' => 'http://drupal.org/server-permissions' )),
2013-01-10 17:18:17 +00:00
);
}
else {
$requirements [ 'translations directory writable' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translations directory' ),
'value' => t ( 'The translations directory is writable.' ),
2013-01-10 17:18:17 +00:00
);
}
}
// If the translations server can not be contacted, throw an error.
if ( ! $online ) {
$requirements [ 'online' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Internet' ),
'value' => t ( 'The translation server is offline.' ),
2013-01-10 17:18:17 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The installer requires to contact the translation server to download a translation file. Check your internet connection and verify that your website can reach the translation server at <a href="!server_url">!server_url</a>.' , array ( '!server_url' => $server_url )),
2013-01-10 17:18:17 +00:00
);
}
else {
$requirements [ 'online' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Internet' ),
'value' => t ( 'The translation server is online.' ),
2013-01-10 17:18:17 +00:00
);
// If translation file is not found at the translation server, throw an
// error.
if ( ! $translation_available ) {
$requirements [ 'translation available' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translation' ),
'value' => t ( 'The %language translation is not available.' , array ( '%language' => $language )),
2013-01-10 17:18:17 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The %language translation file is not available at the translation server. <a href="!url">Choose a different language</a> or select English and translate your website later.' , array ( '%language' => $language , '!url' => check_url ( $_SERVER [ 'SCRIPT_NAME' ]))),
2013-01-10 17:18:17 +00:00
);
}
else {
$requirements [ 'translation available' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translation' ),
'value' => t ( 'The %language translation is available.' , array ( '%language' => $language )),
2013-01-10 17:18:17 +00:00
);
}
}
2013-01-25 07:16:02 +00:00
if ( $translations_directory_exists && $readable && $writable && $translation_available ) {
2013-01-10 17:18:17 +00:00
$translation_downloaded = install_retrieve_file ( $translation_url , $translations_directory );
if ( ! $translation_downloaded ) {
$requirements [ 'translation downloaded' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Translation' ),
'value' => t ( 'The %language translation could not be downloaded.' , array ( '%language' => $language )),
2013-01-10 17:18:17 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The %language translation file could not be downloaded. <a href="!url">Choose a different language</a> or select English and translate your website later.' , array ( '%language' => $language , '!url' => check_url ( $_SERVER [ 'SCRIPT_NAME' ]))),
2013-01-10 17:18:17 +00:00
);
}
}
return $requirements ;
}
2010-02-17 04:19:51 +00:00
/**
2010-03-26 22:14:46 +00:00
* Checks installation requirements and reports any errors .
2010-02-17 04:19:51 +00:00
*/
function install_check_requirements ( $install_state ) {
$profile = $install_state [ 'parameters' ][ 'profile' ];
// Check the profile requirements.
2012-08-10 09:18:18 +00:00
$requirements = drupal_check_profile ( $profile , $install_state );
2010-02-17 04:19:51 +00:00
// If Drupal is not set up already, we need to create a settings file.
if ( ! $install_state [ 'settings_verified' ]) {
2012-09-12 09:41:56 +00:00
$readable = FALSE ;
2010-02-17 04:19:51 +00:00
$writable = FALSE ;
$conf_path = './' . conf_path ( FALSE , TRUE );
$settings_file = $conf_path . '/settings.php' ;
2010-06-04 09:18:15 +00:00
$default_settings_file = './sites/default/default.settings.php' ;
2010-02-17 04:19:51 +00:00
$file = $conf_path ;
$exists = FALSE ;
// Verify that the directory exists.
if ( drupal_verify_install_file ( $conf_path , FILE_EXIST , 'dir' )) {
2010-09-14 18:46:40 +00:00
// Check if a settings.php file already exists.
2010-02-17 04:19:51 +00:00
$file = $settings_file ;
if ( drupal_verify_install_file ( $settings_file , FILE_EXIST )) {
// If it does, make sure it is writable.
2012-09-12 09:41:56 +00:00
$readable = drupal_verify_install_file ( $settings_file , FILE_READABLE );
$writable = drupal_verify_install_file ( $settings_file , FILE_WRITABLE );
2010-02-17 04:19:51 +00:00
$exists = TRUE ;
}
}
2010-06-04 09:18:15 +00:00
// If default.settings.php does not exist, or is not readable, throw an
// error.
if ( ! drupal_verify_install_file ( $default_settings_file , FILE_EXIST | FILE_READABLE )) {
$requirements [ 'default settings file exists' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Default settings file' ),
'value' => t ( 'The default settings file does not exist.' ),
2010-06-04 09:18:15 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The @drupal installer requires that the %default-file file not be modified in any way from the original download.' , array ( '@drupal' => drupal_install_profile_distribution_name (), '%default-file' => $default_settings_file )),
2010-06-04 09:18:15 +00:00
);
}
2010-09-14 18:46:40 +00:00
// Otherwise, if settings.php does not exist yet, we can try to copy
// default.settings.php to create it.
elseif ( ! $exists ) {
$copied = drupal_verify_install_file ( $conf_path , FILE_EXIST | FILE_WRITABLE , 'dir' ) && @ copy ( $default_settings_file , $settings_file );
if ( $copied ) {
// If the new settings file has the same owner as default.settings.php,
// this means default.settings.php is owned by the webserver user.
// This is an inherent security weakness because it allows a malicious
// webserver process to append arbitrary PHP code and then execute it.
// However, it is also a common configuration on shared hosting, and
// there is nothing Drupal can do to prevent it. In this situation,
// having settings.php also owned by the webserver does not introduce
// any additional security risk, so we keep the file in place.
if ( fileowner ( $default_settings_file ) === fileowner ( $settings_file )) {
2012-11-26 22:17:56 +00:00
$readable = drupal_verify_install_file ( $settings_file , FILE_READABLE );
$writable = drupal_verify_install_file ( $settings_file , FILE_WRITABLE );
2010-09-14 18:46:40 +00:00
$exists = TRUE ;
}
// If settings.php and default.settings.php have different owners, this
// probably means the server is set up "securely" (with the webserver
// running as its own user, distinct from the user who owns all the
// Drupal PHP files), although with either a group or world writable
// sites directory. Keeping settings.php owned by the webserver would
// therefore introduce a security risk. It would also cause a usability
// problem, since site owners who do not have root access to the file
// system would be unable to edit their settings file later on. We
// therefore must delete the file we just created and force the
// administrator to log on to the server and create it manually.
else {
2010-09-22 07:05:22 +00:00
$deleted = @ drupal_unlink ( $settings_file );
// We expect deleting the file to be successful (since we just
// created it ourselves above), but if it fails somehow, we set a
// variable so we can display a one-time error message to the
// administrator at the bottom of the requirements list. We also try
// to make the file writable, to eliminate any conflicting error
// messages in the requirements list.
$exists = ! $deleted ;
if ( $exists ) {
$settings_file_ownership_error = TRUE ;
2012-11-26 22:17:56 +00:00
$readable = drupal_verify_install_file ( $settings_file , FILE_READABLE );
$writable = drupal_verify_install_file ( $settings_file , FILE_WRITABLE );
2010-09-22 07:05:22 +00:00
}
2010-09-14 18:46:40 +00:00
}
}
}
2010-06-04 09:18:15 +00:00
// If settings.php does not exist, throw an error.
2010-02-17 04:19:51 +00:00
if ( ! $exists ) {
$requirements [ 'settings file exists' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Settings file' ),
'value' => t ( 'The settings file does not exist.' ),
2010-02-17 04:19:51 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The @drupal installer requires that you create a settings file as part of the installation process. Copy the %default_file file to %file. More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>.' , array ( '@drupal' => drupal_install_profile_distribution_name (), '%file' => $file , '%default_file' => $default_settings_file , '@install_txt' => base_path () . 'core/INSTALL.txt' )),
2010-02-17 04:19:51 +00:00
);
}
else {
$requirements [ 'settings file exists' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Settings file' ),
'value' => t ( 'The %file file exists.' , array ( '%file' => $file )),
2010-02-17 04:19:51 +00:00
);
2012-09-12 09:41:56 +00:00
// If settings.php is not readable, throw an error.
if ( ! $readable ) {
$requirements [ 'settings file readable' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Settings file' ),
'value' => t ( 'The settings file is not readable.' ),
2012-09-12 09:41:56 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( '@drupal requires read permissions to %file at all times. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.' , array ( '@drupal' => drupal_install_profile_distribution_name (), '%file' => $file , '@handbook_url' => 'http://drupal.org/server-permissions' )),
2012-09-12 09:41:56 +00:00
);
}
2010-06-04 09:18:15 +00:00
// If settings.php is not writable, throw an error.
2010-02-17 04:19:51 +00:00
if ( ! $writable ) {
$requirements [ 'settings file writable' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Settings file' ),
'value' => t ( 'The settings file is not writable.' ),
2010-02-17 04:19:51 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.' , array ( '@drupal' => drupal_install_profile_distribution_name (), '%file' => $file , '@handbook_url' => 'http://drupal.org/server-permissions' )),
2010-02-17 04:19:51 +00:00
);
}
else {
$requirements [ 'settings file' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Settings file' ),
'value' => t ( 'The settings file is writable.' ),
2010-09-22 07:05:22 +00:00
);
}
if ( ! empty ( $settings_file_ownership_error )) {
$requirements [ 'settings file ownership' ] = array (
2013-06-17 13:35:07 +00:00
'title' => t ( 'Settings file' ),
'value' => t ( 'The settings file is owned by the web server.' ),
2010-09-22 07:05:22 +00:00
'severity' => REQUIREMENT_ERROR ,
2013-06-17 13:35:07 +00:00
'description' => t ( 'The @drupal installer failed to create a settings file with proper file ownership. Log on to your web server, remove the existing %file file, and create a new one by copying the %default_file file to %file. More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>. If you have problems with the file permissions on your server, consult the <a href="@handbook_url">online handbook</a>.' , array ( '@drupal' => drupal_install_profile_distribution_name (), '%file' => $file , '%default_file' => $default_settings_file , '@install_txt' => base_path () . 'core/INSTALL.txt' , '@handbook_url' => 'http://drupal.org/server-permissions' )),
2010-02-17 04:19:51 +00:00
);
}
}
}
return $requirements ;
}
2013-01-10 17:18:17 +00:00
/**
* Displays installation requirements .
*
* @ param array $install_state
* An array of information about the current installation state .
* @ param array $requirements
* An array of requirements , in the same format as is returned by
* hook_requirements () .
*
* @ return
* A themed status report , or an exception if there are requirement errors .
* If there are only requirement warnings , a themed status report is shown
* initially , but the user is allowed to bypass it by providing 'continue=1'
* in the URL . Otherwise , no output is returned , so that the next task can be
* run in the same page request .
*
* @ thows \Exception
*/
function install_display_requirements ( $install_state , $requirements ) {
// Check the severity of the requirements reported.
$severity = drupal_requirements_severity ( $requirements );
// If there are errors, always display them. If there are only warnings, skip
// them if the user has provided a URL parameter acknowledging the warnings
// and indicating a desire to continue anyway. See drupal_requirements_url().
if ( $severity == REQUIREMENT_ERROR || ( $severity == REQUIREMENT_WARNING && empty ( $install_state [ 'parameters' ][ 'continue' ]))) {
if ( $install_state [ 'interactive' ]) {
2013-06-17 13:35:07 +00:00
drupal_set_title ( t ( 'Requirements problem' ));
2013-01-10 17:18:17 +00:00
$status_report = theme ( 'status_report' , array ( 'requirements' => $requirements ));
2013-06-17 13:35:07 +00:00
$status_report .= t ( 'Check the messages and <a href="!url">try again</a>.' , array ( '!url' => check_url ( drupal_requirements_url ( $severity ))));
2013-01-10 17:18:17 +00:00
return $status_report ;
}
else {
// Throw an exception showing any unmet requirements.
$failures = array ();
foreach ( $requirements as $requirement ) {
// Skip warnings altogether for non-interactive installations; these
// proceed in a single request so there is no good opportunity (and no
// good method) to warn the user anyway.
if ( isset ( $requirement [ 'severity' ]) && $requirement [ 'severity' ] == REQUIREMENT_ERROR ) {
$failures [] = $requirement [ 'title' ] . ': ' . $requirement [ 'value' ] . " \n \n " . $requirement [ 'description' ];
}
}
if ( ! empty ( $failures )) {
throw new \Exception ( implode ( " \n \n " , $failures ));
}
}
}
}
2010-02-17 04:19:51 +00:00
/**
2012-10-05 18:12:56 +00:00
* Form constructor for a site configuration form .
*
* @ param $install_state
* An array of information about the current installation state .
2012-08-31 15:56:36 +00:00
*
* @ see install_configure_form ()
* @ see install_configure_form_validate ()
* @ see install_configure_form_submit ()
2012-10-05 18:12:56 +00:00
* @ ingroup forms
2010-02-17 04:19:51 +00:00
*/
2010-04-23 07:50:28 +00:00
function _install_configure_form ( $form , & $form_state , & $install_state ) {
2010-02-17 04:19:51 +00:00
$form [ 'site_information' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Site information' ),
2010-02-17 04:19:51 +00:00
);
$form [ 'site_information' ][ 'site_name' ] = array (
'#type' => 'textfield' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Site name' ),
2010-02-17 04:19:51 +00:00
'#required' => TRUE ,
'#weight' => - 20 ,
);
$form [ 'site_information' ][ 'site_mail' ] = array (
2012-03-02 07:29:16 +00:00
'#type' => 'email' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Site e-mail address' ),
2010-02-17 04:19:51 +00:00
'#default_value' => ini_get ( 'sendmail_from' ),
2013-06-17 13:35:07 +00:00
'#description' => t ( " Automated e-mails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these e-mails from being flagged as spam. " ),
2010-02-17 04:19:51 +00:00
'#required' => TRUE ,
'#weight' => - 15 ,
);
$form [ 'admin_account' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Site maintenance account' ),
2010-02-17 04:19:51 +00:00
);
$form [ 'admin_account' ][ 'account' ][ '#tree' ] = TRUE ;
$form [ 'admin_account' ][ 'account' ][ 'name' ] = array ( '#type' => 'textfield' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Username' ),
2010-02-17 04:19:51 +00:00
'#maxlength' => USERNAME_MAX_LENGTH ,
2013-06-17 13:35:07 +00:00
'#description' => t ( 'Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.' ),
2010-02-17 04:19:51 +00:00
'#required' => TRUE ,
'#weight' => - 10 ,
'#attributes' => array ( 'class' => array ( 'username' )),
);
2012-03-02 07:29:16 +00:00
$form [ 'admin_account' ][ 'account' ][ 'mail' ] = array (
'#type' => 'email' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'E-mail address' ),
2010-02-17 04:19:51 +00:00
'#required' => TRUE ,
'#weight' => - 5 ,
);
$form [ 'admin_account' ][ 'account' ][ 'pass' ] = array (
'#type' => 'password_confirm' ,
'#required' => TRUE ,
'#size' => 25 ,
'#weight' => 0 ,
);
2013-06-29 21:47:17 +00:00
$form [ 'regional_settings' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2013-06-29 21:47:17 +00:00
'#title' => t ( 'Regional settings' ),
2010-02-17 04:19:51 +00:00
);
2013-06-11 22:23:08 +00:00
$countries = Drupal :: service ( 'country_manager' ) -> getList ();
2013-06-29 21:47:17 +00:00
$form [ 'regional_settings' ][ 'site_default_country' ] = array (
2010-02-17 04:19:51 +00:00
'#type' => 'select' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Default country' ),
2010-10-07 03:26:41 +00:00
'#empty_value' => '' ,
2012-11-29 07:37:55 +00:00
'#default_value' => config ( 'system.date' ) -> get ( 'country.default' ),
2010-02-17 04:19:51 +00:00
'#options' => $countries ,
2013-06-17 13:35:07 +00:00
'#description' => t ( 'Select the default country for the site.' ),
2010-02-17 04:19:51 +00:00
'#weight' => 0 ,
);
2013-06-29 21:47:17 +00:00
$form [ 'regional_settings' ][ 'date_default_timezone' ] = array (
2010-02-17 04:19:51 +00:00
'#type' => 'select' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Default time zone' ),
2010-02-17 04:19:51 +00:00
'#default_value' => date_default_timezone_get (),
'#options' => system_time_zones (),
2013-06-17 13:35:07 +00:00
'#description' => t ( 'By default, dates in this site will be displayed in the chosen time zone.' ),
2010-02-17 04:19:51 +00:00
'#weight' => 5 ,
'#attributes' => array ( 'class' => array ( 'timezone-detect' )),
);
$form [ 'update_notifications' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2013-06-17 13:35:07 +00:00
'#title' => t ( 'Update notifications' ),
2010-02-17 04:19:51 +00:00
);
$form [ 'update_notifications' ][ 'update_status_module' ] = array (
'#type' => 'checkboxes' ,
'#options' => array (
2013-06-17 13:35:07 +00:00
1 => t ( 'Check for updates automatically' ),
2 => t ( 'Receive e-mail notifications' ),
2010-02-17 04:19:51 +00:00
),
'#default_value' => array ( 1 , 2 ),
2013-06-17 13:35:07 +00:00
'#description' => t ( 'The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to <a href="@drupal">Drupal.org</a>.' , array ( '@drupal' => 'http://drupal.org' )),
2010-02-17 04:19:51 +00:00
'#weight' => 15 ,
);
2012-11-04 21:32:20 +00:00
$form [ 'update_notifications' ][ 'update_status_module' ][ 2 ] = array (
'#states' => array (
'visible' => array (
'input[name="update_status_module[1]"]' => array ( 'checked' => TRUE ),
),
),
);
2010-02-17 04:19:51 +00:00
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-02-17 04:19:51 +00:00
$form [ 'actions' ][ 'submit' ] = array (
'#type' => 'submit' ,
2013-06-17 13:35:07 +00:00
'#value' => t ( 'Save and continue' ),
2010-02-17 04:19:51 +00:00
'#weight' => 15 ,
);
return $form ;
}
/**
2012-08-31 15:56:36 +00:00
* Form validation handler for install_configure_form () .
*
* @ see install_configure_form_submit ()
2010-02-17 04:19:51 +00:00
*/
function install_configure_form_validate ( $form , & $form_state ) {
if ( $error = user_validate_name ( $form_state [ 'values' ][ 'account' ][ 'name' ])) {
form_error ( $form [ 'admin_account' ][ 'account' ][ 'name' ], $error );
}
}
/**
2012-08-31 15:56:36 +00:00
* Form submission handler for install_configure_form () .
*
* @ see install_configure_form_validate ()
2010-02-17 04:19:51 +00:00
*/
function install_configure_form_submit ( $form , & $form_state ) {
global $user ;
2012-07-02 17:20:33 +00:00
config ( 'system.site' )
-> set ( 'name' , $form_state [ 'values' ][ 'site_name' ])
-> set ( 'mail' , $form_state [ 'values' ][ 'site_mail' ])
2013-06-29 10:56:53 +00:00
-> set ( 'langcode' , language_default () -> id )
2012-07-02 17:20:33 +00:00
-> save ();
2012-12-06 16:19:03 +00:00
config ( 'system.timezone' )
-> set ( 'default' , $form_state [ 'values' ][ 'date_default_timezone' ])
-> save ();
2012-11-29 07:37:55 +00:00
config ( 'system.date' )
-> set ( 'country.default' , $form_state [ 'values' ][ 'site_default_country' ])
-> save ();
2010-02-17 04:19:51 +00:00
// Enable update.module if this option was selected.
if ( $form_state [ 'values' ][ 'update_status_module' ][ 1 ]) {
2012-08-31 17:19:49 +00:00
module_enable ( array ( 'file' , 'update' ), FALSE );
2010-02-17 04:19:51 +00:00
// Add the site maintenance account's email address to the list of
// addresses to be notified when updates are available, if selected.
if ( $form_state [ 'values' ][ 'update_status_module' ][ 2 ]) {
2012-08-03 16:52:07 +00:00
config ( 'update.settings' ) -> set ( 'notification.emails' , array ( $form_state [ 'values' ][ 'account' ][ 'mail' ])) -> save ();
2010-02-17 04:19:51 +00:00
}
}
// We precreated user 1 with placeholder values. Let's save the real values.
$account = user_load ( 1 );
2012-04-26 03:51:09 +00:00
$account -> init = $account -> mail = $form_state [ 'values' ][ 'account' ][ 'mail' ];
2013-07-24 19:40:03 +00:00
$account -> roles = $account -> getRoles ();
$account -> activate ();
2012-04-26 03:51:09 +00:00
$account -> timezone = $form_state [ 'values' ][ 'date_default_timezone' ];
$account -> pass = $form_state [ 'values' ][ 'account' ][ 'pass' ];
$account -> name = $form_state [ 'values' ][ 'account' ][ 'name' ];
$account -> save ();
2010-02-17 04:19:51 +00:00
// Load global $user and perform final login tasks.
2013-06-27 08:23:39 +00:00
$account = user_load ( 1 );
user_login_finalize ( $account );
2010-02-17 04:19:51 +00:00
// Record when this install ran.
2012-11-04 09:53:56 +00:00
variable_set ( 'install_time' , $_SERVER [ 'REQUEST_TIME' ]);
2010-02-17 04:19:51 +00:00
}