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 432f19b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions composer/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<warning>'
. '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:'
. '</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 isLegacyVagrantfile($vagrantfile) {
if (!file_exists($vagrantfile)) {
return false;
}
return strpos(file_get_contents($vagrantfile), '# Load the real Vagrantfile') !== FALSE;
}
}

0 comments on commit 432f19b

Please sign in to comment.