5 description => "Rename opac_news with additional_contents",
8 my $dbh = $args->{dbh};
10 if( TableExists('opac_news') ) {
12 ALTER TABLE opac_news RENAME additional_contents
16 if ( foreign_key_exists('additional_contents', 'opac_news_branchcode_ibfk') ) {
19 ALTER TABLE additional_contents
20 DROP KEY borrowernumber_fk,
21 DROP KEY opac_news_branchcode_ibfk,
22 DROP FOREIGN KEY borrowernumber_fk,
23 DROP FOREIGN KEY opac_news_branchcode_ibfk
27 ALTER TABLE additional_contents
28 ADD CONSTRAINT additional_contents_borrowernumber_fk
29 FOREIGN KEY (borrowernumber)
30 REFERENCES borrowers (borrowernumber) ON DELETE SET NULL ON UPDATE CASCADE
34 ALTER TABLE additional_contents
35 ADD CONSTRAINT additional_contents_branchcode_ibfk
36 FOREIGN KEY (branchcode)
37 REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
43 SET content = REGEXP_REPLACE(content, '<<\\\\s*opac_news\.', '<<additional_contents.')
47 SET content = REGEXP_REPLACE(content, '\\\\[%\\\\s*opac_news\.', '[% additional_contents.')
51 UPDATE systempreferences
52 SET variable="AdditionalContentsEditor"
53 WHERE variable="NewsToolEditor"
58 SET code="edit_additional_contents"
59 WHERE code="edit_news"
62 unless ( column_exists('additional_contents', 'category' ) ) {
64 ALTER TABLE additional_contents
65 ADD COLUMN `category` VARCHAR(20) NOT NULL COMMENT 'category for the additional content'
69 unless ( column_exists('additional_contents', 'location' ) ) {
71 ALTER TABLE additional_contents
72 ADD COLUMN `location` VARCHAR(255) NOT NULL COMMENT 'location of the additional content'
77 unless ( column_exists('additional_contents', 'code' ) ) {
79 ALTER TABLE additional_contents
80 ADD COLUMN `code` VARCHAR(100) NOT NULL COMMENT 'code to group content per lang'
85 my $contents = $dbh->selectall_arrayref(q|SELECT * FROM additional_contents|, { Slice => {} });
86 for my $c ( @$contents ) {
87 my ( $category, $location, $new_lang );
88 if ( $c->{lang} eq '' ) {
90 $location = 'staff_and_opac';
91 $new_lang = 'default';
92 } elsif ( $c->{lang} eq 'koha' ) {
94 $location = 'staff_only';
95 $new_lang = 'default';
96 } elsif ( $c->{lang} eq 'slip' ) {
99 $new_lang = 'default';
100 } elsif ( $c->{lang} =~ m|_| ) {
101 ( $location, $new_lang ) = split '_', $c->{lang};
102 $category = 'html_customizations'
105 $location = 'opac_only';
106 $new_lang = $c->{lang};
109 die "There is something wrong here, we didn't find a valid category for idnew=" . $c->{idnew} unless $category;
111 # Now this is getting weird
112 # We are adding an extra news with the same code when the lang is not "default" (/"en")
114 $new_lang = "default" if $new_lang eq 'en'; # Assume that "en" is "default"
116 my $sth_update = $dbh->prepare(q|
117 UPDATE additional_contents
118 SET category=?, location=?, lang=?
123 if ( $new_lang ne 'default' ) {
125 INSERT INTO additional_contents(category, code, location, branchcode, title, content, lang, published_on, updated_on, expirationdate, number, borrowernumber)
126 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
127 |, undef, $category, 'tmp_code', $location, $c->{branchcode}, $c->{title}, $c->{content}, 'default', $c->{published_on}, $c->{updated_on}, $c->{expirationdate}, $c->{number}, $c->{borrowernumber});
129 $parent_idnew = $dbh->last_insert_id(undef, undef, 'additional_contents', undef);
131 $sth_update->execute($category, $location, $new_lang, $c->{idnew});
133 my $idnew = $parent_idnew || $c->{idnew};
134 my $code = ( grep {$_ eq $location} qw( staff_and_opac staff_only opac_only slip ) ) ? "${location}_$idnew" : "News_$idnew";
135 $dbh->do(q|UPDATE additional_contents SET code=? WHERE idnew = ?|, undef, $code, $parent_idnew) if $parent_idnew;
136 $dbh->do(q|UPDATE additional_contents SET code=? WHERE idnew = ?|, undef, $code, $c->{idnew});
140 ALTER TABLE additional_contents
141 ADD UNIQUE KEY additional_contents_uniq (`category`,`code`,`branchcode`,`lang`)