install.core.inc 91 KB

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