Passed
Pull Request — master (#1301)
by Michael
05:31
created

SystemMaintenance   F

Complexity

Total Complexity 62

Size/Duplication

Total Lines 400
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 201
dl 0
loc 400
rs 3.44
c 1
b 0
f 0
wmc 62

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A dump_tables() 0 20 3
A CleanAvatar() 0 18 3
A clearDirectory() 0 12 5
C CheckRepairAnalyzeOptimizeQueries() 0 63 15
A displayTables() 0 17 4
A CleanCache() 0 19 5
B dump_modules() 0 32 6
A CleanSession() 0 5 1
B dump_table_datas() 0 60 11
A dump_write() 0 11 2
A dump_table_structure() 0 24 6

How to fix   Complexity   

Complex Class

Complex classes like SystemMaintenance often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SystemMaintenance, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Maintenance class manager
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @author              Cointin Maxime (AKA Kraven30)
15
 * @package             system
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
19
20
/**
21
 * System Maintenance
22
 *
23
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
24
 * @package             system
25
 */
26
class SystemMaintenance
27
{
28
    public $db;
29
    public $prefix;
30
31
    /**
32
     * Constructor
33
     */
34
    public function __construct()
35
    {
36
        /* @var XoopsMySQLDatabase $db */
37
        $db           = XoopsDatabaseFactory::getDatabaseConnection();
38
        $this->db     = $db;
39
        $this->prefix = $this->db->prefix . '_';
40
    }
41
42
    /**
43
     * Display Tables
44
     *
45
     * @param bool $array
46
     *
47
     * @internal param $array
48
     * @return array|string
49
     */
50
    public function displayTables($array = true)
51
    {
52
        $tables = array();
53
        $sql = 'SHOW TABLES';
54
        $result = $this->db->queryF($sql);
55
        if (!$this->db->isResultSet($result)) {
56
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
57
        }
58
        while (false !== ($myrow = $this->db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

58
        while (false !== ($myrow = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
59
            $value          = array_values($myrow);
60
            $value          = substr($value[0], strlen(XOOPS_DB_PREFIX) + 1);
61
            $tables[$value] = $value;
62
        }
63
        if (true === (bool) $array) {
64
            return $tables;
65
        } else {
66
            return implode(',', $tables);
67
        }
68
    }
69
70
    /**
71
     * Clear sessions
72
     *
73
     * @return bool
74
     */
75
    public function CleanSession()
76
    {
77
        $result = $this->db->queryF('TRUNCATE TABLE ' . $this->db->prefix('session'));
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
78
79
        return true;
80
    }
81
82
    /**
83
     * CleanAvatar
84
     *
85
     * Clean up orphaned custom avatars left when a user is deleted.
86
     *
87
     * @author slider84 of Team FrXoops
88
     *
89
     * @return boolean
90
     */
91
    public function CleanAvatar()
92
    {
93
        $sql = 'SELECT avatar_id, avatar_file FROM ' . $this->db->prefix('avatar') . " WHERE avatar_type='C' AND avatar_id IN (" . 'SELECT t1.avatar_id FROM ' . $this->db->prefix('avatar_user_link') . ' AS t1 ' . 'LEFT JOIN ' . $this->db->prefix('users') . ' AS t2 ON t2.uid=t1.user_id ' . 'WHERE t2.uid IS NULL)';
94
        $result = $this->db->queryF($sql);
95
        if (!$this->db->isResultSet($result)) {
96
            \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
97
        }
98
99
        while (false !== ($myrow = $this->db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

99
        while (false !== ($myrow = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
100
            //delete file
101
            @unlink(XOOPS_UPLOAD_PATH . '/' . $myrow['avatar_file']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

101
            /** @scrutinizer ignore-unhandled */ @unlink(XOOPS_UPLOAD_PATH . '/' . $myrow['avatar_file']);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
102
            //clean avatar table
103
            $result1 = $this->db->queryF('DELETE FROM ' . $this->db->prefix('avatar') . ' WHERE avatar_id=' . $myrow['avatar_id']);
0 ignored issues
show
Unused Code introduced by
The assignment to $result1 is dead and can be removed.
Loading history...
104
        }
105
        //clean any deleted users from avatar_user_link table
106
        $result2 = $this->db->queryF('DELETE FROM ' . $this->db->prefix('avatar_user_link') . ' WHERE user_id NOT IN (SELECT uid FROM ' . $this->db->prefix('users') . ')');
0 ignored issues
show
Unused Code introduced by
The assignment to $result2 is dead and can be removed.
Loading history...
107
108
        return true;
109
    }
110
111
    /**
112
     * Delete all files in a directory
113
     *
114
     * @param string $dir directory to clear
115
     *
116
     * @return void
117
     */
118
    protected function clearDirectory($dir)
119
    {
120
        if (is_dir($dir)) {
121
            if ($dirHandle = opendir($dir)) {
122
                while (($file = readdir($dirHandle)) !== false) {
123
                    if (filetype($dir . $file) === 'file') {
124
                        unlink($dir . $file);
125
                    }
126
                }
127
                closedir($dirHandle);
128
            }
129
			file_put_contents($dir . 'index.php', '<?php' . PHP_EOL  . 'header("HTTP/1.0 404 Not Found");' . PHP_EOL);
130
        }
131
    }
132
133
    /**
134
     * Clean cache 'xoops_data/caches/smarty_cache'
135
     *
136
     * @param array $cacheList int[] of cache "ids"
137
     *                         1 = smarty cache
138
     *                         2 = smarty compile
139
     *                         3 = xoops cache
140
     * @return bool
141
     */
142
    public function CleanCache($cacheList)
143
    {
144
        foreach ($cacheList as $cache) {
145
            switch ($cache) {
146
                case 1:
147
                    $this->clearDirectory(XOOPS_VAR_PATH . '/caches/smarty_cache/');
148
                    break;
149
                case 2:
150
                    $this->clearDirectory(XOOPS_VAR_PATH . '/caches/smarty_compile/');
151
                    break;
152
                case 3:
153
                    $this->clearDirectory(XOOPS_VAR_PATH . '/caches/xoops_cache/');
154
                    break;
155
                default:
156
                    return false;
157
            }
158
        }
159
160
        return true;
161
    }
162
163
    /**
164
     * Maintenance database
165
     *
166
     * @param array tables 'list of tables'
167
     * @param array maintenance 'optimize, check, repair, analyze'
0 ignored issues
show
Bug introduced by
The type maintenance 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...
168
     * @return array
169
     */
170
    public function CheckRepairAnalyzeOptimizeQueries($tables, $maintenance)
171
    {
172
        $ret = '<table class="outer"><th>' . _AM_SYSTEM_MAINTENANCE_TABLES1 . '</th><th>' . _AM_SYSTEM_MAINTENANCE_TABLES_OPTIMIZE . '</th><th>' . _AM_SYSTEM_MAINTENANCE_TABLES_CHECK . '</th><th>' . _AM_SYSTEM_MAINTENANCE_TABLES_REPAIR . '</th><th>' . _AM_SYSTEM_MAINTENANCE_TABLES_ANALYZE . '</th>';
173
        $tab = array();
174
        for ($i = 0; $i < 4; ++$i) {
175
            $tab[$i] = $i + 1;
176
        }
177
        $tab1 = array();
178
        for ($i = 0; $i < 4; ++$i) {
179
            if (in_array($tab[$i], $maintenance)) {
180
                $tab1[$i] = $tab[$i];
181
            } else {
182
                $tab1[$i] = '0';
183
            }
184
        }
185
        unset($tab);
186
        $class       = 'odd';
187
        $tablesCount = count($tables);
188
        for ($i = 0; $i < $tablesCount; ++$i) {
189
            $ret .= '<tr class="' . $class . '"><td align="center">' . $this->prefix . $tables[$i] . '</td>';
190
            for ($j = 0; $j < 4; ++$j) {
191
                if ($tab1[$j] == 1) {
192
                    // Optimize
193
                    $result = $this->db->queryF('OPTIMIZE TABLE ' . $this->prefix . $tables[$i]);
194
                    if ($result) {
195
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('success.png') . '" /></td>';
196
                    } else {
197
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('cancel.png') . '" /></td>';
198
                    }
199
                } elseif ($tab1[$j] == 2) {
200
                    // Check tables
201
                    $result = $this->db->queryF('CHECK TABLE ' . $this->prefix . $tables[$i]);
202
                    if ($result) {
203
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('success.png') . '" /></td>';
204
                    } else {
205
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('cancel.png') . '" /></td>';
206
                    }
207
                } elseif ($tab1[$j] == 3) {
208
                    // Repair
209
                    $result = $this->db->queryF('REPAIR TABLE ' . $this->prefix . $tables[$i]);
210
                    if ($result) {
211
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('success.png') . '" /></td>';
212
                    } else {
213
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('cancel.png') . '" /></td>';
214
                    }
215
                } elseif ($tab1[$j] == 4) {
216
                    // Analyze
217
                    $result = $this->db->queryF('ANALYZE TABLE ' . $this->prefix . $tables[$i]);
218
                    if ($result) {
219
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('success.png') . '" /></td>';
220
                    } else {
221
                        $ret .= '<td class="xo-actions txtcenter"><img src="' . system_AdminIcons('cancel.png') . '" /></td>';
222
                    }
223
                } else {
224
                    $ret .= '<td>&nbsp;</td>';
225
                }
226
            }
227
            $ret .= '</tr>';
228
            $class = ($class === 'even') ? 'odd' : 'even';
229
        }
230
        $ret .= '</table>';
231
232
        return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type string which is incompatible with the documented return type array.
Loading history...
233
    }
234
235
    /**
236
     * Dump by tables
237
     *
238
     * @param array tables 'list of tables'
0 ignored issues
show
Bug introduced by
The type tables 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...
239
     * @param int   drop
0 ignored issues
show
Bug introduced by
The type drop 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...
240
     * @return array 'ret[0] = dump, ret[1] = display result
241
     */
242
    public function dump_tables($tables, $drop)
243
    {
244
        $ret    = array();
245
        $ret[0] = "# \n";
246
        $ret[0] .= "# Dump SQL, Generate by Xoops \n";
247
        $ret[0] .= '# Date : ' . date('d-m-Y - H:i') . " \n";
248
        $ret[1]      = '<table class="outer"><tr><th width="30%">' . _AM_SYSTEM_MAINTENANCE_DUMP_TABLES . '</th><th width="35%">' . _AM_SYSTEM_MAINTENANCE_DUMP_STRUCTURES . '</th><th  width="35%">' . _AM_SYSTEM_MAINTENANCE_DUMP_NB_RECORDS . '</th></tr>';
249
        $class       = 'odd';
250
        $tablesCount = count($tables);
251
        for ($i = 0; $i < $tablesCount; ++$i) {
252
            //structure
253
            $ret = $this->dump_table_structure($ret, $this->prefix . $tables[$i], $drop, $class);
254
            //data
255
            $ret   = $this->dump_table_datas($ret, $this->prefix . $tables[$i]);
256
            $class = ($class === 'even') ? 'odd' : 'even';
257
        }
258
        $ret = $this->dump_write($ret);
259
        $ret[1] .= '</table>';
260
261
        return $ret;
262
    }
263
264
    /**
265
     * Dump by modules
266
     *
267
     * @param array modules 'list of modules'
0 ignored issues
show
Bug introduced by
The type modules 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...
268
     * @param int   drop
269
     * @return array 'ret[0] = dump, ret[1] = display result
270
     */
271
    public function dump_modules($modules, $drop)
272
    {
273
        $ret    = array();
274
        $ret[0] = "# \n";
275
        $ret[0] .= "# Dump SQL, Generate by Xoops \n";
276
        $ret[0] .= '# Date : ' . date('d-m-Y - H:i') . " \n";
277
        $ret[0] .= "# \n\n";
278
        $ret[1]       = '<table class="outer"><tr><th width="30%">' . _AM_SYSTEM_MAINTENANCE_DUMP_TABLES . '</th><th width="35%">' . _AM_SYSTEM_MAINTENANCE_DUMP_STRUCTURES . '</th><th  width="35%">' . _AM_SYSTEM_MAINTENANCE_DUMP_NB_RECORDS . '</th></tr>';
279
        $class        = 'odd';
280
        $modulesCount = count($modules);
281
        for ($i = 0; $i < $modulesCount; ++$i) {
282
            /* @var XoopsModuleHandler $module_handler */
283
            $module_handler = xoops_getHandler('module');
284
            $module         = $module_handler->getByDirname($modules[$i]);
285
            $ret[1] .= '<tr><th colspan="3" align="left">' . ucfirst($modules[$i]) . '</th></tr>';
286
            $modtables = $module->getInfo('tables');
287
            if ($modtables !== false && is_array($modtables)) {
288
                foreach ($modtables as $table) {
289
                    //structure
290
                    $ret = $this->dump_table_structure($ret, $this->prefix . $table, $drop, $class);
291
                    //data
292
                    $ret   = $this->dump_table_datas($ret, $this->prefix . $table);
293
                    $class = ($class === 'even') ? 'odd' : 'even';
294
                }
295
            } else {
296
                $ret[1] .= '<tr><td colspan="3" align="center">' . _AM_SYSTEM_MAINTENANCE_DUMP_NO_TABLES . '</td></tr>';
297
            }
298
        }
299
        $ret[1] .= '</table>';
300
        $ret = $this->dump_write($ret);
301
302
        return $ret;
303
    }
304
305
    /**
306
     * Dump table structure
307
     *
308
     * @param array
309
     * @param string table
310
     * @param int    drop
311
     * @param string class
312
     * @return array 'ret[0] = dump, ret[1] = display result
313
     */
314
    public function dump_table_structure($ret, $table, $drop, $class)
315
    {
316
        $verif  = false;
317
        $sql = 'SHOW create table `' . $table . '`;';
318
        $result = $this->db->queryF($sql);
319
        if ($this->db->isResultSet($result)) {
320
            if ($row = $this->db->fetchArray($result)) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

320
            if ($row = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result)) {
Loading history...
321
                $ret[0] .= '# Table structure for table `' . $table . "` \n\n";
322
                if ($drop == 1) {
323
                    $ret[0] .= 'DROP TABLE IF EXISTS `' . $table . "`;\n\n";
324
                }
325
                $verif = true;
326
                $ret[0] .= $row['Create Table'] . ";\n\n";
327
            }
328
        }
329
330
        $ret[1] .= '<tr class="' . $class . '"><td align="center">' . $table . '</td><td class="xo-actions txtcenter">';
331
        $ret[1] .= ($verif === true) ? '<img src="' . system_AdminIcons('success.png') . '" />' : '<img src="' . system_AdminIcons('cancel.png') . '" />';
332
        $ret[1] .= '</td>';
333
        if ($this->db->isResultSet($result)) {
334
            $this->db->freeRecordSet($result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::freeRecordSet() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

334
            $this->db->freeRecordSet(/** @scrutinizer ignore-type */ $result);
Loading history...
335
        }
336
337
        return $ret;
338
    }
339
340
    /**
341
     * Dump table data
342
     *
343
     * @param array
344
     * @param string table
0 ignored issues
show
Bug introduced by
The type table 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...
345
     * @return array 'ret[0] = dump, ret[1] = display result
346
     */
347
    public function dump_table_datas($ret, $table)
348
    {
349
        $count  = 0;
350
        $sql = 'SELECT * FROM ' . $table . ';';
351
        $result = $this->db->queryF($sql);
352
        if ($this->db->isResultSet($result)) {
353
            $num_rows   = $this->db->getRowsNum($result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::getRowsNum() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

353
            $num_rows   = $this->db->getRowsNum(/** @scrutinizer ignore-type */ $result);
Loading history...
354
            $num_fields = $this->db->getFieldsNum($result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::getFieldsNum() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

354
            $num_fields = $this->db->getFieldsNum(/** @scrutinizer ignore-type */ $result);
Loading history...
355
356
            if ($num_rows > 0) {
357
                $field_type = array();
358
                $i          = 0;
359
                while ($i < $num_fields) {
360
                    $meta = mysqli_fetch_field($result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of mysqli_fetch_field() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

360
                    $meta = mysqli_fetch_field(/** @scrutinizer ignore-type */ $result);
Loading history...
361
                    $field_type[] = $meta->type;
362
                    ++$i;
363
                }
364
365
                $ret[0] .= 'INSERT INTO `' . $table . "` values\n";
366
                $index = 0;
367
                while ($row = $this->db->fetchRow($result)) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchRow() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

367
                while ($row = $this->db->fetchRow(/** @scrutinizer ignore-type */ $result)) {
Loading history...
368
                    ++$count;
369
                    $ret[0] .= '(';
370
                    for ($i = 0; $i < $num_fields; ++$i) {
371
                        if (null === $row[$i]) {
372
                            $ret[0] .= 'null';
373
                        } else {
374
                            switch ($field_type[$i]) {
375
                                case 'int':
376
                                    $ret[0] .= $row[$i];
377
                                    break;
378
                                default:
379
                                    $ret[0] .= "'" . $this->db->escape($row[$i]) . "'";
380
                            }
381
                        }
382
                        if ($i < $num_fields - 1) {
383
                            $ret[0] .= ',';
384
                        }
385
                    }
386
                    $ret[0] .= ')';
387
388
                    if ($index < $num_rows - 1) {
389
                        $ret[0] .= ',';
390
                    } else {
391
                        $ret[0] .= ';';
392
                    }
393
                    $ret[0] .= "\n";
394
                    ++$index;
395
                }
396
            }
397
        }
398
        $ret[1] .= '<td align="center">';
399
        $ret[1] .= $count . '&nbsp;' . _AM_SYSTEM_MAINTENANCE_DUMP_RECORDS . '</td></tr>';
400
        $ret[0] .= "\n";
401
        if ($this->db->isResultSet($result)) {
402
            $this->db->freeRecordSet($result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::freeRecordSet() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

402
            $this->db->freeRecordSet(/** @scrutinizer ignore-type */ $result);
Loading history...
403
        }
404
        $ret[0] .= "\n";
405
406
        return $ret;
407
    }
408
409
    /**
410
     * Dump Write
411
     *
412
     * @param array
413
     * @return array 'ret[0] = dump, ret[1] = display result
414
     */
415
    public function dump_write($ret)
416
    {
417
        $file_name = 'dump_' . date('Y.m.d') . '_' . date('H.i.s') . '.sql';
418
        $path_file = './admin/maintenance/dump/' . $file_name;
419
        if (file_put_contents($path_file, $ret[0])) {
420
            $ret[1] .= '<table class="outer"><tr><th colspan="2" align="center">' . _AM_SYSTEM_MAINTENANCE_DUMP_FILE_CREATED . '</th><th>' . _AM_SYSTEM_MAINTENANCE_DUMP_RESULT . '</th></tr><tr><td colspan="2" align="center"><a href="' . XOOPS_URL . '/modules/system/admin/maintenance/dump/' . $file_name . '">' . $file_name . '</a></td><td  class="xo-actions txtcenter"><img src="' . system_AdminIcons('success.png') . '" /></td><tr></table>';
421
        } else {
422
            $ret[1] .= '<table class="outer"><tr><th colspan="2" align="center">' . _AM_SYSTEM_MAINTENANCE_DUMP_FILE_CREATED . '</th><th>' . _AM_SYSTEM_MAINTENANCE_DUMP_RESULT . '</th></tr><tr><td colspan="2" class="xo-actions txtcenter">' . $file_name . '</td><td  class="xo-actions txtcenter"><img src="' . system_AdminIcons('cancel.png') . '" /></td><tr></table>';
423
        }
424
425
        return $ret;
426
    }
427
}
428