From 16c9bda7321b07d6534640a1e9bc55e930b87008 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Tue, 29 May 2018 13:37:10 -0300 Subject: [PATCH] Merge from upstream, fix scaffolding issue (#18) * Honor .env files and suggest usage (#351) * Remove extra whitespace (#371) * Updated argument name * Bump minimal version * Bump minimal version to 8.5.3 * Fix installer path for drush commandfiles. * Composer lock from PHP 5.6 * Removing drupal-scaffold from the post-* commands --- .env.example | 27 ++++++++++++++++ .gitignore | 3 ++ README.md | 3 +- composer.json | 6 ++-- composer.lock | 52 ++++++++++++++++++++++++++++++- drush/Commands/PolicyCommands.php | 4 +-- load.environment.php | 20 ++++++++++++ 7 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 .env.example create mode 100644 load.environment.php diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000..60581237b1 --- /dev/null +++ b/.env.example @@ -0,0 +1,27 @@ +# +# Copy and rename this file to .env at root of this project. +# + +# A common use case is to supply database creds via the environment. Edit settings.php +# like so: +# +# $databases['default']['default'] = [ +# 'database' => getenv('MYSQL_DATABASE'), +# 'driver' => 'mysql', +# 'host' => getenv('MYSQL_HOSTNAME'), +# 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', +# 'password' => getenv('MYSQL_PASSWORD'), +# 'port' => getenv('MYSQL_PORT'), +# 'prefix' => '', +# 'username' => getenv('MYSQL_USER'), +# ]; +# +# Uncomment and populate as needed. +# MYSQL_DATABASE= +# MYSQL_HOSTNAME= +# MYSQL_PASSWORD= +# MYSQL_PORT= +# MYSQL_USER= + +# Another common use case is to set Drush's --uri via environment. +# DRUSH_OPTIONS_URI=http://example.com diff --git a/.gitignore b/.gitignore index cf18fe4b20..50d278d8f4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ # Ignore files generated by PhpStorm /.idea/ + +# Ignore .env files as they are personal +/.env diff --git a/README.md b/README.md index 1be593b3b1..dff0566bfa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/drupal-composer/drupal-project.svg?branch=8.x)](https://travis-ci.org/drupal-composer/drupal-project) -This project template should provide a kickstart for managing your site +This project template provides a starter kit for managing your site dependencies with [Composer](https://getcomposer.org/). If you want to know how to use it as replacement for @@ -49,6 +49,7 @@ When installing the given `composer.json` some tasks are taken care of: * Creates `web/sites/default/files`-directory. * Latest version of drush is installed locally for use at `vendor/bin/drush`. * Latest version of DrupalConsole is installed locally for use at `vendor/bin/drupal`. +* Creates environment variables based on your .env file. See [.env.example](.env.example). ## Updating Drupal Core diff --git a/composer.json b/composer.json index 4c224baaf7..d473119944 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "drupal/console": "^1.0.2", "drupal/core": "8.5.*", "drush/drush": "^9.0.0", + "vlucas/phpdotenv": "^2.4", "webflo/drupal-finder": "^1.0.0", "webmozart/path-util": "^2.3" }, @@ -40,7 +41,8 @@ "autoload": { "classmap": [ "scripts/composer/ScriptHandler.php" - ] + ], + "files": ["load.environment.php"] }, "scripts": { "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold", @@ -64,7 +66,7 @@ "web/modules/contrib/{$name}": ["type:drupal-module"], "web/profiles/contrib/{$name}": ["type:drupal-profile"], "web/themes/contrib/{$name}": ["type:drupal-theme"], - "drush/contrib/{$name}": ["type:drupal-drush"] + "drush/Commands/{$name}": ["type:drupal-drush"] } } } diff --git a/composer.lock b/composer.lock index abcd089ee3..fb14a74507 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "461b9a6c4e0e9d6ec5dca0641682fc5f", + "content-hash": "d3739d4181794aa094cc7de616391b41", "packages": [ { "name": "alchemy/zippy", @@ -4587,6 +4587,56 @@ ], "time": "2018-03-20T04:25:58+00:00" }, + { + "name": "vlucas/phpdotenv", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "3cc116adbe4b11be5ec557bf1d24dc5e3a21d18c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/3cc116adbe4b11be5ec557bf1d24dc5e3a21d18c", + "reference": "3cc116adbe4b11be5ec557bf1d24dc5e3a21d18c", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "phpunit/phpunit": "^4.8 || ^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause-Attribution" + ], + "authors": [ + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "http://www.vancelucas.com" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "time": "2016-09-01T10:05:43+00:00" + }, { "name": "webflo/drupal-finder", "version": "1.1.0", diff --git a/drush/Commands/PolicyCommands.php b/drush/Commands/PolicyCommands.php index 85ee907a85..b5bdec6cd6 100644 --- a/drush/Commands/PolicyCommands.php +++ b/drush/Commands/PolicyCommands.php @@ -19,7 +19,7 @@ class PolicyCommands extends DrushCommands { * @throws \Exception */ public function sqlSyncValidate(CommandData $commandData) { - if ($commandData->input()->getArgument('destination') == '@prod') { + if ($commandData->input()->getArgument('target') == '@prod') { throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__])); } } @@ -32,7 +32,7 @@ public function sqlSyncValidate(CommandData $commandData) { * @throws \Exception */ public function rsyncValidate(CommandData $commandData) { - if (preg_match("/^@prod/", $commandData->input()->getArgument('destination'))) { + if (preg_match("/^@prod/", $commandData->input()->getArgument('target'))) { throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__])); } } diff --git a/load.environment.php b/load.environment.php new file mode 100644 index 0000000000..769343fd6f --- /dev/null +++ b/load.environment.php @@ -0,0 +1,20 @@ +load(); +} +catch (InvalidPathException $e) { + // Do nothing. Production environments rarely use .env files. +}