pkp / orcidProfile

A plugin to pull ORCID information into a PKP user profile
GNU General Public License v3.0
15 stars 48 forks source link

orcidAuthorize employment information not available #305

Open ewhanson opened 7 months ago

ewhanson commented 7 months ago

Describe the bug When the orcidAuthorize handler method is run, the public API is called to fetch information about the authenticated ORCID user, including any employment information.

The affiliation field on the OJS registration form is supposed to be filled with the following information from an associative array returned from the /employments ORCID endpoint $employmentJson['employment-summary'][0]['organization']['name'], but the key of employment-summary is not included.

See PHP generated warning:

PHP Warning: Undefined array key "employment-summary" in [path-to-ojs]/plugins/generic/orcidProfile/OrcidProfileHandler.php on line 166

To confirm:

Additional context Observed in OJS 3.4, but likely an issue in previous versions.

Nostrabramus commented 1 month ago

I had the same problem but I think I solved it. I'm using the orcidProfile 3.3.0 with OJS 3.3.0.10. I have already checked on the most updated github versions of the plugin and the bug persists.

I found two problems:

  1. the response variable is not re-assigned and therefore it keeps the Json array of the person and not that of the employment
  2. the decode of the Json array of the employment does not take into account the correct structure of the array, the current code expects: ['employment-summary'][0]['organization']['name'] but the structure of the array that is returned is the following: ['affiliation-group'][0]['summaries'][0]['employment-summary']['organization']['name']

My solution (version 3.3.0)

problem 1 file: /orcidProfile/pages/OrcidHandler.inc.php line 117 is: $httpClient->request( but it must be: $response = $httpClient->request( (since the variable is not reassigned, it retains the previously loaded Json array)

problem 2 file /orcidProfile/pages/OrcidHandler.inc.php line 140 is: opener.document.getElementById("affiliation").value = ' . json_encode(@$employmentJson['employment-summary'][0]['organization']['name']) . '; but it must be: opener.document.getElementById("affiliation").value = ' . json_encode(@$employmentJson['affiliation-group'][0]['summaries'][0]['employment-summary']['organization']['name']) . '; (to extract data from the working architecture)

I made these two corrections and it works for me, if needed I can do the pull-request.

I found the same problems on version 3.4.0 but the file involved is: /orcidProfile/OrcidProfileHandler.php line 148 and line 173

I hope I was helpful.

Abramo

ewhanson commented 2 weeks ago

Thanks @Nostrabramus for confirming this! I've confirmed and addressed this in the big refactor the ORCID plugin just went through (on the main branch), but will get this changed ported back to OJS 3.3 and 3.4.