]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/circ_rules.pl
8c63e7de83b9ec3712cb17edd08f12e8cad67162
[working/Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / circ_rules.pl
1 #/usr/bin/perl
2 use strict; use warnings;
3 use lib q|../../../perlmods/|;
4 use OpenILS::Utils::ScriptRunner;
5 use OpenILS::Utils::CStoreEditor qw/:funcs/;
6 use OpenILS::Application::Circ::ScriptBuilder;
7 use Time::HiRes qw/time/;
8 require '../oils_header.pl';
9 use vars qw/ $user $authtoken $apputils /;
10
11 my $events                      = 'result.events';
12 my $fatal_events        = 'result.fatalEvents';
13 my $info_events = 'result.infoEvents';
14
15
16 # ---------------------------------------------------------------------
17 # SCRIPT VARS
18 # ----------------------------------------------------------------------
19 #my $patronid                                   = 3;
20 my $patronid                                    = 1000502;
21 my $copyid                                              = 8000107;
22 my $patron_items_out                    = 11;
23 my $patron_overdue_count        = 11;
24 my $patron_fines                                = 20;
25
26 # these are not currently tested in the scripts
27 my $is_renewal                                  = 0;
28 my $is_non_cat                                  = 0;
29 my $is_hold                                             = 0;
30 my $non_cat_type                                = 1;
31 # ---------------------------------------------------------------------
32
33
34
35 my $bsconfig = shift;
36 my $script = shift;
37
38 die "$0: <bootstrap> <script>\n" unless $script;
39
40 my $path;
41
42 ($path, $script) = ($script =~ m#(/.*/)(.*)#);
43
44 osrf_connect($bsconfig);
45
46 my $s = time;
47 my $runner = OpenILS::Application::Circ::ScriptBuilder->build(
48         {
49                 copy_id                                         => $copyid,
50                 patron_id                                       => $patronid,
51                 fetch_patron_circ_info  => 1,
52                 _direct                                         => {
53                         isNonCat                => $is_non_cat,
54                         isRenewal       => $is_renewal,
55                         nonCatType      => $non_cat_type,
56                 }
57         }
58 );
59
60
61 # ---------------------------------------------------------------------
62 # Override the default log functions for convenience
63 # ---------------------------------------------------------------------
64 $runner->insert(log_activity    => sub { print "@_\n"; return 1;} );
65 $runner->insert(log_error               => sub { print "@_\n"; return 1;} );
66 $runner->insert(log_warn                => sub { print "@_\n"; return 1;} );
67 $runner->insert(log_info                => sub { print "@_\n"; return 1;} );
68 $runner->insert(log_debug               => sub { print "@_\n"; return 1;} );
69 $runner->insert(log_internal    => sub { print "@_\n"; return 1;} );
70
71
72 $runner->add_path($path);
73
74
75 # ---------------------------------------------------------------------
76 # Run the script
77 # ---------------------------------------------------------------------
78 print "\nLoading script: $script\n";
79 print "\n" . '-'x70 . "\n";
80
81 $runner->load($script);
82 $runner->run or die "Script died: $@";
83 my $end = time - $s;
84
85
86 # ---------------------------------------------------------------------
87 # Print out any events that occurred
88 # ---------------------------------------------------------------------
89 print "\n" . '-'x70 . "\n";
90
91 show_events( 'events', $runner->retrieve($events));
92 show_events( 'fatal_events', $runner->retrieve($fatal_events));
93 show_events( 'info_events', $runner->retrieve($info_events));
94
95 print "\ntime = $end\n";
96
97
98 sub show_events {
99         my $t = shift;
100         my $e = shift;
101         my @e;
102
103         if($e and @e = split(/,/, $e)) {
104                 print "$t : $_\n" for @e;
105
106         } else {
107                 print "No $t occurred\n";
108         } 
109 }
110
111 print "\n";
112
113
114
115 # don't forget these..
116 #$runner->insert( "$evt.isRenewal", $is_renewal );
117 #$runner->insert( "$evt.isNonCat", $is_non_cat );
118 #$runner->insert( "$evt.isHold", $is_hold );
119 #$runner->insert( "$evt.nonCatType", $non_cat_type );
120