function SourcePluginBase::count

Gets the source count.

Return a count of available source records, from the cache if appropriate. Returns -1 if the source is not countable.

Parameters

bool $refresh: (optional) Whether or not to refresh the count. Defaults to FALSE. Not all implementations support the reset flag. In such instances this parameter is ignored and the result of calling the method will always be up to date.

Return value

int The count.

1 call to SourcePluginBase::count()
ContentEntity::count in core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php
4 methods override SourcePluginBase::count()
ContentEntity::count in core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php
EmbeddedDataSource::count in core/modules/migrate/src/Plugin/migrate/source/EmbeddedDataSource.php
EmptySource::count in core/modules/migrate/src/Plugin/migrate/source/EmptySource.php
SqlBase::count in core/modules/migrate/src/Plugin/migrate/source/SqlBase.php

File

core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php, line 448

Class

SourcePluginBase
The base class for source plugins.

Namespace

Drupal\migrate\Plugin\migrate\source

Code

public function count($refresh = FALSE) {
  if ($this->skipCount) {
    return -1;
  }
  if (!isset($this->cacheKey)) {
    $this->cacheKey = hash('sha256', $this->getPluginId());
  }
  // If a refresh is requested, or we're not caching counts, ask the derived
  // class to get the count from the source.
  if ($refresh || !$this->cacheCounts) {
    $count = $this->doCount();
    $this->getCache()
      ->set($this->cacheKey, $count);
  }
  else {
    // Caching is in play, first try to retrieve a cached count.
    $cache_object = $this->getCache()
      ->get($this->cacheKey, 'cache');
    if (is_object($cache_object)) {
      // Success.
      $count = $cache_object->data;
    }
    else {
      // No cached count, ask the derived class to count 'em up, and cache
      // the result.
      $count = $this->doCount();
      $this->getCache()
        ->set($this->cacheKey, $count);
    }
  }
  return $count;
}

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