Bug 28207: Fix biblio_framework.frameworktext isn't in GROUP BY
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 26 Apr 2021 08:49:12 +0000 (10:49 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 30 Apr 2021 15:07:32 +0000 (17:07 +0200)
When a new framework is created and "Marc structure" is opened, a SQL
error happened if sql_strict_mode is on.

Test plan:
Create a 2 new biblio frameworks
Click "Marc structure" for one of them
=> You see the list of all frameworks with an existing structure

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
admin/marctagstructure.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt

index cc47c60..634ea5e 100755 (executable)
@@ -187,18 +187,16 @@ if ($op eq 'add_form') {
 ################## ITEMTYPE_CREATE ##################################
 # called automatically if an unexisting  frameworkis selected
 } elsif ($op eq 'framework_create') {
-       $sth = $dbh->prepare("select count(*),marc_tag_structure.frameworkcode,frameworktext from marc_tag_structure,biblio_framework where biblio_framework.frameworkcode=marc_tag_structure.frameworkcode group by marc_tag_structure.frameworkcode");
-       $sth->execute;
-       my @existingframeworkloop;
-       while (my ($tot,$thisframeworkcode,$frameworktext) = $sth->fetchrow) {
-               if ($tot>0) {
-                       push @existingframeworkloop, {
-                value => $thisframeworkcode,
-                frameworktext => $frameworktext,
-            };
-               }
-       }
-    $template->param( existingframeworkloop => \@existingframeworkloop );
+    my $frameworks = Koha::BiblioFrameworks->search(
+        {
+            'marc_tag_structure.frameworkcode' => { '!=' => undef }
+        },
+        {
+            join => 'marc_tag_structure',
+            distinct => 1
+        }
+    );
+    $template->param( existing_frameworks => $frameworks );
 
 ################## DEFAULT ##################################
 } else { # DEFAULT
index 2898385..88b58d9 100644 (file)
@@ -217,8 +217,8 @@ MARC frameworks &rsaquo; Administration &rsaquo; Koha
         Create framework for [% framework.frameworkcode | html %] ([% framework.frameworktext | html %]) using
         <select name="existingframeworkcode">
             <option value="">Default</option>
-        [% FOREACH existingframeworkloo IN existingframeworkloop %]
-            <option value="[% existingframeworkloo.value | html %]">[% existingframeworkloo.frameworktext | html %]</option>
+        [% FOREACH fw IN existing_frameworks%]
+            <option value="[% fw.frameworkcode | html %]">[% fw.frameworktext | html %]</option>
         [% END %]
         </select>
         <input type="submit" value="OK" />