You are here

public static function CreateStatusEntities::execute in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 8 modules/cms_content_sync_migrate_acquia_content_hub/src/CreateStatusEntities.php \Drupal\cms_content_sync_migrate_acquia_content_hub\CreateStatusEntities::execute()
  2. 2.0.x modules/cms_content_sync_migrate_acquia_content_hub/src/CreateStatusEntities.php \Drupal\cms_content_sync_migrate_acquia_content_hub\CreateStatusEntities::execute()

Batch create Status Entities for collected nodes.

Parameters

$nid:

$flow_id:

$bundle_id:

$pools:

$field_name:

$type:

File

modules/cms_content_sync_migrate_acquia_content_hub/src/CreateStatusEntities.php, line 84

Class

CreateStatusEntities

Namespace

Drupal\cms_content_sync_migrate_acquia_content_hub

Code

public static function execute($entity_type, $entity_id, $flow_id, $pool_id, $type) {
  $entity = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->load($entity_id);

  // Drupal doesn't reliably update their taxonomy_index table when a node gets deleted.
  if (!$entity) {
    return;
  }

  // If a node has a match, create a status entity.
  // Ensure that a status entity does not already exist.
  $entity_status = EntityStatus::getInfoForEntity($entity_type, $entity
    ->uuid(), $flow_id, $pool_id);
  if (!$entity_status) {
    $data = [
      'flow' => $flow_id,
      'pool' => $pool_id,
      'entity_type' => $entity_type,
      'entity_uuid' => $entity
        ->uuid(),
      'entity_type_version' => Flow::getEntityTypeVersion($entity_type, $entity
        ->bundle()),
      'flags' => 0,
      'source_url' => NULL,
    ];
    if ($entity_type == 'node' && $type == 'pull') {
      $data['last_' . $type] = $entity
        ->getChangedTime();
    }
    $entity_status = EntityStatus::create($data);
    if ($type == 'push') {
      $entity_status
        ->isPushEnabled(TRUE);
      $entity_status
        ->isSourceEntity(TRUE);
    }
    $entity_status
      ->save();
  }
}