protected function DbDumpCommand::generateScript in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Command/DbDumpCommand.php \Drupal\Core\Command\DbDumpCommand::generateScript()
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.
1 call to DbDumpCommand::generateScript()
- DbDumpCommand::execute in core/
lib/ Drupal/ Core/ Command/ DbDumpCommand.php - Executes the current command.
File
- core/
lib/ Drupal/ Core/ Command/ DbDumpCommand.php, line 77
Class
- DbDumpCommand
- Provides a command to dump the current database to a script.
Namespace
Drupal\Core\CommandCode
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 version.
$script = str_replace('{{VERSION}}', \Drupal::VERSION, $script);
// Substitute in the tables.
$script = str_replace('{{TABLES}}', trim($tables), $script);
return trim($script);
}