From 9abef95e479fad604946786e4c2f5ddc0b5163c1 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 14 Nov 2024 01:45:13 +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/cgi-bin/koha/mainpage.pl 5. Open the console, and run the following: debug_shared_js(); 6. Note that the console log shows "You successfully ran this function!" 7. Go to http://localhost:8080/cgi-bin/koha/opac-main.pl 8. Open the console, and run the following: debug_shared_js(); 9. Note that the console log shows "You successfully ran this function!" 10. 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" --- Koha/Template/Plugin/Asset.pm | 15 +++++++++++---- Makefile.PL | 9 +++++++++ debian/templates/apache-shared-intranet.conf | 3 ++- debian/templates/apache-shared-opac.conf | 3 ++- etc/koha-httpd.conf | 9 +++++++-- .../prog/en/includes/intranet-bottom.inc | 1 + .../bootstrap/en/includes/opac-bottom.inc | 1 + public/shared/js/debug.js | 3 +++ rewrite-config.PL | 1 + 9 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 public/shared/js/debug.js diff --git a/Koha/Template/Plugin/Asset.pm b/Koha/Template/Plugin/Asset.pm index 0afe209805..b1a6cced7f 100644 --- a/Koha/Template/Plugin/Asset.pm +++ b/Koha/Template/Plugin/Asset.pm @@ -124,7 +124,7 @@ Returns the URL for the given file =cut sub url { - my ( $self, $filename ) = @_; + my ( $self, $filename, $args ) = @_; my $stash = $self->{_CONTEXT}->stash(); my $interface = $stash->get('interface'); @@ -136,13 +136,20 @@ sub url { my ($basename, $dirname, $suffix) = fileparse($filename, qr/\.[^.]*/); my $type = substr $suffix, 1; + + my $version = Koha::version; + $version =~ s/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/$1.$2$3$4/; + + my $shared = $args->{shared}; + if ($shared){ + my $url = File::Spec->catfile('/shared',$dirname, "${basename}_${version}${suffix}"); + return $url; + } + my @dirs = ( "$theme", ".", ); - - my $version = Koha::version; - $version =~ s/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/$1.$2$3$4/; foreach my $dir (@dirs) { my $abspath = File::Spec->catfile($root, $dir, $filename); if (-e $abspath) { 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/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc index cb6b50ae30..fd9e436c38 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc @@ -169,6 +169,7 @@ [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %] [% END %] [% KohaPlugins.get_plugins_intranet_js | $raw %] + diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index 50d78ea97b..859e79abd2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -203,5 +203,6 @@ $(document).ready(function() { [% Asset.js("js/cookieconsent.js") | $raw %] [% END %] [% KohaPlugins.get_plugins_opac_js | $raw %] + diff --git a/public/shared/js/debug.js b/public/shared/js/debug.js new file mode 100644 index 0000000000..453e3f70c3 --- /dev/null +++ b/public/shared/js/debug.js @@ -0,0 +1,3 @@ +function debug_shared_js (){ + console.log("You successfully ran this function!"); +} 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