[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-400-gc4eddbd
Shawn Moore
shawn at bestpractical.com
Wed Mar 22 14:17:42 EDT 2017
The branch, 4.4/serialize-json-initialdata has been updated
via c4eddbd1ab6fd489b8a4cfe59a22bcb04ac0c5fd (commit)
from eff1ba9470453bfc2348c07118c7a2c7c78c97d1 (commit)
Summary of changes:
lib/RT/Migrate/Serializer/JSON.pm | 32 +++++---
t/api/initialdata-roundtrip.t | 152 ++++++++++++++++++++++++++++++++++++++
2 files changed, 175 insertions(+), 9 deletions(-)
- Log -----------------------------------------------------------------
commit c4eddbd1ab6fd489b8a4cfe59a22bcb04ac0c5fd
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Mar 22 18:15:46 2017 +0000
Avoid throwing errors on disabled many-to-many relationships
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 6bf297b..4e66b25 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -253,7 +253,8 @@ sub _CanonicalizeManyToMany {
for my $primary (values %{ $self->{Records}{$primary_class} }) {
@{ $primary->{$primary_key} }
- = map &$canonicalize_object,
+ = grep defined,
+ map &$canonicalize_object,
sort { $a->{SortOrder} <=> $b->{SortOrder} }
@{ $primary->{$primary_key} || [] };
@@ -396,9 +397,10 @@ sub CanonicalizeObjects {
object_primary_ref => 'CustomField',
primary_class => 'RT::CustomField',
canonicalize_object => sub {
- ref($_->{ObjectId})
- ? $self->_GetSerializedByRef($_->{ObjectId})->{Name}
- : $_->{ObjectId};
+ my $id = $_->{ObjectId};
+ return $id if !ref($id);
+ my $serialized = $self->_GetSerializedByRef($id);
+ return $serialized ? $serialized->{Name} : undef;
},
);
@@ -418,6 +420,12 @@ sub CanonicalizeObjects {
object_class => 'RT::ObjectClass',
object_primary_ref => 'Class',
primary_class => 'RT::Class',
+ canonicalize_object => sub {
+ my $id = $_->{ObjectId};
+ return $id if !ref($id);
+ my $serialized = $self->_GetSerializedByRef($id);
+ return $serialized ? $serialized->{Name} : undef;
+ },
);
$self->_CanonicalizeManyToMany(
@@ -425,9 +433,10 @@ sub CanonicalizeObjects {
object_primary_ref => 'CustomRole',
primary_class => 'RT::CustomRole',
canonicalize_object => sub {
- ref($_->{ObjectId})
- ? $self->_GetSerializedByRef($_->{ObjectId})->{Name}
- : $_->{ObjectId};
+ my $id = $_->{ObjectId};
+ return $id if !ref($id);
+ my $serialized = $self->_GetSerializedByRef($id);
+ return $serialized ? $serialized->{Name} : undef;
},
);
@@ -443,8 +452,13 @@ sub CanonicalizeObjects {
canonicalize_object => sub {
my %object = %$_;
delete @object{qw/id Scrip/};
- $object{ObjectId} = $self->_GetSerializedByRef($object{ObjectId})->{Name}
- if $object{ObjectId}; # 0 meaning Global can stay 0
+
+ if (ref($_->{ObjectId})) {
+ my $serialized = $self->_GetSerializedByRef($_->{ObjectId});
+ return undef if !$serialized;
+ $object{ObjectId} = $serialized->{Name};
+ }
+
return \%object;
},
);
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 4db90b7..c6af165 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -468,6 +468,158 @@ my @tests = (
},
{
+ name => 'Disabled many-to-many relationships',
+ create => sub {
+ my $disabled_queue = RT::Queue->new(RT->SystemUser);
+ my ($ok, $msg) = $disabled_queue->Create(
+ Name => 'Disabled Queue',
+ );
+ ok($ok, $msg);
+
+ my $enabled_cf = RT::CustomField->new(RT->SystemUser);
+ ($ok, $msg) = $enabled_cf->Create(
+ Name => 'Enabled CF',
+ Type => 'FreeformSingle',
+ LookupType => RT::Ticket->CustomFieldLookupType,
+ );
+ ok($ok, $msg);
+
+ my $disabled_cf = RT::CustomField->new(RT->SystemUser);
+ ($ok, $msg) = $disabled_cf->Create(
+ Name => 'Disabled CF',
+ Type => 'FreeformSingle',
+ LookupType => RT::Ticket->CustomFieldLookupType,
+ );
+ ok($ok, $msg);
+
+ my $enabled_scrip = RT::Scrip->new(RT->SystemUser);
+ ($ok, $msg) = $enabled_scrip->Create(
+ Queue => 0,
+ Description => 'Enabled Scrip',
+ Template => 'Blank',
+ ScripCondition => 'On Create',
+ ScripAction => 'Notify Owner',
+ );
+ ok($ok, $msg);
+ $enabled_scrip->RemoveFromObject(0);
+
+ my $disabled_scrip = RT::Scrip->new(RT->SystemUser);
+ ($ok, $msg) = $disabled_scrip->Create(
+ Queue => 0,
+ Description => 'Disabled Scrip',
+ Template => 'Blank',
+ ScripCondition => 'On Create',
+ ScripAction => 'Notify Owner',
+ );
+ ok($ok, $msg);
+ $disabled_scrip->RemoveFromObject(0);
+
+ my $enabled_class = RT::Class->new(RT->SystemUser);
+ ($ok, $msg) = $enabled_class->Create(
+ Name => 'Enabled Class',
+ );
+ ok($ok, $msg);
+
+ my $disabled_class = RT::Class->new(RT->SystemUser);
+ ($ok, $msg) = $disabled_class->Create(
+ Name => 'Disabled Class',
+ );
+ ok($ok, $msg);
+
+ my $enabled_role = RT::CustomRole->new(RT->SystemUser);
+ ($ok, $msg) = $enabled_role->Create(
+ Name => 'Enabled Role',
+ );
+ ok($ok, $msg);
+
+ my $disabled_role = RT::CustomRole->new(RT->SystemUser);
+ ($ok, $msg) = $disabled_role->Create(
+ Name => 'Disabled Role',
+ );
+ ok($ok, $msg);
+
+ for my $object ($enabled_cf, $disabled_cf,
+ $enabled_scrip, $disabled_scrip,
+ $enabled_class, $disabled_class,
+ $enabled_role, $disabled_role) {
+
+ # slightly inconsistent API
+ my ($queue_a, $queue_b) = ($disabled_queue, $general);
+ ($queue_a, $queue_b) = ($queue_a->Id, $queue_b->Id)
+ if $object->isa('RT::Scrip')
+ || $object->isa('RT::CustomRole');
+
+ ($ok, $msg) = $object->AddToObject($queue_a);
+ ok($ok, $msg);
+
+ ($ok, $msg) = $object->AddToObject($queue_b);
+ ok($ok, $msg);
+ }
+
+ for my $object ($disabled_queue,
+ $disabled_cf,
+ $disabled_scrip,
+ $disabled_class,
+ $disabled_role) {
+ ($ok, $msg) = $object->SetDisabled(1);
+ ok($ok, $msg);
+ }
+ },
+ present => sub {
+ my $from_initialdata = shift;
+
+ my $disabled_queue = RT::Queue->new(RT->SystemUser);
+ $disabled_queue->Load('Disabled Queue');
+
+ my $enabled_cf = RT::CustomField->new(RT->SystemUser);
+ $enabled_cf->Load('Enabled CF');
+ ok($enabled_cf->Id, 'loaded Enabled CF');
+ is($enabled_cf->Name, 'Enabled CF', 'Enabled CF Name');
+ ok($enabled_cf->IsAdded($general->Id), 'Enabled CF added to General');
+
+ my $disabled_cf = RT::CustomField->new(RT->SystemUser);
+ $disabled_cf->Load('Disabled CF');
+
+ my $enabled_scrip = RT::Scrip->new(RT->SystemUser);
+ $enabled_scrip->LoadByCols(Description => 'Enabled Scrip');
+ ok($enabled_scrip->Id, 'loaded Enabled Scrip');
+ is($enabled_scrip->Description, 'Enabled Scrip', 'Enabled Scrip Name');
+ ok($enabled_scrip->IsAdded($general->Id), 'Enabled Scrip added to General');
+ my $disabled_scrip = RT::Scrip->new(RT->SystemUser);
+ $disabled_scrip->LoadByCols(Description => 'Disabled Scrip');
+
+ my $enabled_class = RT::Class->new(RT->SystemUser);
+ $enabled_class->Load('Enabled Class');
+ ok($enabled_class->Id, 'loaded Enabled Class');
+ is($enabled_class->Name, 'Enabled Class', 'Enabled Class Name');
+ ok($enabled_class->IsApplied($general->Id), 'Enabled Class added to General');
+
+ my $disabled_class = RT::Class->new(RT->SystemUser);
+ $disabled_class->Load('Disabled Class');
+
+ my $enabled_role = RT::CustomRole->new(RT->SystemUser);
+ $enabled_role->Load('Enabled Role');
+ ok($enabled_role->Id, 'loaded Enabled Role');
+ is($enabled_role->Name, 'Enabled Role', 'Enabled Role Name');
+ ok($enabled_role->IsAdded($general->Id), 'Enabled Role added to General');
+
+ my $disabled_role = RT::CustomRole->new(RT->SystemUser);
+ $disabled_role->Load('Disabled Role');
+
+ for my $object ($disabled_queue, $disabled_cf,
+ $disabled_scrip, $disabled_class,
+ $disabled_role) {
+ if ($from_initialdata) {
+ ok(!$object->Id, "disabled " . ref($object) . " excluded");
+ }
+ else {
+ ok($object->Disabled, "disabled " . ref($object));
+ }
+ }
+ },
+ },
+
+ {
name => 'Unapplied Objects',
create => sub {
my $scrip = RT::Scrip->new(RT->SystemUser);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list