From f3da9dbfd21e97fb1c97867143c425c29e530374 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Tue, 12 Dec 2023 14:02:40 +0200 Subject: [PATCH] [FINNA-1206] MARC: Move ISSN field specs to a member variable. --- CHANGELOG.md | 2 +- src/RecordManager/Base/Record/Marc.php | 46 +++++++++++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc833b0..866e14c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Anything marked with [**BC**] is known to affect backward compatibility with pre ### Changed -- Format of $isbnFields definition array in Marc.php has been changed to include the type of ISBN field. It can be used to avoid reporting invalid ISBNs or extra content in combined fields in the `warnings_field` index field. +- Format of $isbnFields and $issnFields definition arrays in Marc.php have been changed to include the type of the field. It can be used to avoid reporting invalid e.g. ISBNs or extra content in combined fields in the `warnings_field` index field. ## 2.2.0 - 2023-11-13 diff --git a/src/RecordManager/Base/Record/Marc.php b/src/RecordManager/Base/Record/Marc.php index d0fe68ce..e0898887 100644 --- a/src/RecordManager/Base/Record/Marc.php +++ b/src/RecordManager/Base/Record/Marc.php @@ -143,6 +143,30 @@ class Marc extends AbstractRecord ], ]; + /** + * Field specs for ISSN fields + * + * 'type' can be 'normal', 'combined' or 'invalid'; it's not currently used but + * exists for future needs and compatibility with $isbnFields. + * + * @var array + */ + protected $issnFields = [ + [ + 'type' => 'normal', + 'selector' => [ + [MarcHandler::GET_NORMAL, '022', ['a']], + [MarcHandler::GET_NORMAL, '440', ['x']], + [MarcHandler::GET_NORMAL, '490', ['x']], + [MarcHandler::GET_NORMAL, '730', ['x']], + [MarcHandler::GET_NORMAL, '773', ['x']], + [MarcHandler::GET_NORMAL, '776', ['x']], + [MarcHandler::GET_NORMAL, '780', ['x']], + [MarcHandler::GET_NORMAL, '785', ['x']], + ], + ], + ]; + /** * MARC record creation callback * @@ -451,18 +475,16 @@ public function toSolrArray(Database $db = null) } } } - $data['issn'] = $this->getFieldsSubfields( - [ - [MarcHandler::GET_NORMAL, '022', ['a']], - [MarcHandler::GET_NORMAL, '440', ['x']], - [MarcHandler::GET_NORMAL, '490', ['x']], - [MarcHandler::GET_NORMAL, '730', ['x']], - [MarcHandler::GET_NORMAL, '773', ['x']], - [MarcHandler::GET_NORMAL, '776', ['x']], - [MarcHandler::GET_NORMAL, '780', ['x']], - [MarcHandler::GET_NORMAL, '785', ['x']], - ] - ); + + foreach ($this->issnFields as $fieldSpec) { + // phpcs:ignore + /** @psalm-suppress DuplicateArrayKey,InvalidOperand */ + $data['issn'] = [ + ...($data['issn'] ?? []), + ...$this->getFieldsSubfields($fieldSpec['selector']), + ]; + } + $data['doi_str_mv'] = $this->getDOIs(); $cn = $this->getFirstFieldSubfields(