6
6
use Composer \DependencyResolver \Operation \InstallOperation ;
7
7
use Composer \DependencyResolver \Operation \UninstallOperation ;
8
8
use Composer \DependencyResolver \Operation \UpdateOperation ;
9
+ use Composer \InstalledVersions ;
9
10
use Composer \Installer \PackageEvent ;
10
11
use Composer \IO \IOInterface ;
11
12
use Composer \Package \PackageInterface ;
@@ -50,7 +51,6 @@ class Installer {
50
51
'index.php ' ,
51
52
'core/install.php ' ,
52
53
'core/rebuild.php ' ,
53
- 'core/modules/statistics/statistics.php ' ,
54
54
];
55
55
56
56
/**
@@ -108,6 +108,8 @@ public function __construct(Composer $composer, IOInterface $io) {
108
108
109
109
$ this ->setAssetFileTypes ();
110
110
111
+ $ this ->getStatisticsPath ();
112
+
111
113
$ this ->excludes = $ this ->getConfig ('excludes ' , []);
112
114
}
113
115
@@ -125,7 +127,7 @@ public function __construct(Composer $composer, IOInterface $io) {
125
127
public function getConfig ($ name , $ default = NULL ) {
126
128
$ extra = $ this ->composer ->getPackage ()->getExtra ();
127
129
128
- // TODO: Backward compatibility for old configs. Remove on stable version.
130
+ // @todo Backward compatibility for old configs. Remove on stable version.
129
131
$ legacyConfigs = [
130
132
'drupal-app-dir ' ,
131
133
'drupal-web-dir ' ,
@@ -368,7 +370,7 @@ public function createAssetSymlinks() {
368
370
}
369
371
370
372
/**
371
- * Create a PHP stub file at web directory.
373
+ * Create a PHP stub file at we directory.
372
374
*
373
375
* @param string $path
374
376
* The PHP file from the app directory.
@@ -434,4 +436,65 @@ public function setAssetFileTypes() {
434
436
$ this ->assetFileTypes = $ event ->getAssetFileTypes ();
435
437
}
436
438
439
+ /**
440
+ * Get the path to the Composer root directory.
441
+ */
442
+ public function getComposerRoot (): string |false {
443
+ foreach (InstalledVersions::getAllRawData () as $ data ) {
444
+ if (isset ($ data ['versions ' ]['drupal/core ' ])) {
445
+ return realpath ($ data ['root ' ]['install_path ' ]);
446
+ }
447
+ }
448
+ $ root = InstalledVersions::getRootPackage ();
449
+ return realpath ($ root ['install_path ' ]);
450
+ }
451
+
452
+ /**
453
+ * Return module path from appDir.
454
+ *
455
+ * @param string $module
456
+ * The PHP file from the app directory.
457
+ *
458
+ * @return string|null
459
+ * Module Path.
460
+ */
461
+ protected function getModulePath (string $ module ): ?string {
462
+ $ composerRoot = $ this ->getComposerRoot ();
463
+ $ extra = $ this ->composer ->getPackage ()->getExtra ();
464
+ $ fs = new SymfonyFilesystem ();
465
+ $ installerPaths = $ extra ['installer-paths ' ];
466
+ $ searchType = 'type:drupal-module ' ;
467
+ $ modulePath = NULL ;
468
+
469
+ foreach ($ installerPaths as $ key => $ types ) {
470
+ if (in_array ($ searchType , $ types , TRUE )) {
471
+ $ modulePath = (string ) str_replace ('{$name} ' , $ module , $ key );
472
+ break ;
473
+ }
474
+ }
475
+ if (!$ fs ->exists ($ composerRoot . '/ ' . $ modulePath ) || !$ modulePath ) {
476
+ return NULL ;
477
+ }
478
+
479
+ $ moduleBasePath = str_replace ($ this ->appDir . '/ ' , '' , $ modulePath );
480
+ return $ moduleBasePath ;
481
+ }
482
+
483
+ /**
484
+ * Get path of Statistics module.
485
+ */
486
+ protected function getStatisticsPath (): void {
487
+ $ composerRoot = $ this ->getComposerRoot ();
488
+ $ fs = new SymfonyFilesystem ();
489
+ $ statisticsPath = $ this ->getModulePath ('statistics ' );
490
+ $ statisticsCorePath = 'core/modules/statistics/statistics.php ' ;
491
+
492
+ if ($ fs ->exists ($ composerRoot . '/ ' . $ this ->appDir . '/ ' . $ statisticsCorePath )) {
493
+ array_push ($ this ->frontControllers , $ statisticsCorePath );
494
+ }
495
+ elseif ($ statisticsPath ) {
496
+ array_push ($ this ->frontControllers , $ statisticsPath . '/statistics.php ' );
497
+ }
498
+ }
499
+
437
500
}
0 commit comments