Skip to content
Snippets Groups Projects
Commit b302be99 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3342227 by omkar.podey, phenaproxima, Wim Leers:...

Issue #3342227 by omkar.podey, phenaproxima, Wim Leers: ScaffoldFilePermissionsValidator should use ComposerInspector instead of ComposerUtility
parent ef7959d8
No related branches found
No related tags found
No related merge requests found
...@@ -105,8 +105,6 @@ services: ...@@ -105,8 +105,6 @@ services:
- { name: event_subscriber } - { name: event_subscriber }
automatic_updates.validator.scaffold_file_permissions: automatic_updates.validator.scaffold_file_permissions:
class: Drupal\automatic_updates\Validator\ScaffoldFilePermissionsValidator class: Drupal\automatic_updates\Validator\ScaffoldFilePermissionsValidator
arguments:
- '@package_manager.path_locator'
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
automatic_updates.validator.cron_server: automatic_updates.validator.cron_server:
......
...@@ -6,7 +6,7 @@ namespace Drupal\automatic_updates\Validator; ...@@ -6,7 +6,7 @@ namespace Drupal\automatic_updates\Validator;
use Drupal\automatic_updates\Updater; use Drupal\automatic_updates\Updater;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\ComposerUtility; use Drupal\package_manager\ComposerInspector;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\PreOperationStageEvent;
...@@ -27,13 +27,17 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface ...@@ -27,13 +27,17 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface
use StringTranslationTrait; use StringTranslationTrait;
/** /**
* Constructs a SiteDirectoryPermissionsValidator object. * Constructs a ScaffoldFilePermissionsValidator object.
* *
* @param \Drupal\package_manager\ComposerInspector $composerInspector
* The Composer inspector service.
* @param \Drupal\package_manager\PathLocator $pathLocator * @param \Drupal\package_manager\PathLocator $pathLocator
* The path locator service. * The path locator service.
*/ */
public function __construct(protected PathLocator $pathLocator) { public function __construct(
} private ComposerInspector $composerInspector,
private PathLocator $pathLocator,
) {}
/** /**
* Validates that scaffold files have the appropriate permissions. * Validates that scaffold files have the appropriate permissions.
...@@ -53,15 +57,14 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface ...@@ -53,15 +57,14 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface
} }
$site_dir .= '/sites/default'; $site_dir .= '/sites/default';
$stage = $event->stage; $active_scaffold_files = $this->getDefaultSiteFilesFromScaffold($this->pathLocator->getProjectRoot());
$active_scaffold_files = $this->getDefaultSiteFilesFromScaffold($stage->getActiveComposer());
// If the active directory and stage directory have different files // If the active directory and stage directory have different files
// scaffolded into `sites/default` (i.e., files were added, renamed, or // scaffolded into `sites/default` (i.e., files were added, renamed, or
// deleted), the site directory itself must be writable for the changes to // deleted), the site directory itself must be writable for the changes to
// be applied. // be applied.
if ($event instanceof PreApplyEvent) { if ($event instanceof PreApplyEvent) {
$staged_scaffold_files = $this->getDefaultSiteFilesFromScaffold($stage->getStageComposer()); $staged_scaffold_files = $this->getDefaultSiteFilesFromScaffold($event->stage->getStageDirectory());
if ($active_scaffold_files !== $staged_scaffold_files) { if ($active_scaffold_files !== $staged_scaffold_files) {
$paths[] = $site_dir; $paths[] = $site_dir;
...@@ -88,8 +91,8 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface ...@@ -88,8 +91,8 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface
/** /**
* Returns the list of file names scaffolded into `sites/default`. * Returns the list of file names scaffolded into `sites/default`.
* *
* @param \Drupal\package_manager\ComposerUtility $composer * @param string $working_dir
* A Composer utility helper for a directory. * The directory in which to run Composer.
* *
* @return string[] * @return string[]
* The names of files that are scaffolded into `sites/default`, stripped * The names of files that are scaffolded into `sites/default`, stripped
...@@ -99,13 +102,12 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface ...@@ -99,13 +102,12 @@ final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface
* directory doesn't have the `drupal/core` package installed, the returned * directory doesn't have the `drupal/core` package installed, the returned
* array will be empty. * array will be empty.
*/ */
protected function getDefaultSiteFilesFromScaffold(ComposerUtility $composer): array { protected function getDefaultSiteFilesFromScaffold(string $working_dir): array {
$installed = $composer->getInstalledPackages(); $installed = $this->composerInspector->getInstalledPackagesList($working_dir);
if (array_key_exists('drupal/core', $installed)) { if (isset($installed['drupal/core'])) {
$extra = $installed['drupal/core']->getExtra();
// We expect Drupal core to provide a list of scaffold files. // We expect Drupal core to provide a list of scaffold files.
$files = $extra['drupal-scaffold']['file-mapping']; $files = (array) json_decode($this->composerInspector->getConfig('extra.drupal-scaffold.file-mapping', $installed['drupal/core']->path . '/composer.json'));
} }
else { else {
$files = []; $files = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment