View | Details | Raw Unified | Return to bug 3492
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug_3492.pl (+79 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "3492",
6
    description => "Migrate reservefee from categories to circulation rules and remove deprecated column",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Check if the reservefee column still exists
12
        my $column_exists = $dbh->selectrow_array(
13
            q{
14
            SELECT COUNT(*)
15
            FROM INFORMATION_SCHEMA.COLUMNS
16
            WHERE TABLE_SCHEMA = DATABASE()
17
            AND TABLE_NAME = 'categories'
18
            AND COLUMN_NAME = 'reservefee'
19
        }
20
        );
21
22
        if ($column_exists) {
23
24
            # Check if we have any existing reservefees to migrate
25
            my $existing_fees = $dbh->selectall_arrayref(
26
                q{
27
                SELECT categorycode, reservefee
28
                FROM categories
29
                WHERE reservefee IS NOT NULL AND reservefee > 0
30
            }, { Slice => {} }
31
            );
32
33
            if (@$existing_fees) {
34
                say_info(
35
                    $out,
36
                    "Migrating "
37
                        . scalar(@$existing_fees)
38
                        . " existing hold fees from categories to circulation rules..."
39
                );
40
41
                # Migrate existing reservefee values to circulation_rules
42
                my $insert_rule = $dbh->prepare(
43
                    q{
44
                    INSERT IGNORE INTO circulation_rules
45
                    (branchcode, categorycode, itemtype, rule_name, rule_value)
46
                    VALUES (NULL, ?, NULL, 'hold_fee', ?)
47
                }
48
                );
49
50
                my $migrated = 0;
51
                for my $fee (@$existing_fees) {
52
                    $insert_rule->execute( $fee->{categorycode}, $fee->{reservefee} );
53
                    if ( $insert_rule->rows ) {
54
                        $migrated++;
55
                    }
56
                }
57
58
                say_success( $out, "Successfully migrated $migrated hold fee rules to circulation_rules table." );
59
60
                if ( $migrated < @$existing_fees ) {
61
                    say_warning( $out, "Some rules may have already existed and were not overwritten." );
62
                }
63
            } else {
64
                say_info( $out, "No existing hold fees found in categories table to migrate." );
65
            }
66
67
            # Remove the deprecated reservefee column
68
            say_info( $out, "Removing deprecated reservefee column from categories table..." );
69
            $dbh->do(q{ALTER TABLE categories DROP COLUMN reservefee});
70
            say_success( $out, "Successfully removed reservefee column from categories table." );
71
72
        } else {
73
            say_info( $out, "The reservefee column has already been removed from the categories table." );
74
        }
75
76
        say_info( $out, "Hold fees can now be configured in Administration > Circulation and fine rules." );
77
        say_success( $out, "Migration complete: Hold fees are now fully managed through circulation rules." );
78
    },
79
};
(-)a/installer/data/mysql/kohastructure.sql (-2 lines)
Lines 1803-1809 CREATE TABLE `categories` ( Link Here
1803
  `dateofbirthrequired` tinyint(1) DEFAULT NULL COMMENT 'the minimum age required for the patron category',
1803
  `dateofbirthrequired` tinyint(1) DEFAULT NULL COMMENT 'the minimum age required for the patron category',
1804
  `enrolmentfee` decimal(28,6) DEFAULT NULL COMMENT 'enrollment fee for the patron',
1804
  `enrolmentfee` decimal(28,6) DEFAULT NULL COMMENT 'enrollment fee for the patron',
1805
  `overduenoticerequired` tinyint(1) DEFAULT NULL COMMENT 'are overdue notices sent to this patron category (1 for yes, 0 for no)',
1805
  `overduenoticerequired` tinyint(1) DEFAULT NULL COMMENT 'are overdue notices sent to this patron category (1 for yes, 0 for no)',
1806
  `reservefee` decimal(28,6) DEFAULT NULL COMMENT 'cost to place holds',
1807
  `hidelostitems` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'are lost items shown to this category (1 for yes, 0 for no)',
1806
  `hidelostitems` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'are lost items shown to this category (1 for yes, 0 for no)',
1808
  `category_type` varchar(1) NOT NULL DEFAULT 'A' COMMENT 'type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff)',
1807
  `category_type` varchar(1) NOT NULL DEFAULT 'A' COMMENT 'type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff)',
1809
  `BlockExpiredPatronOpacActions` varchar(128) NOT NULL DEFAULT 'follow_syspref_BlockExpiredPatronOpacActions' COMMENT 'specific actions expired patrons of this category are blocked from performing or if the BlockExpiredPatronOpacActions system preference is to be followed',
1808
  `BlockExpiredPatronOpacActions` varchar(128) NOT NULL DEFAULT 'follow_syspref_BlockExpiredPatronOpacActions' COMMENT 'specific actions expired patrons of this category are blocked from performing or if the BlockExpiredPatronOpacActions system preference is to be followed',
1810
- 

Return to bug 3492