Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
purge
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 configure
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
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\cache;
14
15use Symfony\Component\Console\Command\Command as symfony_command;
16use Symfony\Component\Console\Input\InputInterface;
17use Symfony\Component\Console\Output\OutputInterface;
18use Symfony\Component\Console\Style\SymfonyStyle;
19
20class purge extends \phpbb\console\command\command
21{
22    /** @var \phpbb\cache\driver\driver_interface */
23    protected $cache;
24
25    /** @var \phpbb\db\driver\driver_interface */
26    protected $db;
27
28    /** @var \phpbb\db\tools\tools_interface */
29    protected $db_tools;
30
31    /** @var \phpbb\auth\auth */
32    protected $auth;
33
34    /** @var \phpbb\log\log_interface */
35    protected $log;
36
37    /** @var \phpbb\config\config */
38    protected $config;
39
40    /**
41    * Constructor
42    *
43    * @param \phpbb\user                            $user    User instance
44    * @param \phpbb\cache\driver\driver_interface    $cache    Cache instance
45    * @param \phpbb\db\driver\driver_interface        $db        Database connection
46    * @param \phpbb\db\tools\tools_interface        $db_tools Database tools
47    * @param \phpbb\auth\auth                        $auth    Auth instance
48    * @param \phpbb\log\log_interface                $log    Logger instance
49    * @param \phpbb\config\config                    $config    Config instance
50    */
51    public function __construct(\phpbb\user $user, \phpbb\cache\driver\driver_interface $cache, \phpbb\db\driver\driver_interface $db,
52                                \phpbb\db\tools\tools_interface $db_tools, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\config\config $config)
53    {
54        $this->cache = $cache;
55        $this->db = $db;
56        $this->db_tools = $db_tools;
57        $this->auth = $auth;
58        $this->log = $log;
59        $this->config = $config;
60        parent::__construct($user);
61    }
62
63    /**
64    * {@inheritdoc}
65    */
66    protected function configure()
67    {
68        $this
69            ->setName('cache:purge')
70            ->setDescription($this->user->lang('PURGE_CACHE'))
71        ;
72    }
73
74    /**
75    * Executes the command cache:purge.
76    *
77    * Purge the cache (including permissions) and increment the asset_version number
78    *
79    * @param InputInterface  $input  An InputInterface instance
80    * @param OutputInterface $output An OutputInterface instance
81    *
82    * @return int
83    */
84    protected function execute(InputInterface $input, OutputInterface $output)
85    {
86        $this->config->increment('assets_version', 1);
87        $this->cache->purge();
88
89        // Clear permissions
90        $this->auth->acl_clear_prefetch();
91        phpbb_cache_moderators($this->db, $this->db_tools, $this->cache, $this->auth);
92
93        $this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array());
94
95        $io = new SymfonyStyle($input, $output);
96        $io->success($this->user->lang('PURGE_CACHE_SUCCESS'));
97
98        return symfony_command::SUCCESS;
99    }
100}