Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Write a Composer warning message when upgrading from < 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyc committed Apr 24, 2017
1 parent 0e44625 commit e738adf
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions composer/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<warning>'
. '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:'
. '</warning>'
);
$this->io->writeError('');
$this->io->writeError(json_encode(['extra' => ['drupalvm' => ['config_dir' => '<sub-directory>']]], 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;
}
}

0 comments on commit e738adf

Please sign in to comment.