You are here

protected function TreeLockTrait::lockTree in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 src/Storage/TreeLockTrait.php \Drupal\entity_hierarchy\Storage\TreeLockTrait::lockTree()

Locks tree.

Parameters

string $fieldName: Field name.

string $entityTypeId: Entity Type ID.

Throws

\Exception When lock cannot be acquired after 30 seconds.

4 calls to TreeLockTrait::lockTree()
EntityReferenceHierarchy::postSave in src/Plugin/Field/FieldType/EntityReferenceHierarchy.php
Defines custom post-save behavior for field values.
EntityReferenceHierarchyFieldItemList::postSave in src/Plugin/Field/FieldType/EntityReferenceHierarchyFieldItemList.php
Defines custom post-save behavior for field values.
ParentEntityDeleteUpdater::moveChildren in src/Storage/ParentEntityDeleteUpdater.php
Moves children to their grandparent or root.
ParentEntityRevisionUpdater::moveChildren in src/Storage/ParentEntityRevisionUpdater.php
Move children from old revision to new revision.

File

src/Storage/TreeLockTrait.php, line 56

Class

TreeLockTrait
Defines a trait for locking tree operations.

Namespace

Drupal\entity_hierarchy\Storage

Code

protected function lockTree($fieldName, $entityTypeId) {
  $count = 0;
  while (!$this
    ->lockBackend()
    ->acquire($this
    ->getLockName($fieldName, $entityTypeId))) {

    // Wait a while before trying again.
    sleep(1);
    $count++;
    if ($count === 30) {
      throw new \Exception('Unable to acquire lock to update tree.');
    }
  }
}