Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8.2 deprecations #3893

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions module/VuFind/src/VuFind/ILS/Driver/Unicorn.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,18 +1286,6 @@ protected function formatDateTime($time)
return $dateTimeString;
}

/**
* Convert the given ISO-8859-1 string to UTF-8 if it is not already UTF-8.
*
* @param string $s The string to convert.
*
* @return string The input string converted to UTF-8
*/
protected function toUTF8($s)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is no more used, co I removed it instead of fixing it

{
return (mb_detect_encoding($s, 'UTF-8') == 'UTF-8') ? $s : utf8_encode($s);
}

/**
* Given a location field, return the values relevant to VuFind.
*
Expand Down
74 changes: 43 additions & 31 deletions module/VuFind/src/VuFind/ILS/Driver/Voyager.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ protected function getStatusData($sqlRows)
'status_array' => [$row['STATUS']],
'location' => $row['TEMP_LOCATION'] > 0
? $this->getLocationName($row['TEMP_LOCATION'])
: utf8_encode($row['LOCATION']),
: $this->utf8Encode($row['LOCATION']),
'reserve' => $row['ON_RESERVE'],
'callnumber' => $row['CALLNUMBER'],
'item_sort_seq' => $row['ITEM_SEQUENCE_NUMBER'],
Expand Down Expand Up @@ -846,7 +846,7 @@ protected function getPurchaseHistoryData($id)
$raw = $processed = [];
// Collect raw data:
while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) {
$raw[] = $row['MFHD_ID'] . '||' . utf8_encode($row['ENUMCHRON']);
$raw[] = $row['MFHD_ID'] . '||' . $this->utf8Encode($row['ENUMCHRON']);
}
// Deduplicate data and format it:
foreach (array_unique($raw) as $current) {
Expand Down Expand Up @@ -986,7 +986,7 @@ protected function getLocationName($id)
$bind = ['id' => $id];
$sqlStmt = $this->executeSQL($sql, $bind);
$sqlRow = $sqlStmt->fetch(PDO::FETCH_ASSOC);
$cache[$id] = utf8_encode($sqlRow['LOCATION']);
$cache[$id] = $this->utf8Encode($sqlRow['LOCATION']);
}

return $cache[$id];
Expand All @@ -1008,7 +1008,7 @@ protected function processHoldingRow($sqlRow)
'status' => $sqlRow['STATUS'],
'location' => $sqlRow['TEMP_LOCATION'] > 0
? $this->getLocationName($sqlRow['TEMP_LOCATION'])
: utf8_encode($sqlRow['LOCATION']),
: $this->utf8Encode($sqlRow['LOCATION']),
'reserve' => $sqlRow['ON_RESERVE'],
'callnumber' => $sqlRow['CALLNUMBER'],
'barcode' => $sqlRow['ITEM_BARCODE'],
Expand Down Expand Up @@ -1110,7 +1110,7 @@ protected function processHoldingData($data, $id, $patron = null)
$holding[$i] += [
'availability' => $availability['available'],
'enumchron' => isset($row['ITEM_ENUM'])
? utf8_encode($row['ITEM_ENUM']) : null,
? $this->utf8Encode($row['ITEM_ENUM']) : null,
'duedate' => $this->processHoldingDueDate($row),
'number' => $number,
'requests_placed' => $requests_placed,
Expand Down Expand Up @@ -1293,18 +1293,18 @@ public function patronLogin($username, $login)
}

try {
$bindUsername = strtolower(utf8_decode($username));
$bindUsername = strtolower(mb_convert_encoding($username, 'ISO-8859-1', 'UTF-8'));
$compareLogin = mb_strtolower($login, 'UTF-8');

$sqlStmt = $this->executeSQL($sql, [':username' => $bindUsername]);
// For some reason barcode is not unique, so evaluate all resulting
// rows just to be safe
while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) {
$primary = null !== $row['LOGIN']
? mb_strtolower(utf8_encode($row['LOGIN']), 'UTF-8')
? mb_strtolower($this->utf8Encode($row['LOGIN']), 'UTF-8')
: null;
$fallback = $fallbackLoginField && null === $row['LOGIN']
? mb_strtolower(utf8_encode($row['FALLBACK_LOGIN']), 'UTF-8')
? mb_strtolower($this->utf8Encode($row['FALLBACK_LOGIN']), 'UTF-8')
: null;

if (
Expand All @@ -1314,9 +1314,9 @@ public function patronLogin($username, $login)
&& $fallback == $compareLogin)
) {
return [
'id' => utf8_encode($row['PATRON_ID']),
'firstname' => utf8_encode($row['FIRST_NAME']),
'lastname' => utf8_encode($row['LAST_NAME']),
'id' => $this->utf8Encode($row['PATRON_ID']),
'firstname' => $this->utf8Encode($row['FIRST_NAME']),
'lastname' => $this->utf8Encode($row['LAST_NAME']),
'cat_username' => $username,
'cat_password' => $login,
// There's supposed to be a getPatronEmailAddress stored
Expand Down Expand Up @@ -1474,10 +1474,10 @@ protected function processMyTransactionsData($sqlRow, $patron = false)
$transaction = [
'id' => $sqlRow['BIB_ID'],
'item_id' => $sqlRow['ITEM_ID'],
'barcode' => utf8_encode($sqlRow['ITEM_BARCODE']),
'barcode' => $this->utf8Encode($sqlRow['ITEM_BARCODE']),
'duedate' => $dueDate,
'dueStatus' => $dueStatus,
'volume' => str_replace('v.', '', utf8_encode($sqlRow['ITEM_ENUM'])),
'volume' => str_replace('v.', '', $this->utf8Encode($sqlRow['ITEM_ENUM'])),
'publication_year' => $sqlRow['YEAR'],
'title' => empty($sqlRow['TITLE_BRIEF'])
? $sqlRow['TITLE'] : $sqlRow['TITLE_BRIEF'],
Expand All @@ -1495,7 +1495,7 @@ protected function processMyTransactionsData($sqlRow, $patron = false)
}
if (!empty($this->config['Loans']['display_borrowing_location'])) {
$transaction['borrowingLocation']
= utf8_encode($sqlRow['BORROWING_LOCATION']);
= $this->utf8Encode($sqlRow['BORROWING_LOCATION']);
}

return $transaction;
Expand Down Expand Up @@ -1619,7 +1619,7 @@ protected function processFinesData($sqlRow)
}

return ['amount' => $sqlRow['FINE_FEE_AMOUNT'],
'fine' => utf8_encode($sqlRow['FINE_FEE_DESC']),
'fine' => $this->utf8Encode($sqlRow['FINE_FEE_DESC']),
'balance' => $sqlRow['FINE_FEE_BALANCE'],
'createdate' => $createDate,
'checkout' => $chargeDate,
Expand Down Expand Up @@ -1765,7 +1765,7 @@ protected function processMyHoldsData($sqlRow)
'available' => $available,
'reqnum' => $sqlRow['HOLD_RECALL_ID'],
'item_id' => $sqlRow['ITEM_ID'],
'volume' => str_replace('v.', '', utf8_encode($sqlRow['ITEM_ENUM'])),
'volume' => str_replace('v.', '', $this->utf8Encode($sqlRow['ITEM_ENUM'])),
'publication_year' => $sqlRow['YEAR'],
'title' => empty($sqlRow['TITLE_BRIEF'])
? $sqlRow['TITLE'] : $sqlRow['TITLE_BRIEF'],
Expand Down Expand Up @@ -1957,24 +1957,24 @@ protected function processMyStorageRetrievalRequestsData($sqlRow)

return [
'id' => $sqlRow['BIB_ID'],
'status' => utf8_encode($sqlRow['STATUS_DESC']),
'status' => $this->utf8Encode($sqlRow['STATUS_DESC']),
'statusDate' => $statusDate,
'location' => $this->getLocationName($sqlRow['PICKUP_LOCATION_ID']),
'create' => $createDate,
'processed' => $processedDate,
'expire' => $expireDate,
'reply' => utf8_encode($sqlRow['REPLY_NOTE']),
'reply' => $this->utf8Encode($sqlRow['REPLY_NOTE']),
'available' => $available,
'canceled' => $sqlRow['STATUS'] == 7 ? $statusDate : false,
'reqnum' => $sqlRow['CALL_SLIP_ID'],
'item_id' => $sqlRow['ITEM_ID'],
'volume' => str_replace(
'v.',
'',
utf8_encode($sqlRow['ITEM_ENUM'])
$this->utf8Encode($sqlRow['ITEM_ENUM'])
),
'issue' => utf8_encode($sqlRow['ITEM_CHRON']),
'year' => utf8_encode($sqlRow['ITEM_YEAR']),
'issue' => $this->utf8Encode($sqlRow['ITEM_CHRON']),
'year' => $this->utf8Encode($sqlRow['ITEM_YEAR']),
'title' => empty($sqlRow['TITLE_BRIEF'])
? $sqlRow['TITLE'] : $sqlRow['TITLE_BRIEF'],
];
Expand Down Expand Up @@ -2042,40 +2042,40 @@ public function getMyProfile($patron)
$patron = [];
while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) {
if (!empty($row['FIRST_NAME'])) {
$patron['firstname'] = utf8_encode($row['FIRST_NAME']);
$patron['firstname'] = $this->utf8Encode($row['FIRST_NAME']);
}
if (!empty($row['LAST_NAME'])) {
$patron['lastname'] = utf8_encode($row['LAST_NAME']);
$patron['lastname'] = $this->utf8Encode($row['LAST_NAME']);
}
if (!empty($row['PHONE_NUMBER'])) {
if ($primaryPhoneType === $row['PHONE_DESC']) {
$patron['phone'] = utf8_encode($row['PHONE_NUMBER']);
$patron['phone'] = $this->utf8Encode($row['PHONE_NUMBER']);
} elseif ($mobilePhoneType === $row['PHONE_DESC']) {
$patron['mobile_phone'] = utf8_encode($row['PHONE_NUMBER']);
$patron['mobile_phone'] = $this->utf8Encode($row['PHONE_NUMBER']);
}
}
if (!empty($row['PATRON_GROUP_NAME'])) {
$patron['group'] = utf8_encode($row['PATRON_GROUP_NAME']);
$patron['group'] = $this->utf8Encode($row['PATRON_GROUP_NAME']);
}
$validator = new EmailAddressValidator();
$addr1 = utf8_encode($row['ADDRESS_LINE1']);
$addr1 = $this->utf8Encode($row['ADDRESS_LINE1']);
if ($validator->isValid($addr1)) {
$patron['email'] = $addr1;
} elseif (!isset($patron['address1'])) {
if (!empty($addr1)) {
$patron['address1'] = $addr1;
}
if (!empty($row['ADDRESS_LINE2'])) {
$patron['address2'] = utf8_encode($row['ADDRESS_LINE2']);
$patron['address2'] = $this->utf8Encode($row['ADDRESS_LINE2']);
}
if (!empty($row['ZIP_POSTAL'])) {
$patron['zip'] = utf8_encode($row['ZIP_POSTAL']);
$patron['zip'] = $this->utf8Encode($row['ZIP_POSTAL']);
}
if (!empty($row['CITY'])) {
$patron['city'] = utf8_encode($row['CITY']);
$patron['city'] = $this->utf8Encode($row['CITY']);
}
if (!empty($row['COUNTRY'])) {
$patron['country'] = utf8_encode($row['COUNTRY']);
$patron['country'] = $this->utf8Encode($row['COUNTRY']);
}
}
}
Expand Down Expand Up @@ -2638,4 +2638,16 @@ protected function executeSQL($sql, $bind = [])

return $sqlStmt;
}

/**
* Convert string from ISO 8859-1 into UTF-8
*
* @param string $iso88591 String to convert
*
* @return string
*/
protected function utf8Encode(string $iso88591): string
{
return mb_convert_encoding($iso88591, 'UTF-8', 'ISO-8859-1');
}
}
4 changes: 2 additions & 2 deletions module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public function getPickUpLocations($patron = false, $holdDetails = null)
while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) {
$pickResponse[] = [
'locationID' => $row['LOCATION_ID'],
'locationDisplay' => utf8_encode($row['LOCATION_NAME']),
'locationDisplay' => $this->utf8Encode($row['LOCATION_NAME']),
];
}
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ function ($s) {
while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) {
$results[] = [
'id' => $row['GROUP_ID'],
'name' => utf8_encode($row['GROUP_NAME']),
'name' => $this->utf8Encode($row['GROUP_NAME']),
];
}

Expand Down
Loading
Loading