Skip to content

Commit

Permalink
PCHR-4346: Fix undefined index error when using the HRJobContract.get…
Browse files Browse the repository at this point in the history
…FullDetails API

This API call is an optimized way to fetch all the information for a Job Contract,
which is stored in multiple different database tables. It does that by running
a single SQL query, joining all the tables and the necessary fields.

In the resultset, in order to differentiate which field belongs to which entity,
each field is prefixed with the entity name (examplei: details__<field_name>). After
the data is fetched from the database, the `HRJobContractRevision::normalizeFullDetailsResult()`
was used to loop through all the fields in the resultset, detect to which entity they
belong to and organize the data in a proper way.

Besides the fields returned by the query, the resultset object also contains some internal
fields. In the past, all of these fields were prefixed with an underscore, but on
civicrm/civicrm-core#12276 a new `resultCopies` field was added,
and since it does not start with an underscore, the logic to filter out the internal
fields stopped working. To fix that, instead of looping through all of the fields from
the resultset, we call the `toArray()` method which will return a list of fields and
values containing only those returned by the SQL query.
  • Loading branch information
davialexandre committed Oct 23, 2018
1 parent 60fe817 commit b728232
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions hrjobcontract/CRM/Hrjobcontract/BAO/HRJobContractRevision.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,9 @@ private static function buildEntityQueryArray($entity, $revision, $query) {
protected static function normalizeFullDetailsResult($result) {
$normalized = [];

foreach ($result as $key => $value) {
if ($key[0] == '_' || $key == 'N') { continue; } // ignores "internal" fields

list($entity, $field) = explode('__', $key);
$allFields = $result->toArray();
foreach ($allFields as $entityField => $value) {
list($entity, $field) = explode('__', $entityField);

// This is necessary because some fields are stored in the DB as strings
// although the content is actually a JSON. It is done automatically when
Expand Down

0 comments on commit b728232

Please sign in to comment.