This file is indexed.

/usr/share/otrs/scripts/DBUpdateTo6/MigrateConfigEffectiveValues.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
# --
# 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::MigrateConfigEffectiveValues;    ## no critic

use strict;
use warnings;

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

our @ObjectDependencies = (
    'Kernel::Config',
    'Kernel::System::Main',
    'Kernel::System::Log',
    'Kernel::System::SysConfig::Migration',
);

=head1 NAME

scripts::DBUpdateTo6::MigrateConfigEffectiveValues - Migrate config effective values.

=cut

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

    my $Verbose = $Param{CommandlineOptions}->{Verbose} || 0;

    # Move and rename ZZZAuto.pm from OTRS 5 away from Kernel/Config/Files
    my ( $FileClass, $FilePath ) = $Self->_MoveZZZAuto();

    # check error
    if ( !$FilePath ) {
        if ($Verbose) {
            print
                "    Could not find Kernel/Config/Files/ZZZAuto.pm or Kernel/Config/Backups/ZZZAutoOTRS5.pm, skipping...\n";
        }
        return 1;
    }

    # Rebuild config to read the xml config files from otrs 6 to write them
    # to the database and deploy them to ZZZAAuto.pm
    $Self->RebuildConfig();
    if ($Verbose) {
        print "\n    If you see errors about 'Setting ... is invalid', that's fine, no need to worry! \n"
            . "    This could happen because some config settings are no longer needed for OTRS 6 \n"
            . "    or you may have some packages installed, which will be migrated \n"
            . "    in a later step (during the package upgrade). \n"
            . "\n"
            . "    The configuration migration can take some time, please be patient.\n";
    }

    # migrate the effective values from modified settings in OTRS 5 to OTRS 6
    my $Success = $Kernel::OM->Get('Kernel::System::SysConfig::Migration')->MigrateConfigEffectiveValues(
        FileClass => $FileClass,
        FilePath  => $FilePath,
        NoOutput  => !$Verbose,
    );

    return $Success;
}

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

    my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');

    # define old location of ZZZAuto.pm and file class name
    my $OldLocation  = "$Home/Kernel/Config/Files/ZZZAuto.pm";
    my $OldFileClass = 'Kernel::Config::Files::ZZZAuto';

    # define backup directory, new location of ZZZAuto.pm (renamed to ZZZAutoOTRS5.pm)
    # and new file class
    my $BackupDirectory = "$Home/Kernel/Config/Backups";
    my $NewLocation     = "$BackupDirectory/ZZZAutoOTRS5.pm";
    my $NewFileClass    = 'Kernel::Config::Backups::ZZZAutoOTRS5';

    # ZZZAuto.pm file does not exist
    if ( !-e $OldLocation ) {

        # but Kernel/Config/Backups/ZZZAutoOTRS5.pm exists already
        return ( $NewFileClass, $NewLocation ) if -e $NewLocation;

        # error
        return;
    }

    # check if backup directory exists
    if ( !-d $BackupDirectory ) {

        # we try to create it
        if ( !mkdir $BackupDirectory ) {
            $Kernel::OM->Get('Kernel::System::Log')->Log(
                Priority => 'error',
                Message  => "Could not create directory $BackupDirectory!",
            );
            return;
        }
    }

    # move it to new location and rename it
    system("mv $OldLocation $NewLocation");

    my $MainObject = $Kernel::OM->Get('Kernel::System::Main');

    # Read the content of the file. Make sure to open it in UTF-8 mode, in order to preserve multi-byte characters.
    #   Please see bug#13344 for more information.
    my $ContentSCALARRef = $MainObject->FileRead(
        Location => $NewLocation,
        Mode     => 'utf8',
    );

    # rename the package name inside the file
    ${$ContentSCALARRef} =~ s{^package $OldFileClass;$}{package $NewFileClass;}ms;

    # write content back to file
    my $FileLocation = $MainObject->FileWrite(
        Location   => $NewLocation,
        Content    => $ContentSCALARRef,
        Mode       => 'utf8',
        Permission => '644',
    );

    return ( $NewFileClass, $FileLocation );
}

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