From 58fcbe6f3732f3508a935f462ee250a34dfbe7bc Mon Sep 17 00:00:00 2001 From: Adrien Saurat Date: Mon, 9 Jan 2012 10:56:39 +0100 Subject: [PATCH] Bug 7241: corrects log action for CIRC and CATALOGUING Content-Type: text/plain; charset="UTF-8" For CIRCULATION: ISSUE and RETURN actions now store itemnumber instead of biblionumber. For CATALOGUING: we now know if the code stored in the object field is an item or a biblio (thanks to a new field called objectinfo). Signed-off-by: Jared Camins-Esakov This patch does not change the user interface for the cataloguing log, but fixes the problem with the circ log. --- C4/Biblio.pm | 6 +++--- C4/Circulation.pm | 4 ++-- C4/Items.pm | 8 ++++---- C4/Log.pm | 6 +++--- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++++++++ 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 98e4f5b..c81c0e4 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -274,7 +274,7 @@ sub AddBiblio { # now add the record ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save; - logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog"); + logaction( "CATALOGUING", "ADD", $biblionumber, "", "BIBLIO" ) if C4::Context->preference("CataloguingLog"); return ( $biblionumber, $biblioitemnumber ); } @@ -304,7 +304,7 @@ sub ModBiblio { if ( C4::Context->preference("CataloguingLog") ) { my $newrecord = GetMarcBiblio($biblionumber); - logaction( "CATALOGUING", "MODIFY", $biblionumber, "BEFORE=>" . $newrecord->as_formatted ); + logaction( "CATALOGUING", "MODIFY", $biblionumber, "BEFORE=>" . $newrecord->as_formatted, "BIBLIO" ); } # Cleaning up invalid fields must be done early or SetUTF8Flag is liable to @@ -452,7 +452,7 @@ sub DelBiblio { # from being generated by _koha_delete_biblioitems $error = _koha_delete_biblio( $dbh, $biblionumber ); - logaction( "CATALOGUING", "DELETE", $biblionumber, "" ) if C4::Context->preference("CataloguingLog"); + logaction( "CATALOGUING", "DELETE", $biblionumber, "", "BIBLIO" ) if C4::Context->preference("CataloguingLog"); return; } diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e68db64..03d9620 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1078,7 +1078,7 @@ sub AddIssue { } } - logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $biblio->{'biblionumber'}) + logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $item->{'itemnumber'}) if C4::Context->preference("IssueLog"); } return ($datedue); # not necessarily the same as when it came in! @@ -1647,7 +1647,7 @@ sub AddReturn { }); } - logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'biblionumber'}) + logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'}) if C4::Context->preference("ReturnLog"); # FIXME: make this comment intelligible. diff --git a/C4/Items.pm b/C4/Items.pm index 04cb417..4b4d219 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -270,7 +270,7 @@ sub AddItem { ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef ); - logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); + logaction("CATALOGUING", "ADD", $itemnumber, Dumper($item), "ITEM") if C4::Context->preference("CataloguingLog"); return ($item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber); } @@ -362,7 +362,7 @@ sub AddItemBatchFromMarc { push @itemnumbers, $itemnumber; # FIXME not checking error $item->{'itemnumber'} = $itemnumber; - logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); + logaction("CATALOGUING", "ADD", $itemnumber, Dumper($item), "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)); @@ -520,7 +520,7 @@ sub ModItem { # item status is possible ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef ); - logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog"); + logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item), "ITEM") if C4::Context->preference("CataloguingLog"); } =head2 ModItemTransfer @@ -589,7 +589,7 @@ sub DelItem { # This last update statement makes that the timestamp column in deleteditems is updated too. If you remove these lines, please add a line to update the timestamp separately. See Bugzilla report 7146 and Biblio.pm (DelBiblio). #search item field code - logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); + logaction("CATALOGUING", "DELETE", $itemnumber, "", "ITEM") if C4::Context->preference("CataloguingLog"); } =head2 CheckItemPreSave diff --git a/C4/Log.pm b/C4/Log.pm index 6b8ff17..7041482 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -66,7 +66,7 @@ number is set to 0, which is the same as the superlibrarian's number. #' sub logaction { - my ($modulename, $actionname, $objectnumber, $infos)=@_; + my ($modulename, $actionname, $objectnumber, $infos, $objectinfo)=@_; # Get ID of logged in user. if called from a batch job, # no user session exists and C4::Context->userenv() returns @@ -75,8 +75,8 @@ sub logaction { 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); + my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info,objectinfo) values (now(),?,?,?,?,?,?)"); + $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos,$objectinfo); $sth->finish; } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 37113c2..d86f46f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2392,6 +2392,7 @@ CREATE TABLE `action_logs` ( `module` text, `action` text, `object` int(11) default NULL, + `objectinfo` text, `info` text, PRIMARY KEY (`action_id`), KEY (`timestamp`,`user`) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 099dfb9..0d8d90f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4663,6 +4663,14 @@ ENDOFRENEWAL print "Upgrade to $DBversion done (Added a system preference to allow renewal of Patron account either from todays date or from existing expiry date in the patrons account.)\n"; SetVersion($DBversion); } + +$DBversion = "XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `action_logs` ADD `objectinfo` TEXT NULL AFTER `object`;"); + print "Upgrade to $DBversion done (Add objectinfo column to action_logs)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) -- 1.7.2.5