This file is indexed.

/usr/share/otrs/scripts/DBUpdateTo6/MigrateTicketNotifications.pm is in otrs2 6.0.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package scripts::DBUpdateTo6::MigrateTicketNotifications;    ## no critic

use strict;
use warnings;

use parent qw(scripts::DBUpdateTo6::Base);

our @ObjectDependencies = (
    'Kernel::System::DB',
    'Kernel::System::NotificationEvent',
);

=head1 NAME

scripts::DBUpdateTo6::MigrateTicketNotifications - Migrate ticket notification contents.

=cut

sub Run {
    my ( $Self, %Param ) = @_;

    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
    my $Verbose = $Param{CommandlineOptions}->{Verbose} || 0;

    # check if article_type table exists
    my $TableExists = $Self->TableExists(
        Table => 'article_type',
    );

    # Skip execution if article_type table is missing.
    if ( !$TableExists ) {
        print "\n        - Article types table missing, skipping...\n\n" if $Verbose;
        return 1;
    }

    # Collect data for further calculation of article type mapping.
    return if !$DBObject->Prepare(
        SQL => 'SELECT id, name FROM article_type',
    );

    my %ArticleTypes;
    while ( my @Row = $DBObject->FetchrowArray() ) {
        $ArticleTypes{ $Row[0] } = $Row[1];
    }

    return if !$DBObject->Prepare(
        SQL => 'SELECT id, name FROM communication_channel',
    );

    my %CommunicationChannels;
    while ( my @Row = $DBObject->FetchrowArray() ) {
        $CommunicationChannels{ $Row[1] } = $Row[0];
    }

    my $NotificationEventObject = $Kernel::OM->Get('Kernel::System::NotificationEvent');

    my %NotificationEventList = $NotificationEventObject->NotificationList(
        Type    => 'Ticket',
        Details => 1,
    );

    for my $NotificationEventID ( sort keys %NotificationEventList ) {

        my $UpdateNeeded = 0;

        # Check for ArticleTypeIDs and map those entries to new options:
        #   - IsVisibleForCustomer
        #   - CommunicationChannelID
        if ( $NotificationEventList{$NotificationEventID}->{Data}->{ArticleTypeID} ) {
            my $IsVisibleForCustomer;
            my @CommunicationChannelIDs;
            for my $ArticleTypeID ( @{ $NotificationEventList{$NotificationEventID}->{Data}->{ArticleTypeID} } ) {

                # Deduce customer visibility option. Set only if it's the same for all selected article type IDs.
                #   Otherwise, leave it undefined, so both types are considered.
                if (
                    $ArticleTypes{$ArticleTypeID}
                    && $ArticleTypes{$ArticleTypeID} =~ /(-ext|phone|fax|sms|webrequest)/i
                    )
                {
                    if ( !defined $IsVisibleForCustomer ) {
                        $IsVisibleForCustomer = 1;
                    }
                    else {
                        if ( !$IsVisibleForCustomer ) {
                            $IsVisibleForCustomer = undef;
                        }
                    }
                }
                elsif ( $ArticleTypes{$ArticleTypeID} ) {
                    if ( !defined $IsVisibleForCustomer ) {
                        $IsVisibleForCustomer = 0;
                    }
                    else {
                        if ($IsVisibleForCustomer) {
                            $IsVisibleForCustomer = undef;
                        }
                    }
                }

                # Deduce communication channel ID and save it.
                my $CommunicationChannelID;
                if ( $ArticleTypes{$ArticleTypeID} && $ArticleTypes{$ArticleTypeID} =~ /email-/i ) {
                    $CommunicationChannelID = $CommunicationChannels{Email};
                }
                elsif ( $ArticleTypes{$ArticleTypeID} && $ArticleTypes{$ArticleTypeID} =~ /phone/i ) {
                    $CommunicationChannelID = $CommunicationChannels{Phone};
                }
                elsif ( $ArticleTypes{$ArticleTypeID} && $ArticleTypes{$ArticleTypeID} =~ /chat-/i ) {
                    $CommunicationChannelID = $CommunicationChannels{Chat};
                }
                else {
                    $CommunicationChannelID = $CommunicationChannels{Internal};
                }
                if ( !grep { $_ eq $CommunicationChannelID } @CommunicationChannelIDs ) {
                    push @CommunicationChannelIDs, $CommunicationChannelID;
                }
            }

            delete $NotificationEventList{$NotificationEventID}->{Data}->{ArticleTypeID};
            $NotificationEventList{$NotificationEventID}->{Data}->{ArticleIsVisibleForCustomer}
                = [$IsVisibleForCustomer];
            $NotificationEventList{$NotificationEventID}->{Data}->{ArticleCommunicationChannelID}
                = \@CommunicationChannelIDs;

            $UpdateNeeded = 1;
        }

        # Check for transport-based NotificationArticleTypeIDs and convert them to IsVisibleForCustomer entries.
        if ( $NotificationEventList{$NotificationEventID}->{Data}->{NotificationArticleTypeID} ) {

            if ( $NotificationEventList{$NotificationEventID}->{Data}->{NotificationArticleTypeID}->[0] == 3 ) {
                $NotificationEventList{$NotificationEventID}->{Data}->{IsVisibleForCustomer} = ['on'];
            }
            delete $NotificationEventList{$NotificationEventID}->{Data}->{NotificationArticleTypeID};

            $UpdateNeeded = 1;
        }

        # Update notification entries if needed.
        if ($UpdateNeeded) {
            $NotificationEventObject->NotificationUpdate(
                %{ $NotificationEventList{$NotificationEventID} },
                UserID => 1,
            );
        }
    }

    return 1;
}

1;

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (L<http://otrs.org/>).

This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.

=cut