class DbDumpCommand extends DbCommandBase (View source)

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

This script exports all tables in the given database, and all data (except for tables denoted as schema-only). The resulting script creates the tables and populates them with the exported data.

This command is currently only compatible with MySQL. Making it backend-agnostic will require \Drupal\Core\Database\Schema support the ability to retrieve table schema information. Note that using a raw SQL dump file here (eg, generated from mysqldump or pg_dump) is not an option since these tend to still be database-backend specific.

Properties

protected array $excludeTables

An array of table patterns to exclude completely.

Methods

configure()

{@inheritdoc}

getDatabaseConnection(InputInterface $input)

Parse input options decide on a database.

int
execute(InputInterface $input, OutputInterface $output)

{@inheritdoc}

string
generateScript(Connection $connection, array $schema_only = [])

Generates the database script.

array
getTables(Connection $connection)

Returns a list of tables, not including those set to be excluded.

array
getTableSchema(Connection $connection, string $table)

Returns a schema array for a given table.

getTableIndexes(Connection $connection, string $table, array $definition)

Adds primary key, unique keys, and index information to the schema.

getTableCollation(Connection $connection, string $table, array $definition)

Set the table collation.

array
getTableData(Connection $connection, string $table)

Gets all data from a given table.

string
fieldTypeMap(Connection $connection, string $type)

Given a database field type, return a Drupal type.

string|null
fieldSizeMap(Connection $connection, string $type)

Given a database field type, return a Drupal size.

string
getFieldOrder(Connection $connection, string $table)

Gets field ordering for a given table.

string
getTemplate()

The script template.

string
getTableScript(string $table, array $schema, array $data)

The part of the script for each table.

Details

protected configure()

{@inheritdoc}

protected Connection getDatabaseConnection(InputInterface $input)

Parse input options decide on a database.

Parameters

InputInterface $input

Input object.

Return Value

Connection

protected int execute(InputInterface $input, OutputInterface $output)

{@inheritdoc}

Parameters

InputInterface $input
OutputInterface $output

Return Value

int

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

Generates the database script.

Parameters

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.

protected array getTables(Connection $connection)

Returns a list of tables, not including those set to be excluded.

Parameters

Connection $connection

The database connection to use.

Return Value

array

An array of table names.

protected array getTableSchema(Connection $connection, string $table)

Returns a schema array for a given table.

This implementation is hard-coded for MySQL.

Parameters

Connection $connection

The database connection to use.

string $table

The table name.

Return Value

array

A schema array (as defined by hook_schema()).

protected getTableIndexes(Connection $connection, string $table, array $definition)

Adds primary key, unique keys, and index information to the schema.

Parameters

Connection $connection

The database connection to use.

string $table

The table to find indexes for.

array $definition

The schema definition to modify.

protected getTableCollation(Connection $connection, string $table, array $definition)

Set the table collation.

Parameters

Connection $connection

The database connection to use.

string $table

The table to find indexes for.

array $definition

The schema definition to modify.

protected array getTableData(Connection $connection, string $table)

Gets all data from a given table.

If a table is set to be schema only, and empty array is returned.

Parameters

Connection $connection

The database connection to use.

string $table

The table to query.

Return Value

array

The data from the table as an array.

protected string fieldTypeMap(Connection $connection, string $type)

Given a database field type, return a Drupal type.

Parameters

Connection $connection

The database connection to use.

string $type

The MySQL field type.

Return Value

string

The Drupal schema field type. If there is no mapping, the original field type is returned.

protected string|null fieldSizeMap(Connection $connection, string $type)

Given a database field type, return a Drupal size.

Parameters

Connection $connection

The database connection to use.

string $type

The MySQL field type.

Return Value

string|null

The Drupal schema field size.

protected string getFieldOrder(Connection $connection, string $table)

Gets field ordering for a given table.

Parameters

Connection $connection

The database connection to use.

string $table

The table name.

Return Value

string

The order string to append to the query.

protected string getTemplate()

The script template.

Return Value

string

The template for the generated PHP script.

protected string getTableScript(string $table, array $schema, array $data)

The part of the script for each table.

Parameters

string $table

Table name.

array $schema

Drupal schema definition.

array $data

Data for the table.

Return Value

string

The table create statement, and if there is data, the insert command.