-
Notifications
You must be signed in to change notification settings - Fork 32
Prevent warnings when $parsed_date[EDTFUtils::YEAR_BASE] is not set #139
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
Conversation
I'm unable to reproduce the error. I spun up a current version of site-template, created an item using the value Can you provide a more specific example of how to reproduce the error? |
27b64e6
to
058a40a
Compare
058a40a
to
97b11f1
Compare
You're right, apologies for reporting Looks like the warnings we're observing are due to invalid EDTF inputs in the DB - or at least, that's one way to trigger them. While these should ideally be validated for storage, I do think it's an improvement to check An alternative approach could be to call EDTFUtils::validate() on the date we're formatting, and return an empty string if the date is not EDTF-valid. That feels more specific, but like a bigger change. Happy to switch to that if preferred. I've included test coverage, and 9fe716d should pass for valid dates, a18c741 then shows PHPUnit failures due to warnings when some additional inputs are provided, and then 6ad41ef is the fix proposed here initially. The invalid inputs are any non-EDTF value, for example:
Failing test outputAt a18c741 we see this output where the undefined array keys are referenced; this is fixed in the subsequent commit.
|
97b11f1
to
3f4ce0e
Compare
3f4ce0e
to
552aebc
Compare
Would someone please permit the introduced tests to run on this PR? I see "This workflow requires approval from a maintainer." and I seek your approval 😄 |
The failure are all coding styles. Be sure to use |
f578378
to
bbddd2f
Compare
Doh! Fixed, rebased (squashed PHPCS into the history rather than adding a separate commit), let's try that again. Thanks @seth-shaw-asu :) |
Yet more style fixes are needed. |
bbddd2f
to
aa694cd
Compare
Updated once more, thanks. I had missed a few trailing periods, and am omitting PHPCBF changes which aren't relevant to this PR (eg (edit: I didn't do that, because it was a different failure.) |
Ugh, I thought Oh, wrong function, doh. |
This is the last bit holding the checks back:
|
aa694cd
to
c5b3fe8
Compare
Thanks for your patience :) |
All is green. I'll give it a test. |
I can confirm that the PR, as it exists, works. The warnings are gone. However, after thinking about it for a bit while testing, we really ought to add a warning when we come across bad data in this field. So I think the idea shared earlier...
... is a better idea. That said, instead of simply returning an empty string (which results in a poor user experience), I would return the original string value as-is and create a Drupal logger message indicating the item at fault along with the validator's messages. That way, site admins can see helpful messages instead of vague ones. |
For the site affected here, the current issue is that exporting collections to CSV generates a large number of warnings. (In an internal ticket, the ~1000-odd invalid values in EDTF fields have been reported to the customer for addressing.) The current behaviour for this site is that invalid EDTF values are not presented to the public via node view, and don't seem to be surfaced in the edit interface. Fields are using the "Default EDTF widget" element for edit. If I understand right, #139 (comment) would be a change in behaviour for this module: where a site currently has an invalid EDTF value, I think we don't expect that to be surfaced? (Maybe I described that poorly with 'return an empty string', I was forgetting that the validate function returns a non-empty array on validation failure.) For the customer affected, my goal here was to reduce log noise and (separately) allow them to tidy up some invalid data. I have a concern that logging each "bad" value would add load both to CSV exports (already a demanding task) and to regular page display (a small thing, but not insignificant with current levels of web crawling). Would you consider merging this as-is (introduces test coverage, small change to eliminate a PHP warning) and working towards improved validation and reporting separately? I see there's other validation improvements forthcoming in eg #123 and #129, and a suggestion in 129 to use professional-wiki/edtf. |
Meant to say this but lost it in edits. AFAICT the current behaviour of this module is that invalid EDTF inputs:
In the UAT environment, I wasn't able to get an invalid value to show up in the admin UI or the frontend, nor to save it. (The existing values will have been imported from CSV, bypassing form validation.) In the production environment, I dug through existing invalid values, and the only invalid one I see exposed in the admin UI is EDIT: A site admin has been hard at work fixing invalid values - so my comment above that they are not exposed in admin UI was incorrect. Invalid values such as (for my reference: production node 6367 above) The UAT and production environments aren't identical here and I don't want to experiment with production. Anyway, this is mostly to say that I'd want to be careful about revealing invalid date values to the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
GitHub Issue: (link)
What does this Pull Request do?
The YEAR_BASE value is set conditionally, only when YEAR_EXPONENT has been populated.
controlled_access_terms/src/Plugin/Field/FieldFormatter/EDTFFormatter.php
Lines 228 to 231 in 05a0811
controlled_access_terms/src/EDTFUtils.php
Lines 209 to 214 in 05a0811
When YEAR_BASE is unset, which happens when YEAR_EXPONENT is not set, formatting some inputs may trigger warnings or errors in Drupal.
Various invalid EDTF values were identified in the site where this was noted. This led to a large number of warnings being logged, particularly when exporting CSV of collection data using Views.
On the affected site, this also correlated with thumbnails not being viewable (but am not confident if that is the root cause of the thumbnail issue).
What's new?
Improve validation of EDTF inputs when being formatted, eliminate some warnings when invalid data supplied.
How should this be tested?
Formatting output for some invalid EDTF values should trigger this behaviour. Example inputs are (empty string), "not-an-EDTF-date", "1900s", etc.
Test coverage is added here, and may want to be expanded for additional inputs.
Additional Notes:
Interested parties
@Islandora/committers, @antbrown