Bug 12598: Update code to use new modules
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 1 Jun 2017 13:12:48 +0000 (10:12 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 16 Feb 2018 16:57:58 +0000 (13:57 -0300)
Signed-off-by: Colin Campbell <colin.campbell@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Patrons/Import.pm
koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt
t/db_dependent/Koha/Patrons/Import.t

index 6b53c4b..9155c36 100644 (file)
@@ -23,10 +23,12 @@ use Carp;
 use Text::CSV;
 
 use C4::Members;
-use C4::Branch;
 use C4::Members::Attributes qw(:all);
 use C4::Members::AttributeTypes;
 
+use Koha::Libraries;
+use Koha::Patrons;
+use Koha::Patron::Categories;
 use Koha::DateUtils;
 
 =head1 NAME
@@ -401,7 +403,7 @@ Returns an array of borrowers' table columns.
 sub set_column_keys {
     my ($self, $extended) = @_;
 
-    my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } C4::Members::columns();
+    my @columnkeys = map { $_ ne 'borrowernumber' ? $_ : () } Koha::Patrons->columns();
     push( @columnkeys, 'patron_attributes' ) if $extended;
 
     return @columnkeys;
@@ -450,8 +452,8 @@ sub check_branch_code {
     }
 
     # look for branch code
-    my $branch_name = GetBranchName( $branchcode );
-    unless( $branch_name ) {
+    my $library = Koha::Libraries->find( $branchcode );
+    unless( $library ) {
         push (@$missing_criticals, { key => 'branchcode', line => $line_number, lineraw => $borrowerline,
                                      value => $branchcode, branch_map => 1, });
     }
@@ -475,7 +477,7 @@ sub check_borrower_category {
     }
 
     # Looking for borrower category
-    my $category = GetBorrowercategory( $categorycode );
+    my $category = Koha::Patron::Categories->find($categorycode);
     unless( $category ) {
         push (@$missing_criticals, { key => 'categorycode', line => $line_number, lineraw => $borrowerline,
                                      value => $categorycode, category_map => 1, });
index 7c53da8..9989414 100644 (file)
             </fieldset>
         [% END %]
 
-        <fieldset class="action"><input type="submit" value="Import" /></fieldset>
+        <fieldset class="action">
+            <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
+            <input type="submit" value="Import" />
+        </fieldset>
     </form>
 [% END %]
 
 you can supply dates in ISO format (e.g., '2010-10-28').
         </li>
     </ul>
-    </fieldset>
-    [% END %]
-    <fieldset class="action">
-        <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
-        <input type="submit" value="Import" />
-    </fieldset>
-</form>
-[% END %]
-
 </div>
 </div>
 </div>
index 3c46ce2..4e4bde4 100644 (file)
@@ -392,17 +392,19 @@ subtest 'test_set_column_keys' => sub {
 subtest 'test_set_column_keys' => sub {
     plan tests => 2;
 
+    my @columns = Koha::Patrons->columns;
     # Given ... nothing at all
     # When ... Then ...
     my @columnkeys_0 = $patrons_import->set_column_keys(undef);
-    is(scalar @columnkeys_0, 66, 'Got the expected array size from set column keys with undef extended');
+    # -1 because we do not want the borrowernumber column
+    is(scalar @columnkeys_0, @columns - 1, 'Got the expected array size from set column keys with undef extended');
 
     # Given ... extended.
     my $extended = 1;
 
     # When ... Then ...
     my @columnkeys_1 = $patrons_import->set_column_keys($extended);
-    is(scalar @columnkeys_1, 67, 'Got the expected array size from set column keys with extended');
+    is(scalar @columnkeys_1, @columns - 1 + $extended, 'Got the expected array size from set column keys with extended');
 };
 
 subtest 'test_set_patron_attributes' => sub {