From 2f864a9b428d642df650d01a51ffa42b6826d82a Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 10 May 2011 23:21:44 +0000 Subject: [PATCH] replace missing RT scrips on upgrade, #9569 --- FS/FS/TicketSystem.pm | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + rt/Makefile | 2 ++ rt/Makefile.in | 2 ++ 4 files changed, 58 insertions(+) diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm index f5c8e7dad..8ea4b03a8 100644 --- a/FS/FS/TicketSystem.pm +++ b/FS/FS/TicketSystem.pm @@ -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; } diff --git a/Makefile b/Makefile index 7cf90ccc7..18944c51b 100644 --- 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 "\ diff --git a/rt/Makefile b/rt/Makefile index 6ba9063e1..8f9202080 100644 --- a/rt/Makefile +++ b/rt/Makefile @@ -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)) diff --git a/rt/Makefile.in b/rt/Makefile.in index d41633fff..f963faa25 100644 --- a/rt/Makefile.in +++ b/rt/Makefile.in @@ -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)) -- 2.11.0