You are here

function backup_migrate_destination_dropbox::edit_form_submit in Backup and Migrate Dropbox 7.2

Same name and namespace in other branches
  1. 7.3 destinations.dropbox.inc \backup_migrate_destination_dropbox::edit_form_submit()
  2. 7 destinations.dropbox.inc \backup_migrate_destination_dropbox::edit_form_submit()

Submit the form for the settings for the files destination.

_state

Parameters

array $form:

File

./destinations.dropbox.inc, line 251
destinations.dropbox.inc

Class

backup_migrate_destination_dropbox
A destination for sending database backups to a Dropbox account.

Code

function edit_form_submit($form, &$form_state) {

  // Add the token.
  $form_state['values']['settings']['token'] = $form_state['values']['token'];
  if ($form_state['values']['token'] !== $this
    ->settings('token')) {
    $form_state['values']['settings']['token'] = $form_state['values']['token'];

    // Different token may mean different Dropbox folder: clear the file list.
    $this
      ->file_cache_clear();

    // We need this new token right away to create the folder.

    /** @noinspection PhpUndefinedFieldInspection */
    $this->settings['token'] = $form_state['values']['token'];
  }

  // Strip any / at begin and end.
  $form_state['values']['path'] = trim($form_state['values']['path'], '/');
  if (!empty($form_state['values']['path'])) {

    // Create folder and clear the file list cache if it was changed.
    try {
      $this
        ->getDropboxApi()
        ->create_folder($form_state['values']['path']);
      drupal_set_message(t("The folder '%path' has been created in your Dropbox app folder", array(
        '%path' => $form_state['values']['path'],
      )), 'status');
      $this
        ->file_cache_clear();
    } catch (Exception $e) {
      if (strpos($e
        ->getMessage(), 'path/conflict/folder') !== FALSE) {

        // Do not display "Folder already exists" messages, as these are not
        // errors. However, check if the path was changed, so we can clear the
        // file list cache.
        if ($form_state['values']['path'] !== $this->dest_url['path']) {
          $this
            ->file_cache_clear();
        }
      }
      else {
        watchdog('backup_migrate', 'Backup Migrate Dropbox Error: ' . $e
          ->getMessage(), array(), WATCHDOG_ERROR);
        drupal_set_message('Backup Migrate Dropbox Error: ' . $e
          ->getMessage(), 'error');
      }
    }
  }

  // Store the app name.
  $form_state['values']['settings']['app_name'] = $form_state['values']['app_name'];
  parent::edit_form_submit($form, $form_state);
}