Commit fd8c8cd9 authored by alexpott's avatar alexpott

Issue #2384675 by sidharrell, cilefen, Mile23, damiankloip, dawehner, Wim...

Issue #2384675 by sidharrell, cilefen, Mile23, damiankloip, dawehner, Wim Leers, alexpott, neclimdul: Deprecate conf_path()
parent 074fdb1f
......@@ -136,7 +136,7 @@ services:
arguments: ['@database', '@cache_tags.invalidator.checksum']
cache.backend.apcu:
class: Drupal\Core\Cache\ApcuBackendFactory
arguments: ['@app.root', '@cache_tags.invalidator.checksum']
arguments: ['@app.root', '@site.path', '@cache_tags.invalidator.checksum']
cache.backend.php:
class: Drupal\Core\Cache\PhpBackendFactory
arguments: ['@cache_tags.invalidator.checksum']
......@@ -545,6 +545,15 @@ services:
class: Drupal\Core\AppRootFactory
arguments: ['@kernel']
public: false
site.path:
class: SplString
factory: site.path.factory:get
tags:
- { name: parameter_service }
site.path.factory:
class: Drupal\Core\SitePathFactory
arguments: ['@kernel']
public: false
controller_resolver:
class: Drupal\Core\Controller\ControllerResolver
arguments: ['@class_resolver']
......
......@@ -367,7 +367,7 @@ function install_begin_request($class_loader, &$install_state) {
// Determine whether base system services are ready to operate.
$install_state['config_verified'] = install_ensure_config_directory(CONFIG_ACTIVE_DIRECTORY) && install_ensure_config_directory(CONFIG_STAGING_DIRECTORY);
$install_state['database_verified'] = install_verify_database_settings();
$install_state['database_verified'] = install_verify_database_settings($site_path);
$install_state['settings_verified'] = $install_state['config_verified'] && $install_state['database_verified'];
// Install factory tables only after checking the database.
......@@ -1077,11 +1077,17 @@ function install_verify_completed_task() {
/**
* Verifies that settings.php specifies a valid database connection.
*
* @param string $site_path
* The site path.
*
* @return bool
* TRUE if there are no database errors.
*/
function install_verify_database_settings() {
function install_verify_database_settings($site_path) {
if ($database = Database::getConnectionInfo()) {
$database = $database['default'];
$settings_file = './' . conf_path(FALSE) . '/settings.php';
$settings_file = './' . $site_path . '/settings.php';
$errors = install_database_errors($database, $settings_file);
if (empty($errors)) {
return TRUE;
......@@ -1902,8 +1908,9 @@ function install_check_translations($langcode, $server_pattern) {
$readable = FALSE;
$writable = FALSE;
// @todo: Make this configurable.
$files_directory = conf_path() . '/files';
$translations_directory = conf_path() . '/files/translations';
$site_path = \Drupal::service('site.path');
$files_directory = $site_path . '/files';
$translations_directory = $site_path . '/files/translations';
$translations_directory_exists = FALSE;
$translation_available = FALSE;
$online = FALSE;
......@@ -2081,12 +2088,12 @@ function install_check_requirements($install_state) {
foreach ($default_files as $default_file_info) {
$readable = FALSE;
$writable = FALSE;
$conf_path = './' . conf_path(FALSE);
$file = $conf_path . "/{$default_file_info['file']}";
$site_path = './' . \Drupal::service('site.path');
$file = $site_path . "/{$default_file_info['file']}";
$default_file = "./sites/default/{$default_file_info['file_default']}";
$exists = FALSE;
// Verify that the directory exists.
if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
if (drupal_verify_install_file($site_path, FILE_EXIST, 'dir')) {
if (drupal_verify_install_file($file, FILE_EXIST)) {
// If it does, make sure it is writable.
$readable = drupal_verify_install_file($file, FILE_READABLE);
......@@ -2111,7 +2118,7 @@ function install_check_requirements($install_state) {
// Otherwise, if $file does not exist yet, we can try to copy
// $default_file to create it.
elseif (!$exists) {
$copied = drupal_verify_install_file($conf_path, FILE_EXIST | FILE_WRITABLE, 'dir') && @copy($default_file, $file);
$copied = drupal_verify_install_file($site_path, FILE_EXIST | FILE_WRITABLE, 'dir') && @copy($default_file, $file);
if ($copied) {
// If the new $file file has the same owner as $default_file this means
// $default_file is owned by the webserver user. This is an inherent
......
......@@ -197,7 +197,7 @@ function drupal_get_database_types() {
*/
function drupal_rewrite_settings($settings = array(), $settings_file = NULL) {
if (!isset($settings_file)) {
$settings_file = conf_path(FALSE) . '/settings.php';
$settings_file = \Drupal::service('site.path') . '/settings.php';
}
// Build list of setting names and insert the values into the global namespace.
$variable_names = array();
......@@ -470,13 +470,13 @@ function drupal_install_config_directories() {
$config_directories_hash = Crypt::randomBytesBase64(55);
if (empty($config_directories[CONFIG_ACTIVE_DIRECTORY])) {
$settings['config_directories'][CONFIG_ACTIVE_DIRECTORY] = (object) [
'value' => conf_path() . '/files/config_' . $config_directories_hash . '/active',
'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/active',
'required' => TRUE,
];
}
if (empty($config_directories[CONFIG_STAGING_DIRECTORY])) {
$settings['config_directories'][CONFIG_STAGING_DIRECTORY] = (object) [
'value' => conf_path() . '/files/config_' . $config_directories_hash . '/staging',
'value' => \Drupal::service('site.path') . '/files/config_' . $config_directories_hash . '/staging',
'required' => TRUE,
];
}
......
......@@ -30,11 +30,13 @@ class ApcuBackendFactory implements CacheFactoryInterface {
*
* @param string $root
* The app root.
* @param string $site_path
* The site path.
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
* The cache tags checksum provider.
*/
public function __construct($root, CacheTagsChecksumInterface $checksum_provider) {
$this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, conf_path());
public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) {
$this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path);
$this->checksumProvider = $checksum_provider;
}
......
......@@ -48,7 +48,7 @@ public function getFormOptions(array $database) {
// Make the text more accurate for SQLite.
$form['database']['#title'] = t('Database file');
$form['database']['#description'] = t('The absolute path to the file where @drupal data will be stored. This must be writable by the web server and should exist outside of the web root.', array('@drupal' => drupal_install_profile_distribution_name()));
$default_database = conf_path(FALSE) . '/files/.ht.sqlite';
$default_database = \Drupal::service('site.path') . '/files/.ht.sqlite';
$form['database']['#default_value'] = empty($database['database']) ? $default_database : $database['database'];
return $form;
}
......
......@@ -8,8 +8,10 @@
namespace Drupal\Core\Extension;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Extension\Discovery\RecursiveExtensionFilterIterator;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
/**
* Discovers available extensions in the filesystem.
......@@ -162,8 +164,16 @@ public function scan($type, $include_tests = NULL) {
$searchdirs[static::ORIGIN_PARENT_SITE] = $parent_site;
}
// Search the site-specific directory.
$searchdirs[static::ORIGIN_SITE] = conf_path();
// Find the site-specific directory to search. Since we are using this
// method to discover extensions including profiles, we might be doing this
// at install time. Therefore Kernel service is not always available, but is
// preferred.
if (\Drupal::hasService('kernel')) {
$searchdirs[static::ORIGIN_SITE] = \Drupal::service('site.path');
}
else {
$searchdirs[static::ORIGIN_SITE] = DrupalKernel::findSitePath(Request::createFromGlobals());
}
// Unless an explicit value has been passed, manually check whether we are
// in a test environment, in which case test extensions must be included.
......
......@@ -20,6 +20,13 @@
*/
class SiteConfigureForm extends ConfigFormBase {
/**
* The site path.
*
* @var string
*/
protected $sitePath;
/**
* The user storage.
*
......@@ -60,6 +67,8 @@ class SiteConfigureForm extends ConfigFormBase {
*
* @param string $root
* The app root.
* @param string $site_path
* The site path.
* @param \Drupal\user\UserStorageInterface $user_storage
* The user storage.
* @param \Drupal\Core\State\StateInterface $state
......@@ -69,8 +78,9 @@ class SiteConfigureForm extends ConfigFormBase {
* @param \Drupal\Core\Locale\CountryManagerInterface $country_manager
* The country manager.
*/
public function __construct($root, UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) {
public function __construct($root, $site_path, UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) {
$this->root = $root;
$this->sitePath = $site_path;
$this->userStorage = $user_storage;
$this->state = $state;
$this->moduleInstaller = $module_installer;
......@@ -83,6 +93,7 @@ public function __construct($root, UserStorageInterface $user_storage, StateInte
public static function create(ContainerInterface $container) {
return new static(
$container->get('app.root'),
$container->get('site.path'),
$container->get('entity.manager')->getStorage('user'),
$container->get('state'),
$container->get('module_installer'),
......@@ -115,7 +126,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['#title'] = $this->t('Configure site');
// Warn about settings.php permissions risk
$settings_dir = conf_path();
$settings_dir = $this->sitePath;
$settings_file = $settings_dir . '/settings.php';
// Check that $_POST is empty so we only show this message when the form is
// first displayed, not on the next page after it is submitted. (We do not
......
......@@ -11,12 +11,39 @@
use Drupal\Core\Database\Database;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form to configure and rewrite settings.php.
*/
class SiteSettingsForm extends FormBase {
/**
* The site path.
*
* @var string
*/
protected $sitePath;
/**
* Constructs a new SiteSettingsForm.
*
* @param string $site_path
* The site path.
*/
public function __construct($site_path) {
$this->sitePath = $site_path;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('site.path')
);
}
/**
* {@inheritdoc}
*/
......@@ -28,8 +55,7 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$conf_path = './' . conf_path(FALSE);
$settings_file = $conf_path . '/settings.php';
$settings_file = './' . $this->sitePath . '/settings.php';
$form['#title'] = $this->t('Database configuration');
......
......@@ -117,7 +117,6 @@ public static function initialize($app_root, $site_path, &$class_loader) {
$config = array();
$databases = array();
// Make conf_path() available as local variable in settings.php.
if (is_readable($app_root . '/' . $site_path . '/settings.php')) {
require $app_root . '/' . $site_path . '/settings.php';
}
......
<?php
/**
* @file
* Contains \Drupal\Core\SitePathFactory.
*/
namespace Drupal\Core;
/**
* Gets the site path from the kernel.
*/
class SitePathFactory {
/**
* The Drupal kernel.
*
* @var \Drupal\Core\DrupalKernelInterface
*/
protected $drupalKernel;
/**
* Constructs an SitePathFactory instance.
*
* @param \Drupal\Core\DrupalKernelInterface $drupal_kernel
* The Drupal kernel.
*/
public function __construct(DrupalKernelInterface $drupal_kernel) {
$this->drupalKernel = $drupal_kernel;
}
/**
* Gets the site path.
*
* @return string
* The site path.
*/
public function get() {
return $this->drupalKernel->getSitePath();
}
}
......@@ -8,7 +8,9 @@
namespace Drupal\Core\StreamWrapper;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines a Drupal public (public://) stream wrapper class.
......@@ -57,12 +59,39 @@ public function getExternalUrl() {
/**
* Returns the base path for public://.
*
* If we have a setting for the public:// scheme's path, we use that.
* Otherwise we build a reasonable default based on the site.path service if
* it's available, or a default behavior based on the request.
*
* The site path is injectable from the site.path service:
* @code
* $base_path = PublicStream::basePath(\Drupal::service('site.path'));
* @endcode
*
* @param \SplString $site_path
* (optional) The site.path service parameter, which is typically the path
* to sites/ in a Drupal installation. This allows you to inject the site
* path using services from the caller. If omitted, this method will use the
* global service container or the kernel's default behavior to determine
* the site path.
*
* @return string
* The base path for public:// typically sites/default/files.
*/
public static function basePath() {
$base_path = Settings::get('file_public_path', conf_path() . '/files');
return $base_path;
public static function basePath(\SplString $site_path = NULL) {
if ($site_path === NULL) {
// Find the site path. Kernel service is not always available at this
// point, but is preferred, when available.
if (\Drupal::hasService('kernel')) {
$site_path = \Drupal::service('site.path');
}
else {
// If there is no kernel available yet, we call the static
// findSitePath().
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
}
}
return Settings::get('file_public_path', $site_path . '/files');
}
}
......@@ -31,7 +31,7 @@ public function getDescription() {
}
function getDirectoryPath() {
return conf_path() . '/files';
return \Drupal::service('site.path') . '/files';
}
/**
......
......@@ -31,7 +31,7 @@ public function getDescription() {
}
function getDirectoryPath() {
return conf_path() . '/files';
return \Drupal::service('site.path') . '/files';
}
/**
......
......@@ -15,7 +15,8 @@
function locale_install() {
// Create the interface translations directory and ensure it's writable.
if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) {
$directory = conf_path() . '/files/translations';
$site_path = \Drupal::service('site.path');
$directory = $site_path . '/files/translations';
\Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save();
}
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
......
......@@ -1136,7 +1136,8 @@ private function prepareEnvironment() {
}
// Backup current in-memory configuration.
$this->originalSite = conf_path();
$site_path = \Drupal::service('site.path');
$this->originalSite = $site_path;
$this->originalSettings = Settings::getAll();
$this->originalConfig = $GLOBALS['config'];
// @todo Remove all remnants of $GLOBALS['conf'].
......@@ -1151,7 +1152,7 @@ private function prepareEnvironment() {
// Save further contextual information.
// Use the original files directory to avoid nesting it within an existing
// simpletest directory if a test is executed within a test.
$this->originalFileDirectory = Settings::get('file_public_path', conf_path() . '/files');
$this->originalFileDirectory = Settings::get('file_public_path', $site_path . '/files');
$this->originalProfile = drupal_get_profile();
$this->originalUser = isset($user) ? clone $user : NULL;
......@@ -1221,7 +1222,6 @@ private function prepareEnvironment() {
// After preparing the environment and changing the database prefix, we are
// in a valid test environment.
drupal_valid_test_ua($this->databasePrefix);
conf_path(FALSE, TRUE);
// Reset settings.
new Settings(array(
......@@ -1335,7 +1335,6 @@ private function restoreEnvironment() {
else {
drupal_valid_test_ua(FALSE);
}
conf_path(TRUE, TRUE);
// Restore original shutdown callbacks.
$callbacks = &drupal_register_shutdown_function();
......
......@@ -161,6 +161,7 @@ function stubTest() {
// @see drupal_generate_test_ua();
$key_file = DRUPAL_ROOT . '/sites/simpletest/' . substr($this->databasePrefix, 10) . '/.htkey';
$private_key = Crypt::randomBytesBase64(55);
$site_path = $this->container->get('site.path');
file_put_contents($key_file, $private_key);
// This causes the first of the fifteen passes asserted in
......@@ -192,7 +193,7 @@ function stubTest() {
// These cause the eleventh to fourteenth of the fifteen passes asserted in
// confirmStubResults().
$this->assertTrue(file_exists(conf_path() . '/settings.testing.php'));
$this->assertTrue(file_exists($site_path . '/settings.testing.php'));
// Check the settings.testing.php file got included.
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
// Check that the test-specific service file got loaded.
......
......@@ -19,7 +19,8 @@ class DirectoryTest extends FileTestBase {
* Test local directory handling functions.
*/
function testFileCheckLocalDirectoryHandling() {
$directory = conf_path() . '/files';
$site_path = $this->container->get('site.path');
$directory = $site_path . '/files';
// Check a new recursively created local directory for correct file system
// permissions.
......
......@@ -34,7 +34,8 @@ class ReadOnlyStreamWrapperTest extends FileTestBase {
function testReadOnlyBehavior() {
// Generate a test file
$filename = $this->randomMachineName();
$filepath = conf_path() . '/files/' . $filename;
$site_path = $this->container->get('site.path');
$filepath = $site_path . '/files/' . $filename;
file_put_contents($filepath, $filename);
// Generate a read-only stream wrapper instance
......@@ -79,7 +80,7 @@ function testReadOnlyBehavior() {
// Test the mkdir() function by attempting to create a directory.
$dirname = $this->randomMachineName();
$dir = conf_path() . '/files/' . $dirname;
$dir = $site_path . '/files/' . $dirname;
$readonlydir = $this->scheme . '://' . $dirname;
$this->assertFalse(@drupal_mkdir($readonlydir, 0775, 0), 'Unable to create directory with read-only stream wrapper.');
// Create a temporary directory for testing purposes
......
......@@ -9,6 +9,8 @@
use Drupal\simpletest\InstallerTestBase;
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
/**
* Tests the installer with an existing settings file.
......@@ -48,14 +50,17 @@ protected function setUp() {
'required' => TRUE,
);
// Use the kernel to find the site path because the site.path service should
// not be available at this point in the install process.
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
// Pre-configure config directories.
$this->settings['config_directories'] = array(
CONFIG_ACTIVE_DIRECTORY => (object) array(
'value' => conf_path() . '/files/config_active',
'value' => $site_path . '/files/config_active',
'required' => TRUE,
),
CONFIG_STAGING_DIRECTORY => (object) array(
'value' => conf_path() . '/files/config_staging',
'value' => $site_path . '/files/config_staging',
'required' => TRUE,
),
);
......
......@@ -21,6 +21,7 @@ class SettingsRewriteTest extends KernelTestBase {
*/
function testDrupalRewriteSettings() {
include_once \Drupal::root() . '/core/includes/install.inc';
$site_path = $this->container->get('site.path');
$tests = array(
array(
'original' => '$no_index_value_scalar = TRUE;',
......@@ -99,7 +100,7 @@ function testDrupalRewriteSettings() {
),
);
foreach ($tests as $test) {
$filename = Settings::get('file_public_path', conf_path() . '/files') . '/mock_settings.php';
$filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
file_put_contents(\Drupal::root() . '/' . $filename, "<?php\n" . $test['original'] . "\n");
drupal_rewrite_settings($test['settings'], $filename);
$this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
......@@ -117,7 +118,7 @@ function testDrupalRewriteSettings() {
'expected' => '$no_index = true;'
);
// Make an empty file.
$filename = Settings::get('file_public_path', conf_path() . '/files') . '/mock_settings.php';
$filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
file_put_contents(\Drupal::root() . '/' . $filename, "");
// Write the setting to the file.
......
......@@ -10,11 +10,13 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Url;
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Language\Language;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PrivateStream;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\system\SystemRequirements;
use Symfony\Component\HttpFoundation\Request;
/**
* Implements hook_requirements().
......@@ -250,12 +252,19 @@ function system_requirements($phase) {
// Test configuration files and directory for writability.
if ($phase == 'runtime') {
$conf_errors = array();
$conf_path = conf_path();
if (!drupal_verify_install_file($conf_path, FILE_NOT_WRITABLE, 'dir')) {
$conf_errors[] = t("The directory %file is not protected from modifications and poses a security risk. You must change the directory's permissions to be non-writable.", array('%file' => $conf_path));
// Find the site path. Kernel service is not always available at this point,
// but is preferred, when available.
if (\Drupal::hasService('kernel')) {
$site_path = \Drupal::service('site.path');
}
else {
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
}
if (!drupal_verify_install_file($site_path, FILE_NOT_WRITABLE, 'dir')) {
$conf_errors[] = t("The directory %file is not protected from modifications and poses a security risk. You must change the directory's permissions to be non-writable.", array('%file' => $site_path));
}
foreach (array('settings.php', 'settings.local.php', 'services.yml') as $conf_file) {
$full_path = $conf_path . '/' . $conf_file;
$full_path = $site_path . '/' . $conf_file;
if (file_exists($full_path) && !drupal_verify_install_file($full_path, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE)) {
$conf_errors[] = t("The file %file is not protected from modifications and poses a security risk. You must change the file's permissions to be non-writable.", array('%file' => $full_path));
}
......@@ -391,7 +400,9 @@ function system_requirements($phase) {
else {
// If we are installing Drupal, the settings.php file might not exist yet
// in the intended site directory, so don't require it.
$directories[] = conf_path(FALSE) . '/files';
$request = Request::createFromGlobals();
$site_path = DrupalKernel::findSitePath($request);
$directories[] = $site_path . '/files';
}
if ($file_private_path = Settings::get('file_private_path')) {
$directories[] = $file_private_path;
......@@ -418,7 +429,7 @@ function system_requirements($phase) {
$requirements['config directories'] = array(
'title' => t('Configuration directories'),
'value' => t('Not present'),
'description' => t('Your %file file must define the $config_directories variable as an array containing the name of a directories in which configuration files can be written.', array('%file' => conf_path() . '/settings.php')),
'description' => t('Your %file file must define the $config_directories variable as an array containing the name of a directories in which configuration files can be written.', array('%file' => $site_path . '/settings.php')),
'severity' => REQUIREMENT_ERROR,
);
}
......
......@@ -33,6 +33,13 @@ class UpdateManagerInstall extends FormBase {
*/
protected $root;
/**
* The site path.
*
* @var string
*/
protected $sitePath;
/**
* Constructs a new UpdateManagerInstall.
*
......@@ -40,10 +47,13 @@ class UpdateManagerInstall extends FormBase {
* The app root.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param string $site_path
* The site path.
*/
public function __construct($root, ModuleHandlerInterface $module_handler) {
public function __construct($root, ModuleHandlerInterface $module_handler, $site_path) {
$this->root = $root;
$this->moduleHandler = $module_handler;
$this->sitePath = $site_path;
}
/**
......@@ -59,7 +69,8 @@ public function getFormId() {
public static function create(ContainerInterface $container) {
return new static(
$container->get('app.root'),
$container->get('module_handler')
$container->get('module_handler'),
$container->get('site.path')
);
}
......@@ -217,7 +228,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// install the code, there's no need to prompt for FTP/SSH credentials.
// Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke
// update_authorize_run_install() directly.
if (fileowner($project_real_location) == fileowner(conf_path())) {
if (fileowner($project_real_location) == fileowner($this->sitePath)) {
$this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
$filetransfer = new Local($this->root);
call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));
......
......@@ -41,6 +41,13 @@ class UpdateReady extends FormBase {
*/
protected $state;
/**
* The Site path.
*
* @var string
*/
protected $sitePath;
/**
* Constructs a new UpdateReady object.
*
......@@ -50,11 +57,14 @@ class UpdateReady extends FormBase {
* The object that manages enabled modules in a Drupal installation.
* @param \Drupal\Core\State\StateInterface $state
* The state key value store.
* @param string $site_path
* The site path.
*/
public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state) {
public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state, $site_path) {
$this->root = $root;
$this->moduleHandler = $module_handler;
$this->state = $state;
$this->sitePath = $site_path;
}
/**
......@@ -71,7 +81,8 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('app.root'),
$container->get('module_handler'),
$container->get('state')
$container->get('state'),
$container->get('site.path')
);
}
......@@ -142,7 +153,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// trying to install the code, there's no need to prompt for FTP/SSH
// credentials. Instead, we instantiate a Drupal\Core\FileTransfer\Local
// and invoke update_authorize_run_update() directly.
if (fileowner($project_real_location) == fileowner(conf_path())) {
if (fileowner($project_real_location) == fileowner($this->sitePath)) {
$this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
$filetransfer = new Local($this->root);
update_authorize_run_update($filetransfer, $updates);
......
......@@ -306,7 +306,8 @@ function update_manager_local_transfers_allowed() {
// the configuration directory to determine if local transfers will be
// allowed.
$temporary_file = drupal_tempnam('temporary://', 'update_');
$local_transfers_allowed = fileowner($temporary_file) === fileowner(conf_path());
$site_path = \Drupal::service('site.path');
$local_transfers_allowed = fileowner($temporary_file) === fileowner($site_path);
// Clean up. If this fails, we can ignore it (since this is just a temporary
// file anyway).
......
......@@ -48,7 +48,7 @@
* sites/8080.www.drupal.org.mysite.test/.