From fb9474a6c33f0160db6e68d43b0864ae77178bc5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 14 Nov 2024 02:02:46 +0000 Subject: [PATCH] Bug 35716: (alternate) Add a "public" directory to Koha and share its "shared" subdir This change adds a "public" directory to Koha. Using Apache configuration, we share "public/shared" as "/shared", which allows us to serve the same static content for both the OPAC and the staff interface. At this time, this must be non-translated static assets, such as CSS, vendor Javascript libraries, images, or other code which does not deal with translatable strings. Test plan: 1. Apply the patch and koha-plack --restart kohadev 2. Make sure you're using a correct koha-gitify NOTE: See https://gitlab.com/koha-community/koha-gitify/-/merge_requests/3 NOTE: Need to modify koha-gitify for rewriting apache-shared-*.conf files NOTE: 'Alias /shared "/usr/share/koha/public/shared"' => qq#Alias /shared "$gitcheckout/public/shared"#, 3. Setup Apache configuration sudo cp debian/templates/apache-shared-opac.conf /etc/koha/apache-shared-opac.conf sudo cp debian/templates/apache-shared-intranet.conf /etc/koha/apache-shared-intranet.conf sudo rm /etc/koha/apache*git.conf sudo /kohadevbox/gitify/koha-gitify kohadev /kohadevbox/koha sudo service apache2 restart 4. Go to http://localhost:8081/shared/.placeholder Note that there's a file there 5. http://localhost:8080/shared/.placeholder Note that it's the same file as the staff interface 6. Check Koha installations -- 1. Check a "single" build NOTE: For simplicity, run the following as the root user: make clean rm -rf /opt/kohatest/ INSTALL_MODE=single INSTALL_BASE=/opt/kohatest PERL_MM_USE_DEFAULT=1 perl Makefile.PL make make install vi /opt/kohatest/etc/koha-httpd.conf Note that the 'shared' alias is there: Alias /shared "/opt/kohatest/public/shared" 2. Check a "dev" build NOTE: For simplicity, run the following as the root user: make clean rm -rf /opt/kohatest/ INSTALL_MODE=dev INSTALL_BASE=/opt/kohatest PERL_MM_USE_DEFAULT=1 perl Makefile.PL make make install vi /opt/kohatest/etc/koha-httpd.conf Note that the 'shared' alias is there: Alias /shared "/kohadevbox/koha/public/shared" 3. Check a "standard" build NOTE: For simplicity, run the following as the root user: make clean rm -rf /opt/kohatest/ INSTALL_MODE=standard INSTALL_BASE=/opt/kohatest KOHA_USER=root PERL_MM_USE_DEFAULT=1 perl Makefile.PL make make install vi /etc/kohatest/koha-httpd.conf Note that the 'shared' alias is there: Alias /shared "/opt/kohatest/public/shared" --- Makefile.PL | 9 +++++++++ debian/templates/apache-shared-intranet.conf | 3 ++- debian/templates/apache-shared-opac.conf | 3 ++- etc/koha-httpd.conf | 9 +++++++-- public/shared/.placeholder | 1 + rewrite-config.PL | 1 + 6 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 public/shared/.placeholder diff --git a/Makefile.PL b/Makefile.PL index 62062d96b2..eab08bf493 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -198,6 +198,10 @@ HTML templates for the OPAC interface. HTML files, images, etc. for DocumentRoot for the OPAC interface. +=item PUBLIC_WWW_DIR + +Public files for WWW interfaces. + =item PERL_MODULE_DIR Perl modules (at present just the C4 modules) that are intimately @@ -331,6 +335,7 @@ my $target_map = { './Koha.pm' => 'PERL_MODULE_DIR', './koha-tmpl/intranet-tmpl' => { target => 'INTRANET_TMPL_DIR', trimdir => -1 }, './koha-tmpl/opac-tmpl' => { target => 'OPAC_TMPL_DIR', trimdir => -1 }, + './public' => { target => 'PUBLIC_WWW_DIR', trimdir => -1 }, './kohaversion.pl' => 'INTRANET_CGI_DIR', './labels' => 'INTRANET_CGI_DIR', './lib' => { target => 'PERL_MODULE_LIB_DIR', trimdir => -1 }, @@ -1458,6 +1463,7 @@ sub get_target_directories { $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin'); $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{'PUBLIC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'public'); $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'); @@ -1491,6 +1497,8 @@ sub get_target_directories { $skipdirs{'OPAC_TMPL_DIR'} = 1; $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl'); $skipdirs{'OPAC_WWW_DIR'} = 1; + $dirmap{'PUBLIC_WWW_DIR'} = File::Spec->catdir($curdir, 'public'); + $skipdirs{'PUBLIC_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; @@ -1523,6 +1531,7 @@ sub get_target_directories { $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin'); $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{'PUBLIC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'public'); $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); diff --git a/debian/templates/apache-shared-intranet.conf b/debian/templates/apache-shared-intranet.conf index 49b742f868..89cf93a962 100644 --- a/debian/templates/apache-shared-intranet.conf +++ b/debian/templates/apache-shared-intranet.conf @@ -7,6 +7,7 @@ DocumentRoot /usr/share/koha/intranet/htdocs +Alias /shared "/usr/share/koha/public/shared" ScriptAlias /cgi-bin/koha/ "/usr/share/koha/intranet/cgi-bin/" ScriptAlias /index.html "/usr/share/koha/intranet/cgi-bin/mainpage.pl" ScriptAlias /search "/usr/share/koha/intranet/cgi-bin/catalogue/search.pl" @@ -18,7 +19,7 @@ RewriteRule ^/cgi-bin/koha/(C4|debian|docs|etc|installer/data|install_misc|Koha| RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/catalogue/detail.pl?biblionumber=$1 [PT] RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT] RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT] -RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L] +RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [PT,L] RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT] RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/preservation/.*.pl$ diff --git a/debian/templates/apache-shared-opac.conf b/debian/templates/apache-shared-opac.conf index 2568e0c966..6ae04664da 100644 --- a/debian/templates/apache-shared-opac.conf +++ b/debian/templates/apache-shared-opac.conf @@ -7,6 +7,7 @@ DocumentRoot /usr/share/koha/opac/htdocs +Alias /shared "/usr/share/koha/public/shared" ScriptAlias /cgi-bin/koha/ "/usr/share/koha/opac/cgi-bin/opac/" ScriptAlias /index.html "/usr/share/koha/opac/cgi-bin/opac/opac-main.pl" ScriptAlias /search "/usr/share/koha/opac/cgi-bin/opac/opac-search.pl" @@ -15,7 +16,7 @@ ScriptAlias /opac-search.pl "/usr/share/koha/opac/cgi-bin/opac/opac-search.pl" RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/opac-detail\.pl?bib=$1 [PT] RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT] RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT] -RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L] +RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [PT,L] = 2.4> AliasMatch "^/sitemap(.*)" "/var/lib/koha/${instance}/sitemap/sitemap$1" diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index f09bfaf91c..3fbecad0c6 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -7,6 +7,8 @@ ServerAdmin __WEBMASTER_EMAIL__ DocumentRoot __OPAC_WWW_DIR__ ServerName __WEBSERVER_HOST__ + + Alias /shared "__PUBLIC_WWW_DIR__/shared" # ServerAlias opac.mydomain.com ScriptAlias /cgi-bin/koha/ "__OPAC_CGI_DIR__/opac/" ScriptAlias /index.html "__OPAC_CGI_DIR__/opac/opac-main.pl" @@ -105,7 +107,7 @@ RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/opac-detail\.pl?bib=$1 [PT] RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT] RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT] - RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L] + RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [PT,L] RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT] RewriteRule ^/cgi-bin/koha/preservation/.*$ /cgi-bin/koha/preservation/home.pl [PT] @@ -140,6 +142,9 @@ ServerAdmin __WEBMASTER_EMAIL__ DocumentRoot __INTRANET_WWW_DIR__ ServerName __WEBSERVER_HOST__:__WEBSERVER_PORT_LIBRARIAN__ + + Alias /shared "__PUBLIC_WWW_DIR__/shared" + # ServerAlias intranet.mydomain.com ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/" ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl" @@ -230,7 +235,7 @@ RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/catalogue/detail.pl?biblionumber=$1 [PT] RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT] RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT] - RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L] + RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [PT,L] # REST API configuration diff --git a/public/shared/.placeholder b/public/shared/.placeholder new file mode 100644 index 0000000000..72f83bee77 --- /dev/null +++ b/public/shared/.placeholder @@ -0,0 +1 @@ +#This is a placeholder diff --git a/rewrite-config.PL b/rewrite-config.PL index b0ecb8f80d..1e65d717fd 100644 --- a/rewrite-config.PL +++ b/rewrite-config.PL @@ -118,6 +118,7 @@ my %configuration = ( '__OPAC_CGI_DIR__' => "$prefix/opac/cgi-bin", '__OPAC_TMPL_DIR__' => "$prefix/opac/templates", '__OPAC_WWW_DIR__' => "$prefix/opac/www", + '__PUBLIC_WWW_DIR__' => "$prefix/public", '__PERL_MODULE_DIR__' => ($ENV{'INSTALLSITELIB'} || sprintf($prefix."/lib/perl5/site_perl/%vd",$^V))."/koha", '__KOHA_CONF_DIR__' => "$prefix/etc/koha", '__ZEBRA_CONF_DIR__' => "$prefix/etc/koha/zebradb", -- 2.39.5