function DbDumpCommand::getTableScript

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Command/DbDumpCommand.php \Drupal\Core\Command\DbDumpCommand::getTableScript()
  2. 10 core/lib/Drupal/Core/Command/DbDumpCommand.php \Drupal\Core\Command\DbDumpCommand::getTableScript()
  3. 11.x core/lib/Drupal/Core/Command/DbDumpCommand.php \Drupal\Core\Command\DbDumpCommand::getTableScript()

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.

1 call to DbDumpCommand::getTableScript()
DbDumpCommand::generateScript in core/lib/Drupal/Core/Command/DbDumpCommand.php
Generates the database script.

File

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

Class

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

Namespace

Drupal\Core\Command

Code

protected function getTableScript($table, array $schema, array $data) {
    $output = '';
    $output .= "\$connection->schema()->createTable('" . $table . "', " . Variable::export($schema) . ");\n\n";
    if (!empty($data)) {
        $insert = '';
        foreach ($data as $record) {
            $insert .= "->values(" . Variable::export($record) . ")\n";
        }
        $fields = Variable::export(array_keys($schema['fields']));
        $output .= <<<EOT
\$connection->insert('{<span class="php-variable">$table</span>}')
->fields({<span class="php-variable">$fields</span>})
{<span class="php-variable">$insert</span>}->execute();

EOT;
    }
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.