You are here

class FeedsEnclosureUnique in Feeds Atom 6

Same name and namespace in other branches
  1. 7 plugins/FeedsAtomRDFProcessor.inc \FeedsEnclosureUnique

Specialized version of FeedsEnclosure to ensure uniqueness when saving.

Hierarchy

Expanded class hierarchy of FeedsEnclosureUnique

File

plugins/FeedsAtomRDFProcessor.inc, line 245
Contains the feeds atom RDF processor class.

View source
class FeedsEnclosureUnique extends FeedsEnclosure {

  /**
   * Saves the file represented by this enclosure to disk.
   *
   * If the file already exists, based on its sha1() hash, then we will simply
   * reuse the existing file rather than saving a new one.
   *
   * @param $target_dir
   *   The directory to which to save the file.  Note that if the file has already
   *   been imported it is possible that it will not be in the requested directory,
   *   in which case this method returns the existing file info in its existing
   *   location.
   * @return
   *   The file info array as defined by filefield of the file that we just saved,
   *   or of the pre-existing file that should be used instead.
   */
  public function saveTo($target_dir) {
    $new_file_hash = sha1_file($this->file);
    $fid = db_result(db_query("SELECT fid FROM {feeds_atom_file_import} WHERE sha1 = '%s'", $new_file_hash));
    if ($fid) {

      // Pull the info for the existing file and return that. We won't save
      // the new file at all.
      $info = field_file_load($fid);
      return $info;
    }
    else {

      // Save the new file, and record its hash for later matching.
      $info = field_file_save_file($this->file, array(), $target_dir);
      db_query("INSERT INTO {feeds_atom_file_import} (fid, sha1) VALUES (%d, '%s')", $info['fid'], $new_file_hash);
      return $info;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsElement::$value protected property
FeedsElement::getValue public function @todo Make value public and deprecate use of getValue(). 3
FeedsElement::__toString public function 1
FeedsEnclosure::$delete_file protected property Delete flag, denoting whether a file should be deleted when this object is destroyed.
FeedsEnclosure::$file protected property
FeedsEnclosure::$mime_type protected property
FeedsEnclosure::getContent public function
FeedsEnclosure::getFile public function @todo Get file extension from mime_type. @todo This is not concurrency safe.
FeedsEnclosure::getMIMEType public function 1
FeedsEnclosure::__construct public function Constructor, requires MIME type. Overrides FeedsElement::__construct 1
FeedsEnclosure::__destruct public function Destructor, clean up any temporary files.
FeedsEnclosureUnique::saveTo public function Saves the file represented by this enclosure to disk.