Issues (31)

acp/dbtool_module.php (8 issues)

Labels
Severity
1
<?php
2
/**
3
 *
4
 * Database Optimize & Repair Tool
5
 *
6
 * @copyright (c) 2013 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\dbtool\acp;
12
13
/**
14
 * @package acp
15
 */
16
class dbtool_module
17
{
18
	/** @var \phpbb\db\driver\driver_interface */
0 ignored issues
show
The type phpbb\db\driver\driver_interface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
	protected $db;
20
21
	/** @var \phpbb\language\language */
0 ignored issues
show
The type phpbb\language\language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
	protected $language;
23
24
	/** @var \phpbb\request\request */
0 ignored issues
show
The type phpbb\request\request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
	protected $request;
26
27
	/** @var \phpbb\template\template */
0 ignored issues
show
The type phpbb\template\template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
	protected $template;
29
30
	/** @var \vse\dbtool\tool\tool_interface */
31
	protected $db_tool;
32
33
	/** @var string */
34
	public $page_title;
35
36
	/** @var string */
37
	public $tpl_name;
38
39
	/** @var string */
40
	public $u_action;
41
42
	/**
43
	 * Constructor
44
	 */
45
	public function __construct()
46
	{
47
		global $phpbb_container;
48
49
		try
50
		{
51
			$this->db       = $phpbb_container->get('dbal.conn');
52
			$this->language = $phpbb_container->get('language');
53
			$this->request  = $phpbb_container->get('request');
54
			$this->template = $phpbb_container->get('template');
55
			$this->db_tool  = $phpbb_container->get('vse.dbtool.tool');
56
		}
57
		catch (\Exception $e)
58
		{
59
			trigger_error($e->getMessage(), E_USER_WARNING);
60
		}
61
62
		$this->language->add_lang('dbtool_acp', 'vse/dbtool');
63
	}
64
65
	/**
66
	 * Main ACP module
67
	 *
68
	 * @access public
69
	 */
70
	public function main()
71
	{
72
		$this->tpl_name = 'acp_dbtool';
73
		$this->page_title = 'ACP_OPTIMIZE_REPAIR';
74
75
		if (!$this->db_tool->is_mysql())
76
		{
77
			trigger_error($this->language->lang('WARNING_MYSQL'), E_USER_WARNING);
78
		}
79
80
		if ($this->request->is_set_post('submit'))
81
		{
82
			$this->run_tool();
83
		}
84
85
		$this->display_tables();
86
	}
87
88
	/**
89
	 * Run database tool
90
	 *
91
	 * @access protected
92
	 */
93
	protected function run_tool()
94
	{
95
		$operation = strtoupper($this->request->variable('operation', ''));
96
		$tables = $this->request->variable('mark', ['']);
97
		$disable_board = $this->request->variable('disable_board', 0);
98
99
		if (confirm_box(true))
0 ignored issues
show
The function confirm_box was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
		if (/** @scrutinizer ignore-call */ confirm_box(true))
Loading history...
100
		{
101
			if (!count($tables))
102
			{
103
				trigger_error($this->language->lang('TABLE_ERROR') . adm_back_link($this->u_action), E_USER_WARNING);
0 ignored issues
show
The function adm_back_link was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
				trigger_error($this->language->lang('TABLE_ERROR') . /** @scrutinizer ignore-call */ adm_back_link($this->u_action), E_USER_WARNING);
Loading history...
104
			}
105
106
			if ($this->db_tool->is_valid_operation($operation))
107
			{
108
				$results = $this->db_tool->run($operation, $tables, $disable_board);
109
				$results = '<br>' . implode('<br>', $results);
110
				trigger_error($this->language->lang($operation . '_SUCCESS') . $results . adm_back_link($this->u_action));
111
			}
112
		}
113
		else
114
		{
115
			confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields([
0 ignored issues
show
The function build_hidden_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
			confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), /** @scrutinizer ignore-call */ build_hidden_fields([
Loading history...
116
				'submit'		=> 1,
117
				'operation'		=> $operation,
118
				'mark'			=> $tables,
119
				'disable_board'	=> $disable_board,
120
			]), 'confirm_dbtool.html');
121
		}
122
	}
123
124
	/**
125
	 * Generate Show Table Data
126
	 *
127
	 * @access protected
128
	 */
129
	protected function display_tables()
130
	{
131
		$table_data = [];
132
		$total_data_size = $total_data_free = 0;
133
134
		$tables = $this->db->sql_query('SHOW TABLE STATUS');
135
		while ($table = $this->db->sql_fetchrow($tables))
136
		{
137
			$table['Engine'] = (!empty($table['Type']) ? $table['Type'] : $table['Engine']);
138
			if (!$this->db_tool->is_valid_engine($table['Engine']))
139
			{
140
				continue;
141
			}
142
143
			// Data_free should always be 0 for InnoDB tables
144
			if ($this->db_tool->is_innodb($table['Engine']))
145
			{
146
				$table['Data_free'] = 0;
147
			}
148
149
			$data_size = $table['Data_length'] + $table['Index_length'];
150
			$total_data_size += $data_size;
151
			$total_data_free += $table['Data_free'];
152
153
			$table_data[] = [
154
				'TABLE_NAME'	=> $table['Name'],
155
				'TABLE_TYPE'	=> $table['Engine'],
156
				'DATA_SIZE'		=> get_formatted_filesize($data_size),
0 ignored issues
show
The function get_formatted_filesize was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

156
				'DATA_SIZE'		=> /** @scrutinizer ignore-call */ get_formatted_filesize($data_size),
Loading history...
157
				'DATA_FREE'		=> get_formatted_filesize($table['Data_free']),
158
				'S_OVERHEAD'	=> (bool) $table['Data_free'],
159
			];
160
		}
161
		$this->db->sql_freeresult($tables);
162
163
		$this->template->assign_vars([
164
			'TABLE_DATA'		=> $table_data,
165
			'TOTAL_DATA_SIZE'	=> get_formatted_filesize($total_data_size),
166
			'TOTAL_DATA_FREE'	=> get_formatted_filesize($total_data_free),
167
			'U_ACTION'			=> $this->u_action,
168
		]);
169
	}
170
}
171