Bugzilla – Attachment 77604 Details for
Bug 21173
Add hours as age unit to auto item modifications by age for damaged_on, itemlost_on and withdrawn_on fields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.
Bug-21173---Customize-age-unit-and-starting-point-.patch (text/plain), 17.61 KB, created by
Alex Buckley
on 2018-08-08 22:55:56 UTC
(
hide
)
Description:
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2018-08-08 22:55:56 UTC
Size:
17.61 KB
patch
obsolete
>From c1f84f06e3b6f6452b4f754649f362e6d4168226 Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Mon, 6 Aug 2018 14:08:57 +0000 >Subject: [PATCH] Bug 21173 - Customize age unit and starting point for > automatic item modification by age tool and cronjob. > >This allows librarians to define either the item creation date or items >last altered timestamp as the starting point for the age of the item so >the autmatic_item_modification_by_age.pl can alter item fields for >example for items which have been in the catalogue for a while. > >A use case for this functionality is: >* When an items shelving location changes from 'In processing' to 'Shelving trolley' after 1 hour the status 'Shelving trolley' is removed for the item. The unit 'Hours' can now be set (extending the functionality of this cronjob from just calculating item age in days) and the age starting point of 'Last altered' can be defined so existing items in the catalogue like this example item will be altered by the cronjob. > >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 >alsthough 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'. > >When you select 'Days' then the Age starting point selection will appear >where you can specify if you want the rule to work on the number of days >since the item was last altered or number of days since the item was >created. > >NOTE: If you select 'Hours' as the unit type when creating a new rule >then the Age starting point selection area is hidden. This is because >the item creation value is saved in the database as a date not a >datetime. Therefore we cannot calculate the number of hours since the >item was created in the Koha catalog. > >Therefore if the unit is set to 'Hours' then by default the item will >use the item last altered value (stored as a date time) as the age >starting point. > >For existing rules if they have the unit set to 'Hours' then the Age >starting point area is hidden by default when the page loads. > >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='Days', 'Age starting point'='Created', Condition 'items.homebranch'='<a branchcode of a branch in your Koha instance>', substituions 'items.homebranch'='<another branchcode in your Koha instance>' > >10. Now click 'Save' and confirm the data displayed for both rules is >correct. > >11. In the database manually set the location field of two items to >'CART' and set their timestamp 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 and 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. > >15. Now restart koha-common with this command: sudo >/etc/init.d/koha-common restart > >16. 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. > >Sponsored-By: Toi Ohomai Institute of Technology, New Zealand >--- > C4/Items.pm | 17 ++++- > .../tools/automatic_item_modification_by_age.tt | 76 +++++++++++++++++++--- > .../prog/js/automatic_item_modification_by_age.js | 12 ++++ > tools/automatic_item_modification_by_age.pl | 18 ++++- > 4 files changed, 111 insertions(+), 12 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index 837c195..088ba3f 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -2827,6 +2827,8 @@ sub ToggleNewStatus { > my $report; > for my $rule ( @rules ) { > my $age = $rule->{age}; >+ my $unit = $rule->{unit}; >+ my $age_starting_point = $rule->{age_starting_point}; > my $conditions = $rule->{conditions}; > my $substitutions = $rule->{substitutions}; > my @params; >@@ -2855,8 +2857,19 @@ sub ToggleNewStatus { > } > } > if ( defined $age ) { >- $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; >- push @params, $age; >+ # Calculate item age based on hours since item last altered >+ if ( defined $rule && defined $age_starting_point && $unit eq "hours" && $age_starting_point eq "itemaltered" ) { >+ $query .= q| AND HOUR(TIMEDIFF(NOW(), items.timestamp)) >= ? |; >+ push @params, $age; >+ } elsif ( defined $rule && defined $age_starting_point && $unit eq "days" && $age_starting_point eq "itemaltered" ) { >+ # Calculate item age based on days since item last altered >+ $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.timestamp) >= ? |; >+ push @params, $age; >+ } else { >+ # Calculate item age based on days since item was created >+ $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(items.dateaccessioned) >= ? |; >+ push @params, $age; >+ } > } > my $sth = $dbh->prepare($query); > $sth->execute( @params ); >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 7e1d5a3..cb4a5f7 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 >@@ -70,10 +70,39 @@ > <legend>Rule <span class="rulecount">[% loop.count %]</span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend> > <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled --> > <div class="age"> >- <h5>Age in days</h5> >+ <h5>Age</h5> > <input class="age" type="number" value="[% rule.age %]" name="age_[% id %]" /> > </div> >- <div class="blocks"> >+ <div> >+ <h5>Unit</h5> >+ <p>Note: If the unit of 'Hours' is set then you cannot choose an age starting point, the item age starting point wil default to the last item alteration event. The Age starting point selection will be hidden if you have set the unit to 'Hours'.</p> >+ <select id="existing_rule_unit" name="unit_[% id %]" id="unit"> >+ <option value="">Choose a unit</option> >+ [% IF rule.unit == "hours" %] >+ <option value="hours" selected="selected">Hours</option> >+ <option value="days">Days</option> >+ [% ELSIF rule.unit == "days" %] >+ <option value="days" selected="selected">Days</option> >+ <option value="hours">Hours</option> >+ [% END %] >+ </select> >+ </div> >+ [% IF rule.unit == "days" %] >+ <div id="age_starting_point_div"> >+ <h5>Age starting point (starting point from which the item age is calculated)</h5> >+ <select name="age_starting_point_[% id %]" id="age_starting_point"> >+ <option value="">Choose age starting point</option> >+ [% IF rule.age_starting_point == "itemcreation" %] >+ <option value="itemcreation" selected="selected">Created</option> >+ <option value="itemaltered">Item last altered</option> >+ [% ELSIF rule.age_starting_point == "itemaltered" %] >+ <option value="itemaltered" selected="selected">Last altered</option> >+ <option value="itemcreation">Item creation</option> >+ [% END %] >+ </select> >+ </div> >+ [% END %] >+ <div class="blocks"> > <h5>Conditions</h5> > [% FOR condition IN rule.conditions %] > <div class="block"> >@@ -87,7 +116,6 @@ > [% END %] > [% END %] > </select> >- = > <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a> >@@ -108,7 +136,6 @@ > [% END %] > [% END %] > </select> >- = > <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a> >@@ -131,9 +158,26 @@ > <legend>Rule <span class="rulecount"></span> <a href="#" class="remove_rule"><i class="fa fa-trash"></i> Remove this rule</a></legend> > <input type="hidden" name="unique_id" /> > <div class="age"> >- <h5>Age in days</h5> >+ <h5>Age</h5> > <input class="age" type="number" value="" name="age" /> > </div> >+ <div> >+ <h5>Unit</h5> >+ <p>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'.</p> >+ <select id="new_rule_unit" name="unit" /> >+ <option value="">Choose an age unit</option> >+ <option id="hours" value="hours">Hours</option> >+ <option id="days" value="days">Days</option> >+ </select> >+ </div> >+ <div id="new_rule_age_starting_point_div"> >+ <h5>Age starting point (starting point from which the item age is calculated)</h5> >+ <select name="age_starting_point"> >+ <option value="">Choose age starting point</option> >+ <option value="itemcreation">Created</option> >+ <option value="itemaltered">Last altered</option> >+ </select> >+ </div> > <div class="blocks"> > <h5>Conditions</h5> > <div class="block"> >@@ -143,7 +187,6 @@ > <option value="[% field %]">[% field %]</option> > [% END %] > </select> >- = > <input type="text" value="" name="condition_value" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a condition</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove condition</a> >@@ -158,7 +201,6 @@ > <option value="[% field %]">[% field %]</option> > [% END %] > </select> >- = > <input type="text" value="" name="substitution_value" /> > <a class="add_block" href="#"><i class="fa fa-plus"></i> Add a substitution</a> > <a class="remove_block" href="#"><i class="fa fa-trash"></i> Remove substitution</a> >@@ -173,6 +215,7 @@ > <thead> > <tr> > <th>Age</th> >+ <th>Age starting point</th> > <th>Conditions</th> > <th>Substitutions</th> > </tr> >@@ -181,13 +224,28 @@ > [% FOR rule IN rules %] > <tr> > <td> >- [% IF rule.age.defined and rule.age.length > 0 %] >- [% rule.age %] days >+ [% IF rule.age.defined and rule.unit.defined and rule.age.length > 0 %] >+ [% IF rule.age == 1 %] >+ [% IF rule.unit == "days" %] >+ [% rule.age %] day >+ [% ELSE %] >+ [% rule.age %] hour >+ [% END %] >+ [% ELSE %] >+ [% rule.age %] [% rule.unit %] >+ [% END %] > [% ELSE %] > There is no age for this rule. > [% END %] > </td> > <td> >+ [% IF rule.age_starting_point.defined %] >+ [% rule.age_starting_point %] >+ [% ELSE %] >+ There is no age starting point for this rule. >+ [% END %] >+ </td> >+ <td> > [% FOR condition IN rule.conditions %] > [% IF condition.field %] > <div class="block"> >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 6c37d9b..ea5e686 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,6 +52,8 @@ 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(); > remove_block_action($(this)); >@@ -61,6 +63,16 @@ $(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(); >diff --git a/tools/automatic_item_modification_by_age.pl b/tools/automatic_item_modification_by_age.pl >index 12a1c00..807d79b 100755 >--- a/tools/automatic_item_modification_by_age.pl >+++ b/tools/automatic_item_modification_by_age.pl >@@ -39,7 +39,7 @@ use C4::Context; > use C4::Items; > use C4::Output; > use C4::Koha; >- >+use Data::Dumper; > use Koha::Items; > use Koha::Biblioitems; > >@@ -86,9 +86,25 @@ if ( $op eq 'update' ) { > push @{ $rule->{conditions} }, {} > unless @{ $rule->{conditions} }; > $rule->{age} = $cgi->param("age_$unique_id"); >+ >+ if ($cgi->param("unit_$unique_id")) { >+ $rule->{unit} = $cgi->param("unit_$unique_id"); >+ } else { >+ $rule->{unit} = $cgi->param("unit"); >+ } >+ >+ if ($cgi->param("age_starting_point_$unique_id")) { >+ $rule->{age_starting_point} = $cgi->param("age_starting_point_$unique_id"); >+ } elsif ($cgi->param("age_starting_point")) { >+ $rule->{age_starting_point} = $cgi->param("age_starting_point"); >+ } else { >+ $rule->{age_starting_point} = "itemaltered" >+ } >+ > push @rules, $rule; > } > my $syspref_content = to_json( \@rules ); >+ > C4::Context->set_preference($syspref_name, $syspref_content); > > $op = 'show'; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21173
:
77547
|
77548
|
77604
|
77605
|
78917
|
79914
|
138870
|
138871
|
138872
|
138894
|
138895
|
138896
|
156137
|
156138
|
156139
|
158574
|
158575
|
160715
|
160716