You are here

function backup_migrate_source_db_mysql::sources in Backup and Migrate 8.3

Same name and namespace in other branches
  1. 6.3 includes/sources.db.mysql.inc \backup_migrate_source_db_mysql::sources()
  2. 7.3 includes/sources.db.mysql.inc \backup_migrate_source_db_mysql::sources()

Declare any mysql databases defined in the settings.php file as a possible source.

File

includes/sources.db.mysql.inc, line 52
Functions to handle the direct to database source.

Class

backup_migrate_source_db_mysql
A source type for backing up from database server.

Code

function sources() {
  $out = array();
  global $databases;
  foreach ((array) $databases as $db_key => $target) {
    foreach ((array) $target as $tgt_key => $info) {

      // Only mysql/mysqli supported by this source.
      $key = $db_key . ':' . $tgt_key;
      if ($info['driver'] === 'mysql') {
        $url = $info['driver'] . '://' . $info['username'] . ':' . $info['password'] . '@' . $info['host'] . (isset($info['port']) ? ':' . $info['port'] : '') . '/' . $info['database'];
        if ($source = backup_migrate_create_destination('mysql', array(
          'url' => $url,
        ))) {

          // Treat the default database differently because it is probably the only one available.
          if ($key == 'default:default') {
            $source
              ->set_id('db');
            $source
              ->set_name(t('Default Database'));

            // Dissalow backing up to the default database because that's confusing and potentially dangerous.
            $source
              ->remove_op('scheduled backup');
            $source
              ->remove_op('manual backup');
          }
          else {
            $source
              ->set_id('db:' . $key);
            $source
              ->set_name($key . ": " . $source
              ->get_display_location());
          }
          $out[$source
            ->get_id()] = $source;
        }
      }
    }
  }
  return $out;
}