[Koha-bugs] [Bug 29113] New "code" field for additional contents is not useful for the end users

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Nov 19 11:38:32 CET 2021


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29113

--- Comment #29 from Jonathan Druart <jonathan.druart+koha at gmail.com> ---
(In reply to Marcel de Rooy from comment #28)
> +                    code           => $code || 'tmp_code',
> 
> Please explain.
The code is mandatory at DB level so we must add a temporary code during the
insert, then update it after

I feel like it should actually be 'tmp_code' always, at this point we are
creating a new entry and $code should never be set.

We could add the following change

diff --git a/tools/additional-contents.pl b/tools/additional-contents.pl
index e63a44a809a..59721e24b2a 100755
--- a/tools/additional-contents.pl
+++ b/tools/additional-contents.pl
@@ -159,7 +159,7 @@ elsif ( $op eq 'add_validate' ) {
             my $additional_content = Koha::AdditionalContent->new(
                 {
                     category       => $category,
-                    code           => $code || 'tmp_code',
+                    code           => 'tmp_code',
                     location       => $location,
                     branchcode     => $branchcode,
                     title          => $title,
@@ -173,13 +173,11 @@ elsif ( $op eq 'add_validate' ) {
             )->store;
             eval {
                 $additional_content->store;
-                unless ($code) {
-                    $additional_content->discard_changes;
-                    $code = $category eq 'news'
-                      ? 'News_' . $additional_content->idnew
-                      : $location . '_' . $additional_content->idnew;
-                    $additional_content->code($code)->store;
-                }
+                $additional_content->discard_changes;
+                $code = $category eq 'news'
+                  ? 'News_' . $additional_content->idnew
+                  : $location . '_' . $additional_content->idnew;
+                $additional_content->code($code)->store;
             };
             if ($@) {
                 $success = 0;

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list