You are here

function backup_migrate_destination_dropbox::save_file in Backup and Migrate Dropbox 7

Same name and namespace in other branches
  1. 6.2 destinations.dropbox.inc \backup_migrate_destination_dropbox::save_file()
  2. 6 destinations.dropbox.inc \backup_migrate_destination_dropbox::save_file()
  3. 7.3 destinations.dropbox.inc \backup_migrate_destination_dropbox::save_file()
  4. 7.2 destinations.dropbox.inc \backup_migrate_destination_dropbox::save_file()

Save to to the Dropbox destination.

File

./destinations.dropbox.inc, line 20
destinations.dropbox.inc

Class

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

Code

function save_file($file, $settings) {

  // Set up a temporary file to transfer up to dropbox.
  $filename = $file->file_info['filename'] . '.' . implode('.', $file->ext);
  $destination_filename = realpath(variable_get('file_temporary_path', '')) . '/' . $filename;
  rename($file
    ->filepath(), $destination_filename);

  // Initialize the dropbox api.
  module_load_include('inc', 'backup_migrate_dropbox', 'backup_migrate_dropbox.dropbox_api');
  $dropbox_api = new BackupMigrateDropboxAPI();
  $token = $this
    ->settings('token');
  $dropbox_api
    ->setToken($token);
  $path = '/' . $this->dest_url['path'] . '/' . $filename;
  try {
    $dropbox_api
      ->file_upload($destination_filename, $path);
  } catch (exception $e) {
    watchdog('backup_migrate', 'Backup Migrate Dropbox Error: ' . $e
      ->getMessage(), array(), WATCHDOG_ERROR);
    drupal_set_message('Backup Migrate Dropbox Error: ' . $e
      ->getMessage(), 'error');
    return NULL;
  }
  return $file;
}