From 161db94bf2e5d318d3f975032e05f80eda8508a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Tue, 3 Dec 2024 18:27:32 +0000 Subject: [PATCH 1/9] fix: remove unecessary module It was established that there is no need for the LibKey integration to be a module. This removes the SQL that would have added it to the modules table in the Aspen database. --- code/web/sys/DBMaintenance/version_updates/24.12.00.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/code/web/sys/DBMaintenance/version_updates/24.12.00.php b/code/web/sys/DBMaintenance/version_updates/24.12.00.php index 394fc09765..0605973037 100644 --- a/code/web/sys/DBMaintenance/version_updates/24.12.00.php +++ b/code/web/sys/DBMaintenance/version_updates/24.12.00.php @@ -80,13 +80,6 @@ function getUpdates24_12_00(): array { //alexander - PTFS-Europe //chloe - PTFS-Europe - 'create_libkey_module' => [ - 'title' => 'Create LibKey Module', - 'description' => 'Add LibKey to the list of modules', - 'sql' => [ - "INSERT INTO modules (name) VALUES ('LibKey')", - ], - ], // create_libkey_module 'create_libkey_permissions' => [ 'title' => 'Create LibKey Permissions', 'description' => 'Add an LibKey permission section containing the Administer LibKey Settings permission', From 64e4a9c57028cb9f94fb93edcc28c261ce5c7d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Tue, 3 Dec 2024 18:29:10 +0000 Subject: [PATCH 2/9] fix: remove duplicated lines These were likely involuntarily duplicated during a merge conflict resolution. Remove the redundant lines. --- code/web/sys/Account/User.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/code/web/sys/Account/User.php b/code/web/sys/Account/User.php index 7193d55056..f1ad179911 100644 --- a/code/web/sys/Account/User.php +++ b/code/web/sys/Account/User.php @@ -3872,10 +3872,6 @@ public function getAdminActions() { 'Administer All System Messages', 'Administer Library System Messages', ]); - $sections['local_enrichment']->addAction(new AdminAction('System Messages', 'System Messages allow you to display messages to your patrons in specific locations.', '/Admin/SystemMessages'), [ - 'Administer All System Messages', - 'Administer Library System Messages', - ]); $sections['third_party_enrichment'] = new AdminSection('Third Party Enrichment'); $sections['third_party_enrichment']->addAction(new AdminAction('Accelerated Reader Settings', 'Define settings to load Accelerated Reader information directly from Renaissance Learning.', '/Enrichment/ARSettings'), 'Administer Third Party Enrichment API Keys'); From df58ae1ae0a69d899cb1c970b85789632a3ab8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Tue, 3 Dec 2024 18:31:05 +0000 Subject: [PATCH 3/9] fix: do not proceed if no setting found Removes an unecessary fetch() call as find(true) already executes a fetch(), and changes the control flow so that getLibKeyLink() returns null early if no setting is found (only move on to creating an instance of CurlWrapper if the setting was found). --- code/web/Drivers/LibKeyDriver.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/web/Drivers/LibKeyDriver.php b/code/web/Drivers/LibKeyDriver.php index aa70bf4279..16d2439aee 100644 --- a/code/web/Drivers/LibKeyDriver.php +++ b/code/web/Drivers/LibKeyDriver.php @@ -1,14 +1,13 @@ whereAdd("id=$activeLibrary->libKeySettingId"); - if ($settings->find(true)) { - $settings->fetch(); + if (!$settings->find(true)) { + return null; } $curlWrapper = new CurlWrapper; $response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $this->extractDoi($doiUrl) . "?access_token=" . $settings->apiKey); From 27ebf39091a5f9cf1d848c1518ba8a85089b7ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Tue, 3 Dec 2024 18:34:40 +0000 Subject: [PATCH 4/9] feat: check for libKey setting Only ever use the LibKey integration if a LibKey setting is associated with the active library. This aims to ensure that the LibKey integration code only runs if LibKey has been set up for the relevant library. --- code/web/RecordDrivers/MarcRecordDriver.php | 25 +++++++++------------ code/web/services/Record/AJAX.php | 21 +++++++++++------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/code/web/RecordDrivers/MarcRecordDriver.php b/code/web/RecordDrivers/MarcRecordDriver.php index a76c638bba..def88aab4a 100644 --- a/code/web/RecordDrivers/MarcRecordDriver.php +++ b/code/web/RecordDrivers/MarcRecordDriver.php @@ -1314,14 +1314,7 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a $i = 0; if (count($relatedUrls) > 1) { //We will show a popup to let people choose the URL they want - foreach($relatedUrls as $relatedUrl) { - $libKeyLink = $this->getLibKeyUrl($relatedUrl['url']); - if (!empty($libKeyLink)) { - $libKeyRelatedUrl = $relatedUrl; - $libKeyrelatedUrl['url'] = $libKeyLink; - $relatedUrls[] = $libKeyRelatedUrl; - } - } + $title = translate([ 'text' => 'Access Online', 'isPublicFacing' => true, @@ -1335,17 +1328,17 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a 'id' => "accessOnline_{$this->getId()}", 'target' => '_blank', ]; - } elseif (count($relatedUrls) == 1) { + } elseif (count($relatedUrls) == 1) { - $libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']); - if (!empty($libKeyLink)) { + if (Library::getActiveLibrary()->libKeySettingId != -1) { + $libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']); $title = translate([ 'text' => 'Access Online', 'isPublicFacing' => true, ]); $actions[] = [ 'title' => $title, - 'url' => $libKeyLink, + 'url' => $libKeyLink ? $libKeyLink : '', 'requireLogin' => false, 'type' => 'access_online', 'id' => "accessOnline_{$this->getId()}", @@ -1690,9 +1683,11 @@ public function getMoreDetailsOptions() { $interface->assign('periodicalIssues', $issues); } $links = $this->getLinks(); - $libKeyLink = $this->getLibKeyUrl($links[0]['url']); - if (!empty($libKeyLink)) { - $links[] = ['title' => $libKeyLink, 'url' => $libKeyLink]; + if (Library::getActiveLibrary()->libKeySettingId != -1) { + $libKeyLink = $this->getLibKeyUrl($links[0]['url']); + if (!empty($libKeyLink)) { + $links[] = ['title' => $libKeyLink, 'url' => $libKeyLink]; + } } $interface->assign('links', $links); $interface->assign('show856LinksAsTab', $library->getGroupedWorkDisplaySettings()->show856LinksAsTab); diff --git a/code/web/services/Record/AJAX.php b/code/web/services/Record/AJAX.php index 6fb67847ce..d4799d351f 100644 --- a/code/web/services/Record/AJAX.php +++ b/code/web/services/Record/AJAX.php @@ -1996,17 +1996,24 @@ function viewItem(): array { if ($item->itemId == $itemId) { $relatedUrls = $item->getRelatedUrls(); foreach ($relatedUrls as $relatedUrl) { - $libKeyLink = $this->getLibKeyUrl($relatedUrl['url']); - if (!empty($libKeyLink)) { - return [ - 'success' => true, - 'url' => $libKeyLink - ]; + if (Library::getActiveLibrary()->libKeySettingId != -1) { + $libKeyLink = $this->getLibKeyUrl($relatedUrl['url']); + if (!empty($libKeyLink)) { + return [ + 'success' => true, + 'url' => $libKeyLink + ]; + } else { + return [ + 'success' => true, + 'url' => $relatedUrl['url'] + ]; + } } else { return [ 'success' => true, 'url' => $relatedUrl['url'] - ]; + ]; } } } From 8575fa4f31dc28660a9ceb0344d1f4921ea480f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Tue, 3 Dec 2024 20:07:17 +0000 Subject: [PATCH 5/9] feat: check if a url contains a DOI --- code/web/Drivers/LibKeyDriver.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/web/Drivers/LibKeyDriver.php b/code/web/Drivers/LibKeyDriver.php index 16d2439aee..e4a0f4e888 100644 --- a/code/web/Drivers/LibKeyDriver.php +++ b/code/web/Drivers/LibKeyDriver.php @@ -2,6 +2,9 @@ class LibKeyDriver { public function getLibKeyLink(string $doiUrl): string | null { + if (!$this->containsDoi($doiUrl)) { + return null; + } require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php'; $activeLibrary = Library::getActiveLibrary(); $settings = new LibKeySetting(); @@ -20,4 +23,7 @@ public function extractDoi(string $url): string { $doi = str_replace(["https://doi.org/", "http://"], "", $url); return $doi; } + public function containsDoi(string $url): bool { + return preg_match('/10.\d{4,9}\/[-._;()\/:A-Z0-9]/', $url); + } } \ No newline at end of file From 064007aedf109877a3462755303ac35e76bd6545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Wed, 4 Dec 2024 09:48:11 +0000 Subject: [PATCH 6/9] fix: handle empty 856 u field --- code/web/RecordDrivers/MarcRecordDriver.php | 4 ++-- code/web/services/Record/AJAX.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/web/RecordDrivers/MarcRecordDriver.php b/code/web/RecordDrivers/MarcRecordDriver.php index def88aab4a..804cf939b3 100644 --- a/code/web/RecordDrivers/MarcRecordDriver.php +++ b/code/web/RecordDrivers/MarcRecordDriver.php @@ -1330,7 +1330,7 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a ]; } elseif (count($relatedUrls) == 1) { - if (Library::getActiveLibrary()->libKeySettingId != -1) { + if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($relatedUrls[0]['url'])) { $libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']); $title = translate([ 'text' => 'Access Online', @@ -1683,7 +1683,7 @@ public function getMoreDetailsOptions() { $interface->assign('periodicalIssues', $issues); } $links = $this->getLinks(); - if (Library::getActiveLibrary()->libKeySettingId != -1) { + if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($relatedUrls[0]['url'])) { $libKeyLink = $this->getLibKeyUrl($links[0]['url']); if (!empty($libKeyLink)) { $links[] = ['title' => $libKeyLink, 'url' => $libKeyLink]; diff --git a/code/web/services/Record/AJAX.php b/code/web/services/Record/AJAX.php index d4799d351f..09e4d40721 100644 --- a/code/web/services/Record/AJAX.php +++ b/code/web/services/Record/AJAX.php @@ -1996,7 +1996,7 @@ function viewItem(): array { if ($item->itemId == $itemId) { $relatedUrls = $item->getRelatedUrls(); foreach ($relatedUrls as $relatedUrl) { - if (Library::getActiveLibrary()->libKeySettingId != -1) { + if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($relatedUrl['url'])) { $libKeyLink = $this->getLibKeyUrl($relatedUrl['url']); if (!empty($libKeyLink)) { return [ From 45e09f0959cd99ae5bb83595b3d4e7dcf6fd7230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Wed, 4 Dec 2024 09:54:49 +0000 Subject: [PATCH 7/9] fix: handle lower case char in doi --- code/web/Drivers/LibKeyDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/web/Drivers/LibKeyDriver.php b/code/web/Drivers/LibKeyDriver.php index e4a0f4e888..cc2fa3563c 100644 --- a/code/web/Drivers/LibKeyDriver.php +++ b/code/web/Drivers/LibKeyDriver.php @@ -24,6 +24,6 @@ public function extractDoi(string $url): string { return $doi; } public function containsDoi(string $url): bool { - return preg_match('/10.\d{4,9}\/[-._;()\/:A-Z0-9]/', $url); + return preg_match('/10.\d{4,9}\/[-._;()\/:A-Za-z0-9]/', $url); } } \ No newline at end of file From c14764f37da2cf47db50daa06cce07bffd0d7c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Wed, 4 Dec 2024 09:58:21 +0000 Subject: [PATCH 8/9] fix: amend variable name --- code/web/RecordDrivers/MarcRecordDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/web/RecordDrivers/MarcRecordDriver.php b/code/web/RecordDrivers/MarcRecordDriver.php index 804cf939b3..ee20d2086b 100644 --- a/code/web/RecordDrivers/MarcRecordDriver.php +++ b/code/web/RecordDrivers/MarcRecordDriver.php @@ -1683,7 +1683,7 @@ public function getMoreDetailsOptions() { $interface->assign('periodicalIssues', $issues); } $links = $this->getLinks(); - if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($relatedUrls[0]['url'])) { + if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($links[0]['url'])) { $libKeyLink = $this->getLibKeyUrl($links[0]['url']); if (!empty($libKeyLink)) { $links[] = ['title' => $libKeyLink, 'url' => $libKeyLink]; From 22cc01d3a05bdbcef1759e69a2606ae40d7bf14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Wed, 4 Dec 2024 11:08:51 +0000 Subject: [PATCH 9/9] fix: default to related url If no LibKey link is found, use the related url instead. --- code/web/RecordDrivers/MarcRecordDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/web/RecordDrivers/MarcRecordDriver.php b/code/web/RecordDrivers/MarcRecordDriver.php index ee20d2086b..8b72c3981a 100644 --- a/code/web/RecordDrivers/MarcRecordDriver.php +++ b/code/web/RecordDrivers/MarcRecordDriver.php @@ -1328,7 +1328,7 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a 'id' => "accessOnline_{$this->getId()}", 'target' => '_blank', ]; - } elseif (count($relatedUrls) == 1) { + } elseif (count($relatedUrls) == 1) { if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($relatedUrls[0]['url'])) { $libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']); @@ -1338,7 +1338,7 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a ]); $actions[] = [ 'title' => $title, - 'url' => $libKeyLink ? $libKeyLink : '', + 'url' => $libKeyLink ? $libKeyLink : $relatedUrls[0]['url'], 'requireLogin' => false, 'type' => 'access_online', 'id' => "accessOnline_{$this->getId()}",