[Rt-commit] rt branch, 4.6/log-view-db-config-change-history, repushed
Aaron Trevena
ast at bestpractical.com
Tue Mar 10 14:24:00 EDT 2020
The branch 4.6/log-view-db-config-change-history was deleted and repushed:
was 977afe17e3c7dcea36d9d1022bb1fd7b42a5c5ca
now e8aa052571775de3552356a39537070e5b617586
1: fcbb76ce2 ! 1: 4bd810170 Schema updates for tracking db configuration changes in transactions
@@ -19,9 +19,9 @@
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
--CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
-
+ CREATE INDEX Configurations2 ON Configurations (Disabled);
+-
diff --git a/etc/schema.Pg b/etc/schema.Pg
--- a/etc/schema.Pg
@@ -35,25 +35,13 @@
OldValue varchar(255) NULL ,
NewValue varchar(255) NULL ,
ReferenceType varchar(255) NULL,
- OldReference integer NULL ,
- NewReference integer NULL ,
- Data varchar(255) NULL ,
--
- Creator integer NOT NULL DEFAULT 0 ,
-- Created TIMESTAMP NULL ,
-+ Created TIMESTAMP NULL,
- PRIMARY KEY (id)
--
- );
- CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId);
-
@@
PRIMARY KEY (id)
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
--CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
+ CREATE INDEX Configurations2 ON Configurations (Disabled);
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
@@ -68,24 +56,13 @@
OldValue varchar(255) collate NOCASE NULL ,
NewValue varchar(255) collate NOCASE NULL ,
ReferenceType varchar(255) collate NOCASE NULL ,
- OldReference integer NULL ,
- NewReference integer NULL ,
- Data varchar(255) collate NOCASE NULL ,
--
- Creator integer NULL DEFAULT 0 ,
-- Created DATETIME NULL
--
-+ Created DATETIME NULL
- ) ;
- CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId);
-
@@
LastUpdated timestamp DEFAULT NULL
);
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
--CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
+ CREATE INDEX Configurations2 ON Configurations (Disabled);
diff --git a/etc/schema.mysql b/etc/schema.mysql
@@ -100,71 +77,14 @@
OldValue varchar(255) NULL ,
NewValue varchar(255) NULL ,
ReferenceType varchar(255) CHARACTER SET ascii NULL,
- OldReference integer NULL ,
- NewReference integer NULL ,
- Data varchar(255) NULL ,
--
- Creator integer NOT NULL DEFAULT 0 ,
- Created DATETIME NULL ,
- PRIMARY KEY (id)
@@
PRIMARY KEY (id)
) ENGINE=InnoDB CHARACTER SET utf8mb4;
-CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
--CREATE INDEX Configurations2 ON Configurations (Disabled);
+CREATE INDEX Configurations1 ON Configurations (Name(128), Disabled);
+ CREATE INDEX Configurations2 ON Configurations (Disabled);
-
-diff --git a/etc/upgrade/4.5.1/schema.Oracle b/etc/upgrade/4.5.1/schema.Oracle
---- a/etc/upgrade/4.5.1/schema.Oracle
-+++ b/etc/upgrade/4.5.1/schema.Oracle
-@@
- LastUpdated DATE
- );
-
--CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
--CREATE INDEX Configurations2 ON Configurations (Disabled);
-+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
-+
-+
-
-diff --git a/etc/upgrade/4.5.1/schema.Pg b/etc/upgrade/4.5.1/schema.Pg
---- a/etc/upgrade/4.5.1/schema.Pg
-+++ b/etc/upgrade/4.5.1/schema.Pg
-@@
- PRIMARY KEY (id)
- );
-
--CREATE UNIQUE INDEX Configurations1 ON Configurations (LOWER(Name));
--CREATE INDEX Configurations2 ON Configurations (Disabled);
-+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
-+
-+
-
-diff --git a/etc/upgrade/4.5.1/schema.SQLite b/etc/upgrade/4.5.1/schema.SQLite
---- a/etc/upgrade/4.5.1/schema.SQLite
-+++ b/etc/upgrade/4.5.1/schema.SQLite
-@@
- LastUpdated timestamp DEFAULT NULL
- );
-
--CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
--CREATE INDEX Configurations2 ON Configurations (Disabled);
-+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
-
-
-diff --git a/etc/upgrade/4.5.1/schema.mysql b/etc/upgrade/4.5.1/schema.mysql
---- a/etc/upgrade/4.5.1/schema.mysql
-+++ b/etc/upgrade/4.5.1/schema.mysql
-@@
- PRIMARY KEY (id)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
--CREATE UNIQUE INDEX Configurations1 ON Configurations (Name);
--CREATE INDEX Configurations2 ON Configurations (Disabled);
-+CREATE INDEX Configurations1 ON Configurations (Name(128), Disabled);
-+
diff --git a/etc/upgrade/4.5.3/schema.Oracle b/etc/upgrade/4.5.3/schema.Oracle
new file mode 100644
@@ -173,6 +93,10 @@
@@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR2(255);
++
++DROP INDEX Configurations1;
++CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
+\ No newline at end of file
diff --git a/etc/upgrade/4.5.3/schema.Pg b/etc/upgrade/4.5.3/schema.Pg
new file mode 100644
@@ -181,6 +105,10 @@
@@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) NULL;
++
++DROP INDEX IF EXISTS Configurations1;
++CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
+\ No newline at end of file
diff --git a/etc/upgrade/4.5.3/schema.SQLite b/etc/upgrade/4.5.3/schema.SQLite
new file mode 100644
@@ -189,6 +117,10 @@
@@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) collate NOCASE NULL;
++
++DROP INDEX IF EXISTS Configurations1;
++CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
+\ No newline at end of file
diff --git a/etc/upgrade/4.5.3/schema.mysql b/etc/upgrade/4.5.3/schema.mysql
new file mode 100644
@@ -197,5 +129,32 @@
@@
+-- Add transaction support for new config in database feature
+ALTER TABLE Transactions MODIFY Field VARCHAR(255) CHARACTER SET ascii DEFAULT NULL;
++
++DROP INDEX IF EXISTS Configurations1;
++CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
\ No newline at end of file
+diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
+--- a/lib/RT/Transaction.pm
++++ b/lib/RT/Transaction.pm
+@@
+ Type =>
+ {read => 1, write => 1, sql_type => 12, length => 20, is_blob => 0, is_numeric => 0, type => 'varchar(20)', default => ''},
+ Field =>
+- {read => 1, write => 1, sql_type => 12, length => 40, is_blob => 0, is_numeric => 0, type => 'varchar(40)', default => ''},
++ {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
+ OldValue =>
+ {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
+ NewValue =>
+
+diff --git a/share/html/Admin/Tools/EditConfig.html b/share/html/Admin/Tools/EditConfig.html
+--- a/share/html/Admin/Tools/EditConfig.html
++++ b/share/html/Admin/Tools/EditConfig.html
+@@
+ % }
+ </div><!-- content-all -->
+ </div><!-- titlebox-content -->
+-</div><!-- configuration -->
+\ No newline at end of file
++</div><!-- configuration -->
+
2: aa03eafe0 ! 2: dd73ca770 Log DB config changes as transactions
@@ -21,15 +21,25 @@
--- a/lib/RT/Configuration.pm
+++ b/lib/RT/Configuration.pm
@@
+ $args{'ContentType'} = 'perl';
+ }
+
+- my $old_value = RT->Config->Get($args{Name});
+- unless (defined($old_value) && length($old_value)) {
+- $old_value = $self->loc('(no value)');
+- }
+-
+ ( $id, $msg ) = $self->SUPER::Create(
+ map { $_ => $args{$_} } grep {exists $args{$_}}
+ qw(Name Content ContentType),
+@@
$content = $self->loc('(no value)');
}
-+ my $old_content_type;
- if ( ref $old_value ) {
- $old_value = $self->_SerializeContent($old_value);
-+ $old_content_type = 'perl';
- }
-
+- if ( ref $old_value ) {
+- $old_value = $self->_SerializeContent($old_value);
+- }
+-
- RT->Logger->info(
- sprintf(
- '%s changed %s from "%s" to "%s"',
@@ -43,20 +53,13 @@
+ Field => $self->Name,
+ ObjectType => 'RT::Configuration',
+ ObjectId => $self->id,
-+ NewValue => ( $args{content_type} ) ? sprintf('%s value', $args{content_type}) : $content,
-+ OldValue => ( $old_content_type ) ? sprintf('%s value', $old_content_type) : $old_value,
+ ReferenceType => ref($self),
+ NewReference => $self->id,
);
- return ( $id, $self->loc( '[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $content // '' ) );
+
-+ if (not ($old_content_type || $args{content_type}) ) {
-+ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name . " from " . $old_value . " to " . $content);
-+ return ($id, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $content // ''));
-+ } else {
-+ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
-+ return ($id, $self->loc("[_1] changed", $self->Name));
-+ }
++ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
++ return ($id, $self->loc("[_1] changed", $self->Name));
}
=head2 CurrentUserCanSee
@@ -65,7 +68,6 @@
my $self = shift;
return (0, $self->loc("Permission Denied")) unless $self->CurrentUserCanSee;
- my ($ok, $msg) = $self->SUPER::Delete(@_);
-+ my $old_value = ( ref $self->Content ) ? sprintf('%s value', $self->ContentType) : $self->Content;
+ my ( $ok, $msg ) = $self->SetDisabled( 1 );
return ($ok, $msg) if !$ok;
RT->Config->ApplyConfigChangeToAllServerProcesses;
@@ -76,34 +78,26 @@
+ Field => $self->Name,
+ ObjectType => 'RT::Configuration',
+ ObjectId => $self->Id,
-+ NewValue => $self->loc("Deleted"),
+ ReferenceType => ref($self),
+ OldReference => $self->id,
-+ OldValue => $old_value,
+ );
+
return ($ok, $self->loc("Database setting removed."));
}
@@
- $content_type = 'perl';
}
-- $RT::Handle->BeginTransaction;
-+ ( $ok, $msg ) = $self->SetDisabled( 1 );
-+ return ($ok, $msg) if !$ok;
-
+ $RT::Handle->BeginTransaction;
+-
- ($ok, $msg) = $self->_Set( Field => 'Content', Value => $value );
- if (!$ok) {
-- $RT::Handle->Rollback;
++ ( $ok, $msg ) = $self->SetDisabled( 1 );
++ unless ($ok) {
+ $RT::Handle->Rollback;
- return ($ok, $self->loc("Unable to update [_1]: [_2]", $self->Name, $msg));
-- }
-+ my ( $new_id, $new_msg ) = $self->SUPER::Create(
-+ Name => $self->Name,
-+ Content => $value,
-+ ContentType => $content_type,
-+ Disabled => 0,
-+ );
++ return ($ok, $msg);
+ }
- if ($self->ContentType ne $content_type) {
- ($ok, $msg) = $self->_Set( Field => 'ContentType', Value => $content_type );
@@ -111,7 +105,15 @@
- $RT::Handle->Rollback;
- return ($ok, $self->loc("Unable to update [_1]: [_2]", $self->Name, $msg));
- }
++ my ( $new_id, $new_msg ) = $self->SUPER::Create(
++ Name => $self->Name,
++ Content => $value,
++ ContentType => $content_type,
++ Disabled => 0,
++ );
++
+ unless ($new_id) {
++ $RT::Handle->Rollback;
+ return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $self->Name, $value, $new_msg));
}
@@ -123,35 +125,28 @@
}
- if (!ref($value) && !ref($old_value)) {
+- RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name . " from " . $old_value . " to " . $value);
+- return ($ok, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value, $value));
+- } else {
+- RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
+- return ($ok, $self->loc("[_1] changed", $self->Name));
+- }
+ my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+ Type => 'SetConfig',
+ Field => $self->Name,
+ ObjectType => 'RT::Configuration',
+ ObjectId => $new_id,
-+ NewValue => ( $content_type ) ? sprintf('%s value', $content_type) : $value,
-+ OldValue => ( $self->ContentType ) ? sprintf('%s value', $self->ContentType) : $self->Content,
+ ReferenceType => ref($self),
+ OldReference => $self->id,
+ NewReference => $new_id,
+ );
+
-+ if ( not ($self->ContentType || $content_type) ) {
- RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name . " from " . $old_value . " to " . $value);
- return ($ok, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value, $value));
- } else {
-
-diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
---- a/lib/RT/Transaction.pm
-+++ b/lib/RT/Transaction.pm
-@@
- Type =>
- {read => 1, write => 1, sql_type => 12, length => 20, is_blob => 0, is_numeric => 0, type => 'varchar(20)', default => ''},
- Field =>
-- {read => 1, write => 1, sql_type => 12, length => 40, is_blob => 0, is_numeric => 0, type => 'varchar(40)', default => ''},
-+ {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
- OldValue =>
- {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
- NewValue =>
++ $RT::Handle->Commit;
++ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
++ return( 1, $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value || '', $value || '') );
+ }
+
+ =head2 ValidateContent
diff --git a/share/html/Admin/Tools/EditConfig.html b/share/html/Admin/Tools/EditConfig.html
--- a/share/html/Admin/Tools/EditConfig.html
@@ -191,19 +186,4 @@
my ($ok, $msg) = $setting->SetContent($val);
push @results, $msg;
$has_error++ if !$ok;
-@@
- $RT::Handle->Commit;
- }
- RT->Config->EndDatabaseConfigChanges;
-+ RT->Config->ApplyConfigChangeToAllServerProcesses unless ($has_error);
- }
-
- my $nav_type='tab'; # 'tab' or 'pill'
-@@
- % }
- </div><!-- content-all -->
- </div><!-- titlebox-content -->
--</div><!-- configuration -->
-\ No newline at end of file
-+</div><!-- configuration -->
3: 7b2f1812b ! 3: 985d54402 Page to view DB config transaction history
@@ -1,6 +1,6 @@
Author: Aaron Trevena <ast at bestpractical.com>
- Log DB config changes as transactions
+ Page to view DB config transaction history
Added page to view transaction log or configurations
@@ -38,53 +38,32 @@
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@
- return ( 0, $self->loc( "Transaction->Create couldn't, as you didn't specify an object type and id"));
- }
-
--
--
- #lets create our transaction
- my %params = (
- Type => $args{'Type'},
-@@
my $self = shift;
return "Attachment content modified";
},
+ SetConfig => sub {
+ my $self = shift;
-+ my $new_value = $self->NewValue;
-+ my $old_value = $self->OldValue;
++ my ($new_value, $old_value);
+
-+ # pull in old value from reference if data structure
-+ if ($old_value =~ m/^(perl|json).value$/) {
++ # pull in old value from reference if exists
++ if ( $self->OldReference ) {
+ my $oldobj = RT::Configuration->new($self->CurrentUser);
+ $oldobj->Load($self->OldReference);
+ $old_value = $oldobj->Content;
+ }
+
-+ # pull in new value from reference if data structure
-+ if ($new_value =~ m/^(perl|json).value$/) {
++ # pull in new value from reference if exists
++ if ( $self->NewReference ) {
+ my $newobj = RT::Configuration->new($self->CurrentUser);
+ $newobj->Load($self->NewReference);
+ $new_value = $newobj->Content;
+ }
-+
-+ my $description = sprintf('<b>%s updated %s</b><br/>%s', $self->CreatorObj->Name, $self->Field, "\n");
-+ $description .= $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value || '', $new_value || '');
++ my $description .= $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value || '', $new_value || '');
+ return $description;
+ },
+ DeleteConfig => sub {
+ my $self = shift;
-+ my $description = sprintf('<b>%s deleted %s</b><br/>%s', $self->CreatorObj->Name, $self->Field,"\n");
-+ my $old_value = $self->OldValue;
-+ # pull in old value from reference if data structure
-+ if ($old_value =~ m/^(perl|json).value$/) {
-+ my $oldobj = RT::Configuration->new($self->CurrentUser);
-+ $oldobj->Load($self->OldReference);
-+ $old_value = $oldobj->Content;
-+ }
-+
-+ $description .= $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value, $self->loc("Deleted"));
++ my $description = $self->loc('[_1] Deleted"', $self->Field);
+ return $description;
+ }
);
@@ -92,21 +71,20 @@
@@
+ =cut
+
++# Note this will cause errors in /Transaction/Display.html for some non-ticket objects
++# such as RT::Configuration, pass DisplayPath => '#' to not link to /Transaction/Display.html
sub CustomFieldLookupType {
- "RT::Queue-RT::Ticket-RT::Transaction";
-+ my $self = shift;
-+
-+ # skip if it's a table/class with no custom fields
-+ if (ref($self) && ($self->ObjectType =~ m/RT::(Configuration)/)) {
-+ return "";
-+ }
-+ else {
-+ return "RT::Queue-RT::Ticket-RT::Transaction";
-+ }
++ "RT::Queue-RT::Ticket-RT::Transaction"
}
+-
+ =head2 SquelchMailTo
+ Similar to Ticket class SquelchMailTo method - returns a list of
diff --git a/share/html/Admin/Tools/ConfigHistory.html b/share/html/Admin/Tools/ConfigHistory.html
new file mode 100644
@@ -163,40 +141,32 @@
+<%INIT>
+my $title = loc('System Configuration');
+unless ($session{'CurrentUser'}->HasRight( Object=> $RT::System, Right => 'SuperUser')) {
-+ Abort(loc('This feature is only available to system administrators'));
++ Abort(loc('This feature is only available to system administrators'));
+}
-+
-+# get the transactions?
-+# start off just getting all of them!
+
+my $Transactions = RT::Transactions->new($session{CurrentUser});
+$Transactions->Limit(FIELD => 'ObjectType', VALUE => 'RT::Configuration');
+$Transactions->OrderBy(FIELD => 'Created', ORDER => 'DESC');
+</%INIT>
+<& /Admin/Elements/Header, Title => $title &>
-+<& /Elements/Tabs &>
++ <& /Elements/Tabs &>
+ <div class="configuration">
-+ <div class="history configurations" id="configurations">
-+ <& /Widgets/TitleBoxStart, title => $title, class => 'fullwidth' &>
-+ </div>
-+<div class="history-container">
++ <& /Admin/Elements/ConfigHelp &>
++ <&|/Widgets/TitleBox, title => loc('History'), class => 'fullwidth' &>
+% my $i = 1;
+% while (my $tx = $Transactions->Next()) {
-+<& /Elements/ShowTransaction,
++ <& /Elements/ShowTransaction,
+ Transaction => $tx,
+ ShowHeaders => 1,
+ ShowDisplayModes => 0,
+ ShowActions => 1,
++ DisplayPath => '#',
+ HasTxnCFs => 0,
+ RowNum => $i
-+&>
++ &>
+% $i++;
+% }
-+</div>
++ </&>
+ </div>
-+</div>
-+<hr class="clear">
-+</div>
-+</div>
+
4: 977afe17e ! 4: e8aa05257 Tests for DB config transactions and history
@@ -1,6 +1,6 @@
Author: Aaron Trevena <ast at bestpractical.com>
- Log DB config changes as transactions
+ Tests for DB config transactions and history
Added unit tests for storing and viewing Configuration change history in transactions
@@ -63,15 +63,11 @@
+
+sub check_history_page_item {
+ my ($tx, $change) = @_;
-+ my $link = "/Transaction/Display.html?id=".$tx->id;
++ my $link = sprintf('#?id=%d#txn-%d', $tx->ObjectId,$tx->id);
+ ok($m->find_link(url => $link), 'found tx link in history');
-+
-+ my $link_m = $m->clone;
-+ $link_m->get_ok($link, 'fetched tx link in history ok');
-+ $link_m->content_contains(stringify($change->{new_value}), 'fetched tx has new value');
-+ $link_m->content_contains( "$change->{setting} changed from", 'fetched tx has changed field');
++ $m->content_contains(stringify($change->{new_value}), 'fetched tx has new value');
++ $m->content_contains( "$change->{setting} changed from", 'fetched tx has changed field');
+}
-+
+
sub stringify {
my $value = shift;
More information about the rt-commit
mailing list