[Rt-commit] rt branch, 4.6/log-view-db-config-change-history, repushed
Aaron Trevena
ast at bestpractical.com
Mon Mar 23 14:08:05 EDT 2020
The branch 4.6/log-view-db-config-change-history was deleted and repushed:
was 710cd648485be64847a1ac177805922c1ad67622
now b33406d3f291f9551dac64310645ffe94aa0ee68
1: 9082be19f8 ! 1: 039be68775 Schema updates for tracking db configuration changes in transactions
@@ -103,7 +103,7 @@
+++ b/etc/upgrade/4.5.3/schema.Pg
@@
+-- Add transaction support for new config in database feature
-+ALTER TABLE Transactions MODIFY Field VARCHAR(255) NULL;
++ALTER TABLE Transactions ALTER COLUMN Field TYPE varchar(255);
+
+DROP INDEX IF EXISTS Configurations1;
+CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
@@ -113,9 +113,6 @@
--- /dev/null
+++ b/etc/upgrade/4.5.3/schema.SQLite
@@
-+-- 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);
@@ -127,7 +124,7 @@
+-- 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;
++DROP INDEX Configurations1 ON Configurations;
+CREATE INDEX Configurations1 ON Configurations (Name, Disabled);
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
@@ -143,14 +140,3 @@
{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: 29ebb5fd04 ! 2: 9599eb692d Log DB config changes as transactions
@@ -38,32 +38,22 @@
- return (0, $error);
- }
- $args{'ContentType'} = 'perl';
-- }
--
++ ( $id, $msg ) = $self->_Create(%args);
++ unless ($id) {
++ return (0, $msg);
+ }
+
- my $old_value = RT->Config->Get($args{Name});
- unless (defined($old_value) && length($old_value)) {
- $old_value = $self->loc('(no value)');
-- }
--
++ my ($content, $error) = $self->Content;
++ unless (defined($content) && length($content)) {
++ $content = $self->loc('(no value)');
+ }
+
- ( $id, $msg ) = $self->SUPER::Create(
- map { $_ => $args{$_} } grep {exists $args{$_}}
- qw(Name Content ContentType),
-- );
-+ ( $id, $msg ) = $self->_Create(%args);
- unless ($id) {
-- return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $args{Name}, $args{Content}, $msg));
-+ return (0, $msg);
- }
-
-- RT->Config->ApplyConfigChangeToAllServerProcesses;
--
- my ($content, $error) = $self->Content;
- unless (defined($content) && length($content)) {
- $content = $self->loc('(no value)');
- }
-
-- if ( ref $old_value ) {
-- $old_value = $self->_SerializeContent($old_value);
+ my ( $Trans, $tx_msg, $TransObj ) = $self->_NewTransaction(
+ Type => 'SetConfig',
+ Field => $self->Name,
@@ -71,11 +61,25 @@
+ ObjectId => $self->id,
+ ReferenceType => ref($self),
+ NewReference => $self->id,
-+ );
+ );
+- unless ($id) {
+- return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $args{Name}, $args{Content}, $msg));
+ unless ($Trans) {
+ return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $args{Name}, $content, $tx_msg));
}
+ RT->Config->ApplyConfigChangeToAllServerProcesses;
+
+- my ($content, $error) = $self->Content;
+- unless (defined($content) && length($content)) {
+- $content = $self->loc('(no value)');
+- }
+-
++ my $old_value = RT->Config->Get($args{Name});
+ if ( ref $old_value ) {
+ $old_value = $self->_SerializeContent($old_value);
+ }
+-
- RT->Logger->info(
- sprintf(
- '%s changed %s from "%s" to "%s"',
@@ -85,10 +89,7 @@
- $content // ''
- )
- );
-+ RT->Config->ApplyConfigChangeToAllServerProcesses;
-+
-+ my $old_value = RT->Config->Get($args{Name});
-+ RT->Logger->info($self->CurrentUser->Name . " changed " . $self->Name);
++ RT->Logger->info($self->CurrentUser->Name . " changed " . $args{Name});
return ( $id, $self->loc( '[_1] changed from "[_2]" to "[_3]"', $self->Name, $old_value // '', $content // '' ) );
}
@@ -97,10 +98,14 @@
my $self = shift;
return (0, $self->loc("Permission Denied")) unless $self->CurrentUserCanSee;
- my ($ok, $msg) = $self->SUPER::Delete(@_);
+- return ($ok, $msg) if !$ok;
++
++ $RT::Handle->BeginTransaction;
+ my ( $ok, $msg ) = $self->SetDisabled( 1 );
- return ($ok, $msg) if !$ok;
- RT->Config->ApplyConfigChangeToAllServerProcesses;
- RT->Logger->info($self->CurrentUser->Name . " removed database setting for " . $self->Name);
++ unless ($ok) {
++ $RT::Handle->Rollback;
++ return ($ok, $msg);
++ }
+
+ my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
+ Type => 'DeleteConfig',
@@ -110,6 +115,10 @@
+ ReferenceType => ref($self),
+ OldReference => $self->id,
+ );
++
++ $RT::Handle->Commit;
+ RT->Config->ApplyConfigChangeToAllServerProcesses;
+ RT->Logger->info($self->CurrentUser->Name . " removed database setting for " . $self->Name);
+
return ($ok, $self->loc("Database setting removed."));
}
@@ -151,7 +160,7 @@
+ Name => $self->Name,
+ Content => $raw_value,
+ ContentType => $content_type,
-+ _Replace => 0
++ _Replace => 1
+ );
- ($ok, $msg) = $self->_Set( Field => 'Content', Value => $value );
@@ -186,12 +195,11 @@
+ return (0, $self->loc("Setting [_1] to [_2] failed: [_3]", $self->Name, $value, $tx_msg));
}
-- $RT::Handle->Commit;
+ $RT::Handle->Commit;
RT->Config->ApplyConfigChangeToAllServerProcesses;
- unless (defined($value) && length($value)) {
- $value = $self->loc('(no value)');
-+ $RT::Handle->Commit;
+ my ($old_value, $error) = $self->Content;
+ unless (defined($old_value) && length($old_value)) {
+ $old_value = $self->loc('(no value)');
3: 04b624e6ed ! 3: 1d4c3d4e4d Remove unused stringify function in configuration edit page
@@ -1,6 +1,6 @@
Author: Aaron Trevena <ast at bestpractical.com>
- remove unused stringify function in configuration edit page
+ Remove unused stringify function in configuration edit page
diff --git a/share/html/Admin/Tools/EditConfig.html b/share/html/Admin/Tools/EditConfig.html
--- a/share/html/Admin/Tools/EditConfig.html
4: 934901c888 ! 4: fee61e2cc9 Page to view DB config transaction history
@@ -15,9 +15,9 @@
- $page->child( display => title => loc('View'), path => "/Admin/Tools/Configuration.html" );
- $page->child( history => title => loc('Edit'), path => "/Admin/Tools/EditConfig.html" );
+ if ( $request_path =~ m{^/Admin/Tools/(Configuration|EditConfig|ConfigHistory)} ) {
-+ $page->child( "display", title => loc('View'), path => "/Admin/Tools/Configuration.html" );
-+ $page->child( "modify", title => loc('Edit'), path => "/Admin/Tools/EditConfig.html" );
-+ $page->child( "history", title => loc('History'), path => "/Admin/Tools/ConfigHistory.html" );
++ $page->child( "display" => title => loc('View'), path => "/Admin/Tools/Configuration.html" );
++ $page->child( "modify" => title => loc('Edit'), path => "/Admin/Tools/EditConfig.html" );
++ $page->child( "history" => title => loc('History'), path => "/Admin/Tools/ConfigHistory.html" );
}
# due to historical reasons of always having been in /Elements/Tabs
@@ -37,25 +37,21 @@
+ if ( $self->OldReference ) {
+ my $oldobj = RT::Configuration->new($self->CurrentUser);
+ $oldobj->Load($self->OldReference);
-+ $old_value = ($oldobj->ContentType =~ /(json|perl)/) ?
-+ sprintf('<pre>%s</pre>', $oldobj->Content) : $oldobj->Content;
++ $old_value = $oldobj->Content;
+ }
+
+ # 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->ContentType =~ /(json|perl)/) ?
-+ sprintf('<pre>%s</pre>', $newobj->Content) : $newobj->Content;
-+
++ $new_value = $newobj->Content;
+ }
-+ my $description = $self->loc('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value // '', $new_value // '');
-+ return $description;
++ #loc()
++ return ('[_1] changed from "[_2]" to "[_3]"', $self->Field, $old_value // '', $new_value // '');
+ },
+ DeleteConfig => sub {
+ my $self = shift;
-+ my $description = $self->loc('[_1] Deleted"', $self->Field);
-+ return $description;
++ return ('[_1] deleted"', $self->Field); #loc()
+ }
);
@@ -127,7 +123,8 @@
+ <& /Elements/Tabs &>
+ <div class="configuration history">
+ <& /Admin/Elements/ConfigHelp &>
-+ <&|/Widgets/TitleBox, title => loc('History') &>
++ <&|/Widgets/TitleBox, title => loc('History') &>
++ <div class="history-container">
+% my $i = 1;
+% while (my $tx = $Transactions->Next()) {
+ <& /Elements/ShowTransaction,
@@ -141,16 +138,8 @@
+ &>
+% $i++;
+% }
++</div>
+ </&>
+ </div>
+
-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 -->
-+
-
5: 710cd64848 ! 5: b33406d3f2 Tests for DB config transactions and history
@@ -58,7 +58,6 @@
+ is($tx->ObjectType, 'RT::Configuration', 'tx is config change');
+ is($tx->Field, $change->{setting}, 'tx matches field changed');
+ is($tx->NewValue, stringify($change->{new_value}), 'tx value matches');
-+ $change->{tx_id} = $tx->id;
+}
+
+sub check_history_page_item {
More information about the rt-commit
mailing list