Completed
Push — development ( 6352e5...8bea34 )
by Nils
07:55
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
include $_SESSION['settings']['cpassman_dir'].'/includes/config/settings.php';
18
global $k;
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
changeDB();
61
changeDB();
62
63
//This will permit to update DB due to major change in log_items table for 1.08 version needs.
64
65
function changeDB()
66
{
67
    global $k, $spanish_vals, $french_vals, $english_vals, $dbTmp;
68
    $res = mysqli_query($dbTmp, "SELECT * FROM ".$_SESSION['pre']."log_items") or die(mysqli_error($dbTmp));
69
    while ($data = mysqli_fetch_array($res)) {
70
        $action = "";
71
        //ENGLISH
72 View Code Duplication
        foreach ($english_vals as $lang) {
73
            if ($lang[1] == $data['action']) {
74
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']);
75
                $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...
76
                $action = $lang[0];
77
            }
78
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
79
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['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']."'");
80
                $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...
81
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
82
                $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['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."'"));
83
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['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]."'");
84
                $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...
85
            }
86
        }
87
88
        //FRENCH
89
        $action = "";
90 View Code Duplication
        foreach ($french_vals as $lang) {
91
            if ($lang[1] == $data['action']) {
92
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']);
93
                $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...
94
                $action = $lang[0];
95
            }
96
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
97
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['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']."'");
98
                $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...
99
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
100
                $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['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."'"));
101
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['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]."'");
102
                $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...
103
            }
104
        }
105
106
        //SPANISH
107
        $action = "";
108 View Code Duplication
        foreach ($spanish_vals as $lang) {
109
            if ($lang[1] == $data['action']) {
110
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']);
111
                $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...
112
                $action = $lang[0];
113
            }
114
            if ($lang[1] == $data['raison'] && !empty($data['raison'])) {
115
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['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']."'");
116
                $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...
117
            } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) {
118
                $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['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."'"));
119
                mysqli_query($dbTmp, "UPDATE ".$_SESSION['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]."'");
120
                $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...
121
            }
122
        }
123
    }
124
}
125