~bestpractical/rt/master

« back to all changes in this revision

Viewing changes to share/html/Admin/Scrips/Elements/EditCustomCode

  • Committer: sunnavy
  • Date: 2023-10-19 19:45:11 UTC
  • mfrom: (8471.1.577)
  • Revision ID: git-v1:9fca83d11d15fb8034308194b9c9052d5df7d454
Merge branch '5.0-trunk'

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
    <textarea spellcheck="false" cols="80" class="form-control" rows="<% $lines %>" name="<% $method %>"><% $code %></textarea>
66
66
  </div>
67
67
</div>
 
68
 
 
69
% if ( $errors{$method} ) {
 
70
<div class="row mt-2">
 
71
  <div class="label col-2 labeltop scrip-log">
 
72
    <% loc('Log Output') %>:
 
73
  </div>
 
74
  <div class="value col-9">
 
75
    <textarea spellcheck="false" cols="80" rows="5" class="form-control" readonly><% $errors{$method} %></textarea>
 
76
  </div>
 
77
</div>
 
78
% }
 
79
 
68
80
% }
69
81
 
70
82
</&>
79
91
);
80
92
 
81
93
my $min_lines = 10;
 
94
 
 
95
my %errors = (
 
96
    'CustomIsApplicableCode' => '',
 
97
    'CustomPrepareCode'      => '',
 
98
    'CustomCommitCode'       => '',
 
99
);
 
100
 
 
101
if ( $Scrip->id ) {
 
102
    my @stages = ();
 
103
    if ( $Scrip->ConditionObj->ExecModule eq 'UserDefined' ) {
 
104
        push @stages, 'IsApplicable';
 
105
    }
 
106
    if ( $Scrip->ActionObj->ExecModule eq 'UserDefined' ) {
 
107
        push @stages, 'Prepare', 'Commit';
 
108
    }
 
109
 
 
110
    my $logdir = RT->Config->Get('LogDir') || File::Spec->catdir( $RT::VarPath, 'log' );
 
111
    $logdir    = File::Spec->catdir( $logdir, 'scrips' );
 
112
    foreach my $stage ( @stages ) {
 
113
        my $filename = File::Spec->catfile( $logdir, 'scrip-' . $Scrip->id . '-' .  $stage . '.log' );
 
114
        if ( -s $filename ) {
 
115
            local $/;
 
116
            open ( my $f, '<:encoding(UTF-8)', $filename )
 
117
                or die "Cannot open initialdata file '$filename' for read: $@";
 
118
            $errors{ 'Custom' . $stage . 'Code' } = <$f>;
 
119
        }
 
120
    }
 
121
}
82
122
</%INIT>