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