Passed
Push — master ( 05faca...9c86bf )
by Richard
08:39 queued 13s
created

SystemMaintenance::CleanCache()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 19
rs 9.4888
cc 5
nc 5
nop 1
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
            throw new \RuntimeException(
57
                \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->error(), E_USER_ERROR
58
            );
59
        }
60
        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

60
        while (false !== ($myrow = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
61
            $value          = array_values($myrow);
62
            $value          = substr($value[0], strlen(XOOPS_DB_PREFIX) + 1);
63
            $tables[$value] = $value;
64
        }
65
        if (true === (bool)$array) {
66
            return $tables;
67
        } else {
68
            return implode(',', $tables);
69
        }
70
    }
71
72
    /**
73
     * Clear sessions
74
     *
75
     * @return bool
76
     */
77
    public function CleanSession()
78
    {
79
        $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...
80
81
        return true;
82
    }
83
84
    /**
85
     * CleanAvatar
86
     *
87
     * Clean up orphaned custom avatars left when a user is deleted.
88
     *
89
     * @author slider84 of Team FrXoops
90
     *
91
     * @return boolean
92
     */
93
    public function CleanAvatar()
94
    {
95
        $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)';
96
        $result = $this->db->queryF($sql);
97
        if (!$this->db->isResultSet($result)) {
98
            throw new \RuntimeException(
99
                \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->error(), E_USER_ERROR
100
            );
101
        }
102
103
        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

103
        while (false !== ($myrow = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
104
            //delete file
105
            @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

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

324
            if ($row = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result)) {
Loading history...
325
                $ret[0] .= '# Table structure for table `' . $table . "` \n\n";
326
                if ($drop == 1) {
327
                    $ret[0] .= 'DROP TABLE IF EXISTS `' . $table . "`;\n\n";
328
                }
329
                $verif = true;
330
                $ret[0] .= $row['Create Table'] . ";\n\n";
331
            }
332
        }
333
334
        $ret[1] .= '<tr class="' . $class . '"><td align="center">' . $table . '</td><td class="xo-actions txtcenter">';
335
        $ret[1] .= ($verif === true) ? '<img src="' . system_AdminIcons('success.png') . '" />' : '<img src="' . system_AdminIcons('cancel.png') . '" />';
336
        $ret[1] .= '</td>';
337
        if ($this->db->isResultSet($result)) {
338
            $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

338
            $this->db->freeRecordSet(/** @scrutinizer ignore-type */ $result);
Loading history...
339
        }
340
341
        return $ret;
342
    }
343
344
    /**
345
     * Dump table data
346
     *
347
     * @param array
348
     * @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...
349
     * @return array 'ret[0] = dump, ret[1] = display result
350
     */
351
    public function dump_table_datas($ret, $table)
352
    {
353
        $count  = 0;
354
        $sql = 'SELECT * FROM ' . $table . ';';
355
        $result = $this->db->queryF($sql);
356
        if ($this->db->isResultSet($result)) {
357
            $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

357
            $num_rows   = $this->db->getRowsNum(/** @scrutinizer ignore-type */ $result);
Loading history...
358
            $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

358
            $num_fields = $this->db->getFieldsNum(/** @scrutinizer ignore-type */ $result);
Loading history...
359
360
            if ($num_rows > 0) {
361
                $field_type = array();
362
                $i          = 0;
363
                while ($i < $num_fields) {
364
                    $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

364
                    $meta = mysqli_fetch_field(/** @scrutinizer ignore-type */ $result);
Loading history...
365
                    $field_type[] = $meta->type;
366
                    ++$i;
367
                }
368
369
                $ret[0] .= 'INSERT INTO `' . $table . "` values\n";
370
                $index = 0;
371
                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

371
                while ($row = $this->db->fetchRow(/** @scrutinizer ignore-type */ $result)) {
Loading history...
372
                    ++$count;
373
                    $ret[0] .= '(';
374
                    for ($i = 0; $i < $num_fields; ++$i) {
375
                        if (null === $row[$i]) {
376
                            $ret[0] .= 'null';
377
                        } else {
378
                            switch ($field_type[$i]) {
379
                                case 'int':
380
                                    $ret[0] .= $row[$i];
381
                                    break;
382
                                default:
383
                                    $ret[0] .= "'" . $this->db->escape($row[$i]) . "'";
384
                            }
385
                        }
386
                        if ($i < $num_fields - 1) {
387
                            $ret[0] .= ',';
388
                        }
389
                    }
390
                    $ret[0] .= ')';
391
392
                    if ($index < $num_rows - 1) {
393
                        $ret[0] .= ',';
394
                    } else {
395
                        $ret[0] .= ';';
396
                    }
397
                    $ret[0] .= "\n";
398
                    ++$index;
399
                }
400
            }
401
        }
402
        $ret[1] .= '<td align="center">';
403
        $ret[1] .= $count . '&nbsp;' . _AM_SYSTEM_MAINTENANCE_DUMP_RECORDS . '</td></tr>';
404
        $ret[0] .= "\n";
405
        if ($this->db->isResultSet($result)) {
406
            $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

406
            $this->db->freeRecordSet(/** @scrutinizer ignore-type */ $result);
Loading history...
407
        }
408
        $ret[0] .= "\n";
409
410
        return $ret;
411
    }
412
413
    /**
414
     * Dump Write
415
     *
416
     * @param array
417
     * @return array 'ret[0] = dump, ret[1] = display result
418
     */
419
    public function dump_write($ret)
420
    {
421
        $file_name = 'dump_' . date('Y.m.d') . '_' . date('H.i.s') . '.sql';
422
        $path_file = './admin/maintenance/dump/' . $file_name;
423
        if (file_put_contents($path_file, $ret[0])) {
424
            $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>';
425
        } else {
426
            $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>';
427
        }
428
429
        return $ret;
430
    }
431
}
432