From 414aa0aef643d147a1901b55bfa4479b73652d52 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 13 Nov 2018 14:38:27 -0300 Subject: [PATCH] Bug 15836: Remove deprecated subroutines It will take too much time to fix the failures here, given the simplicity of the subroutines I would be in favor of deleting them and continue the move on a separate bug report to use Koha::Object-objects Signed-off-by: Katrin Fischer I've checked that everything removed is no longer in use. Signed-off-by: Nick Clemens --- C4/ClassSource.pm | 198 +--------------------------------- t/db_dependent/ClassSource.t | 201 ----------------------------------- 2 files changed, 1 insertion(+), 398 deletions(-) delete mode 100644 t/db_dependent/ClassSource.t diff --git a/C4/ClassSource.pm b/C4/ClassSource.pm index fc4cfbb658..8c133bce70 100644 --- a/C4/ClassSource.pm +++ b/C4/ClassSource.pm @@ -49,12 +49,10 @@ sources and sorting rules. @EXPORT = qw( &GetClassSources &GetClassSource - &GetClassSortRules &GetClassSortRule - &GetSourcesForSortRule &GetClassSort - + ); =head2 GetClassSources @@ -95,31 +93,6 @@ sub GetClassSources { } -=head2 AddClassSource - - DEPRECATED - - AddClassSource($cn_source, $description, $used, $class_sort_rule); - - Adds a class_sources row. - -=cut - -sub AddClassSource { - - my ($cn_source, $description, $used, $class_sort_rule) = @_; - my $exists = GetClassSource($cn_source); - if ($exists) { - return 0; - } - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("INSERT INTO `class_sources` - (`cn_source`, `description`, `used`, `class_sort_rule`) - VALUES (?, ?, ?, ?)"); - $sth->execute($cn_source, $description, $used, $class_sort_rule); - return 1; -} - =head2 GetClassSource my $hashref = GetClassSource($cn_source); @@ -138,110 +111,6 @@ sub GetClassSource { return $row; } -=head2 ModClassSource - - DEPRECATED - - ModClassSource($cn_source, $description, $used, $class_sort_rule); - - Updates a class_sources row. - -=cut - -sub ModClassSource { - - my ($cn_source, $description, $used, $class_sort_rule) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("UPDATE `class_sources` - SET `description` = ?, - `used` = ?, - `class_sort_rule` = ? - WHERE `cn_source` = ?"); - $sth->execute($description, $used, $class_sort_rule, $cn_source); - -} - -=head2 DelClassSource - - DEPRECATED - - DelClassSource($cn_source); - - Deletes class_sources row. - -=cut - -sub DelClassSource { - - my ($cn_source) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("DELETE FROM `class_sources` WHERE `cn_source` = ?"); - $sth->execute($cn_source); - -} - -=head2 GetClassSortRules - - my $sort_rules = GetClassSortRules(); - -Returns reference to hash of references to -the class sorting rules, keyed on class_sort_rule - -=head3 Example - - my $sort_rules = GetClassSortRules(); - my @sort_rules = (); - foreach my $sort_rule (sort keys %$sort_rules) { - my $sort_rule = $sort_rules->{$sort_rule}; - push @sort_rules, - { - rule => $sort_rule->{'class_sort_rule'}, - description => $sort_rule->{'description'}, - sort_routine => $sort_rule->{'sort_routine'} - } - } - -=cut - -sub GetClassSortRules { - - my %class_sort_rules = (); - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules`"); - $sth->execute(); - while (my $sort_rule = $sth->fetchrow_hashref) { - $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule; - } - - return \%class_sort_rules; - -} - -=head2 AddClassSortRule - - DEPRECATED - - AddClassSortRule($class_sort_rule, $description, $sort_routine); - - Adds a class_sort_rules row. - -=cut - -sub AddClassSortRule { - - my ($class_sort_rule, $description, $sort_routine) = @_; - my $exists = GetClassSortRule($class_sort_rule); - if ($exists) { - return 0; - } - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("INSERT INTO `class_sort_rules` - (`class_sort_rule`, `description`, `sort_routine`) - VALUES (?, ?, ?)"); - $sth->execute($class_sort_rule, $description, $sort_routine); - return 1; -} - =head2 GetClassSortRule my $hashref = GetClassSortRule($class_sort_rule); @@ -260,71 +129,6 @@ sub GetClassSortRule { return $row; } -=head2 ModClassSortRule - - DEPRECATED - - ModClassSortRule($class_sort_rule, $description, $sort_routine); - - Updates a class_sort_rules row. - -=cut - -sub ModClassSortRule { - - my ($class_sort_rule, $description, $sort_routine) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("UPDATE `class_sort_rules` - SET `description` = ?, - `sort_routine` = ? - WHERE `class_sort_rule` = ?"); - $sth->execute($description, $sort_routine, $class_sort_rule); - -} - -=head2 DelClassSortRule - - DEPRECATED - - DelClassSortRule($class_sort_rule); - - Deletes class_sort_rules row. - -=cut - -sub DelClassSortRule { - - my ($class_sort_rule) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); - $sth->execute($class_sort_rule); - -} - -=head2 GetSourcesForSortRule - - my @source = GetSourcesForSortRule($class_sort_rule); - - Retrieves an array class_source.cn_rule for each source - that uses the supplied $class_sort_rule. - -=cut - -sub GetSourcesForSortRule { - - my ($class_sort_rule) = @_; - - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?"); - $sth->execute($class_sort_rule); - my @sources = (); - while (my ($source) = $sth->fetchrow_array()) { - push @sources, $source; - } - return @sources; - -} - =head2 GetClassSort my $cn_sort = GetClassSort($cn_source, $cn_class, $cn_item); diff --git a/t/db_dependent/ClassSource.t b/t/db_dependent/ClassSource.t deleted file mode 100644 index 6d4ab7ec4b..0000000000 --- a/t/db_dependent/ClassSource.t +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/perl - -use Modern::Perl; - -use Test::More tests => 25; -use Test::Warn; - -use C4::Context; - -BEGIN { - use_ok('C4::ClassSource'); -} -can_ok( 'C4::ClassSource', - qw( AddClassSortRule - AddClassSource - GetClassSort - GetClassSortRule - GetClassSortRules - GetClassSource - GetClassSources - DelClassSortRule - DelClassSource - GetSourcesForSortRule - ModClassSortRule - ModClassSource) -); - -#Start transaction -my $dbh = C4::Context->dbh; -$dbh->{RaiseError} = 1; -$dbh->{AutoCommit} = 0; - -#Start tests -$dbh->do(q|DELETE FROM class_sources|); -$dbh->do(q|DELETE FROM class_sort_rules|); - -#Test AddClassSortRule -my $countSources = scalar( keys(%{ GetClassSources() }) ); -my $countSources2 = scalar( keys(%{ GetClassSortRules() }) ); -AddClassSortRule( 'sortrule1', 'description1', 'routine1' ); -AddClassSortRule( 'sortrule2', 'description2', 'routine2' ); -is( - scalar( keys(%{ GetClassSortRules() }) ), - $countSources + 2, - "SortRule1 and SortRules2 have been added" -); - -#Test AddClassSource -AddClassSource( 'source1', 'Description_source1', 1, 'sortrule1' ); -AddClassSource( 'source2', 'Description_source2', 0, 'sortrule1' ); -is( - scalar( keys(%{ GetClassSources() }) ), - $countSources2 + 2, - "Source1 and source2 have been added" -); - -#Test GetClassSortRule -is_deeply( - GetClassSortRule('sortrule1'), - { - class_sort_rule => 'sortrule1', - description => 'description1', - sort_routine => 'routine1' - }, - "GetClassSort gives sortrule1's information" -); -is_deeply( GetClassSortRule(), undef, - "GetClassSort without params returns undef" ); -is_deeply( GetClassSortRule('doesnt_exist'), - undef, "GetClassSort with an id which doesn't exist returns undef" ); - -#Test GetClassSortRules -my $getsortrules = GetClassSortRules(); -is_deeply( - $getsortrules, - { - sortrule1 => { - class_sort_rule => 'sortrule1', - description => 'description1', - sort_routine => 'routine1' - }, - sortrule2 => { - class_sort_rule => 'sortrule2', - description => 'description2', - sort_routine => 'routine2' - } - }, - "GetClassSortRules returns the id off all SortRule and their information" -); - -#Test GetClassSource -my $getsource1 = GetClassSource('source1'); -is_deeply( - $getsource1, - { - cn_source => 'source1', - description => 'Description_source1', - used => 1, - class_sort_rule => 'sortrule1' - }, - "GetClassSource gives source1's information" -); -is_deeply( GetClassSource(), undef, - "GetClassSource without params returns undef" ); -is_deeply( GetClassSource('doesnt_exist'), - undef, "GetClassSource with an id which doesn't exist returns undef" ); - -#Test GetClassSources -my $getsources = GetClassSources(); -is_deeply( - $getsources, - { - source1 => { - cn_source => 'source1', - description => 'Description_source1', - used => 1, - class_sort_rule => 'sortrule1' - }, - source2 => { - cn_source => 'source2', - description => 'Description_source2', - used => 0, - class_sort_rule => 'sortrule1' - } - }, - "GetClassSources returns the id off all sources and their information" -); - -#Test GetClassSort -my $getclassSort; -warning_like - { $getclassSort = GetClassSort( 'source1', 'sortrule1', 'item1' ) } - qr/attempting to use non-existent class sorting routine/, - 'Non-existent class warning caught'; -is( $getclassSort, "SORTRULE1_ITEM1", -" the sort key corresponding to Source1 and sortrule1 and item1 is SORTRULE1_ITEM1" -); - -#Test GetSourcesForSorSortRule -my @sources = GetSourcesForSortRule('sortrule1'); -is_deeply( - \@sources, - [ 'source1', 'source2' ], - "Sortrule1 has source1 and source2" -); -@sources = GetSourcesForSortRule(); -is_deeply( \@sources, [], - "Without params GetSourcesForSortRule returns an empty array" ); -@sources = GetSourcesForSortRule('doesnt_exist'); -is_deeply( \@sources, [], - "With a wrong params GetSourcesForSortRule returns an empty array" ); - -#Test DelClassSortRule -#DelClassSortRule ('sortrule1'); -#is(scalar (keys (%{ GetClassSortRules() })),1,"SortRule1 has been deleted");#FIXME : impossible if some sources exist -DelClassSortRule('sortrule2'); -is( scalar( keys(%{ GetClassSortRules() }) ), 1, "SortRule2 has been deleted" ); -DelClassSortRule(); -is( scalar( keys(%{ GetClassSortRules() }) ), - 1, "Without params DelClassSortRule doesn't do anything" ); -DelClassSortRule('doesnt_exist'); -is( scalar( keys(%{ GetClassSortRules() }) ), - 1, "With wrong id, DelClassSortRule doesn't do anything" ); - -#Test DelClassSource -DelClassSource('source2'); -is( scalar( keys(%{ GetClassSources() }) ), 1, "Source2 has been deleted" ); -DelClassSource(); -is( scalar( keys(%{ GetClassSources() }) ), - 1, "Without params DelClassSource doesn't do anything" ); -DelClassSource('doesnt_exist'); -is( scalar( keys(%{ GetClassSources() }) ), - 1, "With wrong id, DelClassSource doesn't do anything" ); - -#Test ModClassSortRule -ModClassSortRule( 'sortrule1', 'description1_modified', 'routine1_modified' ); -is_deeply( - GetClassSortRule('sortrule1'), - { - class_sort_rule => 'sortrule1', - description => 'description1_modified', - sort_routine => 'routine1_modified' - }, - "Sortrule1 has been modified" -); - -#Test ModClassSource -ModClassSource( 'source1', 'Description_source1_modified', 0, 'sortrule1' ); -is_deeply( - GetClassSource('source1'), - { - cn_source => 'source1', - description => 'Description_source1_modified', - used => 0, - class_sort_rule => 'sortrule1' - }, - "Source1 has been modified" -); - -#End transaction -$dbh->rollback; -- 2.39.5