You are here

public function MailhandlerAttachmentEnclosure::getFile in Mailhandler 7.2

Same name and namespace in other branches
  1. 6.2 plugins/mailhandler/commands/MailhandlerCommandsFiles.class.php \MailhandlerAttachmentEnclosure::getFile()

Save the attachment data the same way as the parent class for remote files.

File

plugins/mailhandler/commands/MailhandlerCommandsFiles.class.php, line 111
MailhandlerCommandsFiles class.

Class

MailhandlerAttachmentEnclosure
Attachment enclosure, can be part of the result array.

Code

public function getFile($destination, $replace = FILE_EXISTS_RENAME) {
  $file = FALSE;
  if ($this
    ->getValue()) {

    // Prepare destination directory.
    file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);

    // Save the file.
    if (file_uri_target($destination)) {
      $destination = trim($destination, '/') . '/';
    }
    try {
      $filename = $this
        ->getLocalValue();
      if (module_exists('transliteration')) {
        require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
        $filename = transliteration_clean_filename($filename);
      }
      $file = file_save_data($this
        ->getContent(), $destination . $filename, $replace);
    } catch (Exception $e) {
      watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
    }

    // We couldn't make sense of this enclosure, throw an exception.
    if (!$file) {
      throw new Exception(t('Invalid enclosure %enclosure', array(
        '%enclosure' => $this
          ->getValue(),
      )));
    }
    return $file;
  }
}