Completed
Push — master ( 3e6f39...ee2ef7 )
by cam
04:21
created

v009.php ➔ maj_legacy_v009_dist()   F

Complexity

Conditions 18
Paths 24

Size

Total Lines 123

Duplication

Lines 72
Ratio 58.54 %

Importance

Changes 0
Metric Value
cc 18
nc 24
nop 2
dl 72
loc 123
rs 3.8933
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
/***************************************************************************\
4
 *  SPIP, Système de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright © avec tendresse depuis 2001                                 *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribué sous licence GNU/GPL.     *
10
 *  Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne.   *
11
\***************************************************************************/
12
13
/**
14
 * Gestion des mises à jour de SPIP, versions 0.9*
15
 *
16
 * @package SPIP\Core\SQL\Upgrade
17
 **/
18
if (!defined('_ECRIRE_INC_VERSION')) {
19
	return;
20
}
21
22
/**
23
 * Mises à jour de SPIP n°009
24
 *
25
 * @param float $version_installee Version actuelle
26
 * @param float $version_cible Version de destination
27
 **/
28
function maj_legacy_v009_dist($version_installee, $version_cible) {
29
	if (upgrade_vers(0.98, $version_installee, $version_cible)) {
0 ignored issues
show
Deprecated Code introduced by
The function upgrade_vers() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
30
31
		sql_query("ALTER TABLE spip_articles ADD maj TIMESTAMP");
32
		sql_query("ALTER TABLE spip_articles ADD export VARCHAR(10) DEFAULT 'oui'");
33
		sql_query("ALTER TABLE spip_articles ADD images TEXT DEFAULT ''");
34
		sql_query("ALTER TABLE spip_articles ADD date_redac datetime DEFAULT '0000-00-00 00:00:00' NOT NULL");
35
		sql_query("ALTER TABLE spip_articles DROP INDEX id_article");
36
		sql_query("ALTER TABLE spip_articles ADD INDEX id_rubrique (id_rubrique)");
37
		sql_query("ALTER TABLE spip_articles ADD visites INTEGER DEFAULT '0' NOT NULL");
38
		sql_query("ALTER TABLE spip_articles ADD referers BLOB NOT NULL");
39
40
		sql_query("ALTER TABLE spip_auteurs ADD maj TIMESTAMP");
41
		sql_query("ALTER TABLE spip_auteurs ADD pgp BLOB NOT NULL");
42
43
		sql_query("ALTER TABLE spip_auteurs_articles ADD INDEX id_auteur (id_auteur), ADD INDEX id_article (id_article)");
44
45
		sql_query("ALTER TABLE spip_rubriques ADD maj TIMESTAMP");
46
		sql_query("ALTER TABLE spip_rubriques ADD export VARCHAR(10) DEFAULT 'oui', ADD id_import BIGINT DEFAULT '0'");
47
48
		sql_query("ALTER TABLE spip_breves ADD maj TIMESTAMP");
49
		sql_query("ALTER TABLE spip_breves DROP INDEX id_breve");
50
		sql_query("ALTER TABLE spip_breves DROP INDEX id_breve_2");
51
		sql_query("ALTER TABLE spip_breves ADD INDEX id_rubrique (id_rubrique)");
52
53
		sql_query("ALTER TABLE spip_forum ADD ip VARCHAR(16)");
54
		sql_query("ALTER TABLE spip_forum ADD maj TIMESTAMP");
55
		sql_query("ALTER TABLE spip_forum DROP INDEX id_forum");
56
		sql_query("ALTER TABLE spip_forum ADD INDEX id_parent (id_parent), ADD INDEX id_rubrique (id_rubrique), ADD INDEX id_article(id_article), ADD INDEX id_breve(id_breve)");
57
		maj_version(0.98);
0 ignored issues
show
Deprecated Code introduced by
The function maj_version() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
58
	}
59
60
	if (upgrade_vers(0.99, $version_installee, $version_cible)) {
0 ignored issues
show
Deprecated Code introduced by
The function upgrade_vers() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
61
62
		$result = sql_query("SELECT DISTINCT id_article FROM spip_forum WHERE id_article!=0 AND id_parent=0");
63
64 View Code Duplication
		while ($row = sql_fetch($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
			unset($forums_article);
66
			$id_article = $row['id_article'];
67
			$result2 = sql_query("SELECT id_forum FROM spip_forum WHERE id_article=$id_article");
68
			for (; ;) {
69
				unset($forums);
70
				while ($row2 = sql_fetch($result2)) {
71
					$forums[] = $row2['id_forum'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$forums was never initialized. Although not strictly required by PHP, it is generally a good practice to add $forums = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
72
				}
73
				if (!$forums) {
0 ignored issues
show
Bug introduced by
The variable $forums does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
74
					break;
75
				}
76
				$forums = join(',', $forums);
77
				$forums_article[] = $forums;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$forums_article was never initialized. Although not strictly required by PHP, it is generally a good practice to add $forums_article = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
78
				$result2 = sql_query("SELECT id_forum FROM spip_forum WHERE id_parent IN ($forums)");
79
			}
80
			$forums_article = join(',', $forums_article);
0 ignored issues
show
Bug introduced by
The variable $forums_article does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
81
			sql_query("UPDATE spip_forum SET id_article=$id_article WHERE id_forum IN ($forums_article)");
82
		}
83
84
		$result = sql_query("SELECT DISTINCT id_breve FROM spip_forum WHERE id_breve!=0 AND id_parent=0");
85
86 View Code Duplication
		while ($row = sql_fetch($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
			unset($forums_breve);
88
			$id_breve = $row['id_breve'];
89
			$result2 = sql_query("SELECT id_forum FROM spip_forum WHERE id_breve=$id_breve");
90
			for (; ;) {
91
				unset($forums);
92
				while ($row2 = sql_fetch($result2)) {
93
					$forums[] = $row2['id_forum'];
94
				}
95
				if (!$forums) {
96
					break;
97
				}
98
				$forums = join(',', $forums);
99
				$forums_breve[] = $forums;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$forums_breve was never initialized. Although not strictly required by PHP, it is generally a good practice to add $forums_breve = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
100
				$result2 = sql_query("SELECT id_forum FROM spip_forum WHERE id_parent IN ($forums)");
101
			}
102
			$forums_breve = join(',', $forums_breve);
0 ignored issues
show
Bug introduced by
The variable $forums_breve does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
103
			sql_query("UPDATE spip_forum SET id_breve=$id_breve WHERE id_forum IN ($forums_breve)");
104
		}
105
106
		$result = sql_query("SELECT DISTINCT id_rubrique FROM spip_forum WHERE id_rubrique!=0 AND id_parent=0");
107
108 View Code Duplication
		while ($row = sql_fetch($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
			unset($forums_rubrique);
110
			$id_rubrique = $row['id_rubrique'];
111
			$result2 = sql_query("SELECT id_forum FROM spip_forum WHERE id_rubrique=$id_rubrique");
112
			for (; ;) {
113
114
				unset($forums);
115
				while ($row2 = sql_fetch($result2)) {
116
					$forums[] = $row2['id_forum'];
117
				}
118
				if (!$forums) {
119
					break;
120
				}
121
				$forums = join(',', $forums);
122
				$forums_rubrique[] = $forums;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$forums_rubrique was never initialized. Although not strictly required by PHP, it is generally a good practice to add $forums_rubrique = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
123
				$result2 = sql_query("SELECT id_forum FROM spip_forum WHERE id_parent IN ($forums)");
124
			}
125
			$forums_rubrique = join(',', $forums_rubrique);
0 ignored issues
show
Bug introduced by
The variable $forums_rubrique does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
126
			sql_query("UPDATE spip_forum SET id_rubrique=$id_rubrique WHERE id_forum IN ($forums_rubrique)");
127
128
		}
129
		maj_version(0.99);
0 ignored issues
show
Deprecated Code introduced by
The function maj_version() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
130
	}
131
132
	if (upgrade_vers(0.997, $version_installee, $version_cible)) {
0 ignored issues
show
Deprecated Code introduced by
The function upgrade_vers() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
133
		sql_query("DROP TABLE spip_index");
134
		maj_version(0.997);
0 ignored issues
show
Deprecated Code introduced by
The function maj_version() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
135
	}
136
137 View Code Duplication
	if (upgrade_vers(0.999, $version_installee, $version_cible)) {
0 ignored issues
show
Deprecated Code introduced by
The function upgrade_vers() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
139
		sql_query("ALTER TABLE spip_auteurs CHANGE pass pass tinyblob NOT NULL");
140
		sql_query("ALTER TABLE spip_auteurs ADD htpass tinyblob NOT NULL");
141
		$result = sql_query("SELECT id_auteur, pass FROM spip_auteurs WHERE pass!=''");
142
143
		while ($r = sql_fetch($result)) {
144
			$htpass = generer_htpass($r['pass']);
145
			$pass = md5($pass);
0 ignored issues
show
Bug introduced by
The variable $pass does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
146
			sql_query("UPDATE spip_auteurs SET pass='$pass', htpass='$htpass' WHERE id_auteur=" . $r['id_auteur']);
147
		}
148
		maj_version(0.999);
0 ignored issues
show
Deprecated Code introduced by
The function maj_version() has been deprecated with message: Utiliser `maj_plugin()` ou la globale `maj` pour le core.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
149
	}
150
}
151