# now add the record
$biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
- &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$biblionumber,"biblio")
- if C4::Context->preference("CataloguingLog");
+ logaction("CATALOGUING", "ADD", $biblionumber, "biblio") if C4::Context->preference("CataloguingLog");
return ( $biblionumber, $biblioitemnumber );
}
my ( $record, $biblionumber, $frameworkcode ) = @_;
if (C4::Context->preference("CataloguingLog")) {
my $newrecord = GetMarcBiblio($biblionumber);
- &logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$biblionumber,"BEFORE=>".$newrecord->as_formatted);
+ logaction("CATALOGUING", "MODIFY", $biblionumber, "BEFORE=>".$newrecord->as_formatted);
}
my $dbh = C4::Context->dbh;
# from being generated by _koha_delete_biblioitems
$error = _koha_delete_biblio( $dbh, $biblionumber );
- &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"")
- if C4::Context->preference("CataloguingLog");
+ logaction("CATALOGUING", "DELETE", $biblionumber, "") if C4::Context->preference("CataloguingLog");
+
return;
}
);
}
- &logaction(C4::Context->userenv->{'number'},"CIRCULATION","ISSUE",$borrower->{'borrowernumber'},$biblio->{'biblionumber'})
+ logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $biblio->{'biblionumber'})
if C4::Context->preference("IssueLog");
return ($datedue);
}
$borrower->{'borrowernumber'}
);
- &logaction(C4::Context->userenv->{'number'},"CIRCULATION","RETURN",$iteminformation->{borrowernumber},$iteminformation->{'biblionumber'})
+ logaction("CIRCULATION", "RETURN", $iteminformation->{borrowernumber}, $iteminformation->{'biblionumber'})
if C4::Context->preference("ReturnLog");
#adding message if holdingbranch is non equal a userenv branch to return the document to homebranch
my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
_add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
- logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$itemnumber,"item")
- if C4::Context->preference("CataloguingLog");
+ logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
return ($item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber);
}
push @itemnumbers, $itemnumber; # FIXME not checking error
$item->{'itemnumber'} = $itemnumber;
- &logaction(C4::Context->userenv->{'number'},"CATALOGUING","ADD",$itemnumber,"item")
- if C4::Context->preference("CataloguingLog");
+ logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
$item_field->replace_with($new_item_marc->field($itemtag));
or die "FAILED _marc_from_item_hash($whole_item, $frameworkcode)";
_replace_item_field_in_biblio($new_item_marc, $biblionumber, $itemnumber, $frameworkcode);
- (C4::Context->userenv eq '0') and die "userenv is '0', not hashref"; # logaction line would crash anyway
($new_item_marc eq '0') and die "$new_item_marc is '0', not hashref"; # logaction line would crash anyway
- logaction(C4::Context->userenv->{'number'},"CATALOGUING","MODIFY",$itemnumber,$new_item_marc->as_formatted)
- if C4::Context->preference("CataloguingLog");
+ logaction("CATALOGUING", "MODIFY", $itemnumber, $new_item_marc->as_formatted) if C4::Context->preference("CataloguingLog");
}
=head2 ModItemTransfer
}
}
&ModBiblioMarc( $record, $biblionumber, $frameworkcode );
- &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$itemnumber,"item")
- if C4::Context->preference("CataloguingLog");
+ logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
}
=head2 CheckItemPreSave
}
if ( C4::Context->preference("LetterLog") ) {
logaction(
- $userenv->{number},
"ACQUISITION",
"Send Acquisition claim letter",
"",
Message => "" . $innerletter->{content},
);
sendmail(%mail);
- &logaction(
- C4::Context->userenv->{'number'},
+ logaction(
"ACQUISITION",
"CLAIM ISSUE",
undef,
=item logaction
- &logaction($usernumber, $modulename, $actionname, $objectnumber, $infos);
+ &logaction($modulename, $actionname, $objectnumber, $infos);
-Adds a record into action_logs table to report the different changes upon the database
+Adds a record into action_logs table to report the different changes upon the database.
+Each log entry includes the number of the user currently logged in. For batch
+jobs, which operate without authenticating a user and setting up a session, the user
+number is set to 0, which is the same as the superlibrarian's number.
=cut
#'
sub logaction {
- my ($usernumber,$modulename, $actionname, $objectnumber, $infos)=@_;
- $usernumber='' unless $usernumber;
+ my ($modulename, $actionname, $objectnumber, $infos)=@_;
+
+ # Get ID of logged in user. if called from a batch job,
+ # no user session exists and C4::Context->userenv() returns
+ # the scalar '0'.
+ my $userenv = C4::Context->userenv();
+ my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0;
+
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info) values (now(),?,?,?,?,?)");
$sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos);
# is adult check guarantees;
UpdateGuarantees(%data);
}
- &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"$query (executed w/ arg: $data{'borrowernumber'})")
+ logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "$query (executed w/ arg: $data{'borrowernumber'})")
if C4::Context->preference("BorrowersLog");
}
$data{'borrowernumber'} = $dbh->{'mysql_insertid'}; # unneeded w/ autoincrement ?
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best.
- &logaction(C4::Context->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
- if C4::Context->preference("BorrowersLog");
+ logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
# check for enrollment fee & add it if needed
$sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
return 1;
}
- &logaction(C4::Context->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
- if C4::Context->preference("BorrowersLog");
+ logaction("MEMBERS", "CHANGE PASS", $member, "") if C4::Context->preference("BorrowersLog");
}
$sth = $dbh->prepare($query);
$sth->execute($borrowernumber);
$sth->finish;
- &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
- if C4::Context->preference("BorrowersLog");
+ logaction("MEMBERS", "DELETE", $borrowernumber, "") if C4::Context->preference("BorrowersLog");
return $sth->rows;
}
}
# logging action
&logaction(
- C4::Context->userenv->{'number'},
"FINES",
$type,
$borrowernumber,
my $rows=$sth->rows;
$sth->finish;
- &logaction(C4::Context->userenv->{'number'},"SERIAL","MODIFY",$subscriptionid,"")
- if C4::Context->preference("SubscriptionLog");
+ logaction("SERIAL", "MODIFY", $subscriptionid, "") if C4::Context->preference("SubscriptionLog");
return $rows;
}
format_date_in_iso($startdate)
);
- &logaction(C4::Context->userenv->{'number'},"SERIAL","ADD",$subscriptionid,"")
- if C4::Context->preference("SubscriptionLog");
+ logaction("SERIAL", "ADD", $subscriptionid, "") if C4::Context->preference("SubscriptionLog");
#set serial flag on biblio if not already set.
my ($null, ($bib)) = GetBiblio($biblionumber);
$sth->execute( format_date_in_iso($startdate),
$numberlength, $weeklength, $monthlength, $subscriptionid );
- &logaction(C4::Context->userenv->{'number'},"SERIAL","RENEW",$subscriptionid,"")
- if C4::Context->preference("SubscriptionLog");
+ logaction("SERIAL", "RENEW", $subscriptionid, "") if C4::Context->preference("SubscriptionLog");
}
=head2 NewIssue
"DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid");
$dbh->do("DELETE FROM serial WHERE subscriptionid=$subscriptionid");
- &logaction(C4::Context->userenv->{'number'},"SERIAL","DELETE",$subscriptionid,"")
- if C4::Context->preference("SubscriptionLog");
+ logaction("SERIAL", "DELETE", $subscriptionid, "") if C4::Context->preference("SubscriptionLog");
}
=head2 DelIssue