Skip to content

Commit fb9f5aa

Browse files
Merge pull request #4256 from corentin-soriano/upgrade_improvement
BUGFIX - Upgrade process improvement and speedup
2 parents 08a4fbb + 60b2493 commit fb9f5aa

17 files changed

+284
-199
lines changed

includes/config/include.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
define('TP_COPYRIGHT', '2009-'.date('Y'));
4141
define('TP_ALLOWED_TAGS', '<b><i><sup><sub><em><strong><u><br><br /><a><strike><ul><blockquote><blockquote><img><li><h1><h2><h3><h4><h5><ol><small><font>');
4242
define('TP_FILE_PREFIX', 'EncryptedFile_');
43-
define('NUMBER_ITEMS_IN_BATCH', 100);
43+
define('NUMBER_ITEMS_IN_BATCH', 1000);
4444
define('WIP', false);
4545
define('UPGRADE_SEND_EMAILS', true);
4646
define('KEY_LENGTH', 16);

includes/libraries/teampassclasses/passwordmanager/src/PasswordManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function migratePassword(string $hashedPassword, string $plainPassword, i
6262
// Vérifiez si le mot de passe a été haché avec passwordlib
6363
if ($this->isPasswordLibHash($hashedPassword)) {
6464
// Utilisez la vérification de passwordlib ici
65-
if ($this->passwordLibVerify($hashedPassword, $plainPassword)) {
65+
if ($this->passwordLibVerify($hashedPassword, html_entity_decode($plainPassword))) {
6666
// Password is valid, hash it with new system
6767
$newHashedPassword = $this->hashPassword($plainPassword);
6868
$userInfo['pw'] = $newHashedPassword;

install/install.queries.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ function encryptFollowingDefuse($message, $ascii_key)
382382
`object_id` int(12) NOT NULL,
383383
`user_id` int(12) NOT NULL,
384384
`share_key` text NOT NULL,
385-
PRIMARY KEY (`increment_id`)
385+
PRIMARY KEY (`increment_id`),
386+
INDEX idx_object_user (`object_id`, `user_id`)
386387
) CHARSET=utf8;'
387388
);
388389
$mysqli_result = mysqli_query(
@@ -471,7 +472,8 @@ function encryptFollowingDefuse($message, $ascii_key)
471472
`updated_at` varchar(30) NULL,
472473
`deleted_at` varchar(30) NULL,
473474
PRIMARY KEY (`id`),
474-
KEY `restricted_inactif_idx` (`restricted_to`,`inactif`)
475+
KEY `restricted_inactif_idx` (`restricted_to`,`inactif`),
476+
INDEX items_perso_id_idx (`perso`, `id`)
475477
) CHARSET=utf8;"
476478
);
477479
} elseif ($task === 'log_items') {
@@ -486,7 +488,8 @@ function encryptFollowingDefuse($message, $ascii_key)
486488
`raison` text NULL,
487489
`old_value` MEDIUMTEXT NULL DEFAULT NULL,
488490
`encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
489-
PRIMARY KEY (`increment_id`)
491+
PRIMARY KEY (`increment_id`),
492+
INDEX log_items_item_action_user_idx (`id_item`, `action`, `id_user`)
490493
) CHARSET=utf8;"
491494
);
492495
// create index
@@ -1311,13 +1314,14 @@ function encryptFollowingDefuse($message, $ascii_key)
13111314
$dbTmp,
13121315
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "background_tasks_logs` (
13131316
`increment_id` int(12) NOT NULL AUTO_INCREMENT,
1314-
`created_at` varchar(20) NOT NULL,
1317+
`created_at` INT NOT NULL,
13151318
`job` varchar(50) NOT NULL,
13161319
`status` varchar(10) NOT NULL,
1317-
`updated_at` varchar(20) DEFAULT NULL,
1318-
`finished_at` varchar(20) DEFAULT NULL,
1320+
`updated_at` INT DEFAULT NULL,
1321+
`finished_at` INT DEFAULT NULL,
13191322
`treated_objects` varchar(20) DEFAULT NULL,
1320-
PRIMARY KEY (`increment_id`)
1323+
PRIMARY KEY (`increment_id`),
1324+
INDEX idx_created_at (`created_at`)
13211325
) CHARSET=utf8;"
13221326
);
13231327
} else if ($task === 'ldap_groups_roles') {

install/upgrade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ function aesEncrypt(text)
754754
function manageUpgradeScripts(file_number)
755755
{
756756
var start_at = 0;
757-
var noitems_by_loop = 100;
757+
var noitems_by_loop = 1000;
758758
var loop_number = 0;
759759

760760
if (file_number == 0) {

install/upgrade_operations.php

+38-9
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,15 @@
7373
$port = DB_PORT;
7474
$user = DB_USER;
7575

76-
if (mysqli_connect(
77-
$server,
78-
$user,
79-
$pass,
80-
$database,
81-
$port
82-
)) {
83-
$db_link = mysqli_connect(
76+
if ($db_link = mysqli_connect(
8477
$server,
8578
$user,
8679
$pass,
8780
$database,
8881
$port
89-
);
82+
)
83+
) {
84+
$db_link->set_charset(DB_ENCODING);
9085
} else {
9186
$res = 'Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error());
9287
echo '[{"finish":"1", "msg":"", "error":"Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error()) . '!"}]';
@@ -102,6 +97,9 @@
10297
// ---->
10398
// OPERATION - 20230604_1 - generate key for item_key
10499

100+
// Start transaction to avoid autocommit
101+
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);
102+
105103
// Get items to treat
106104
$rows = mysqli_query(
107105
$db_link,
@@ -113,6 +111,8 @@
113111
// Handle error on query
114112
if (!$rows) {
115113
echo '[{"finish":"1" , "error":"'.mysqli_error($db_link).'"}]';
114+
mysqli_commit($db_link);
115+
mysqli_close($db_link);
116116
exit();
117117
}
118118

@@ -131,6 +131,8 @@
131131
);
132132
if (mysqli_error($db_link)) {
133133
echo '[{"finish":"1", "next":"", "error":"MySQL Error! '.addslashes(mysqli_error($db_link)).'"}]';
134+
mysqli_commit($db_link);
135+
mysqli_close($db_link);
134136
exit();
135137
}
136138
}
@@ -158,12 +160,17 @@
158160
}
159161
// Return back
160162
echo '[{"finish":"'.$finish.'" , "next":"", "error":"", "total":"'.$total.'"}]';
163+
// Commit transaction.
164+
mysqli_commit($db_link);
161165
}
162166

163167

164168
function populateItemsTable_CreatedAt($pre, $post_nb)
165169
{
166170
global $db_link;
171+
// Start transaction to avoid autocommit
172+
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);
173+
167174
// loop on items - created_at
168175
$items = mysqli_query(
169176
$db_link,
@@ -190,12 +197,19 @@ function populateItemsTable_CreatedAt($pre, $post_nb)
190197
"SELECT * FROM `" . $pre . "items` WHERE created_at IS NULL"
191198
)
192199
);
200+
201+
// Commit transaction.
202+
mysqli_commit($db_link);
203+
193204
return $remainingItems > 0 ? 0 : 1;
194205
}
195206

196207
function populateItemsTable_UpdatedAt($pre)
197208
{
198209
global $db_link;
210+
// Start transaction to avoid autocommit
211+
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);
212+
199213
// loop on items - updated_at
200214
$items = mysqli_query(
201215
$db_link,
@@ -212,12 +226,18 @@ function populateItemsTable_UpdatedAt($pre)
212226
}
213227
}
214228

229+
// Commit transaction.
230+
mysqli_commit($db_link);
231+
215232
return 1;
216233
}
217234

218235
function populateItemsTable_DeletedAt($pre)
219236
{
220237
global $db_link;
238+
// Start transaction to avoid autocommit
239+
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);
240+
221241
// loop on items - deleted_at
222242
$items = mysqli_query(
223243
$db_link,
@@ -234,6 +254,9 @@ function populateItemsTable_DeletedAt($pre)
234254
}
235255
}
236256

257+
// Commit transaction.
258+
mysqli_commit($db_link);
259+
237260
return 1;
238261
}
239262

@@ -273,6 +296,9 @@ function installPurgeUnnecessaryKeys(bool $allUsers = true, int $user_id=0, stri
273296
function installPurgeUnnecessaryKeysForUser(int $user_id=0, string $pre)
274297
{
275298
global $db_link;
299+
// Start transaction to avoid autocommit
300+
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);
301+
276302
if ($user_id === 0) {
277303
return;
278304
}
@@ -319,6 +345,9 @@ function installPurgeUnnecessaryKeysForUser(int $user_id=0, string $pre)
319345
WHERE object_id IN ('.$pfItemsList.') AND user_id NOT IN ('.TP_USER_ID.', '.$user_id.')'
320346
);
321347
}
348+
349+
// Commit transaction.
350+
mysqli_commit($db_link);
322351
}
323352

324353

install/upgrade_run_3.0.0.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,15 @@
7878
$port = DB_PORT;
7979
$user = DB_USER;
8080

81-
if (mysqli_connect(
82-
$server,
83-
$user,
84-
$pass,
85-
$database,
86-
$port
87-
)) {
88-
$db_link = mysqli_connect(
81+
if ($db_link = mysqli_connect(
8982
$server,
9083
$user,
9184
$pass,
9285
$database,
9386
$port
94-
);
87+
)
88+
) {
89+
$db_link->set_charset(DB_ENCODING);
9590
} else {
9691
$res = 'Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error());
9792
echo '[{"finish":"1", "msg":"", "error":"Impossible to get connected to server. Error is: ' . addslashes(mysqli_connect_error()) . '!"}]';
@@ -248,7 +243,8 @@
248243
`object_id` int(12) NOT NULL,
249244
`user_id` int(12) NOT NULL,
250245
`share_key` text NOT NULL,
251-
PRIMARY KEY (`increment_id`)
246+
PRIMARY KEY (`increment_id`),
247+
INDEX idx_object_user (`object_id`, `user_id`)
252248
) CHARSET=utf8;'
253249
);
254250

install/upgrade_run_3.0.0_fields.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,14 @@
6969
$port = DB_PORT;
7070
$user = DB_USER;
7171

72-
if (mysqli_connect(
73-
$server,
74-
$user,
75-
$pass,
76-
$database,
77-
$port
78-
)
79-
) {
80-
$db_link = mysqli_connect(
72+
if ($db_link = mysqli_connect(
8173
$server,
8274
$user,
8375
$pass,
8476
$database,
8577
$port
86-
);
78+
)
79+
) {
8780
$db_link->set_charset(DB_ENCODING);
8881
} else {
8982
$res = 'Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error());
@@ -161,7 +154,7 @@
161154
);
162155

163156
// Encrypt with Object Key
164-
$cryptedStuff = doDataEncryption($passwd['string']);
157+
$cryptedStuff = doDataEncryption(html_entity_decode($passwd['string']));
165158

166159
// Store new password in DB
167160
mysqli_query(

install/upgrade_run_3.0.0_files.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,14 @@
7474
$port = DB_PORT;
7575
$user = DB_USER;
7676

77-
if (mysqli_connect(
78-
$server,
79-
$user,
80-
$pass,
81-
$database,
82-
$port
83-
)
84-
) {
85-
$db_link = mysqli_connect(
77+
if ($db_link = mysqli_connect(
8678
$server,
8779
$user,
8880
$pass,
8981
$database,
9082
$port
91-
);
83+
)
84+
) {
9285
$db_link->set_charset(DB_ENCODING);
9386
} else {
9487
$res = 'Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error());

install/upgrade_run_3.0.0_logs.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,14 @@
6969
$port = DB_PORT;
7070
$user = DB_USER;
7171

72-
if (mysqli_connect(
72+
if ($db_link = mysqli_connect(
7373
$server,
7474
$user,
7575
$pass,
7676
$database,
7777
$port
7878
)
7979
) {
80-
$db_link = mysqli_connect(
81-
$server,
82-
$user,
83-
$pass,
84-
$database,
85-
$port
86-
);
8780
$db_link->set_charset(DB_ENCODING);
8881
} else {
8982
$res = 'Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error());
@@ -163,7 +156,7 @@
163156
);
164157

165158
// Encrypt with Object Key
166-
$cryptedStuff = doDataEncryption($passwd['string']);
159+
$cryptedStuff = doDataEncryption(html_entity_decode($passwd['string']));
167160

168161
// Store new password in DB
169162
mysqli_query(

0 commit comments

Comments
 (0)