Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
enable
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 2
72
0.00% covered (danger)
0.00%
0 / 1
 configure
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
56
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*/
13namespace phpbb\console\command\extension;
14
15use Symfony\Component\Console\Command\Command as symfony_command;
16use Symfony\Component\Console\Input\InputArgument;
17use Symfony\Component\Console\Input\InputInterface;
18use Symfony\Component\Console\Output\OutputInterface;
19use Symfony\Component\Console\Style\SymfonyStyle;
20
21class enable extends command
22{
23    /**
24     * {@inheritdoc}
25     */
26    protected function configure()
27    {
28        $this
29            ->setName('extension:enable')
30            ->setDescription($this->user->lang('CLI_DESCRIPTION_ENABLE_EXTENSION'))
31            ->addArgument(
32                'extension-name',
33                InputArgument::REQUIRED,
34                $this->user->lang('CLI_EXTENSION_NAME')
35            )
36        ;
37    }
38
39    /**
40     * Executes the command extension:enable.
41     *
42     * Enables the specified extension
43     *
44     * @param InputInterface  $input  An InputInterface instance
45     * @param OutputInterface $output An OutputInterface instance
46     *
47     * @return int
48     */
49    protected function execute(InputInterface $input, OutputInterface $output)
50    {
51        $io = new SymfonyStyle($input, $output);
52
53        $name = $input->getArgument('extension-name');
54
55        if (!$this->manager->is_available($name))
56        {
57            $io->error($this->user->lang('CLI_EXTENSION_NOT_EXIST', $name));
58            return symfony_command::FAILURE;
59        }
60
61        $extension = $this->manager->get_extension($name);
62
63        if (($enableable = $extension->is_enableable()) !== true)
64        {
65            $message = !empty($enableable) ? $enableable : $this->user->lang('CLI_EXTENSION_NOT_ENABLEABLE', $name);
66            $message = is_array($message) ? implode(PHP_EOL, $message) : $message;
67            $io->error($message);
68            return symfony_command::FAILURE;
69        }
70
71        if ($this->manager->is_enabled($name))
72        {
73            $io->error($this->user->lang('CLI_EXTENSION_ENABLED', $name));
74            return symfony_command::FAILURE;
75        }
76
77        $this->manager->enable($name);
78        $this->manager->load_extensions();
79
80        if ($this->manager->is_enabled($name))
81        {
82            $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($name));
83            $this->check_apcu_cache($io);
84            $io->success($this->user->lang('CLI_EXTENSION_ENABLE_SUCCESS', $name));
85            return symfony_command::SUCCESS;
86        }
87        else
88        {
89            $io->error($this->user->lang('CLI_EXTENSION_ENABLE_FAILURE', $name));
90            return symfony_command::FAILURE;
91        }
92    }
93}