for my $name (keys %$settings) {
my $val = $$settings{$name};
- my $set = $e->search_actor_user_setting({usr => $user_id, name => $name})->[0];
+ my $set = $e->search_actor_user_setting({usr => $user_id, name => $name});
+ if ($set && ref($set) eq 'ARRAY') {
+ $set = $set->[0];
+ } else {
+ $set = undef;
+ }
if(defined $val) {
$val = OpenSRF::Utils::JSON->perl2JSON($val);
$name,
{flesh => 1, flesh_fields => {'coust' => ['update_perm']}}
]) or return $e->die_event;
- my $set = $e->search_actor_org_unit_setting({org_unit => $org_id, name => $name})->[0];
+ my $set = $e->search_actor_org_unit_setting({org_unit => $org_id, name => $name});
+ if ($set && ref($set) eq 'ARRAY') {
+ $set = $set->[0];
+ } else {
+ $set = undef;
+ }
# If there is no relevant permission, the default assumption will
# be, "no, the caller cannot change that value."
sub get_setting {
my($e, $user_id, $setting) = @_;
- my $val = $e->search_actor_user_setting({usr => $user_id, name => $setting})->[0];
+ my $val = $e->search_actor_user_setting({usr => $user_id, name => $setting});
+ if ($val && ref($val) eq 'ARRAY') {
+ $val = $val->[0];
+ } else {
+ $val = undef;
+ }
return undef unless $val; # XXX this should really return undef, but needs testing
return OpenSRF::Utils::JSON->JSON2perl($val->value);
}
my $e = new_editor(authtoken => $auth);
return $e->event unless $e->checkauth;
- my $card = $e->search_actor_card({barcode => $barcode})->[0]
- or return $e->event;
+ my $card = $e->search_actor_card({barcode => $barcode});
+ if (ref($card) eq 'ARRAY' && $card->[0]) {
+ $card = $card->[0];
+ } else {
+ return $e->event;
+ }
my $user = flesh_user($card->usr, $e, $flesh_home_ou);
return $e->event unless $e->allowed(
if( $api =~ /username/o ) {
# make sure no one else has this username
- my $exist = $e->search_actor_user({usrname=>$new_val},{idlist=>1});
- if (@$exist) {
+ my $exist = $e->search_actor_user({usrname=>$new_val},{idlist=>1});
+ if (ref($exist) eq 'ARRAY' && @$exist) {
$e->rollback;
return new OpenILS::Event('USERNAME_EXISTS');
}
$e->allowed('VIEW_USER_FINES_SUMMARY', $user->home_ou);
}
- return $e->search_money_open_user_summary({usr => $user_id})->[0];
+ my $mous = $e->search_money_open_user_summary({usr => $user_id});
+ if (ref($mous) eq 'ARRAY') {
+ $mous = $mous->[0];
+ } else {
+ $mous = undef;
+ }
+ return $mous;
}
my( @lost, @cr, @lo );
- for my $c (@$open) {
- push( @lost, $c->id ) if $c->stop_fines eq 'LOST';
- push( @cr, $c->id ) if $c->stop_fines eq 'CLAIMSRETURNED';
- push( @lo, $c->id ) if $c->stop_fines eq 'LONGOVERDUE';
- }
+ if (ref($open) eq 'ARRAY') {
+ for my $c (@$open) {
+ push( @lost, $c->id ) if $c->stop_fines eq 'LOST';
+ push( @cr, $c->id ) if $c->stop_fines eq 'CLAIMSRETURNED';
+ push( @lo, $c->id ) if $c->stop_fines eq 'LONGOVERDUE';
+ }
+ }
return {
lost => \@lost,
]
);
+ return [] if (ref($mbts) ne 'ARRAY');
return [map {$_->id} @$mbts] if $api =~ /\.ids/;
return $mbts unless $api =~ /fleshed/;
api_name => "open-ils.actor.groups.tree.retrieve",
notes => "Returns a list of user groups"
);
-
+
sub retrieve_groups_tree {
my( $self, $client ) = @_;
- return new_editor()->search_permission_grp_tree(
+ my $tree = new_editor()->search_permission_grp_tree(
[
{ parent => undef},
- {
+ {
flesh => -1,
- flesh_fields => { pgt => ["children"] },
+ flesh_fields => { pgt => ["children"] },
order_by => { pgt => 'name'}
}
]
- )->[0];
+ );
+ if (ref($tree) eq 'ARRAY') {
+ return $tree->[0];
+ } else {
+ return undef;
+ }
}
my $e = new_editor(authtoken=>$authtoken, xact=>1);
return $e->die_event unless $e->checkauth;
return $e->die_event unless $e->allowed('REGISTER_WORKSTATION', $owner);
- my $existing = $e->search_actor_workstation({name => $name})->[0];
+ my $existing = $e->search_actor_workstation({name => $name});
+ if (ref($existing) eq 'ARRAY') {
+ $existing = $existing->[0];
+ }
if( $existing ) {
select => { aou => ["id","shortname", "name"]},
}
]
- )->[0];
+ );
+ if (ref($tree) eq 'ARRAY') {
+ $tree = trim_tree($tree->[0]);
+ } else {
+ $tree = undef;
+ }
- return trim_tree($tree);
+ return $tree;
}
{org_unit => $U->get_org_ancestors($context_org)},
{order_by => {pgpt => 'id'}}
]);
- $conn->respond($_) for @$list;
+ if (ref($list) eq 'ARRAY') {
+ $conn->respond($_) for @$list;
+ }
return undef;
}
my $vals = $e->search_actor_usr_org_unit_opt_in(
{org_unit=>$opt_orgs, usr=>$user_id},{idlist=>1});
- return 1 if @$vals;
+ return 1 if (ref($vals) eq 'ARRAY' && @$vals);
return 0;
}
my $e = new_editor(authtoken => $auth, xact=>1);
return $e->die_event unless $e->checkauth;
-
+
# if a specific org unit wasn't passed in, get one based on the defaults;
if(!$org_id){
my $wsou = $e->requestor->ws_ou;
my $opt_depth = $U->ou_ancestor_setting_value($wsou,'org.patron_opt_default');
# get the org unit at that depth
my $org = $e->json_query({
- from => [ 'actor.org_unit_ancestor_at_depth', $wsou, $opt_depth ]})->[0];
-
- $org_id = $org->{id};
+ from => [ 'actor.org_unit_ancestor_at_depth', $wsou, $opt_depth ]});
+ if ($ref($org) eq 'ARRAY') {
+ $org = $org->[0];
+ $org_id = $org->{id};
+ }
+ return $e->event unless($org_id);
}
my $user = $e->retrieve_actor_user($user_id) or return $e->die_event;
if($barcode) {
my $card = $e->search_actor_card([
{barcode => $barcode},
- {flesh => 1, flesh_fields => {ac => ['usr']}}])->[0] or return 0;
+ {flesh => 1, flesh_fields => {ac => ['usr']}}]);
+ if (ref($card) eq 'ARRAY' && @$card) {
+ $card = $card->[0];
+ } else {
+ return 0;
+ }
$user_by_barcode = $card->usr;
$user = $user_by_barcode;
}
if($barcode) {
my $card = $e->search_actor_card([
{barcode => $barcode},
- {flesh => 1, flesh_fields => {ac => ['usr']}}])->[0];
+ {flesh => 1, flesh_fields => {ac => ['usr']}}]);
+ $card = $card->[0] if (ref($card) eq 'ARRAY');
if ($id_as_barcode =~ /^t/i) {
if (!$card) {
$user = $e->retrieve_actor_user($barcode);
}
if ($username) {
- $user_by_username = $e->search_actor_user({usrname => $username})->[0] or return OpenILS::Event->new( 'ACTOR_USR_NOT_FOUND' );
+ $user_by_username = $e->search_actor_user({usrname => $username});
+ if (ref($user_by_username) eq 'ARRAY' && @$user_by_username) {
+ $user_by_username = $user_by_username->[0];
+ } else {
+ return OpenILS::Event->new( 'ACTOR_USR_NOT_FOUND' );
+ }
$user = $user_by_username;
}
# disallow the merge if any subordinate accounts are in collections
my $colls = $e->search_money_collections_tracker({usr => $user_ids}, {idlist => 1});
- return OpenILS::Event->new('MERGED_USER_IN_COLLECTIONS', payload => $user_ids) if @$colls;
+ return OpenILS::Event->new('MERGED_USER_IN_COLLECTIONS', payload => $user_ids) if (ref($colls) eq 'ARRAY' && @$colls);
my $master_user = $e->retrieve_actor_user($master_id) or return $e->die_event;
my $del_addrs = ($U->ou_ancestor_setting_value(
# Get the user, if any, depending on the input value
if ($user_id_type eq 'username') {
- $user = $e->search_actor_user({usrname => $user_id})->[0];
+ $user = $e->search_actor_user({usrname => $user_id});
+ $user = (ref($user) eq 'ARRAY') ? $user->[0] : undef;
if (!$user) {
$e->die_event;
return OpenILS::Event->new( 'ACTOR_USER_NOT_FOUND' );
} elsif ($user_id_type eq 'barcode') {
my $card = $e->search_actor_card([
{barcode => $user_id},
- {flesh => 1, flesh_fields => {ac => ['usr']}}])->[0];
- if (!$card) {
+ {flesh => 1, flesh_fields => {ac => ['usr']}}]);
+ $card = (ref($card) eq 'ARRAY') ? $card->[0] : undef;
+ if (!$card) {
$e->die_event;
return OpenILS::Event->new('ACTOR_USER_NOT_FOUND');
}
$user = $card->usr;
}
-
+
# If the user doesn't have an email address, we can't help them
if (!$user->email) {
$e->die_event;
return OpenILS::Event->new('PATRON_NO_EMAIL_ADDRESS');
}
-
+
my $email_must_match = $U->ou_ancestor_setting_value($user->home_ou, 'circ.password_reset_request_requires_matching_email');
if ($email_must_match) {
if ($user->email ne $email) {
has_been_reset => 0
});
- if (!$aupr->[0]) {
+ if (ref($aupr) ne 'ARRAY' || !$aupr->[0]) {
$e->die_event;
return OpenILS::Event->new('PATRON_NOT_AN_ACTIVE_PASSWORD_RESET_REQUEST');
}
}
});
- if(@$types) {
+ if(ref($types) eq 'ARRAY' && @$types) {
$conn->respond($_) for
@{$e->search_config_usr_setting_type({name => [map {$_->{name}} @$types]})};
}
substream => 1
});
- return undef unless @$data;
+ return undef unless (ref($data) eq 'ARRAY' && @$data);
if ($for_print) {
}
);
if($context =~ /actor/) {
- my $filter_result = ();
+ my $filter_result = [];
my $patron;
+ return $filter_result if (ref($db_result) ne 'ARRAY');
foreach my $result (@$db_result) {
if($result->{type} eq 'actor') {
if($e->requestor->id != $result->{id}) {