format_time()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
/*
3
*******************************************************
4
***													***
5
*** backpack										***
6
*** Cedric MONTUY pour CHG-WEB                      ***
7
*** Original author : Yoshi Sakai					***
8
***													***
9
*******************************************************
10
*/
11
12
use Xmf\Module\Admin;
13
/** @var Admin $adminObject */
14
15
$ok      = 0;
16
$op      = '';
17
$message = '';
18
$table   = [];
19
$op      = (isset($_POST['op'])) ? filter_input(INPUT_POST, 'op', FILTER_SANITIZE_STRING, ['flags' => FILTER_NULL_ON_FAILURE]) : false;
20
$ok      = (isset($_POST['ok'])) ? filter_input(INPUT_POST, 'ok', FILTER_SANITIZE_STRING, ['flags' => FILTER_NULL_ON_FAILURE]) : false;
21
22
require_once __DIR__ . '/admin_header.php';
23
xoops_cp_header();
24
$adminObject = Admin::getInstance();
25
$adminObject->displayNavigation(basename(__FILE__));
26
27
function format_time($seconds)
28
{
29
    $hour       = $seconds / 3600;
30
    $total_time = $seconds - ($hour * 3600);
0 ignored issues
show
Unused Code introduced by
The assignment to $total_time is dead and can be removed.
Loading history...
31
    $min        = $seconds / 60;
32
    $sec        = $seconds % 60;
33
    $format     = sprintf('%02d', $hour) . ':' . sprintf('%02d', $min) . ':' . sprintf('%02d', $sec);
34
    return $format;
35
}
36
37
if (1 != $ok) {
38
    $op = '';
39
}
40
switch ($op) {
41
    case 'conf_opt':
42
        echo _AM_PROCESS_EFFECTUE . '<br>';
43
        $r = $xoopsDB->queryF('SHOW TABLES');
44
        while (false !== ($row = $xoopsDB->fetchRow($r))) {
45
            $table[] = $row[0];
46
        }
47
        if (0 == count($table)) {
48
            $ok      = 0;
49
            $message = _AM_PASOK_PASTABLE;
50
            break;
51
        }
52
53
        if (1 == count($table)) {
54
            $xoopsDB->queryF('LOCK TABLES `' . $table[0] . '` WRITE');
55
        } elseif (count($table) > 1) {
56
            $xoopsDB->queryF('LOCK TABLES `' . implode('` WRITE, `', $table) . '` WRITE');
57
        } else {
58
            $ok      = 0;
59
            $message = _AM_ERROR_UNKNOWN;
0 ignored issues
show
Bug introduced by
The constant _AM_ERROR_UNKNOWN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
60
            break;
61
        }
62
        echo _AM_LOCK_BDD . '<br>';
63
        $t1 = time();
64
        foreach ($table as $val) {
65
            $b1 = time();
66
            if ($xoopsDB->query('OPTIMIZE TABLE `' . $val . '`')) {
67
                $b2         = time();
68
                $table_time = $b2 - $b1;
69
                echo _AM_OPTIMIZE . ' ' . $val . ' OK (' . _AM_TEMPS_ECOULE . ' : ' . format_time($table_time) . ')<br>';
70
            }
71
        }
72
        $xoopsDB->queryF('UNLOCK TABLES');
73
        echo _AM_UNLOCK_BDD . '<br>';
74
        $t2         = time();
75
        $total_time = $t2 - $t1;
76
        echo _AM_TEMPS_TOT . ' : ' . format_time($total_time) . '<br>';
77
        echo '<p style="text-align: center;"><a href="index.php">' . _AM_RETURNTOSTART . '</a></p>';
78
        break;
79
    default:
80
        $ok = 1;
81
        xoops_confirm(['op' => 'conf_opt', 'ok' => 1], XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/optimizer.php', _AM_OPT_WARNING . '<br>' . _AM_PRECISION . '<br>' . _AM_VERIF_SUR . '<br><a href="index.php">' . _AM_RETURNTOSTART . '</a>');
82
}
83
if (1 != $ok) {
84
    echo $message;
85
    echo '<p style="text-align: center;"><a href="index.php">' . _AM_RETURNTOSTART . '</a></p>';
86
}
87
require __DIR__ . '/admin_footer.php';
88