Bug 28519: Put CGI::Session::Serialize::yamlxs in lib directory
authorDavid Cook <dcook@prosentient.com.au>
Mon, 7 Jun 2021 00:14:55 +0000 (00:14 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 17 Jun 2021 08:07:36 +0000 (10:07 +0200)
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 <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Auth.pm
Makefile.PL
debian/scripts/koha-functions.sh
etc/koha-httpd.conf
etc/koha-worker.service
lib/CGI/Session/Serialize/yamlxs.pm [new file with mode: 0644]
misc/bin/koha-index-daemon-ctl.sh
misc/koha-install-log
rewrite-config.PL

index cb35984..2a2e3b6 100644 (file)
@@ -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
 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();
 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;
 }
 
 
 }
 
 
index 9ade476..b044dd1 100644 (file)
@@ -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',
   './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',
   './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{'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');
         $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;
         $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_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');
         $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{'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');
         $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.
 
     # 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) {
 # 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) 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";
     $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;
     # 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...
         {
        # 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);
        }
                $env .= "\n\n";
                $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
        }
@@ -1777,6 +1792,26 @@ sub postamble {
     return "$env\n";
 }
 
     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__
 
 
 __END__
 
index f82ebfc..8888ad6 100755 (executable)
@@ -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)
     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
     else
         DEV_INSTALL=""
     fi
index fc2e440..62b5520 100644 (file)
@@ -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"
 #  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!
 
    # This syntax allows you to override a system preference
    # for a given virtual host. Use with caution!
    ErrorLog __LOG_DIR__/koha-error_log
 #  TransferLog __LOG_DIR__/koha-access.log
    SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
    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,
    Options +FollowSymLinks
 
    # If you are overriding any system preferences,
 #  DocumentRoot __INTRANET_CGI_DIR__/api
 #  ServerName api.__WEBSERVER_HOST__:__WEBSERVER_PORT__
 #  SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"
 #  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
 #
 #  <IfModule mod_rewrite.c>
 #  ErrorLog __LOG_DIR__/koha-api-error_log
 #
 #  <IfModule mod_rewrite.c>
index 126698b..e53ab30 100644 (file)
@@ -4,7 +4,7 @@ Description=Koha Task Queue Worker
 After=syslog.target network.target
 
 [Service]
 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
 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 (file)
index 0000000..77d2a8d
--- /dev/null
@@ -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;
index 1c8f4fe..b974b57 100755 (executable)
@@ -32,7 +32,7 @@ GROUP=__KOHA_GROUP__
 DBNAME=__DB_NAME__
 NAME=koha-index-daemon-$DBNAME
 LOGDIR=__LOG_DIR__
 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
 KOHA_CONF=__KOHA_CONF_DIR__/koha-conf.xml
 ERRLOG=$LOGDIR/koha-index-daemon.err
 STDOUT=$LOGDIR/koha-index-daemon.log
index 7e56fd1..52ce8c9 100644 (file)
@@ -64,3 +64,5 @@ FONT_DIR=__FONT_DIR__
 USE_ELASTICSEARCH=__USE_ELASTICSEARCH__
 ELASTICSEARCH_SERVERS=__ELASTICSEARCH_SERVERS__
 ELASTICSEARCH_INDEX=__ELASTICSEARCH_INDEX__
 USE_ELASTICSEARCH=__USE_ELASTICSEARCH__
 ELASTICSEARCH_SERVERS=__ELASTICSEARCH_SERVERS__
 ELASTICSEARCH_INDEX=__ELASTICSEARCH_INDEX__
+PERL_MODULE_LIB_DIR=__PERL_MODULE_LIB_DIR__
+PERL5LIB_DIRS=__PERL5LIB_DIRS__
index 4484e60..b0ecb8f 100644 (file)
@@ -159,6 +159,8 @@ my %configuration = (
   '__SMTP_USER_NAME__' => '',
   '__SMTP_PASSWORD__'  => '',
   '__SMTP_DEBUG__'     => '0',
   '__SMTP_USER_NAME__' => '',
   '__SMTP_PASSWORD__'  => '',
   '__SMTP_DEBUG__'     => '0',
+  '__PERL_MODULE_LIB_DIR__'  => "$prefix/lib",
+  '__PERL5LIB_DIRS__'  => "$prefix/lib",
 );
 
 # Override configuration from the environment
 );
 
 # Override configuration from the environment