Skip to content
Snippets Groups Projects
Commit 31bbe3b7 authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

[VUFIND-1422] Fix a couple of prefix handling issues in the MultiBackend driver. (#1711)

parent 2ba2a631
No related merge requests found
......@@ -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);
......
......@@ -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);
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment