Bug 14369: Only show 'Create labels' link on staged records import when status is...
authorKatrin Fischer <katrin.fischer.83@web.de>
Sun, 12 Apr 2020 22:06:05 +0000 (22:06 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 21 Apr 2020 11:28:56 +0000 (12:28 +0100)
The label creator won't be able to add a batch for items, if they are
not imported into the database (missing itemnumber). This patch hides
the link, when the status is not imported, to avoid the error situation.

To test:
- Export a record with items from your Koha installation
- Delete items and record from Koha
- Stage the record with the items - the "Create labels" link should be showing
- Try to create the labels - note error
- Apply patch
- Retry - the link should no longer show
- Import the records - the link should show now
- Create labels again - a new batch should have been created
- Verify the link on the batch # leads to the batch in the labels module

Bonus: Moves the message from the .pl file to the template to make
it translatable.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
tools/manage-marc-import.pl

index 0fde39f..a3edfdf 100644 (file)
                         [% ELSE %]
                             <div class="dialog message">
                         [% END %]
-                            <b><p>[% label_batch_msg | html %]</p></b>
+                            <p><b>
+                                [% IF ( label_batch_msg == "error" ) %]
+                                    Error attempting to create label batch. Please ask your system administrator to check the log for more details.
+                                [% ELSE %]
+                                    Label <a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=edit&element_id=[% label_batch_msg | uri %]" >batch #[% label_batch_msg | html %]</a> created.
+                                [% END %]
+                            </b></p>
                         </div>
                     [% END %]
 
                                     </td>
                                     <td>[% batch_lis.upload_timestamp | html %]</td>
                                     <td>[% batch_lis.num_records | html %]</td>
-                                    <td>[% batch_lis.num_items | html %][% IF ( batch_lis.num_items ) %] <a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]&amp;op=create_labels">(Create label batch)</a>[% END %]</td>
+                                    <td>[% batch_lis.num_items | html %]
+                                        [% IF ( batch_lis.num_items && batch_lis.import_status == 'imported' ) %]
+                                            (<a href="[% batch_lis.script_name | url %]?import_batch_id=[% batch_lis.import_batch_id | uri %]&amp;op=create_labels">Create label batch</a>)
+                                        [% END %]
+                                    </td>
                                     <td class="actions">
                                         [% IF ( batch_lis.can_clean ) %]
                                             <form method="post" action="[% batch_lis.script_name | html %]" name="clean_batch_[% batch_lis.import_batch_id | html %]" id="clean_batch_[% batch_lis.import_batch_id | html %]" class="batch_form batch_clean">
             [% END %]
         </ul>
     </nav>
-[% END %]
\ No newline at end of file
+[% END %]
index 4fea400..6f9405d 100755 (executable)
@@ -69,12 +69,12 @@ if ($op eq "create_labels") {
        #create a batch of labels, then lose $op & $import_batch_id so we get back to import batch list.
        my $label_batch_id = create_labelbatch_from_importbatch($import_batch_id);
         if ($label_batch_id == -1) {
-            $template->param(   label_batch_msg => "Error attempting to create label batch. Please ask your system administrator to check the log for more details.",
+            $template->param(   label_batch_msg => "error",
                                 message_type    => 'alert',
             );
         }
         else {
-            $template->param(   label_batch_msg => "Label batch #$label_batch_id created.",
+            $template->param(   label_batch_msg => $label_batch_id,
                                 message_type    => 'dialog',
             );
         }