Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
b13178e7
Commit
b13178e7
authored
Jun 01, 2017
by
Ilya Tregubov
Committed by
Robert Lyon
Sep 04, 2017
Browse files
Bug #1694342: clean password from event_log takes long time
behatnotneeded Change-Id: Ic511e25066ebd84b80118e71f70c6f867a3564b4
parent
9ec57cc0
Changes
1
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/db/upgrade.php
View file @
b13178e7
...
...
@@ -4885,28 +4885,49 @@ function xmldb_core_upgrade($oldversion=0) {
}
if
(
$oldversion
<
2016090223
)
{
if
(
$records
=
get_records_sql_array
(
"SELECT event, data, time FROM
{
event_log
}
WHERE event = ?"
,
array
(
'createuser'
)))
{
log_debug
(
'Remove sensitive data from event_log'
);
$count
=
0
;
$limit
=
1000
;
$total
=
count
(
$records
);
foreach
(
$records
as
$record
)
{
$where
=
clone
$record
;
$data
=
json_decode
(
$record
->
data
);
if
(
isset
(
$data
->
password
))
{
unset
(
$data
->
password
);
$cleandata
=
json_encode
(
$data
);
$record
->
data
=
$cleandata
;
update_record
(
'event_log'
,
$record
,
$where
);
set_field
(
'usr'
,
'passwordchange'
,
1
,
'username'
,
$data
->
username
);
}
$count
++
;
if
((
$count
%
$limit
)
==
0
||
$count
==
$total
)
{
log_debug
(
"
$count
/
$total
"
);
set_time_limit
(
30
);
}
}
}
// These are the records with passwords in the data.
if
(
$records
=
get_records_sql_array
(
"SELECT event, data, time
FROM
{
event_log
}
WHERE event = ?
AND position(',
\"
password
\"
:
\"\"
,' in data) = 0
"
,
array
(
'createuser'
)))
{
log_debug
(
'Remove sensitive data from event_log'
);
$count
=
0
;
$limit
=
1000
;
$total
=
count
(
$records
);
foreach
(
$records
as
$record
)
{
$where
=
clone
$record
;
$data
=
json_decode
(
$record
->
data
);
if
(
isset
(
$data
->
password
))
{
unset
(
$data
->
password
);
$cleandata
=
json_encode
(
$data
);
$record
->
data
=
$cleandata
;
update_record
(
'event_log'
,
$record
,
$where
);
set_field
(
'usr'
,
'passwordchange'
,
1
,
'username'
,
$data
->
username
);
}
$count
++
;
if
((
$count
%
$limit
)
==
0
||
$count
==
$total
)
{
log_debug
(
"
$count
/
$total
"
);
set_time_limit
(
30
);
}
}
}
// These are the records with empty passwords in the data.
// No need for them to reset the password.
log_debug
(
'Update sensitive data from event_log'
);
$sql_count
=
"SELECT COUNT(*)
FROM
{
event_log
}
WHERE event = ?
AND position(',
\"
password
\"
:
\"\"
,' in data) > 0"
;
$count
=
get_field_sql
(
$sql_count
,
array
(
'createuser'
));
if
(
$count
>
0
)
{
$sql
=
"UPDATE
{
event_log
}
SET data = replace(data, ',
\"
password
\"
:
\"\"
', '')
WHERE event = ?
AND position(',
\"
password
\"
:
\"\"
,' in data) > 0"
;
execute_sql
(
$sql
,
array
(
'createuser'
));
}
log_debug
(
"
$count
records updated."
);
}
return
$status
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment