From e1de593de8b07f33bc39544461666f89dd4b5a32 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 6 Jan 2016 10:41:44 +0000
Subject: [PATCH] Bug 4941: Remove the singleBranchMode system preference

The singleBranchMode system preference does not make sense.
Either the install has only 1 library defined or several. In both case,
we can easily guess the behavior to follow.

So the idea of this patch is to replace the fetch of this syspref with a
call to count the number of libraries defined in DB.

Test plan:
1/ From a fresh Koha install, execute the DB entry to remove the pref.
2/ Define only 1 library
3/ Confirm that Koha behaves the same as before (try to change your
library, look at the facets)
4/ Create another library (or more) and reinsert the pref and set it:
  insert into systempreferences (variable, value)
    values('singleBranchMode', 1);
5/ Execute the DB entry
You should get a warning message.
6/ Repeat 3.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Does what it says, but will change behaviour for any Koha install that
has 2 branches defined, One circulation, and this preference set.
If that is an acceptable change, we might need to make sure this is noted well in the
release notes.
---
 C4/Auth.pm                                                         | 3 ++-
 C4/Koha.pm                                                         | 6 ++----
 C4/Search.pm                                                       | 3 ++-
 C4/UsageStats.pm                                                   | 1 -
 C4/XSLT.pm                                                         | 2 +-
 installer/data/mysql/sysprefs.sql                                  | 1 -
 .../intranet-tmpl/prog/en/modules/admin/preferences/opac.pref      | 7 -------
 opac/opac-reserve.pl                                               | 4 ++--
 8 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/C4/Auth.pm b/C4/Auth.pm
index cda7ae0..4c8db61 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -33,6 +33,7 @@ use C4::Search::History;
 use Koha;
 use Koha::AuthUtils qw(hash_password);
 use Koha::LibraryCategories;
+use Koha::Libraries;
 use POSIX qw/strftime/;
 use List::MoreUtils qw/ any /;
 use Encode qw( encode is_utf8);
@@ -421,7 +422,7 @@ sub get_template_and_user {
         hide_marc       => C4::Context->preference("hide_marc"),
         item_level_itypes  => C4::Context->preference('item-level_itypes'),
         patronimages       => C4::Context->preference("patronimages"),
-        singleBranchMode   => C4::Context->preference("singleBranchMode"),
+        singleBranchMode   => ( Koha::Libraries->search->count == 1 ),
         XSLTDetailsDisplay => C4::Context->preference("XSLTDetailsDisplay"),
         XSLTResultsDisplay => C4::Context->preference("XSLTResultsDisplay"),
         using_https        => $using_https,
diff --git a/C4/Koha.pm b/C4/Koha.pm
index 0bb2bd7..2f7af3d 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -794,8 +794,7 @@ sub getFacets {
             }
             ];
 
-            unless ( C4::Context->preference("singleBranchMode")
-                || Koha::Libraries->search->count == 1 )
+            unless ( Koha::Libraries->search->count == 1 )
             {
                 my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
                 if (   $DisplayLibraryFacets eq 'both'
@@ -876,8 +875,7 @@ sub getFacets {
             },
             ];
 
-            unless ( C4::Context->preference("singleBranchMode")
-                || Koha::Libraries->search->count == 1 )
+            unless ( Koha::Libraries->search->count == 1 )
             {
                 my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
                 if (   $DisplayLibraryFacets eq 'both'
diff --git a/C4/Search.pm b/C4/Search.pm
index f52e0ee..58ccf84 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -31,6 +31,7 @@ use C4::Branch;
 use C4::Reserves;    # GetReserveStatus
 use C4::Debug;
 use C4::Charset;
+use Koha::Libraries;
 use YAML;
 use URI::Escape;
 use Business::ISBN;
@@ -618,7 +619,7 @@ sub getRecords {
                                 $facets_info->{$link_value}->{'label_value'} =~
                                 /Libraries/
                             )
-                            and ( C4::Context->preference('singleBranchMode') )
+                            and ( Koha::Libraries->search->count == 1 )
                           );
                     }
                 }
diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm
index b07bc1e..869b6af 100644
--- a/C4/UsageStats.pm
+++ b/C4/UsageStats.pm
@@ -267,7 +267,6 @@ sub BuildReport {
         OpacRenewalBranch
         OPACViewOthersSuggestions
         SearchMyLibraryFirst
-        singleBranchMode
         AnonSuggestions
         EnableOpacSearchHistory
         OPACPrivacy
diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index 7a94f2c..d7658a2 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -204,7 +204,7 @@ sub XSLTParse4Display {
                               UseAuthoritiesForTracings TraceSubjectSubdivisions
                               Display856uAsImage OPACDisplay856uAsImage 
                               UseControlNumber IntranetBiblioDefaultView BiblioDefaultView
-                              singleBranchMode OPACItemLocation DisplayIconsXSLT
+                              OPACItemLocation DisplayIconsXSLT
                               AlternateHoldingsField AlternateHoldingsSeparator
                               TrackClicks opacthemes IdRef / )
     {
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index aa53139..7e2af1a 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -420,7 +420,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('ShowPatronImageInWebBasedSelfCheck','0','','If ON, displays patron image when a patron uses web-based self-checkout','YesNo'),
 ('ShowReviewer','full','none|full|first|surname|firstandinitial|username','Choose how a commenter\'s identity is presented alongside comments in the OPAC','Choice'),
 ('ShowReviewerPhoto','1','','If ON, photo of reviewer will be shown beside comments in OPAC','YesNo'),
-('singleBranchMode','0',NULL,'Operate in Single-branch mode, hide branch selection in the OPAC','YesNo'),
 ('SlipCSS','',NULL,'Slips CSS url.','free'),
 ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
 ('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
index 09b850c..7476f17 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
@@ -477,13 +477,6 @@ OPAC:
             - the acquisition details on OPAC detail pages.
     Policy:
         -
-            - pref: singleBranchMode
-              default: 0
-              choices:
-                  yes: "Don't allow"
-                  no: Allow
-            - patrons to select their branch on the OPAC or show branch names with callnumbers.
-        -
             - pref: SearchMyLibraryFirst
               choices:
                   yes: Limit
diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl
index 60232cc..ed5df38 100755
--- a/opac/opac-reserve.pl
+++ b/opac/opac-reserve.pl
@@ -35,8 +35,8 @@ use C4::Overdues;
 use C4::Debug;
 use Koha::DateUtils;
 use Koha::Borrower::Debarments qw(IsDebarred);
+use Koha::Libraries;
 use Date::Calc qw/Today Date_to_Days/;
-# use Data::Dumper;
 
 my $maxreserves = C4::Context->preference("maxreserves");
 
@@ -228,7 +228,7 @@ if ( $query->param('place_reserve') ) {
 
         my $canreserve = 0;
 
-        my $singleBranchMode = C4::Context->preference("singleBranchMode");
+        my $singleBranchMode = Koha::Libraries->search->count == 1;
         if ( $singleBranchMode || !$OPACChooseBranch )
         {    # single branch mode or disabled user choosing
             $branch = $borr->{'branchcode'};
-- 
2.7.0.rc3