Exemple #1
0
 /**
  * Test loading the script back into the database.
  */
 public function testScriptLoad()
 {
     if ($this->skipTests) {
         $this->pass("Skipping test since the DbDumpCommand is currently only compatible with MySql");
         return;
     }
     // Generate the script.
     $application = new DbDumpApplication(Database::getConnection(), $this->container->get('module_handler'));
     $command = $application->find('dump-database-d8-mysql');
     $command_tester = new CommandTester($command);
     $command_tester->execute([]);
     $script = $command_tester->getDisplay();
     // Store original schemas and drop tables to avoid errors.
     foreach ($this->tables as $table) {
         $this->originalTableSchemas[$table] = $this->getTableSchema($table);
         $this->originalTableIndexes[$table] = $this->getTableIndexes($table);
         Database::getConnection()->schema()->dropTable($table);
     }
     // This will load the data.
     $file = sys_get_temp_dir() . '/' . $this->randomMachineName();
     file_put_contents($file, $script);
     require_once $file;
     // The tables should now exist and the schemas should match the originals.
     foreach ($this->tables as $table) {
         $this->assertTrue(Database::getConnection()->schema()->tableExists($table), SafeMarkup::format('Table @table created by the database script.', ['@table' => $table]));
         $this->assertIdentical($this->originalTableSchemas[$table], $this->getTableSchema($table), SafeMarkup::format('The schema for @table was properly restored.', ['@table' => $table]));
         $this->assertIdentical($this->originalTableIndexes[$table], $this->getTableIndexes($table), SafeMarkup::format('The indexes for @table were properly restored.', ['@table' => $table]));
     }
     // Ensure the test config has been replaced.
     $config = unserialize(db_query("SELECT data FROM {config} WHERE name = 'test_config'")->fetchField());
     $this->assertIdentical($config, $this->data, 'Script has properly restored the config table data.');
     // Ensure the cache data was not exported.
     $this->assertFalse(\Drupal::cache('discovery')->get('test'), 'Cache data was not exported to the script.');
 }
#!/usr/bin/env php
<?php 
use Drupal\Core\Command\DbDumpApplication;
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
if (PHP_SAPI !== 'cli') {
    return;
}
// Bootstrap.
$autoloader = (require __DIR__ . '/../../autoload.php');
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
$application = new DbDumpApplication(Database::getConnection(), \Drupal::moduleHandler());
$application->run();