pkp / googleScholar

Exposes OJS and OPS metadata to Google Scholar for harvesting.
GNU General Public License v3.0
2 stars 12 forks source link

Fatal error when issue can't be found #4

Closed consultbelieve closed 1 year ago

consultbelieve commented 3 years ago

The error is:

PHP Fatal error: Uncaught Error: Call to a member function getYear() on null in /var/www/ojs/plugins/generic/googleScholar/GoogleScholarPlugin.inc.ph p:102\nStack trace:\n#0 /var/www/ojs/lib/pkp/classes/plugins/HookRegistry.inc.php(107): GoogleScholarPlugin->submissionView('ArticleHandler:...', Array)\n#1 /var/www/ojs/pages/article/ArticleHandler.inc.php(280): HookRegistry::call('Arti cleHandler:...', Array)\n

This causes a HTTP500 for any articles for which $issue is not defined.

This is the line causing the problem:

if (is_a($submission, 'Submission') && ($datePublished = $submission->getDatePublished()) && (!$issue->getYear() || $issue->getYear() == strftime('%Y', strtotime($datePublished)))) {

Our fix was to move the following line:

if ($issue) {

up from where it appears 7 lines below so that the section 111-122 appears as:

if ($issue) { if (is_a($submission, 'Submission') && ($datePublished = $submission->getDatePublished()) && (!$issue->getYear() || $issue->getYear() == strftime('%Y', strtotime($datePublished)))) { $templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . strftime('%Y/%m/%d', strtotime($datePublished)) . '"/>'); } elseif ($issue && $issue->getYear()) { $templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . htmlspecialchars($issue->getYear()) . '"/>'); } elseif ($issue && ($datePublished = $issue->getDatePublished())) { $templateMgr->addHeader('googleScholarDate', '<meta name="citation_date" content="' . strftime('%Y/%m/%d', strtotime($datePublished)) . '"/>'); } if ($issue->getShowVolume()) $templateMgr->addHeader('googleScholarVolume', '<meta name="citation_volume" content="' . htmlspecialchars($issue->getVolume()) . '"/>'); if ($issue->getShowNumber()) $templateMgr->addHeader('googleScholarNumber', '<meta name="citation_issue" content="' . htmlspecialchars($issue->getNumber()) . '"/>'); }

Ideally, wouldn't want this overwritten in a future release and so posting it up here so it can be considered for future versions

asmecher commented 3 years ago

@consultbelieve, could you submit the proposed change as a pull request?

jonasraoni commented 1 year ago

Looks like this can be closed, there are checks before using the $issue.