[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-395-g2d5fa70
Shawn Moore
shawn at bestpractical.com
Tue Mar 21 17:44:15 EDT 2017
The branch, 4.4/serialize-json-initialdata has been updated
via 2d5fa70aa607dede9898e5548cf471fa78e3dd03 (commit)
via 05fe10ea97ef5d06587df815c0af3ce25ad47d35 (commit)
via d639f04a89da41c0d8f0d3faae8852146e584238 (commit)
via 5e4fb6cf65df0244ed15ec765cbc9df91f5c8956 (commit)
from ae258629a93010f8f057185684878e01b76d605f (commit)
Summary of changes:
lib/RT/Article.pm | 1 -
lib/RT/Handle.pm | 32 ++++++++++++--
lib/RT/Migrate/Serializer/JSON.pm | 9 ++++
t/api/initialdata-roundtrip.t | 92 ++++++++++++++++++++++++++++++++++++++-
4 files changed, 128 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit 5e4fb6cf65df0244ed15ec765cbc9df91f5c8956
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 21 21:05:59 2017 +0000
initialdata support for @Articles
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 680409b..83d9815 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -853,10 +853,10 @@ sub InsertData {
# Slurp in stuff to insert from the datafile. Possible things to go in here:-
our (@Groups, @Users, @Members, @ACL, @Queues, @Classes, @ScripActions, @ScripConditions,
@Templates, @CustomFields, @CustomRoles, @Scrips, @Attributes, @Initial, @Final,
- @Catalogs, @Assets, @OCFVs);
+ @Catalogs, @Assets, @Articles, @OCFVs);
local (@Groups, @Users, @Members, @ACL, @Queues, @Classes, @ScripActions, @ScripConditions,
@Templates, @CustomFields, @CustomRoles, @Scrips, @Attributes, @Initial, @Final,
- @Catalogs, @Assets, @OCFVs);
+ @Catalogs, @Assets, @Articles, @OCFVs);
local $@;
@@ -907,6 +907,7 @@ sub InsertData {
Final => \@Final,
Catalogs => \@Catalogs,
Assets => \@Assets,
+ Articles => \@Articles,
OCFVs => \@OCFVs,
},
) or return (0, "Couldn't load data from '$datafile' for import:\n\nERROR:" . $@);
@@ -1154,6 +1155,31 @@ sub InsertData {
$RT::Logger->debug("done.");
}
+ if ( @Articles ) {
+ $RT::Logger->debug("Creating Articles...");
+
+ for my $item (@Articles) {
+ my $attributes = delete $item->{ Attributes };
+ my $ocfvs = delete $item->{ CustomFields };
+
+ my $new_entry = RT::Article->new(RT->SystemUser);
+ my ( $return, $msg ) = $new_entry->Create(%$item);
+ unless ( $return ) {
+ $RT::Logger->error( $msg );
+ }
+ else {
+ $RT::Logger->debug( $return ."." );
+ }
+
+ $_->{Object} = $new_entry for @{$attributes || []};
+ push @Attributes, @{$attributes || []};
+ $_->{Object} = $new_entry for @{$ocfvs || []};
+ push @OCFVs, @{$ocfvs || []};
+ }
+
+ $RT::Logger->debug("done.");
+ }
+
if ( @CustomFields ) {
$RT::Logger->debug("Creating custom fields...");
commit d639f04a89da41c0d8f0d3faae8852146e584238
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 21 21:21:20 2017 +0000
Fix Asset loading via initialdata
Copy/paste bug, which has been there since assets was cored in 4e652c42
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 83d9815..812d4c3 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1133,7 +1133,7 @@ sub InsertData {
if ( @Assets ) {
$RT::Logger->debug("Creating Assets...");
- for my $item (@Catalogs) {
+ for my $item (@Assets) {
my $attributes = delete $item->{ Attributes };
my $ocfvs = delete $item->{ CustomFields };
commit 05fe10ea97ef5d06587df815c0af3ce25ad47d35
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 21 21:39:11 2017 +0000
Remove unused CustomFields default from Article->Create
The way you specify CustomFields to Create is including CustomField-*
params in the top-level argument list, so including a default of
CustomFields => {} is misleading
diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index 0e223e5..fa205f4 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -97,7 +97,6 @@ sub Create {
Name => '',
Summary => '',
Class => '0',
- CustomFields => {},
Links => {},
Topics => [],
Disabled => 0,
commit 2d5fa70aa607dede9898e5548cf471fa78e3dd03
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Mar 21 21:40:34 2017 +0000
Test for Articles roundtrip through initialdata
Including several different CFs
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index e921a9f..40468cc 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -381,6 +381,14 @@ sub CanonicalizeObjectCustomFieldValues {
delete $self->{Records}{'RT::ObjectCustomFieldValue'};
}
+sub CanonicalizeArticles {
+ my $self = shift;
+
+ for my $record (values %{ $self->{Records}{'RT::Article'} }) {
+ delete $record->{URI};
+ }
+}
+
sub CanonicalizeObjects {
my $self = shift;
@@ -490,6 +498,7 @@ sub WriteFile {
$self->CanonicalizeGroups;
$self->CanonicalizeGroupMembers;
$self->CanonicalizeCustomFields;
+ $self->CanonicalizeArticles;
delete $self->{Records}{'RT::Attribute'};
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 869fc22..ef4e889 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -207,7 +207,7 @@ my @tests = (
my %extra = (
Group => { method => 'CreateUserDefinedGroup' },
Asset => undef,
- Article => undef,
+ Article => { Class => 'General' },
Ticket => undef,
Transaction => undef,
User => undef,
@@ -249,7 +249,6 @@ my @tests = (
my %load = (
Transaction => undef,
Ticket => undef,
- Article => undef,
User => undef,
Asset => undef,
);
@@ -592,6 +591,95 @@ my @tests = (
is($queue->Type, 'Simple', 'Type');
},
},
+ {
+ name => 'Articles',
+ create => sub {
+ my $class = RT::Class->new(RT->SystemUser);
+ my ($ok, $msg) = $class->Create(
+ Name => 'Test',
+ );
+ ok($ok, $msg);
+
+ my $content = RT::CustomField->new(RT->SystemUser);
+ $content->LoadByCols(
+ Name => "Content",
+ Type => "Text",
+ LookupType => RT::Article->CustomFieldLookupType,
+ );
+ ok($content->Id, "loaded builtin Content CF");
+
+ my $tags = RT::CustomField->new(RT->SystemUser);
+ ($ok, $msg) = $tags->Create(
+ Name => "Tags",
+ Type => "FreeformMultiple",
+ LookupType => RT::Article->CustomFieldLookupType,
+ );
+ ok($ok, $msg);
+ ($ok, $msg) = $tags->AddToObject($class);
+ ok($ok, $msg);
+
+ my $clearance = RT::CustomField->new(RT->SystemUser);
+ ($ok, $msg) = $clearance->Create(
+ Name => "Clearance",
+ Type => "SelectSingle",
+ LookupType => RT::Article->CustomFieldLookupType,
+ );
+ ok($ok, $msg);
+ ($ok, $msg) = $clearance->AddToObject($class);
+ ok($ok, $msg);
+
+ ($ok, $msg) = $clearance->AddValue(Name => 'Unclassified');
+ ok($ok, $msg);
+ ($ok, $msg) = $clearance->AddValue(Name => 'Classified');
+ ok($ok, $msg);
+ ($ok, $msg) = $clearance->AddValue(Name => 'Top Secret');
+ ok($ok, $msg);
+
+ my $coffee = RT::Article->new(RT->SystemUser);
+ ($ok, $msg) = $coffee->Create(
+ Class => 'Test',
+ Name => 'Coffee time',
+ "CustomField-" . $content->Id => 'Always',
+ "CustomField-" . $clearance->Id => 'Unclassified',
+ "CustomField-" . $tags->Id => ['drink', 'coffee', 'how the humans live'],
+ );
+ ok($ok, $msg);
+
+ my $twd = RT::Article->new(RT->SystemUser);
+ ($ok, $msg) = $twd->Create(
+ Class => 'Test',
+ Name => 'Total world domination plans',
+ "CustomField-" . $content->Id => 'REDACTED',
+ "CustomField-" . $clearance->Id => 'Top Secret',
+ "CustomField-" . $tags->Id => ['snakes', 'clowns'],
+ );
+ ok($ok, $msg);
+ },
+ present => sub {
+ my $class = RT::Class->new(RT->SystemUser);
+ $class->Load('Test');
+ ok($class->Id, 'loaded class');
+ is($class->Name, 'Test', 'Name');
+
+ my $coffee = RT::Article->new(RT->SystemUser);
+ $coffee->LoadByCols(Name => 'Coffee time');
+ ok($coffee->Id, 'loaded article');
+ is($coffee->Name, 'Coffee time', 'Name');
+ is($coffee->Class, $class->Id, 'Class');
+ is($coffee->FirstCustomFieldValue('Content'), 'Always', 'Content CF');
+ is($coffee->FirstCustomFieldValue('Clearance'), 'Unclassified', 'Clearance CF');
+ is($coffee->CustomFieldValuesAsString('Tags', Separator => '.'), 'drink.coffee.how the humans live', 'Tags CF');
+
+ my $twd = RT::Article->new(RT->SystemUser);
+ $twd->LoadByCols(Name => 'Coffee time');
+ ok($twd->Id, 'loaded article');
+ is($twd->Name, 'Coffee time', 'Name');
+ is($twd->Class, $class->Id, 'Class');
+ is($twd->FirstCustomFieldValue('Content'), 'REDACTED', 'Content CF');
+ is($twd->FirstCustomFieldValue('Clearance'), 'Top Secret', 'Clearance CF');
+ is($twd->CustomFieldValuesAsString('Tags', Separator => '.'), 'snakes.clowns', 'Tags CF');
+ },
+ },
);
my $id = 0;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list