comparison core/includes/install.inc @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
3 /** 3 /**
4 * @file 4 * @file
5 * API functions for installing modules and themes. 5 * API functions for installing modules and themes.
6 */ 6 */
7 7
8 use Drupal\Core\Extension\Dependency;
8 use Drupal\Component\Utility\Unicode; 9 use Drupal\Component\Utility\Unicode;
10 use Drupal\Core\File\FileSystemInterface;
9 use Symfony\Component\HttpFoundation\RedirectResponse; 11 use Symfony\Component\HttpFoundation\RedirectResponse;
10 use Drupal\Component\Utility\Crypt; 12 use Drupal\Component\Utility\Crypt;
11 use Drupal\Component\Utility\OpCodeCache; 13 use Drupal\Component\Utility\OpCodeCache;
12 use Drupal\Component\Utility\UrlHelper; 14 use Drupal\Component\Utility\UrlHelper;
13 use Drupal\Core\Extension\ExtensionDiscovery; 15 use Drupal\Core\Extension\ExtensionDiscovery;
508 // settings.php it will have already been created and verified earlier, and 510 // settings.php it will have already been created and verified earlier, and
509 // if it wasn't specified in settings.php, it is created here inside the 511 // if it wasn't specified in settings.php, it is created here inside the
510 // public files directory, which has already been verified to be writable 512 // public files directory, which has already been verified to be writable
511 // itself. But if it somehow fails anyway, the installation cannot proceed. 513 // itself. But if it somehow fails anyway, the installation cannot proceed.
512 // Bail out using a similar error message as in system_requirements(). 514 // Bail out using a similar error message as in system_requirements().
513 if (!file_prepare_directory($config_directories[CONFIG_SYNC_DIRECTORY], FILE_CREATE_DIRECTORY) 515 if (!\Drupal::service('file_system')->prepareDirectory($config_directories[CONFIG_SYNC_DIRECTORY], FileSystemInterface::CREATE_DIRECTORY)
514 && !file_exists($config_directories[CONFIG_SYNC_DIRECTORY])) { 516 && !file_exists($config_directories[CONFIG_SYNC_DIRECTORY])) {
515 throw new Exception(t('The directory %directory could not be created. To proceed with the installation, either create the directory or ensure that the installer has the permissions to create it automatically. For more information, see the <a href=":handbook_url">online handbook</a>.', [ 517 throw new Exception(t('The directory %directory could not be created. To proceed with the installation, either create the directory or ensure that the installer has the permissions to create it automatically. For more information, see the <a href=":handbook_url">online handbook</a>.', [
516 '%directory' => config_get_config_directory(CONFIG_SYNC_DIRECTORY), 518 '%directory' => config_get_config_directory(CONFIG_SYNC_DIRECTORY),
517 ':handbook_url' => 'https://www.drupal.org/server-permissions', 519 ':handbook_url' => 'https://www.drupal.org/server-permissions',
518 ])); 520 ]));
521 // Put a README.txt into the sync config directory. This is required so that 523 // Put a README.txt into the sync config directory. This is required so that
522 // they can later be added to git. Since this directory is auto-created, we 524 // they can later be added to git. Since this directory is auto-created, we
523 // have to write out the README rather than just adding it to the drupal core 525 // have to write out the README rather than just adding it to the drupal core
524 // repo. 526 // repo.
525 $text = 'This directory contains configuration to be imported into your Drupal site. To make this configuration active, visit admin/config/development/configuration/sync.' . ' For information about deploying configuration between servers, see https://www.drupal.org/documentation/administer/config'; 527 $text = 'This directory contains configuration to be imported into your Drupal site. To make this configuration active, visit admin/config/development/configuration/sync.' . ' For information about deploying configuration between servers, see https://www.drupal.org/documentation/administer/config';
526 file_put_contents(config_get_config_directory(CONFIG_SYNC_DIRECTORY) . '/README.txt', $text); 528 file_put_contents(config_get_config_directory(CONFIG_SYNC_DIRECTORY) . '/README.txt', "$text\n");
527 } 529 }
528 } 530 }
529 531
530 /** 532 /**
531 * Ensures that the config directory exists and is writable, or can be made so. 533 * Ensures that the config directory exists and is writable, or can be made so.
535 * 537 *
536 * @return bool 538 * @return bool
537 * TRUE if the config directory exists and is writable. 539 * TRUE if the config directory exists and is writable.
538 * 540 *
539 * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use 541 * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use
540 * config_get_config_directory() and file_prepare_directory() instead. 542 * config_get_config_directory() and
543 * \Drupal\Core\File\FileSystemInterface::prepareDirectory() instead.
541 * 544 *
542 * @see https://www.drupal.org/node/2501187 545 * @see https://www.drupal.org/node/2501187
543 */ 546 */
544 function install_ensure_config_directory($type) { 547 function install_ensure_config_directory($type) {
545 @trigger_error('install_ensure_config_directory() is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0. Use config_get_config_directory() and file_prepare_directory() instead. See https://www.drupal.org/node/2501187.', E_USER_DEPRECATED); 548 @trigger_error('install_ensure_config_directory() is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0. Use config_get_config_directory() and \Drupal\Core\File\FileSystemInterface::prepareDirectory() instead. See https://www.drupal.org/node/2501187.', E_USER_DEPRECATED);
546 // The config directory must be defined in settings.php. 549 // The config directory must be defined in settings.php.
547 global $config_directories; 550 global $config_directories;
548 if (!isset($config_directories[$type])) { 551 if (!isset($config_directories[$type])) {
549 return FALSE; 552 return FALSE;
550 } 553 }
551 // The logic here is similar to that used by system_requirements() for other 554 // The logic here is similar to that used by system_requirements() for other
552 // directories that the installer creates. 555 // directories that the installer creates.
553 else { 556 else {
554 $config_directory = config_get_config_directory($type); 557 $config_directory = config_get_config_directory($type);
555 return file_prepare_directory($config_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); 558 return \Drupal::service('file_system')->prepareDirectory($config_directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
556 } 559 }
557 } 560 }
558 561
559 /** 562 /**
560 * Verifies that all dependencies are met for a given installation profile. 563 * Verifies that all dependencies are met for a given installation profile.
776 break; 779 break;
777 } 780 }
778 } 781 }
779 } 782 }
780 783
781 if (@drupal_mkdir($file, $mod)) { 784 if (@\Drupal::service('file_system')->mkdir($file, $mod)) {
782 return TRUE; 785 return TRUE;
783 } 786 }
784 else { 787 else {
785 return FALSE; 788 return FALSE;
786 } 789 }
1118 ]; 1121 ];
1119 $profile_path = drupal_get_path('profile', $profile); 1122 $profile_path = drupal_get_path('profile', $profile);
1120 $info = \Drupal::service('info_parser')->parse("$profile_path/$profile.info.yml"); 1123 $info = \Drupal::service('info_parser')->parse("$profile_path/$profile.info.yml");
1121 $info += $defaults; 1124 $info += $defaults;
1122 1125
1126 $dependency_name_function = function ($dependency) {
1127 return Dependency::createFromString($dependency)->getName();
1128 };
1123 // Convert dependencies in [project:module] format. 1129 // Convert dependencies in [project:module] format.
1124 $info['dependencies'] = array_map(function ($dependency) { 1130 $info['dependencies'] = array_map($dependency_name_function, $info['dependencies']);
1125 return ModuleHandler::parseDependency($dependency)['name'];
1126 }, $info['dependencies']);
1127 1131
1128 // Convert install key in [project:module] format. 1132 // Convert install key in [project:module] format.
1129 $info['install'] = array_map(function ($dependency) { 1133 $info['install'] = array_map($dependency_name_function, $info['install']);
1130 return ModuleHandler::parseDependency($dependency)['name'];
1131 }, $info['install']);
1132 1134
1133 // drupal_required_modules() includes the current profile as a dependency. 1135 // drupal_required_modules() includes the current profile as a dependency.
1134 // Remove that dependency, since a module cannot depend on itself. 1136 // Remove that dependency, since a module cannot depend on itself.
1135 $required = array_diff(drupal_required_modules(), [$profile]); 1137 $required = array_diff(drupal_required_modules(), [$profile]);
1136 1138