Skip to content

Commit

Permalink
Remove the extra loop to keep complexity down.
Browse files Browse the repository at this point in the history
  • Loading branch information
laceysanderson committed Apr 29, 2024
1 parent d2f0384 commit d5a2549
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions tripal/src/Services/TripalPublish.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,31 +777,18 @@ protected function insertFieldItems($field_name, $matches, $titles, $entities, $
$j++;
$total++;

// Lets retrieve all the values for the required property types
// in this match. These are used to confirm if this record has already
// been published and if not, then these will be inserted.
$required_property_values = [];
foreach ($required_property_keys as $key) {
$required_property_values[$key] = $match[$field_name][$delta][$key]['value']->getValue();
}

// Check if we have an existing entry for this particular datastore record.
if (isset($delta, $existing[$entity_id])) {
// Do we need to worry about the delta not matching? Let's check this
// is really the same record just in case.
if (empty(array_diff_assoc($existing[$entity_id][$delta], $required_property_values))) {
// @debug print "SKIPPING: Not publishing $entity_id|$delta because the required property values are already published:" . print_r($required_property_values, TRUE);
continue;
}
else {
// @debug print "WARNING: The delta didn't match the value we expected!\n";
/** @debug
$required_property_values = [];
foreach ($required_property_keys as $key) {
$required_property_values[$key] = $match[$field_name][$delta][$key]['value']->getValue();
}
print "SKIPPING: Not publishing $entity_id|$delta because the required property values are already published:" . print_r($required_property_values, TRUE);
*/
continue;
}

// @todo we should also skip if this entry is empty, right?
// Note: when publishing a contact, we see the description is published
// every time if no description was entered.

// @debug print "-- PUBLISHING: $entity_id|$delta " . print_r($required_property_values, TRUE);
// Add items to those that are not already published.
$sql .= "(:bundle_$j, :deleted_$j, :entity_id_$j, :revision_id_$j, :langcode_$j, :delta_$j, ";
Expand All @@ -811,7 +798,8 @@ protected function insertFieldItems($field_name, $matches, $titles, $entities, $
$args[":revision_id_$j"] = 1;
$args[":langcode_$j"] = 'und';
$args[":delta_$j"] = $delta;
foreach ($required_property_values as $key => $value) {
foreach ($required_property_keys as $key) {
$value = $match[$field_name][$delta][$key]['value']->getValue();
$placeholder = ':' . $field_name . '_'. $key . '_' . $j;
$sql .= $placeholder . ', ';
$args[$placeholder] = $value;
Expand Down Expand Up @@ -896,18 +884,24 @@ public function publish($filters = []) {
$this->logger->notice("Step 1 of 6: Find matching records... ");
$matches = $this->storage->findValues($search_values);

/* @debug matches srray
/* @debug matches array
print "\nDebuggin Matches after findValues():\n";
foreach ($matches as $entity_id => $lvl1) {
foreach ($lvl1 as $field_name => $lvl2) {
foreach ($lvl2 as $delta => $lvl3) {
$record_id = $lvl3['record_id']['value']->getValue();
$link = (array_key_exists('link', $lvl3)) ? $lvl3['link']['value']->getValue() : 'Not a Linker';
print "Match $entity_id|$field_name|$delta: record '$record_id'; link '$link'.\n";
if ($field_name == 'contact_project') {
foreach ($lvl2 as $delta => $lvl3) {
$debug_values = [];
foreach ($lvl3 as $key => $valueobj) {
$debug_values[$key] = $valueobj['value']->getValue();
}
print "Match $entity_id|$field_name|$delta: " . print_r($debug_values, TRUE);
}
}
}
}
*/


$this->logger->notice("Step 2 of 6: Generate page titles...");
$titles = $this->getEntityTitles($matches);

Expand All @@ -918,6 +912,23 @@ public function publish($filters = []) {
// need to publish these matches.
list($new_matches, $new_titles) = $this->excludeExisting($matches, $titles, $existing);

/* @debug matches array
print "\nDebuggin Matches after exclude existing:\n";
foreach ($matches as $entity_id => $lvl1) {
foreach ($lvl1 as $field_name => $lvl2) {
if ($field_name == 'contact_project') {
foreach ($lvl2 as $delta => $lvl3) {
$debug_values = [];
foreach ($lvl3 as $key => $valueobj) {
$debug_values[$key] = $valueobj['value']->getValue();
}
print "Match $entity_id|$field_name|$delta: " . print_r($debug_values, TRUE);
}
}
}
}
*/

// Note: entities are not tied to any storage backend. An entity
// references an "object". The information about that object
// is in the form of fields and can come from any number of data storage
Expand Down

0 comments on commit d5a2549

Please sign in to comment.