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