#!/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%/*}
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/";
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";
)
--- /dev/null
+#!/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();