public function removePlugin($pluginName, OutputInterface $output, $notify = true)
{
$this->installComposer();
$this->prepareCacheDir();
/*if (!$this->isInstalled($pluginName)) {
$output->writeln('<info>Plugin "'.$pluginName.'" is not installed yet</info>');
return;
}*/
$composerFile = $this->newsoopDir . 'composer.json';
$composerDefinitions = json_decode(file_get_contents($composerFile), true);
foreach ($composerDefinitions['require'] as $package => $version) {
if ($package == $pluginName) {
if ($notify) {
$process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' application/console plugins:dispatch ' . $pluginName . ' remove');
$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 remove event", 1);
}
}
$output->writeln('<info>Remove "' . $pluginName . '" from composer.json file</info>');
unset($composerDefinitions['require'][$package]);
file_put_contents($composerFile, \Newscoop\Gimme\Json::indent(json_encode($composerDefinitions)));
$process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar update ' . $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 removing plugin", 1);
}
}
}
$cachedPluginMeta = $this->newsoopDir . '/plugins/cache/uninstall_' . str_replace('/', '-', $pluginName) . '_package.json';
if (file_exists($cachedPluginMeta)) {
$pluginMeta = json_decode(file_get_contents($cachedPluginMeta), true);
$this->em->getRepository('Newscoop\\Entity\\Plugin')->removePlugin($pluginName);
// clear cache files
$filesystem = new Filesystem();
$filesystem->remove($cachedPluginMeta);
$filesystem->remove($this->pluginsDir . '/' . $pluginMeta['targetDir'] . '/');
}
$this->saveAvaiablePluginsToCacheFile();
$this->clearCache($output);
$output->writeln('<info>Plugin ' . $pluginName . ' is removed!</info>');
}