blob: 20bb082cc31f7ff741dfe18838e57860367e28e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Updates;
use Piwik\Common;
use Piwik\Db;
use Piwik\Plugins\Installation\ServerFilesGenerator;
use Piwik\Updater;
use Piwik\Updater\Migration;
use Piwik\Updater\Migration\Factory as MigrationFactory;
use Piwik\Updates;
class Updates_3_0_0_b4 extends Updates
{
/**
* @var MigrationFactory
*/
private $migration;
/**
* @var string
*/
private $userTable = 'user';
public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}
/**
* Here you can define one or multiple SQL statements that should be executed during the update.
* @param Updater $updater
* @return Migration[]
*/
public function getMigrations(Updater $updater)
{
$migrations = [];
$migrations = $this->getUserDatabaseMigrations($migrations);
return $migrations;
}
public function doUpdate(Updater $updater)
{
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
$updater->executeMigrations(__FILE__, $this->getUserPasswordMigrations([]));
ServerFilesGenerator::createFilesForSecurity();
}
/**
* Returns database migrations for this update.
* @param Migration[] $queries
* @return Migration[]
*/
private function getUserDatabaseMigrations($queries)
{
$queries[] = $this->migration->db->changeColumn($this->userTable, 'password', 'password', 'VARCHAR(255) NOT NULL');
return $queries;
}
/**
* Returns migrations to hash existing password with bcrypt.
* @param Migration[] $queries
* @return Migration[]
*/
private function getUserPasswordMigrations($queries)
{
$db = Db::get();
$userTable = Common::prefixTable($this->userTable);
$users = $db->fetchAll(
'SELECT `login`, `password` FROM `' . $userTable . '` WHERE LENGTH(`password`) = 32'
);
foreach ($users as $user) {
$queries[] = $this->migration->db->boundSql(
'UPDATE `' . $userTable . '`'
. ' SET `password` = ?'
. ' WHERE `login` = ?',
[
password_hash($user['password'], PASSWORD_BCRYPT),
$user['login'],
]
);
}
return $queries;
}
}
|