This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Tools::Migrate::ConfigXMLStructure;
use strict;
use warnings;
use File::Basename;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::Main',
'Kernel::System::SysConfig::Migration',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Migrate XML configuration files from OTRS 5 to OTRS 6.');
$Self->AddOption(
Name => 'source-directory',
Description => "Directory which contains configuration XML files that needs to be migrated.",
Required => 1,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
# Perform any custom validations here. Command execution can be stopped with die().
my $Directory = $Self->GetOption('source-directory');
if ( $Directory && !-d $Directory ) {
die "Directory $Directory does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Migrating configuration XML files...</yellow>\n");
# needed objects
my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
my $Directory = $Self->GetOption('source-directory');
my @Files = $MainObject->DirectoryRead(
Directory => $Directory,
Filter => '*.xml',
);
if ( !@Files ) {
$Self->PrintError("No XML files found in $Directory.");
return $Self->ExitCodeError();
}
if ( !-d "$Directory/XML" ) {
# Create XML directory
mkdir "$Directory/XML";
}
FILE:
for my $File (@Files) {
my $TargetPath = "$Directory/XML/" . basename($File);
$Self->Print("$File -> $TargetPath...");
# Read XML file
my $ContentRef = $MainObject->FileRead(
Location => $File,
Mode => 'utf8',
);
# Get file name without extension
my $FileName = $File;
$FileName =~ s{^.*/(.*?)\..*$}{$1}gsmx;
# Migrate
my $Result = $Kernel::OM->Get('Kernel::System::SysConfig::Migration')->MigrateXMLStructure(
Content => $$ContentRef,
Name => $FileName,
);
if ( !$Result ) {
$Self->Print("<red>Failed.</red>\n");
next FILE;
}
# Save result
my $Success = $MainObject->FileWrite(
Location => $TargetPath,
Content => \$Result,
Mode => 'utf8',
);
$Self->Print(" <green>Done.</green>\n");
}
$Self->Print("\n<green>Done.</green>\n");
return $Self->ExitCodeOk();
}
1;
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut

View File

@@ -0,0 +1,124 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Tools::Migrate::DTL2TT;
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::System::Main',
'Kernel::Output::Template::Provider',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Migrate DTL files to Template::Toolkit.');
$Self->AddArgument(
Name => 'directory',
Description => "Toplevel OTRS or module directory where DTL files need to be converted.",
Required => 1,
ValueRegex => qr/.*/smx,
);
return;
}
sub Run {
my ( $Self, %Param ) = @_;
my $ProviderObject = $Kernel::OM->Get('Kernel::Output::Template::Provider');
my $Directory = $Self->GetArgument('directory');
if ( !-d $Directory ) {
$Self->PrintError("Please provide a directory. '$Directory' is not a valid directory.");
return $Self->ExitCodeError();
}
my @FileList;
# Regular DTLs
if ( -d "$Directory/Kernel/Output/HTML/" ) {
push @FileList, $Kernel::OM->Get('Kernel::System::Main')->DirectoryRead(
Directory => "$Directory/Kernel/Output/HTML/",
Filter => "*.dtl",
Recursive => 1,
);
}
# Customized DTLs
if ( -d "$Directory/Custom/Kernel/Output/HTML/" ) {
push @FileList, $Kernel::OM->Get('Kernel::System::Main')->DirectoryRead(
Directory => "$Directory/Custom/Kernel/Output/HTML/",
Filter => "*.dtl",
Recursive => 1,
);
}
# XML configuration files, may also contain DTL tags
if ( -d "$Directory/Kernel/Config/Files/" ) {
push @FileList, $Kernel::OM->Get('Kernel::System::Main')->DirectoryRead(
Directory => "$Directory/Kernel/Config/Files/",
Filter => "*.xml",
Recursive => 1,
);
}
if ( !@FileList ) {
$Self->PrintError("No affected files found in $Directory.");
return $Self->ExitCodeError();
}
my $Success = 1;
for my $File (@FileList) {
my $ContentRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $File,
Mode => 'utf8',
);
my $TTFile = $File;
$TTFile =~ s{[.]dtl$}{.tt}smx;
print "$File -> $TTFile\n";
# Correct file name in header (*.dtl -> *.tt)
${$ContentRef} =~ s{(\A# --\n# [a-zA-Z0-9/]+[.])dtl[ ]}{$1tt };
my $TTContent;
eval {
$TTContent = $ProviderObject->MigrateDTLtoTT( Content => ${$ContentRef} );
};
if ($@) {
$Self->PrintError("There were errors processing this file:\n$@\n");
$Success = 0;
}
if ( $TTContent ne ${$ContentRef} ) {
$Kernel::OM->Get('Kernel::System::Main')->FileWrite(
Location => $TTFile,
Content => \$TTContent,
Mode => 'utf8',
);
}
}
if ( !$Success ) {
$Self->PrintError("\nThere were errors converting the files, please see above!\n");
return $Self->ExitCodeError();
}
$Self->Print("\n<green>All files ok.</green>\n");
return $Self->ExitCodeOk();
}
1;