Commit 2fd5f316 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3303143 by phenaproxima: Move getStagingRoot() to PathLocator

parent 390a2f5c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
    $fixture_dir = __DIR__ . '/../../fixtures/two_projects';
    Beginner::setFixturePath($fixture_dir);
    $this->container->get('package_manager.path_locator')
      ->setPaths($fixture_dir, $fixture_dir . '/vendor', '');
      ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL);
    $this->drupalLogin($user);
    $this->drupalPlaceBlock('local_tasks_block', ['primary' => TRUE]);
  }
@@ -227,7 +227,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
    $fixture_dir = __DIR__ . '/../../fixtures/one_project';
    Beginner::setFixturePath($fixture_dir);
    $this->container->get('package_manager.path_locator')
      ->setPaths($fixture_dir, $fixture_dir . '/vendor', '');
      ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL);
    $assert = $this->assertSession();
    $user = $this->createUser(
      [
@@ -246,7 +246,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
    $fixture_dir = __DIR__ . '/../../fixtures/no_project';
    Beginner::setFixturePath($fixture_dir);
    $this->container->get('package_manager.path_locator')
      ->setPaths($fixture_dir, $fixture_dir . '/vendor', '');
      ->setPaths($fixture_dir, $fixture_dir . '/vendor', '', NULL);
    $this->getSession()->reload();
    $assert->pageTextContains('Updates were found, but they must be performed manually. See the list of available updates for more information.');
    $this->assertNoUpdates();
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ services:
    class: Drupal\package_manager\PathLocator
    arguments:
      - '%app.root%'
      - '@config.factory'
      - '@file_system'

  # Validators.
  package_manager.validator.composer_executable:
+46 −1
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Drupal\package_manager;

use Composer\Autoload\ClassLoader;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;

/**
 * Computes file system paths that are needed to stage code changes.
@@ -16,14 +18,42 @@ class PathLocator {
   */
  protected $appRoot;

  /**
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The file system service.
   *
   * @var \Drupal\Core\File\FileSystemInterface
   */
  protected $fileSystem;

  /**
   * Constructs a PathLocator object.
   *
   * @param string $app_root
   *   The absolute path of the running Drupal code base.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   * @param \Drupal\Core\File\FileSystemInterface $file_system
   *   The file system service.
   */
  public function __construct(string $app_root) {
  public function __construct(string $app_root, ConfigFactoryInterface $config_factory = NULL, FileSystemInterface $file_system = NULL) {
    $this->appRoot = $app_root;
    if (empty($config_factory)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $config_factory argument is deprecated in automatic_updates:2.0.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.', E_USER_DEPRECATED);
      $config_factory = \Drupal::configFactory();
    }
    $this->configFactory = $config_factory;
    if (empty($file_system)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $file_system argument is deprecated in automatic_updates:2.0.1 and will be required before automatic_updates:3.0.0. See https://www.drupal.org/node/3300008.', E_USER_DEPRECATED);
      $file_system = \Drupal::service('file_system');
    }
    $this->fileSystem = $file_system;
  }

  /**
@@ -84,4 +114,19 @@ class PathLocator {
    return trim($web_root, DIRECTORY_SEPARATOR);
  }

  /**
   * Returns the directory where staging areas will be created.
   *
   * The staging root may be affected by site settings, so stages may wish to
   * cache the value returned by this method, to ensure that they use the same
   * staging root throughout their life cycle.
   *
   * @return string
   *   The absolute path of the directory where staging areas should be created.
   */
  public function getStagingRoot(): string {
    $site_id = $this->configFactory->get('system.site')->get('uuid');
    return $this->fileSystem->getTempDirectory() . DIRECTORY_SEPARATOR . '.package_manager' . $site_id;
  }

}
+1 −2
Original line number Diff line number Diff line
@@ -625,8 +625,7 @@ class Stage {
    // cycle.
    $dir = $this->tempStore->get(self::TEMPSTORE_STAGING_ROOT_KEY);
    if (empty($dir)) {
      $site_id = $this->configFactory->get('system.site')->get('uuid');
      $dir = $this->fileSystem->getTempDirectory() . DIRECTORY_SEPARATOR . '.package_manager' . $site_id;
      $dir = $this->pathLocator->getStagingRoot();
      $this->tempStore->set(self::TEMPSTORE_STAGING_ROOT_KEY, $dir);
    }
    return $dir;
+7 −4
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@ class PackageManagerBypassServiceProvider extends ServiceProviderBase {
  public function alter(ContainerBuilder $container) {
    parent::alter($container);

    $state = new Reference('state');
    $arguments = [
      new Reference('state'),
      $state,
      new Reference(Filesystem::class),
    ];
    if (Settings::get('package_manager_bypass_composer_stager', TRUE)) {
@@ -34,9 +35,11 @@ class PackageManagerBypassServiceProvider extends ServiceProviderBase {
      }
    }

    $container->getDefinition('package_manager.path_locator')
      ->setClass(PathLocator::class)
      ->addArgument($arguments[0]);
    $definition = $container->getDefinition('package_manager.path_locator')
      ->setClass(PathLocator::class);
    $arguments = $definition->getArguments();
    array_unshift($arguments, $state);
    $definition->setArguments($arguments);
  }

}
Loading