diff --git a/code/web/Drivers/Koha.php b/code/web/Drivers/Koha.php index 6886add4ec..18e97a2a02 100644 --- a/code/web/Drivers/Koha.php +++ b/code/web/Drivers/Koha.php @@ -46,6 +46,7 @@ function updateHomeLibrary(User $patron, string $homeLibraryCode) { $curRow = $results->fetch_assoc(); $address = $curRow['address']; $city = $curRow['city']; + $results->close(); } $postVariables = [ @@ -142,6 +143,7 @@ function updatePatronInfo($patron, $canUpdateContactInfo, $fromMasquerade = fals $city = $curRow['city']; $lastname = $curRow['surname']; } + $results->close(); } $postVariables = [ @@ -437,7 +439,6 @@ public function getCheckouts(User $patron): array { if ($renewPrefRow = $renewPrefResults->fetch_assoc()) { $renewPref = $renewPrefRow['autorenew_checkouts']; } - $renewPrefResults->close(); } $timer->logTime("Loaded borrower preference for autorenew_checkouts"); @@ -455,7 +456,6 @@ public function getCheckouts(User $patron): array { $patronIsExpired = true; } } - $patronExpirationResults->close(); } $timer->logTime("Loaded patron expiration date"); @@ -714,6 +714,7 @@ public function getCheckouts(User $patron): array { $checkouts[$curCheckout->source . $curCheckout->sourceId . $curCheckout->userId] = $curCheckout; } + $results->close(); //Check to see if any checkouts are Claims Returned $allIssueIdsAsString = implode(',', $allIssueIds); @@ -902,9 +903,11 @@ public function patronLogin($username, $password, $validatedViaSSO) { $patronId = $lookupUserRow['borrowernumber']; $newUser = $this->loadPatronInfoFromDB($patronId, null, $barcode); if (!empty($newUser) && !($newUser instanceof AspenError)) { + $lookupUserResult->close(); return $newUser; } } + $lookupUserResult->close(); } else if ($this->getKohaVersion() >= 22.1110) { //Authenticate the user using KOHA API $oauthToken = $this->getOAuthToken(); @@ -949,9 +952,11 @@ public function patronLogin($username, $password, $validatedViaSSO) { $expiredPasswordResult = $this->processExpiredPassword($lookupUserRow['borrowernumber'], $barcode); if ($expiredPasswordResult != null) { + $lookupUserResult->close(); return $expiredPasswordResult; } } + $lookupUserResult->close(); } $result['messages'][] = translate([ 'text' => 'Unable to authenticate with the ILS. Please try again later or contact the library.', @@ -1020,6 +1025,7 @@ public function patronLogin($username, $password, $validatedViaSSO) { if ($lookupUserResult->num_rows > 0) { $userExistsInDB = true; $lookupUserRow = $lookupUserResult->fetch_assoc(); + $lookupUserResult->close(); if (UserAccount::isUserMasquerading()) { $patronId = $lookupUserRow['borrowernumber']; $newUser = $this->loadPatronInfoFromDB($patronId, null, $barcode); @@ -1040,6 +1046,8 @@ public function patronLogin($username, $password, $validatedViaSSO) { return new AspenError('Maximum number of failed login attempts reached, your account has been locked.'); } } + } else { + $lookupUserResult->close(); } } } else { @@ -1092,6 +1100,7 @@ public function processExpiredPassword($borrowernumber, $barcode) : ?ExpiredPass } } } + $passwordExpirationResult->close(); } catch (Exception $e) { //This happens if password expiration is not enabled } @@ -1214,6 +1223,7 @@ private function loadPatronInfoFromDB($patronId, $password, $suppliedUsernameOrB global $logger; $logger->log("Could not get information about patron category", Logger::LOG_ERROR); } + $patronCategoryResult->close(); } else { global $logger; $logger->log("Could not get information about patron category", Logger::LOG_ERROR); @@ -1329,6 +1339,7 @@ private function loadPatronInfoFromDB($patronId, $password, $suppliedUsernameOrB return $user; } + return $userExistsInDB; } @@ -1439,6 +1450,7 @@ public function doReadingHistoryAction(User $patron, string $action, array $sele $address = $curRow['address']; $city = $curRow['city']; } + $results->close(); } else { //We could not connect to the database, don't update, so we don't corrupt the DB global $logger; @@ -1607,6 +1619,8 @@ public function getReadingHistory($patron, $page = 1, $recordsPerPage = -1, $sor } $readingHistoryTitles[] = $curTitle; } + + $readingHistoryTitleRS->close(); } } @@ -2533,7 +2547,7 @@ public function getHolds($patron, $page = 1, $recordsPerPage = -1, $sortOption = $holds['available'][$curHold->source . $curHold->cancelId . $curHold->userId] = $curHold; } } - + $results->close(); //Load additional ILL Requests that are not shipped $oauthToken = $this->getOAuthToken(); @@ -2974,7 +2988,6 @@ public function renewCheckout($patron, $recordId, $itemId = null, $itemIndex = n $renewSql = "SELECT issues.*, items.biblionumber, items.itype, items.itemcallnumber, items.enumchron, title, author, issues.renewals from issues left join items on items.itemnumber = issues.itemnumber left join biblio ON items.biblionumber = biblio.biblionumber where borrowernumber = '" . mysqli_escape_string($this->dbConnection, $patron->unique_ils_id) . "' AND issues.itemnumber = $itemId limit 1"; } - $renewResults = mysqli_query($this->dbConnection, $renewSql); $maxRenewals = 0; $params = [ @@ -2990,15 +3003,16 @@ public function renewCheckout($patron, $recordId, $itemId = null, $itemIndex = n //Parse the result if (isset($renewResponse->success) && ($renewResponse->success == 1)) { + $renewResults = mysqli_query($this->dbConnection, $renewSql); while ($curRow = mysqli_fetch_assoc($renewResults)) { $patronType = $patron->patronType; $itemType = $curRow['itype']; $checkoutBranch = $curRow['branchcode']; if ($this->getKohaVersion() >= 22.11) { - $renewCount = $curRow['renewals_count'] + 1; + $renewCount = $curRow['renewals_count']; } else { - $renewCount = $curRow['renewals'] + 1; + $renewCount = $curRow['renewals']; } /** @noinspection SqlResolve */ $issuingRulesSql = "SELECT * FROM circulation_rules where rule_name = 'renewalsallowed' AND (categorycode IN ('$patronType', '*') OR categorycode IS NULL) and (itemtype IN('$itemType', '*') OR itemtype is null) and (branchcode IN ('$checkoutBranch', '*') OR branchcode IS NULL) order by branchcode desc, categorycode desc, itemtype desc limit 1"; @@ -3010,6 +3024,7 @@ public function renewCheckout($patron, $recordId, $itemId = null, $itemIndex = n $issuingRulesRS->close(); } } + $renewResults->close(); $renewsRemaining = ($maxRenewals - $renewCount); @@ -3731,6 +3746,7 @@ function getSelfRegistrationFields($type = 'selfReg') { while ($curRow = $results->fetch_assoc()) { $kohaPreferences[$curRow['variable']] = $curRow['value']; } + $results->close(); if ($type == 'selfReg') { $unwantedFields = explode('|', $kohaPreferences['PatronSelfRegistrationBorrowerUnwantedField']); @@ -4850,6 +4866,7 @@ function getNewMaterialsRequestForm(User $user) { while ($curRow = $results->fetch_assoc()) { $kohaPreferences[$curRow['variable']] = $curRow['value']; } + $results->close(); if (isset($kohaPreferences['OPACSuggestionMandatoryFields'])) { $mandatoryFields = array_flip(explode('|', $kohaPreferences['OPACSuggestionMandatoryFields'])); @@ -5182,6 +5199,7 @@ function getNumMaterialsRequests(User $user) { if ($curRow = $results->fetch_assoc()) { $numRequests = $curRow['numRequests']; } + $results->close(); return $numRequests; } @@ -5306,6 +5324,7 @@ function getMaterialsRequests(User $user) { } $allRequests[] = $request; } + $results->close(); return $allRequests; } @@ -5411,6 +5430,7 @@ function getPatronUpdateForm($user) { } } } + $results->close(); //Set default values for extended patron attributes if ($this->getKohaVersion() > 21.05) { @@ -5724,6 +5744,7 @@ function importListsFromIls($patron) { } $results['totalLists']++; } + $listResults->close(); return $results; } @@ -5922,6 +5943,7 @@ public function findNewUser($patronBarcode, $patronUsername) { return $newUser; } } + $lookupUserResult->close(); }else{ //search by username /** @noinspection SqlResolve */ @@ -5936,6 +5958,7 @@ public function findNewUser($patronBarcode, $patronUsername) { return $newUser; } } + $lookupUserResult->close(); } return false; @@ -5960,6 +5983,7 @@ public function findNewUserByEmail($patronEmail): mixed { } else if ($lookupUserResult->num_rows > 1) { return 'Found more than one user.'; } + $lookupUserResult->close(); return false; } @@ -5974,18 +5998,21 @@ public function findUserByField($field, $value) { $sql = "SELECT borrowernumber, cardnumber, " . mysqli_escape_string($this->dbConnection, $field) . " from borrowers where " . mysqli_escape_string($this->dbConnection, $field) . " = '" . mysqli_escape_string($this->dbConnection, $value) . "'"; $lookupUserResult = mysqli_query($this->dbConnection, $sql); + $return_value = false; if ($lookupUserResult->num_rows == 1) { $lookupUserRow = $lookupUserResult->fetch_assoc(); $patronId = $lookupUserRow['borrowernumber']; $newUser = $this->loadPatronInfoFromDB($patronId, null, $lookupUserRow['cardnumber']); if (!empty($newUser) && !($newUser instanceof AspenError)) { - return $newUser; + $return_value = $newUser; } } else if ($lookupUserResult->num_rows > 1) { - return 'Found more than one user.'; + $return_value = 'Found more than one user.'; } - return false; + $lookupUserResult->close(); + + return $return_value; } /** @@ -6002,6 +6029,7 @@ public function showMessagingSettings(): bool { $allowed = false; } } + $preferenceRS->close(); return $allowed; } @@ -6035,6 +6063,7 @@ public function getMessagingSettingsTemplate(User $patron): ?string { $enablePhoneMessaging |= !empty($systemPreference['value']); } } + $systemPreferencesRS->close(); $interface->assign('enablePhoneMessaging', $enablePhoneMessaging); /** @noinspection SqlResolve */ @@ -6044,6 +6073,7 @@ public function getMessagingSettingsTemplate(User $patron): ?string { $interface->assign('smsAlertNumber', $borrowerRow['smsalertnumber']); $interface->assign('smsProviderId', $borrowerRow['sms_provider_id']); } + $borrowerRS->close(); //Lookup which transports are allowed /** @noinspection SqlResolve */ @@ -6062,6 +6092,7 @@ public function getMessagingSettingsTemplate(User $patron): ?string { } $messagingSettings[$transportId]['allowableTransports'][$transportSetting['message_transport_type']] = $transportSetting['message_transport_type']; } + $transportSettingRS->close(); //Get the list of notices to display information for /** @noinspection SqlResolve */ @@ -6105,6 +6136,7 @@ public function getMessagingSettingsTemplate(User $patron): ?string { } $messageAttributes[] = $messageType; } + $messageAttributesRS->close(); $interface->assign('messageAttributes', $messageAttributes); //Get messaging settings for the user @@ -6130,6 +6162,7 @@ public function getMessagingSettingsTemplate(User $patron): ?string { $messagingSettings[$messageType]['selectedTransports'][$userMessagingSetting['message_transport_type']] = $userMessagingSetting['message_transport_type']; } } + $userMessagingSettingsRS->close(); $interface->assign('messagingSettings', $messagingSettings); $validNoticeDays = []; @@ -6159,6 +6192,7 @@ public function getMessagingSettingsTemplate(User $patron): ?string { } else { $noticeLanguages[$language] = $language; } + $languageRS->close(); } /** @noinspection SqlResolve */ $borrowerLanguageSql = "SELECT lang FROM borrowers where borrowernumber = '" . mysqli_escape_string($this->dbConnection, $patron->unique_ils_id) . "'"; @@ -6166,8 +6200,9 @@ public function getMessagingSettingsTemplate(User $patron): ?string { if ($borrowerLanguageRow = $borrowerLanguageRS->fetch_assoc()) { $preferredNoticeLanguage = $borrowerLanguageRow['lang']; } - + $borrowerLanguageRS->close(); } + $interface->assign('canTranslateNotices', $canTranslateNotices); $interface->assign('noticeLanguages', $noticeLanguages); $interface->assign('preferredNoticeLanguage', $preferredNoticeLanguage); @@ -6573,6 +6608,7 @@ public function getShowAutoRenewSwitch(User $patron) { while ($curRow = $results->fetch_assoc()) { $showAutoRenew = $curRow['value']; } + $results->close(); return $showAutoRenew; } @@ -6588,6 +6624,7 @@ public function isAutoRenewalEnabledForUser(User $patron) { $autoRenewEnabled = $curRow['autorenew_checkouts']; break; } + $results->close(); } return $autoRenewEnabled; } @@ -6610,6 +6647,7 @@ public function updateAutoRenewal(User $patron, bool $allowAutoRenewal) { $address = $curRow['address']; $city = $curRow['city']; } + $results->close(); } $postVariables = [ @@ -6692,6 +6730,7 @@ function getPasswordRecoveryTemplate() { $uniqueKeyValid = true; } } + $lookupResult->close(); if (!$uniqueKeyValid) { $error = translate([ 'text' => 'The link you clicked is either invalid, or expired.
Be sure you used the link from the email, or contact library staff for assistance.
Please contact the library if you need further assistance.', @@ -6733,6 +6772,8 @@ function processPasswordRecovery() { $uniqueKeyValid = true; } } + $lookupResult->close(); + if (!$uniqueKeyValid) { $error = translate([ 'text' => 'The link you clicked is either invalid, or expired.
Be sure you used the link from the email, or contact library staff for assistance.
Please contact the library if you need further assistance.', @@ -6846,6 +6887,8 @@ function setExtendedAttributes() { $extendedAttributes[] = $attribute; } + $borrowerAttributeTypesRS->close(); + return $extendedAttributes; } @@ -7033,6 +7076,7 @@ public function getEditableUsername(User $user) { if ($curRow = $results->fetch_assoc()) { return $curRow['userId']; } + $results->close(); } return null; } @@ -7054,6 +7098,7 @@ public function updateEditableUsername(User $patron, string $username): array { 'message' => 'Sorry, that username is not available.', ]; } + $results->close(); } //Load required fields from Koha here to make sure we don't wipe them out /** @noinspection SqlResolve */ @@ -7066,6 +7111,7 @@ public function updateEditableUsername(User $patron, string $username): array { $address = $curRow['address']; $city = $curRow['city']; } + $results->close(); } $postVariables = [ @@ -7148,6 +7194,7 @@ public function getILSMessages(User $user) { 'messageStyle' => 'info', ]; } + $results->close(); } } @@ -7191,6 +7238,7 @@ public function getILSMessages(User $user) { ]; } } + $results->close(); } return $messages; @@ -7429,6 +7477,7 @@ public function getCurbsidePickupSettings($locationCode) { } } } + $results->close(); } } else { @@ -7685,6 +7734,7 @@ function validateUniqueId(User $user) { $lookupUserResult = mysqli_query($this->dbConnection, $sql); if ($lookupUserResult->num_rows > 0) { $lookupUserRow = $lookupUserResult->fetch_assoc(); + $lookupUserResult->close(); if ($lookupUserRow['borrowernumber'] != $user->unique_ils_id) { global $logger; $logger->log("Updating unique id for user from $user->unique_ils_id to {$lookupUserRow['borrowernumber']}", Logger::LOG_WARNING); @@ -7917,7 +7967,9 @@ public function lookupAccountByEmail(string $email) : array { 'name' => trim(trim($curRow['firstname'] . ' ' . $curRow['middle_name']) . ' ' . $curRow['surname']), ]; } + $results->close(); } + if (count($cardNumbers) == 0) { return [ 'success' => false, @@ -7952,6 +8004,7 @@ public function lookupAccountByPhoneNumber(string $phone) : array { 'patronId' => $curRow['borrowernumber'] ]; } + $results->close(); } if (count($cardNumbers) == 0) { return [ @@ -7982,6 +8035,7 @@ public function getBasicRegistrationForm() : array { while ($curRow = $results->fetch_assoc()) { $kohaPreferences[$curRow['variable']] = $curRow['value']; } + $results->close(); $unwantedFields = explode('|', $kohaPreferences['PatronSelfRegistrationBorrowerUnwantedField']); $requiredFields = explode('|', $kohaPreferences['PatronSelfRegistrationBorrowerMandatoryField']); @@ -8190,6 +8244,8 @@ public function bypassReadingHistoryUpdate($patron, $isNightlyUpdate) : bool { $expirationDate = strtotime($curRow['dateexpiry']); } } + + $results->close(); } //Don't update reading history if we've never seen the patron or the patron was last seen before we last updated reading history @@ -8388,6 +8444,8 @@ public function checkoutByAPI(User $patron, $barcode, Location $currentLocation) 'isPublicFacing' => true, ]); } + + $lookupItemResult->close(); } return $result; @@ -8419,6 +8477,7 @@ public function getMessageTypes(): array { $transports[$curRow['module']][$i]['name'] = $curRow['name']; $i++; } + $results->close(); } return $transports; @@ -8478,6 +8537,8 @@ public function updateMessageQueue(): array { } } + $results->close(); + return [ 'success' => true, 'message' => 'Added ' . $numAdded . ' to message queue' @@ -8537,6 +8598,8 @@ public function updateUserMessageQueue(User $patron): array { } + $results->close(); + return [ 'success' => true, 'message' => 'Updated user message queue' @@ -8569,4 +8632,4 @@ protected function getUserMessageTranslation($code, User $patron): array { return $result; } -} \ No newline at end of file +} diff --git a/code/web/release_notes/24.09.00.MD b/code/web/release_notes/24.09.00.MD index 525044bf65..70664c0fb6 100644 --- a/code/web/release_notes/24.09.00.MD +++ b/code/web/release_notes/24.09.00.MD @@ -142,6 +142,7 @@ - Remove superfluous loop in Koha driver function updateHomeLibrary #1968 (*KMH*) - Hide empty item groups for volume-level holds in Koha (*KMH*) - Remove old pre-production Koha volumes code (*KMH*) +- Properly close the connections to Koha from Aspen (*KMH*) - Fix query to select circulation rules for Koha (*KMH*) ### GitHub Actions