5 * Contains \DrupalProject\composer\ScriptHandler.
8 namespace DrupalProject\composer;
10 use Composer\Script\Event;
11 use Composer\Semver\Comparator;
12 use Symfony\Component\Filesystem\Filesystem;
16 protected static function getDrupalRoot($project_root) {
17 return $project_root . '/web';
20 public static function createRequiredFiles(Event $event) {
21 $fs = new Filesystem();
22 $root = static::getDrupalRoot(getcwd());
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');
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");
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");
52 // Create the files directory with chmod 0777
53 if (!$fs->exists($root . '/sites/default/files')) {
55 $fs->mkdir($root . '/sites/default/files', 0777);
57 $event->getIO()->write("Create a sites/default/files directory with chmod 0777");
62 * Checks if the installed version of Composer is compatible.
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.
73 * @see https://github.com/composer/composer/pull/5035
75 public static function checkComposerVersion(Event $event) {
76 $composer = $event->getComposer();
77 $io = $event->getIO();
79 $version = $composer::VERSION;
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;
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>');
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>.');