Backport r9186, r9187, and r9215 from trunk:
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 8 Jul 2008 17:26:49 +0000 (17:26 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 8 Jul 2008 17:26:49 +0000 (17:26 +0000)
  * Add a -u flag to autogen.sh to update org_unit proximity
  * Make autogen.sh guess at the location of opensrf_core.xml if no args are passed at the command line

git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2_2@9993 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/Makefile
Open-ILS/src/extras/autogen.sh
Open-ILS/src/extras/org_tree_proximity.pl [new file with mode: 0644]

index 76c9b53..6584bd2 100644 (file)
@@ -100,6 +100,7 @@ autojs-install:
        cp extras/fieldmapper.pl $(BINDIR)
        cp extras/org_tree_js.pl $(BINDIR)
        cp extras/org_tree_html_options.pl $(BINDIR)
+       cp extras/org_tree_proximity.pl $(BINDIR)
        cp extras/autogen.sh $(BINDIR)
        cp support-scripts/offline-blocked-list.pl $(BINDIR) # this should probably be somewhere else
 # -----------------------------------------------------------------------------------
index 8804b2b..798c168 100755 (executable)
@@ -1,6 +1,49 @@
 #!/bin/bash
+# -----------------------------------------------------------------------
+# Copyright (C) 2005-2008  Georgia Public Library Service
+# Bill Erickson <billserickson@gmail.com>
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# -----------------------------------------------------------------------
+
 # vim:noet:ts=4
 
+# ---------------------------------------------------------------------------
+# Make sure we're running as the correct user
+# ---------------------------------------------------------------------------
+[ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
+
+function usage {
+       echo "";
+       echo "usage: $0 [-u] -c <c_config>";
+       echo "";
+       echo "Mandatory parameters:";
+       echo -e "  -c\t\tfull path to C configuration file (opensrf_core.xml)";
+       echo "";
+       echo "Optional parameters:";
+       echo -e "  -u\t\tupdate proximity of library sites in organization tree";
+       echo -e "    \t\t(this is expensive for a large organization tree)";
+       echo "";
+       echo "Examples:";
+       echo "";
+       echo "  Update organization tree:";
+       echo "    $0 -c /openils/conf/opensrf_core.xml";
+       echo "    $0 /openils/conf/opensrf_core.xml";
+       echo "";
+       echo "  Update organization tree and refresh proximity:";
+       echo "    $0 -u -c /openils/conf/opensrf_core.xml";
+       echo "";
+       exit;
+}
+
 (
 
 BASEDIR=${0%/*}
@@ -13,7 +56,18 @@ cd "$BASEDIR"
 
 CONFIG="$1";
 
-[ -z "$CONFIG" ] && echo "usage: $0 <bootstrap_config>" && exit;
+# ---------------------------------------------------------------------------
+# Load the command line options and set the global vars
+# ---------------------------------------------------------------------------
+while getopts  "c:u h" flag; do
+       case $flag in   
+               "c")            CONFIG="$OPTARG";;
+               "u")            PROXIMITY="REFRESH";;
+               "h")            usage;;
+       esac;
+done
+
+[ -z "$CONFIG" ] && usage;
 
 JSDIR="/openils/var/web/opac/common/js/";
 SLIMPACDIR="/openils/var/web/opac/extras/slimpac/";
@@ -30,6 +84,13 @@ perl org_tree_js.pl "$CONFIG" > "$JSDIR/OrgTree.js";
 echo "Updating OrgTree HTML";
 perl org_tree_html_options.pl "$CONFIG" "$SLIMPACDIR/lib_list.inc";
 
+if [ "$PROXIMITY" ]
+then
+       echo "Refreshing proximity of org units";
+       perl org_tree_proximity.pl "$CONFIG";
+fi
+
+echo "";
 echo "Done";
 
 )
diff --git a/Open-ILS/src/extras/org_tree_proximity.pl b/Open-ILS/src/extras/org_tree_proximity.pl
new file mode 100644 (file)
index 0000000..97a435f
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+# -----------------------------------------------------------------------
+# Copyright (C) 2008  Laurentian University
+# Dan Scott <dscott@laurentian.ca>
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# -----------------------------------------------------------------------
+
+# calculate the proximity of organizations in the organization tree
+
+# vim:noet:ts=4:sw=4
+
+use OpenSRF::AppSession;
+use OpenSRF::System;
+use OpenILS::Utils::Fieldmapper;
+use OpenSRF::Utils::SettingsClient;
+
+die "usage: perl org_tree_proximity.pl <bootstrap_config>" unless $ARGV[0];
+OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
+
+Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
+
+my $ses = OpenSRF::AppSession->create("open-ils.storage");
+my $result = $ses->request("open-ils.storage.actor.org_unit.refresh_proximity");
+
+if ($result) {
+       print "Successfully updated the organization proximity";
+} else {
+       print "Failed to update the organiziation proximity";
+}
+
+$ses->disconnect();