public function updatePlugin($pluginName, $version, OutputInterface $output, $notify = true)
{
$this->installComposer();
$output->writeln('<info>Update "' . $pluginName . '"</info>');
sleep(10);
$process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar update --prefer-dist' . $this->dev . ' ' . $pluginName);
$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 updating plugin", 1);
}
$this->saveAvaiablePluginsToCacheFile();
$this->clearCache($output);
$this->prepareCacheDir();
if ($notify) {
$process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' application/console plugins:dispatch ' . $pluginName . ' update');
$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 dispatching update event", 1);
}
}
$cachedPluginMeta = $this->newsoopDir . '/plugins/cache/update_' . str_replace('/', '-', $pluginName) . '_package.json';
if (file_exists($cachedPluginMeta)) {
$pluginMeta = json_decode(file_get_contents($cachedPluginMeta), true);
$pluginDetails = file_get_contents($this->pluginsDir . '/' . $pluginMeta['target']['targetDir'] . '/composer.json');
$this->em->getRepository('Newscoop\\Entity\\Plugin')->updatePlugin($pluginMeta['target'], $pluginDetails);
// clear cache files
$filesystem = new Filesystem();
$filesystem->remove($cachedPluginMeta);
}
$output->writeln('<info>Plugin ' . $pluginName . ' is updated!</info>');
}