[Rt-commit] rt branch, 4.4/core-assets, updated. rt-4.2.11-40-g979b49a

Todd Wade todd at bestpractical.com
Wed Sep 30 10:52:40 EDT 2015


The branch, 4.4/core-assets has been updated
       via  979b49a2e859649b2caf73d37b0d14f13866c835 (commit)
      from  8b54627400a0cb95e51d73377c10127eb8f9c8e9 (commit)

Summary of changes:
 etc/initialdata               | 33 ++++-------------------
 etc/upgrade/4.3.10/content    | 19 ++++++++++++--
 etc/upgrade/upgrade-assets.in |  4 +--
 lib/RT/Handle.pm              | 61 ++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 82 insertions(+), 35 deletions(-)

- Log -----------------------------------------------------------------
commit 979b49a2e859649b2caf73d37b0d14f13866c835
Author: Todd Wade <todd at bestpractical.com>
Date:   Wed Sep 30 10:52:24 2015 -0400

    commit sunnavy's feedback

diff --git a/etc/initialdata b/etc/initialdata
index f876940..ac3445c 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -23,6 +23,11 @@
              Description => 'A system-internal queue for the approvals system',
              Disabled    => 2, } );
 
+ at Catalogs = ({
+    Name        => "General assets",      # loc
+    Description => "The default catalog", # loc
+});
+
 @ScripActions = (
 
     {  Name        => 'Autoreply To Requestors',    # loc
@@ -887,32 +892,4 @@ Hour:         { $SubscriptionObj->SubValue('Hour') }
     },
 );
 
-require RT::Asset;
-# Create global role groups
-push @Final, sub {
-    foreach my $type (RT::Asset->Roles) {
-        next if $type eq "Owner";   # There's a core global role group for Owner
-
-        my $group = RT::Group->new( RT->SystemUser );
-        my ($ok, $msg) = $group->CreateRoleGroup(
-            Object              => RT->System,
-            Name                => $type,
-            InsideTransaction   => 0,
-        );
-        RT->Logger->error("Couldn't create global asset role group '$type': $msg")
-            unless $ok;
-    }
-};
-
-# Create default catalog
-push @Final, sub {
-    my $catalog = RT::Catalog->new( RT->SystemUser );
-    my ($ok, $msg) = $catalog->Create(
-        Name        => "General assets",
-        Description => "The default catalog",
-    );
-    RT->Logger->error("Couldn't create default catalog 'General assets': $msg")
-        unless $ok;
-};
-
 1;
diff --git a/etc/upgrade/4.3.10/content b/etc/upgrade/4.3.10/content
index 92b05b7..4694774 100644
--- a/etc/upgrade/4.3.10/content
+++ b/etc/upgrade/4.3.10/content
@@ -10,7 +10,13 @@ push @Final, sub {
     foreach my $type (RT::Asset->Roles) {
         next if $type eq "Owner";   # There's a core global role group for Owner
 
-        my $group = RT::Group->new( RT->SystemUser );
+        my $group = RT->System->RoleGroup( $type );
+        if ( $group->id ) {
+            RT->Logger->debug("Assets role '$type' already exists.");
+            next;
+        }
+
+        $group = RT::Group->new( RT->SystemUser );
         my ($ok, $msg) = $group->CreateRoleGroup(
             Object              => RT->System,
             Name                => $type,
@@ -23,9 +29,18 @@ push @Final, sub {
 
 # Create default catalog
 push @Final, sub {
+    my $Name = 'General assets';
+
     my $catalog = RT::Catalog->new( RT->SystemUser );
+    $catalog->Load( $Name );
+
+    if ( $catalog->id ) {
+        RT->Logger->debug("Catalog role '$Name' already exists.");
+        next;
+    }
+
     my ($ok, $msg) = $catalog->Create(
-        Name        => "General assets",
+        Name        => $Name,
         Description => "The default catalog",
     );
     RT->Logger->error("Couldn't create default catalog 'General assets': $msg")
diff --git a/etc/upgrade/upgrade-assets.in b/etc/upgrade/upgrade-assets.in
index d46980b..1cae850 100644
--- a/etc/upgrade/upgrade-assets.in
+++ b/etc/upgrade/upgrade-assets.in
@@ -61,9 +61,9 @@ my $db_type = RT->Config->Get('DatabaseType');
 
 my $dbh = $RT::Handle->dbh;
 
-my $found_assets_tables;
+my $found_assets_tables = {};
 foreach my $name ( $RT::Handle->_TableNames ) {
-    next unless $name =~ /^RTx_/i;
+    next unless grep $name eq $_, qw(RTxAssets RTxCatalogs);
     $found_assets_tables->{lc $name}++;
 }
 
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index e11a2a0..3494b1f 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -806,6 +806,25 @@ sub InsertInitialData {
         return ($val, $msg) unless $val;
     }
 
+    # assets role groups
+    foreach my $name (RT::Asset->Roles) {
+        next if $name eq "Owner";
+
+        my $group = RT->System->RoleGroup( $name );
+        if ( $group->id ) {
+            push @warns, "Assets role '$name' already exists.";
+            next;
+        }
+
+        $group = RT::Group->new( RT->SystemUser );
+        my ($val, $msg) = $group->CreateRoleGroup(
+            Object              => RT->System,
+            Name                => $name,
+            InsideTransaction   => 0,
+        );
+        return ($val, $msg) unless $val;
+    }
+
     push @warns, "You appear to have a functional RT database."
         if @warns;
 
@@ -829,10 +848,11 @@ sub InsertData {
 
     # Slurp in stuff to insert from the datafile. Possible things to go in here:-
     our (@Groups, @Users, @Members, @ACL, @Queues, @ScripActions, @ScripConditions,
-           @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final);
+           @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final,
+           @Catalogs, @Assets);
     local (@Groups, @Users, @Members, @ACL, @Queues, @ScripActions, @ScripConditions,
-           @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final);
-
+           @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final,
+           @Catalogs, @Assets);
     local $@;
     $RT::Logger->debug("Going to load '$datafile' data file");
     eval { require $datafile }
@@ -997,6 +1017,41 @@ sub InsertData {
         }
         $RT::Logger->debug("done.");
     }
+
+    if ( @Catalogs ) {
+        $RT::Logger->debug("Creating Catalogs...");
+
+        for my $item (@Catalogs) {
+            my $new_entry = RT::Catalog->new(RT->SystemUser);
+            my ( $return, $msg ) = $new_entry->Create(%$item);
+            unless ( $return ) {
+                $RT::Logger->error( $msg );
+            }
+            else {
+                $RT::Logger->debug( $return ."." );
+            }
+        }
+
+        $RT::Logger->debug("done.");
+    }
+    if ( @Assets ) {
+        $RT::Logger->debug("Creating Assets...");
+
+        for my $item (@Catalogs) {
+            my $new_entry = RT::Asset->new(RT->SystemUser);
+            my ( $return, $msg ) = $new_entry->Create(%$item);
+            unless ( $return ) {
+                $RT::Logger->error( $msg );
+            }
+            else {
+                $RT::Logger->debug( $return ."." );
+            }
+        }
+
+        $RT::Logger->debug("done.");
+    }
+
+
     if ( @CustomFields ) {
         $RT::Logger->debug("Creating custom fields...");
         for my $item ( @CustomFields ) {

-----------------------------------------------------------------------


More information about the rt-commit mailing list