[Koha-patches] [PATCH] Bug 5185 - allow the last seen time to be updated by batch modification

Chris Cormack chrisc at catalyst.net.nz
Tue Aug 31 01:48:21 CEST 2010


From: Robin Sheat <robin at catalyst.net.nz>

This adds a syspref "UpdateLastSeenBatch" that will make batch
modifications update the last seen time of their item.

Signed-off-by: Chris Cormack <chrisc at catalyst.net.nz>
---
 C4/Items.pm                                        |    8 +++++++-
 installer/data/mysql/en/mandatory/sysprefs.sql     |    1 +
 installer/data/mysql/updatedatabase.pl             |    6 ++++++
 .../en/modules/admin/preferences/cataloguing.pref  |    8 +++++++-
 tools/batchMod.pl                                  |    3 ++-
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index 794bff7..1930a27 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -373,7 +373,8 @@ sub AddItemBatchFromMarc {
 
 =head2 ModItemFromMarc
 
-  ModItemFromMarc($item_marc, $biblionumber, $itemnumber);
+  ModItemFromMarc($item_marc, $biblionumber, $itemnumber, 
+        $update_last_seen);
 
 This function updates an item record based on a supplied
 C<MARC::Record> object containing an embedded item field.
@@ -428,6 +429,7 @@ sub ModItemFromMarc {
     my $item_marc = shift;
     my $biblionumber = shift;
     my $itemnumber = shift;
+    my $update_last_seen = shift;
 
     my $dbh = C4::Context->dbh;
     my $frameworkcode = GetFrameworkCode( $biblionumber );
@@ -439,6 +441,10 @@ sub ModItemFromMarc {
     foreach my $item_field (keys %default_values_for_mod_from_marc) {
         $item->{$item_field} = $default_values_for_mod_from_marc{$item_field} unless exists $item->{$item_field};
     }
+    if ($update_last_seen) {
+        my $today = C4::Dates->new();
+        $item->{'datelastseen'} = $today->output("iso");
+    }
     my $unlinked_item_subfields = _get_unlinked_item_subfields($localitemmarc, $frameworkcode);
    
     return ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); 
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 8bfed37..19dcec6 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -286,3 +286,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI:Authorized_IPs','','.','Restricts usage of ILS-DI to some IPs','Free');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OverduesBlockCirc','noblock','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','noblock|confirmation|block','Choice');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('DisplayMultiPlaceHold','1','Display the ability to place multiple holds or not','','YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UpdateLastSeenBatch','0','Whether to update datelastseen when doing batch modifications','','YesNo');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index e289a21..23ff3ec 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -3708,6 +3708,12 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.01.00.147";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('UpdateLastSeenBatch','0','Whether to update datelastseen when doing batch modifications','','YesNo')");
+    print "Upgrade to $DBversion done (Add UpdateLastSeenBatch system preference)\n";
+    SetVersion($DBversion);
+}
 
 =item DropAllForeignKeys($table)
 
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
index 4e06abc..b8adaf4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
@@ -130,4 +130,10 @@ Cataloging:
                   simplified: a summary
                   full: a full list
             - of the serial issues.
-
+    Batch Operations:
+        -
+            - pref: UpdateLastSeenBatch
+              choices:
+                  yes: Update
+                  no: "Don't update"
+            - the <code>datalastseen</code> field on items when performing batch modifications.
diff --git a/tools/batchMod.pl b/tools/batchMod.pl
index f5138d1..ea21de9 100755
--- a/tools/batchMod.pl
+++ b/tools/batchMod.pl
@@ -132,6 +132,7 @@ if ($op eq "action") {
 
 	# For each item
 	my $i = 1; 
+        my $update_last_seen = C4::Context->preference('UpdateLastSeenBatch');
 	foreach my $itemnumber(@itemnumbers){
 
 		$job->progress($i) if $runinbackground;
@@ -151,7 +152,7 @@ if ($op eq "action") {
 			my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
 			my $localmarcitem=Item2Marc($itemdata);
 			UpdateMarcWith($marcitem,$localmarcitem);
-			eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
+			eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber,$update_last_seen)};
 		    }
 		}
 		$i++;
-- 
1.7.0.4



More information about the Koha-patches mailing list