Passed
Push — teampass_3.0 ( 416a97...870788 )
by Nils
06:42
created

changeDB()   F

Complexity

Conditions 21
Paths 688

Size

Total Lines 56
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 22
Bugs 0 Features 0
Metric Value
cc 21
eloc 42
c 22
b 0
f 0
nc 688
nop 0
dl 0
loc 56
rs 0.4333

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @package       upgrade_db_1.08.php
4
 * @author        Nils Laumaillé <[email protected]>
5
 * @version       2.1.27
6
 * @copyright     2009-2019 Nils Laumaillé
7
 * @license       GNU GPL-3.0
8
 * @link          https://www.teampass.net
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
require_once('../sources/SecureHandler.php');
16
session_name('teampass_session');
17
session_start();
18
require_once '../includes/config/settings.php';
19
//ENGLISH
20
$english_vals = array(
21
    array('at_modification', "Modification"),
22
    array('at_creation', "Creation"),
23
    array('at_delete', "Deletion"),
24
    array('at_pw', "Password changed."),
25
    array('at_category', "Group"),
26
    array('at_personnel', "Personnal"),
27
    array('at_description', "Description"),
28
    array('at_url', "Url"),
29
    array('at_login', "Login"),
30
    array('at_label', "Label")
31
);
32
//FRENCH
33
$french_vals = array(
34
    array('at_modification', "Modification"),
35
    array('at_creation', "Création"),
36
    array('at_delete', "Suppression"),
37
    array('at_pw', "Mot de passe changé."),
38
    array('at_category', "Group"),
39
    array('at_personnel', "Personnel"),
40
    array('at_description', "Description."),
41
    array('at_url', "Url"),
42
    array('at_login', "Login"),
43
    array('at_label', "Label")
44
);
45
//SPANISH
46
$spanish_vals = array(
47
    array('at_modification', "Modificacion"),
48
    array('at_creation', "Creacion"),
49
    array('at_delete', "Borrado"),
50
    array('at_pw', "Contraseéa cambiada."),
51
    array('at_category', "Grupo"),
52
    array('at_personnel', "Personal"),
53
    array('at_description', "Descripcion."),
54
    array('at_url', "Url"),
55
    array('at_login', "Login"),
56
    array('at_label', "Etiqueta")
57
);
58
59
changeDB();
60
61
//This will permit to update DB due to major change in log_items table for 1.08 version needs.
62
63
function changeDB()
64
{
65
    global $spanish_vals, $french_vals, $english_vals, $dbTmp;
66
    $res = mysqli_query($dbTmp, "SELECT * FROM ".$pre."log_items") or die(mysqli_error($dbTmp));
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Comprehensibility Best Practice introduced by
The variable $pre seems to be never defined.
Loading history...
67
    while ($data = mysqli_fetch_array($res)) {
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type boolean; however, parameter $result of mysqli_fetch_array() 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

67
    while ($data = mysqli_fetch_array(/** @scrutinizer ignore-type */ $res)) {
Loading history...
68
        $action = "";
69
        //ENGLISH
70
        foreach ($english_vals as $lang) {
71
            if ($lang[1] == $data['action']) {
72
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']);
73
                $found = true;
74
                $action = $lang[0];
75
            }
76
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
77
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'");
78
                $found = true;
79
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
80
                $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$pre."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'"));
0 ignored issues
show
Bug introduced by
It seems like mysqli_query($dbTmp, 'SE...on ='' . $action . ''') can also be of type boolean; however, parameter $result of mysqli_fetch_row() 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

80
                $data1 = mysqli_fetch_row(/** @scrutinizer ignore-type */ mysqli_query($dbTmp, "SELECT action FROM ".$pre."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'"));
Loading history...
81
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'");
82
                $found = true;
83
            }
84
        }
85
86
        //FRENCH
87
        $action = "";
88
        foreach ($french_vals as $lang) {
89
            if ($lang[1] == $data['action']) {
90
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']);
91
                $found = true;
92
                $action = $lang[0];
93
            }
94
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
95
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'");
96
                $found = true;
97
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
98
                $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$pre."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'"));
99
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'");
100
                $found = true;
101
            }
102
        }
103
104
        //SPANISH
105
        $action = "";
106
        foreach ($spanish_vals as $lang) {
107
            if ($lang[1] == $data['action']) {
108
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']);
109
                $found = true;
110
                $action = $lang[0];
111
            }
112
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
113
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'");
114
                $found = true;
115
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
116
                $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$pre."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'"));
117
                mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'");
118
                $found = true;
119
            }
120
        }
121
    }
122
}
123