test Drupal site working on Koality Theme Builder
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.8 KiB

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