Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
notify_user
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
6
 get_step_count
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_task_lang_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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\install\module\install_finish\task;
15
16use phpbb\config\db;
17
18/**
19 * Logs installation and sends an email to the admin
20 */
21class notify_user extends \phpbb\install\task_base
22{
23    /**
24     * @var \phpbb\install\helper\config
25     */
26    protected $install_config;
27
28    /**
29     * @var \phpbb\install\helper\iohandler\iohandler_interface
30     */
31    protected $iohandler;
32
33    /**
34     * @var \phpbb\auth\auth
35     */
36    protected $auth;
37
38    /**
39     * @var db
40     */
41    protected $config;
42
43    /**
44     * @var \phpbb\log\log_interface
45     */
46    protected $log;
47
48    /**
49     * @var \phpbb\user
50     */
51    protected $user;
52
53    /**
54     * @var string
55     */
56    protected $phpbb_root_path;
57
58    /**
59     * @var string
60     */
61    protected $php_ext;
62
63    /**
64     * Constructor
65     *
66     * @param \phpbb\install\helper\container_factory                $container
67     * @param \phpbb\install\helper\config                            $install_config
68     * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler
69     * @param string                                                $phpbb_root_path
70     * @param string                                                $php_ext
71     */
72    public function __construct(\phpbb\install\helper\container_factory $container, \phpbb\install\helper\config $install_config, \phpbb\install\helper\iohandler\iohandler_interface $iohandler, $phpbb_root_path, $php_ext)
73    {
74        $this->install_config    = $install_config;
75        $this->iohandler        = $iohandler;
76
77        $this->auth                = $container->get('auth');
78        $this->log                = $container->get('log');
79        $this->user                = $container->get('user');
80        $this->phpbb_root_path    = $phpbb_root_path;
81        $this->php_ext            = $php_ext;
82
83        // We need to reload config for cases when it doesn't have all values
84        /** @var \phpbb\cache\driver\driver_interface $cache */
85        $cache = $container->get('cache.driver');
86        $cache->destroy('config');
87
88        $this->config = new db(
89            $container->get('dbal.conn'),
90            $cache,
91            $container->get_parameter('tables.config')
92        );
93
94        global $config;
95        $config = $this->config;
96
97        parent::__construct(true);
98    }
99
100    /**
101     * {@inheritdoc}
102     */
103    public function run()
104    {
105        $this->user->session_begin();
106        $this->user->setup('common');
107
108        if ($this->config['email_enable'])
109        {
110            include ($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
111
112            $messenger = new \messenger(false);
113            $messenger->template('installed', $this->install_config->get('user_language', 'en'));
114            $messenger->to($this->config['board_email'], $this->install_config->get('admin_name'));
115            $messenger->anti_abuse_headers($this->config, $this->user);
116            $messenger->assign_vars(array(
117                    'USERNAME'        => html_entity_decode($this->install_config->get('admin_name'), ENT_COMPAT),
118                    'PASSWORD'        => html_entity_decode($this->install_config->get('admin_passwd'), ENT_COMPAT))
119            );
120            $messenger->send(NOTIFY_EMAIL);
121        }
122
123        // Login admin
124        // Ugly but works
125        $this->auth->login(
126            $this->install_config->get('admin_name'),
127            $this->install_config->get('admin_passwd'),
128            false,
129            true,
130            true
131        );
132
133        $this->iohandler->set_cookie($this->config['cookie_name'] . '_sid', $this->user->session_id);
134        $this->iohandler->set_cookie($this->config['cookie_name'] . '_u', $this->user->cookie_data['u']);
135        $this->iohandler->set_cookie($this->config['cookie_name'] . '_k', $this->user->cookie_data['k']);
136
137        // Create log
138        $this->log->add(
139            'admin',
140            $this->user->data['user_id'],
141            $this->user->ip,
142            'LOG_INSTALL_INSTALLED',
143            false,
144            array($this->config['version'])
145        );
146
147        // Remove install_lock
148        @unlink($this->phpbb_root_path . 'cache/install_lock');
149    }
150
151    /**
152     * {@inheritdoc}
153     */
154    public static function get_step_count()
155    {
156        return 1;
157    }
158
159    /**
160     * {@inheritdoc}
161     */
162    public function get_task_lang_name()
163    {
164        return 'TASK_NOTIFY_USER';
165    }
166}