-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1926081 - Add modification_time datetime column to profiles table…
… denoting when the profile was last updated (schema only)
- Loading branch information
Showing
3 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ use Bugzilla::Field; | |
use Date::Parse; | ||
use Date::Format; | ||
use IO::File; | ||
use List::MoreUtils qw(uniq); | ||
use List::Util qw(max uniq); | ||
use URI; | ||
use URI::QueryParam; | ||
|
||
|
@@ -838,6 +838,9 @@ sub update_table_definitions { | |
# Bug 1803658 - [email protected] | ||
$dbh->bz_alter_column('ts_error', 'message', {TYPE => 'TEXT', NOTNULL => 1}); | ||
|
||
# Bug 1926081 - [email protected] | ||
_migrate_profiles_modification_ts(); | ||
|
||
################################################################ | ||
# New --TABLE-- changes should go *** A B O V E *** this point # | ||
################################################################ | ||
|
@@ -4437,6 +4440,39 @@ sub _update_see_also_any_url { | |
} | ||
} | ||
|
||
sub _migrate_profiles_modification_ts { | ||
my $dbh = Bugzilla->dbh; | ||
|
||
return if $dbh->bz_column_info('profiles', 'modification_ts'); | ||
|
||
$dbh->bz_add_column('profiles', 'modification_ts', {TYPE => 'DATETIME'}); | ||
|
||
my $sth = $dbh->prepare( | ||
'UPDATE profiles SET modification_ts = FROM_UNIXTIME(?) WHERE userid = ?'); | ||
|
||
my $user_ids | ||
= $dbh->selectall_arrayref('SELECT userid FROM profiles ORDER BY userid'); | ||
foreach my $user_id (@{$user_ids}) { | ||
my ($audit_log_when) = $dbh->selectrow_array( | ||
'SELECT UNIX_TIMESTAMP(at_time) FROM audit_log | ||
WHERE class = \'Bugzilla::User\' AND object_id = ? ORDER BY at_time DESC ' | ||
. $dbh->sql_limit(1), undef, $user_id | ||
); | ||
my ($profiles_act_when) = $dbh->selectrow_array( | ||
'SELECT UNIX_TIMESTAMP(profiles_when) FROM profiles_activity | ||
WHERE userid = ? ORDER BY profiles_when DESC ' | ||
. $dbh->sql_limit(1), undef, $user_id | ||
); | ||
|
||
# We use unix timestamps to make value comparison easier | ||
my $modification_ts = max($audit_log_when, $profiles_act_when); | ||
$sth->execute($modification_ts, $user_id); | ||
} | ||
|
||
$dbh->bz_alter_column('profiles', 'modification_ts', | ||
{TYPE => 'DATETIME', NOTNULL => 1}); | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters