From a072b5305e941e24b5faf1a5a4c79b06846eca02 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 8 Mar 2023 10:56:07 +0100 Subject: [PATCH] Bug 31383: Restore updated_on for individual content Sponsored-by: Rijksmuseum, Netherlands Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- Koha/AdditionalContentsLocalization.pm | 13 ------------ .../Result/AdditionalContentsLocalization.pm | 20 +++++++++++++++++-- .../data/mysql/atomicupdate/bug_31383.pl | 9 +++++---- installer/data/mysql/kohastructure.sql | 1 + tools/additional-contents.pl | 19 ++++++++++-------- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Koha/AdditionalContentsLocalization.pm b/Koha/AdditionalContentsLocalization.pm index 82bd961c2a..f70def51c7 100644 --- a/Koha/AdditionalContentsLocalization.pm +++ b/Koha/AdditionalContentsLocalization.pm @@ -150,19 +150,6 @@ sub published_on { return $self->additional_content->published_on(@params); } -=head3 updated_on - - $c->updated_on; - -Return the date of the last update of the content - -=cut - -sub updated_on { - my ( $self, @params ) = @_; - return $self->additional_content->updated_on(@params); -} - =head3 expirationdate $c->expirationdate; diff --git a/Koha/Schema/Result/AdditionalContentsLocalization.pm b/Koha/Schema/Result/AdditionalContentsLocalization.pm index 6553f8bb04..ed4fb504ab 100644 --- a/Koha/Schema/Result/AdditionalContentsLocalization.pm +++ b/Koha/Schema/Result/AdditionalContentsLocalization.pm @@ -66,6 +66,15 @@ the body of your additional content lang +=head2 updated_on + + data_type: 'timestamp' + datetime_undef_if_invalid: 1 + default_value: current_timestamp + is_nullable: 0 + +last modification + =cut __PACKAGE__->add_columns( @@ -89,6 +98,13 @@ __PACKAGE__->add_columns( { data_type => "mediumtext", is_nullable => 0 }, "lang", { data_type => "varchar", default_value => "", is_nullable => 0, size => 50 }, + "updated_on", + { + data_type => "timestamp", + datetime_undef_if_invalid => 1, + default_value => \"current_timestamp", + is_nullable => 0, + }, ); =head1 PRIMARY KEY @@ -140,8 +156,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-03-08 08:09:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KRaaWslsavWVmDbZF/NwcQ +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-03-08 09:59:00 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7N/mHMqyPJJsYaA8V968wQ sub koha_object_class { 'Koha::AdditionalContentsLocalization'; diff --git a/installer/data/mysql/atomicupdate/bug_31383.pl b/installer/data/mysql/atomicupdate/bug_31383.pl index 2bda07cb88..3a3d7584f5 100755 --- a/installer/data/mysql/atomicupdate/bug_31383.pl +++ b/installer/data/mysql/atomicupdate/bug_31383.pl @@ -20,6 +20,7 @@ return { `title` varchar(250) NOT NULL DEFAULT '' COMMENT 'title of the additional content', `content` mediumtext NOT NULL COMMENT 'the body of your additional content', `lang` varchar(50) NOT NULL DEFAULT '' COMMENT 'lang', + `updated_on` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'last modification', PRIMARY KEY (`id`), UNIQUE KEY `additional_contents_localizations_uniq` (`additional_content_id`,`lang`), CONSTRAINT `additional_contents_localizations_ibfk1` FOREIGN KEY (`additional_content_id`) REFERENCES `additional_contents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE @@ -29,19 +30,19 @@ return { my $contents = $dbh->selectall_arrayref(q{SELECT MIN(id) AS id, category, code, branchcode FROM additional_contents GROUP BY category, code, branchcode}, { Slice => {} }); my $sth_insert = $dbh->prepare(q{ - INSERT INTO additional_contents_localizations(additional_content_id, title, content, lang) - VALUES(?, ?, ?, ?) + INSERT INTO additional_contents_localizations(additional_content_id, title, content, lang, updated_on) + VALUES(?, ?, ?, ?, ?) }); for my $content ( @$contents ) { my $q = q{ - SELECT title, content, lang, branchcode + SELECT title, content, lang, branchcode, updated_on FROM additional_contents WHERE category=? AND code=? AND }; $q .= defined $content->{branchcode} ? " branchcode = ?" : " branchcode IS NULL"; my $translated_contents = $dbh->selectall_arrayref($q, { Slice => {} }, $content->{category}, $content->{code}, defined $content->{branchcode} ? $content->{branchcode} : ()); for my $translated_content ( @$translated_contents ) { - $sth_insert->execute($content->{id}, $translated_content->{title}, $translated_content->{content}, $translated_content->{lang}); + $sth_insert->execute($content->{id}, $translated_content->{title}, $translated_content->{content}, $translated_content->{lang}, $translated_content->{updated_on}); } } $dbh->do(q{ diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3e37e15b35..30766f38f7 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -217,6 +217,7 @@ CREATE TABLE `additional_contents_localizations` ( `title` varchar(250) NOT NULL DEFAULT '' COMMENT 'title of the additional content', `content` mediumtext NOT NULL COMMENT 'the body of your additional content', `lang` varchar(50) NOT NULL DEFAULT '' COMMENT 'lang', + `updated_on` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'last modification', PRIMARY KEY (`id`), UNIQUE KEY `additional_contents_localizations_uniq` (`additional_content_id`,`lang`), CONSTRAINT `additional_contents_localizations_ibfk1` FOREIGN KEY (`additional_content_id`) REFERENCES `additional_contents` (`id`) ON DELETE CASCADE ON UPDATE CASCADE diff --git a/tools/additional-contents.pl b/tools/additional-contents.pl index 75c32ca9c3..988089025f 100755 --- a/tools/additional-contents.pl +++ b/tools/additional-contents.pl @@ -135,23 +135,26 @@ elsif ( $op eq 'add_validate' ) { next unless $title || $content; push @seen_ids, $id; - push @translated_contents, - { + my $translated_content = { title => $title, content => $content, lang => $lang, - }; + }; - if ( C4::Context->preference("NewsLog") ) { - my $existing_content = $existing_contents->find($id); - if ( $existing_content ) { - if ( $existing_content->title ne $title || $existing_content->content ne $content ) { + my $existing_content = $existing_contents->find($id); + if ( $existing_content ) { + if ( $existing_content->title ne $title || $existing_content->content ne $content ) { + if ( C4::Context->preference("NewsLog") ) { logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)); } } else { - logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)) + $translated_content->{updated_on} = $existing_content->updated_on; } + } elsif( C4::Context->preference("NewsLog") ) { + logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content)) } + + push @translated_contents, $translated_content; } if ( C4::Context->preference("NewsLog") ) { -- 2.39.5