diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php index 9e028cdd0cd40a6eb9cdf934a2f8a5ae698f6634..9dd7e45b312df230cee53c71c87d0b3e4bd5dec7 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php +++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php @@ -936,7 +936,9 @@ class MultiBackend extends AbstractBase implements \Laminas\Log\LoggerAwareInter ); $driver = $this->getDriver($source); if ($driver) { - $holdDetails = $this->stripIdPrefixes($holdDetails, $source); + $holdDetails = $this->stripIdPrefixes( + $holdDetails, $source, ['id', 'item_id', 'cat_username'] + ); return $driver->getCancelHoldDetails($holdDetails); } throw new ILSException('No suitable backend driver found'); @@ -1552,7 +1554,7 @@ class MultiBackend extends AbstractBase implements \Laminas\Log\LoggerAwareInter $value, $source, $modifyFields ); } else { - if (!is_numeric($key) + if (!ctype_digit((string)$key) && $value !== '' && in_array($key, $modifyFields) ) { @@ -1593,7 +1595,8 @@ class MultiBackend extends AbstractBase implements \Laminas\Log\LoggerAwareInter ); } else { $prefixLen = strlen($source) + 1; - if ((!is_array($data) || in_array($key, $modifyFields)) + if ((!is_array($data) + || (!ctype_digit((string)$key) && in_array($key, $modifyFields))) && strncmp("$source.", $value, $prefixLen) == 0 ) { $array[$key] = substr($value, $prefixLen); diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php index 04c7d3117a325a036ca49316fca467f78aa327a4..3b2bebfaf79a8db03b859df8527acab9988d85ae 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php @@ -5,7 +5,7 @@ * PHP version 7 * * Copyright (C) Villanova University 2011. - * Copyright (C) The National Library of Finland 2014-2016. + * Copyright (C) The National Library of Finland 2014-2020. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -29,7 +29,6 @@ */ namespace VuFindTest\ILS\Driver; -use Laminas\Log\Writer\Mock; use VuFind\ILS\Driver\MultiBackend; /** @@ -281,6 +280,20 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase $driver, 'addIdPrefixes', [$data, $source, $modify] ); $this->assertEquals($expected, $result); + + // Numeric keys are not considered + $data = [ + 'id' => 'record1', + 'cat_username' => ['foo', 'bar'] + ]; + $expected = [ + 'id' => "$source.record1", + 'cat_username' => ['foo', 'bar'] + ]; + $result = $this->callMethod( + $driver, 'addIdPrefixes', [$data, $source, $modify] + ); + $this->assertEquals($expected, $result); } /** @@ -346,6 +359,20 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase $driver, 'stripIdPrefixes', [$data, $source, $modify] ); $this->assertEquals($expected, $result); + + // Numeric keys are not considered + $data = [ + 'id' => "$source.record1", + 'test' => ["$source.foo", "$source.bar"] + ]; + $expected = [ + 'id' => "record1", + 'test' => ["$source.foo", "$source.bar"] + ]; + $result = $this->callMethod( + $driver, 'stripIdPrefixes', [$data, $source] + ); + $this->assertEquals($expected, $result); } /**