|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
use Xmf\Database\Tables; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Upgrade from 2.5.7 to 2.5.8 |
|
7
|
|
|
* |
|
8
|
|
|
* See the enclosed file license.txt for licensing information. |
|
9
|
|
|
* If you did not receive this file, get it at http://www.gnu.org/licenses/gpl-2.0.html |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
12
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) |
|
13
|
|
|
* @package Upgrade |
|
14
|
|
|
* @since 2.5.9 |
|
15
|
|
|
* @author XOOPS Team |
|
16
|
|
|
*/ |
|
17
|
|
|
class Upgrade_259 extends XoopsUpgrade |
|
18
|
|
|
{ |
|
19
|
|
|
public $tasks = array( |
|
20
|
|
|
'sess_id', |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* __construct |
|
25
|
|
|
* |
|
26
|
|
|
* make sure we have XMF active |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
parent::__construct(basename(__DIR__)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Return the length of a database table column |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $table table name |
|
37
|
|
|
* @param string $column column name |
|
38
|
|
|
* |
|
39
|
|
|
* @return int column length or zero on error |
|
40
|
|
|
*/ |
|
41
|
|
View Code Duplication |
private function getColumnLength($table, $column) |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var XoopsMySQLDatabase $db */ |
|
44
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
45
|
|
|
|
|
46
|
|
|
$dbname = constant('XOOPS_DB_NAME'); |
|
47
|
|
|
$table = $db->prefix($table); |
|
48
|
|
|
|
|
49
|
|
|
$sql = sprintf( |
|
50
|
|
|
'SELECT `CHARACTER_MAXIMUM_LENGTH` FROM `information_schema`.`COLUMNS` ' |
|
51
|
|
|
. "WHERE TABLE_SCHEMA = '%s'AND TABLE_NAME = '%s' AND COLUMN_NAME = '%s'", |
|
52
|
|
|
$db->escape($dbname), |
|
53
|
|
|
$db->escape($table), |
|
54
|
|
|
$db->escape($column) |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
/** @var mysqli_result $result */ |
|
58
|
|
|
$result = $db->query($sql); |
|
|
|
|
|
|
59
|
|
|
if ($result) { |
|
60
|
|
|
$row = $db->fetchRow($result); |
|
61
|
|
|
if ($row) { |
|
62
|
|
|
$columnLength = $row[0]; |
|
63
|
|
|
return (int) $columnLength; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
return 0; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* In PHP 7.1 Session ID length could be any length between 22 and 256 |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
public function check_sess_id() |
|
75
|
|
|
{ |
|
76
|
|
|
return (bool) ($this->getColumnLength('session', 'sess_id') >= 256); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Expand session id column to varchar(256) to accommodate expanded size possible in PHP 7.1 |
|
81
|
|
|
* Force ascii character set to prevent key length issues. |
|
82
|
|
|
* |
|
83
|
|
|
* @return bool |
|
84
|
|
|
*/ |
|
85
|
|
View Code Duplication |
public function apply_sess_id() |
|
86
|
|
|
{ |
|
87
|
|
|
$migrate = new Tables(); |
|
88
|
|
|
$migrate->useTable('session'); |
|
89
|
|
|
$migrate->alterColumn('session', 'sess_id', "varchar(256) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT ''"); |
|
90
|
|
|
return $migrate->executeQueue(true); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$upg = new Upgrade_259(); |
|
95
|
|
|
return $upg; |
|
96
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.