]> git.uio.no Git - usit-rt.git/blame - etc/upgrade/switch-templates-to
Upgrade to 4.2.8
[usit-rt.git] / etc / upgrade / switch-templates-to
CommitLineData
3ffc5f4f
MKG
1#!/usr/bin/perl
2# BEGIN BPS TAGGED BLOCK {{{
3#
4# COPYRIGHT:
5#
6# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
7# <sales@bestpractical.com>
8#
9# (Except where explicitly superseded by other copyright notices)
10#
11#
12# LICENSE:
13#
14# This work is made available to you under the terms of Version 2 of
15# the GNU General Public License. A copy of that license should have
16# been provided with this software, but in any event can be snarfed
17# from www.gnu.org.
18#
19# This work is distributed in the hope that it will be useful, but
20# WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22# General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27# 02110-1301 or visit their web page on the internet at
28# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
29#
30#
31# CONTRIBUTION SUBMISSION POLICY:
32#
33# (The following paragraph is not intended to limit the rights granted
34# to you to modify and distribute this software under the terms of
35# the GNU General Public License and is only of importance to you if
36# you choose to contribute your changes and enhancements to the
37# community by submitting them to Best Practical Solutions, LLC.)
38#
39# By intentionally submitting any modifications, corrections or
40# derivatives to this work, or any other work intended for use with
41# Request Tracker, to Best Practical Solutions, LLC, you confirm that
42# you are the copyright holder for those contributions and you grant
43# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44# royalty-free, perpetual, license to use, copy, create derivative
45# works based on those contributions, and sublicense and distribute
46# those contributions and any derivatives thereof.
47#
48# END BPS TAGGED BLOCK }}}
49use strict;
50use warnings;
51
52use lib "local/lib";
53use lib "lib";
54
55use RT;
56
57my $to = shift || '';
58my $from;
59
60if ($to =~ /html|text/i) {
61 $to = $to =~ /html/i ? 'html' : 'text';
62 $from = $to eq 'html' ? 'text' : 'html';
63} else {
64 print "Usage: $0 [html|text]\n";
65 warn "Please specify if you'd like to switch to HTML or text templates.\n";
66 exit 1;
67}
68
69RT::LoadConfig();
70RT->Config->Set('LogToSTDERR' => 'info');
71RT::Init();
72
73$| = 1;
74
75my @templates = (
76 "Autoreply",
77 "Transaction",
78 "Admin Correspondence",
79 "Correspondence",
80 "Admin Comment",
81 "Status Change",
82 "Resolved",
83 "New Pending Approval",
84 "Approval Passed",
85 "All Approvals Passed",
86 "Approval Rejected",
87 "Approval Ready for Owner",
88);
89
90$RT::Handle->BeginTransaction();
91
92use RT::Scrips;
93my $scrips = RT::Scrips->new( RT->SystemUser );
94$scrips->UnLimit;
95
96for (@templates) {
97 $scrips->Limit(
98 FIELD => 'Template',
99 VALUE => ($to eq 'html' ? $_ : "$_ in HTML"),
100 ENTRYAGGREGATOR => 'OR'
101 );
102}
103
104my $switched = 0;
105while ( my $s = $scrips->Next ) {
106 my $new = $s->TemplateObj->Name;
107
108 if ($to eq 'html') {
109 $new .= ' in HTML';
110 } else {
111 $new =~ s/ in HTML$//;
112 }
113
114 print $s->id, ": ", $s->Description, "\n";
115 print " ", $s->TemplateObj->Name, " -> $new\n\n";
116
117 my ($ok, $msg) = $s->SetTemplate($new);
118
119 if ($ok) {
120 $switched++;
121 } else {
122 warn " Couldn't switch templates: $msg\n";
123 }
124}
125
126$RT::Handle->Commit;
127
128if ($switched) {
129 print <<" EOT";
130Switched $switched scrips to $to templates. You should now manually port any
131customizations from the old templates to the new templates.
132 EOT
133 exit 1 if $switched != $scrips->Count;
134}
135elsif ($scrips->Count) {
136 print <<" EOT";
137@{[$scrips->Count]} scrips using $from templates were found, but none were
138successfully switched to $to. See the errors above.
139 EOT
140 exit 1;
141}
142else {
143 print <<" EOT";
144No scrips were found using the $from templates, so none were switched to
145$to templates.
146 EOT
147}
148