[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-432-g829683e
Shawn Moore
shawn at bestpractical.com
Thu Mar 23 17:22:35 EDT 2017
The branch, 4.4/serialize-json-initialdata has been updated
via 829683e22417179c4aa49a9c95e4267e286bb8b1 (commit)
from aacd6f0c8bbbe4165dea120982549db56b5e77e6 (commit)
Summary of changes:
sbin/rt-merge-initialdata.in | 59 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 50 insertions(+), 9 deletions(-)
- Log -----------------------------------------------------------------
commit 829683e22417179c4aa49a9c95e4267e286bb8b1
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Mar 23 21:19:33 2017 +0000
Handle simple scalar column updates
diff --git a/sbin/rt-merge-initialdata.in b/sbin/rt-merge-initialdata.in
index b569b30..7674949 100644
--- a/sbin/rt-merge-initialdata.in
+++ b/sbin/rt-merge-initialdata.in
@@ -46,6 +46,7 @@
# those contributions and any derivatives thereof.
#
# END BPS TAGGED BLOCK }}}
+use 5.010;
use strict;
use warnings;
@@ -78,6 +79,7 @@ use RT;
RT::LoadConfig();
RT::Init();
+use List::MoreUtils 'uniq';
use JSON ();
my $JSON = JSON->new->canonical;
@@ -96,6 +98,10 @@ my @record_types = qw/Groups Users Members ACL Queues Classes
CustomFields CustomRoles Scrips
Catalogs Assets Articles/;
+my %class_type = (
+ Members => 'GroupMembers',
+);
+
for my $type (@record_types) {
my ($new_records, $updated_records, $deleted_records) = find_differences(
$base_records->{$type},
@@ -103,9 +109,50 @@ for my $type (@record_types) {
$type,
);
- my $collection_class = "RT::$type";
+ my $collection_class = "RT::" . ($class_type{$type} || $type);
my $record_class = $collection_class->RecordClass;
+ for (@$updated_records) {
+ my ($base, $edited) = @$_;
+ my $id = $base->{id};
+ my $record = $record_class->new(RT->SystemUser);
+ $record->Load($id);
+ if (!$record->Id) {
+ RT->Logger->error("Unable to load $record_class $id for updating; skipping");
+ next;
+ }
+
+ for my $column (uniq sort keys(%$base), keys(%$edited)) {
+ my $base_value = $base->{$column} // "";
+ my $edited_value = $edited->{$column} // "";
+
+ for ($base_value, $edited_value) {
+ $_ = !!$_ if JSON::is_bool($_)
+ }
+
+ if (!ref($base_value) && !ref($edited_value)) {
+ next if $base_value eq $edited_value;
+
+ my $method = "Set$column";
+ if ($record->can($method) || $record->_Accessible($column, 'write')) {
+ my ($ok, $msg) = $record->$method($edited_value);
+ if ($ok) {
+ RT->Logger->debug("Updated $record_class #$id $column: $msg");
+ }
+ else {
+ RT->Logger->error("Unable to update $record_class #$id $column: $msg");
+ }
+ }
+ else {
+ die "Unable to handle updating $record_class $column (no method)";
+ }
+ }
+ else {
+ die "Unable to handle updating $record_class $column (composite value)";
+ }
+ }
+ }
+
for my $new (@$new_records) {
my $record = $record_class->new(RT->SystemUser);
}
@@ -127,18 +174,12 @@ for my $type (@record_types) {
}
if ($ok) {
- RT->Logger->debug("Deleted $record_class $id: $msg");
+ RT->Logger->debug("Deleted $record_class #$id: $msg");
}
else {
- RT->Logger->error("Unable to delete $record_class $id: $msg");
+ RT->Logger->error("Unable to delete $record_class #$id: $msg");
}
}
-
- for (@$updated_records) {
- my ($base, $edited) = @_;
- my $record = $record_class->new(RT->SystemUser);
- $record->Load($base->{id});
- }
}
sub find_differences {
-----------------------------------------------------------------------
More information about the rt-commit
mailing list