Skip to content

Commit b371b94

Browse files
committed
DIS-239: refactor: update Aspen db on succcess
Since patron email are stored in the Aspen database, we should not treat them as transient data (which is what loadContactInfomation handles). This modifies how Aspen ensures that the updated email value is shown to the user: instead of reloading the data from Evergreen, we update its value in Aspen db on success, so that the new value can be fetched from Aspen db on page reload.
1 parent a1a24fe commit b371b94

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

code/web/Drivers/Evergreen.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -789,22 +789,28 @@ public function updatePatronInfo(User $patron, $canUpdateContactInfo, $fromMasqu
789789
$userMessages['messages'][] = 'Your contact information cannot be updated.';
790790
return $userMessages;
791791
}
792-
$propertyName = '';
793792

794793
if (!isset($_REQUEST['email'])) {
795794
return $userMessages;
796795
}
796+
797797
$propertyName = 'email';
798798
$propertyValue = $_REQUEST['email'];
799-
$response = $this->updatePatronProperty($propertyName, $propertyValue, $patron->ils_password, $authToken);
799+
$response = $this->updatePatronPropertyInEvergreen($propertyName, $propertyValue, $patron->ils_password, $authToken);
800+
801+
if($response['success']) {
802+
$patron->email = $propertyValue;
803+
$patron->update();
804+
}
805+
800806
$userMessages['messages'][] = $response['success'] ? 'Your email has been updated.' : 'Your email could not be updated. Please contact your library';
801807
$userMessages['success'] = $response['success'];
802808

803809
return $userMessages;
804810
}
805811

806-
private function updatePatronProperty($propertyName, $propertyValue, $patronIlsPassword, $authToken): array {
807-
$evergreenUrl = $this->accountProfile->patronApiUrl . "/osrf-gateway-v1/$propertyName";
812+
private function updatePatronPropertyInEvergreen(string $propertyEvergreenName, string $propertyValue, string $patronIlsPassword, string $authToken): array {
813+
$evergreenUrl = $this->accountProfile->patronApiUrl . "/osrf-gateway-v1/$propertyEvergreenName";
808814
$headers = [
809815
'Content-Type: application/x-www-form-urlencoded',
810816
];
@@ -815,13 +821,13 @@ private function updatePatronProperty($propertyName, $propertyValue, $patronIlsP
815821
* determines which is which
816822
*/
817823
$request = 'service=open-ils.actor';
818-
$request .= "&method=open-ils.actor.user.$propertyName.update";
824+
$request .= "&method=open-ils.actor.user.$propertyEvergreenName.update";
819825
$requestParams = '&param=' . json_encode($authToken);
820826
$requestParams .= '&param=' . json_encode($propertyValue);
821827
$requestParams .= '&param=' . json_encode($patronIlsPassword);
822828

823829
$apiResponse = $this->apiCurlWrapper->curlPostPage($evergreenUrl, $request . $requestParams);
824-
ExternalRequestLogEntry::logRequest('evergreen.updatePatronProperty', 'POST', $evergreenUrl, $this->apiCurlWrapper->getHeaders(), $request, $this->apiCurlWrapper->getResponseCode(), $apiResponse, []);
830+
ExternalRequestLogEntry::logRequest('evergreen.updatePatronPropertyInEvergreen', 'POST', $evergreenUrl, $this->apiCurlWrapper->getHeaders(), $request, $this->apiCurlWrapper->getResponseCode(), $apiResponse, []);
825831

826832
$responseData = json_decode($apiResponse, true);
827833
$response = ['success' => false, 'message' => ['code' => '', 'text' => 'Evergreen sent an unexpected response']];
@@ -838,7 +844,7 @@ private function updatePatronProperty($propertyName, $propertyValue, $patronIlsP
838844

839845
if (!$response['success']) {
840846
global $logger;
841-
$logger->log('Error updating patron property ' . $propertyName . ': ' . $responseData['payload'][0]['desc'], Logger::LOG_ERROR);
847+
$logger->log('Error updating patron property ' . $propertyEvergreenName . ': ' . $responseData['payload'][0]['desc'], Logger::LOG_ERROR);
842848
$response['message']['code'] = $responseData['payload'][0]['textcode'];
843849
$response['message']['text'] = $responseData['payload'][0]['desc'];
844850
return $response;
@@ -2593,9 +2599,6 @@ public function loadContactInformation(User $user) {
25932599
if (!empty($mappedPatronData['suffix'])) {
25942600
$user->_fullname .= ' ' . $mappedPatronData['suffix'];
25952601
}
2596-
if (!empty($mappedPatronData['email'])) {
2597-
$user->email = $mappedPatronData['email'];
2598-
}
25992602
$user->_fullname = trim($user->_fullname);
26002603

26012604
if (!empty($mappedPatronData['expire_date'])) {

0 commit comments

Comments
 (0)