8.5.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)
8.0.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)
8.1.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)
8.2.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)
8.3.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)
8.4.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)
8.6.x SourcePluginBase.php SourcePluginBase::count($refresh = FALSE)

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.

3 methods override SourcePluginBase::count()
EmbeddedDataSource::count in core/modules/migrate/src/Plugin/migrate/source/EmbeddedDataSource.php
Gets the source count.
EmptySource::count in core/modules/migrate/src/Plugin/migrate/source/EmptySource.php
Gets the source count.
SqlBase::count in core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
Gets the source count.

File

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

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;
}