function SourcePluginBase::count

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php \Drupal\migrate\Plugin\migrate\source\SourcePluginBase::count()
  2. 10 core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php \Drupal\migrate\Plugin\migrate\source\SourcePluginBase::count()
  3. 11.x core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php \Drupal\migrate\Plugin\migrate\source\SourcePluginBase::count()

Gets the source count.

Return a count of available source records, from the cache if appropriate. Returns MigrateSourceInterface::NOT_COUNTABLE 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 calls to SourcePluginBase::count()
CacheableEmbeddedDataSource::count in core/modules/migrate/tests/modules/migrate_cache_counts_test/src/Plugin/migrate/source/CacheableEmbeddedDataSource.php
Gets the source count.
ContentEntity::count in core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php
Gets the source count.
Variable::initializeIterator in core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php
Initializes the iterator with the source data.
2 methods override SourcePluginBase::count()
ContentEntity::count in core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php
Gets the source count.
EmbeddedDataSource::count in core/modules/migrate/src/Plugin/migrate/source/EmbeddedDataSource.php
Gets the source count.

File

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

Class

SourcePluginBase
The base class for source plugins.

Namespace

Drupal\migrate\Plugin\migrate\source

Code

public function count($refresh = FALSE) {
    if ($this->skipCount) {
        return MigrateSourceInterface::NOT_COUNTABLE;
    }
    // Return the cached count if we are caching counts and a refresh is not
    // requested.
    if ($this->cacheCounts && !$refresh) {
        $cache_object = $this->getCache()
            ->get($this->cacheKey, 'cache');
        if (is_object($cache_object)) {
            return $cache_object->data;
        }
    }
    $count = $this->doCount();
    // Update the cache if we are caching counts.
    if ($this->cacheCounts) {
        $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.