function DbDumpCommand::getTemplate

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

The script template.

Return value

string The template for the generated PHP script.

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

File

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

Class

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

Namespace

Drupal\Core\Command

Code

protected function getTemplate() {
    // The template contains an instruction for the file to be ignored by PHPCS.
    // This is because the files can be huge and coding standards are
    // irrelevant.
    $script = <<<'END_OF_SCRIPT'
<?php
// phpcs:ignoreFile
/**
 * @file
 * A database agnostic dump for testing purposes.
 *
 * This file was generated by the Drupal {{VERSION}} db-tools.php script.
 */

use Drupal\Core\Database\Database;

$connection = Database::getConnection();
// Ensure any tables with a serial column with a value of 0 are created as
// expected.
if ($connection->databaseType() === 'mysql') {
  $sql_mode = $connection->query("SELECT @@sql_mode;")->fetchField();
  $connection->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'");
}

{{TABLES}}

// Reset the SQL mode.
if ($connection->databaseType() === 'mysql') {
  $connection->query("SET sql_mode = '$sql_mode'");
}
END_OF_SCRIPT;
    return $script;
}

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