public function upgrade(OutputInterface $output, $doUpdate = false)
{
if ($doUpdate) {
$this->clearCache($output);
}
$allPlugins = $this->pluginsService->getAllAvailablePlugins();
$require = array();
$update = array();
foreach ($allPlugins as $key => $value) {
// work only with modern packages
if (strpos($value->getName(), '/') !== false) {
$require[] = $value->getName() . ' ' . $value->getVersion();
$update[] = $value->getName();
if ($doUpdate) {
$details = json_decode($value->getDetails(), true);
if (array_key_exists('targetDir', $details)) {
$filesystem = new Filesystem();
if (!is_writable($this->pluginsDir . $details['targetDir'] . '/')) {
throw new Exception("Plugins directory must be writable: " . $this->pluginsDir, 1);
}
$filesystem->remove($this->pluginsDir . $details['targetDir'] . '/');
}
}
}
}
$require = implode(' ', $require);
$update = implode(' ', $update);
if ($doUpdate) {
$doUpdate = ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar update ' . $update . ' ' . $this->dev;
}
$process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar require ' . $require . ' --no-update' . $doUpdate);
$output->writeln('<info>require ' . $require . ' --no-update</info>');
if ($doUpdate) {
$output->writeln('<info>update ' . $update . '</info>');
}
$process->setTimeout(3600);
$process->run(function ($type, $buffer) use($output) {
if ('err' === $type) {
$output->write('<error>' . $buffer . '</error>');
} else {
$output->write('<info>' . $buffer . '</info>');
}
});
if (!$process->isSuccessful()) {
throw new \Exception("Error with reverting plugins", 1);
}
$this->saveAvaiablePluginsToCacheFile();
if ($doUpdate) {
$this->clearCache($output);
}
}