Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
install
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 configure
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\console\command\extension;
15
16use phpbb\composer\extension_manager;
17use phpbb\composer\io\console_io;
18use phpbb\language\language;
19use Symfony\Component\Console\Command\Command as symfony_command;
20use Symfony\Component\Console\Formatter\OutputFormatterStyle;
21use Symfony\Component\Console\Input\InputArgument;
22use Symfony\Component\Console\Input\InputInterface;
23use Symfony\Component\Console\Input\InputOption;
24use Symfony\Component\Console\Output\OutputInterface;
25use Symfony\Component\Console\Style\SymfonyStyle;
26
27class install extends \phpbb\console\command\command
28{
29    /**
30     * @var extension_manager Composer extensions manager
31     */
32    protected $manager;
33
34    /**
35     * @var language
36     */
37    protected $language;
38
39    public function __construct(\phpbb\user $user, extension_manager $manager, language $language)
40    {
41        $this->manager = $manager;
42        $this->language = $language;
43
44        $language->add_lang('acp/extensions');
45
46        parent::__construct($user);
47    }
48
49    /**
50    * Sets the command name and description
51    *
52    * @return void
53    */
54    protected function configure()
55    {
56        $this
57            ->setName('extension:install')
58            ->setDescription($this->language->lang('CLI_DESCRIPTION_EXTENSION_INSTALL'))
59            ->addOption(
60                'enable',
61                null,
62                InputOption::VALUE_NONE,
63                $this->language->lang('CLI_DESCRIPTION_EXTENSION_INSTALL_OPTION_ENABLE'))
64            ->addArgument(
65                'extensions',
66                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
67                $this->language->lang('CLI_DESCRIPTION_EXTENSION_INSTALL_ARGUMENT'))
68        ;
69    }
70
71    /**
72    * Executes the command extension:install
73    *
74    * @param InputInterface $input
75    * @param OutputInterface $output
76    * @return int
77    */
78    protected function execute(InputInterface $input, OutputInterface $output)
79    {
80        $output->getFormatter()->setStyle('warning', new OutputFormatterStyle('black', 'yellow'));
81
82        $io = new SymfonyStyle($input, $output);
83
84        if (!$this->manager->check_requirements())
85        {
86            $io->error($this->language->lang('EXTENSIONS_COMPOSER_NOT_WRITABLE'));
87            return symfony_command::FAILURE;
88        }
89
90        $composer_io = new console_io($input, $output, $this->getHelperSet(), $this->language);
91        $extensions = $input->getArgument('extensions');
92
93        if ($input->getOption('enable'))
94        {
95            $this->manager->set_enable_on_install(true);
96        }
97
98        $this->manager->install($extensions, $composer_io);
99
100        $io->success($this->language->lang('EXTENSIONS_INSTALLED'));
101
102        return symfony_command::SUCCESS;
103    }
104}