From bab53e12f6b0531e7890b87283e14822f59b7be1 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 19 Feb 2025 15:00:57 -0300 Subject: [PATCH] DIS-397 Add logging to INN-Reach results fetch method This patch adds * logging of the external request made to INN-Reach, through `ExternalRequestLogEntry::logRequest` * a check for the HTTP response status code, and if it is not 200, an error log will be generated Test plan: 1. Enable the INN-Reach integration 2. Have random credentials for the OAuth2 section 3. Perform a search 4. Make sure your IP gets external requests logged => An error log should be generated => There's a log on the external requests logs Signed-off-by: Tomas Cohen Arazi --- code/web/release_notes/25.03.00.MD | 2 ++ code/web/sys/InterLibraryLoan/InnReach.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/code/web/release_notes/25.03.00.MD b/code/web/release_notes/25.03.00.MD index d3545bf820..6f6fd72c2d 100644 --- a/code/web/release_notes/25.03.00.MD +++ b/code/web/release_notes/25.03.00.MD @@ -36,6 +36,7 @@ ### Other Updates - Remove unused AspenLiDASettings class. (DIS-393) (*MDN*) - Added check to make sure `$catalog` is not null before calling `hasIlsConsentSupport()` in `Library.php`. (DIS-394) (*LS*) +- Add logging to INN-Reach contents fetching (DIS-397) (*TC*) // kirstien @@ -81,6 +82,7 @@ ### Theke Solutions - Lucas Montoya (LM) + - Tomás Cohen Arazi (TC) ## Special Testing thanks to - Myranda Fuentes (Grove) diff --git a/code/web/sys/InterLibraryLoan/InnReach.php b/code/web/sys/InterLibraryLoan/InnReach.php index 48bcdffeb0..39af97b874 100644 --- a/code/web/sys/InterLibraryLoan/InnReach.php +++ b/code/web/sys/InterLibraryLoan/InnReach.php @@ -4,16 +4,24 @@ */ require_once ROOT_DIR . '/sys/CurlWrapper.php'; +require_once ROOT_DIR . '/sys/SystemLogging/ExternalRequestLogEntry.php'; class InnReach { /** * Load search results from INN-Reach using the encore interface. **/ function getTopSearchResults($searchTerms, $maxResults) { + global $logger; $innReachUrl = $this->getSearchLink($searchTerms); //Load the HTML from INN-Reach $req = new CurlWrapper(); $innReachInfo = $req->curlGetPage($innReachUrl); + $responseCode = $req->getResponseCode(); + //Logging + ExternalRequestLogEntry::logRequest('innreach.getTopSearchResults', 'GET', $innReachUrl, $req->getHeaders(), '', $responseCode, $innReachInfo, []); + if ($responseCode != 200) { + $logger->log('Unable to search for titles on INN-Reach. Response code was ' . $responseCode, Logger::LOG_ERROR); + } //Get the total number of results if (preg_match('/.*?(\d+) - (\d+) of (\d+).*?<\/span>/s', $innReachInfo, $summaryInfo)) {