Pathologic was missing because of a .git folder inside.
[yaffs-website] / scripts / composer / ScriptHandler.php
1 <?php
2
3 /**
4  * @file
5  * Contains \DrupalProject\composer\ScriptHandler.
6  */
7
8 namespace DrupalProject\composer;
9
10 use Composer\Script\Event;
11 use Composer\Semver\Comparator;
12 use Symfony\Component\Filesystem\Filesystem;
13
14 class ScriptHandler {
15
16   protected static function getDrupalRoot($project_root) {
17     return $project_root . '/web';
18   }
19
20   public static function createRequiredFiles(Event $event) {
21     $fs = new Filesystem();
22     $root = static::getDrupalRoot(getcwd());
23
24     $dirs = [
25       'modules',
26       'profiles',
27       'themes',
28     ];
29
30     // Required for unit testing
31     foreach ($dirs as $dir) {
32       if (!$fs->exists($root . '/'. $dir)) {
33         $fs->mkdir($root . '/'. $dir);
34         $fs->touch($root . '/'. $dir . '/.gitkeep');
35       }
36     }
37
38     // Prepare the settings file for installation
39     if (!$fs->exists($root . '/sites/default/settings.php') and $fs->exists($root . '/sites/default/default.settings.php')) {
40       $fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php');
41       $fs->chmod($root . '/sites/default/settings.php', 0666);
42       $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
43     }
44
45     // Prepare the services file for installation
46     if (!$fs->exists($root . '/sites/default/services.yml') and $fs->exists($root . '/sites/default/default.services.yml')) {
47       $fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml');
48       $fs->chmod($root . '/sites/default/services.yml', 0666);
49       $event->getIO()->write("Create a sites/default/services.yml file with chmod 0666");
50     }
51
52     // Create the files directory with chmod 0777
53     if (!$fs->exists($root . '/sites/default/files')) {
54       $oldmask = umask(0);
55       $fs->mkdir($root . '/sites/default/files', 0777);
56       umask($oldmask);
57       $event->getIO()->write("Create a sites/default/files directory with chmod 0777");
58     }
59   }
60
61   /**
62    * Checks if the installed version of Composer is compatible.
63    *
64    * Composer 1.0.0 and higher consider a `composer install` without having a
65    * lock file present as equal to `composer update`. We do not ship with a lock
66    * file to avoid merge conflicts downstream, meaning that if a project is
67    * installed with an older version of Composer the scaffolding of Drupal will
68    * not be triggered. We check this here instead of in drupal-scaffold to be
69    * able to give immediate feedback to the end user, rather than failing the
70    * installation after going through the lengthy process of compiling and
71    * downloading the Composer dependencies.
72    *
73    * @see https://github.com/composer/composer/pull/5035
74    */
75   public static function checkComposerVersion(Event $event) {
76     $composer = $event->getComposer();
77     $io = $event->getIO();
78
79     $version = $composer::VERSION;
80
81     // The dev-channel of composer uses the git revision as version number,
82     // try to the branch alias instead.
83     if (preg_match('/^[0-9a-f]{40}$/i', $version)) {
84       $version = $composer::BRANCH_ALIAS_VERSION;
85     }
86
87     // If Composer is installed through git we have no easy way to determine if
88     // it is new enough, just display a warning.
89     if ($version === '@package_version@' || $version === '@package_branch_alias_version@') {
90       $io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>');
91     }
92     elseif (Comparator::lessThan($version, '1.0.0')) {
93       $io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.');
94       exit(1);
95     }
96   }
97
98 }