You are here

protected function Sql::countHelper in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/src/Plugin/migrate/id_map/Sql.php \Drupal\migrate\Plugin\migrate\id_map\Sql::countHelper()

Counts records in a table.

Parameters

int|array $status: (optional) Status code(s) to filter the source_row_status column.

string $table: (optional) The table to work. Defaults to NULL.

Return value

int The number of records.

5 calls to Sql::countHelper()
Sql::errorCount in core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
Returns the number of items that failed to import.
Sql::importedCount in core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
Returns the number of imported items in the map.
Sql::messageCount in core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
Returns the number of messages saved.
Sql::processedCount in core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
Returns the number of processed items in the map.
Sql::updateCount in core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
Returns a count of items which are marked as needing update.

File

core/modules/migrate/src/Plugin/migrate/id_map/Sql.php, line 777

Class

Sql
Defines the sql based ID map implementation.

Namespace

Drupal\migrate\Plugin\migrate\id_map

Code

protected function countHelper($status = NULL, $table = NULL) {

  // Use database directly to avoid creating tables.
  $query = $this->database
    ->select($table ?: $this
    ->mapTableName());
  if (isset($status)) {
    $query
      ->condition('source_row_status', $status, is_array($status) ? 'IN' : '=');
  }
  try {
    $count = (int) $query
      ->countQuery()
      ->execute()
      ->fetchField();
  } catch (DatabaseException $e) {

    // The table does not exist, therefore there are no records.
    $count = 0;
  }
  return $count;
}