From 7124a652d974059258a8d42817eaa2d991030394 Mon Sep 17 00:00:00 2001 From: Ines WALLON Date: Mon, 26 May 2025 21:16:49 +0200 Subject: [PATCH 1/2] Issue #25: Add compatibility with the statistics contrib module. --- src/Installer.php | 69 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/Installer.php b/src/Installer.php index e16ce89..d9a8587 100755 --- a/src/Installer.php +++ b/src/Installer.php @@ -6,6 +6,7 @@ use Composer\DependencyResolver\Operation\InstallOperation; use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Operation\UpdateOperation; +use Composer\InstalledVersions; use Composer\Installer\PackageEvent; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; @@ -50,7 +51,6 @@ class Installer { 'index.php', 'core/install.php', 'core/rebuild.php', - 'core/modules/statistics/statistics.php', ]; /** @@ -108,6 +108,8 @@ public function __construct(Composer $composer, IOInterface $io) { $this->setAssetFileTypes(); + $this->getStatisticsPath(); + $this->excludes = $this->getConfig('excludes', []); } @@ -125,7 +127,7 @@ public function __construct(Composer $composer, IOInterface $io) { public function getConfig($name, $default = NULL) { $extra = $this->composer->getPackage()->getExtra(); - // TODO: Backward compatibility for old configs. Remove on stable version. + // @todo Backward compatibility for old configs. Remove on stable version. $legacyConfigs = [ 'drupal-app-dir', 'drupal-web-dir', @@ -368,7 +370,7 @@ public function createAssetSymlinks() { } /** - * Create a PHP stub file at web directory. + * Create a PHP stub file at we directory. * * @param string $path * The PHP file from the app directory. @@ -434,4 +436,65 @@ public function setAssetFileTypes() { $this->assetFileTypes = $event->getAssetFileTypes(); } + /** + * Get the path to the Composer root directory. + */ + public function getComposerRoot(): string|false { + foreach (InstalledVersions::getAllRawData() as $data) { + if (isset($data['versions']['drupal/core'])) { + return realpath($data['root']['install_path']); + } + } + $root = InstalledVersions::getRootPackage(); + return realpath($root['install_path']); + } + + /** + * Return module path from appDir. + * + * @param string $module + * The PHP file from the app directory. + * + * @return string|null + * Module Path. + */ + protected function getModulePath(string $module): ?string { + $composerRoot = $this->getComposerRoot(); + $extra = $this->composer->getPackage()->getExtra(); + $fs = new SymfonyFilesystem(); + $installerPaths = $extra['installer-paths']; + $searchType = 'type:drupal-module'; + $modulePath = NULL; + + foreach ($installerPaths as $key => $types) { + if (in_array($searchType, $types, TRUE)) { + $modulePath = (string) str_replace('{$name}', $module, $key); + break; + } + } + if (!$fs->exists($composerRoot . '/' . $modulePath) || !$modulePath) { + return NULL; + } + + $moduleBasePath = str_replace($this->appDir . '/', '', $modulePath); + return $moduleBasePath; + } + + /** + * Get path of Statistics module. + */ + protected function getStatisticsPath(): void { + $composerRoot = $this->getComposerRoot(); + $fs = new SymfonyFilesystem(); + $statisticsPath = $this->getModulePath('statistics'); + $statisticsCorePath = 'core/modules/statistics/statistics.php'; + + if ($fs->exists($composerRoot . '/' . $this->appDir . '/' . $statisticsCorePath)) { + array_push($this->frontControllers, $statisticsCorePath); + } + elseif ($statisticsPath) { + array_push($this->frontControllers, $statisticsPath . '/statistics.php'); + } + } + } From f59e1b3cb07791f283a087d17cd0cf34515a601f Mon Sep 17 00:00:00 2001 From: Ines WALLON Date: Thu, 19 Jun 2025 00:53:08 +0200 Subject: [PATCH 2/2] Issue #25: Check if Composer root path exist in Statistics and fix typo --- src/Installer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Installer.php b/src/Installer.php index d9a8587..29deb8f 100755 --- a/src/Installer.php +++ b/src/Installer.php @@ -370,7 +370,7 @@ public function createAssetSymlinks() { } /** - * Create a PHP stub file at we directory. + * Create a PHP stub file at web directory. * * @param string $path * The PHP file from the app directory. @@ -486,6 +486,10 @@ protected function getModulePath(string $module): ?string { protected function getStatisticsPath(): void { $composerRoot = $this->getComposerRoot(); $fs = new SymfonyFilesystem(); + if (!$fs->exists($composerRoot)) { + $this->io->writeError('> drupal-paranoia: Composer root path not found.'); + return; + } $statisticsPath = $this->getModulePath('statistics'); $statisticsCorePath = 'core/modules/statistics/statistics.php';