class FeedsEnclosureUnique in Feeds Atom 6
Same name and namespace in other branches
- 7 plugins/FeedsAtomRDFProcessor.inc \FeedsEnclosureUnique
Specialized version of FeedsEnclosure to ensure uniqueness when saving.
Hierarchy
- class \FeedsElement
- class \FeedsEnclosure
- class \FeedsEnclosureUnique
- class \FeedsEnclosure
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsElement:: |
protected | property | ||
FeedsElement:: |
public | function | @todo Make value public and deprecate use of getValue(). | 3 |
FeedsElement:: |
public | function | 1 | |
FeedsEnclosure:: |
protected | property | Delete flag, denoting whether a file should be deleted when this object is destroyed. | |
FeedsEnclosure:: |
protected | property | ||
FeedsEnclosure:: |
protected | property | ||
FeedsEnclosure:: |
public | function | ||
FeedsEnclosure:: |
public | function | @todo Get file extension from mime_type. @todo This is not concurrency safe. | |
FeedsEnclosure:: |
public | function | 1 | |
FeedsEnclosure:: |
public | function |
Constructor, requires MIME type. Overrides FeedsElement:: |
1 |
FeedsEnclosure:: |
public | function | Destructor, clean up any temporary files. | |
FeedsEnclosureUnique:: |
public | function | Saves the file represented by this enclosure to disk. |