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 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
set_up_database
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 check_requirements
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 run
0.00% covered (danger)
0.00%
0 / 11
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_database\task;
15
16use phpbb\filesystem\filesystem_interface;
17use phpbb\install\database_task;
18use phpbb\install\helper\config;
19use phpbb\install\helper\database;
20use phpbb\install\helper\iohandler\iohandler_interface;
21
22/**
23 * Set up database for table generation
24 */
25class set_up_database extends database_task
26{
27    /**
28     * @var config
29     */
30    protected $config;
31
32    /**
33     * @var database
34     */
35    protected $database_helper;
36
37    /**
38     * @var filesystem_interface
39     */
40    protected $filesystem;
41
42    /**
43     * @var string
44     */
45    protected $schema_file_path;
46
47    /**
48     * @var string
49     */
50    protected $phpbb_root_path;
51
52    /**
53     * Constructor
54     *
55     * @param config                $config
56     * @param database                $db_helper
57     * @param filesystem_interface    $filesystem
58     * @param iohandler_interface    $iohandler
59     * @param string                $phpbb_root_path
60     */
61    public function __construct(config $config,
62                                database $db_helper,
63                                filesystem_interface $filesystem,
64                                iohandler_interface $iohandler,
65                                string $phpbb_root_path)
66    {
67        $this->config            = $config;
68        $this->database_helper    = $db_helper;
69        $this->filesystem        = $filesystem;
70        $this->phpbb_root_path    = $phpbb_root_path;
71
72        parent::__construct(
73            self::get_doctrine_connection($db_helper, $config),
74            $iohandler,
75            false
76        );
77    }
78
79    /**
80     * {@inheritdoc}
81     */
82    public function check_requirements() : bool
83    {
84        $dbms = $this->config->get('dbms');
85        $dbms_info = $this->database_helper->get_available_dbms($dbms);
86        $schema_name = $dbms_info[$dbms]['SCHEMA'];
87
88        if ($dbms === 'mysql')
89        {
90            $schema_name .= '_41';
91        }
92
93        $this->schema_file_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
94
95        return $this->filesystem->exists($this->schema_file_path);
96    }
97
98    /**
99     * {@inheritdoc}
100     */
101    public function run()
102    {
103        $dbms = $this->config->get('dbms');
104        $dbms_info = $this->database_helper->get_available_dbms($dbms);
105        $delimiter = $dbms_info[$dbms]['DELIM'];
106        $table_prefix = $this->config->get('table_prefix');
107
108        $sql_query = @file_get_contents($this->schema_file_path);
109        $sql_query = str_replace('phpbb_', ' ' . $table_prefix, $sql_query);
110        $sql_query = $this->database_helper->remove_comments($sql_query);
111        $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
112
113        foreach ($sql_query as $sql)
114        {
115            $this->exec_sql($sql);
116        }
117
118        unset($sql_query);
119    }
120
121    /**
122     * {@inheritdoc}
123     */
124    public static function get_step_count() : int
125    {
126        return 1;
127    }
128
129    /**
130     * {@inheritdoc}
131     */
132    public function get_task_lang_name() : string
133    {
134        return 'TASK_SETUP_DATABASE';
135    }
136}