From 40089a0a538dffca7ee5bd619b902b9830e4460c Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 7 Jun 2021 00:14:55 +0000 Subject: [PATCH] Bug 28519: Put CGI::Session::Serialize::yamlxs in lib directory This patch adds a "lib" directory to the source tree which gets mapped to the same directory as "C4" and "Koha" for single and standard installations. CGI::Session::Serialize::yamlxs is put into this "lib" directory. This patch also includes some changes so that dev/git installations work as well. Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart --- C4/Auth.pm | 34 ++++--------------------- Makefile.PL | 39 +++++++++++++++++++++++++++-- debian/scripts/koha-functions.sh | 2 +- etc/koha-httpd.conf | 6 ++--- etc/koha-worker.service | 2 +- lib/CGI/Session/Serialize/yamlxs.pm | 22 ++++++++++++++++ misc/bin/koha-index-daemon-ctl.sh | 2 +- misc/koha-install-log | 2 ++ rewrite-config.PL | 2 ++ 9 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 lib/CGI/Session/Serialize/yamlxs.pm diff --git a/C4/Auth.pm b/C4/Auth.pm index cb35984b2e..2a2e3b6779 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1,31 +1,3 @@ -package CGI::Session::Serialize::yamlxs; -# Proof of concept: CGI::Session::Serialize::yamlxs for CGI::Session: - -use strict; -use warnings; - -# hacky hack to trick CGI::Session loader for serializers not to die in its "require": -$INC{'CGI/Session/Serialize/yamlxs.pm'} = '1'; - -use CGI::Session::ErrorHandler; -use YAML::XS (); - -$CGI::Session::Serialize::yamlxs::VERSION = '0.1'; -@CGI::Session::Serialize::yamlxs::ISA = ( "CGI::Session::ErrorHandler" ); - -sub freeze { - my ($self, $data) = @_; - return YAML::XS::Dump($data); -} - -sub thaw { - my ($self, $string) = @_; - return (YAML::XS::Load($string))[0]; -} -# ******************************************************************** - - - package C4::Auth; # Copyright 2000-2002 Katipo Communications @@ -1899,7 +1871,11 @@ sub _get_session_params { sub get_session { my $sessionID = shift; my $params = _get_session_params(); - return CGI::Session->new( $params->{dsn}, $sessionID, $params->{dsn_args} ); + my $session = CGI::Session->new( $params->{dsn}, $sessionID, $params->{dsn_args} ); + if ( ! $session ){ + die CGI::Session->errstr(); + } + return $session; } diff --git a/Makefile.PL b/Makefile.PL index 9ade47696c..b044dd165c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -334,6 +334,7 @@ my $target_map = { './koha-tmpl/opac-tmpl' => {target => 'OPAC_TMPL_DIR', trimdir => -1}, './kohaversion.pl' => 'INTRANET_CGI_DIR', './labels' => 'INTRANET_CGI_DIR', + './lib' => {target => 'PERL_MODULE_LIB_DIR', trimdir => -1}, './mainpage.pl' => 'INTRANET_CGI_DIR', './Makefile.PL' => 'NONE', './MANIFEST.SKIP' => 'NONE', @@ -1433,6 +1434,7 @@ sub get_target_directories { $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl'); $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs'); $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib'); + $dirmap{'PERL_MODULE_LIB_DIR'} = File::Spec->catdir(@basedir, $package, 'lib'); $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc'); $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb'); $dirmap{'Z3950_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'z3950'); @@ -1464,8 +1466,11 @@ sub get_target_directories { $skipdirs{'OPAC_TMPL_DIR'} = 1; $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl'); $skipdirs{'OPAC_WWW_DIR'} = 1; + #NOTE: We're hacking the dirmap here, so that PERL_MODULE_DIR tokens get rewritten correctly for git installs $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir); $skipdirs{'PERL_MODULE_DIR'} = 1; + $dirmap{'PERL_MODULE_LIB_DIR'} = File::Spec->catdir($curdir,'lib'); + $skipdirs{'PERL_MODULE_LIB_DIR'} = 1; $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc'); $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb'); $dirmap{'Z3950_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'z3950'); @@ -1494,6 +1499,7 @@ sub get_target_directories { $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl'); $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs'); $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib'); + $dirmap{'PERL_MODULE_LIB_DIR'} = File::Spec->catdir(@basedir, $package, 'lib'); $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package); $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb'); $dirmap{'Z3950_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'z3950'); @@ -1646,6 +1652,8 @@ sub install { # This means that we're completely overriding EU::MM's default # installation and uninstallation targets. + my $perl5lib_dirs = _build_perl5lib_string({ target_dirs => $target_directories }); + # If installation is on Win32, we need to do permissions different from *nix if ( $^O =~ /darwin|linux|cygwin|freebsd|solaris/ ) { # this value needs to be verified for each platform and modified accordingly foreach my $key (sort keys %$target_directories) { @@ -1700,7 +1708,7 @@ install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_en $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n"; $install .= "\t\$(NOECHO) \$(ECHO)\n"; $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n"; - $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n"; + $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$perl5lib_dirs\n"; $install .= "\t\$(NOECHO) \$(ECHO)\n"; $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n"; $install .= "\t\$(NOECHO) \$(ECHO)\n"; @@ -1767,9 +1775,16 @@ sub postamble { # rewrite-confg.PL my $env; + + #NOTE: Build __PERL5LIB_DIRS__ for rewrite-config.PL + my $perl5lib_dirs = _build_perl5lib_string({ target_dirs => $target_directories }); + if ($perl5lib_dirs){ + $env .= "export __PERL5LIB_DIRS__ := $perl5lib_dirs\n" + } + # Hereagain, we must alter syntax per platform... { - $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories); + $env .= join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories); $env .= "\n\n"; $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config); } @@ -1777,6 +1792,26 @@ sub postamble { return "$env\n"; } +sub _build_perl5lib_string { + my ($args) = @_; + my %unique_map = (); + my $perl5lib_str; + my $target_dirs = $args->{target_dirs}; + my @dir_codes = ("PERL_MODULE_DIR","PERL_MODULE_LIB_DIR"); + if ($target_dirs){ + foreach my $code (@dir_codes){ + my $path = $target_dirs->{ $code }; + if ($path){ + $unique_map{$path} = 1 unless $unique_map{$path}; + } + } + my @paths = sort keys %unique_map; + if (@paths){ + $perl5lib_str = join(':',@paths); + } + } + return $perl5lib_str; +} __END__ diff --git a/debian/scripts/koha-functions.sh b/debian/scripts/koha-functions.sh index f82ebfcc80..8888ad6290 100755 --- a/debian/scripts/koha-functions.sh +++ b/debian/scripts/koha-functions.sh @@ -330,7 +330,7 @@ adjust_paths_dev_install() if [ "$dev_install" != "" ] && [ "$dev_install" != "0" ]; then DEV_INSTALL=1 KOHA_HOME=$(run_safe_xmlstarlet $instancename intranetdir) - PERL5LIB=$KOHA_HOME + PERL5LIB="$KOHA_HOME:$KOHA_HOME/lib" else DEV_INSTALL="" fi diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index fc2e440a6e..62b5520afa 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -16,7 +16,7 @@ # CustomLog __LOG_DIR__/koha-opac-access.log combined # TransferLog __LOG_DIR__/koha-opac-access.log SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml" - SetEnv PERL5LIB "__PERL_MODULE_DIR__" + SetEnv PERL5LIB "__PERL5LIB_DIRS__" # This syntax allows you to override a system preference # for a given virtual host. Use with caution! @@ -143,7 +143,7 @@ ErrorLog __LOG_DIR__/koha-error_log # TransferLog __LOG_DIR__/koha-access.log SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml" - SetEnv PERL5LIB "__PERL_MODULE_DIR__" + SetEnv PERL5LIB "__PERL5LIB_DIRS__" Options +FollowSymLinks # If you are overriding any system preferences, @@ -254,7 +254,7 @@ # DocumentRoot __INTRANET_CGI_DIR__/api # ServerName api.__WEBSERVER_HOST__:__WEBSERVER_PORT__ # SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml" -# SetEnv PERL5LIB "__PERL_MODULE_DIR__" +# SetEnv PERL5LIB "__PERL5LIB_DIRS__" # ErrorLog __LOG_DIR__/koha-api-error_log # # diff --git a/etc/koha-worker.service b/etc/koha-worker.service index 126698b4c1..e53ab30e0f 100644 --- a/etc/koha-worker.service +++ b/etc/koha-worker.service @@ -4,7 +4,7 @@ Description=Koha Task Queue Worker After=syslog.target network.target [Service] -Environment=PERL5LIB=__PERL_MODULE_DIR__ +Environment=PERL5LIB=__PERL5LIB_DIRS__ Environment=KOHA_CONF=__KOHA_CONF_DIR__/koha-conf.xml ExecStart=__SCRIPT_DIR__/background_jobs_worker.pl Restart=on-failure diff --git a/lib/CGI/Session/Serialize/yamlxs.pm b/lib/CGI/Session/Serialize/yamlxs.pm new file mode 100644 index 0000000000..77d2a8d51a --- /dev/null +++ b/lib/CGI/Session/Serialize/yamlxs.pm @@ -0,0 +1,22 @@ +package CGI::Session::Serialize::yamlxs; + +use strict; +use warnings; + +use CGI::Session::ErrorHandler; +use YAML::XS (); + +$CGI::Session::Serialize::yamlxs::VERSION = '0.1'; +@CGI::Session::Serialize::yamlxs::ISA = ( "CGI::Session::ErrorHandler" ); + +sub freeze { + my ($self, $data) = @_; + return YAML::XS::Dump($data); +} + +sub thaw { + my ($self, $string) = @_; + return (YAML::XS::Load($string))[0]; +} + +1; diff --git a/misc/bin/koha-index-daemon-ctl.sh b/misc/bin/koha-index-daemon-ctl.sh index 1c8f4fef4a..b974b570a8 100755 --- a/misc/bin/koha-index-daemon-ctl.sh +++ b/misc/bin/koha-index-daemon-ctl.sh @@ -32,7 +32,7 @@ GROUP=__KOHA_GROUP__ DBNAME=__DB_NAME__ NAME=koha-index-daemon-$DBNAME LOGDIR=__LOG_DIR__ -PERL5LIB=__PERL_MODULE_DIR__ +PERL5LIB="__PERL5LIB_DIRS__" KOHA_CONF=__KOHA_CONF_DIR__/koha-conf.xml ERRLOG=$LOGDIR/koha-index-daemon.err STDOUT=$LOGDIR/koha-index-daemon.log diff --git a/misc/koha-install-log b/misc/koha-install-log index 7e56fd1876..52ce8c9d24 100644 --- a/misc/koha-install-log +++ b/misc/koha-install-log @@ -64,3 +64,5 @@ FONT_DIR=__FONT_DIR__ USE_ELASTICSEARCH=__USE_ELASTICSEARCH__ ELASTICSEARCH_SERVERS=__ELASTICSEARCH_SERVERS__ ELASTICSEARCH_INDEX=__ELASTICSEARCH_INDEX__ +PERL_MODULE_LIB_DIR=__PERL_MODULE_LIB_DIR__ +PERL5LIB_DIRS=__PERL5LIB_DIRS__ diff --git a/rewrite-config.PL b/rewrite-config.PL index 4484e60d34..b0ecb8f80d 100644 --- a/rewrite-config.PL +++ b/rewrite-config.PL @@ -159,6 +159,8 @@ my %configuration = ( '__SMTP_USER_NAME__' => '', '__SMTP_PASSWORD__' => '', '__SMTP_DEBUG__' => '0', + '__PERL_MODULE_LIB_DIR__' => "$prefix/lib", + '__PERL5LIB_DIRS__' => "$prefix/lib", ); # Override configuration from the environment -- 2.39.5