You are here

public function SubscriberAudit::findEntitiesToDelete in Acquia Content Hub 8

Find entities to delete.

Parameters

array $entity_type_ids: An array of entity type ids we want to search and delete.

Return value

array A double array keyed by 'delete' and 'missing' entities.

2 calls to SubscriberAudit::findEntitiesToDelete()
SubscriberAudit::deleteEntities in acquia_contenthub_audit/src/SubscriberAudit.php
Delete Entities.
SubscriberAudit::generateManifest in acquia_contenthub_audit/src/SubscriberAudit.php
Generate Manifest file.

File

acquia_contenthub_audit/src/SubscriberAudit.php, line 167

Class

SubscriberAudit
Audits Subscribers.

Namespace

Drupal\acquia_contenthub_audit

Code

public function findEntitiesToDelete(array $entity_type_ids = []) {
  $entities = $this->common
    ->executeAllFilters();
  unset($entities['total']);
  $uuids = array_keys($entities);
  $query = $this->database
    ->select('acquia_contenthub_entities_tracking', 't')
    ->fields('t');
  if (!empty($uuids)) {
    $query
      ->condition('t.entity_uuid', $uuids, 'NOT IN');
  }
  $query
    ->condition('t.status_import', ContentHubEntitiesTracking::IS_DEPENDENT, '<>');
  $query
    ->condition('t.status_import', '', '<>');

  // Make the entity types configurable.
  if (!empty($entity_type_ids)) {
    $query
      ->condition('t.entity_type', $entity_type_ids, 'IN');
  }
  $results = $query
    ->execute();

  // Build a list of uuids which filters did not match.
  $unmatched_uuids = [];
  foreach ($results as $item) {
    $unmatched_uuids[$item->entity_uuid] = $item;
  }

  // Retrieve our list of missing items to see if any are in the hub.
  $entities_in_hub = $this->client
    ->readEntities(array_keys($unmatched_uuids));

  // Build the list of things missing from ContentHub.
  $missing_uuids = array_diff_key($unmatched_uuids, $entities_in_hub);
  $unmatched_uuids = array_diff_key($unmatched_uuids, $missing_uuids);
  return [
    'delete' => $unmatched_uuids,
    'missing' => $missing_uuids,
  ];
}