function WorkspaceAssociation::deleteAssociations

Same name and namespace in other branches
  1. 10 core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::deleteAssociations()
  2. 9 core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::deleteAssociations()
  3. 8.9.x core/modules/workspaces/src/WorkspaceAssociation.php \Drupal\workspaces\WorkspaceAssociation::deleteAssociations()

Deletes all the workspace association records for the given workspace.

Parameters

string|null $workspace_id: (optional) A workspace entity ID. Defaults to NULL.

string|null $entity_type_id: (optional) The target entity type of the associations to delete. Defaults to NULL.

int[]|string[]|null $entity_ids: (optional) The target entity IDs of the associations to delete. Defaults to NULL.

int[]|string[]|null $revision_ids: (optional) The target entity revision IDs of the associations to delete. Defaults to NULL.

Overrides WorkspaceAssociationInterface::deleteAssociations

1 call to WorkspaceAssociation::deleteAssociations()
WorkspaceAssociation::onPostPublish in core/modules/workspaces/src/WorkspaceAssociation.php
Triggers clean-up operations after a workspace is published.

File

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

Class

WorkspaceAssociation
Provides a class for CRUD operations on workspace associations.

Namespace

Drupal\workspaces

Code

public function deleteAssociations($workspace_id = NULL, $entity_type_id = NULL, $entity_ids = NULL, $revision_ids = NULL) {
  if (!$workspace_id && !$entity_type_id) {
    throw new \InvalidArgumentException('A workspace ID or an entity type ID must be provided.');
  }
  try {
    $transaction = $this->database
      ->startTransaction();
    $this->doDeleteAssociations(static::TABLE, $workspace_id, $entity_type_id, $entity_ids, $revision_ids);
    $this->doDeleteAssociations(static::REVISION_TABLE, $workspace_id, $entity_type_id, $entity_ids, $revision_ids);
  } catch (\Exception $e) {
    if (isset($transaction)) {
      $transaction->rollBack();
    }
    Error::logException($this->logger, $e);
    throw $e;
  }
  $this->associatedRevisions = $this->associatedInitialRevisions = [];
}

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