You are here

function backup_migrate_update_7310 in Backup and Migrate 7.3

Disable e-mail destinations.

1 call to backup_migrate_update_7310()
BmTestUpdate7310::testUpdate7310 in tests/BmTestUpdate7310.test
Test update 7310.
1 string reference to 'backup_migrate_update_7310'
BmTestUpdate7310::testUpdate7310 in tests/BmTestUpdate7310.test
Test update 7310.

File

./backup_migrate.install, line 992
Install hooks for Backup and Migrate.

Code

function backup_migrate_update_7310() {
  $out = '';

  // Disable scheduled e-mail back-ups to allow users to review their
  // destinations first.
  //
  // Which e-mail destinations exist?
  $destinations = db_select('backup_migrate_destinations', 'bmd')
    ->fields('bmd', array(
    'machine_name',
  ))
    ->condition('subtype', 'email', '=')
    ->execute()
    ->fetchAllAssoc('machine_name', PDO::FETCH_ASSOC);
  $destinations = array_keys($destinations);
  if (!empty($destinations)) {

    // Which schedules contain enabled e-mail destinations?
    $or = db_or();
    $or
      ->condition('destination_id', $destinations, 'IN');
    $or
      ->condition('copy_destination_id', $destinations, 'IN');
    $schedules_query = db_select('backup_migrate_schedules', 'bms')
      ->fields('bms', array(
      'schedule_id',
      'name',
    ))
      ->condition($or)
      ->condition('enabled', 1, '=');
    $schedules = $schedules_query
      ->execute()
      ->fetchAllAssoc('schedule_id', PDO::FETCH_ASSOC);

    // Disable the relevant schedules.
    if (count($schedules) > 0) {
      $email_schedules = array_keys($schedules);
      $names = array_map(function ($name) {
        return $name['name'];
      }, $schedules);
      $replacements = array(
        '@schedules' => '<ul><li>' . implode('</li><li>', $names) . '</li></ul>',
      );
      db_update('backup_migrate_schedules')
        ->fields([
        'enabled' => '0',
      ])
        ->condition('schedule_id', $email_schedules, 'IN')
        ->execute();
      $out .= t('Schedules that back up to e-mail destinations have been disabled. Check that you are using the correct e-mail addresses, then re-enable manually. The following schedules have been disabled: @schedules', $replacements);
    }
  }
  if (!empty($out)) {
    return $out;
  }
  else {
    return t('No destinations were affected by this change.');
  }
}