[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-436-g0c8e730
Shawn Moore
shawn at bestpractical.com
Thu Mar 23 17:43:19 EDT 2017
The branch, 4.4/serialize-json-initialdata has been updated
via 0c8e730601744245269479a83e690eefca3037be (commit)
via baf2ea482f9aa6ea3b00e920d112cc2475653ef8 (commit)
via 82dc029efcd09e4020cd15cb1bd5bc4dd45c90a0 (commit)
from a2632fca5042bdf92dd783962a96f5d33586bdeb (commit)
Summary of changes:
sbin/rt-merge-initialdata.in | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
- Log -----------------------------------------------------------------
commit 82dc029efcd09e4020cd15cb1bd5bc4dd45c90a0
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Mar 23 21:38:42 2017 +0000
Avoid blowing up on comparing scalars
diff --git a/sbin/rt-merge-initialdata.in b/sbin/rt-merge-initialdata.in
index 0a52329..5ef1dbd 100644
--- a/sbin/rt-merge-initialdata.in
+++ b/sbin/rt-merge-initialdata.in
@@ -224,7 +224,8 @@ sub find_differences {
sub is_deeply_equal {
my ($left, $right) = @_;
- return $JSON->encode($left) eq $JSON->encode($right);
+ # use [] to avoid nonref issues without changing $JSON itself
+ return $JSON->encode([$left]) eq $JSON->encode([$right]);
}
sub slurp_json {
commit baf2ea482f9aa6ea3b00e920d112cc2475653ef8
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Mar 23 21:38:59 2017 +0000
Avoid spurious warnings when base!=edited but edited=current
diff --git a/sbin/rt-merge-initialdata.in b/sbin/rt-merge-initialdata.in
index 5ef1dbd..f5ea2ca 100644
--- a/sbin/rt-merge-initialdata.in
+++ b/sbin/rt-merge-initialdata.in
@@ -135,6 +135,9 @@ for my $type (@record_types) {
if (!ref($base_value) && !ref($edited_value)) {
my $method = "Set$column";
if ($record->can($method) || $record->_Accessible($column, 'write')) {
+ # skip if it was already updated outside initialdata
+ next if ($record->$method//"") eq $edited_value;
+
my ($ok, $msg) = $record->$method($edited_value);
if ($ok) {
RT->Logger->debug("Updated $record_class #$id $column: $msg");
commit 0c8e730601744245269479a83e690eefca3037be
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Thu Mar 23 21:39:17 2017 +0000
Reuse InsertData
This is bananas. It relies on a quirk of Perl's "open" function
which treats the filename as its content if you pass it as a reference.
In other words:
my $json = JSON->encode({ ... });
open my $handle, '<', \$json;
Will have $handle vend the $json content.
This lets us reuse RT::Handle::InsertData without a large refactor
diff --git a/sbin/rt-merge-initialdata.in b/sbin/rt-merge-initialdata.in
index f5ea2ca..bbdaea3 100644
--- a/sbin/rt-merge-initialdata.in
+++ b/sbin/rt-merge-initialdata.in
@@ -102,6 +102,8 @@ my %class_type = (
Members => 'GroupMembers',
);
+my %new_for_insertdata;
+
for my $type (@record_types) {
my ($new_records, $updated_records, $deleted_records) = find_differences(
$base_records->{$type},
@@ -112,6 +114,8 @@ for my $type (@record_types) {
my $collection_class = "RT::" . ($class_type{$type} || $type);
my $record_class = $collection_class->RecordClass;
+ $new_for_insertdata{$type} = $new_records;
+
for (@$updated_records) {
my ($base, $edited) = @$_;
my $id = $base->{id};
@@ -156,10 +160,6 @@ for my $type (@record_types) {
}
}
- for my $new (@$new_records) {
- my $record = $record_class->new(RT->SystemUser);
- }
-
for my $deleted (@$deleted_records) {
my $id = $deleted->{id};
my $record = $record_class->new(RT->SystemUser);
@@ -185,6 +185,9 @@ for my $type (@record_types) {
}
}
+my $new_json = $JSON->encode(\%new_for_insertdata);
+$RT::Handle->InsertData(\$new_json, undef, disconnect_after => 0);
+
sub find_differences {
my $base_records = shift;
my $edited_records = shift;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list