[Koha-patches] [PATCH] Bug 7844 - plack intranet tooling for developers

Dobrica Pavlinusic dpavlin at rot13.org
Thu Mar 29 13:59:29 CEST 2012


intranet.psgi example and script to run any Koha intranet under plack

This assumes that intranetdir in koha-conf.xml points to source code checkout.

It also defines new enviroment variables:

PLACK_DEBUG - turn debugging panels on
PLACK_MINIFY - minify JavaScript and CSS which saves us ~10k on each page load

Test scenario:
1. install plack, using ./cpanm-install.pl
2. start ./intranet-plack.sh sitename
   from misc/plack directory so it can find intranet.psgi here
3. open intranet page http://localhost:5001/cgi-bin/koha/mainpage.pl
---
 misc/plack/cpanm-install.sh  |    8 +++++++
 misc/plack/intranet-plack.sh |   18 +++++++++++++++++
 misc/plack/intranet.psgi     |   44 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 0 deletions(-)
 create mode 100755 misc/plack/cpanm-install.sh
 create mode 100755 misc/plack/intranet-plack.sh
 create mode 100644 misc/plack/intranet.psgi

diff --git a/misc/plack/cpanm-install.sh b/misc/plack/cpanm-install.sh
new file mode 100755
index 0000000..589cb73
--- /dev/null
+++ b/misc/plack/cpanm-install.sh
@@ -0,0 +1,8 @@
+#!/bin/sh -xe
+
+sudo cpan App::cpanminus
+cpanm --sudo Task::Plack \
+	Plack::Middleware::Static::Minifier \
+	Plack::Middleware::Debug::Profiler::NYTProf \
+	Plack::Middleware::Debug::DBIProfile
+
diff --git a/misc/plack/intranet-plack.sh b/misc/plack/intranet-plack.sh
new file mode 100755
index 0000000..716b902
--- /dev/null
+++ b/misc/plack/intranet-plack.sh
@@ -0,0 +1,18 @@
+#!/bin/sh -xe
+
+site=ffzg
+test ! -z "$1" && site=$1
+dir=`dirname $0`
+opt=""
+
+export KOHA_CONF=/etc/koha/sites/$site/koha-conf.xml 
+export INTRANETDIR="$( xmlstarlet sel -t -v 'yazgfs/config/intranetdir' $KOHA_CONF )"
+
+if [ ! -e "$INTRANETDIR/C4" ] ; then
+	echo "intranetdir in $KOHA_CONF doesn't point to Koha git checkout"
+	exit 1
+fi
+
+# we are not wathcing all CGI scripts since that tends to use a lot of CPU time for plackup
+opt="--reload -R $INTRANETDIR/C4"
+sudo -E -u $site-koha plackup -I $INTRANETDIR $opt --port 5001 $dir/intranet.psgi
diff --git a/misc/plack/intranet.psgi b/misc/plack/intranet.psgi
new file mode 100644
index 0000000..e7ec40e
--- /dev/null
+++ b/misc/plack/intranet.psgi
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+use Plack::Builder;
+use Plack::App::CGIBin;
+use Plack::Middleware::Debug;
+use Plack::App::Directory;
+
+# cpanm Plack::Middleware::Debug::DBIProfile
+
+use C4::Context;
+use C4::Languages;
+use C4::Members;
+use C4::Dates;
+use C4::Boolean;
+use C4::Letters;
+use C4::Koha;
+use C4::XSLT;
+use C4::Branch;
+use C4::Category;
+
+my $app=Plack::App::CGIBin->new(root => $ENV{INTRANETDIR});
+
+builder {
+
+	enable_if { $ENV{PLACK_DEBUG} } 'Debug',  panels => [
+		qw(Environment Response Timer Memory),
+#		[ 'Profiler::NYTProf', exclude => [qw(.*\.css .*\.png .*\.ico .*\.js .*\.gif)] ],
+#		[ 'DBITrace', level => 1 ], # a LOT of fine-graded SQL trace
+		[ 'DBIProfile', profile => 2 ],
+	];
+
+	enable_if { $ENV{PLACK_DEBUG} } 'StackTrace';
+
+	enable "Plack::Middleware::Static",
+		path => qr{^/intranet-tmpl/}, root => '/srv/koha/koha-tmpl/';
+
+	enable_if { $ENV{PLACK_MINIFIER} } "Plack::Middleware::Static::Minifier",
+		path => qr{^/intranet-tmpl/},
+		root => './koha-tmpl/';
+
+
+	mount "/cgi-bin/koha" => $app;
+
+};
+
-- 
1.7.2.5



More information about the Koha-patches mailing list