aboutsummaryrefslogtreecommitdiff
path: root/cli/Commands/Plugins/PluginActivate.php
blob: df5763593fab6dca53ff6c029523c5b9e456b738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

namespace Studip\Cli\Commands\Plugins;

use Studip\Cli\Commands\AbstractPluginCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class PluginActivate extends AbstractPluginCommand
{
    protected static $defaultName = 'plugin:activate';

    protected function configure(): void
    {
        $this->setDescription('Activate a plugin.');
        $this->setHelp('This command activates a plugin.');
        $this->addArgument('pluginname', InputArgument::REQUIRED, 'name of the plugin');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $pluginname = $input->getArgument('pluginname');

        $pluginManager = \PluginManager::getInstance();
        $plugin = $this->findPluginByName($pluginManager, $pluginname);
        if (null === $plugin) {
            $output->writeln('<error>Could not find plugin of that name.</error>');

            return Command::FAILURE;
        }

        $pluginManager->setPluginEnabled($plugin['id'], true);
        $output->writeln('Plugin activated.');

        return Command::SUCCESS;
    }
}