replace missing RT scrips on upgrade, #9569
authormark <mark>
Tue, 10 May 2011 23:21:44 +0000 (23:21 +0000)
committermark <mark>
Tue, 10 May 2011 23:21:44 +0000 (23:21 +0000)
FS/FS/TicketSystem.pm
Makefile
rt/Makefile
rt/Makefile.in

index f5c8e7d..8ea4b03 100644 (file)
@@ -84,6 +84,59 @@ sub _upgrade_data {
     );
     die $msg if !$val;
   }
+
+  # Create any missing scrips
+  our (@Groups, @Users, @ACL, @Queues, @ScripActions, @ScripConditions,
+       @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final);
+  my $datafile = '%%%RT_PATH%%%/etc/initialdata';
+  eval { require $datafile };
+  if ( $@ ) {
+    warn "Couldn't load RT data from '$datafile': $@\n(skipping)\n";
+    return;
+  }
+
+  my $search = RT::ScripConditions->new($CurrentUser);
+  $search->UnLimit;
+  my %condition = map { lc($_->Name), $_->Id } @{ $search->ItemsArrayRef };
+
+  $search = RT::ScripActions->new($CurrentUser);
+  $search->UnLimit;
+  my %action = map { lc($_->Name), $_->Id } @{ $search->ItemsArrayRef };
+
+  $search = RT::Templates->new($CurrentUser);
+  $search->UnLimit;
+  my %template = map { lc($_->Name), $_->Id } @{ $search->ItemsArrayRef };
+
+  my $Scrip = RT::Scrip->new($CurrentUser);
+  foreach my $s ( @Scrips ) {
+    my $desc = $s->{'Description'};
+    my ($c, $a, $t) = map lc,
+      @{ $s }{'ScripCondition', 'ScripAction', 'Template'};
+    if ( !$condition{$c} ) {
+      warn "ScripCondition '$c' not found.\n";
+      next;
+    }
+    if ( !$action{$a} ) {
+      warn "ScripAction '$a' not found.\n";
+      next;
+    }
+    if ( !$template{$t} ) {
+      warn "Template '$t' not found.\n";
+      next;
+    }
+    my %param = (
+      ScripCondition => $condition{$c},
+      ScripAction => $action{$a},
+      Template => $template{$t},
+      Queue => 0,
+    );
+    $Scrip->LoadByCols(%param);
+    if (!defined($Scrip->Id)) {
+      my ($val, $msg) = $Scrip->Create(%param, Description => $desc);
+      die $msg if !$val;
+    }
+  } #foreach (@Scrips)
+
   return;
 }
 
index 7cf90cc..18944c5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -191,6 +191,7 @@ perl-modules:
          s|%%%FREESIDE_CACHE%%%|${FREESIDE_CACHE}|g;\
          s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
          s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
+         s'%%%RT_PATH%%%'${RT_PATH}'g; \
          s'%%%MASONDATA%%%'${MASONDATA}'g;\
        " blib/lib/FS/*.pm;\
        perl -p -i -e "\
index 6ba9063..8f92020 100644 (file)
@@ -327,6 +327,8 @@ fixperms:
 
        chmod 0440 $(DESTDIR)$(CONFIG_FILE)
        chmod 0640 $(DESTDIR)$(SITE_CONFIG_FILE)
+       # Make this externally readable
+       chmod 0440 $(DESTDIR)$(RT_ETC_PATH)/initialdata
 
        # Make the system binaries
        cd $(DESTDIR)$(RT_BIN_PATH) && ( chmod 0755 $(BINARIES) ; chown $(BIN_OWNER) $(BINARIES);  chgrp $(RTGROUP) $(BINARIES))
index d41633f..f963faa 100644 (file)
@@ -327,6 +327,8 @@ fixperms:
 
        chmod 0440 $(DESTDIR)$(CONFIG_FILE)
        chmod 0640 $(DESTDIR)$(SITE_CONFIG_FILE)
+       # Make this externally readable
+       chmod 0440 $(DESTDIR)$(RT_ETC_PATH)/initialdata
 
        # Make the system binaries
        cd $(DESTDIR)$(RT_BIN_PATH) && ( chmod 0755 $(BINARIES) ; chown $(BIN_OWNER) $(BINARIES);  chgrp $(RTGROUP) $(BINARIES))