You are here

public function backup_migrate_destination_db_mysql::destinations in Backup and Migrate 7.3

Same name and namespace in other branches
  1. 8.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::destinations()
  2. 8.3 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::destinations()
  3. 6.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::destinations()
  4. 7.2 includes/destinations.db.mysql.inc \backup_migrate_destination_db_mysql::destinations()

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

File

includes/destinations.db.mysql.inc, line 72
Functions to handle the direct to database destination.

Class

backup_migrate_destination_db_mysql
A destination type for saving to a database server.

Code

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

      // Only mysql/mysqli supported by this destination.
      $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 ($destination = 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') {
            $destination
              ->set_id('db');
            $destination
              ->set_name(t('Default Database'));

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