From 432f19ba0dd86779122956aaf0a1a3c87030965d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Sun, 23 Apr 2017 17:30:28 -0500 Subject: [PATCH] Write a Composer warning message when upgrading from < 5.0.0 --- composer/src/Plugin.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/composer/src/Plugin.php b/composer/src/Plugin.php index 925b49e4c..74ce911dc 100644 --- a/composer/src/Plugin.php +++ b/composer/src/Plugin.php @@ -57,9 +57,34 @@ public function addVagrantfile(Event $event) { if (file_exists($source)) { if (!file_exists($target) || md5_file($source) != md5_file($target)) { + $isLegacy = $this->isLegacyVagrantfile($target); + copy($source, $target); + + $extra = $this->composer->getPackage()->getExtra(); + if ($isLegacy && !isset($extra['drupalvm']['config_dir'])) { + $this->io->writeError( + '' + . 'Drupal VM has been updated and consequently written over your Vagrantfile which from now on will be managed by Drupal VM. ' + . 'Due to this change, you are required to set your `config_dir` location in your composer.json file. Below follows the necessary change:' + . '' + ); + $this->io->writeError(''); + $this->io->writeError(json_encode(['extra' => ['drupalvm' => ['config_dir' => '']]], JSON_PRETTY_PRINT)); + } } } } + /** + * Return if the parent project is using the < 5.0.0 delegating Vagrantfile. + * + * @return bool + */ + private function isLegacyVagrantfile($vagrantfile) { + if (!file_exists($vagrantfile)) { + return false; + } + return strpos(file_get_contents($vagrantfile), '# Load the real Vagrantfile') !== FALSE; + } }