Newscoop\Services\Plugins\ManagerService::installPlugin PHP Method

installPlugin() public method

Install plugin inside Newscoop - it's a wrapper for all tasks connected with plugin installation
public installPlugin ( string $pluginName, string $version, Symfony\Component\Console\Output\OutputInterface $output, boolean $notify = true )
$pluginName string
$version string
$output Symfony\Component\Console\Output\OutputInterface
$notify boolean
    public function installPlugin($pluginName, $version, $output, $notify = true)
    {
        $this->installComposer();
        $this->prepareCacheDir();
        $pluginMeta = explode('/', $pluginName);
        if (count($pluginMeta) !== 2) {
            throw new \Exception("Plugin name is invalid, try \"vendor/plugin-name\"", 1);
        }
        $process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar require --no-update ' . $pluginName . ':' . $version . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' composer.phar update ' . $pluginName . '  --prefer-dist ' . $this->dev . ' -n');
        $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 installing plugin", 1);
        }
        $cachedPluginMeta = $this->newsoopDir . '/plugins/cache/add_' . str_replace('/', '-', $pluginName) . '_package.json';
        if (file_exists($cachedPluginMeta)) {
            $pluginMeta = json_decode(file_get_contents($cachedPluginMeta), true);
            $pluginDetails = file_get_contents($this->pluginsDir . '/' . $pluginMeta['targetDir'] . '/composer.json');
            $this->em->getRepository('Newscoop\\Entity\\Plugin')->addPlugin($pluginMeta, $pluginDetails);
            // clear cache files
            $filesystem = new Filesystem();
            $filesystem->remove($cachedPluginMeta);
        }
        $this->saveAvaiablePluginsToCacheFile();
        $this->clearCache($output);
        if ($notify) {
            $process = new Process('cd ' . $this->newsoopDir . ' && php -d memory_limit=' . $this->config['internal_memory_limit'] . ' application/console plugins:dispatch ' . $pluginName . ' install');
            $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 install event", 1);
            }
        }
        $output->writeln('<info>Plugin ' . $pluginName . ' is installed!</info>');
    }