Bugzilla – Attachment 98335 Details for
Bug 18936
Move issuingrules into circulation_rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18936: (follow-up) Add cloning of circulation rules back to Koha
Bug-18936-follow-up-Add-cloning-of-circulation-rul.patch (text/plain), 9.31 KB, created by
Jonathan Druart
on 2020-02-03 16:08:58 UTC
(
hide
)
Description:
Bug 18936: (follow-up) Add cloning of circulation rules back to Koha
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-02-03 16:08:58 UTC
Size:
9.31 KB
patch
obsolete
>From 879256ddb57932ab0aff58595d91c45ca6eb6cc4 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <joonas.kylmala@helsinki.fi> >Date: Tue, 28 Jan 2020 13:46:55 +0000 >Subject: [PATCH] Bug 18936: (follow-up) Add cloning of circulation rules back > to Koha >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >The "Clone these rules" feature in admin/smart-rules.pl was >dropped. This re-implements the cloning using Koha objects. > >Signed-off-by: Minna Kivinen <minna.kivinen@hamk.fi> > >Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi> >--- > Koha/CirculationRule.pm | 15 +++++ > Koha/CirculationRules.pm | 14 +++++ > admin/clone-rules.pl | 51 ++++------------- > admin/smart-rules.pl | 7 ++- > t/db_dependent/Koha/IssuingRules.t | 111 ++++++++++++++++++++++++++++++++++++- > 5 files changed, 155 insertions(+), 43 deletions(-) > >diff --git a/Koha/CirculationRule.pm b/Koha/CirculationRule.pm >index 5206c7d9aa..d5c9b864c9 100644 >--- a/Koha/CirculationRule.pm >+++ b/Koha/CirculationRule.pm >@@ -71,6 +71,21 @@ sub item_type { > return $self->{item_type}; > } > >+=head3 clone >+ >+Clone a circulation rule to another branch >+ >+=cut >+ >+sub clone { >+ my ($self, $to_branch) = @_; >+ >+ my $cloned_rule = $self->unblessed; >+ $cloned_rule->{branchcode} = $to_branch; >+ delete $cloned_rule->{id}; >+ return Koha::CirculationRule->new( $cloned_rule )->store; >+} >+ > =head3 _type > > =cut >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >index 2aaf056aaa..1e50251fa7 100644 >--- a/Koha/CirculationRules.pm >+++ b/Koha/CirculationRules.pm >@@ -358,6 +358,20 @@ sub delete { > } > } > >+=head3 clone >+ >+Clone a set of circulation rules to another branch >+ >+=cut >+ >+sub clone { >+ my ( $self, $to_branch ) = @_; >+ >+ while ( my $rule = $self->next ){ >+ $rule->clone($to_branch); >+ } >+} >+ > =head3 get_opacitemholds_policy > > my $can_place_a_hold_at_item_level = Koha::CirculationRules->get_opacitemholds_policy( { patron => $patron, item => $item } ); >diff --git a/admin/clone-rules.pl b/admin/clone-rules.pl >index dd071252d9..cefc11ede8 100755 >--- a/admin/clone-rules.pl >+++ b/admin/clone-rules.pl >@@ -32,9 +32,9 @@ use C4::Output; > use C4::Auth; > use C4::Koha; > use C4::Debug; >+use Koha::CirculationRules; > > my $input = new CGI; >-my $dbh = C4::Context->dbh; > > my ($template, $loggedinuser, $cookie) > = get_template_and_user({template_name => "admin/clone-rules.tt", >@@ -51,50 +51,19 @@ my $tobranch = $input->param("tobranch"); > $template->param(frombranch => $frombranch) if ($frombranch); > $template->param(tobranch => $tobranch) if ($tobranch); > >-if ($frombranch && $tobranch) { >+if ($frombranch && $tobranch && $frombranch ne $tobranch) { >+ $frombranch = ( $frombranch ne '*' ? $frombranch : undef ); >+ $tobranch = ( $tobranch ne '*' ? $tobranch : undef ); > >- my $error; >+ Koha::CirculationRules->search({branchcode => $tobranch})->delete; > >- # First, we create a temporary table with the rules we want to clone >- my $query = "CREATE TEMPORARY TABLE tmpissuingrules ENGINE=memory SELECT * FROM issuingrules WHERE branchcode=?"; >- my $sth = $dbh->prepare($query); >- my $res = $sth->execute($frombranch); >- $error = 1 unless ($res); >- >- if (!$error) { >- # We modify these rules according to the new branchcode >- $query = "UPDATE tmpissuingrules SET branchcode=? WHERE branchcode=?"; >- $sth = $dbh->prepare($query); >- $res = $sth->execute($tobranch, $frombranch); >- $error = 1 unless ($res); >- } >- >- if (!$error) { >- # We delete the rules for the existing branchode >- $query = "DELETE FROM issuingrules WHERE branchcode=?"; >- $sth = $dbh->prepare($query); >- $res = $sth->execute($tobranch); >- $error = 1 unless ($res); >- } >- >- >- if (!$error) { >- # We insert the new rules from our temporary table >- $query = "INSERT INTO issuingrules SELECT * FROM tmpissuingrules WHERE branchcode=?"; >- $sth = $dbh->prepare($query); >- $res = $sth->execute($tobranch); >- $error = 1 unless ($res); >- } >- >- # Finally, we delete our temporary table >- $query = "DROP TABLE tmpissuingrules"; >- $sth = $dbh->prepare($query); >- $res = $sth->execute(); >- >- $template->param(result => "1"); >- $template->param(error => $error); >+ my $rules = Koha::CirculationRules->search({ branchcode => $frombranch }); >+ $rules->clone($tobranch); >+} else { >+ $template->param(error => 1); > } > >+$template->param(result => 1); > > > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index 4d4ec5a6b3..ceb4a9be5b 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -574,13 +574,18 @@ my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['des > > my $itemtypes = Koha::ItemTypes->search_with_localization; > >+my $humanbranch = ( $branch ne '*' ? $branch : undef ); >+ >+my $definedbranch = Koha::CirculationRules->search({ branchcode => $humanbranch })->count ? 1 : 0; >+ > $template->param(show_branch_cat_rule_form => 1); > > $template->param( > patron_categories => $patron_categories, > itemtypeloop => $itemtypes, >- humanbranch => ( $branch ne '*' ? $branch : undef ), >+ humanbranch => $humanbranch, > current_branch => $branch, >+ definedbranch => $definedbranch, > ); > output_html_with_http_headers $input, $cookie, $template->output; > >diff --git a/t/db_dependent/Koha/IssuingRules.t b/t/db_dependent/Koha/IssuingRules.t >index 2cdb143a93..4d37fcfebc 100644 >--- a/t/db_dependent/Koha/IssuingRules.t >+++ b/t/db_dependent/Koha/IssuingRules.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use Test::Deep qw( cmp_methods ); > use Test::Exception; > >@@ -566,6 +566,115 @@ subtest 'set_rule' => sub { > }; > }; > >+subtest 'clone' => sub { >+ plan tests => 2; >+ >+ my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; >+ my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; >+ my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; >+ >+ subtest 'Clone multiple rules' => sub { >+ plan tests => 4; >+ >+ Koha::CirculationRules->delete; >+ >+ Koha::CirculationRule->new({ >+ branchcode => undef, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'fine', >+ rule_value => 5, >+ })->store; >+ >+ Koha::CirculationRule->new({ >+ branchcode => undef, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'lengthunit', >+ rule_value => 'days', >+ })->store; >+ >+ Koha::CirculationRules->search({ branchcode => undef })->clone($branchcode); >+ >+ my $rule_fine = Koha::CirculationRules->get_effective_rule({ >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'fine', >+ }); >+ my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({ >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'lengthunit', >+ }); >+ >+ _is_row_match( >+ $rule_fine, >+ { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'fine', >+ rule_value => 5, >+ }, >+ 'When I attempt to get cloned fine rule,' >+ .' then the above one is returned.' >+ ); >+ _is_row_match( >+ $rule_lengthunit, >+ { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'lengthunit', >+ rule_value => 'days', >+ }, >+ 'When I attempt to get cloned lengthunit rule,' >+ .' then the above one is returned.' >+ ); >+ >+ }; >+ >+ subtest 'Clone one rule' => sub { >+ plan tests => 2; >+ >+ Koha::CirculationRules->delete; >+ >+ Koha::CirculationRule->new({ >+ branchcode => undef, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'fine', >+ rule_value => 5, >+ })->store; >+ >+ my $rule = Koha::CirculationRules->search({ branchcode => undef })->next; >+ $rule->clone($branchcode); >+ >+ my $cloned_rule = Koha::CirculationRules->get_effective_rule({ >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'fine', >+ }); >+ >+ _is_row_match( >+ $cloned_rule, >+ { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => $itemtype, >+ rule_name => 'fine', >+ rule_value => '5', >+ }, >+ 'When I attempt to get cloned fine rule,' >+ .' then the above one is returned.' >+ ); >+ >+ }; >+}; >+ > sub _is_row_match { > my ( $rule, $expected, $message ) = @_; > >-- >2.11.0
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 18936
:
65247
|
65248
|
65249
|
67629
|
67758
|
68236
|
71034
|
71035
|
71036
|
71037
|
71038
|
71039
|
71040
|
71041
|
72230
|
72231
|
72232
|
72233
|
72234
|
72235
|
72236
|
72237
|
72238
|
91953
|
91954
|
91955
|
91956
|
91957
|
91958
|
91959
|
91960
|
91961
|
91962
|
91963
|
91964
|
91965
|
91966
|
91967
|
91968
|
91969
|
91970
|
91971
|
91972
|
91973
|
91974
|
91975
|
94179
|
94180
|
94181
|
94182
|
94183
|
94184
|
94185
|
94186
|
94187
|
94188
|
94189
|
94190
|
94191
|
94192
|
94193
|
94194
|
94195
|
94196
|
94197
|
94198
|
94199
|
94200
|
98299
|
98300
|
98301
|
98302
|
98303
|
98304
|
98305
|
98306
|
98307
|
98308
|
98309
|
98310
|
98311
|
98312
|
98313
|
98314
|
98315
|
98316
|
98317
|
98318
|
98319
|
98320
|
98321
|
98322
|
98323
|
98324
|
98325
|
98326
|
98327
|
98328
|
98329
|
98330
|
98331
|
98332
|
98333
|
98334
| 98335 |
98336
|
98337
|
98338
|
98339
|
98340
|
98341
|
98342
|
98343
|
98344
|
98345
|
98346
|
98347
|
98407
|
98408