DbDumpCommand::generateScript

protected DbDumpCommand::generateScript(Connection $connection, array $schema_only = [])

Generates the database script.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection to use.

array $schema_only: Table patterns for which to only dump the schema, no data.

Return value

string The PHP script. The PHP script.

File

core/lib/Drupal/Core/Command/DbDumpCommand.php, line 75

Class

DbDumpCommand
Provides a command to dump the current database to a script.

Namespace

Drupal\Core\Command

Code

protected function generateScript(Connection $connection, array $schema_only = []) {
  $tables = '';

  $schema_only_patterns = [];
  foreach ($schema_only as $match) {
    $schema_only_patterns[] = '/^' . $match . '$/';
  }

  foreach ($this->getTables($connection) as $table) {
    $schema = $this->getTableSchema($connection, $table);
    // Check for schema only.
    if (empty($schema_only_patterns) || preg_replace($schema_only_patterns, '', $table)) {
      $data = $this->getTableData($connection, $table);
    }
    else {
      $data = [];
    }
    $tables .= $this->getTableScript($table, $schema, $data);
  }
  $script = $this->getTemplate();
  // Substitute in the tables.
  $script = str_replace('{{TABLES}}', trim($tables), $script);
  return trim($script);
}
doc_Drupal
2016-10-29 09:01:08
Comments
Leave a Comment

Please login to continue.