function Resource::delete in D7 Media 6
Delete a file and its database record.
Parameters
$force: Boolean indicating that the file should be deleted even if hook_file_references() reports that the file is in use.
Return value
mixed TRUE for success, array for reference count, or FALSE in the event of an error.
See also
hook_file_references()
File
- resource/
resource.module, line 220 - Resource API for Drupal, a replacement for files.
Class
- Resource
- Base Resource class.
Code
function delete($force = FALSE) {
// If any module returns a value from the reference hook, the
// file will not be deleted from Drupal, but file_delete will
// return a populated array that tests as TRUE.
if (!$force && ($references = module_invoke_all('resource', $this))) {
return $references;
}
// Let other modules clean up on delete.
module_invoke_all('resource_delete', $this);
// Make sure the file is deleted before removing its row from the
// database, so UIs can still find the file in the database.
if (unlink($this->url)) {
db_query('DELETE FROM {resource} WHERE rid = %d', $this->rid);
// remove internally used static cache entries.
$this
->reset_cache('rid::' . $this->rid);
$this
->reset_cache('url::' . $this->url);
return TRUE;
}
return FALSE;
}