Problem/Motivation
When manually constructing a download url as the Media Entity Download project description explains:
$url = Url::fromRoute(
'media_entity_download.download',
[
'media' => $media_id,
],
[
'query' => [
'delta' => $delta,
],
]
);The counter is not incremented.
Proposed resolution
Make the module more robust by replacing media_entity_download_count_file_access() (which is more of a hack/workaround than a solid solution) with a request event subscriber that triggers every time the media_entity_download.download route is visited. This way, there aren't any accidental increments when file access is checked. Also, because we have direct access to the media entity, the logic becomes a lot simpler.
This indirectly fixes the following issues as well:
- #3518039: media_entity_download_count_file_access() doesn't account for empty response from file_get_file_references()
- #3350813: The media_entity_download_count_file_access function doesn't skip the /media/add/X path properly
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork media_entity_download_count-3621768
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dieterholvoet commentedComment #4
vipin.mittal18