Bug 18837: Introduce delegation to backends for unmediated workflows
authorAndrew Isherwood <andrew.isherwood@ptfs-europe.com>
Thu, 26 Apr 2018 11:04:58 +0000 (12:04 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 15 Mar 2019 19:33:36 +0000 (19:33 +0000)
This patch adds support to Illrequest.pm to allow delegation of
unmediated requests to happen in backends that support them.

It is a recreation of
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=66629&action=diff
which had diverged sufficiently as to make it impossible to apply

Signed-off-by: Stephen Graham <s.graham4@herts.ac.uk>
Signed-off-by: David Peacock <d.m.peacock@herts.ac.uk>
Signed-off-by: Jayne Maisey <j.maisey@herts.ac.uk>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Illrequest.pm

index 7158aa5..19efa85 100644 (file)
@@ -352,12 +352,14 @@ capabilities & custom_capability and their callers.
 sub _backend_capability {
     my ( $self, $name, $args ) = @_;
     my $capability = 0;
+    # See if capability is defined in backend
     try {
         $capability = $self->_backend->capabilities($name);
     } catch {
         return 0;
     };
-    if ( $capability ) {
+    # Try to invoke it
+    if ( $capability && ref($capability) eq 'CODE' ) {
         return &{$capability}($args);
     } else {
         return 0;
@@ -819,6 +821,20 @@ sub backend_create {
     # ...Updating status!
     $self->status('QUEUED')->store unless ( $permitted );
 
+    ## Handle Unmediated ILLs
+
+    # For the unmediated workflow we only need to delegate to our backend. If
+    # that backend supports unmediateld_ill, it will do its thing and return a
+    # proper response.  If it doesn't then _backend_capability returns 0, so
+    # we keep the current result.
+    if ( C4::Context->preference("ILLModuleUnmediated") && $permitted ) {
+        my $unmediated_result = $self->_backend_capability(
+            'unmediated_ill',
+            $args
+        );
+        $result = $unmediated_result if $unmediated_result;
+    }
+
     return $self->expandTemplate($result);
 }