You are here

public function MigrateSource::count in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 includes/source.inc \MigrateSource::count()

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

Parameters

boolean $refresh:

File

includes/source.inc, line 135
Define base for migration sources.

Class

MigrateSource
Abstract base class for source handling.

Code

public function count($refresh = FALSE) {
  if ($this->skipCount) {
    return -1;
  }
  if (!isset($this->cacheKey)) {
    $this->cacheKey = md5((string) $this);
  }

  // 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
      ->computeCount();
    cache_set($this->cacheKey, $count, 'cache');
  }
  else {

    // Caching is in play, first try to retrieve a cached count.
    $cache_object = cache_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
        ->computeCount();
      cache_set($this->cacheKey, $count, 'cache');
    }
  }
  return $count;
}