|
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 => "35972", |
| 6 |
description => "Add course_type column to courses table for flexible course displays", |
| 7 |
up => sub { |
| 8 |
my ($args) = @_; |
| 9 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
| 10 |
|
| 11 |
unless ( column_exists( 'courses', 'course_type' ) ) { |
| 12 |
say_info( $out, "Adding course_type column to courses table..." ); |
| 13 |
|
| 14 |
# Add the course_type column with default value 'COURSE' |
| 15 |
$dbh->do( |
| 16 |
q{ |
| 17 |
ALTER TABLE courses |
| 18 |
ADD COLUMN course_type VARCHAR(80) DEFAULT 'COURSE' |
| 19 |
AFTER course_id |
| 20 |
} |
| 21 |
); |
| 22 |
|
| 23 |
say_success( $out, "Added column 'courses.course_type'" ); |
| 24 |
|
| 25 |
# Migrate existing 'thesis tables' (department='TT') to new system |
| 26 |
my $migrated_courses = $dbh->do( |
| 27 |
q{ |
| 28 |
UPDATE courses |
| 29 |
SET course_type = 'RESEARCH_TABLE' |
| 30 |
WHERE department = 'TT' |
| 31 |
} |
| 32 |
); |
| 33 |
|
| 34 |
if ( $migrated_courses && $migrated_courses > 0 ) { |
| 35 |
say_success( $out, "Migrated $migrated_courses thesis table(s) to course_type='RESEARCH_TABLE'" ); |
| 36 |
} else { |
| 37 |
say_info( $out, "No thesis tables (department='TT') found to migrate" ); |
| 38 |
} |
| 39 |
|
| 40 |
# Add authorized value category for course types |
| 41 |
$dbh->do( |
| 42 |
q{ |
| 43 |
INSERT IGNORE INTO authorised_value_categories (category_name, is_system) |
| 44 |
VALUES ('CR_TYPE', 1) |
| 45 |
} |
| 46 |
); |
| 47 |
say_success( $out, "Added authorized value category 'CR_TYPE'" ); |
| 48 |
|
| 49 |
# Add default authorized values for course types |
| 50 |
$dbh->do( |
| 51 |
q{ |
| 52 |
INSERT IGNORE INTO authorised_values (category, authorised_value, lib, lib_opac) |
| 53 |
VALUES |
| 54 |
('CR_TYPE', 'COURSE', 'Course reserve', 'Course reserve'), |
| 55 |
('CR_TYPE', 'RESEARCH_TABLE', 'Research table', 'Research table'), |
| 56 |
('CR_TYPE', 'ON_DISPLAY', 'On display', 'On display') |
| 57 |
} |
| 58 |
); |
| 59 |
say_success( $out, "Added default course type authorized values" ); |
| 60 |
|
| 61 |
say_info( $out, "Course types can be customized in Administration > Authorized values > CR_TYPE" ); |
| 62 |
say_info( $out, "The 'lib' field controls staff interface display text" ); |
| 63 |
say_info( $out, "The 'lib_opac' field controls OPAC display text" ); |
| 64 |
say_success( $out, "Migration complete: Course reserves now supports multiple display types" ); |
| 65 |
|
| 66 |
} else { |
| 67 |
say_info( $out, "The course_type column already exists in the courses table." ); |
| 68 |
} |
| 69 |
}, |
| 70 |
}; |