You are here

public function StubTracker::cleanUp in Acquia Content Hub 8.2

Removes any stub entities created during the import process.

This method prevents sample entity data from being permanently saved in the database. Tracking of potential stub entities is compared against the DependencyStack object. Any entity not found in the stack is considered to be a stub and is deleted.

The stack and stub properties are reset when this is complete to prevent bleed-through between runs.

Parameters

bool $all: Whether to delete all stubs or to delete them conditionally.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

src/StubTracker.php, line 105

Class

StubTracker
Class StubTracker.

Namespace

Drupal\acquia_contenthub

Code

public function cleanUp($all = FALSE) {
  if (!$this
    ->isTracking()) {
    return;
  }
  foreach ($this->stubs as $entity_type => $entity_ids) {
    $storage = $this
      ->getEntityTypeManager()
      ->getStorage($entity_type);
    foreach ($entity_ids as $id) {
      $entity = $storage
        ->load($id);
      if (!$entity) {
        continue;
      }
      if ($all) {
        $entity
          ->delete();
      }
      else {
        $this
          ->deleteStubConditionally($entity);
      }
    }
  }
  $this->stack = [];
  $this->stubs = [];
}