diff --git a/composer.json b/composer.json
index b04483e8a..0060120a7 100644
--- a/composer.json
+++ b/composer.json
@@ -43,6 +43,12 @@
"config": {
"sort-packages": true
},
+ "autoload": {
+ "classmap": [
+ "scripts/composer/ScriptHandler.php"
+ ],
+ "files": ["load.environment.php"]
+ },
"scripts": {
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
diff --git a/load.environment.php b/load.environment.php
new file mode 100644
index 000000000..769343fd6
--- /dev/null
+++ b/load.environment.php
@@ -0,0 +1,20 @@
+load();
+}
+catch (InvalidPathException $e) {
+ // Do nothing. Production environments rarely use .env files.
+}
diff --git a/scripts/composer/ScriptHandler.php b/scripts/composer/ScriptHandler.php
new file mode 100644
index 000000000..a75e4d34e
--- /dev/null
+++ b/scripts/composer/ScriptHandler.php
@@ -0,0 +1,100 @@
+locateRoot(getcwd());
+ $drupalRoot = $drupalFinder->getDrupalRoot();
+
+ $dirs = [
+ 'modules',
+ 'profiles',
+ 'themes',
+ ];
+
+ // Required for unit testing
+ foreach ($dirs as $dir) {
+ if (!$fs->exists($drupalRoot . '/'. $dir)) {
+ $fs->mkdir($drupalRoot . '/'. $dir);
+ $fs->touch($drupalRoot . '/'. $dir . '/.gitkeep');
+ }
+ }
+
+ // Prepare the settings file for installation
+ if (!$fs->exists($drupalRoot . '/sites/default/settings.php') and $fs->exists($drupalRoot . '/sites/default/default.settings.php')) {
+ $fs->copy($drupalRoot . '/sites/default/default.settings.php', $drupalRoot . '/sites/default/settings.php');
+ require_once $drupalRoot . '/core/includes/bootstrap.inc';
+ require_once $drupalRoot . '/core/includes/install.inc';
+ $settings['config_directories'] = [
+ CONFIG_SYNC_DIRECTORY => (object) [
+ 'value' => Path::makeRelative($drupalFinder->getComposerRoot() . '/config/sync', $drupalRoot),
+ 'required' => TRUE,
+ ],
+ ];
+ drupal_rewrite_settings($settings, $drupalRoot . '/sites/default/settings.php');
+ $fs->chmod($drupalRoot . '/sites/default/settings.php', 0666);
+ $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
+ }
+
+ // Create the files directory with chmod 0777
+ if (!$fs->exists($drupalRoot . '/sites/default/files')) {
+ $oldmask = umask(0);
+ $fs->mkdir($drupalRoot . '/sites/default/files', 0777);
+ umask($oldmask);
+ $event->getIO()->write("Create a sites/default/files directory with chmod 0777");
+ }
+ }
+
+ /**
+ * Checks if the installed version of Composer is compatible.
+ *
+ * Composer 1.0.0 and higher consider a `composer install` without having a
+ * lock file present as equal to `composer update`. We do not ship with a lock
+ * file to avoid merge conflicts downstream, meaning that if a project is
+ * installed with an older version of Composer the scaffolding of Drupal will
+ * not be triggered. We check this here instead of in drupal-scaffold to be
+ * able to give immediate feedback to the end user, rather than failing the
+ * installation after going through the lengthy process of compiling and
+ * downloading the Composer dependencies.
+ *
+ * @see https://github.com/composer/composer/pull/5035
+ */
+ public static function checkComposerVersion(Event $event) {
+ $composer = $event->getComposer();
+ $io = $event->getIO();
+
+ $version = $composer::VERSION;
+
+ // The dev-channel of composer uses the git revision as version number,
+ // try to the branch alias instead.
+ if (preg_match('/^[0-9a-f]{40}$/i', $version)) {
+ $version = $composer::BRANCH_ALIAS_VERSION;
+ }
+
+ // If Composer is installed through git we have no easy way to determine if
+ // it is new enough, just display a warning.
+ if ($version === '@package_version@' || $version === '@package_branch_alias_version@') {
+ $io->writeError('You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.');
+ }
+ elseif (Comparator::lessThan($version, '1.0.0')) {
+ $io->writeError('Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing.');
+ exit(1);
+ }
+ }
+
+}
diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php
index 2f7de773b..ea5342ea6 100644
--- a/vendor/composer/autoload_classmap.php
+++ b/vendor/composer/autoload_classmap.php
@@ -11,6 +11,7 @@ return array(
'DivisionByZeroError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',
'Drupal' => $baseDir . '/web/core/lib/Drupal.php',
'DrupalFinder\\DrupalFinder' => $vendorDir . '/webflo/drupal-finder/src/DrupalFinder.php',
+ 'DrupalProject\\composer\\ScriptHandler' => $baseDir . '/scripts/composer/ScriptHandler.php',
'Drupal\\Component\\Utility\\Timer' => $baseDir . '/web/core/lib/Drupal/Component/Utility/Timer.php',
'Drupal\\Component\\Utility\\Unicode' => $baseDir . '/web/core/lib/Drupal/Component/Utility/Unicode.php',
'Drupal\\Core\\Database\\Database' => $baseDir . '/web/core/lib/Drupal/Core/Database/Database.php',
diff --git a/vendor/composer/autoload_files.php b/vendor/composer/autoload_files.php
index 92568ff3d..b322b262d 100644
--- a/vendor/composer/autoload_files.php
+++ b/vendor/composer/autoload_files.php
@@ -27,4 +27,5 @@ return array(
'801c31d8ed748cfa537fa45402288c95' => $vendorDir . '/psy/psysh/src/functions.php',
'952683d815ff0a7bf322b93c0be7e4e4' => $vendorDir . '/chi-teck/drupal-code-generator/src/bootstrap.php',
'5a12a5271c58108e0aa33355e6ac54ea' => $vendorDir . '/drupal/console-core/src/functions.php',
+ 'd511210698f02d87ca48e3972f64323e' => $baseDir . '/load.environment.php',
);
diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php
index 2304470dc..a7e634fdb 100644
--- a/vendor/composer/autoload_static.php
+++ b/vendor/composer/autoload_static.php
@@ -28,6 +28,7 @@ class ComposerStaticInit5b1c1b80ca16f098d2571547d6c6045f
'801c31d8ed748cfa537fa45402288c95' => __DIR__ . '/..' . '/psy/psysh/src/functions.php',
'952683d815ff0a7bf322b93c0be7e4e4' => __DIR__ . '/..' . '/chi-teck/drupal-code-generator/src/bootstrap.php',
'5a12a5271c58108e0aa33355e6ac54ea' => __DIR__ . '/..' . '/drupal/console-core/src/functions.php',
+ 'd511210698f02d87ca48e3972f64323e' => __DIR__ . '/../..' . '/load.environment.php',
);
public static $prefixLengthsPsr4 = array (
@@ -537,6 +538,7 @@ class ComposerStaticInit5b1c1b80ca16f098d2571547d6c6045f
'DivisionByZeroError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',
'Drupal' => __DIR__ . '/../..' . '/web/core/lib/Drupal.php',
'DrupalFinder\\DrupalFinder' => __DIR__ . '/..' . '/webflo/drupal-finder/src/DrupalFinder.php',
+ 'DrupalProject\\composer\\ScriptHandler' => __DIR__ . '/../..' . '/scripts/composer/ScriptHandler.php',
'Drupal\\Component\\Utility\\Timer' => __DIR__ . '/../..' . '/web/core/lib/Drupal/Component/Utility/Timer.php',
'Drupal\\Component\\Utility\\Unicode' => __DIR__ . '/../..' . '/web/core/lib/Drupal/Component/Utility/Unicode.php',
'Drupal\\Core\\Database\\Database' => __DIR__ . '/../..' . '/web/core/lib/Drupal/Core/Database/Database.php',