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 Skosmos 2 deprecated concept pages (bool value causes crash) #1673

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

osma
Copy link
Member

@osma osma commented Aug 30, 2024

Reasons for creating this PR

Concept pages for deprecated concepts are currently broken in Skosmos 2. The bool value for owl:deprecated is causing a crash in Concept->removeDuplicateValues, like this:

[Fri Aug 30 11:48:39.758115 2024] [php:error] [pid 144739] [client 127.0.0.1:47930] PHP Fatal error:  Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, bool given in /var/www/html/Skosmos2/model/Concept.php:663\nStack trace:\n#0 /var/www/html/Skosmos2/model/Concept.php(663): method_exists()\n#1 /var/www/html/Skosmos2/model/Concept.php(645): Concept->removeDuplicatePropertyValues()\n#2 /var/www/html/Skosmos2/vendor/twig/twig/src/Extension/CoreExtension.php(1570): Concept->getProperties()\n#3 /tmp/Skosmos2-template-cache/85/859484638bd554063232d14751ee5b62.php(400): twig_get_attribute()\n#4 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(405): __TwigTemplate_402425c04623ea52800d487a70a4fa76->doDisplay()\n#5 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(378): Twig\\Template->displayWithErrorHandling()\n#6 /tmp/Skosmos2-template-cache/f5/f599161f85f65508bd79705eed18e150.php(95): Twig\\Template->display()\n#7 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(182): __TwigTemplate_3a76ea3e7d1dccaed153adfaa566d71b->block_content()\n#8 /tmp/Skosmos2-template-cache/bd/bdda9141010ddb078ba4895e1561cb70.php(864): Twig\\Template->displayBlock()\n#9 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(182): __TwigTemplate_55703627091ff672c05e8057e32b3174->block_error()\n#10 /tmp/Skosmos2-template-cache/bd/bdda9141010ddb078ba4895e1561cb70.php(232): Twig\\Template->displayBlock()\n#11 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(405): __TwigTemplate_55703627091ff672c05e8057e32b3174->doDisplay()\n#12 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(378): Twig\\Template->displayWithErrorHandling()\n#13 /tmp/Skosmos2-template-cache/f5/f599161f85f65508bd79705eed18e150.php(56): Twig\\Template->display()\n#14 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(405): __TwigTemplate_3a76ea3e7d1dccaed153adfaa566d71b->doDisplay()\n#15 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(378): Twig\\Template->displayWithErrorHandling()\n#16 /var/www/html/Skosmos2/vendor/twig/twig/src/Template.php(390): Twig\\Template->display()\n#17 /var/www/html/Skosmos2/controller/WebController.php(192): Twig\\Template->render()\n#18 /var/www/html/Skosmos2/index.php(87): WebController->invokeVocabularyConcept()\n#19 {main}\n  thrown in /var/www/html/Skosmos2/model/Concept.php on line 663

I had to do some digging to figure out the cause. It happens only when there is a rdfs:label available for the owl:deprecated property in the current vocabulary, or the default graph. Having a label makes Concept->getProperties consider the owl:deprecated property, but it will crash in Concept->removeDuplicateValues because the value of owl:deprecated is of type bool that the code wasn't prepared for.

This PR fixes the crash by adding an extra is_object check. To verify that the fix is working, there is a new unit test as well as a new test vocabulary containing triples that can be accessed through the default graph. Also, owl:deprecated is added to the list of deleted properties to keep it from being displayed on the concept page.

Link to relevant issue(s), if any

Fixes #1635 (for skosmos 2)

Description of the changes in this PR

  • avoid crash by adding an is_object($label) check
  • add owl:deprecated to list of properties that will not be displayed on concept page (otherwise it would be shown to the user)
  • add phpunit test (including required test vocab data)

Known problems or uncertainties in this PR

The same fix has to be done for Skosmos 3 as well.

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@osma osma added the bug label Aug 30, 2024
@osma osma added this to the 2.x milestone Aug 30, 2024
@osma osma self-assigned this Aug 30, 2024
model/Concept.php Outdated Show resolved Hide resolved
Copy link

sonarqubecloud bot commented Aug 30, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link
Contributor

@joelit joelit left a comment

Choose a reason for hiding this comment

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

LGTM - all use cases that were affected seem to work now

@osma osma merged commit ba92b43 into skosmos-2 Aug 30, 2024
5 of 8 checks passed
@osma osma deleted the fix-skosmos2-deprecated-bool branch August 30, 2024 12:40
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.

3 participants