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

Breadcrumb

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

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

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

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 81

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 = [], int $insert_count = 1000) {
    $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, $insert_count);
    }
    $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);
}

API Navigation

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