when you upload two files with the same file name, upload module gives them different names on file system, but the filename field in table files stayes the same for both files.

in the other hand, filename field of file_downloads table contains file name as it is on the file system.

in the described situation, your code $result = db_query("SELECT fd.filename, fd.count, fd.timestamp, f.nid, n.type FROM {file_downloads} fd JOIN {files} f ON fd.filename = f.filename JOIN {node} n ON n.nid = f.nid" . tablesort_sql($header)); will not fetch those files, thus, they won't be displayed on download_counter page.

Comments

darko.ilic’s picture

Title: download_count_view_page() and files with same filename » this should help
StatusFileSize
new1.2 KB

works for me...

darko.ilic’s picture

Title: this should help » oups!
StatusFileSize
new1.21 KB

I forgot LIKE is case in-sensitive by default

please ignore my previous patch, here's the one that works

Chill35’s picture

Title: oups! » download_count_view_page() and files with same filename
Assigned: Unassigned » Chill35
Status: Active » Needs review

Great catch. And great fix. I looked at your code and I am impressed. Your knowledge of mysql surpassses mine.

The filename that is recorded in {file_downloads} is indeed the actual file name. Not the filename (a.k.a file description) that appears to users in the node.

$result = db_query("SELECT fd.filename, fd.count, fd.timestamp, f.nid, n.type FROM {file_downloads} fd JOIN {files} f ON BINARY fd.filename LIKE SUBSTRING(f.filepath FROM 7) JOIN {node} n ON n.nid = f.nid" . tablesort_sql($header));

I will test this quickly and apply the patch.

Note to you & everyone : if you look at the download_count.install, I am just not doing anything for a pgsql database. Do you know what the pgsql syntax would be for LIKE SUBSTRING(f.filepath FROM 7)... would it be the same ? Is the database creation the same, also, for a pgsql database ?

Thanks a million!

darko.ilic’s picture

thank _you_ for the module, it was quite helpful :)

see ya

Chill35’s picture

Status: Needs review » Fixed

I also had to modify theme_download_count_body($node), darko.

I also fixed the Drupal 5.x version.

I used a slightly different approach because the SUBSTRING(f.filepath FROM 7) did not work in all scenarios. I used CONCAT with the File System Path.

Here's the solution I used:

$fileDirectoryPath = file_directory_path() . '/';
... JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) ... $fileDirectoryPath);

Etc.

Thanks again! Let me know if we'll run into case-sensitive glitches with that fix.

The fix is now in CVS and new versions will be built within the next 24 hours.

Chill35’s picture

I surfed the MySQL doc, but didn't find what I was looking for, i.e. the equivalent of the php function strstr. I wanted to use something like: WHERE the filename is a substring of filepath... Maybe I had to use something like SUBSTRING(f.filepath FROM -COUNT(fd.filename)).

Anonymous’s picture

Status: Fixed » Closed (fixed)