You are here

function backup_migrate_destination_files::_save_file in Backup and Migrate 8.2

Same name and namespace in other branches
  1. 8.3 includes/destinations.file.inc \backup_migrate_destination_files::_save_file()
  2. 6.3 includes/destinations.file.inc \backup_migrate_destination_files::_save_file()
  3. 7.3 includes/destinations.file.inc \backup_migrate_destination_files::_save_file()
  4. 7.2 includes/destinations.file.inc \backup_migrate_destination_files::_save_file()

File save destination callback.

Overrides backup_migrate_destination::_save_file

File

includes/destinations.file.inc, line 32
A destination type for saving locally to the server.

Class

backup_migrate_destination_files
A destination type for saving locally to the server.

Code

function _save_file($file, $settings) {
  if ($dir = $this
    ->get_location()) {
    if ($dir = $this
      ->check_dir($dir)) {
      $filepath = rtrim($dir, "/") . "/" . $file
        ->filename();
      if (file_unmanaged_move($file
        ->filepath(), $filepath)) {

        // chmod, chown and chgrp the file if needed.
        if ($chmod = $this
          ->settings('chmod')) {
          if (!@drupal_chmod($filepath, octdec($chmod))) {
            _backup_migrate_message('Unable to set the file mode for: @file', array(
              '@file' => $filepath,
            ), 'error');
          }
        }
        if ($chgrp = $this
          ->settings('chgrp')) {
          if (!@chgrp($filepath, $chgrp)) {
            _backup_migrate_message('Unable to set the file group for: @file', array(
              '@file' => $filepath,
            ), 'error');
          }
        }
        return $file;
      }
      else {
        _backup_migrate_message('Unable to save the file to the directory: @dir', array(
          '@dir' => $dir,
        ), 'error');
      }
    }
  }
}