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

Commit e738adf

Browse files
committed
Write a Composer warning message when upgrading from < 5.0.0
1 parent 0e44625 commit e738adf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

composer/src/Plugin.php

+27
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,36 @@ public function addVagrantfile(Event $event) {
5757

5858
if (file_exists($source)) {
5959
if (!file_exists($target) || md5_file($source) != md5_file($target)) {
60+
$isLegacy = $this->isLegacy();
61+
6062
copy($source, $target);
63+
64+
$extra = $this->composer->getPackage()->getExtra();
65+
if ($isLegacy && !isset($extra['drupalvm']['config_dir'])) {
66+
$this->io->writeError(
67+
'<warning>'
68+
. 'Drupal VM has been updated and consquently written over your Vagrantfile which from now on will be managed by Drupal VM. '
69+
. 'Due to this change, you are now required to set your `config_dir` location in your composer.json file. Below follows the necessary change:'
70+
. '</warning>'
71+
);
72+
$this->io->writeError('');
73+
$this->io->writeError(json_encode(['extra' => ['drupalvm' => ['config_dir' => '<sub-directory>']]], JSON_PRETTY_PRINT));
74+
}
6175
}
6276
}
6377
}
6478

79+
/**
80+
* Return if the parent project is using the < 5.0.0 delegating Vagrantfile.
81+
*
82+
* @return bool
83+
*/
84+
private function isLegacy() {
85+
$baseDir = dirname(Factory::getComposerFile());
86+
$vagrantfile = $baseDir . '/Vagrantfile';
87+
if (!file_exists($vagrantfile)) {
88+
return false;
89+
}
90+
return strpos(file_get_contents($vagrantfile), '# Load the real Vagrantfile') !== FALSE;
91+
}
6592
}

0 commit comments

Comments
 (0)