function media_filter_track_usage in D7 Media 7
Tracks usage of media fids by the media filter.
Parameters
$fid: The media fid.
1 call to media_filter_track_usage()
- media_token_to_markup in includes/
media.filter.inc - Replace callback to convert a media file tag into HTML markup.
File
- includes/
media.filter.inc, line 695 - Functions related to the WYSIWYG editor and the media input filter.
Code
function media_filter_track_usage($fid) {
// This function only tracks when fids are found by the media filter.
// It would be impractical to check when formatted text is edited to remove
// references to fids, however by keeping a timestamp, we can implement
// rudimentary garbage collection in hook_flush_caches().
// However we only need to track that an fid has ever been referenced,
// not every time, so avoid updating this table more than once per month,
// per fid.
$timestamp = db_query('SELECT timestamp FROM {media_filter_usage} WHERE fid = :fid', array(
':fid' => $fid,
))
->fetchField();
if (!$timestamp || $timestamp <= REQUEST_TIME - 86400 * 30) {
db_merge('media_filter_usage')
->key(array(
'fid' => $fid,
))
->fields(array(
'fid' => $fid,
'timestamp' => REQUEST_TIME,
))
->execute();
}
}