You are here

public function backup_migrate_source_db_mysql::sources in Backup and Migrate 7.3

Same name and namespace in other branches
  1. 8.3 includes/sources.db.mysql.inc \backup_migrate_source_db_mysql::sources()
  2. 6.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 79
Functions to handle the direct to database source.

Class

backup_migrate_source_db_mysql
A source type for backing up from database server.

Code

public 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') {

        // Compile the database connection string.
        $url = 'mysql://';
        $url .= urlencode($info['username']) . ':' . urlencode($info['password']);
        $url .= '@';
        $url .= urlencode($info['host']);
        if (!empty($info['port'])) {
          $url .= ':' . $info['port'];
        }
        $url .= '/' . urlencode($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;
}