Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
add_languages | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
execute_step | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
get_step_count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_task_lang_name | |
0.00% |
0 / 1 |
|
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 | |
14 | namespace phpbb\install\module\install_data\task; |
15 | |
16 | use Doctrine\DBAL\Driver\Statement as DriverStatement; |
17 | use Doctrine\DBAL\Statement; |
18 | use phpbb\install\database_task; |
19 | use phpbb\install\helper\config; |
20 | use phpbb\install\helper\container_factory; |
21 | use phpbb\install\helper\database; |
22 | use phpbb\install\helper\iohandler\iohandler_interface; |
23 | use phpbb\install\sequential_task; |
24 | use phpbb\language\language_file_helper; |
25 | |
26 | class add_languages extends database_task |
27 | { |
28 | use sequential_task; |
29 | |
30 | /** |
31 | * @var config |
32 | */ |
33 | protected $config; |
34 | |
35 | /** |
36 | * @var iohandler_interface |
37 | */ |
38 | protected $iohandler; |
39 | |
40 | /** |
41 | * @var language_file_helper |
42 | */ |
43 | protected $language_helper; |
44 | |
45 | /** |
46 | * @var string |
47 | */ |
48 | protected $lang_table; |
49 | |
50 | /** |
51 | * @var DriverStatement|Statement |
52 | */ |
53 | protected $stmt; |
54 | |
55 | /** |
56 | * Constructor |
57 | * |
58 | * @param config $config Installer config. |
59 | * @param database $db_helper Database helper. |
60 | * @param iohandler_interface $iohandler Installer's input-output handler |
61 | * @param container_factory $container Installer's DI container |
62 | * @param language_file_helper $language_helper Language file helper service |
63 | */ |
64 | public function __construct(config $config, |
65 | database $db_helper, |
66 | iohandler_interface $iohandler, |
67 | container_factory $container, |
68 | language_file_helper $language_helper) |
69 | { |
70 | $this->config = $config; |
71 | $this->iohandler = $iohandler; |
72 | $this->language_helper = $language_helper; |
73 | $this->lang_table = $container->get_parameter('tables.lang'); |
74 | |
75 | parent::__construct(self::get_doctrine_connection($db_helper, $config), $this->iohandler,true); |
76 | } |
77 | |
78 | /** |
79 | * {@inheritdoc} |
80 | */ |
81 | public function run() |
82 | { |
83 | $languages = $this->language_helper->get_available_languages(); |
84 | $sql = 'INSERT INTO ' . $this->lang_table |
85 | . ' (lang_iso, lang_dir, lang_english_name, lang_local_name, lang_author)' |
86 | . ' VALUES (:lang_iso, :lang_dir, :lang_english_name, :lang_local_name, :lang_author)'; |
87 | $this->stmt = $this->create_prepared_stmt($sql); |
88 | $this->execute($this->config, $languages); |
89 | } |
90 | |
91 | /** |
92 | * {@inheritdoc} |
93 | */ |
94 | protected function execute_step($key, $value) : void |
95 | { |
96 | $this->exec_prepared_stmt($this->stmt, [ |
97 | 'lang_iso' => $value['iso'], |
98 | 'lang_dir' => $value['iso'], |
99 | 'lang_english_name' => htmlspecialchars($value['name'], ENT_COMPAT), |
100 | 'lang_local_name' => htmlspecialchars($value['local_name'], ENT_COMPAT, 'UTF-8'), |
101 | 'lang_author' => htmlspecialchars($value['author'], ENT_COMPAT, 'UTF-8'), |
102 | ]); |
103 | |
104 | $installed_languages = $this->config->get('installed_languages', []); |
105 | $installed_languages[] = (int) $this->get_last_insert_id(); |
106 | $this->config->set('installed_languages', $installed_languages); |
107 | } |
108 | |
109 | /** |
110 | * {@inheritdoc} |
111 | */ |
112 | public static function get_step_count() : int |
113 | { |
114 | return 1; |
115 | } |
116 | |
117 | /** |
118 | * {@inheritdoc} |
119 | */ |
120 | public function get_task_lang_name() : string |
121 | { |
122 | return 'TASK_ADD_LANGUAGES'; |
123 | } |
124 | } |