]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm
allow circ.reshelving_complete.interval ou setting to override the default reshelving...
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Utils / CStoreEditor.pm
1 use strict; use warnings;
2 package OpenILS::Utils::CStoreEditor;
3 use OpenILS::Application::AppUtils;
4 use OpenSRF::AppSession;
5 use OpenSRF::EX qw(:try);
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Event;
8 use Data::Dumper;
9 use OpenSRF::Utils::JSON;
10 use OpenSRF::Utils::Logger qw($logger);
11 my $U = "OpenILS::Application::AppUtils";
12 my %PERMS;
13 my $cache;
14 my %xact_ed_cache;
15
16 our $always_xact = 0;
17 our $_loaded = 1;
18
19 #my %PERMS = (
20 #       'biblio.record_entry'   => { update => 'UPDATE_MARC' },
21 #       'asset.copy'                            => { update => 'UPDATE_COPY'},
22 #       'asset.call_number'             => { update => 'UPDATE_VOLUME'},
23 #       'action.circulation'            => { retrieve => 'VIEW_CIRCULATIONS'},
24 #);
25
26 sub flush_forced_xacts {
27     for my $k ( keys %xact_ed_cache ) {
28         $xact_ed_cache{$k}->rollback;
29         delete $xact_ed_cache{$k};
30     }
31 }
32
33 # -----------------------------------------------------------------------------
34 # Export some useful functions
35 # -----------------------------------------------------------------------------
36 use vars qw(@EXPORT_OK %EXPORT_TAGS);
37 use Exporter;
38 use base qw/Exporter/;
39 push @EXPORT_OK, ( 'new_editor', 'new_rstore_editor' );
40 %EXPORT_TAGS = ( funcs => [ qw/ new_editor new_rstore_editor / ] );
41
42 sub new_editor { return OpenILS::Utils::CStoreEditor->new(@_); }
43
44 sub new_rstore_editor { 
45         my $e = OpenILS::Utils::CStoreEditor->new(@_); 
46         $e->app('open-ils.reporter-store');
47         return $e;
48 }
49
50
51 # -----------------------------------------------------------------------------
52 # Log levels
53 # -----------------------------------------------------------------------------
54 use constant E => 'error';
55 use constant W => 'warn';
56 use constant I => 'info';
57 use constant D => 'debug';
58 use constant A => 'activity';
59
60
61
62 # -----------------------------------------------------------------------------
63 # Params include:
64 #       xact=><true> : creates a storage transaction
65 #       authtoken=>$token : the login session key
66 # -----------------------------------------------------------------------------
67 sub new {
68         my( $class, %params ) = @_;
69         $class = ref($class) || $class;
70         my $self = bless( \%params, $class );
71         $self->{checked_perms} = {};
72         return $self;
73 }
74
75
76 sub app {
77         my( $self, $app ) = @_;
78         $self->{app} = $app if $app;
79         $self->{app} = 'open-ils.cstore' unless $self->{app};
80         return $self->{app};
81 }
82
83
84 # -----------------------------------------------------------------------------
85 # Log the editor metadata along with the log string
86 # -----------------------------------------------------------------------------
87 sub log {
88         my( $self, $lev, $str ) = @_;
89         my $s = "editor[";
90     if ($always_xact) {
91         $s .= "!|";
92     } elsif ($self->{xact}) {
93         $s .= "1|";
94     } else {
95             $s .= "0|";
96     }
97         $s .= "0" unless $self->requestor;
98         $s .= $self->requestor->id if $self->requestor;
99         $s .= "]";
100         $logger->$lev("$s $str");
101 }
102
103 # -----------------------------------------------------------------------------
104 # Verifies the auth token and fetches the requestor object
105 # -----------------------------------------------------------------------------
106 sub checkauth {
107         my $self = shift;
108         $self->log(D, "checking auth token ".$self->authtoken);
109         my ($reqr, $evt) = $U->checkses($self->authtoken);
110         $self->event($evt) if $evt;
111         return $self->{requestor} = $reqr;
112 }
113
114
115 =head test
116 sub checkauth {
117         my $self = shift;
118         $cache = OpenSRF::Utils::Cache->new('global') unless $cache;
119         $self->log(D, "checking cached auth token ".$self->authtoken);
120         my $user = $cache->get_cache("oils_auth_".$self->authtoken);
121         return $self->{requestor} = $user->{userobj} if $user;
122         $self->event(OpenILS::Event->new('NO_SESSION'));
123         return undef;
124 }
125 =cut
126
127
128 # -----------------------------------------------------------------------------
129 # Returns the last generated event
130 # -----------------------------------------------------------------------------
131 sub event {
132         my( $self, $evt ) = @_;
133         $self->{event} = $evt if $evt;
134         return $self->{event};
135 }
136
137 # -----------------------------------------------------------------------------
138 # Destroys the transaction and disconnects where necessary,
139 # then returns the last event that occurred
140 # -----------------------------------------------------------------------------
141 sub die_event {
142         my $self = shift;
143         $self->rollback;
144         return $self->event;
145 }
146
147
148 # -----------------------------------------------------------------------------
149 # Clears the last caught event
150 # -----------------------------------------------------------------------------
151 sub clear_event {
152         my $self = shift;
153         $self->{event} = undef;
154 }
155
156 sub authtoken {
157         my( $self, $auth ) = @_;
158         $self->{authtoken} = $auth if $auth;
159         return $self->{authtoken};
160 }
161
162 sub timeout {
163     my($self, $to) = @_;
164     $self->{timeout} = $to if defined $to;
165     return defined($self->{timeout}) ? $self->{timeout} : 60;
166 }
167
168 # -----------------------------------------------------------------------------
169 # fetches the session, creating if necessary.  If 'xact' is true on this
170 # object, a db session is created
171 # -----------------------------------------------------------------------------
172 sub session {
173         my( $self, $session ) = @_;
174         $self->{session} = $session if $session;
175
176         if(!$self->{session}) {
177                 $self->{session} = OpenSRF::AppSession->create($self->app);
178
179                 if( ! $self->{session} ) {
180                         my $str = "Error creating cstore session with OpenSRF::AppSession->create()!";
181                         $self->log(E, $str);
182                         throw OpenSRF::EX::ERROR ($str);
183                 }
184
185                 $self->{session}->connect if $self->{xact} or $self->{connect} or $always_xact;
186                 $self->xact_start if $self->{xact} or $always_xact;
187         }
188
189     $xact_ed_cache{$self->{xact_id}} = $self if $always_xact;
190         return $self->{session};
191 }
192
193
194 # -----------------------------------------------------------------------------
195 # Starts a storage transaction
196 # -----------------------------------------------------------------------------
197 sub xact_start {
198         my $self = shift;
199         $self->log(D, "starting new db session");
200         my $stat = $self->request($self->app . '.transaction.begin') unless $self->{xact_id};
201         $self->log(E, "error starting database transaction") unless $stat;
202     $self->{xact_id} = $stat;
203         return $stat;
204 }
205
206 # -----------------------------------------------------------------------------
207 # Commits a storage transaction
208 # -----------------------------------------------------------------------------
209 sub xact_commit {
210         my $self = shift;
211         $self->log(D, "comitting db session");
212         my $stat = $self->request($self->app.'.transaction.commit') if $self->{xact_id};
213         $self->log(E, "error comitting database transaction") unless $stat;
214     delete $self->{xact_id};
215         return $stat;
216 }
217
218 # -----------------------------------------------------------------------------
219 # Rolls back a storage stransaction
220 # -----------------------------------------------------------------------------
221 sub xact_rollback {
222         my $self = shift;
223    return unless $self->{session};
224         $self->log(I, "rolling back db session");
225         my $stat = $self->request($self->app.".transaction.rollback") if $self->{xact_id};
226         $self->log(E, "error rolling back database transaction") unless $stat;
227     delete $self->{xact_id};
228         return $stat;
229 }
230
231
232
233 # -----------------------------------------------------------------------------
234 # Rolls back the transaction and disconnects
235 # -----------------------------------------------------------------------------
236 sub rollback {
237         my $self = shift;
238         $self->xact_rollback;
239    delete $self->{xact};
240         $self->disconnect;
241 }
242
243 sub disconnect {
244         my $self = shift;
245         $self->session->disconnect if $self->{session};
246    delete $self->{session};
247 }
248
249
250 # -----------------------------------------------------------------------------
251 # commits the db session and destroys the session
252 # -----------------------------------------------------------------------------
253 sub commit {
254         my $self = shift;
255         return unless $self->{xact_id};
256         $self->xact_commit;
257         $self->session->disconnect;
258         $self->{session} = undef;
259 }
260
261 # -----------------------------------------------------------------------------
262 # clears all object data. Does not commit the db transaction.
263 # -----------------------------------------------------------------------------
264 sub reset {
265         my $self = shift;
266         $self->disconnect;
267         $$self{$_} = undef for (keys %$self);
268 }
269
270
271 # -----------------------------------------------------------------------------
272 # commits and resets
273 # -----------------------------------------------------------------------------
274 sub finish {
275         my $self = shift;
276         $self->commit;
277         $self->reset;
278 }
279
280
281
282 # -----------------------------------------------------------------------------
283 # Does a simple storage request
284 # -----------------------------------------------------------------------------
285 sub request {
286         my( $self, $method, @params ) = @_;
287
288     my $val;
289         my $err;
290         my $argstr = __arg_to_string( (scalar(@params)) == 1 ? $params[0] : \@params);
291
292         $self->log(I, "request $method : $argstr");
293
294         if( ($self->{xact} or $always_xact) and 
295                         $self->session->state != OpenSRF::AppSession::CONNECTED() ) {
296                 #$logger->error("CStoreEditor lost it's connection!!");
297                 throw OpenSRF::EX::ERROR ("CStore connection timed out - transaction cannot continue");
298         }
299
300
301         try {
302
303         my $req = $self->session->request($method, @params);
304
305         if($self->substream) {
306             $self->log(D,"running in substream mode");
307             $val = [];
308             while( my $resp = $req->recv(timeout => $self->timeout) ) {
309                 push(@$val, $resp->content) if $resp->content;
310             }
311
312         } else {
313             my $resp = $req->recv(timeout => $self->timeout);
314             $val = $resp->content;
315         }
316
317         $req->finish;
318
319         } catch Error with {
320                 $err = shift;
321                 $self->log(E, "request error $method : $argstr : $err");
322         };
323
324         throw $err if $err;
325         return $val;
326 }
327
328 sub substream {
329    my( $self, $bool ) = @_;
330    $self->{substream} = $bool if defined $bool;
331    return $self->{substream};
332 }
333
334
335 # -----------------------------------------------------------------------------
336 # Sets / Returns the requstor object.  This is set when checkauth succeeds.
337 # -----------------------------------------------------------------------------
338 sub requestor {
339         my($self, $requestor) = @_;
340         $self->{requestor} = $requestor if $requestor;
341         return $self->{requestor};
342 }
343
344
345
346 # -----------------------------------------------------------------------------
347 # Holds the last data received from a storage call
348 # -----------------------------------------------------------------------------
349 sub data {
350         my( $self, $data ) = @_;
351         $self->{data} = $data if defined $data;
352         return $self->{data};
353 }
354
355
356 # -----------------------------------------------------------------------------
357 # True if this perm has already been checked at this org
358 # -----------------------------------------------------------------------------
359 sub perm_checked {
360         my( $self, $perm, $org ) = @_;
361         $self->{checked_perms}->{$org} = {}
362                 unless $self->{checked_perms}->{$org};
363         my $checked = $self->{checked_perms}->{$org}->{$perm};
364         if(!$checked) {
365                 $self->{checked_perms}->{$org}->{$perm} = 1;
366                 return 0;
367         }
368         return 1;
369 }
370
371
372
373 # -----------------------------------------------------------------------------
374 # Returns true if the requested perm is allowed.  If the perm check fails,
375 # $e->event is set and undef is returned
376 # The perm user is $e->requestor->id and perm org defaults to the requestor's
377 # ws_ou
378 # if perm is an array of perms, method will return true at the first allowed
379 # permission.  If none of the perms are allowed, the perm_failure event
380 # is created with the last perm to fail
381 # -----------------------------------------------------------------------------
382 my $PERM_QUERY = {
383     select => {
384         au => [ {
385             transform => 'permission.usr_has_perm',
386             alias => 'has_perm',
387             column => 'id',
388             params => []
389         } ]
390     },
391     from => 'au',
392     where => {},
393 };
394
395 my $OBJECT_PERM_QUERY = {
396     select => {
397         au => [ {
398             transform => 'permission.usr_has_object_perm',
399             alias => 'has_perm',
400             column => 'id',
401             params => []
402         } ]
403     },
404     from => 'au',
405     where => {},
406 };
407
408 sub allowed {
409         my( $self, $perm, $org, $object, $hint ) = @_;
410         my $uid = $self->requestor->id;
411         $org ||= $self->requestor->ws_ou;
412
413     my $perms = (ref($perm) eq 'ARRAY') ? $perm : [$perm];
414
415     for $perm (@$perms) {
416             $self->log(I, "checking perms user=$uid, org=$org, perm=$perm");
417     
418         if($object) {
419             my $params;
420             if(ref $object) {
421                 # determine the ID field and json_hint from the object
422                 my $id_field = $object->Identity;
423                 $params = [$perm, $object->json_hint, $object->$id_field];
424             } else {
425                 # we were passed an object-id and json_hint
426                 $params = [$perm, $hint, $object];
427             }
428             push(@$params, $org) if $org;
429             $OBJECT_PERM_QUERY->{select}->{au}->[0]->{params} = $params;
430             $OBJECT_PERM_QUERY->{where}->{id} = $uid;
431             return 1 if $U->is_true($self->json_query($OBJECT_PERM_QUERY)->[0]->{has_perm});
432
433         } else {
434             $PERM_QUERY->{select}->{au}->[0]->{params} = [$perm, $org];
435             $PERM_QUERY->{where}->{id} = $uid;
436             return 1 if $U->is_true($self->json_query($PERM_QUERY)->[0]->{has_perm});
437         }
438     }
439
440     # set the perm failure event if the permission check returned false
441         my $e = OpenILS::Event->new('PERM_FAILURE', ilsperm => $perm, ilspermloc => $org);
442         $self->event($e);
443         return undef;
444 }
445
446
447 # -----------------------------------------------------------------------------
448 # Returns the list of object IDs this user has object-specific permissions for
449 # -----------------------------------------------------------------------------
450 sub objects_allowed {
451     my($self, $perm, $obj_type) = @_;
452
453     my $perms = (ref($perm) eq 'ARRAY') ? $perm : [$perm];
454     my @ids;
455
456     for $perm (@$perms) {
457         my $query = {
458             select => {puopm => ['object_id']},
459             from => {
460                 puopm => {
461                     ppl => {field => 'id',fkey => 'perm'}
462                 }
463             },
464             where => {
465                 '+puopm' => {usr => $self->requestor->id, object_type => $obj_type},
466                 '+ppl' => {code => $perm}
467             }
468         };
469     
470         my $list = $self->json_query($query);
471         push(@ids, 0+$_->{object_id}) for @$list;
472     }
473
474    my %trim;
475    $trim{$_} = 1 for @ids;
476    return [ keys %trim ];
477 }
478
479
480 # -----------------------------------------------------------------------------
481 # checks the appropriate perm for the operation
482 # -----------------------------------------------------------------------------
483 sub _checkperm {
484         my( $self, $ptype, $action, $org ) = @_;
485         $org ||= $self->requestor->ws_ou;
486         my $perm = $PERMS{$ptype}{$action};
487         if( $perm ) {
488                 return undef if $self->perm_checked($perm, $org);
489                 return $self->event unless $self->allowed($perm, $org);
490         } else {
491                 $self->log(I, "no perm provided for $ptype.$action");
492         }
493         return undef;
494 }
495
496
497
498 # -----------------------------------------------------------------------------
499 # Logs update actions to the activity log
500 # -----------------------------------------------------------------------------
501 sub log_activity {
502         my( $self, $type, $action, $arg ) = @_;
503         my $str = "$type.$action";
504         $str .= _prop_string($arg);
505         $self->log(A, $str);
506 }
507
508
509
510 sub _prop_string {
511         my $obj = shift;
512         my @props = $obj->properties;
513         my $str = "";
514         for(@props) {
515                 my $prop = $obj->$_() || "";
516                 $prop = substr($prop, 0, 128) . "..." if length $prop > 131;
517                 $str .= " $_=$prop";
518         }
519         return $str;
520 }
521
522
523 sub __arg_to_string {
524         my $arg = shift;
525         return "" unless defined $arg;
526         if( UNIVERSAL::isa($arg, "Fieldmapper") ) {
527                 return (defined $arg->id) ? $arg->id : '<new object>';
528         }
529         return OpenSRF::Utils::JSON->perl2JSON($arg);
530         return "";
531 }
532
533
534 # -----------------------------------------------------------------------------
535 # This does the actual storage query.
536 #
537 # 'search' calls become search_where calls and $arg can be a search hash or
538 # an array-ref of storage search options.  
539 #
540 # 'retrieve' expects an id
541 # 'update' expects an object
542 # 'create' expects an object
543 # 'delete' expects an object
544 #
545 # All methods return true on success and undef on failure.  On failure, 
546 # $e->event is set to the generated event.  
547 # Note: this method assumes that updating a non-changed object and 
548 # thereby receiving a 0 from storage, is a successful update.  
549 #
550 # The method will therefore return true so the caller can just do 
551 # $e->update_blah($x) or return $e->event;
552 # The true value returned from storage for all methods will be stored in 
553 # $e->data, until the next method is called.
554 #
555 # not-found events are generated on retrieve and serach methods.
556 # action=search methods will return [] (==true) if no data is found.  If the
557 # caller is interested in the not found event, they can do:  
558 # return $e->event unless @$results; 
559 # -----------------------------------------------------------------------------
560 sub runmethod {
561         my( $self, $action, $type, $arg, $options ) = @_;
562
563    $options ||= {};
564
565         if( $action eq 'retrieve' ) {
566                 if(! defined($arg) ) {
567                         $self->log(W,"$action $type called with no ID...");
568                         $self->event(_mk_not_found($type, $arg));
569                         return undef;
570                 } elsif( ref($arg) =~ /Fieldmapper/ ) {
571                         $self->log(E,"$action $type called with an object.. attempting ID retrieval..");
572                         $arg = $arg->id;
573                 }
574         }
575
576         my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
577         my $method = $self->app.".direct.$type.$action";
578
579         if( $action eq 'search' ) {
580                 $method .= '.atomic';
581
582         } elsif( $action eq 'batch_retrieve' ) {
583                 $action = 'search';
584                 @arg = ( { id => $arg } );
585                 $method =~ s/batch_retrieve/search/o;
586                 $method .= '.atomic';
587
588         } elsif( $action eq 'retrieve_all' ) {
589                 $action = 'search';
590                 $method =~ s/retrieve_all/search/o;
591                 my $tt = $type;
592                 $tt =~ s/\./::/og;
593                 my $fmobj = "Fieldmapper::$tt";
594                 @arg = ( { $fmobj->Identity => { '!=' => undef } } );
595                 $method .= '.atomic';
596         }
597
598         $method =~ s/search/id_list/o if $options->{idlist};
599
600     $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
601     $self->timeout($$options{timeout});
602
603         # remove any stale events
604         $self->clear_event;
605
606         if( $action eq 'update' or $action eq 'delete' or $action eq 'create' ) {
607                 if(!($self->{xact} or $always_xact)) {
608                         $logger->error("Attempt to update DB while not in a transaction : $method");
609                         throw OpenSRF::EX::ERROR ("Attempt to update DB while not in a transaction : $method");
610                 }
611                 $self->log_activity($type, $action, $arg);
612         }
613
614         if($$options{checkperm}) {
615                 my $a = ($action eq 'search') ? 'retrieve' : $action;
616                 my $e = $self->_checkperm($type, $a, $$options{permorg});
617                 if($e) {
618                         $self->event($e);
619                         return undef;
620                 }
621         }
622
623         my $obj; 
624         my $err;
625
626         try {
627                 $obj = $self->request($method, @arg);
628         } catch Error with { $err = shift; };
629         
630
631         if(!defined $obj) {
632                 $self->log(I, "request returned no data : $method");
633
634                 if( $action eq 'retrieve' ) {
635                         $self->event(_mk_not_found($type, $arg));
636
637                 } elsif( $action eq 'update' or 
638                                 $action eq 'delete' or $action eq 'create' ) {
639                         my $evt = OpenILS::Event->new(
640                                 'DATABASE_UPDATE_FAILED', payload => $arg, debug => "$err" );
641                         $self->event($evt);
642                 }
643
644                 if( $err ) {
645                         $self->event( 
646                                 OpenILS::Event->new( 'DATABASE_QUERY_FAILED', 
647                                         payload => $arg, debug => "$err" ));
648                         return undef;
649                 }
650
651                 return undef;
652         }
653
654         if( $action eq 'create' and $obj == 0 ) {
655                 my $evt = OpenILS::Event->new(
656                         'DATABASE_UPDATE_FAILED', payload => $arg, debug => "$err" );
657                 $self->event($evt);
658                 return undef;
659         }
660
661         # If we havn't dealt with the error in a nice way, go ahead and throw it
662         if( $err ) {
663                 $self->event( 
664                         OpenILS::Event->new( 'DATABASE_QUERY_FAILED', 
665                                 payload => $arg, debug => "$err" ));
666                 return undef;
667         }
668
669         if( $action eq 'search' ) {
670                 $self->log(I, "$type.$action : returned ".scalar(@$obj). " result(s)");
671                 $self->event(_mk_not_found($type, $arg)) unless @$obj;
672         }
673
674         if( $action eq 'create' ) {
675                 $self->log(I, "created a new $type object with ID " . $obj->id);
676                 $arg->id($obj->id);
677         }
678
679         $self->data($obj); # cache the data for convenience
680
681         return ($obj) ? $obj : 1;
682 }
683
684
685 sub _mk_not_found {
686         my( $type, $arg ) = @_;
687         (my $t = $type) =~ s/\./_/og;
688         $t = uc($t);
689         return OpenILS::Event->new("${t}_NOT_FOUND", payload => $arg);
690 }
691
692
693
694 # utility method for loading
695 sub __fm2meth { 
696         my $str = shift;
697         my $sep = shift;
698         $str =~ s/Fieldmapper:://o;
699         $str =~ s/::/$sep/g;
700         return $str;
701 }
702
703
704 # -------------------------------------------------------------
705 # Load up the methods from the FM classes
706 # -------------------------------------------------------------
707 my $map = $Fieldmapper::fieldmap;
708 for my $object (keys %$map) {
709         my $obj = __fm2meth($object,'_');
710         my $type = __fm2meth($object, '.');
711
712         my $update = "update_$obj";
713         my $updatef = 
714                 "sub $update {return shift()->runmethod('update', '$type', \@_);}";
715         eval $updatef;
716
717         my $retrieve = "retrieve_$obj";
718         my $retrievef = 
719                 "sub $retrieve {return shift()->runmethod('retrieve', '$type', \@_);}";
720         eval $retrievef;
721
722         my $search = "search_$obj";
723         my $searchf = 
724                 "sub $search {return shift()->runmethod('search', '$type', \@_);}";
725         eval $searchf;
726
727         my $create = "create_$obj";
728         my $createf = 
729                 "sub $create {return shift()->runmethod('create', '$type', \@_);}";
730         eval $createf;
731
732         my $delete = "delete_$obj";
733         my $deletef = 
734                 "sub $delete {return shift()->runmethod('delete', '$type', \@_);}";
735         eval $deletef;
736
737         my $bretrieve = "batch_retrieve_$obj";
738         my $bretrievef = 
739                 "sub $bretrieve {return shift()->runmethod('batch_retrieve', '$type', \@_);}";
740         eval $bretrievef;
741
742         my $retrieveall = "retrieve_all_$obj";
743         my $retrieveallf = 
744                 "sub $retrieveall {return shift()->runmethod('retrieve_all', '$type', \@_);}";
745         eval $retrieveallf;
746 }
747
748 sub json_query {
749     my( $self, $arg, $options ) = @_;
750     $options ||= {};
751         my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg);
752     my $method = $self->app.'.json_query.atomic';
753     $method =~ s/\.atomic$//o if $self->substream($$options{substream} || 0);
754         $self->clear_event;
755     my $obj;
756     my $err;
757     
758     try {
759         $obj = $self->request($method, @arg);
760     } catch Error with { $err = shift; };
761
762     if( $err ) {
763         $self->event(
764             OpenILS::Event->new( 'DATABASE_QUERY_FAILED',
765             payload => $arg, debug => "$err" ));
766         return undef;
767     }
768
769     $self->log(I, "json_query : returned ".scalar(@$obj). " result(s)");
770     return $obj;
771 }
772
773
774
775 1;
776
777