function backup_migrate_destination_dropbox::edit_form_submit in Backup and Migrate Dropbox 7.3
Same name and namespace in other branches
- 7 destinations.dropbox.inc \backup_migrate_destination_dropbox::edit_form_submit()
- 7.2 destinations.dropbox.inc \backup_migrate_destination_dropbox::edit_form_submit()
Handles the form submission.
Note that the settings property of this destination object will be overwritten, not merged, by the 'settings' value in $form_state['values'].
Therefore we have to explicitly set all values that are not on the form submission, i.e. the refresh_token.
_state
Parameters
array $form:
File
- ./
destinations.dropbox.inc, line 203 - 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) {
// Save the refresh token again.
$form_state['values']['settings']['refresh_token'] = $this
->settings('refresh_token');
// Sub folder: strip any / and \ at begin and end.
$form_state['values']['path'] = trim($form_state['values']['path'], '/\\');
// Has the access code been filled in and changed?
if (!empty($form_state['values']['access_code'])) {
// Access code has changed: obtain a new refresh token and first bearer
// token, but we need our id (machine name) to be set (to be able to store
// the bearer token).
$this
->from_array($form_state['values']);
$form_state['values']['settings']['refresh_token'] = $this
->get_dropbox_api()
->obtain_refresh_token($form_state['values']['access_code'], $form['code_verifier']['#value']);
// Different code may mean different Dropbox account: clear the file list.
$this
->file_cache_clear();
}
// Now we can save all values.
parent::edit_form_submit($form, $form_state);
// Now, with all values in place, we create the sub folder.
if (!empty($form_state['values']['path'])) {
// Create folder and clear the file list cache if it was changed.
$path = $this->dest_url['path'];
try {
$this
->get_dropbox_api()
->create_folder($path);
// No exception: folder has been changed and created: tell user and
// clear the file list
drupal_set_message(t("The folder '%path' has been created in your Dropbox app folder", [
'%path' => $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 ($path !== $form['path']['#default_value']) {
$this
->file_cache_clear();
}
}
else {
watchdog('backup_migrate', 'Backup Migrate Dropbox Error: ' . $e
->getMessage(), [], WATCHDOG_ERROR);
drupal_set_message('Backup Migrate Dropbox Error: ' . $e
->getMessage(), 'error');
}
}
}
}