From 306305847e6570e9f1d433099f4b52be00cb7089 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 3 Oct 2018 22:53:27 +0000 Subject: [PATCH] Bug 21173: Fixed rebase removal of filters and changed items.dateaccessioned to datetime datatype This means we can make the auto item modification tool work for hours since item was created Updated test plan: 1. Go to Tools->Automatic item modifications by age and create a new rule by selecting the 'Edit rules' button 2. Notice you can only set the age in the unit of days not hours. Also although not visible in the interface the rule will calculate the age of the item based on when it was created (i.e. added to Koha). 3. Apply patch and run ./updatedatabase.pl in the koha-shell 4. Now revisit Tools->Automatic item modifications by age. Notice the table of existing rules now contains a new column 'Age starting point' this is the date from which the item age is calculated. This enhancement offers you two options as the age starting point: Created (displayed in this table as 'itemcreated') or Last altered (displayed in this table as 'itemaltered'). 5. Click 'Edit rules' to create a new rule. Notice in the form for creating the new rule you can set the unit to either 'Hours' or 'Days'. 6. In the new rule set the following values: Age: 1, Unit: Hours, condition items.location = 'CART', items.location = '' 7. Now save the rule and confirm the correct values are dispayed in the rules table which is loaded 8. Click 'Edit rules' button again. 9. Modify the rule you just created changing Age to 2 and create another new rule with the following values: Age='1', Unit='Hour', 'Age starting point'='Created', Condition 'items.homebranch'='', substituions 'items.homebranch'='' 10. Now click 'Save' and confirm the data displayed for both rules is correct. 11. Create two new items and set their location field to 'CART'. Then in the database set their dateaccessioned value to 2 hours before the current time 12. Exit out of the database terminal and manually run the automatic_item_modification_by_age.pl cronjob from the koha-shell with this command: ./automatic_item_modification_by_age.pl --confirm 13. Now return to the database and notice the two items you set have a location of 'CART' now have a blank location field because the manually run cronjob altered them as they meet the conditions of the rule. 14. Repeat step 11 but this time change the rule in the Auto item modification tool interface to 'Age starting point='Altered'' so we can test the auto item mod tool on items that have been last altered more than 2 hours ago. 15. Enter this text into your /etc/cron.d/koha-common file: */2 * * * * root koha-foreach --enabled /usr/share/koha/bin/cronjobs/automatic_item_modification_by_age.pl --confirm This will make the cronjob run every 2 minutes. 16. Now restart koha-common with this command: sudo /etc/init.d/koha-common restart 17. Now wait for more than 2 minutes and check the database again and notice that the two items have blank location fields as the automatically running cronjob altered the items. 18. Repeat steps 9-17 with the new rules in the auto item modification tool for the following rule conditions: New rule: Age: 2 Age starting point: Created Units: Days Condition 'items.homebranch'='', Substitutions 'items.homebranch'='' New rule: Age: 2 Age starting point: Altered Units: Days Condition 'items.homebranch'='', Substitutions 'items.homebranch'='' Sponsored-By: Toi Ohomai Institute of Technology, New Zealand --- C4/Items.pm | 10 +++++++--- ...ble_change_dateaccessioned_to_datetime_datatype.sql | 1 + .../tools/automatic_item_modification_by_age.tt | 18 +++++++++--------- .../prog/js/automatic_item_modification_by_age.js | 11 ----------- 4 files changed, 17 insertions(+), 23 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_21173-alter_item_table_change_dateaccessioned_to_datetime_datatype.sql diff --git a/C4/Items.pm b/C4/Items.pm index d70256c..9ff6a14 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -289,7 +289,6 @@ sub AddItem { $itype_sth->execute( $item->{'biblionumber'} ); ( $item->{'itype'} ) = $itype_sth->fetchrow_array; } - my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} ); return if $error; @@ -1630,7 +1629,7 @@ C sub _set_defaults_for_add { my $item = shift; - $item->{dateaccessioned} ||= output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); + $item->{dateaccessioned} ||= DateTime->now( time_zone => C4::Context->tz() ); $item->{$_} ||= 0 for (qw( notforloan damaged itemlost withdrawn)); } @@ -1936,11 +1935,16 @@ sub _mod_item_dates { # date formatting for date fields in item hash my @keys = grep { $_ =~ /^onloan$|^date|date$|datetime$/ } keys %$item; - # Incl. dateaccessioned,replacementpricedate,datelastborrowed,datelastseen + # Incl. replacementpricedate,datelastborrowed,datelastseen # NOTE: We do not (yet) have items fields ending with datetime # Fields with _on$ have been handled already foreach my $key ( @keys ) { + # If the key is 'dateaccessioned' then escape out of this loop + # We want to store the date and time for the dateaccessioned field + if ($key eq "dateaccessioned") { + last; + } next if !defined $item->{$key}; # skip undefs my $dt = eval { dt_from_string( $item->{$key} ) }; # eval: dt_from_string will die on us if we pass illegal dates diff --git a/installer/data/mysql/atomicupdate/bug_21173-alter_item_table_change_dateaccessioned_to_datetime_datatype.sql b/installer/data/mysql/atomicupdate/bug_21173-alter_item_table_change_dateaccessioned_to_datetime_datatype.sql new file mode 100644 index 0000000..9a9b254 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_21173-alter_item_table_change_dateaccessioned_to_datetime_datatype.sql @@ -0,0 +1 @@ +ALTER TABLE items MODIFY COLUMN dateaccessioned datetime; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt index 2d35848..42d26d5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt @@ -72,12 +72,12 @@
Age
- +
Unit

Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point will default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.

- [% IF rule.unit == "hours" %] @@ -91,7 +91,7 @@ [% IF rule.unit == "days" %]
@@ -137,7 +137,7 @@ [% END %] [% END %] - + Add a substitution Remove substitution A field name is required @@ -228,12 +228,12 @@ [% IF rule.age.defined and rule.unit.defined and rule.age.length > 0 %] [% IF rule.age == 1 %] [% IF rule.unit == "days" %] - [% rule.age %] day + [% rule.age | html %] day [% ELSE %] - [% rule.age %] hour + [% rule.age | html %] hour [% END %] [% ELSE %] - [% rule.age %] [% rule.unit %] + [% rule.age | html %] [% rule.unit | html %] [% END %] [% ELSE %] There is no age for this rule. @@ -241,7 +241,7 @@ [% IF rule.age_starting_point.defined %] - [% rule.age_starting_point %] + [% rule.age_starting_point | html %] [% ELSE %] There is no age starting point for this rule. [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js b/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js index ea5e686..a2b7ca3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js +++ b/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js @@ -52,7 +52,6 @@ function update_rule_count(){ $(document).ready(function() { $("#new_rule .remove_rule").hide(); $("#new_rule a.remove_block").hide(); - $("#new_rule_age_starting_point_div").hide(); $("#rules a.remove_block").click(function(e){ e.preventDefault(); @@ -63,16 +62,6 @@ $(document).ready(function() { remove_rule_action($(this)); }); - $("#new_rule_unit").change(function(){ - var unitselected = $(this).find("option:selected").attr("id"); - var newruleagestart = document.getElementById("new_rule_age_starting_point_div"); - if (unitselected == "days") { - newruleagestart.style.display = "block" - } else { - newruleagestart.style.display = "none"; - } - }); - var unique_id = $(".rule").length + 1; $(".add_rule").click(function(e){ e.preventDefault(); -- 2.1.4