/**
* Prompt the user to migrate from the legacy project file structure.
*
* If the input is interactive, the user will be asked to migrate up to once
* per hour. The time they were last asked will be stored in the project
* configuration. If the input is not interactive, the user will be warned
* (on every command run) that they should run the 'legacy-migrate' command.
*/
protected function promptLegacyMigrate()
{
static $asked = false;
if ($this->localProject->getLegacyProjectRoot() && $this->getName() !== 'legacy-migrate' && !$asked) {
$asked = true;
$projectRoot = $this->getProjectRoot();
$timestamp = time();
$promptMigrate = true;
if ($projectRoot) {
$projectConfig = $this->localProject->getProjectConfig($projectRoot);
if (isset($projectConfig['migrate']['3.x']['last_asked']) && $projectConfig['migrate']['3.x']['last_asked'] > $timestamp - 3600) {
$promptMigrate = false;
}
}
$this->stdErr->writeln('You are in a project using an old file structure, from previous versions of the ' . self::$config->get('application.name') . '.');
if ($this->input->isInteractive() && $promptMigrate) {
if ($projectRoot && isset($projectConfig)) {
$projectConfig['migrate']['3.x']['last_asked'] = $timestamp;
$this->localProject->writeCurrentProjectConfig($projectConfig, $projectRoot);
}
/** @var \Platformsh\Cli\Helper\QuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');
if ($questionHelper->confirm('Migrate to the new structure?')) {
$code = $this->runOtherCommand('legacy-migrate');
exit($code);
}
} else {
$this->stdErr->writeln('Fix this with: <comment>' . self::$config->get('application.executable') . ' legacy-migrate</comment>');
}
$this->stdErr->writeln('');
}
}