function WorkspaceAssociation::doDeleteAssociations

Executes a delete query for workspace associations.

Parameters

string $table: The database table to delete from.

string|null $workspace_id: The workspace ID to filter by, or NULL to not filter by workspace.

string|null $entity_type_id: The entity type ID to filter by, or NULL to not filter by entity type.

array|null $entity_ids: The entity IDs to filter by, or NULL to not filter by entity IDs.

array|null $revision_ids: The revision IDs to filter by, or NULL to not filter by revision IDs.

Throws

\InvalidArgumentException When required parameters are missing.

1 call to WorkspaceAssociation::doDeleteAssociations()
WorkspaceAssociation::deleteAssociations in core/modules/workspaces/src/WorkspaceAssociation.php
Deletes all the workspace association records for the given workspace.

File

core/modules/workspaces/src/WorkspaceAssociation.php, line 367

Class

WorkspaceAssociation
Provides a class for CRUD operations on workspace associations.

Namespace

Drupal\workspaces

Code

protected function doDeleteAssociations(string $table, ?string $workspace_id = NULL, ?string $entity_type_id = NULL, ?array $entity_ids = NULL, ?array $revision_ids = NULL) : void {
  $query = $this->database
    ->delete($table);
  if ($workspace_id) {
    $query->condition('workspace', $workspace_id);
  }
  if ($entity_type_id) {
    if (!$entity_ids && !$revision_ids) {
      throw new \InvalidArgumentException('A list of entity IDs or revision IDs must be provided for an entity type.');
    }
    $query->condition('target_entity_type_id', $entity_type_id, '=');
    if ($entity_ids) {
      try {
        $query->condition(static::getIdField($entity_type_id), $entity_ids, 'IN');
      } catch (PluginNotFoundException) {
        // When an entity type is being deleted, we no longer have the ability
        // to retrieve its identifier field type, so we try both.
        $query->condition($query->orConditionGroup()
          ->condition('target_entity_id', $entity_ids, 'IN')
          ->condition('target_entity_id_string', $entity_ids, 'IN'));
      }
    }
    if ($revision_ids) {
      $query->condition('target_entity_revision_id', $revision_ids, 'IN');
    }
  }
  $query->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.