You are here

function multiversion_update_8106 in Multiversion 8

Resolve all conflicts for local entities, these entities have been excluded from conflict tracking.

File

./multiversion.install, line 525

Code

function multiversion_update_8106() {
  $entity_type_manager = \Drupal::entityTypeManager();
  $conflict_tracker = \Drupal::service('workspace.conflict_tracker');
  $revision_index = \Drupal::service('multiversion.entity_index.rev');
  $workspaces = $entity_type_manager
    ->getStorage('workspace')
    ->loadMultiple();

  // Load conflicts from all workspaces.
  foreach ($workspaces as $id => $workspace) {
    $conflicts = $conflict_tracker
      ->useWorkspace($workspace)
      ->getAll();
    foreach ($conflicts as $uuid => $conflict) {
      $conflict_keys = array_keys($conflict);
      $rev = reset($conflict_keys);
      $rev_info = $revision_index
        ->useWorkspace($id)
        ->get("{$uuid}:{$rev}");
      if (!empty($rev_info['entity_type_id'])) {
        $entity_type = $entity_type_manager
          ->getStorage($rev_info['entity_type_id'])
          ->getEntityType();

        // Resolve conflicts for local entity types.
        if ($entity_type
          ->get('local') === TRUE) {
          $conflict_tracker
            ->resolveAll($uuid);
        }
      }
    }
  }
}