1 backup.database.inc | public BackupDatabase::defaultSettings() |
Get the default settings for this object.
Return value
array: The default tables whose data can be ignored. These tables mostly contain info which can be easily reproduced (such as cache or search index) but also tables which can become quite bloated but are not necessarily extremely important to back up or migrate during development (such as access log and watchdog).
Overrides Backup::defaultSettings
File
- core/
includes/ backup/ backup.database.inc, line 62 - Functions to handle the direct to/from database backup source.
Class
- BackupDatabase
- A destination type for saving to a database server.
Code
public function defaultSettings() {
$settings = parent::defaultSettings();
$all_tables = $this->getTableNames();
$connection = $this->getDatabaseConnection();
$prefixes = $connection->getPrefixes();
// Check if a default database prefix is set. If in use, only back up the
// tables within that prefix. If prefixes exist for some tables but there
// is no default prefix, maintain the normal behavior of just allowing all
// tables.
$prefixed_tables = array();
$default_prefix = isset($prefixes['default']) ? $prefixes['default'] : NULL;
if ($default_prefix) {
unset($prefixes['default']);
foreach ($all_tables as $table) {
foreach ($prefixes as $non_prefixed_table => $prefix) {
if ($table == $prefix . $non_prefixed_table) {
$prefixed_tables[] = $table;
}
}
if (strpos($table, $default_prefix) === 0) {
$prefixed_tables[] = $table;
}
}
}
// Identify all cache tables as no-data tables.
$nodata_tables = array('cache');
foreach ($all_tables as $table_name) {
if (strpos($table_name, 'cache_') === 0) {
$nodata_tables[] = $table_name;
}
}
// Prefix all the hard-coded no-data tables.
foreach ($nodata_tables as $index => $table) {
$nodata_tables[$index] = $connection->tablePrefix($table) . $table;
}
// Simpletest can create a lot of tables that do not need to be backed up,
// but all of them start with the string 'simpletest' so they can be easily
// excluded.
$simpletest_tables = array();
$valid_simpletest_tables = array(
'simpletest',
'simpletest_prefix',
);
foreach ($valid_simpletest_tables as $index => $table) {
$valid_simpletest_tables[$index] = $connection->tablePrefix($table) . $table;
}
// When assembling the simpletest tables to exclude, make sure to not
// exclude a prefixed table (meaning this backup is happening as part of a
// SimpleTest execution).
foreach ($all_tables as $table_name) {
if (strpos($table_name, 'simpletest') === 0 &&
!in_array($table_name, $valid_simpletest_tables) &&
!in_array($table_name, $prefixed_tables)) {
$simpletest_tables[] = $table_name;
}
}
$included_tables = array();
$excluded_tables = array();
if ($prefixed_tables) {
$included_tables = $prefixed_tables;
}
elseif ($simpletest_tables) {
$excluded_tables = $simpletest_tables;
}
$settings += array(
'nodata_tables' => $nodata_tables,
'exclude_tables' => $excluded_tables,
'include_tables' => $included_tables,
'lock_tables' => FALSE,
'compression' => self::COMPRESSION_GZIP,
);
return $settings;
}