Skip to content

Commit

Permalink
Merge pull request #332 from RotherOSS/issue-323-out_of_band_printing
Browse files Browse the repository at this point in the history
Issue 323 out of band printing
  • Loading branch information
bschmalhofer authored Aug 7, 2020
2 parents f4ff201 + 1c8ef9f commit f40d9b0
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 38 deletions.
42 changes: 22 additions & 20 deletions Kernel/Modules/Installer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ sub new {
my ( $Type, %Param ) = @_;

# Allocate new hash for object.
my $Self = {%Param};
bless( $Self, $Type );

return $Self;
return bless { %Param }, $Type;
}

sub Run {
Expand Down Expand Up @@ -76,9 +73,12 @@ sub Run {
);
}

# Check/get SQL schema directory
# Get and check the SQL schema directory
my $DirOfSQLFiles = $Self->{Path} . '/scripts/database';
if ( !-d $DirOfSQLFiles ) {

# PSGI: throw exception
# non-PSGI: print to STDOUT and exit
$LayoutObject->FatalError(
Message => $LayoutObject->{LanguageObject}->Translate( 'Directory "%s" not found!', $DirOfSQLFiles ),
Comment => Translatable('Please contact the administrator.'),
Expand All @@ -102,7 +102,7 @@ sub Run {
$Self->{Subaction} = 'DBCreate';
}

$Self->{Subaction} = 'Intro' if !$Self->{Subaction};
$Self->{Subaction} ||= 'Intro';

# Set up the build steps.
# The license step is not needed when it is turned off in $Self->{Options}.
Expand Down Expand Up @@ -168,21 +168,22 @@ sub Run {
# Print intro form.
my $Title = $LayoutObject->{LanguageObject}->Translate('Install OTOBO');
if ( $Self->{Subaction} eq 'Intro' ) {
my $Output =
$LayoutObject->Header(
Title => "$Title - "
. $LayoutObject->{LanguageObject}->Translate('Intro')
);

# activate the Intro block
$LayoutObject->Block(
Name => 'Intro',
Data => {}
);
$Output .= $LayoutObject->Output(
TemplateFile => 'Installer',
Data => {},
);
$Output .= $LayoutObject->Footer();
return $Output;

return join '',
$LayoutObject->Header(
Title => "$Title - " . $LayoutObject->{LanguageObject}->Translate('Intro')
),
$LayoutObject->Output(
TemplateFile => 'Installer',
Data => {},
),
$LayoutObject->Footer();
}

# Print license from.
Expand Down Expand Up @@ -230,9 +231,9 @@ sub Run {
}

my %Databases = (
mysql => "MySQL",
postgresql => "PostgreSQL",
oracle => "Oracle",
mysql => 'MySQL',
postgresql => 'PostgreSQL',
oracle => 'Oracle',
);

# Build the select field for the InstallerDBStart.tt.
Expand Down Expand Up @@ -607,6 +608,7 @@ sub Run {
Data => {},
);
$Output .= $LayoutObject->Footer();

return $Output;
}
else {
Expand Down
32 changes: 16 additions & 16 deletions Kernel/Output/HTML/Layout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -947,16 +947,16 @@ sub FatalError {
$Output .= $Self->Footer();

if ( $ENV{OTOBO_RUNS_UNDER_PSGI} ) {
# use the regular flow, the OS process is not terminated
return $Output;
}
else {
# Terminate the process under Apache/mod_perl.
# Apparently there were some bad consequnces from using the regular flow.
$Self->Print( Output => \$Output );

exit;
# The exception should be caught be Plack::Middleware::HTTPExceptions
die Kernel::System::Web::Exception->new( Content => $Output );
}

# Terminate the process under Apache/mod_perl.
# Apparently there were some bad consequnces from using the regular flow.
$Self->Print( Output => \$Output );

exit;
}

sub SecureMode {
Expand Down Expand Up @@ -4394,16 +4394,16 @@ sub CustomerFatalError {
$Output .= $Self->CustomerFooter();

if ( $ENV{OTOBO_RUNS_UNDER_PSGI} ) {
# use the regular flow, the OS process is not terminated
return $Output;
}
else {
# Terminate the process under Apache/mod_perl.
# Apparently there were some bad consequnces from using the regular flow.
$Self->Print( Output => \$Output );

exit;
# The exception should be caught be Plack::Middleware::HTTPExceptions
die Kernel::System::Web::Exception->new( Content => $Output );
}

# Terminate the process under Apache/mod_perl.
# Apparently there were some bad consequnces from using the regular flow.
$Self->Print( Output => \$Output );

exit;
}

sub CustomerNavigationBar {
Expand Down
95 changes: 95 additions & 0 deletions Kernel/System/Web/Exception.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# --
# OTOBO is a web-based ticketing system for service organisations.
# --
# Copyright (C) 2020 Rother OSS GmbH, https://otobo.de/
# --
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# --

package Kernel::System::Web::Exception;

=head1 NAME
Kernel::System::Web::Exception - an exception object for Plack::Middleware::HTTPExceptions
=head1 SYNOPSIS
use Kernel::System::Web::Exception;
# fatal error encounted during handling of a request
my $IsFatal = 1;
if ( $IsFatal ) {
my $Content = "HTTP/1.1 200 OK\nContent-Type: text/plan{\n\nOberwalting, we have a problem";
die Kernel::System::Web::Exception->new( Content => $Content );
}
=head1 DESCRIPTION
The thrown instance provides the method C<as_psgi()> which can be handled by C<Plack::Middleware::HTTPExceptions>.
=cut

use v5.24.0;
use warnings;
use utf8;

# core modules

# CPAN modules
use CGI::Parse::PSGI qw(parse_cgi_output);

# OTOBO modules

our $ObjectManagerDisabled = 1;

=head1 PUBLIC INTERFACE
=head2 new
create an exception object
use Kernel::System::Web::Exception;
my $Content = "HTTP/1.1 200 OK\nContent-Type: text/plan{\n\nOberwalting, we have a problem";
die Kernel::System::Web::Exception->new( Content => $Content );
=cut

sub new {
my ( $Type, %Param ) = @_;

# start with a hash containing the params
return bless { %Param }, $Type;
}

=head2 as_psgi
make use of a caught exception object
my $Response = $CaughtObject->as_psgi()
=cut

sub as_psgi {
my $Self = shift;

# The thrower created the error message
if ( $Self->{Content} ) {
utf8::encode( $Self->{Content} );

return parse_cgi_output( \$Self->{Content} );
}

# error as default
return Plack::Response->new( 500, { 'Content-Type' => 'text/html' }, 'empty exception' );
}

1;
4 changes: 4 additions & 0 deletions bin/docker/build_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
export SOURCE_COMMIT=$(git rev-parse HEAD)
export SOURCE_BRANCH=$(git branch --show-current)

# for local build include a file that gives quick info about the build
rm -f local_docker_build_*
touch local_docker_build_$(hostname)_$(date +'%F-%H%M%S')

# build otobo:local
export DOCKERFILE_PATH=otobo.web.dockerfile
export IMAGE_NAME=otobo:local
Expand Down
9 changes: 7 additions & 2 deletions bin/psgi-bin/otobo.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ use Encode qw(:all);
use CGI ();
use CGI::Carp ();
use CGI::Emulate::PSGI ();
use CGI::Parse::PSGI qw(parse_cgi_output);
use CGI::PSGI;
use Plack::Builder;
use Plack::Response;
Expand Down Expand Up @@ -296,6 +297,7 @@ use Kernel::System::Web::InterfaceCustomer ();
use Kernel::System::Web::InterfacePublic ();
use Kernel::System::Web::InterfaceInstaller ();
use Kernel::System::Web::InterfaceMigrateFromOTRS ();
use Kernel::System::Web::Exception ();
use Kernel::GenericInterface::Provider;
use Kernel::System::ObjectManager;

Expand Down Expand Up @@ -625,6 +627,9 @@ my $OTOBOApp = builder {
# check ever 10s for changed Perl modules
enable 'Plack::Middleware::Refresh';

# we might catch an instance of Kernel::System::Web::Exception
enable 'HTTPExceptions';

# No need to set %ENV or redirect STDIN.
# But STDOUT and STDERR is still like in CGI scripts.
# logic taken from the scripts in bin/cgi-bin and from CGI::Emulate::PSGI
Expand Down Expand Up @@ -664,7 +669,7 @@ my $OTOBOApp = builder {
utf8::encode($HeaderAndContent);

# return a PSGI response
return CGI::Parse::PSGI::parse_cgi_output(\$HeaderAndContent);
return parse_cgi_output(\$HeaderAndContent);
}

# Capture the output written by $Installer->Run().
Expand Down Expand Up @@ -710,7 +715,7 @@ my $OTOBOApp = builder {
}
}

return CGI::Parse::PSGI::parse_cgi_output(\$Buffer);
return parse_cgi_output(\$Buffer);
};
};

Expand Down
1 change: 1 addition & 0 deletions otobo.web.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ RUN useradd --user-group --home-dir $OTOBO_HOME --create-home --shell /bin/bash

# copy the OTOBO installation to /opt/otobo and use it as the working dir
# skip the files set up in .dockerignore
ARG OTOBO_INSTALL=/opt/otobo_install
COPY --chown=$OTOBO_USER:$OTOBO_GROUP . $OTOBO_INSTALL/otobo_next
WORKDIR $OTOBO_INSTALL/otobo_next

Expand Down

0 comments on commit f40d9b0

Please sign in to comment.