Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DbDumpCommand.php

function 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.

int $insert_count: The number of rows to insert in a single statement.

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 452

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, int $insert_count = 1000) {
    $output = '';
    $output .= "\$connection->schema()->createTable('" . $table . "', " . Variable::export($schema) . ");\n\n";
    if (!empty($data)) {
        $data_chunks = array_chunk($data, $insert_count);
        foreach ($data_chunks as $data_chunk) {
            $insert = '';
            foreach ($data_chunk 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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal