Completed
Push — development ( c4d33f...5f74fd )
by Nils
09:26
created

upgrade_db_1.08.php ➔ changeDB()   F

Complexity

Conditions 21
Paths 688

Size

Total Lines 60
Code Lines 43

Duplication

Lines 45
Ratio 75 %

Importance

Changes 0
Metric Value
cc 21
eloc 43
nc 688
nop 0
dl 45
loc 60
rs 3.3333
c 0
b 0
f 0

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
 * @file          upgrade_db_1.08.php
4
 * @author        Nils Laumaillé
5
 * @version       2.1.27
6
 * @copyright     (c) 2009-2017 Nils Laumaillé
7
 * @licensing     GNU AFFERO GPL 3.0
8
 * @link          http://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_start();
17
require_once '../includes/config/settings.php';
18
//ENGLISH
19
$english_vals = array(
20
    array('at_modification', "Modification"),
21
    array('at_creation', "Creation"),
22
    array('at_delete', "Deletion"),
23
    array('at_pw', "Password changed."),
24
    array('at_category', "Group"),
25
    array('at_personnel', "Personnal"),
26
    array('at_description', "Description"),
27
    array('at_url', "Url"),
28
    array('at_login', "Login"),
29
    array('at_label', "Label")
30
);
31
//FRENCH
32
$french_vals = array(
33
    array('at_modification', "Modification"),
34
    array('at_creation', "Création"),
35
    array('at_delete', "Suppression"),
36
    array('at_pw', "Mot de passe changé."),
37
    array('at_category', "Group"),
38
    array('at_personnel', "Personnel"),
39
    array('at_description', "Description."),
40
    array('at_url', "Url"),
41
    array('at_login', "Login"),
42
    array('at_label', "Label")
43
);
44
//SPANISH
45
$spanish_vals = array(
46
    array('at_modification', "Modificacion"),
47
    array('at_creation', "Creacion"),
48
    array('at_delete', "Borrado"),
49
    array('at_pw', "Contraseéa cambiada."),
50
    array('at_category', "Grupo"),
51
    array('at_personnel', "Personal"),
52
    array('at_description', "Descripcion."),
53
    array('at_url', "Url"),
54
    array('at_login', "Login"),
55
    array('at_label', "Etiqueta")
56
);
57
58
changeDB();
59
changeDB();
60
changeDB();
61
62
//This will permit to update DB due to major change in log_items table for 1.08 version needs.
63
64
function changeDB()
65
{
66
    global $spanish_vals, $french_vals, $english_vals, $dbTmp;
67
    $res = mysqli_query($dbTmp, "SELECT * FROM ".$pre."log_items") or die(mysqli_error($dbTmp));
0 ignored issues
show
Bug introduced by
The variable $pre does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
68
    while ($data = mysqli_fetch_array($res)) {
69
        $action = "";
70
        //ENGLISH
71 View Code Duplication
        foreach ($english_vals as $lang) {
72
            if ($lang[1] == $data['action']) {
73
                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']);
74
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
75
                $action = $lang[0];
76
            }
77
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
78
                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']."'");
79
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
80
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
81
                $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."'"));
82
                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]."'");
83
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
84
            }
85
        }
86
87
        //FRENCH
88
        $action = "";
89 View Code Duplication
        foreach ($french_vals as $lang) {
90
            if ($lang[1] == $data['action']) {
91
                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']);
92
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
93
                $action = $lang[0];
94
            }
95
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
96
                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']."'");
97
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
98
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
99
                $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."'"));
100
                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]."'");
101
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
102
            }
103
        }
104
105
        //SPANISH
106
        $action = "";
107 View Code Duplication
        foreach ($spanish_vals as $lang) {
108
            if ($lang[1] == $data['action']) {
109
                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']);
110
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
111
                $action = $lang[0];
112
            }
113
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
114
                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']."'");
115
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
116
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
117
                $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."'"));
118
                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]."'");
119
                $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
120
            }
121
        }
122
    }
123
}
124