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

Minor OverDrive bug fixes. #3877

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

demiankatz
Copy link
Member

While testing some OverDrive templates with the fake connector (since I don't have access to real data), I ran into a number of errors and warnings. This PR improves type/error checking to eliminate those problems. It's possible that these scenarios will never arise with real data, but I don't think it hurts to be error-tolerant in any case!

Could @bpalme and/or @maccabeelevine please review and confirm that I haven't broken anything in the real integration?

@@ -1,5 +1,5 @@
<?php
$previews = $this->driver->getPreviewLinks();
if ($previews->url): ?>
if (isset($previews->url)): ?>
Copy link
Member Author

Choose a reason for hiding this comment

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

I think there's a bigger problem here, because getPreviewLinks always returns an array, so $previews->url is never going to be set. I wasn't sure what was intended, though, so this was my temporary fix to avoid fatal errors. I'm pretty sure more work is needed!

Copy link
Member

Choose a reason for hiding this comment

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

I see that the function doc says it returns an array, and links implies plural, but it doesn't; it returns a struct with properties source, formatType and url.

image

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case, getPreviewLinks may need to be renamed and/or have its doc comment revised. Do you have any suggestions, or should we wait and see what @bpalme says?

@demiankatz demiankatz added this to the 10.1 milestone Aug 23, 2024
Copy link
Member

@maccabeelevine maccabeelevine left a comment

Choose a reason for hiding this comment

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

I think this is an incremental improvement, but @bpalme may have better ideas for how to handle these errors that doesn't provide incorrect data in the UI. It does run fine!

Comment on lines +279 to +284
if ($res) {
$res->copiesAvailable ??= 0;
$res->copiesOwned ??= 0;
$res->numberOfHolds ??= 0;
$res->code = 'od_none';
}
Copy link
Member

Choose a reason for hiding this comment

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

This has the effect of giving incorrect information in the UI (saying 0/0 copies are available) regardless of the truth. That is better than the ugly error output that happens without the if ($res) check, but still not ideal.

Comment on lines +48 to +52
<?=$this->transEsc('od_copies_available', ['%%copies%%' => $copiesAvailable . '/' . ($avail->data->copiesOwned ?? 0)])?>
<?php endif; ?>

<?php if ($avail->data->numberOfHolds > 0): ?>
<?='; ' . $this->transEsc('od_waiting', ['holds' => $avail->data->numberOfHolds], null, true)?>
<?php if (($numHolds = $avail->data->numberOfHolds ?? 0) > 0): ?>
<?='; ' . $this->transEsc('od_waiting', ['holds' => $numHolds], null, true)?>
Copy link
Member

Choose a reason for hiding this comment

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

Same concern here, I'm not sure that saying zero is better than a clean error, although it's certainly better than the ugly current error.

Copy link
Member Author

Choose a reason for hiding this comment

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

This block should only render if the result is greater than zero. Are you seeing otherwise?

Comment on lines +70 to +79
<?php if ($copiesAvailable == 0): ?>
<p>
<a class="btn btn-primary placehold" data-lightbox title="<?=$this->transEsc('request_place_texts')?>"
href="<?=$supportsPatronActions && count($urls) ?
<?php
$holdLink = $supportsPatronActions && count($urls) ?
"$hold_url?od_id=" . urlencode($od_id) . '&rec_id=' . urlencode($rec_id) . '&action=holdConfirm' :
$urls[0]['url']
?>">
<?=$this->icon('place-hold', 'icon-link__icon')?>
<?=$this->transEsc('od_but_hold')?>
</a>
$urls[0]['url'] ?? null;
?>
<?php if ($holdLink): ?>
<a class="btn btn-primary placehold" data-lightbox title="<?=$this->transEsc('request_place_texts')?>"
href="<?=$this->escapeHtmlAttr($holdLink)?>">
Copy link
Member

Choose a reason for hiding this comment

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

I can't test this part as our institution does not $supportsPatronActions, but the code looks reasonable.

@@ -1,5 +1,5 @@
<?php
$previews = $this->driver->getPreviewLinks();
if ($previews->url): ?>
if (isset($previews->url)): ?>
Copy link
Member

Choose a reason for hiding this comment

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

I see that the function doc says it returns an array, and links implies plural, but it doesn't; it returns a struct with properties source, formatType and url.

image

Comment on lines +279 to +284
if ($res) {
$res->copiesAvailable ??= 0;
$res->copiesOwned ??= 0;
$res->numberOfHolds ??= 0;
$res->code = 'od_none';
}
Copy link
Member

Choose a reason for hiding this comment

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

Zero is better than an ugly debug error trace, but it's probably wrong information. Ideal would be a clean error message?

@@ -44,16 +45,16 @@
<?php if (($avail->data->availabilityType ?? 0) == 'AlwaysAvailable'): ?>
<?=$this->transEsc('od_unlimited')?>
<?php else: ?>
<?=$this->transEsc('od_copies_available', ['%%copies%%' => $avail->data->copiesAvailable . '/' . $avail->data->copiesOwned])?>
<?=$this->transEsc('od_copies_available', ['%%copies%%' => $copiesAvailable . '/' . ($avail->data->copiesOwned ?? 0)])?>
Copy link
Member Author

Choose a reason for hiding this comment

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

@maccabeelevine, do you think we should change the else to else if ($avail->data->copiesOwned ?? 0 > 0): so we display nothing if no copies are owned, instead of the weird 0/0 thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants