Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * API functions for installing Drupal.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Component\Utility\UrlHelper;
|
Chris@0
|
9 use Drupal\Core\DrupalKernel;
|
Chris@0
|
10 use Drupal\Core\Database\Database;
|
Chris@0
|
11 use Drupal\Core\Database\DatabaseExceptionWrapper;
|
Chris@0
|
12 use Drupal\Core\Form\FormState;
|
Chris@0
|
13 use Drupal\Core\Installer\Exception\AlreadyInstalledException;
|
Chris@0
|
14 use Drupal\Core\Installer\Exception\InstallerException;
|
Chris@0
|
15 use Drupal\Core\Installer\Exception\InstallProfileMismatchException;
|
Chris@0
|
16 use Drupal\Core\Installer\Exception\NoProfilesException;
|
Chris@0
|
17 use Drupal\Core\Installer\InstallerKernel;
|
Chris@0
|
18 use Drupal\Core\Language\Language;
|
Chris@0
|
19 use Drupal\Core\Language\LanguageManager;
|
Chris@0
|
20 use Drupal\Core\Logger\LoggerChannelFactory;
|
Chris@0
|
21 use Drupal\Core\Site\Settings;
|
Chris@0
|
22 use Drupal\Core\StringTranslation\Translator\FileTranslation;
|
Chris@0
|
23 use Drupal\Core\StackMiddleware\ReverseProxyMiddleware;
|
Chris@0
|
24 use Drupal\Core\StreamWrapper\PublicStream;
|
Chris@0
|
25 use Drupal\Core\Extension\ExtensionDiscovery;
|
Chris@0
|
26 use Drupal\Core\DependencyInjection\ContainerBuilder;
|
Chris@0
|
27 use Drupal\Core\Url;
|
Chris@0
|
28 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@0
|
29 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
Chris@0
|
30 use Symfony\Component\DependencyInjection\Reference;
|
Chris@0
|
31 use Symfony\Component\HttpFoundation\Request;
|
Chris@0
|
32 use Symfony\Component\HttpFoundation\Response;
|
Chris@0
|
33 use Symfony\Component\Routing\Route;
|
Chris@0
|
34 use Drupal\user\Entity\User;
|
Chris@0
|
35 use GuzzleHttp\Exception\RequestException;
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Do not run the task during the current installation request.
|
Chris@0
|
39 *
|
Chris@0
|
40 * This can be used to skip running an installation task when certain
|
Chris@0
|
41 * conditions are met, even though the task may still show on the list of
|
Chris@0
|
42 * installation tasks presented to the user. For example, the Drupal installer
|
Chris@0
|
43 * uses this flag to skip over the database configuration form when valid
|
Chris@0
|
44 * database connection information is already available from settings.php. It
|
Chris@0
|
45 * also uses this flag to skip language import tasks when the installation is
|
Chris@0
|
46 * being performed in English.
|
Chris@0
|
47 */
|
Chris@0
|
48 const INSTALL_TASK_SKIP = 1;
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Run the task on each installation request that reaches it.
|
Chris@0
|
52 *
|
Chris@0
|
53 * This is primarily used by the Drupal installer for bootstrap-related tasks.
|
Chris@0
|
54 */
|
Chris@0
|
55 const INSTALL_TASK_RUN_IF_REACHED = 2;
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * Run the task on each installation request until the database is set up.
|
Chris@0
|
59 *
|
Chris@0
|
60 * This is the default method for running tasks and should be used for most
|
Chris@0
|
61 * tasks that occur after the database is set up; these tasks will then run
|
Chris@0
|
62 * once and be marked complete once they are successfully finished. For
|
Chris@0
|
63 * example, the Drupal installer uses this flag for the batch installation of
|
Chris@0
|
64 * modules on the new site, and also for the configuration form that collects
|
Chris@0
|
65 * basic site information and sets up the site maintenance account.
|
Chris@0
|
66 */
|
Chris@0
|
67 const INSTALL_TASK_RUN_IF_NOT_COMPLETED = 3;
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * Installs Drupal either interactively or via an array of passed-in settings.
|
Chris@0
|
71 *
|
Chris@0
|
72 * The Drupal installation happens in a series of steps, which may be spread
|
Chris@0
|
73 * out over multiple page requests. Each request begins by trying to determine
|
Chris@0
|
74 * the last completed installation step (also known as a "task"), if one is
|
Chris@0
|
75 * available from a previous request. Control is then passed to the task
|
Chris@0
|
76 * handler, which processes the remaining tasks that need to be run until (a)
|
Chris@0
|
77 * an error is thrown, (b) a new page needs to be displayed, or (c) the
|
Chris@0
|
78 * installation finishes (whichever happens first).
|
Chris@0
|
79 *
|
Chris@0
|
80 * @param $class_loader
|
Chris@0
|
81 * The class loader. Normally Composer's ClassLoader, as included by the
|
Chris@0
|
82 * front controller, but may also be decorated; e.g.,
|
Chris@0
|
83 * \Symfony\Component\ClassLoader\ApcClassLoader.
|
Chris@0
|
84 * @param $settings
|
Chris@0
|
85 * An optional array of installation settings. Leave this empty for a normal,
|
Chris@0
|
86 * interactive, browser-based installation intended to occur over multiple
|
Chris@0
|
87 * page requests. Alternatively, if an array of settings is passed in, the
|
Chris@0
|
88 * installer will attempt to use it to perform the installation in a single
|
Chris@0
|
89 * page request (optimized for the command line) and not send any output
|
Chris@0
|
90 * intended for the web browser. See install_state_defaults() for a list of
|
Chris@0
|
91 * elements that are allowed to appear in this array.
|
Chris@0
|
92 *
|
Chris@0
|
93 * @see install_state_defaults()
|
Chris@0
|
94 */
|
Chris@0
|
95 function install_drupal($class_loader, $settings = []) {
|
Chris@0
|
96 // Support the old way of calling this function with just a settings array.
|
Chris@0
|
97 // @todo Remove this when Drush is updated in the Drupal testing
|
Chris@0
|
98 // infrastructure in https://www.drupal.org/node/2389243
|
Chris@0
|
99 if (is_array($class_loader) && $settings === []) {
|
Chris@0
|
100 $settings = $class_loader;
|
Chris@0
|
101 $class_loader = require __DIR__ . '/../../autoload.php';
|
Chris@0
|
102 }
|
Chris@0
|
103
|
Chris@0
|
104 global $install_state;
|
Chris@0
|
105 // Initialize the installation state with the settings that were passed in,
|
Chris@0
|
106 // as well as a boolean indicating whether or not this is an interactive
|
Chris@0
|
107 // installation.
|
Chris@0
|
108 $interactive = empty($settings);
|
Chris@0
|
109 $install_state = $settings + ['interactive' => $interactive] + install_state_defaults();
|
Chris@0
|
110
|
Chris@0
|
111 try {
|
Chris@0
|
112 // Begin the page request. This adds information about the current state of
|
Chris@0
|
113 // the Drupal installation to the passed-in array.
|
Chris@0
|
114 install_begin_request($class_loader, $install_state);
|
Chris@0
|
115 // Based on the installation state, run the remaining tasks for this page
|
Chris@0
|
116 // request, and collect any output.
|
Chris@0
|
117 $output = install_run_tasks($install_state);
|
Chris@0
|
118 }
|
Chris@0
|
119 catch (InstallerException $e) {
|
Chris@0
|
120 // In the non-interactive installer, exceptions are always thrown directly.
|
Chris@0
|
121 if (!$install_state['interactive']) {
|
Chris@0
|
122 throw $e;
|
Chris@0
|
123 }
|
Chris@0
|
124 $output = [
|
Chris@0
|
125 '#title' => $e->getTitle(),
|
Chris@0
|
126 '#markup' => $e->getMessage(),
|
Chris@0
|
127 ];
|
Chris@0
|
128 }
|
Chris@0
|
129
|
Chris@0
|
130 // After execution, all tasks might be complete, in which case
|
Chris@0
|
131 // $install_state['installation_finished'] is TRUE. In case the last task
|
Chris@0
|
132 // has been processed, remove the global $install_state, so other code can
|
Chris@0
|
133 // reliably check whether it is running during the installer.
|
Chris@0
|
134 // @see drupal_installation_attempted()
|
Chris@0
|
135 $state = $install_state;
|
Chris@0
|
136 if (!empty($install_state['installation_finished'])) {
|
Chris@0
|
137 unset($GLOBALS['install_state']);
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 // All available tasks for this page request are now complete. Interactive
|
Chris@0
|
141 // installations can send output to the browser or redirect the user to the
|
Chris@0
|
142 // next page.
|
Chris@0
|
143 if ($state['interactive']) {
|
Chris@0
|
144 // If a session has been initiated in this request, make sure to save it.
|
Chris@0
|
145 if ($session = \Drupal::request()->getSession()) {
|
Chris@0
|
146 $session->save();
|
Chris@0
|
147 }
|
Chris@0
|
148 if ($state['parameters_changed']) {
|
Chris@0
|
149 // Redirect to the correct page if the URL parameters have changed.
|
Chris@0
|
150 install_goto(install_redirect_url($state));
|
Chris@0
|
151 }
|
Chris@0
|
152 elseif (isset($output)) {
|
Chris@0
|
153 // Display a page only if some output is available. Otherwise it is
|
Chris@0
|
154 // possible that we are printing a JSON page and theme output should
|
Chris@0
|
155 // not be shown.
|
Chris@0
|
156 install_display_output($output, $state);
|
Chris@0
|
157 }
|
Chris@0
|
158 elseif ($state['installation_finished']) {
|
Chris@0
|
159 // Redirect to the newly installed site.
|
Chris@0
|
160 install_goto('');
|
Chris@0
|
161 }
|
Chris@0
|
162 }
|
Chris@0
|
163 }
|
Chris@0
|
164
|
Chris@0
|
165 /**
|
Chris@0
|
166 * Returns an array of default settings for the global installation state.
|
Chris@0
|
167 *
|
Chris@0
|
168 * The installation state is initialized with these settings at the beginning
|
Chris@0
|
169 * of each page request. They may evolve during the page request, but they are
|
Chris@0
|
170 * initialized again once the next request begins.
|
Chris@0
|
171 *
|
Chris@0
|
172 * Non-interactive Drupal installations can override some of these default
|
Chris@0
|
173 * settings by passing in an array to the installation script, most notably
|
Chris@0
|
174 * 'parameters' (which contains one-time parameters such as 'profile' and
|
Chris@0
|
175 * 'langcode' that are normally passed in via the URL) and 'forms' (which can
|
Chris@0
|
176 * be used to programmatically submit forms during the installation; the keys
|
Chris@0
|
177 * of each element indicate the name of the installation task that the form
|
Chris@0
|
178 * submission is for, and the values are used as the $form_state->getValues()
|
Chris@0
|
179 * array that is passed on to the form submission via
|
Chris@0
|
180 * \Drupal::formBuilder()->submitForm()).
|
Chris@0
|
181 *
|
Chris@0
|
182 * @see \Drupal\Core\Form\FormBuilderInterface::submitForm()
|
Chris@0
|
183 */
|
Chris@0
|
184 function install_state_defaults() {
|
Chris@0
|
185 $defaults = [
|
Chris@0
|
186 // The current task being processed.
|
Chris@0
|
187 'active_task' => NULL,
|
Chris@0
|
188 // The last task that was completed during the previous installation
|
Chris@0
|
189 // request.
|
Chris@0
|
190 'completed_task' => NULL,
|
Chris@0
|
191 // TRUE when there are valid config directories.
|
Chris@0
|
192 'config_verified' => FALSE,
|
Chris@0
|
193 // TRUE when there is a valid database connection.
|
Chris@0
|
194 'database_verified' => FALSE,
|
Chris@0
|
195 // TRUE if database is empty & ready to install.
|
Chris@0
|
196 'database_ready' => FALSE,
|
Chris@0
|
197 // TRUE when a valid settings.php exists (containing both database
|
Chris@0
|
198 // connection information and config directory names).
|
Chris@0
|
199 'settings_verified' => FALSE,
|
Chris@0
|
200 // TRUE when the base system has been installed and is ready to operate.
|
Chris@0
|
201 'base_system_verified' => FALSE,
|
Chris@0
|
202 // Whether a translation file for the selected language will be downloaded
|
Chris@0
|
203 // from the translation server.
|
Chris@0
|
204 'download_translation' => FALSE,
|
Chris@0
|
205 // An array of forms to be programmatically submitted during the
|
Chris@0
|
206 // installation. The keys of each element indicate the name of the
|
Chris@0
|
207 // installation task that the form submission is for, and the values are
|
Chris@0
|
208 // used as the $form_state->getValues() array that is passed on to the form
|
Chris@0
|
209 // submission via \Drupal::formBuilder()->submitForm().
|
Chris@0
|
210 'forms' => [],
|
Chris@0
|
211 // This becomes TRUE only at the end of the installation process, after
|
Chris@0
|
212 // all available tasks have been completed and Drupal is fully installed.
|
Chris@0
|
213 // It is used by the installer to store correct information in the database
|
Chris@0
|
214 // about the completed installation, as well as to inform theme functions
|
Chris@0
|
215 // that all tasks are finished (so that the task list can be displayed
|
Chris@0
|
216 // correctly).
|
Chris@0
|
217 'installation_finished' => FALSE,
|
Chris@0
|
218 // Whether or not this installation is interactive. By default this will
|
Chris@0
|
219 // be set to FALSE if settings are passed in to install_drupal().
|
Chris@0
|
220 'interactive' => TRUE,
|
Chris@0
|
221 // An array of parameters for the installation, pre-populated by the URL
|
Chris@0
|
222 // or by the settings passed in to install_drupal(). This is primarily
|
Chris@0
|
223 // used to store 'profile' (the name of the chosen installation profile)
|
Chris@0
|
224 // and 'langcode' (the code of the chosen installation language), since
|
Chris@0
|
225 // these settings need to persist from page request to page request before
|
Chris@0
|
226 // the database is available for storage.
|
Chris@0
|
227 'parameters' => [],
|
Chris@0
|
228 // Whether or not the parameters have changed during the current page
|
Chris@0
|
229 // request. For interactive installations, this will trigger a page
|
Chris@0
|
230 // redirect.
|
Chris@0
|
231 'parameters_changed' => FALSE,
|
Chris@0
|
232 // An array of information about the chosen installation profile. This will
|
Chris@0
|
233 // be filled in based on the profile's .info.yml file.
|
Chris@0
|
234 'profile_info' => [],
|
Chris@0
|
235 // An array of available installation profiles.
|
Chris@0
|
236 'profiles' => [],
|
Chris@0
|
237 // The name of the theme to use during installation.
|
Chris@0
|
238 'theme' => 'seven',
|
Chris@0
|
239 // The server URL where the interface translation files can be downloaded.
|
Chris@0
|
240 // Tokens in the pattern will be replaced by appropriate values for the
|
Chris@0
|
241 // required translation file.
|
Chris@0
|
242 'server_pattern' => 'http://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po',
|
Chris@0
|
243 // Installation tasks can set this to TRUE to force the page request to
|
Chris@0
|
244 // end (even if there is no themable output), in the case of an interactive
|
Chris@0
|
245 // installation. This is needed only rarely; for example, it would be used
|
Chris@0
|
246 // by an installation task that prints JSON output rather than returning a
|
Chris@0
|
247 // themed page. The most common example of this is during batch processing,
|
Chris@0
|
248 // but the Drupal installer automatically takes care of setting this
|
Chris@0
|
249 // parameter properly in that case, so that individual installation tasks
|
Chris@0
|
250 // which implement the batch API do not need to set it themselves.
|
Chris@0
|
251 'stop_page_request' => FALSE,
|
Chris@0
|
252 // Installation tasks can set this to TRUE to indicate that the task should
|
Chris@0
|
253 // be run again, even if it normally wouldn't be. This can be used, for
|
Chris@0
|
254 // example, if a single task needs to be spread out over multiple page
|
Chris@0
|
255 // requests, or if it needs to perform some validation before allowing
|
Chris@0
|
256 // itself to be marked complete. The most common examples of this are batch
|
Chris@0
|
257 // processing and form submissions, but the Drupal installer automatically
|
Chris@0
|
258 // takes care of setting this parameter properly in those cases, so that
|
Chris@0
|
259 // individual installation tasks which implement the batch API or form API
|
Chris@0
|
260 // do not need to set it themselves.
|
Chris@0
|
261 'task_not_complete' => FALSE,
|
Chris@0
|
262 // A list of installation tasks which have already been performed during
|
Chris@0
|
263 // the current page request.
|
Chris@0
|
264 'tasks_performed' => [],
|
Chris@0
|
265 // An array of translation files URIs available for the installation. Keyed
|
Chris@0
|
266 // by the translation language code.
|
Chris@0
|
267 'translations' => [],
|
Chris@0
|
268 ];
|
Chris@0
|
269 return $defaults;
|
Chris@0
|
270 }
|
Chris@0
|
271
|
Chris@0
|
272 /**
|
Chris@0
|
273 * Begins an installation request, modifying the installation state as needed.
|
Chris@0
|
274 *
|
Chris@0
|
275 * This function performs commands that must run at the beginning of every page
|
Chris@0
|
276 * request. It throws an exception if the installation should not proceed.
|
Chris@0
|
277 *
|
Chris@0
|
278 * @param $class_loader
|
Chris@0
|
279 * The class loader. Normally Composer's ClassLoader, as included by the
|
Chris@0
|
280 * front controller, but may also be decorated; e.g.,
|
Chris@0
|
281 * \Symfony\Component\ClassLoader\ApcClassLoader.
|
Chris@0
|
282 * @param $install_state
|
Chris@0
|
283 * An array of information about the current installation state. This is
|
Chris@0
|
284 * modified with information gleaned from the beginning of the page request.
|
Chris@0
|
285 */
|
Chris@0
|
286 function install_begin_request($class_loader, &$install_state) {
|
Chris@0
|
287 $request = Request::createFromGlobals();
|
Chris@0
|
288
|
Chris@0
|
289 // Add any installation parameters passed in via the URL.
|
Chris@0
|
290 if ($install_state['interactive']) {
|
Chris@0
|
291 $install_state['parameters'] += $request->query->all();
|
Chris@0
|
292 }
|
Chris@0
|
293
|
Chris@0
|
294 // Validate certain core settings that are used throughout the installation.
|
Chris@0
|
295 if (!empty($install_state['parameters']['profile'])) {
|
Chris@0
|
296 $install_state['parameters']['profile'] = preg_replace('/[^a-zA-Z_0-9]/', '', $install_state['parameters']['profile']);
|
Chris@0
|
297 }
|
Chris@0
|
298 if (!empty($install_state['parameters']['langcode'])) {
|
Chris@0
|
299 $install_state['parameters']['langcode'] = preg_replace('/[^a-zA-Z_0-9\-]/', '', $install_state['parameters']['langcode']);
|
Chris@0
|
300 }
|
Chris@0
|
301
|
Chris@0
|
302 // Allow command line scripts to override server variables used by Drupal.
|
Chris@0
|
303 require_once __DIR__ . '/bootstrap.inc';
|
Chris@0
|
304
|
Chris@0
|
305 // Before having installed the system module and being able to do a module
|
Chris@0
|
306 // rebuild, prime the drupal_get_filename() static cache with the module's
|
Chris@0
|
307 // exact location.
|
Chris@0
|
308 // @todo Remove as part of https://www.drupal.org/node/2186491
|
Chris@0
|
309 drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml');
|
Chris@0
|
310
|
Chris@0
|
311 // If the hash salt leaks, it becomes possible to forge a valid testing user
|
Chris@0
|
312 // agent, install a new copy of Drupal, and take over the original site.
|
Chris@0
|
313 // The user agent header is used to pass a database prefix in the request when
|
Chris@0
|
314 // running tests. However, for security reasons, it is imperative that no
|
Chris@0
|
315 // installation be permitted using such a prefix.
|
Chris@0
|
316 $user_agent = $request->cookies->get('SIMPLETEST_USER_AGENT') ?: $request->server->get('HTTP_USER_AGENT');
|
Chris@0
|
317 if ($install_state['interactive'] && strpos($user_agent, 'simpletest') !== FALSE && !drupal_valid_test_ua()) {
|
Chris@0
|
318 header($request->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
|
Chris@0
|
319 exit;
|
Chris@0
|
320 }
|
Chris@0
|
321 if ($install_state['interactive'] && drupal_valid_test_ua()) {
|
Chris@0
|
322 // Set the default timezone. While this doesn't cause any tests to fail, PHP
|
Chris@0
|
323 // complains if 'date.timezone' is not set in php.ini. The Australia/Sydney
|
Chris@0
|
324 // timezone is chosen so all tests are run using an edge case scenario
|
Chris@0
|
325 // (UTC+10 and DST). This choice is made to prevent timezone related
|
Chris@0
|
326 // regressions and reduce the fragility of the testing system in general.
|
Chris@0
|
327 date_default_timezone_set('Australia/Sydney');
|
Chris@0
|
328 }
|
Chris@0
|
329
|
Chris@0
|
330 $site_path = DrupalKernel::findSitePath($request, FALSE);
|
Chris@0
|
331 Settings::initialize(dirname(dirname(__DIR__)), $site_path, $class_loader);
|
Chris@0
|
332
|
Chris@0
|
333 // Ensure that procedural dependencies are loaded as early as possible,
|
Chris@0
|
334 // since the error/exception handlers depend on them.
|
Chris@0
|
335 require_once __DIR__ . '/../modules/system/system.install';
|
Chris@0
|
336 require_once __DIR__ . '/common.inc';
|
Chris@0
|
337 require_once __DIR__ . '/file.inc';
|
Chris@0
|
338 require_once __DIR__ . '/install.inc';
|
Chris@0
|
339 require_once __DIR__ . '/schema.inc';
|
Chris@0
|
340 require_once __DIR__ . '/database.inc';
|
Chris@0
|
341 require_once __DIR__ . '/form.inc';
|
Chris@0
|
342 require_once __DIR__ . '/batch.inc';
|
Chris@0
|
343
|
Chris@0
|
344 // Load module basics (needed for hook invokes).
|
Chris@0
|
345 include_once __DIR__ . '/module.inc';
|
Chris@0
|
346 require_once __DIR__ . '/entity.inc';
|
Chris@0
|
347
|
Chris@0
|
348 // Create a minimal mocked container to support calls to t() in the pre-kernel
|
Chris@0
|
349 // base system verification code paths below. The strings are not actually
|
Chris@0
|
350 // used or output for these calls.
|
Chris@0
|
351 // @todo Separate API level checks from UI-facing error messages.
|
Chris@0
|
352 $container = new ContainerBuilder();
|
Chris@0
|
353 $container->setParameter('language.default_values', Language::$defaultValues);
|
Chris@0
|
354 $container
|
Chris@0
|
355 ->register('language.default', 'Drupal\Core\Language\LanguageDefault')
|
Chris@0
|
356 ->addArgument('%language.default_values%');
|
Chris@0
|
357 $container
|
Chris@0
|
358 ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
|
Chris@0
|
359 ->addArgument(new Reference('language.default'));
|
Chris@0
|
360
|
Chris@0
|
361 // Register the stream wrapper manager.
|
Chris@0
|
362 $container
|
Chris@0
|
363 ->register('stream_wrapper_manager', 'Drupal\Core\StreamWrapper\StreamWrapperManager')
|
Chris@0
|
364 ->addMethodCall('setContainer', [new Reference('service_container')]);
|
Chris@0
|
365 $container
|
Chris@0
|
366 ->register('file_system', 'Drupal\Core\File\FileSystem')
|
Chris@0
|
367 ->addArgument(new Reference('stream_wrapper_manager'))
|
Chris@0
|
368 ->addArgument(Settings::getInstance())
|
Chris@0
|
369 ->addArgument((new LoggerChannelFactory())->get('file'));
|
Chris@0
|
370
|
Chris@0
|
371 \Drupal::setContainer($container);
|
Chris@0
|
372
|
Chris@0
|
373 // Determine whether base system services are ready to operate.
|
Chris@0
|
374 try {
|
Chris@0
|
375 $sync_directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
|
Chris@0
|
376 $install_state['config_verified'] = file_exists($sync_directory);
|
Chris@0
|
377 }
|
Chris@0
|
378 catch (Exception $e) {
|
Chris@0
|
379 $install_state['config_verified'] = FALSE;
|
Chris@0
|
380 }
|
Chris@0
|
381 $install_state['database_verified'] = install_verify_database_settings($site_path);
|
Chris@0
|
382 // A valid settings.php has database settings and a hash_salt value. Other
|
Chris@0
|
383 // settings like config_directories will be checked by system_requirements().
|
Chris@0
|
384 $install_state['settings_verified'] = $install_state['database_verified'] && (bool) Settings::get('hash_salt', FALSE);
|
Chris@0
|
385
|
Chris@0
|
386 // Install factory tables only after checking the database.
|
Chris@0
|
387 if ($install_state['database_verified'] && $install_state['database_ready']) {
|
Chris@0
|
388 $container
|
Chris@0
|
389 ->register('path.matcher', 'Drupal\Core\Path\PathMatcher')
|
Chris@0
|
390 ->addArgument(new Reference('config.factory'));
|
Chris@0
|
391 }
|
Chris@0
|
392
|
Chris@0
|
393 if ($install_state['settings_verified']) {
|
Chris@0
|
394 try {
|
Chris@0
|
395 $system_schema = system_schema();
|
Chris@0
|
396 end($system_schema);
|
Chris@0
|
397 $table = key($system_schema);
|
Chris@0
|
398 $install_state['base_system_verified'] = Database::getConnection()->schema()->tableExists($table);
|
Chris@0
|
399 }
|
Chris@0
|
400 catch (DatabaseExceptionWrapper $e) {
|
Chris@0
|
401 // The last defined table of the base system_schema() does not exist yet.
|
Chris@0
|
402 // $install_state['base_system_verified'] defaults to FALSE, so the code
|
Chris@0
|
403 // following below will use the minimal installer service container.
|
Chris@0
|
404 // As soon as the base system is verified here, the installer operates in
|
Chris@0
|
405 // a full and regular Drupal environment, without any kind of exceptions.
|
Chris@0
|
406 }
|
Chris@0
|
407 }
|
Chris@0
|
408
|
Chris@0
|
409 // Replace services with in-memory and null implementations. This kernel is
|
Chris@0
|
410 // replaced with a regular one in drupal_install_system().
|
Chris@0
|
411 if (!$install_state['base_system_verified']) {
|
Chris@0
|
412 $environment = 'install';
|
Chris@0
|
413 $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\InstallerServiceProvider';
|
Chris@0
|
414 }
|
Chris@0
|
415 else {
|
Chris@0
|
416 $environment = 'prod';
|
Chris@0
|
417 }
|
Chris@0
|
418
|
Chris@0
|
419 // Only allow dumping the container once the hash salt has been created.
|
Chris@0
|
420 $kernel = InstallerKernel::createFromRequest($request, $class_loader, $environment, (bool) Settings::get('hash_salt', FALSE));
|
Chris@0
|
421 $kernel->setSitePath($site_path);
|
Chris@0
|
422 $kernel->boot();
|
Chris@0
|
423 $container = $kernel->getContainer();
|
Chris@0
|
424 // If Drupal is being installed behind a proxy, configure the request.
|
Chris@0
|
425 ReverseProxyMiddleware::setSettingsOnRequest($request, Settings::getInstance());
|
Chris@0
|
426
|
Chris@0
|
427 // Register the file translation service.
|
Chris@0
|
428 if (isset($GLOBALS['config']['locale.settings']['translation']['path'])) {
|
Chris@0
|
429 $directory = $GLOBALS['config']['locale.settings']['translation']['path'];
|
Chris@0
|
430 }
|
Chris@0
|
431 else {
|
Chris@0
|
432 $directory = $site_path . '/files/translations';
|
Chris@0
|
433 }
|
Chris@0
|
434 $container->set('string_translator.file_translation', new FileTranslation($directory));
|
Chris@0
|
435 $container->get('string_translation')
|
Chris@0
|
436 ->addTranslator($container->get('string_translator.file_translation'));
|
Chris@0
|
437
|
Chris@0
|
438 // Add list of all available profiles to the installation state.
|
Chris@0
|
439 $listing = new ExtensionDiscovery($container->get('app.root'));
|
Chris@0
|
440 $listing->setProfileDirectories([]);
|
Chris@0
|
441 $install_state['profiles'] += $listing->scan('profile');
|
Chris@0
|
442
|
Chris@0
|
443 // Prime drupal_get_filename()'s static cache.
|
Chris@0
|
444 foreach ($install_state['profiles'] as $name => $profile) {
|
Chris@0
|
445 drupal_get_filename('profile', $name, $profile->getPathname());
|
Chris@0
|
446 }
|
Chris@0
|
447
|
Chris@0
|
448 if ($profile = _install_select_profile($install_state)) {
|
Chris@0
|
449 $install_state['parameters']['profile'] = $profile;
|
Chris@0
|
450 install_load_profile($install_state);
|
Chris@0
|
451 if (isset($install_state['profile_info']['distribution']['install']['theme'])) {
|
Chris@0
|
452 $install_state['theme'] = $install_state['profile_info']['distribution']['install']['theme'];
|
Chris@0
|
453 }
|
Chris@0
|
454 }
|
Chris@0
|
455
|
Chris@0
|
456 // Use the language from the profile configuration, if available, to override
|
Chris@0
|
457 // the language previously set in the parameters.
|
Chris@0
|
458 if (isset($install_state['profile_info']['distribution']['langcode'])) {
|
Chris@0
|
459 $install_state['parameters']['langcode'] = $install_state['profile_info']['distribution']['langcode'];
|
Chris@0
|
460 }
|
Chris@0
|
461
|
Chris@0
|
462 // Set the default language to the selected language, if any.
|
Chris@0
|
463 if (isset($install_state['parameters']['langcode'])) {
|
Chris@0
|
464 $default_language = new Language(['id' => $install_state['parameters']['langcode']]);
|
Chris@0
|
465 $container->get('language.default')->set($default_language);
|
Chris@0
|
466 \Drupal::translation()->setDefaultLangcode($install_state['parameters']['langcode']);
|
Chris@0
|
467 }
|
Chris@0
|
468
|
Chris@0
|
469 // Override the module list with a minimal set of modules.
|
Chris@0
|
470 $module_handler = \Drupal::moduleHandler();
|
Chris@0
|
471 if (!$module_handler->moduleExists('system')) {
|
Chris@0
|
472 $module_handler->addModule('system', 'core/modules/system');
|
Chris@0
|
473 }
|
Chris@0
|
474 if ($profile && !$module_handler->moduleExists($profile)) {
|
Chris@0
|
475 $module_handler->addProfile($profile, $install_state['profiles'][$profile]->getPath());
|
Chris@0
|
476 }
|
Chris@0
|
477
|
Chris@0
|
478 // Load all modules and perform request related initialization.
|
Chris@0
|
479 $kernel->preHandle($request);
|
Chris@0
|
480
|
Chris@0
|
481 // Initialize a route on this legacy request similar to
|
Chris@0
|
482 // \Drupal\Core\DrupalKernel::prepareLegacyRequest() since normal routing
|
Chris@0
|
483 // will not happen.
|
Chris@0
|
484 $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
|
Chris@0
|
485 $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
|
Chris@0
|
486
|
Chris@0
|
487 // Prepare for themed output. We need to run this at the beginning of the
|
Chris@0
|
488 // page request to avoid a different theme accidentally getting set. (We also
|
Chris@0
|
489 // need to run it even in the case of command-line installations, to prevent
|
Chris@0
|
490 // any code in the installer that happens to initialize the theme system from
|
Chris@0
|
491 // accessing the database before it is set up yet.)
|
Chris@0
|
492 drupal_maintenance_theme();
|
Chris@0
|
493
|
Chris@0
|
494 if ($install_state['database_verified']) {
|
Chris@0
|
495 // Verify the last completed task in the database, if there is one.
|
Chris@0
|
496 $task = install_verify_completed_task();
|
Chris@0
|
497 }
|
Chris@0
|
498 else {
|
Chris@0
|
499 $task = NULL;
|
Chris@0
|
500
|
Chris@0
|
501 // Do not install over a configured settings.php.
|
Chris@0
|
502 if (Database::getConnectionInfo()) {
|
Chris@0
|
503 throw new AlreadyInstalledException($container->get('string_translation'));
|
Chris@0
|
504 }
|
Chris@0
|
505 }
|
Chris@0
|
506
|
Chris@0
|
507 // Ensure that the active configuration is empty before installation starts.
|
Chris@0
|
508 if ($install_state['config_verified'] && empty($task)) {
|
Chris@0
|
509 if (count($kernel->getConfigStorage()->listAll())) {
|
Chris@0
|
510 $task = NULL;
|
Chris@0
|
511 throw new AlreadyInstalledException($container->get('string_translation'));
|
Chris@0
|
512 }
|
Chris@0
|
513 }
|
Chris@0
|
514
|
Chris@0
|
515 // Modify the installation state as appropriate.
|
Chris@0
|
516 $install_state['completed_task'] = $task;
|
Chris@0
|
517 }
|
Chris@0
|
518
|
Chris@0
|
519 /**
|
Chris@0
|
520 * Runs all tasks for the current installation request.
|
Chris@0
|
521 *
|
Chris@0
|
522 * In the case of an interactive installation, all tasks will be attempted
|
Chris@0
|
523 * until one is reached that has output which needs to be displayed to the
|
Chris@0
|
524 * user, or until a page redirect is required. Otherwise, tasks will be
|
Chris@0
|
525 * attempted until the installation is finished.
|
Chris@0
|
526 *
|
Chris@0
|
527 * @param $install_state
|
Chris@0
|
528 * An array of information about the current installation state. This is
|
Chris@0
|
529 * passed along to each task, so it can be modified if necessary.
|
Chris@0
|
530 *
|
Chris@0
|
531 * @return
|
Chris@0
|
532 * HTML output from the last completed task.
|
Chris@0
|
533 */
|
Chris@0
|
534 function install_run_tasks(&$install_state) {
|
Chris@0
|
535 do {
|
Chris@0
|
536 // Obtain a list of tasks to perform. The list of tasks itself can be
|
Chris@0
|
537 // dynamic (e.g., some might be defined by the installation profile,
|
Chris@0
|
538 // which is not necessarily known until the earlier tasks have run),
|
Chris@0
|
539 // so we regenerate the remaining tasks based on the installation state,
|
Chris@0
|
540 // each time through the loop.
|
Chris@0
|
541 $tasks_to_perform = install_tasks_to_perform($install_state);
|
Chris@0
|
542 // Run the first task on the list.
|
Chris@0
|
543 reset($tasks_to_perform);
|
Chris@0
|
544 $task_name = key($tasks_to_perform);
|
Chris@0
|
545 $task = array_shift($tasks_to_perform);
|
Chris@0
|
546 $install_state['active_task'] = $task_name;
|
Chris@0
|
547 $original_parameters = $install_state['parameters'];
|
Chris@0
|
548 $output = install_run_task($task, $install_state);
|
Chris@0
|
549 // Ensure the maintenance theme is initialized. If the install task has
|
Chris@0
|
550 // rebuilt the container the active theme will not be set. This can occur if
|
Chris@0
|
551 // the task has installed a module.
|
Chris@0
|
552 drupal_maintenance_theme();
|
Chris@0
|
553
|
Chris@0
|
554 $install_state['parameters_changed'] = ($install_state['parameters'] != $original_parameters);
|
Chris@0
|
555 // Store this task as having been performed during the current request,
|
Chris@0
|
556 // and save it to the database as completed, if we need to and if the
|
Chris@0
|
557 // database is in a state that allows us to do so. Also mark the
|
Chris@0
|
558 // installation as 'done' when we have run out of tasks.
|
Chris@0
|
559 if (!$install_state['task_not_complete']) {
|
Chris@0
|
560 $install_state['tasks_performed'][] = $task_name;
|
Chris@0
|
561 $install_state['installation_finished'] = empty($tasks_to_perform);
|
Chris@0
|
562 if ($task['run'] == INSTALL_TASK_RUN_IF_NOT_COMPLETED || $install_state['installation_finished']) {
|
Chris@0
|
563 \Drupal::state()->set('install_task', $install_state['installation_finished'] ? 'done' : $task_name);
|
Chris@0
|
564 }
|
Chris@0
|
565 }
|
Chris@0
|
566 // Stop when there are no tasks left. In the case of an interactive
|
Chris@0
|
567 // installation, also stop if we have some output to send to the browser,
|
Chris@0
|
568 // the URL parameters have changed, or an end to the page request was
|
Chris@0
|
569 // specifically called for.
|
Chris@0
|
570 $finished = empty($tasks_to_perform) || ($install_state['interactive'] && (isset($output) || $install_state['parameters_changed'] || $install_state['stop_page_request']));
|
Chris@0
|
571 } while (!$finished);
|
Chris@0
|
572 return $output;
|
Chris@0
|
573 }
|
Chris@0
|
574
|
Chris@0
|
575 /**
|
Chris@0
|
576 * Runs an individual installation task.
|
Chris@0
|
577 *
|
Chris@0
|
578 * @param $task
|
Chris@0
|
579 * An array of information about the task to be run as returned by
|
Chris@0
|
580 * hook_install_tasks().
|
Chris@0
|
581 * @param $install_state
|
Chris@0
|
582 * An array of information about the current installation state. This is
|
Chris@0
|
583 * passed in by reference so that it can be modified by the task.
|
Chris@0
|
584 *
|
Chris@0
|
585 * @return
|
Chris@0
|
586 * The output of the task function, if there is any.
|
Chris@0
|
587 */
|
Chris@0
|
588 function install_run_task($task, &$install_state) {
|
Chris@0
|
589 $function = $task['function'];
|
Chris@0
|
590
|
Chris@0
|
591 if ($task['type'] == 'form') {
|
Chris@0
|
592 return install_get_form($function, $install_state);
|
Chris@0
|
593 }
|
Chris@0
|
594 elseif ($task['type'] == 'batch') {
|
Chris@0
|
595 // Start a new batch based on the task function, if one is not running
|
Chris@0
|
596 // already.
|
Chris@0
|
597 $current_batch = \Drupal::state()->get('install_current_batch');
|
Chris@0
|
598 if (!$install_state['interactive'] || !$current_batch) {
|
Chris@0
|
599 $batches = $function($install_state);
|
Chris@0
|
600 if (empty($batches)) {
|
Chris@0
|
601 // If the task did some processing and decided no batch was necessary,
|
Chris@0
|
602 // there is nothing more to do here.
|
Chris@0
|
603 return;
|
Chris@0
|
604 }
|
Chris@0
|
605 // Create a one item list of batches if only one batch was provided.
|
Chris@0
|
606 if (isset($batches['operations'])) {
|
Chris@0
|
607 $batches = [$batches];
|
Chris@0
|
608 }
|
Chris@0
|
609 foreach ($batches as $batch) {
|
Chris@0
|
610 batch_set($batch);
|
Chris@0
|
611 // For interactive batches, we need to store the fact that this batch
|
Chris@0
|
612 // task is currently running. Otherwise, we need to make sure the batch
|
Chris@0
|
613 // will complete in one page request.
|
Chris@0
|
614 if ($install_state['interactive']) {
|
Chris@0
|
615 \Drupal::state()->set('install_current_batch', $function);
|
Chris@0
|
616 }
|
Chris@0
|
617 else {
|
Chris@0
|
618 $batch =& batch_get();
|
Chris@0
|
619 $batch['progressive'] = FALSE;
|
Chris@0
|
620 }
|
Chris@0
|
621 }
|
Chris@0
|
622 // Process the batch. For progressive batches, this will redirect.
|
Chris@0
|
623 // Otherwise, the batch will complete.
|
Chris@0
|
624 // Disable the default script for the URL and clone the object, as
|
Chris@0
|
625 // batch_process() will add additional options to the batch URL.
|
Chris@0
|
626 $url = Url::fromUri('base:install.php', ['query' => $install_state['parameters'], 'script' => '']);
|
Chris@0
|
627 $response = batch_process($url, clone $url);
|
Chris@0
|
628 if ($response instanceof Response) {
|
Chris@0
|
629 if ($session = \Drupal::request()->getSession()) {
|
Chris@0
|
630 $session->save();
|
Chris@0
|
631 }
|
Chris@0
|
632 // Send the response.
|
Chris@0
|
633 $response->send();
|
Chris@0
|
634 exit;
|
Chris@0
|
635 }
|
Chris@0
|
636 }
|
Chris@0
|
637 // If we are in the middle of processing this batch, keep sending back
|
Chris@0
|
638 // any output from the batch process, until the task is complete.
|
Chris@0
|
639 elseif ($current_batch == $function) {
|
Chris@0
|
640 $output = _batch_page(\Drupal::request());
|
Chris@0
|
641 // Because Batch API now returns a JSON response for intermediary steps,
|
Chris@0
|
642 // but the installer doesn't handle Response objects yet, just send the
|
Chris@0
|
643 // output here and emulate the old model.
|
Chris@0
|
644 // @todo Replace this when we refactor the installer to use a request-
|
Chris@0
|
645 // response workflow.
|
Chris@0
|
646 if ($output instanceof Response) {
|
Chris@0
|
647 $output->send();
|
Chris@0
|
648 $output = NULL;
|
Chris@0
|
649 }
|
Chris@0
|
650 // The task is complete when we try to access the batch page and receive
|
Chris@0
|
651 // FALSE in return, since this means we are at a URL where we are no
|
Chris@0
|
652 // longer requesting a batch ID.
|
Chris@0
|
653 if ($output === FALSE) {
|
Chris@0
|
654 // Return nothing so the next task will run in the same request.
|
Chris@0
|
655 \Drupal::state()->delete('install_current_batch');
|
Chris@0
|
656 return;
|
Chris@0
|
657 }
|
Chris@0
|
658 else {
|
Chris@0
|
659 // We need to force the page request to end if the task is not
|
Chris@0
|
660 // complete, since the batch API sometimes prints JSON output
|
Chris@0
|
661 // rather than returning a themed page.
|
Chris@0
|
662 $install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;
|
Chris@0
|
663 return $output;
|
Chris@0
|
664 }
|
Chris@0
|
665 }
|
Chris@0
|
666 }
|
Chris@0
|
667
|
Chris@0
|
668 else {
|
Chris@0
|
669 // For normal tasks, just return the function result, whatever it is.
|
Chris@0
|
670 return $function($install_state);
|
Chris@0
|
671 }
|
Chris@0
|
672 }
|
Chris@0
|
673
|
Chris@0
|
674 /**
|
Chris@0
|
675 * Returns a list of tasks to perform during the current installation request.
|
Chris@0
|
676 *
|
Chris@0
|
677 * Note that the list of tasks can change based on the installation state as
|
Chris@0
|
678 * the page request evolves (for example, if an installation profile hasn't
|
Chris@0
|
679 * been selected yet, we don't yet know which profile tasks need to be run).
|
Chris@0
|
680 *
|
Chris@0
|
681 * @param $install_state
|
Chris@0
|
682 * An array of information about the current installation state.
|
Chris@0
|
683 *
|
Chris@0
|
684 * @return
|
Chris@0
|
685 * A list of tasks to be performed, with associated metadata.
|
Chris@0
|
686 */
|
Chris@0
|
687 function install_tasks_to_perform($install_state) {
|
Chris@0
|
688 // Start with a list of all currently available tasks.
|
Chris@0
|
689 $tasks = install_tasks($install_state);
|
Chris@0
|
690 foreach ($tasks as $name => $task) {
|
Chris@0
|
691 // Remove any tasks that were already performed or that never should run.
|
Chris@0
|
692 // Also, if we started this page request with an indication of the last
|
Chris@0
|
693 // task that was completed, skip that task and all those that come before
|
Chris@0
|
694 // it, unless they are marked as always needing to run.
|
Chris@0
|
695 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)) {
|
Chris@0
|
696 unset($tasks[$name]);
|
Chris@0
|
697 }
|
Chris@0
|
698 if (!empty($install_state['completed_task']) && $name == $install_state['completed_task']) {
|
Chris@0
|
699 $completed_task_found = TRUE;
|
Chris@0
|
700 }
|
Chris@0
|
701 }
|
Chris@0
|
702 return $tasks;
|
Chris@0
|
703 }
|
Chris@0
|
704
|
Chris@0
|
705 /**
|
Chris@0
|
706 * Returns a list of all tasks the installer currently knows about.
|
Chris@0
|
707 *
|
Chris@0
|
708 * This function will return tasks regardless of whether or not they are
|
Chris@0
|
709 * intended to run on the current page request. However, the list can change
|
Chris@0
|
710 * based on the installation state (for example, if an installation profile
|
Chris@0
|
711 * hasn't been selected yet, we don't yet know which profile tasks will be
|
Chris@0
|
712 * available).
|
Chris@0
|
713 *
|
Chris@0
|
714 * You can override this using hook_install_tasks() or
|
Chris@0
|
715 * hook_install_tasks_alter().
|
Chris@0
|
716 *
|
Chris@0
|
717 * @param $install_state
|
Chris@0
|
718 * An array of information about the current installation state.
|
Chris@0
|
719 *
|
Chris@0
|
720 * @return
|
Chris@0
|
721 * A list of tasks, with associated metadata as returned by
|
Chris@0
|
722 * hook_install_tasks().
|
Chris@0
|
723 */
|
Chris@0
|
724 function install_tasks($install_state) {
|
Chris@0
|
725 // Determine whether a translation file must be imported during the
|
Chris@0
|
726 // 'install_import_translations' task. Import when a non-English language is
|
Chris@0
|
727 // available and selected. Also we will need translations even if the
|
Chris@0
|
728 // installer language is English but there are other languages on the system.
|
Chris@0
|
729 $needs_translations = (count($install_state['translations']) > 1 && !empty($install_state['parameters']['langcode']) && $install_state['parameters']['langcode'] != 'en') || \Drupal::languageManager()->isMultilingual();
|
Chris@0
|
730 // Determine whether a translation file must be downloaded during the
|
Chris@0
|
731 // 'install_download_translation' task. Download when a non-English language
|
Chris@0
|
732 // is selected, but no translation is yet in the translations directory.
|
Chris@0
|
733 $needs_download = isset($install_state['parameters']['langcode']) && !isset($install_state['translations'][$install_state['parameters']['langcode']]) && $install_state['parameters']['langcode'] != 'en';
|
Chris@0
|
734
|
Chris@0
|
735 // Start with the core installation tasks that run before handing control
|
Chris@0
|
736 // to the installation profile.
|
Chris@0
|
737 $tasks = [
|
Chris@0
|
738 'install_select_language' => [
|
Chris@0
|
739 'display_name' => t('Choose language'),
|
Chris@0
|
740 'run' => INSTALL_TASK_RUN_IF_REACHED,
|
Chris@0
|
741 ],
|
Chris@0
|
742 'install_download_translation' => [
|
Chris@0
|
743 'run' => $needs_download ? INSTALL_TASK_RUN_IF_REACHED : INSTALL_TASK_SKIP,
|
Chris@0
|
744 ],
|
Chris@0
|
745 'install_select_profile' => [
|
Chris@0
|
746 'display_name' => t('Choose profile'),
|
Chris@0
|
747 'display' => empty($install_state['profile_info']['distribution']['name']) && count($install_state['profiles']) != 1,
|
Chris@0
|
748 'run' => INSTALL_TASK_RUN_IF_REACHED,
|
Chris@0
|
749 ],
|
Chris@0
|
750 'install_load_profile' => [
|
Chris@0
|
751 'run' => INSTALL_TASK_RUN_IF_REACHED,
|
Chris@0
|
752 ],
|
Chris@0
|
753 'install_verify_requirements' => [
|
Chris@0
|
754 'display_name' => t('Verify requirements'),
|
Chris@0
|
755 ],
|
Chris@0
|
756 'install_settings_form' => [
|
Chris@0
|
757 'display_name' => t('Set up database'),
|
Chris@0
|
758 'type' => 'form',
|
Chris@0
|
759 // Even though the form only allows the user to enter database settings,
|
Chris@0
|
760 // we still need to display it if settings.php is invalid in any way,
|
Chris@0
|
761 // since the form submit handler is where settings.php is rewritten.
|
Chris@0
|
762 'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
|
Chris@0
|
763 'function' => 'Drupal\Core\Installer\Form\SiteSettingsForm',
|
Chris@0
|
764 ],
|
Chris@0
|
765 'install_write_profile' => [],
|
Chris@0
|
766 'install_verify_database_ready' => [
|
Chris@0
|
767 'run' => $install_state['database_ready'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
|
Chris@0
|
768 ],
|
Chris@0
|
769 'install_base_system' => [
|
Chris@0
|
770 'run' => $install_state['base_system_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
|
Chris@0
|
771 ],
|
Chris@0
|
772 // All tasks below are executed in a regular, full Drupal environment.
|
Chris@0
|
773 'install_bootstrap_full' => [
|
Chris@0
|
774 'run' => INSTALL_TASK_RUN_IF_REACHED,
|
Chris@0
|
775 ],
|
Chris@0
|
776 'install_profile_modules' => [
|
Chris@0
|
777 'display_name' => t('Install site'),
|
Chris@0
|
778 'type' => 'batch',
|
Chris@0
|
779 ],
|
Chris@0
|
780 'install_profile_themes' => [],
|
Chris@0
|
781 'install_install_profile' => [],
|
Chris@0
|
782 'install_import_translations' => [
|
Chris@0
|
783 'display_name' => t('Set up translations'),
|
Chris@0
|
784 'display' => $needs_translations,
|
Chris@0
|
785 'type' => 'batch',
|
Chris@0
|
786 'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
|
Chris@0
|
787 ],
|
Chris@0
|
788 'install_configure_form' => [
|
Chris@0
|
789 'display_name' => t('Configure site'),
|
Chris@0
|
790 'type' => 'form',
|
Chris@0
|
791 'function' => 'Drupal\Core\Installer\Form\SiteConfigureForm',
|
Chris@0
|
792 ],
|
Chris@0
|
793 ];
|
Chris@0
|
794
|
Chris@0
|
795 // Now add any tasks defined by the installation profile.
|
Chris@0
|
796 if (!empty($install_state['parameters']['profile'])) {
|
Chris@0
|
797 // Load the profile install file, because it is not always loaded when
|
Chris@0
|
798 // hook_install_tasks() is invoked (e.g. batch processing).
|
Chris@0
|
799 $profile = $install_state['parameters']['profile'];
|
Chris@0
|
800 $profile_install_file = $install_state['profiles'][$profile]->getPath() . '/' . $profile . '.install';
|
Chris@0
|
801 if (file_exists($profile_install_file)) {
|
Chris@0
|
802 include_once \Drupal::root() . '/' . $profile_install_file;
|
Chris@0
|
803 }
|
Chris@0
|
804 $function = $install_state['parameters']['profile'] . '_install_tasks';
|
Chris@0
|
805 if (function_exists($function)) {
|
Chris@0
|
806 $result = $function($install_state);
|
Chris@0
|
807 if (is_array($result)) {
|
Chris@0
|
808 $tasks += $result;
|
Chris@0
|
809 }
|
Chris@0
|
810 }
|
Chris@0
|
811 }
|
Chris@0
|
812
|
Chris@0
|
813 // Finish by adding the remaining core tasks.
|
Chris@0
|
814 $tasks += [
|
Chris@0
|
815 'install_finish_translations' => [
|
Chris@0
|
816 'display_name' => t('Finish translations'),
|
Chris@0
|
817 'display' => $needs_translations,
|
Chris@0
|
818 'type' => 'batch',
|
Chris@0
|
819 'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
|
Chris@0
|
820 ],
|
Chris@0
|
821 'install_finished' => [],
|
Chris@0
|
822 ];
|
Chris@0
|
823
|
Chris@0
|
824 // Allow the installation profile to modify the full list of tasks.
|
Chris@0
|
825 if (!empty($install_state['parameters']['profile'])) {
|
Chris@0
|
826 $profile = $install_state['parameters']['profile'];
|
Chris@0
|
827 if ($install_state['profiles'][$profile]->load()) {
|
Chris@0
|
828 $function = $install_state['parameters']['profile'] . '_install_tasks_alter';
|
Chris@0
|
829 if (function_exists($function)) {
|
Chris@0
|
830 $function($tasks, $install_state);
|
Chris@0
|
831 }
|
Chris@0
|
832 }
|
Chris@0
|
833 }
|
Chris@0
|
834
|
Chris@0
|
835 // Fill in default parameters for each task before returning the list.
|
Chris@0
|
836 foreach ($tasks as $task_name => &$task) {
|
Chris@0
|
837 $task += [
|
Chris@0
|
838 'display_name' => NULL,
|
Chris@0
|
839 'display' => !empty($task['display_name']),
|
Chris@0
|
840 'type' => 'normal',
|
Chris@0
|
841 'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
|
Chris@0
|
842 'function' => $task_name,
|
Chris@0
|
843 ];
|
Chris@0
|
844 }
|
Chris@0
|
845 return $tasks;
|
Chris@0
|
846 }
|
Chris@0
|
847
|
Chris@0
|
848 /**
|
Chris@0
|
849 * Returns a list of tasks that should be displayed to the end user.
|
Chris@0
|
850 *
|
Chris@0
|
851 * The output of this function is a list suitable for sending to
|
Chris@0
|
852 * maintenance-task-list.html.twig.
|
Chris@0
|
853 *
|
Chris@0
|
854 * @param $install_state
|
Chris@0
|
855 * An array of information about the current installation state.
|
Chris@0
|
856 *
|
Chris@0
|
857 * @return
|
Chris@0
|
858 * A list of tasks, with keys equal to the machine-readable task name and
|
Chris@0
|
859 * values equal to the name that should be displayed.
|
Chris@0
|
860 *
|
Chris@0
|
861 * @see maintenance-task-list.html.twig
|
Chris@0
|
862 */
|
Chris@0
|
863 function install_tasks_to_display($install_state) {
|
Chris@0
|
864 $displayed_tasks = [];
|
Chris@0
|
865 foreach (install_tasks($install_state) as $name => $task) {
|
Chris@0
|
866 if ($task['display']) {
|
Chris@0
|
867 $displayed_tasks[$name] = $task['display_name'];
|
Chris@0
|
868 }
|
Chris@0
|
869 }
|
Chris@0
|
870 return $displayed_tasks;
|
Chris@0
|
871 }
|
Chris@0
|
872
|
Chris@0
|
873 /**
|
Chris@0
|
874 * Builds and processes a form for the installer environment.
|
Chris@0
|
875 *
|
Chris@0
|
876 * Ensures that FormBuilder does not redirect after submitting a form, since the
|
Chris@0
|
877 * installer uses a custom step/flow logic via install_run_tasks().
|
Chris@0
|
878 *
|
Chris@0
|
879 * @param string|array $form_id
|
Chris@0
|
880 * The form ID to build and process.
|
Chris@0
|
881 * @param array $install_state
|
Chris@0
|
882 * The current state of the installation.
|
Chris@0
|
883 *
|
Chris@0
|
884 * @return array|null
|
Chris@0
|
885 * A render array containing the form to render, or NULL in case the form was
|
Chris@0
|
886 * successfully submitted.
|
Chris@0
|
887 *
|
Chris@0
|
888 * @throws \Drupal\Core\Installer\Exception\InstallerException
|
Chris@0
|
889 */
|
Chris@0
|
890 function install_get_form($form_id, array &$install_state) {
|
Chris@0
|
891 // Ensure the form will not redirect, since install_run_tasks() uses a custom
|
Chris@0
|
892 // redirection logic.
|
Chris@0
|
893 $form_state = (new FormState())
|
Chris@0
|
894 ->addBuildInfo('args', [&$install_state])
|
Chris@0
|
895 ->disableRedirect();
|
Chris@0
|
896 $form_builder = \Drupal::formBuilder();
|
Chris@0
|
897 if ($install_state['interactive']) {
|
Chris@0
|
898 $form = $form_builder->buildForm($form_id, $form_state);
|
Chris@0
|
899 // If the form submission was not successful, the form needs to be rendered,
|
Chris@0
|
900 // which means the task is not complete yet.
|
Chris@0
|
901 if (!$form_state->isExecuted()) {
|
Chris@0
|
902 $install_state['task_not_complete'] = TRUE;
|
Chris@0
|
903 return $form;
|
Chris@0
|
904 }
|
Chris@0
|
905 }
|
Chris@0
|
906 else {
|
Chris@0
|
907 // For non-interactive installs, submit the form programmatically with the
|
Chris@0
|
908 // values taken from the installation state.
|
Chris@0
|
909 $install_form_id = $form_builder->getFormId($form_id, $form_state);
|
Chris@0
|
910 if (!empty($install_state['forms'][$install_form_id])) {
|
Chris@0
|
911 $form_state->setValues($install_state['forms'][$install_form_id]);
|
Chris@0
|
912 }
|
Chris@0
|
913 $form_builder->submitForm($form_id, $form_state);
|
Chris@0
|
914
|
Chris@0
|
915 // Throw an exception in case of any form validation error.
|
Chris@0
|
916 if ($errors = $form_state->getErrors()) {
|
Chris@0
|
917 throw new InstallerException(implode("\n", $errors));
|
Chris@0
|
918 }
|
Chris@0
|
919 }
|
Chris@0
|
920 }
|
Chris@0
|
921
|
Chris@0
|
922 /**
|
Chris@0
|
923 * Returns the URL that should be redirected to during an installation request.
|
Chris@0
|
924 *
|
Chris@0
|
925 * The output of this function is suitable for sending to install_goto().
|
Chris@0
|
926 *
|
Chris@0
|
927 * @param $install_state
|
Chris@0
|
928 * An array of information about the current installation state.
|
Chris@0
|
929 *
|
Chris@0
|
930 * @return
|
Chris@0
|
931 * The URL to redirect to.
|
Chris@0
|
932 *
|
Chris@0
|
933 * @see install_full_redirect_url()
|
Chris@0
|
934 */
|
Chris@0
|
935 function install_redirect_url($install_state) {
|
Chris@0
|
936 return 'core/install.php?' . UrlHelper::buildQuery($install_state['parameters']);
|
Chris@0
|
937 }
|
Chris@0
|
938
|
Chris@0
|
939 /**
|
Chris@0
|
940 * Returns the complete URL redirected to during an installation request.
|
Chris@0
|
941 *
|
Chris@0
|
942 * @param $install_state
|
Chris@0
|
943 * An array of information about the current installation state.
|
Chris@0
|
944 *
|
Chris@0
|
945 * @return
|
Chris@0
|
946 * The complete URL to redirect to.
|
Chris@0
|
947 *
|
Chris@0
|
948 * @see install_redirect_url()
|
Chris@0
|
949 */
|
Chris@0
|
950 function install_full_redirect_url($install_state) {
|
Chris@0
|
951 global $base_url;
|
Chris@0
|
952 return $base_url . '/' . install_redirect_url($install_state);
|
Chris@0
|
953 }
|
Chris@0
|
954
|
Chris@0
|
955 /**
|
Chris@0
|
956 * Displays themed installer output and ends the page request.
|
Chris@0
|
957 *
|
Chris@0
|
958 * Installation tasks should use #title to set the desired page
|
Chris@0
|
959 * title, but otherwise this function takes care of theming the overall page
|
Chris@0
|
960 * output during every step of the installation.
|
Chris@0
|
961 *
|
Chris@0
|
962 * @param $output
|
Chris@0
|
963 * The content to display on the main part of the page.
|
Chris@0
|
964 * @param $install_state
|
Chris@0
|
965 * An array of information about the current installation state.
|
Chris@0
|
966 */
|
Chris@0
|
967 function install_display_output($output, $install_state) {
|
Chris@0
|
968 // Ensure the maintenance theme is initialized.
|
Chris@0
|
969 // The regular initialization call in install_begin_request() may not be
|
Chris@0
|
970 // reached in case of an early installer error.
|
Chris@0
|
971 drupal_maintenance_theme();
|
Chris@0
|
972
|
Chris@0
|
973 // Prevent install.php from being indexed when installed in a sub folder.
|
Chris@0
|
974 // robots.txt rules are not read if the site is within domain.com/subfolder
|
Chris@0
|
975 // resulting in /subfolder/install.php being found through search engines.
|
Chris@0
|
976 // When settings.php is writeable this can be used via an external database
|
Chris@0
|
977 // leading a malicious user to gain php access to the server.
|
Chris@0
|
978 $noindex_meta_tag = [
|
Chris@0
|
979 '#tag' => 'meta',
|
Chris@0
|
980 '#attributes' => [
|
Chris@0
|
981 'name' => 'robots',
|
Chris@0
|
982 'content' => 'noindex, nofollow',
|
Chris@0
|
983 ],
|
Chris@0
|
984 ];
|
Chris@0
|
985 $output['#attached']['html_head'][] = [$noindex_meta_tag, 'install_meta_robots'];
|
Chris@0
|
986
|
Chris@0
|
987 // Only show the task list if there is an active task; otherwise, the page
|
Chris@0
|
988 // request has ended before tasks have even been started, so there is nothing
|
Chris@0
|
989 // meaningful to show.
|
Chris@0
|
990 $regions = [];
|
Chris@0
|
991 if (isset($install_state['active_task'])) {
|
Chris@0
|
992 // Let the theming function know when every step of the installation has
|
Chris@0
|
993 // been completed.
|
Chris@0
|
994 $active_task = $install_state['installation_finished'] ? NULL : $install_state['active_task'];
|
Chris@0
|
995 $task_list = [
|
Chris@0
|
996 '#theme' => 'maintenance_task_list',
|
Chris@0
|
997 '#items' => install_tasks_to_display($install_state),
|
Chris@0
|
998 '#active' => $active_task,
|
Chris@0
|
999 ];
|
Chris@0
|
1000 $regions['sidebar_first'] = $task_list;
|
Chris@0
|
1001 }
|
Chris@0
|
1002
|
Chris@0
|
1003 $bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
|
Chris@0
|
1004 $response = $bare_html_page_renderer->renderBarePage($output, $output['#title'], 'install_page', $regions);
|
Chris@0
|
1005 $default_headers = [
|
Chris@0
|
1006 'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT',
|
Chris@0
|
1007 'Last-Modified' => gmdate(DATE_RFC1123, REQUEST_TIME),
|
Chris@0
|
1008 'Cache-Control' => 'no-cache, must-revalidate',
|
Chris@0
|
1009 'ETag' => '"' . REQUEST_TIME . '"',
|
Chris@0
|
1010 ];
|
Chris@0
|
1011 $response->headers->add($default_headers);
|
Chris@0
|
1012 $response->send();
|
Chris@0
|
1013 exit;
|
Chris@0
|
1014 }
|
Chris@0
|
1015
|
Chris@0
|
1016 /**
|
Chris@0
|
1017 * Verifies the requirements for installing Drupal.
|
Chris@0
|
1018 *
|
Chris@0
|
1019 * @param $install_state
|
Chris@0
|
1020 * An array of information about the current installation state.
|
Chris@0
|
1021 *
|
Chris@0
|
1022 * @return
|
Chris@0
|
1023 * A themed status report, or an exception if there are requirement errors.
|
Chris@0
|
1024 */
|
Chris@0
|
1025 function install_verify_requirements(&$install_state) {
|
Chris@0
|
1026 // Check the installation requirements for Drupal and this profile.
|
Chris@0
|
1027 $requirements = install_check_requirements($install_state);
|
Chris@0
|
1028
|
Chris@0
|
1029 // Verify existence of all required modules.
|
Chris@0
|
1030 $requirements += drupal_verify_profile($install_state);
|
Chris@0
|
1031
|
Chris@0
|
1032 return install_display_requirements($install_state, $requirements);
|
Chris@0
|
1033 }
|
Chris@0
|
1034
|
Chris@0
|
1035 /**
|
Chris@0
|
1036 * Installation task; install the base functionality Drupal needs to bootstrap.
|
Chris@0
|
1037 *
|
Chris@0
|
1038 * @param $install_state
|
Chris@0
|
1039 * An array of information about the current installation state.
|
Chris@0
|
1040 */
|
Chris@0
|
1041 function install_base_system(&$install_state) {
|
Chris@0
|
1042 // Install system.module.
|
Chris@0
|
1043 drupal_install_system($install_state);
|
Chris@0
|
1044
|
Chris@0
|
1045 // Prevent the installer from using the system temporary directory after the
|
Chris@0
|
1046 // system module has been installed.
|
Chris@0
|
1047 if (drupal_valid_test_ua()) {
|
Chris@0
|
1048 // While the temporary directory could be preset/enforced in settings.php
|
Chris@0
|
1049 // like the public files directory, some tests expect it to be configurable
|
Chris@0
|
1050 // in the UI. If declared in settings.php, they would no longer be
|
Chris@0
|
1051 // configurable. The temporary directory needs to match what is set in each
|
Chris@0
|
1052 // test types ::prepareEnvironment() step.
|
Chris@0
|
1053 $temporary_directory = dirname(PublicStream::basePath()) . '/temp';
|
Chris@0
|
1054 file_prepare_directory($temporary_directory, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
|
Chris@0
|
1055 \Drupal::configFactory()->getEditable('system.file')
|
Chris@0
|
1056 ->set('path.temporary', $temporary_directory)
|
Chris@0
|
1057 ->save();
|
Chris@0
|
1058 }
|
Chris@0
|
1059
|
Chris@0
|
1060 // Call file_ensure_htaccess() to ensure that all of Drupal's standard
|
Chris@0
|
1061 // directories (e.g., the public files directory and config directory) have
|
Chris@0
|
1062 // appropriate .htaccess files. These directories will have already been
|
Chris@0
|
1063 // created by this point in the installer, since Drupal creates them during
|
Chris@0
|
1064 // the install_verify_requirements() task. Note that we cannot call
|
Chris@0
|
1065 // file_ensure_access() any earlier than this, since it relies on
|
Chris@0
|
1066 // system.module in order to work.
|
Chris@0
|
1067 file_ensure_htaccess();
|
Chris@0
|
1068
|
Chris@0
|
1069 // Prime the drupal_get_filename() static cache with the user module's
|
Chris@0
|
1070 // exact location.
|
Chris@0
|
1071 // @todo Remove as part of https://www.drupal.org/node/2186491
|
Chris@0
|
1072 drupal_get_filename('module', 'user', 'core/modules/user/user.info.yml');
|
Chris@0
|
1073
|
Chris@0
|
1074 // Enable the user module so that sessions can be recorded during the
|
Chris@0
|
1075 // upcoming bootstrap step.
|
Chris@0
|
1076 \Drupal::service('module_installer')->install(['user'], FALSE);
|
Chris@0
|
1077
|
Chris@0
|
1078 // Save the list of other modules to install for the upcoming tasks.
|
Chris@0
|
1079 // State can be set to the database now that system.module is installed.
|
Chris@0
|
1080 $modules = $install_state['profile_info']['dependencies'];
|
Chris@0
|
1081
|
Chris@0
|
1082 \Drupal::state()->set('install_profile_modules', array_diff($modules, ['system']));
|
Chris@0
|
1083 $install_state['base_system_verified'] = TRUE;
|
Chris@0
|
1084 }
|
Chris@0
|
1085
|
Chris@0
|
1086 /**
|
Chris@0
|
1087 * Verifies and returns the last installation task that was completed.
|
Chris@0
|
1088 *
|
Chris@0
|
1089 * @return
|
Chris@0
|
1090 * The last completed task, if there is one. An exception is thrown if Drupal
|
Chris@0
|
1091 * is already installed.
|
Chris@0
|
1092 */
|
Chris@0
|
1093 function install_verify_completed_task() {
|
Chris@0
|
1094 try {
|
Chris@0
|
1095 $task = \Drupal::state()->get('install_task');
|
Chris@0
|
1096 }
|
Chris@0
|
1097 // Do not trigger an error if the database query fails, since the database
|
Chris@0
|
1098 // might not be set up yet.
|
Chris@0
|
1099 catch (\Exception $e) {
|
Chris@0
|
1100 }
|
Chris@0
|
1101 if (isset($task)) {
|
Chris@0
|
1102 if ($task == 'done') {
|
Chris@0
|
1103 throw new AlreadyInstalledException(\Drupal::service('string_translation'));
|
Chris@0
|
1104 }
|
Chris@0
|
1105 return $task;
|
Chris@0
|
1106 }
|
Chris@0
|
1107 }
|
Chris@0
|
1108
|
Chris@0
|
1109 /**
|
Chris@0
|
1110 * Verifies that settings.php specifies a valid database connection.
|
Chris@0
|
1111 *
|
Chris@0
|
1112 * @param string $site_path
|
Chris@0
|
1113 * The site path.
|
Chris@0
|
1114 *
|
Chris@0
|
1115 * @return bool
|
Chris@0
|
1116 * TRUE if there are no database errors.
|
Chris@0
|
1117 */
|
Chris@0
|
1118 function install_verify_database_settings($site_path) {
|
Chris@0
|
1119 if ($database = Database::getConnectionInfo()) {
|
Chris@0
|
1120 $database = $database['default'];
|
Chris@0
|
1121 $settings_file = './' . $site_path . '/settings.php';
|
Chris@0
|
1122 $errors = install_database_errors($database, $settings_file);
|
Chris@0
|
1123 if (empty($errors)) {
|
Chris@0
|
1124 return TRUE;
|
Chris@0
|
1125 }
|
Chris@0
|
1126 }
|
Chris@0
|
1127 return FALSE;
|
Chris@0
|
1128 }
|
Chris@0
|
1129
|
Chris@0
|
1130 /**
|
Chris@0
|
1131 * Verify that the database is ready (no existing Drupal installation).
|
Chris@0
|
1132 */
|
Chris@0
|
1133 function install_verify_database_ready() {
|
Chris@0
|
1134 $system_schema = system_schema();
|
Chris@0
|
1135 end($system_schema);
|
Chris@0
|
1136 $table = key($system_schema);
|
Chris@0
|
1137
|
Chris@0
|
1138 if ($database = Database::getConnectionInfo()) {
|
Chris@0
|
1139 if (Database::getConnection()->schema()->tableExists($table)) {
|
Chris@0
|
1140 throw new AlreadyInstalledException(\Drupal::service('string_translation'));
|
Chris@0
|
1141 }
|
Chris@0
|
1142 }
|
Chris@0
|
1143 }
|
Chris@0
|
1144
|
Chris@0
|
1145 /**
|
Chris@0
|
1146 * Checks a database connection and returns any errors.
|
Chris@0
|
1147 */
|
Chris@0
|
1148 function install_database_errors($database, $settings_file) {
|
Chris@0
|
1149 $errors = [];
|
Chris@0
|
1150
|
Chris@0
|
1151 // Check database type.
|
Chris@0
|
1152 $database_types = drupal_get_database_types();
|
Chris@0
|
1153 $driver = $database['driver'];
|
Chris@0
|
1154 if (!isset($database_types[$driver])) {
|
Chris@0
|
1155 $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.", ['%settings_file' => $settings_file, '@drupal' => drupal_install_profile_distribution_name(), '%driver' => $driver]);
|
Chris@0
|
1156 }
|
Chris@0
|
1157 else {
|
Chris@0
|
1158 // Run driver specific validation
|
Chris@0
|
1159 $errors += $database_types[$driver]->validateDatabaseSettings($database);
|
Chris@0
|
1160 if (!empty($errors)) {
|
Chris@0
|
1161 // No point to try further.
|
Chris@0
|
1162 return $errors;
|
Chris@0
|
1163 }
|
Chris@0
|
1164 // Run tasks associated with the database type. Any errors are caught in the
|
Chris@0
|
1165 // calling function.
|
Chris@0
|
1166 Database::addConnectionInfo('default', 'default', $database);
|
Chris@0
|
1167
|
Chris@0
|
1168 $errors = db_installer_object($driver)->runTasks();
|
Chris@0
|
1169 }
|
Chris@0
|
1170 return $errors;
|
Chris@0
|
1171 }
|
Chris@0
|
1172
|
Chris@0
|
1173 /**
|
Chris@0
|
1174 * Selects which profile to install.
|
Chris@0
|
1175 *
|
Chris@0
|
1176 * @param $install_state
|
Chris@0
|
1177 * An array of information about the current installation state. The chosen
|
Chris@0
|
1178 * profile will be added here, if it was not already selected previously, as
|
Chris@0
|
1179 * will a list of all available profiles.
|
Chris@0
|
1180 *
|
Chris@0
|
1181 * @return
|
Chris@0
|
1182 * For interactive installations, a form allowing the profile to be selected,
|
Chris@0
|
1183 * if the user has a choice that needs to be made. Otherwise, an exception is
|
Chris@0
|
1184 * thrown if a profile cannot be chosen automatically.
|
Chris@0
|
1185 */
|
Chris@0
|
1186 function install_select_profile(&$install_state) {
|
Chris@0
|
1187 if (empty($install_state['parameters']['profile'])) {
|
Chris@0
|
1188 // If there are no profiles at all, installation cannot proceed.
|
Chris@0
|
1189 if (empty($install_state['profiles'])) {
|
Chris@0
|
1190 throw new NoProfilesException(\Drupal::service('string_translation'));
|
Chris@0
|
1191 }
|
Chris@0
|
1192 // Try to automatically select a profile.
|
Chris@0
|
1193 if ($profile = _install_select_profile($install_state)) {
|
Chris@0
|
1194 $install_state['parameters']['profile'] = $profile;
|
Chris@0
|
1195 }
|
Chris@0
|
1196 else {
|
Chris@0
|
1197 // The non-interactive installer requires a profile parameter.
|
Chris@0
|
1198 if (!$install_state['interactive']) {
|
Chris@0
|
1199 throw new InstallerException(t('Missing profile parameter.'));
|
Chris@0
|
1200 }
|
Chris@0
|
1201 // Otherwise, display a form to select a profile.
|
Chris@0
|
1202 return install_get_form('Drupal\Core\Installer\Form\SelectProfileForm', $install_state);
|
Chris@0
|
1203 }
|
Chris@0
|
1204 }
|
Chris@0
|
1205 }
|
Chris@0
|
1206
|
Chris@0
|
1207 /**
|
Chris@0
|
1208 * Determines the installation profile to use in the installer.
|
Chris@0
|
1209 *
|
Chris@0
|
1210 * A profile will be selected in the following order of conditions:
|
Chris@0
|
1211 * - Only one profile is available.
|
Chris@0
|
1212 * - A specific profile name is requested in installation parameters:
|
Chris@0
|
1213 * - For interactive installations via request query parameters.
|
Chris@0
|
1214 * - For non-interactive installations via install_drupal() settings.
|
Chris@0
|
1215 * - A discovered profile that is a distribution. If multiple profiles are
|
Chris@0
|
1216 * distributions, then the first discovered profile will be selected.
|
Chris@0
|
1217 * - Only one visible profile is available.
|
Chris@0
|
1218 *
|
Chris@0
|
1219 * @param array $install_state
|
Chris@0
|
1220 * The current installer state, containing a 'profiles' key, which is an
|
Chris@0
|
1221 * associative array of profiles with the machine-readable names as keys.
|
Chris@0
|
1222 *
|
Chris@0
|
1223 * @return
|
Chris@0
|
1224 * The machine-readable name of the selected profile or NULL if no profile was
|
Chris@0
|
1225 * selected.
|
Chris@0
|
1226 */
|
Chris@0
|
1227 function _install_select_profile(&$install_state) {
|
Chris@0
|
1228 // Don't need to choose profile if only one available.
|
Chris@0
|
1229 if (count($install_state['profiles']) == 1) {
|
Chris@0
|
1230 return key($install_state['profiles']);
|
Chris@0
|
1231 }
|
Chris@0
|
1232 if (!empty($install_state['parameters']['profile'])) {
|
Chris@0
|
1233 $profile = $install_state['parameters']['profile'];
|
Chris@0
|
1234 if (isset($install_state['profiles'][$profile])) {
|
Chris@0
|
1235 return $profile;
|
Chris@0
|
1236 }
|
Chris@0
|
1237 }
|
Chris@0
|
1238 // Check for a distribution profile.
|
Chris@0
|
1239 foreach ($install_state['profiles'] as $profile) {
|
Chris@0
|
1240 $profile_info = install_profile_info($profile->getName());
|
Chris@0
|
1241 if (!empty($profile_info['distribution'])) {
|
Chris@0
|
1242 return $profile->getName();
|
Chris@0
|
1243 }
|
Chris@0
|
1244 }
|
Chris@0
|
1245
|
Chris@0
|
1246 // Get all visible (not hidden) profiles.
|
Chris@0
|
1247 $visible_profiles = array_filter($install_state['profiles'], function ($profile) {
|
Chris@0
|
1248 $profile_info = install_profile_info($profile->getName());
|
Chris@0
|
1249 return !isset($profile_info['hidden']) || !$profile_info['hidden'];
|
Chris@0
|
1250 });
|
Chris@0
|
1251
|
Chris@0
|
1252 if (count($visible_profiles) == 1) {
|
Chris@0
|
1253 return (key($visible_profiles));
|
Chris@0
|
1254 }
|
Chris@0
|
1255 }
|
Chris@0
|
1256
|
Chris@0
|
1257 /**
|
Chris@0
|
1258 * Finds all .po files that are useful to the installer.
|
Chris@0
|
1259 *
|
Chris@0
|
1260 * @return
|
Chris@0
|
1261 * An associative array of file URIs keyed by language code. URIs as
|
Chris@0
|
1262 * returned by file_scan_directory().
|
Chris@0
|
1263 *
|
Chris@0
|
1264 * @see file_scan_directory()
|
Chris@0
|
1265 */
|
Chris@0
|
1266 function install_find_translations() {
|
Chris@0
|
1267 $translations = [];
|
Chris@0
|
1268 $files = \Drupal::service('string_translator.file_translation')->findTranslationFiles();
|
Chris@0
|
1269 // English does not need a translation file.
|
Chris@0
|
1270 array_unshift($files, (object) ['name' => 'en']);
|
Chris@0
|
1271 foreach ($files as $uri => $file) {
|
Chris@0
|
1272 // Strip off the file name component before the language code.
|
Chris@0
|
1273 $langcode = preg_replace('!^(.+\.)?([^\.]+)$!', '\2', $file->name);
|
Chris@0
|
1274 // Language codes cannot exceed 12 characters to fit into the {language}
|
Chris@0
|
1275 // table.
|
Chris@0
|
1276 if (strlen($langcode) <= 12) {
|
Chris@0
|
1277 $translations[$langcode] = $uri;
|
Chris@0
|
1278 }
|
Chris@0
|
1279 }
|
Chris@0
|
1280 return $translations;
|
Chris@0
|
1281 }
|
Chris@0
|
1282
|
Chris@0
|
1283 /**
|
Chris@0
|
1284 * Selects which language to use during installation.
|
Chris@0
|
1285 *
|
Chris@0
|
1286 * @param $install_state
|
Chris@0
|
1287 * An array of information about the current installation state. The chosen
|
Chris@0
|
1288 * langcode will be added here, if it was not already selected previously, as
|
Chris@0
|
1289 * will a list of all available languages.
|
Chris@0
|
1290 *
|
Chris@0
|
1291 * @return
|
Chris@0
|
1292 * For interactive installations, a form or other page output allowing the
|
Chris@0
|
1293 * language to be selected or providing information about language selection,
|
Chris@0
|
1294 * if a language has not been chosen. Otherwise, an exception is thrown if a
|
Chris@0
|
1295 * language cannot be chosen automatically.
|
Chris@0
|
1296 */
|
Chris@0
|
1297 function install_select_language(&$install_state) {
|
Chris@0
|
1298 // Find all available translation files.
|
Chris@0
|
1299 $files = install_find_translations();
|
Chris@0
|
1300 $install_state['translations'] += $files;
|
Chris@0
|
1301
|
Chris@0
|
1302 // If a valid language code is set, continue with the next installation step.
|
Chris@0
|
1303 // When translations from the localization server are used, any language code
|
Chris@0
|
1304 // is accepted because the standard language list is kept in sync with the
|
Chris@0
|
1305 // languages available at http://localize.drupal.org.
|
Chris@0
|
1306 // When files from the translation directory are used, we only accept
|
Chris@0
|
1307 // languages for which a file is available.
|
Chris@0
|
1308 if (!empty($install_state['parameters']['langcode'])) {
|
Chris@0
|
1309 $standard_languages = LanguageManager::getStandardLanguageList();
|
Chris@0
|
1310 $langcode = $install_state['parameters']['langcode'];
|
Chris@0
|
1311 if ($langcode == 'en' || isset($files[$langcode]) || isset($standard_languages[$langcode])) {
|
Chris@0
|
1312 $install_state['parameters']['langcode'] = $langcode;
|
Chris@0
|
1313 return;
|
Chris@0
|
1314 }
|
Chris@0
|
1315 }
|
Chris@0
|
1316
|
Chris@0
|
1317 if (empty($install_state['parameters']['langcode'])) {
|
Chris@0
|
1318 // If we are performing an interactive installation, we display a form to
|
Chris@0
|
1319 // select a right language. If no translation files were found in the
|
Chris@0
|
1320 // translations directory, the form shows a list of standard languages. If
|
Chris@0
|
1321 // translation files were found the form shows a select list of the
|
Chris@0
|
1322 // corresponding languages to choose from.
|
Chris@0
|
1323 if ($install_state['interactive']) {
|
Chris@0
|
1324 return install_get_form('Drupal\Core\Installer\Form\SelectLanguageForm', $install_state);
|
Chris@0
|
1325 }
|
Chris@0
|
1326 // If we are performing a non-interactive installation. If only one language
|
Chris@0
|
1327 // (English) is available, assume the user knows what he is doing. Otherwise
|
Chris@0
|
1328 // throw an error.
|
Chris@0
|
1329 else {
|
Chris@0
|
1330 if (count($files) == 1) {
|
Chris@0
|
1331 $install_state['parameters']['langcode'] = current(array_keys($files));
|
Chris@0
|
1332 return;
|
Chris@0
|
1333 }
|
Chris@0
|
1334 else {
|
Chris@0
|
1335 throw new InstallerException(t('You must select a language to continue the installation.'));
|
Chris@0
|
1336 }
|
Chris@0
|
1337 }
|
Chris@0
|
1338 }
|
Chris@0
|
1339 }
|
Chris@0
|
1340
|
Chris@0
|
1341 /**
|
Chris@0
|
1342 * Download a translation file for the selected language.
|
Chris@0
|
1343 *
|
Chris@0
|
1344 * @param array $install_state
|
Chris@0
|
1345 * An array of information about the current installation state.
|
Chris@0
|
1346 *
|
Chris@0
|
1347 * @return string
|
Chris@0
|
1348 * A themed status report, or an exception if there are requirement errors.
|
Chris@0
|
1349 * Upon successful download the page is reloaded and no output is returned.
|
Chris@0
|
1350 */
|
Chris@0
|
1351 function install_download_translation(&$install_state) {
|
Chris@0
|
1352 // Check whether all conditions are met to download. Download the translation
|
Chris@0
|
1353 // if possible.
|
Chris@0
|
1354 $requirements = install_check_translations($install_state['parameters']['langcode'], $install_state['server_pattern']);
|
Chris@0
|
1355 if ($output = install_display_requirements($install_state, $requirements)) {
|
Chris@0
|
1356 return $output;
|
Chris@0
|
1357 }
|
Chris@0
|
1358
|
Chris@0
|
1359 // The download was successful, reload the page in the new language.
|
Chris@0
|
1360 $install_state['translations'][$install_state['parameters']['langcode']] = TRUE;
|
Chris@0
|
1361 if ($install_state['interactive']) {
|
Chris@0
|
1362 install_goto(install_redirect_url($install_state));
|
Chris@0
|
1363 }
|
Chris@0
|
1364 }
|
Chris@0
|
1365
|
Chris@0
|
1366 /**
|
Chris@0
|
1367 * Attempts to get a file using a HTTP request and to store it locally.
|
Chris@0
|
1368 *
|
Chris@0
|
1369 * @param string $uri
|
Chris@0
|
1370 * The URI of the file to grab.
|
Chris@0
|
1371 * @param string $destination
|
Chris@0
|
1372 * Stream wrapper URI specifying where the file should be placed. If a
|
Chris@0
|
1373 * directory path is provided, the file is saved into that directory under its
|
Chris@0
|
1374 * original name. If the path contains a filename as well, that one will be
|
Chris@0
|
1375 * used instead.
|
Chris@0
|
1376 *
|
Chris@0
|
1377 * @return bool
|
Chris@0
|
1378 * TRUE on success, FALSE on failure.
|
Chris@0
|
1379 */
|
Chris@0
|
1380 function install_retrieve_file($uri, $destination) {
|
Chris@0
|
1381 $parsed_url = parse_url($uri);
|
Chris@0
|
1382 if (is_dir(drupal_realpath($destination))) {
|
Chris@0
|
1383 // Prevent URIs with triple slashes when gluing parts together.
|
Chris@0
|
1384 $path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']);
|
Chris@0
|
1385 }
|
Chris@0
|
1386 else {
|
Chris@0
|
1387 $path = $destination;
|
Chris@0
|
1388 }
|
Chris@0
|
1389
|
Chris@0
|
1390 try {
|
Chris@0
|
1391 $response = \Drupal::httpClient()->get($uri, ['headers' => ['Accept' => 'text/plain']]);
|
Chris@0
|
1392 $data = (string) $response->getBody();
|
Chris@0
|
1393 if (empty($data)) {
|
Chris@0
|
1394 return FALSE;
|
Chris@0
|
1395 }
|
Chris@0
|
1396 }
|
Chris@0
|
1397 catch (RequestException $e) {
|
Chris@0
|
1398 return FALSE;
|
Chris@0
|
1399 }
|
Chris@0
|
1400 return file_put_contents($path, $data) !== FALSE;
|
Chris@0
|
1401 }
|
Chris@0
|
1402
|
Chris@0
|
1403 /**
|
Chris@0
|
1404 * Checks if the localization server can be contacted.
|
Chris@0
|
1405 *
|
Chris@0
|
1406 * @param string $uri
|
Chris@0
|
1407 * The URI to contact.
|
Chris@0
|
1408 *
|
Chris@0
|
1409 * @return string
|
Chris@0
|
1410 * TRUE if the URI was contacted successfully, FALSE if not.
|
Chris@0
|
1411 */
|
Chris@0
|
1412 function install_check_localization_server($uri) {
|
Chris@0
|
1413 try {
|
Chris@0
|
1414 \Drupal::httpClient()->head($uri);
|
Chris@0
|
1415 return TRUE;
|
Chris@0
|
1416 }
|
Chris@0
|
1417 catch (RequestException $e) {
|
Chris@0
|
1418 return FALSE;
|
Chris@0
|
1419 }
|
Chris@0
|
1420 }
|
Chris@0
|
1421
|
Chris@0
|
1422 /**
|
Chris@0
|
1423 * Extracts version information from a drupal core version string.
|
Chris@0
|
1424 *
|
Chris@0
|
1425 * @param string $version
|
Chris@0
|
1426 * Version info string (e.g., 8.0.0, 8.1.0, 8.0.0-dev, 8.0.0-unstable1,
|
Chris@0
|
1427 * 8.0.0-alpha2, 8.0.0-beta3, and 8.0.0-rc4).
|
Chris@0
|
1428 *
|
Chris@0
|
1429 * @return array
|
Chris@0
|
1430 * Associative array of version info:
|
Chris@0
|
1431 * - major: Major version (e.g., "8").
|
Chris@0
|
1432 * - minor: Minor version (e.g., "0").
|
Chris@0
|
1433 * - patch: Patch version (e.g., "0").
|
Chris@0
|
1434 * - extra: Extra version info (e.g., "alpha2").
|
Chris@0
|
1435 * - extra_text: The text part of "extra" (e.g., "alpha").
|
Chris@0
|
1436 * - extra_number: The number part of "extra" (e.g., "2").
|
Chris@0
|
1437 */
|
Chris@0
|
1438 function _install_get_version_info($version) {
|
Chris@0
|
1439 preg_match('/
|
Chris@0
|
1440 (
|
Chris@0
|
1441 (?P<major>[0-9]+) # Major release number.
|
Chris@0
|
1442 \. # .
|
Chris@0
|
1443 (?P<minor>[0-9]+) # Minor release number.
|
Chris@0
|
1444 \. # .
|
Chris@0
|
1445 (?P<patch>[0-9]+) # Patch release number.
|
Chris@0
|
1446 ) #
|
Chris@0
|
1447 ( #
|
Chris@0
|
1448 - # - separator for "extra" version information.
|
Chris@0
|
1449 (?P<extra> #
|
Chris@0
|
1450 (?P<extra_text>[a-z]+) # Release extra text (e.g., "alpha").
|
Chris@0
|
1451 (?P<extra_number>[0-9]*) # Release extra number (no separator between text and number).
|
Chris@0
|
1452 ) #
|
Chris@0
|
1453 | # OR no "extra" information.
|
Chris@0
|
1454 )
|
Chris@0
|
1455 /sx', $version, $matches);
|
Chris@0
|
1456
|
Chris@0
|
1457 return $matches;
|
Chris@0
|
1458 }
|
Chris@0
|
1459
|
Chris@0
|
1460 /**
|
Chris@0
|
1461 * Loads information about the chosen profile during installation.
|
Chris@0
|
1462 *
|
Chris@0
|
1463 * @param $install_state
|
Chris@0
|
1464 * An array of information about the current installation state. The loaded
|
Chris@0
|
1465 * profile information will be added here.
|
Chris@0
|
1466 */
|
Chris@0
|
1467 function install_load_profile(&$install_state) {
|
Chris@0
|
1468 $profile = $install_state['parameters']['profile'];
|
Chris@0
|
1469 $install_state['profiles'][$profile]->load();
|
Chris@0
|
1470 $install_state['profile_info'] = install_profile_info($profile, isset($install_state['parameters']['langcode']) ? $install_state['parameters']['langcode'] : 'en');
|
Chris@0
|
1471 }
|
Chris@0
|
1472
|
Chris@0
|
1473 /**
|
Chris@0
|
1474 * Performs a full bootstrap of Drupal during installation.
|
Chris@0
|
1475 */
|
Chris@0
|
1476 function install_bootstrap_full() {
|
Chris@0
|
1477 // Store the session on the request object and start it.
|
Chris@0
|
1478 /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
|
Chris@0
|
1479 $session = \Drupal::service('session');
|
Chris@0
|
1480 \Drupal::request()->setSession($session);
|
Chris@0
|
1481 $session->start();
|
Chris@0
|
1482 }
|
Chris@0
|
1483
|
Chris@0
|
1484 /**
|
Chris@0
|
1485 * Installs required modules via a batch process.
|
Chris@0
|
1486 *
|
Chris@0
|
1487 * @param $install_state
|
Chris@0
|
1488 * An array of information about the current installation state.
|
Chris@0
|
1489 *
|
Chris@0
|
1490 * @return
|
Chris@0
|
1491 * The batch definition.
|
Chris@0
|
1492 */
|
Chris@0
|
1493 function install_profile_modules(&$install_state) {
|
Chris@0
|
1494 // We need to manually trigger the installation of core-provided entity types,
|
Chris@0
|
1495 // as those will not be handled by the module installer.
|
Chris@0
|
1496 install_core_entity_type_definitions();
|
Chris@0
|
1497
|
Chris@0
|
1498 $modules = \Drupal::state()->get('install_profile_modules') ?: [];
|
Chris@0
|
1499 $files = system_rebuild_module_data();
|
Chris@0
|
1500 \Drupal::state()->delete('install_profile_modules');
|
Chris@0
|
1501
|
Chris@0
|
1502 // Always install required modules first. Respect the dependencies between
|
Chris@0
|
1503 // the modules.
|
Chris@0
|
1504 $required = [];
|
Chris@0
|
1505 $non_required = [];
|
Chris@0
|
1506
|
Chris@0
|
1507 // Add modules that other modules depend on.
|
Chris@0
|
1508 foreach ($modules as $module) {
|
Chris@0
|
1509 if ($files[$module]->requires) {
|
Chris@0
|
1510 $modules = array_merge($modules, array_keys($files[$module]->requires));
|
Chris@0
|
1511 }
|
Chris@0
|
1512 }
|
Chris@0
|
1513 $modules = array_unique($modules);
|
Chris@0
|
1514 foreach ($modules as $module) {
|
Chris@0
|
1515 if (!empty($files[$module]->info['required'])) {
|
Chris@0
|
1516 $required[$module] = $files[$module]->sort;
|
Chris@0
|
1517 }
|
Chris@0
|
1518 else {
|
Chris@0
|
1519 $non_required[$module] = $files[$module]->sort;
|
Chris@0
|
1520 }
|
Chris@0
|
1521 }
|
Chris@0
|
1522 arsort($required);
|
Chris@0
|
1523 arsort($non_required);
|
Chris@0
|
1524
|
Chris@0
|
1525 $operations = [];
|
Chris@0
|
1526 foreach ($required + $non_required as $module => $weight) {
|
Chris@0
|
1527 $operations[] = ['_install_module_batch', [$module, $files[$module]->info['name']]];
|
Chris@0
|
1528 }
|
Chris@0
|
1529 $batch = [
|
Chris@0
|
1530 'operations' => $operations,
|
Chris@0
|
1531 'title' => t('Installing @drupal', ['@drupal' => drupal_install_profile_distribution_name()]),
|
Chris@0
|
1532 'error_message' => t('The installation has encountered an error.'),
|
Chris@0
|
1533 ];
|
Chris@0
|
1534 return $batch;
|
Chris@0
|
1535 }
|
Chris@0
|
1536
|
Chris@0
|
1537 /**
|
Chris@0
|
1538 * Installs entity type definitions provided by core.
|
Chris@0
|
1539 */
|
Chris@0
|
1540 function install_core_entity_type_definitions() {
|
Chris@0
|
1541 $update_manager = \Drupal::entityDefinitionUpdateManager();
|
Chris@0
|
1542 foreach (\Drupal::entityManager()->getDefinitions() as $entity_type) {
|
Chris@0
|
1543 if ($entity_type->getProvider() == 'core') {
|
Chris@0
|
1544 $update_manager->installEntityType($entity_type);
|
Chris@0
|
1545 }
|
Chris@0
|
1546 }
|
Chris@0
|
1547 }
|
Chris@0
|
1548
|
Chris@0
|
1549 /**
|
Chris@0
|
1550 * Installs themes.
|
Chris@0
|
1551 *
|
Chris@0
|
1552 * This does not use a batch, since installing themes is faster than modules and
|
Chris@0
|
1553 * because an installation profile typically installs 1-3 themes only (default
|
Chris@0
|
1554 * theme, base theme, admin theme).
|
Chris@0
|
1555 *
|
Chris@0
|
1556 * @param $install_state
|
Chris@0
|
1557 * An array of information about the current installation state.
|
Chris@0
|
1558 */
|
Chris@0
|
1559 function install_profile_themes(&$install_state) {
|
Chris@0
|
1560 // Install the themes specified by the installation profile.
|
Chris@0
|
1561 $themes = $install_state['profile_info']['themes'];
|
Chris@0
|
1562 \Drupal::service('theme_handler')->install($themes);
|
Chris@0
|
1563
|
Chris@0
|
1564 // Ensure that the install profile's theme is used.
|
Chris@0
|
1565 // @see _drupal_maintenance_theme()
|
Chris@0
|
1566 \Drupal::theme()->resetActiveTheme();
|
Chris@0
|
1567 }
|
Chris@0
|
1568
|
Chris@0
|
1569 /**
|
Chris@0
|
1570 * Installs the install profile.
|
Chris@0
|
1571 *
|
Chris@0
|
1572 * @param $install_state
|
Chris@0
|
1573 * An array of information about the current installation state.
|
Chris@0
|
1574 */
|
Chris@0
|
1575 function install_install_profile(&$install_state) {
|
Chris@0
|
1576 \Drupal::service('module_installer')->install([drupal_get_profile()], FALSE);
|
Chris@0
|
1577 // Install all available optional config. During installation the module order
|
Chris@0
|
1578 // is determined by dependencies. If there are no dependencies between modules
|
Chris@0
|
1579 // then the order in which they are installed is dependent on random factors
|
Chris@0
|
1580 // like PHP version. Optional configuration therefore might or might not be
|
Chris@0
|
1581 // created depending on this order. Ensuring that we have installed all of the
|
Chris@0
|
1582 // optional configuration whose dependencies can be met at this point removes
|
Chris@0
|
1583 // any disparities that this creates.
|
Chris@0
|
1584 \Drupal::service('config.installer')->installOptionalConfig();
|
Chris@0
|
1585
|
Chris@0
|
1586 // Ensure that the install profile's theme is used.
|
Chris@0
|
1587 // @see _drupal_maintenance_theme()
|
Chris@0
|
1588 \Drupal::theme()->resetActiveTheme();
|
Chris@0
|
1589 }
|
Chris@0
|
1590
|
Chris@0
|
1591 /**
|
Chris@0
|
1592 * Prepares the system for import and downloads additional translations.
|
Chris@0
|
1593 *
|
Chris@0
|
1594 * @param $install_state
|
Chris@0
|
1595 * An array of information about the current installation state.
|
Chris@0
|
1596 *
|
Chris@0
|
1597 * @return
|
Chris@0
|
1598 * The batch definition, if there are language files to download.
|
Chris@0
|
1599 */
|
Chris@0
|
1600 function install_download_additional_translations_operations(&$install_state) {
|
Chris@0
|
1601 \Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
|
Chris@0
|
1602
|
Chris@0
|
1603 $langcode = $install_state['parameters']['langcode'];
|
Chris@0
|
1604 if (!($language = ConfigurableLanguage::load($langcode))) {
|
Chris@0
|
1605 // Create the language if not already shipped with a profile.
|
Chris@0
|
1606 $language = ConfigurableLanguage::createFromLangcode($langcode);
|
Chris@0
|
1607 }
|
Chris@0
|
1608 $language->save();
|
Chris@0
|
1609
|
Chris@0
|
1610 // If a non-English language was selected, change the default language and
|
Chris@0
|
1611 // remove English.
|
Chris@0
|
1612 if ($langcode != 'en') {
|
Chris@0
|
1613 \Drupal::configFactory()->getEditable('system.site')
|
Chris@0
|
1614 ->set('langcode', $langcode)
|
Chris@0
|
1615 ->set('default_langcode', $langcode)
|
Chris@0
|
1616 ->save();
|
Chris@0
|
1617 \Drupal::service('language.default')->set($language);
|
Chris@0
|
1618 if (empty($install_state['profile_info']['keep_english'])) {
|
Chris@0
|
1619 entity_delete_multiple('configurable_language', ['en']);
|
Chris@0
|
1620 }
|
Chris@0
|
1621 }
|
Chris@0
|
1622
|
Chris@0
|
1623 // If there is more than one language or the single one is not English, we
|
Chris@0
|
1624 // should download/import translations.
|
Chris@0
|
1625 $languages = \Drupal::languageManager()->getLanguages();
|
Chris@0
|
1626 $operations = [];
|
Chris@0
|
1627 foreach ($languages as $langcode => $language) {
|
Chris@0
|
1628 // The installer language was already downloaded. Check downloads for the
|
Chris@0
|
1629 // other languages if any. Ignore any download errors here, since we
|
Chris@0
|
1630 // are in the middle of an install process and there is no way back. We
|
Chris@0
|
1631 // will not import what we cannot download.
|
Chris@0
|
1632 if ($langcode != 'en' && $langcode != $install_state['parameters']['langcode']) {
|
Chris@0
|
1633 $operations[] = ['install_check_translations', [$langcode, $install_state['server_pattern']]];
|
Chris@0
|
1634 }
|
Chris@0
|
1635 }
|
Chris@0
|
1636 return $operations;
|
Chris@0
|
1637 }
|
Chris@0
|
1638
|
Chris@0
|
1639 /**
|
Chris@0
|
1640 * Imports languages via a batch process during installation.
|
Chris@0
|
1641 *
|
Chris@0
|
1642 * @param $install_state
|
Chris@0
|
1643 * An array of information about the current installation state.
|
Chris@0
|
1644 *
|
Chris@0
|
1645 * @return
|
Chris@0
|
1646 * The batch definition, if there are language files to import.
|
Chris@0
|
1647 */
|
Chris@0
|
1648 function install_import_translations(&$install_state) {
|
Chris@0
|
1649 \Drupal::moduleHandler()->loadInclude('locale', 'translation.inc');
|
Chris@0
|
1650
|
Chris@0
|
1651 // If there is more than one language or the single one is not English, we
|
Chris@0
|
1652 // should import translations.
|
Chris@0
|
1653 $operations = install_download_additional_translations_operations($install_state);
|
Chris@0
|
1654 $languages = \Drupal::languageManager()->getLanguages();
|
Chris@0
|
1655 if (count($languages) > 1 || !isset($languages['en'])) {
|
Chris@0
|
1656 $operations[] = ['_install_prepare_import', [array_keys($languages), $install_state['server_pattern']]];
|
Chris@0
|
1657
|
Chris@0
|
1658 // Set up a batch to import translations for drupal core. Translation import
|
Chris@0
|
1659 // for contrib modules happens in install_import_translations_remaining.
|
Chris@0
|
1660 foreach ($languages as $language) {
|
Chris@0
|
1661 if (locale_translation_use_remote_source()) {
|
Chris@0
|
1662 $operations[] = ['locale_translation_batch_fetch_download', ['drupal', $language->getId()]];
|
Chris@0
|
1663 }
|
Chris@0
|
1664 $operations[] = ['locale_translation_batch_fetch_import', ['drupal', $language->getId(), []]];
|
Chris@0
|
1665 }
|
Chris@0
|
1666
|
Chris@0
|
1667 module_load_include('fetch.inc', 'locale');
|
Chris@0
|
1668 $batch = [
|
Chris@0
|
1669 'operations' => $operations,
|
Chris@0
|
1670 'title' => t('Updating translations.'),
|
Chris@0
|
1671 'progress_message' => '',
|
Chris@0
|
1672 'error_message' => t('Error importing translation files'),
|
Chris@0
|
1673 'finished' => 'locale_translation_batch_fetch_finished',
|
Chris@0
|
1674 'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
|
Chris@0
|
1675 ];
|
Chris@0
|
1676 return $batch;
|
Chris@0
|
1677 }
|
Chris@0
|
1678 }
|
Chris@0
|
1679
|
Chris@0
|
1680 /**
|
Chris@0
|
1681 * Tells the translation import process that Drupal core is installed.
|
Chris@0
|
1682 *
|
Chris@0
|
1683 * @param array $langcodes
|
Chris@0
|
1684 * Language codes used for the translations.
|
Chris@0
|
1685 * @param string $server_pattern
|
Chris@0
|
1686 * Server access pattern (to replace language code, version number, etc. in).
|
Chris@0
|
1687 */
|
Chris@0
|
1688 function _install_prepare_import($langcodes, $server_pattern) {
|
Chris@0
|
1689 \Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
|
Chris@0
|
1690 $matches = [];
|
Chris@0
|
1691
|
Chris@0
|
1692 foreach ($langcodes as $langcode) {
|
Chris@0
|
1693 // Get the translation files located in the translations directory.
|
Chris@0
|
1694 $files = locale_translate_get_interface_translation_files(['drupal'], [$langcode]);
|
Chris@0
|
1695 // Pick the first file which matches the language, if any.
|
Chris@0
|
1696 $file = reset($files);
|
Chris@0
|
1697 if (is_object($file)) {
|
Chris@0
|
1698 $filename = $file->filename;
|
Chris@0
|
1699 preg_match('/drupal-([0-9a-z\.-]+)\.' . $langcode . '\.po/', $filename, $matches);
|
Chris@0
|
1700 // Get the version information.
|
Chris@0
|
1701 if ($version = $matches[1]) {
|
Chris@0
|
1702 $info = _install_get_version_info($version);
|
Chris@0
|
1703 // Picking the first file does not necessarily result in the right file. So
|
Chris@0
|
1704 // we check if at least the major version number is available.
|
Chris@0
|
1705 if ($info['major']) {
|
Chris@0
|
1706 $core = $info['major'] . '.x';
|
Chris@0
|
1707 $data = [
|
Chris@0
|
1708 'name' => 'drupal',
|
Chris@0
|
1709 'project_type' => 'module',
|
Chris@0
|
1710 'core' => $core,
|
Chris@0
|
1711 'version' => $version,
|
Chris@0
|
1712 'server_pattern' => $server_pattern,
|
Chris@0
|
1713 'status' => 1,
|
Chris@0
|
1714 ];
|
Chris@0
|
1715 \Drupal::service('locale.project')->set($data['name'], $data);
|
Chris@0
|
1716 module_load_include('compare.inc', 'locale');
|
Chris@0
|
1717 locale_translation_check_projects_local(['drupal'], [$langcode]);
|
Chris@0
|
1718 }
|
Chris@0
|
1719 }
|
Chris@0
|
1720 }
|
Chris@0
|
1721 }
|
Chris@0
|
1722 }
|
Chris@0
|
1723
|
Chris@0
|
1724 /**
|
Chris@0
|
1725 * Finishes importing files at end of installation.
|
Chris@0
|
1726 *
|
Chris@0
|
1727 * If other projects besides Drupal core have been installed, their translation
|
Chris@0
|
1728 * will be imported here.
|
Chris@0
|
1729 *
|
Chris@0
|
1730 * @param $install_state
|
Chris@0
|
1731 * An array of information about the current installation state.
|
Chris@0
|
1732 *
|
Chris@0
|
1733 * @return array
|
Chris@0
|
1734 * An array of batch definitions.
|
Chris@0
|
1735 */
|
Chris@0
|
1736 function install_finish_translations(&$install_state) {
|
Chris@0
|
1737 \Drupal::moduleHandler()->loadInclude('locale', 'fetch.inc');
|
Chris@0
|
1738 \Drupal::moduleHandler()->loadInclude('locale', 'compare.inc');
|
Chris@0
|
1739 \Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
|
Chris@0
|
1740
|
Chris@0
|
1741 // Build a fresh list of installed projects. When more projects than core are
|
Chris@0
|
1742 // installed, their translations will be downloaded (if required) and imported
|
Chris@0
|
1743 // using a batch.
|
Chris@0
|
1744 $projects = locale_translation_build_projects();
|
Chris@0
|
1745 $languages = \Drupal::languageManager()->getLanguages();
|
Chris@0
|
1746 $batches = [];
|
Chris@0
|
1747 if (count($projects) > 1) {
|
Chris@0
|
1748 $options = _locale_translation_default_update_options();
|
Chris@0
|
1749 if ($batch = locale_translation_batch_update_build([], array_keys($languages), $options)) {
|
Chris@0
|
1750 $batches[] = $batch;
|
Chris@0
|
1751 }
|
Chris@0
|
1752 }
|
Chris@0
|
1753
|
Chris@0
|
1754 // Creates configuration translations.
|
Chris@0
|
1755 $batches[] = locale_config_batch_update_components([], array_keys($languages));
|
Chris@0
|
1756 return $batches;
|
Chris@0
|
1757 }
|
Chris@0
|
1758
|
Chris@0
|
1759 /**
|
Chris@0
|
1760 * Performs final installation steps and displays a 'finished' page.
|
Chris@0
|
1761 *
|
Chris@0
|
1762 * @param $install_state
|
Chris@0
|
1763 * An array of information about the current installation state.
|
Chris@0
|
1764 *
|
Chris@0
|
1765 * @return
|
Chris@0
|
1766 * A message informing the user that the installation is complete.
|
Chris@0
|
1767 */
|
Chris@0
|
1768 function install_finished(&$install_state) {
|
Chris@0
|
1769 $profile = drupal_get_profile();
|
Chris@0
|
1770
|
Chris@0
|
1771 // Installation profiles are always loaded last.
|
Chris@0
|
1772 module_set_weight($profile, 1000);
|
Chris@0
|
1773
|
Chris@0
|
1774 // Build the router once after installing all modules.
|
Chris@0
|
1775 // This would normally happen upon KernelEvents::TERMINATE, but since the
|
Chris@0
|
1776 // installer does not use an HttpKernel, that event is never triggered.
|
Chris@0
|
1777 \Drupal::service('router.builder')->rebuild();
|
Chris@0
|
1778
|
Chris@0
|
1779 // Run cron to populate update status tables (if available) so that users
|
Chris@0
|
1780 // will be warned if they've installed an out of date Drupal version.
|
Chris@0
|
1781 // Will also trigger indexing of profile-supplied content or feeds.
|
Chris@0
|
1782 \Drupal::service('cron')->run();
|
Chris@0
|
1783
|
Chris@0
|
1784 if ($install_state['interactive']) {
|
Chris@0
|
1785 // Load current user and perform final login tasks.
|
Chris@0
|
1786 // This has to be done after drupal_flush_all_caches()
|
Chris@0
|
1787 // to avoid session regeneration.
|
Chris@0
|
1788 $account = User::load(1);
|
Chris@0
|
1789 user_login_finalize($account);
|
Chris@0
|
1790 }
|
Chris@0
|
1791
|
Chris@0
|
1792 $success_message = t('Congratulations, you installed @drupal!', [
|
Chris@0
|
1793 '@drupal' => drupal_install_profile_distribution_name(),
|
Chris@0
|
1794 ]);
|
Chris@0
|
1795 drupal_set_message($success_message);
|
Chris@0
|
1796 }
|
Chris@0
|
1797
|
Chris@0
|
1798 /**
|
Chris@0
|
1799 * Implements callback_batch_operation().
|
Chris@0
|
1800 *
|
Chris@0
|
1801 * Performs batch installation of modules.
|
Chris@0
|
1802 */
|
Chris@0
|
1803 function _install_module_batch($module, $module_name, &$context) {
|
Chris@0
|
1804 \Drupal::service('module_installer')->install([$module], FALSE);
|
Chris@0
|
1805 $context['results'][] = $module;
|
Chris@0
|
1806 $context['message'] = t('Installed %module module.', ['%module' => $module_name]);
|
Chris@0
|
1807 }
|
Chris@0
|
1808
|
Chris@0
|
1809 /**
|
Chris@0
|
1810 * Checks installation requirements and reports any errors.
|
Chris@0
|
1811 *
|
Chris@0
|
1812 * @param string $langcode
|
Chris@0
|
1813 * Language code to check for download.
|
Chris@0
|
1814 * @param string $server_pattern
|
Chris@0
|
1815 * Server access pattern (to replace language code, version number, etc. in).
|
Chris@0
|
1816 *
|
Chris@0
|
1817 * @return array|null
|
Chris@0
|
1818 * Requirements compliance array. If the translation was downloaded
|
Chris@0
|
1819 * successfully then an empty array is returned. Otherwise the requirements
|
Chris@0
|
1820 * error with detailed information. NULL if the file already exists for this
|
Chris@0
|
1821 * language code.
|
Chris@0
|
1822 */
|
Chris@0
|
1823 function install_check_translations($langcode, $server_pattern) {
|
Chris@0
|
1824 $requirements = [];
|
Chris@0
|
1825
|
Chris@0
|
1826 $readable = FALSE;
|
Chris@0
|
1827 $writable = FALSE;
|
Chris@0
|
1828 // @todo: Make this configurable.
|
Chris@0
|
1829 $site_path = \Drupal::service('site.path');
|
Chris@0
|
1830 $files_directory = $site_path . '/files';
|
Chris@0
|
1831 $translations_directory = $site_path . '/files/translations';
|
Chris@0
|
1832 $translations_directory_exists = FALSE;
|
Chris@0
|
1833 $online = FALSE;
|
Chris@0
|
1834
|
Chris@0
|
1835 // First attempt to create or make writable the files directory.
|
Chris@0
|
1836 file_prepare_directory($files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
Chris@0
|
1837 // Then, attempt to create or make writable the translations directory.
|
Chris@0
|
1838 file_prepare_directory($translations_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
Chris@0
|
1839
|
Chris@0
|
1840 // Get values so the requirements errors can be specific.
|
Chris@0
|
1841 if (drupal_verify_install_file($translations_directory, FILE_EXIST, 'dir')) {
|
Chris@0
|
1842 $readable = is_readable($translations_directory);
|
Chris@0
|
1843 $writable = is_writable($translations_directory);
|
Chris@0
|
1844 $translations_directory_exists = TRUE;
|
Chris@0
|
1845 }
|
Chris@0
|
1846
|
Chris@0
|
1847 // The file already exists, no need to attempt to download.
|
Chris@0
|
1848 if ($existing_file = glob($translations_directory . '/drupal-*.' . $langcode . '.po')) {
|
Chris@0
|
1849 return;
|
Chris@0
|
1850 }
|
Chris@0
|
1851
|
Chris@0
|
1852 // Build URL for the translation file and the translation server.
|
Chris@0
|
1853 $variables = [
|
Chris@0
|
1854 '%project' => 'drupal',
|
Chris@0
|
1855 '%version' => \Drupal::VERSION,
|
Chris@0
|
1856 '%core' => \Drupal::CORE_COMPATIBILITY,
|
Chris@0
|
1857 '%language' => $langcode,
|
Chris@0
|
1858 ];
|
Chris@0
|
1859 $translation_url = strtr($server_pattern, $variables);
|
Chris@0
|
1860
|
Chris@0
|
1861 $elements = parse_url($translation_url);
|
Chris@0
|
1862 $server_url = $elements['scheme'] . '://' . $elements['host'];
|
Chris@0
|
1863
|
Chris@0
|
1864 // Build the language name for display.
|
Chris@0
|
1865 $languages = LanguageManager::getStandardLanguageList();
|
Chris@0
|
1866 $language = isset($languages[$langcode]) ? $languages[$langcode][0] : $langcode;
|
Chris@0
|
1867
|
Chris@0
|
1868 // Check if any of the desired translation files are available or if the
|
Chris@0
|
1869 // translation server can be reached. In other words, check if we are online
|
Chris@0
|
1870 // and have an internet connection.
|
Chris@0
|
1871 if ($translation_available = install_check_localization_server($translation_url)) {
|
Chris@0
|
1872 $online = TRUE;
|
Chris@0
|
1873 }
|
Chris@0
|
1874 if (!$translation_available) {
|
Chris@0
|
1875 if (install_check_localization_server($server_url)) {
|
Chris@0
|
1876 $online = TRUE;
|
Chris@0
|
1877 }
|
Chris@0
|
1878 }
|
Chris@0
|
1879
|
Chris@0
|
1880 // If the translations directory does not exists, throw an error.
|
Chris@0
|
1881 if (!$translations_directory_exists) {
|
Chris@0
|
1882 $requirements['translations directory exists'] = [
|
Chris@0
|
1883 'title' => t('Translations directory'),
|
Chris@0
|
1884 'value' => t('The translations directory does not exist.'),
|
Chris@0
|
1885 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
1886 '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>.', ['%translations_directory' => $translations_directory, ':install_txt' => base_path() . 'core/INSTALL.txt']),
|
Chris@0
|
1887 ];
|
Chris@0
|
1888 }
|
Chris@0
|
1889 else {
|
Chris@0
|
1890 $requirements['translations directory exists'] = [
|
Chris@0
|
1891 'title' => t('Translations directory'),
|
Chris@0
|
1892 'value' => t('The directory %translations_directory exists.', ['%translations_directory' => $translations_directory]),
|
Chris@0
|
1893 ];
|
Chris@0
|
1894 // If the translations directory is not readable, throw an error.
|
Chris@0
|
1895 if (!$readable) {
|
Chris@0
|
1896 $requirements['translations directory readable'] = [
|
Chris@0
|
1897 'title' => t('Translations directory'),
|
Chris@0
|
1898 'value' => t('The translations directory is not readable.'),
|
Chris@0
|
1899 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
1900 'description' => t('The installer requires read permissions to %translations_directory at all times. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', ['%translations_directory' => $translations_directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']),
|
Chris@0
|
1901 ];
|
Chris@0
|
1902 }
|
Chris@0
|
1903 // If translations directory is not writable, throw an error.
|
Chris@0
|
1904 if (!$writable) {
|
Chris@0
|
1905 $requirements['translations directory writable'] = [
|
Chris@0
|
1906 'title' => t('Translations directory'),
|
Chris@0
|
1907 'value' => t('The translations directory is not writable.'),
|
Chris@0
|
1908 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
1909 'description' => t('The installer requires write permissions to %translations_directory during the installation process. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', ['%translations_directory' => $translations_directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']),
|
Chris@0
|
1910 ];
|
Chris@0
|
1911 }
|
Chris@0
|
1912 else {
|
Chris@0
|
1913 $requirements['translations directory writable'] = [
|
Chris@0
|
1914 'title' => t('Translations directory'),
|
Chris@0
|
1915 'value' => t('The translations directory is writable.'),
|
Chris@0
|
1916 ];
|
Chris@0
|
1917 }
|
Chris@0
|
1918 }
|
Chris@0
|
1919
|
Chris@0
|
1920 // If the translations server can not be contacted, throw an error.
|
Chris@0
|
1921 if (!$online) {
|
Chris@0
|
1922 $requirements['online'] = [
|
Chris@0
|
1923 'title' => t('Internet'),
|
Chris@0
|
1924 'value' => t('The translation server is offline.'),
|
Chris@0
|
1925 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
1926 '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>.', [':server_url' => $server_url, '@server_url' => $server_url]),
|
Chris@0
|
1927 ];
|
Chris@0
|
1928 }
|
Chris@0
|
1929 else {
|
Chris@0
|
1930 $requirements['online'] = [
|
Chris@0
|
1931 'title' => t('Internet'),
|
Chris@0
|
1932 'value' => t('The translation server is online.'),
|
Chris@0
|
1933 ];
|
Chris@0
|
1934 // If translation file is not found at the translation server, throw an
|
Chris@0
|
1935 // error.
|
Chris@0
|
1936 if (!$translation_available) {
|
Chris@0
|
1937 $requirements['translation available'] = [
|
Chris@0
|
1938 'title' => t('Translation'),
|
Chris@0
|
1939 'value' => t('The %language translation is not available.', ['%language' => $language]),
|
Chris@0
|
1940 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
1941 '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.', ['%language' => $language, ':url' => $_SERVER['SCRIPT_NAME']]),
|
Chris@0
|
1942 ];
|
Chris@0
|
1943 }
|
Chris@0
|
1944 else {
|
Chris@0
|
1945 $requirements['translation available'] = [
|
Chris@0
|
1946 'title' => t('Translation'),
|
Chris@0
|
1947 'value' => t('The %language translation is available.', ['%language' => $language]),
|
Chris@0
|
1948 ];
|
Chris@0
|
1949 }
|
Chris@0
|
1950 }
|
Chris@0
|
1951
|
Chris@0
|
1952 if ($translations_directory_exists && $readable && $writable && $translation_available) {
|
Chris@0
|
1953 $translation_downloaded = install_retrieve_file($translation_url, $translations_directory);
|
Chris@0
|
1954
|
Chris@0
|
1955 if (!$translation_downloaded) {
|
Chris@0
|
1956 $requirements['translation downloaded'] = [
|
Chris@0
|
1957 'title' => t('Translation'),
|
Chris@0
|
1958 'value' => t('The %language translation could not be downloaded.', ['%language' => $language]),
|
Chris@0
|
1959 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
1960 '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.', ['%language' => $language, ':url' => $_SERVER['SCRIPT_NAME']]),
|
Chris@0
|
1961 ];
|
Chris@0
|
1962 }
|
Chris@0
|
1963 }
|
Chris@0
|
1964
|
Chris@0
|
1965 return $requirements;
|
Chris@0
|
1966 }
|
Chris@0
|
1967
|
Chris@0
|
1968 /**
|
Chris@0
|
1969 * Checks installation requirements and reports any errors.
|
Chris@0
|
1970 */
|
Chris@0
|
1971 function install_check_requirements($install_state) {
|
Chris@0
|
1972 $profile = $install_state['parameters']['profile'];
|
Chris@0
|
1973
|
Chris@0
|
1974 // Check the profile requirements.
|
Chris@0
|
1975 $requirements = drupal_check_profile($profile);
|
Chris@0
|
1976
|
Chris@0
|
1977 if ($install_state['settings_verified']) {
|
Chris@0
|
1978 return $requirements;
|
Chris@0
|
1979 }
|
Chris@0
|
1980
|
Chris@0
|
1981 // If Drupal is not set up already, we need to try to create the default
|
Chris@0
|
1982 // settings and services files.
|
Chris@0
|
1983 $default_files = [];
|
Chris@0
|
1984 $default_files['settings.php'] = [
|
Chris@0
|
1985 'file' => 'settings.php',
|
Chris@0
|
1986 'file_default' => 'default.settings.php',
|
Chris@0
|
1987 'title_default' => t('Default settings file'),
|
Chris@0
|
1988 'description_default' => t('The default settings file does not exist.'),
|
Chris@0
|
1989 'title' => t('Settings file'),
|
Chris@0
|
1990 ];
|
Chris@0
|
1991
|
Chris@0
|
1992 foreach ($default_files as $default_file_info) {
|
Chris@0
|
1993 $readable = FALSE;
|
Chris@0
|
1994 $writable = FALSE;
|
Chris@0
|
1995 $site_path = './' . \Drupal::service('site.path');
|
Chris@0
|
1996 $file = $site_path . "/{$default_file_info['file']}";
|
Chris@0
|
1997 $default_file = "./sites/default/{$default_file_info['file_default']}";
|
Chris@0
|
1998 $exists = FALSE;
|
Chris@0
|
1999 // Verify that the directory exists.
|
Chris@0
|
2000 if (drupal_verify_install_file($site_path, FILE_EXIST, 'dir')) {
|
Chris@0
|
2001 if (drupal_verify_install_file($file, FILE_EXIST)) {
|
Chris@0
|
2002 // If it does, make sure it is writable.
|
Chris@0
|
2003 $readable = drupal_verify_install_file($file, FILE_READABLE);
|
Chris@0
|
2004 $writable = drupal_verify_install_file($file, FILE_WRITABLE);
|
Chris@0
|
2005 $exists = TRUE;
|
Chris@0
|
2006 }
|
Chris@0
|
2007 }
|
Chris@0
|
2008
|
Chris@0
|
2009 // If the default $default_file does not exist, or is not readable,
|
Chris@0
|
2010 // report an error.
|
Chris@0
|
2011 if (!drupal_verify_install_file($default_file, FILE_EXIST | FILE_READABLE)) {
|
Chris@0
|
2012 $requirements["default $file file exists"] = [
|
Chris@0
|
2013 'title' => $default_file_info['title_default'],
|
Chris@0
|
2014 'value' => $default_file_info['description_default'],
|
Chris@0
|
2015 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
2016 'description' => t('The @drupal installer requires that the %default-file file not be modified in any way from the original download.', [
|
Chris@0
|
2017 '@drupal' => drupal_install_profile_distribution_name(),
|
Chris@0
|
2018 '%default-file' => $default_file
|
Chris@0
|
2019 ]),
|
Chris@0
|
2020 ];
|
Chris@0
|
2021 }
|
Chris@0
|
2022 // Otherwise, if $file does not exist yet, we can try to copy
|
Chris@0
|
2023 // $default_file to create it.
|
Chris@0
|
2024 elseif (!$exists) {
|
Chris@0
|
2025 $copied = drupal_verify_install_file($site_path, FILE_EXIST | FILE_WRITABLE, 'dir') && @copy($default_file, $file);
|
Chris@0
|
2026 if ($copied) {
|
Chris@0
|
2027 // If the new $file file has the same owner as $default_file this means
|
Chris@0
|
2028 // $default_file is owned by the webserver user. This is an inherent
|
Chris@0
|
2029 // security weakness because it allows a malicious webserver process to
|
Chris@0
|
2030 // append arbitrary PHP code and then execute it. However, it is also a
|
Chris@0
|
2031 // common configuration on shared hosting, and there is nothing Drupal
|
Chris@0
|
2032 // can do to prevent it. In this situation, having $file also owned by
|
Chris@0
|
2033 // the webserver does not introduce any additional security risk, so we
|
Chris@0
|
2034 // keep the file in place. Additionally, this situation also occurs when
|
Chris@0
|
2035 // the test runner is being run be different user than the webserver.
|
Chris@0
|
2036 if (fileowner($default_file) === fileowner($file) || DRUPAL_TEST_IN_CHILD_SITE) {
|
Chris@0
|
2037 $readable = drupal_verify_install_file($file, FILE_READABLE);
|
Chris@0
|
2038 $writable = drupal_verify_install_file($file, FILE_WRITABLE);
|
Chris@0
|
2039 $exists = TRUE;
|
Chris@0
|
2040 }
|
Chris@0
|
2041 // If $file and $default_file have different owners, this probably means
|
Chris@0
|
2042 // the server is set up "securely" (with the webserver running as its
|
Chris@0
|
2043 // own user, distinct from the user who owns all the Drupal PHP files),
|
Chris@0
|
2044 // although with either a group or world writable sites directory.
|
Chris@0
|
2045 // Keeping $file owned by the webserver would therefore introduce a
|
Chris@0
|
2046 // security risk. It would also cause a usability problem, since site
|
Chris@0
|
2047 // owners who do not have root access to the file system would be unable
|
Chris@0
|
2048 // to edit their settings file later on. We therefore must delete the
|
Chris@0
|
2049 // file we just created and force the administrator to log on to the
|
Chris@0
|
2050 // server and create it manually.
|
Chris@0
|
2051 else {
|
Chris@0
|
2052 $deleted = @drupal_unlink($file);
|
Chris@0
|
2053 // We expect deleting the file to be successful (since we just
|
Chris@0
|
2054 // created it ourselves above), but if it fails somehow, we set a
|
Chris@0
|
2055 // variable so we can display a one-time error message to the
|
Chris@0
|
2056 // administrator at the bottom of the requirements list. We also try
|
Chris@0
|
2057 // to make the file writable, to eliminate any conflicting error
|
Chris@0
|
2058 // messages in the requirements list.
|
Chris@0
|
2059 $exists = !$deleted;
|
Chris@0
|
2060 if ($exists) {
|
Chris@0
|
2061 $settings_file_ownership_error = TRUE;
|
Chris@0
|
2062 $readable = drupal_verify_install_file($file, FILE_READABLE);
|
Chris@0
|
2063 $writable = drupal_verify_install_file($file, FILE_WRITABLE);
|
Chris@0
|
2064 }
|
Chris@0
|
2065 }
|
Chris@0
|
2066 }
|
Chris@0
|
2067 }
|
Chris@0
|
2068
|
Chris@0
|
2069 // If the $file does not exist, throw an error.
|
Chris@0
|
2070 if (!$exists) {
|
Chris@0
|
2071 $requirements["$file file exists"] = [
|
Chris@0
|
2072 'title' => $default_file_info['title'],
|
Chris@0
|
2073 'value' => t('The %file does not exist.', ['%file' => $default_file_info['title']]),
|
Chris@0
|
2074 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
2075 'description' => t('The @drupal installer requires that you create a %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>.', [
|
Chris@0
|
2076 '@drupal' => drupal_install_profile_distribution_name(),
|
Chris@0
|
2077 '%file' => $file,
|
Chris@0
|
2078 '%default_file' => $default_file,
|
Chris@0
|
2079 ':install_txt' => base_path() . 'core/INSTALL.txt'
|
Chris@0
|
2080 ]),
|
Chris@0
|
2081 ];
|
Chris@0
|
2082 }
|
Chris@0
|
2083 else {
|
Chris@0
|
2084 $requirements["$file file exists"] = [
|
Chris@0
|
2085 'title' => $default_file_info['title'],
|
Chris@0
|
2086 'value' => t('The %file exists.', ['%file' => $file]),
|
Chris@0
|
2087 ];
|
Chris@0
|
2088 // If the $file is not readable, throw an error.
|
Chris@0
|
2089 if (!$readable) {
|
Chris@0
|
2090 $requirements["$file file readable"] = [
|
Chris@0
|
2091 'title' => $default_file_info['title'],
|
Chris@0
|
2092 'value' => t('The %file is not readable.', ['%file' => $default_file_info['title']]),
|
Chris@0
|
2093 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
2094 'description' => t('@drupal requires read permissions to %file at all times. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', [
|
Chris@0
|
2095 '@drupal' => drupal_install_profile_distribution_name(),
|
Chris@0
|
2096 '%file' => $file,
|
Chris@0
|
2097 ':handbook_url' => 'https://www.drupal.org/server-permissions'
|
Chris@0
|
2098 ]),
|
Chris@0
|
2099 ];
|
Chris@0
|
2100 }
|
Chris@0
|
2101 // If the $file is not writable, throw an error.
|
Chris@0
|
2102 if (!$writable) {
|
Chris@0
|
2103 $requirements["$file file writeable"] = [
|
Chris@0
|
2104 'title' => $default_file_info['title'],
|
Chris@0
|
2105 'value' => t('The %file is not writable.', ['%file' => $default_file_info['title']]),
|
Chris@0
|
2106 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
2107 'description' => t('The @drupal installer requires write permissions to %file during the installation process. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', [
|
Chris@0
|
2108 '@drupal' => drupal_install_profile_distribution_name(),
|
Chris@0
|
2109 '%file' => $file,
|
Chris@0
|
2110 ':handbook_url' => 'https://www.drupal.org/server-permissions'
|
Chris@0
|
2111 ]),
|
Chris@0
|
2112 ];
|
Chris@0
|
2113 }
|
Chris@0
|
2114 else {
|
Chris@0
|
2115 $requirements["$file file"] = [
|
Chris@0
|
2116 'title' => $default_file_info['title'],
|
Chris@0
|
2117 'value' => t('The @file is writable.', ['@file' => $default_file_info['title']]),
|
Chris@0
|
2118 ];
|
Chris@0
|
2119 }
|
Chris@0
|
2120 if (!empty($settings_file_ownership_error)) {
|
Chris@0
|
2121 $requirements["$file file ownership"] = [
|
Chris@0
|
2122 'title' => $default_file_info['title'],
|
Chris@0
|
2123 'value' => t('The @file is owned by the web server.', ['@file' => $default_file_info['title']]),
|
Chris@0
|
2124 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
2125 'description' => t('The @drupal installer failed to create a %file 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>. The <a href=":handbook_url">webhosting issues</a> documentation section offers help on this and other topics.', [
|
Chris@0
|
2126 '@drupal' => drupal_install_profile_distribution_name(),
|
Chris@0
|
2127 '%file' => $file,
|
Chris@0
|
2128 '%default_file' => $default_file,
|
Chris@0
|
2129 ':install_txt' => base_path() . 'core/INSTALL.txt',
|
Chris@0
|
2130 ':handbook_url' => 'https://www.drupal.org/server-permissions'
|
Chris@0
|
2131 ]),
|
Chris@0
|
2132 ];
|
Chris@0
|
2133 }
|
Chris@0
|
2134 }
|
Chris@0
|
2135 }
|
Chris@0
|
2136 return $requirements;
|
Chris@0
|
2137 }
|
Chris@0
|
2138
|
Chris@0
|
2139 /**
|
Chris@0
|
2140 * Displays installation requirements.
|
Chris@0
|
2141 *
|
Chris@0
|
2142 * @param array $install_state
|
Chris@0
|
2143 * An array of information about the current installation state.
|
Chris@0
|
2144 * @param array $requirements
|
Chris@0
|
2145 * An array of requirements, in the same format as is returned by
|
Chris@0
|
2146 * hook_requirements().
|
Chris@0
|
2147 *
|
Chris@0
|
2148 * @return
|
Chris@0
|
2149 * A themed status report, or an exception if there are requirement errors.
|
Chris@0
|
2150 * If there are only requirement warnings, a themed status report is shown
|
Chris@0
|
2151 * initially, but the user is allowed to bypass it by providing 'continue=1'
|
Chris@0
|
2152 * in the URL. Otherwise, no output is returned, so that the next task can be
|
Chris@0
|
2153 * run in the same page request.
|
Chris@0
|
2154 *
|
Chris@0
|
2155 * @throws \Drupal\Core\Installer\Exception\InstallerException
|
Chris@0
|
2156 */
|
Chris@0
|
2157 function install_display_requirements($install_state, $requirements) {
|
Chris@0
|
2158 // Check the severity of the requirements reported.
|
Chris@0
|
2159 $severity = drupal_requirements_severity($requirements);
|
Chris@0
|
2160
|
Chris@0
|
2161 // If there are errors, always display them. If there are only warnings, skip
|
Chris@0
|
2162 // them if the user has provided a URL parameter acknowledging the warnings
|
Chris@0
|
2163 // and indicating a desire to continue anyway. See drupal_requirements_url().
|
Chris@0
|
2164 if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && empty($install_state['parameters']['continue']))) {
|
Chris@0
|
2165 if ($install_state['interactive']) {
|
Chris@0
|
2166 $build['report']['#type'] = 'status_report';
|
Chris@0
|
2167 $build['report']['#requirements'] = $requirements;
|
Chris@0
|
2168 if ($severity == REQUIREMENT_WARNING) {
|
Chris@0
|
2169 $build['#title'] = t('Requirements review');
|
Chris@0
|
2170 $build['#suffix'] = t('Check the messages and <a href=":retry">retry</a>, or you may choose to <a href=":cont">continue anyway</a>.', [':retry' => drupal_requirements_url(REQUIREMENT_ERROR), ':cont' => drupal_requirements_url($severity)]);
|
Chris@0
|
2171 }
|
Chris@0
|
2172 else {
|
Chris@0
|
2173 $build['#title'] = t('Requirements problem');
|
Chris@0
|
2174 $build['#suffix'] = t('Check the messages and <a href=":url">try again</a>.', [':url' => drupal_requirements_url($severity)]);
|
Chris@0
|
2175 }
|
Chris@0
|
2176 return $build;
|
Chris@0
|
2177 }
|
Chris@0
|
2178 else {
|
Chris@0
|
2179 // Throw an exception showing any unmet requirements.
|
Chris@0
|
2180 $failures = [];
|
Chris@0
|
2181 foreach ($requirements as $requirement) {
|
Chris@0
|
2182 // Skip warnings altogether for non-interactive installations; these
|
Chris@0
|
2183 // proceed in a single request so there is no good opportunity (and no
|
Chris@0
|
2184 // good method) to warn the user anyway.
|
Chris@0
|
2185 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
|
Chris@0
|
2186 $failures[] = $requirement['title'] . ': ' . $requirement['value'] . "\n\n" . $requirement['description'];
|
Chris@0
|
2187 }
|
Chris@0
|
2188 }
|
Chris@0
|
2189 if (!empty($failures)) {
|
Chris@0
|
2190 throw new InstallerException(implode("\n\n", $failures));
|
Chris@0
|
2191 }
|
Chris@0
|
2192 }
|
Chris@0
|
2193 }
|
Chris@0
|
2194 }
|
Chris@0
|
2195
|
Chris@0
|
2196 /**
|
Chris@0
|
2197 * Installation task; writes profile to settings.php if possible.
|
Chris@0
|
2198 *
|
Chris@0
|
2199 * @param array $install_state
|
Chris@0
|
2200 * An array of information about the current installation state.
|
Chris@0
|
2201 *
|
Chris@0
|
2202 * @see _install_select_profile()
|
Chris@0
|
2203 *
|
Chris@0
|
2204 * @throws \Drupal\Core\Installer\Exception\InstallProfileMismatchException
|
Chris@0
|
2205 *
|
Chris@0
|
2206 * @deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0. The
|
Chris@0
|
2207 * install profile is written to core.extension.
|
Chris@0
|
2208 */
|
Chris@0
|
2209 function install_write_profile($install_state) {
|
Chris@0
|
2210 // Only need to write to settings.php if it is possible. The primary storage
|
Chris@0
|
2211 // for the install profile is the core.extension configuration.
|
Chris@0
|
2212 $settings_path = \Drupal::service('site.path') . '/settings.php';
|
Chris@0
|
2213 if (is_writable($settings_path)) {
|
Chris@0
|
2214 // Remember the profile which was used.
|
Chris@0
|
2215 $settings['settings']['install_profile'] = (object) [
|
Chris@0
|
2216 'value' => $install_state['parameters']['profile'],
|
Chris@0
|
2217 'required' => TRUE,
|
Chris@0
|
2218 ];
|
Chris@0
|
2219 drupal_rewrite_settings($settings);
|
Chris@0
|
2220 }
|
Chris@0
|
2221 elseif (($settings_profile = Settings::get('install_profile')) && $settings_profile !== $install_state['parameters']['profile']) {
|
Chris@0
|
2222 throw new InstallProfileMismatchException($install_state['parameters']['profile'], $settings_profile, $settings_path, \Drupal::translation());
|
Chris@0
|
2223 }
|
Chris@0
|
2224 }
|