1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package scripts::DBUpdateTo6::MigrateModifiedSettings; ## no critic 10 11use strict; 12use warnings; 13 14use parent qw(scripts::DBUpdateTo6::Base); 15use Kernel::System::VariableCheck qw(:all); 16 17our @ObjectDependencies = ( 18 'Kernel::System::SysConfig', 19 'Kernel::System::Storable', 20); 21 22=head1 NAME 23 24scripts::DBUpdateTo6::MigrateModifiedSettings - Migrate config modified values that are changed from default OTRS 6 to 7 . 25 26This script assumes that SysConfig settings has not been cleaned up. 27 28=cut 29 30sub Run { 31 my ( $Self, %Param ) = @_; 32 33 my $Verbose = $Param{CommandlineOptions}->{Verbose} || 0; 34 my $Success = 1; 35 36 my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig'); 37 my $StorableObject = $Kernel::OM->Get('Kernel::System::Storable'); 38 my @ModifiedSettings; 39 40 my %MigrationSettings = $Self->SettingsToMigrate(); 41 42 SETTINGNAME: 43 for my $SettingName ( sort keys %MigrationSettings ) { 44 45 my %Setting = $SysConfigObject->SettingGet( 46 Name => $SettingName, 47 ); 48 49 if ( !%Setting ) { 50 print "\n - Could not get existing $SettingName!"; 51 $Success = 0; 52 next SETTINGNAME; 53 } 54 55 if ( IsArrayRefWithData( $Setting{EffectiveValue} ) ) { 56 57 # Create a local clone of the value to prevent any modification. 58 my $EffectiveValue = $StorableObject->Clone( 59 Data => $Setting{EffectiveValue}, 60 ); 61 62 for my $Item ( 0 .. $#{$EffectiveValue} ) { 63 64 for my $OldValue ( sort keys %{ $MigrationSettings{$SettingName} } ) { 65 if ( $EffectiveValue->[$Item] eq $OldValue ) { 66 $EffectiveValue->[$Item] = $MigrationSettings{$SettingName}->{$OldValue}; 67 68 my %Setting = ( 69 Name => $SettingName, 70 EffectiveValue => $EffectiveValue, 71 IsValid => 1, 72 ); 73 74 push @ModifiedSettings, \%Setting; 75 } 76 } 77 } 78 } 79 elsif ( IsHashRefWithData( $Setting{EffectiveValue} ) ) { 80 81 # Create a local clone of the value to prevent any modification. 82 my $EffectiveValue = $StorableObject->Clone( 83 Data => $Setting{EffectiveValue}, 84 ); 85 86 for my $Item ( sort keys %{$EffectiveValue} ) { 87 88 for my $OldValue ( sort keys %{ $MigrationSettings{$SettingName} } ) { 89 if ( $EffectiveValue->{$Item} eq $OldValue ) { 90 $EffectiveValue->{$Item} = $MigrationSettings{$SettingName}->{$OldValue}; 91 92 my %Setting = ( 93 Name => $SettingName, 94 EffectiveValue => $EffectiveValue, 95 IsValid => 1, 96 ); 97 98 push @ModifiedSettings, \%Setting; 99 } 100 } 101 } 102 } 103 else { 104 105 for my $OldValue ( sort keys %{ $MigrationSettings{$SettingName} } ) { 106 if ( $Setting{EffectiveValue} eq $OldValue ) { 107 $Setting{EffectiveValue} = $MigrationSettings{$SettingName}->{$OldValue}; 108 109 my %Setting = ( 110 Name => $SettingName, 111 EffectiveValue => [ $Setting{EffectiveValue} ], 112 IsValid => 1, 113 ); 114 115 push @ModifiedSettings, \%Setting; 116 } 117 } 118 } 119 } 120 121 if ( IsArrayRefWithData( \@ModifiedSettings ) ) { 122 123 if ($Verbose) { 124 print "\n - Updating settings..."; 125 } 126 127 my $Result = $SysConfigObject->SettingsSet( 128 UserID => 1, 129 Comments => "Deploy settings with migration module", 130 Settings => \@ModifiedSettings, 131 ); 132 if ($Result) { 133 if ($Verbose) { 134 print 'OK'; 135 } 136 } 137 else { 138 if ($Verbose) { 139 print 'Fail'; 140 } 141 print "\n - There was an error updating settings"; 142 $Success = 0; 143 } 144 } 145 146 print "\n\n" if $Verbose; 147 148 return $Success; 149} 150 151sub SettingsToMigrate { 152 my ( $Self, %Param ) = @_; 153 154 return ( 155 'Loader::Agent::CommonJS###000-Framework' => { 156 'thirdparty/jquery-jstree-3.3.4/jquery.jstree.js' => 'thirdparty/jquery-jstree-3.3.7/jquery.jstree.js', 157 'thirdparty/jquery-3.2.1/jquery.js' => 'thirdparty/jquery-3.4.1/jquery.js', 158 }, 159 'Loader::Customer::CommonJS###000-Framework' => { 160 'thirdparty/jquery-jstree-3.3.4/jquery.jstree.js' => 'thirdparty/jquery-jstree-3.3.7/jquery.jstree.js', 161 'thirdparty/jquery-3.2.1/jquery.js' => 'thirdparty/jquery-3.4.1/jquery.js', 162 }, 163 ); 164} 165 1661; 167