diff --git a/composer/src/Plugin.php b/composer/src/Plugin.php index 925b49e4c..fd5acc4c5 100644 --- a/composer/src/Plugin.php +++ b/composer/src/Plugin.php @@ -57,9 +57,36 @@ public function addVagrantfile(Event $event) { if (file_exists($source)) { if (!file_exists($target) || md5_file($source) != md5_file($target)) { + $isLegacy = $this->isLegacy(); + copy($source, $target); + + $extra = $this->composer->getPackage()->getExtra(); + if ($isLegacy && !isset($extra['drupalvm']['config_dir'])) { + $this->io->writeError( + '' + . 'Drupal VM has been updated and consquently written over your Vagrantfile which from now on will be managed by Drupal VM. ' + . 'Due to this change, you are now 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 isLegacy() { + $baseDir = dirname(Factory::getComposerFile()); + $vagrantfile = $baseDir . '/Vagrantfile'; + if (!file_exists($vagrantfile)) { + return false; + } + return strpos(file_get_contents($vagrantfile), '# Load the real Vagrantfile') !== FALSE; + } }