From 637279a983b01fe0efb5cc9386b857fba2e933d6 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Mon, 29 Dec 2014 15:18:08 +0100
Subject: [PATCH] [PASSED QA] Bug 13497: Remove the pref AddPatronsLists
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The pref AddPatronLists does not work as expected if 'generic' is
selected.
Indeed a patron should be linked to a valid patron category (see the
constraint borrowers_ibfk_1 in the DB structure).

Test plan:
0/ Confirm that the AddPatronLists does not work as expected if you choose
the generic patron types.
1/ Delete all you patron categories and check that the interface invites
you to create one.
2/ Confirm that you are able to create a patron and to link it to a patron
category you have created.

I could not verify step 1/, because at least one Patron category
can not be deleted (Staff, since I'm logged in as a Staff patron
and you can not delete categories that are in use).
Tested 0/ and 2/
Signed-off-by: Marc Véron <veron@veron.ch>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes QA script and tests.
---
 C4/UsageStats.pm                                              |  1 -
 circ/circulation.pl                                           | 11 ++++-------
 installer/data/mysql/sysprefs.sql                             |  1 -
 installer/data/mysql/updatedatabase.pl                        | 10 ++++++++++
 koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc   | 11 +----------
 .../prog/en/modules/admin/preferences/patrons.pref            |  7 -------
 members/members-home.pl                                       |  9 ++-------
 patroncards/members-search.pl                                 |  4 +---
 serials/member-search.pl                                      |  7 +------
 9 files changed, 19 insertions(+), 42 deletions(-)

diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm
index 627fba5..caf8930 100644
--- a/C4/UsageStats.pm
+++ b/C4/UsageStats.pm
@@ -278,7 +278,6 @@ sub BuildReport {
         TrackClicks
         PatronSelfRegistration
         OPACShelfBrowser
-        AddPatronLists
         AutoEmailOpacUser
         AutoEmailPrimaryAddress
         autoMemberNum
diff --git a/circ/circulation.pl b/circ/circulation.pl
index 982669c..2aa9eb0 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -206,13 +206,10 @@ my $borrowerslist;
 my $message;
 if ($findborrower) {
     my $borrowers = Search($findborrower, 'cardnumber') || [];
-    if (C4::Context->preference("AddPatronLists")) {
-        if (C4::Context->preference("AddPatronLists")=~/code/){
-            my $categories = GetBorrowercategoryList;
-            $categories->[0]->{'first'} = 1;
-            $template->param(categories=>$categories);
-        }
-    }
+    my $categories = GetBorrowercategoryList;
+    $categories->[0]->{first} = 1;
+    $template->param( categories => $categories );
+
     if ( @$borrowers == 0 ) {
         $query->param( 'findborrower', '' );
         $message = "'$findborrower'";
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index 9020b4b..5a52888 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -6,7 +6,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('AcquisitionDetails', '1', '', 'Hide/Show acquisition details on the biblio detail page.', 'YesNo'),
 ('AcqViewBaskets','user','user|branch|all','Define which baskets a user is allowed to view: his own only, any within his branch or all','Choice'),
 ('AcqWarnOnDuplicateInvoice','0','','Warn librarians when they try to create a duplicate invoice','YesNo'),
-('AddPatronLists','categorycode','categorycode|category_type','Allow user to choose what list to pick up from when adding patrons','Choice'),
 ('advancedMARCeditor','0','','If ON, the MARC editor won\'t display field/subfield descriptions','YesNo'),
 ('AdvancedSearchLanguages','','','ISO 639-2 codes of languages you wish to see appear as an Advanced search option.  Example: eng|fre|ita','Textarea'),
 ('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice'),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 0ed56c6..8ee80d0 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -9793,6 +9793,16 @@ if(CheckVersion($DBversion)) {
     SetVersion($DBversion);
 }
 
+
+$DBversion = "3.19.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        DELETE FROM systempreferences where variable = 'AddPatronLists'
+    |);
+    print "Upgrade to $DBversion done (Bug XXXXX - Remove the AddPatronLists system preferences)\n";
+    SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
index 35720df..ac97003 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
@@ -3,16 +3,7 @@
     <div class="btn-group">
         <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="icon-plus"></i> New patron <span class="caret"></span></button>
             <ul class="dropdown-menu">
-                [% IF Koha.Preference('AddPatronLists') == 'categorycode' %]
-                    [% FOREACH categorie IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;categorycode=[% categorie.categorycode %]">[% categorie.description %]</a></li>[% END %]
-                [% ELSE %]
-                    <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=A">Adult patron</a></li>
-                    <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=C">Child patron</a></li>
-                    <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=P">Professional patron</a></li>
-                    <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=I">Organization</a></li>
-                    <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=S">Staff patron</a></li>
-                    <li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;category_type=X">Statistical patron</a></li>
-                [% END %]
+                [% FOREACH categorie IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;categorycode=[% categorie.categorycode %]">[% categorie.description %]</a></li>[% END %]
             </ul>
     </div>
 </div>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
index aa567c3..4784f27 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
@@ -1,13 +1,6 @@
 Patrons:
     General:
      -
-         - List
-         - pref: AddPatronLists
-           choices:
-               categorycode: specific categories
-               category_type: general patron types
-         - under the new patron menu.
-     -
          - pref: AutoEmailOpacUser
            choices:
                yes: Send
diff --git a/members/members-home.pl b/members/members-home.pl
index 0d0e279..d589a9c 100755
--- a/members/members-home.pl
+++ b/members/members-home.pl
@@ -67,7 +67,6 @@ if ( C4::Branch::onlymine ) {
 }
 
 my @categories;
-my $no_categories;
 my $no_add = 0;
 if(scalar(@branchloop) < 1){
     $no_add = 1;
@@ -78,14 +77,10 @@ else {
 }
 
 @categories=C4::Category->all;
-if(scalar(@categories) < 1){ 
-    $no_categories = 1; 
-}
-
-if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
+if(scalar(@categories) < 1){
     $no_add = 1;
     $template->param(no_categories => 1);
-} 
+}
 else {
     $template->param(categories=>\@categories);
 }
diff --git a/patroncards/members-search.pl b/patroncards/members-search.pl
index 0c680a0..194dbd7 100755
--- a/patroncards/members-search.pl
+++ b/patroncards/members-search.pl
@@ -39,7 +39,6 @@ my $not_attributes = $cgi->param('not_attributes') || undef;
 
 my @categories=C4::Category->all;
 my %categories_display;
-my $no_categories;
 
 foreach my $category (@categories) {
     my $hash={
@@ -58,8 +57,7 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
                 flagsrequired => {borrowers => 1},
                 debug => 1,});
 
-if(scalar(@categories) < 1){ $no_categories = 1; }
-if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
+if(scalar(@categories) < 1){
     $template->param(no_categories => 1);
 } else {
     $template->param(
diff --git a/serials/member-search.pl b/serials/member-search.pl
index 9ae769b..cd431a4 100755
--- a/serials/member-search.pl
+++ b/serials/member-search.pl
@@ -65,12 +65,7 @@ foreach my $category (@categories){
 			 };
 	$categories_dislay{$$category{categorycode}} = $hash;
 }
-$template->param(
-        "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
-            );
-if (C4::Context->preference("AddPatronLists")=~/code/){
-    $categories[0]->{'first'}=1;
-}
+$categories[0]->{first} = 1;
 
 my $member=$cgi->param('member');
 my $orderby=$cgi->param('orderby');
-- 
1.9.1