Is there a way, currently, to track downloaded files by user? I need this feature and am willing to contribute time to develop it. I have never contributed to a drupal module before, so I would need to know how to go about that. I propose a webfm_download_statistics table with a few functions for loading data into that table. The best case scenario would then be to expose those table columns to the views module so that people could get what ever data they needed from the table.

Please let me know what the best way to accomplish this would be.

Thanks,

CommentFileSizeAuthor
#19 webfm[1].patch9.07 KBjadowd
#17 webfm.patch9.05 KBjadowd
#13 webfm.patch9.22 KBjadowd
#3 webfm[1].patch3.96 KBjadowd

Comments

robmilne’s picture

Look inside the webfm_send_file function of the webfm.module file. This is where file permissions are checked against user permissions before transferring the file. All the information required for your table resides there. I have no time currently for drupal development but I will gladly review a patch.

jadowd’s picture

Okay, I will see if I can get something to you by tomorrow afternoon.

Regards

jadowd’s picture

StatusFileSize
new3.96 KB

Okay, here is my first pass at making a data table that will track a download by user. I modified two files, the .install and the .module file. In the former, I created an update section as well as the table definitions in the install section. In the .module file, I created a function that simply populates that table with a tracking row. I am willing to maintain this additional feature in the hopes of improving this great module. I did not update the .info module as I was pretty sure that I was not supposed to do that.

Go easy on me, this was my very first patch :)

jadowd’s picture

Status: Active » Needs review
beckyjohnson’s picture

Status: Needs review » Active

Eh, I have a question, specifically where were we supposed to see the change that this patch would make? I put the patch on and updated the module and everything works but I couldn't find where it was keeping track of user downloads.

Thanks,
Becky

jadowd’s picture

all I did at this point was to make the logging occur in the data base. I don't understand how views work well enough to expose the tables and columns in the views module yet, and I need this working well enough that I can collect and pull some raw data asap. It looked to me that someone was working on integrating webfm with views, as there are several files that indicated that to me, so I am hoping that piece will be forthcoming soon and I can integrate with that soon enough.

Is that helpful?

beckyjohnson’s picture

Yeah it is, thanks. We're using Webfm in my office and my bosses really want a way to track who reads what in our webfm section..now, I'm working on trying to password protect the section so that only authorized users can look like it.

Becky

jadowd’s picture

just use the permissions interface. I have it set up the same way.

robmilne’s picture

Looks good so far (I haven't tested the patch) though the new table name should be more specific wrt download - there are other possible statistics. I think you will also have to update the views file since it isn't being actively maintained.

You might want to add some admin controls like the option to flush the stats or even to present them within the module rather than just via views.

jadowd’s picture

Okay, I got carried away on some other business, but have come back to this. My question is this... If I have created an /admin/reports interface that reads table data from the table that I created, do I need to send in a second, partial patch, apart from the one that I sent you earlier, or do you want a completely new patch with all my changes in it.

I can do either. I have not added much by way of statistics, only the fields that I had there before. That is all that I need, but I would be willing to track and maintain issues with that feature, in effect, co-support this module, if you like.

Let me know what works best for you and I will do it.

Thanks,

profjk’s picture

subscribing

robmilne’s picture

All patches should be against the official latest release for proper line referencing. Please create a new patch from scratch.

As for co-support, it is a always a good idea to check how new releases impact your code changes. As (unoffical) maintainer I probably won't test contributed features as extensively or in the same way as the original developer.

jadowd’s picture

StatusFileSize
new9.22 KB

Okay, I have a patch ready for testing.

What it does:

An additional table has been added to the schema.

mysql> desc webfm_statistics;
+-------- -+---------------------+------+-----+----------------------------+--------------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+----------------------------+--------------------+
| sid | int(10) unsigned | NO | PRI | NULL | auto_increment |
| uid | int(10) unsigned | NO | | NULL | |
| fid | int(11) | NO | | 0 | |
| dl_time | datetime | NO | | 0000-00-00 00:00:00 | |
+----------+---------------------+------+-----+----------------------------+---------------------+
4 rows in set (0.01 sec)

The report query calls left outer joins against 5 tables to get necessary data.

$query = "SELECT a.sid, a.uid, a.fid, a.dl_time, b.name, b.mail, c.fpath, d.nid, e.title
FROM webfm_statistics a
LEFT OUTER JOIN users b ON a.uid = b.uid
LEFT OUTER JOIN webfm_file c ON a.fid = c.fid
LEFT OUTER JOIN webfm_attach d ON a.fid = c.fid
LEFT OUTER JOIN node e ON d.nid = e.nid";

This gives the ability to build links to the user page, the node if the file is attached to one, and the user's email as well as display the physical file path on disk. All of this information was requested by my client. The purpose of the email was to easily contact a user after the user downloaded a file.

I have created a .csv export function that end users are able to pull, as well as a manual delete function that will clean data out of the table. If desired, I am thinking that automatic report saving (maybe sending via email) and report table cleaning functions that could be executed via cron (my current client )has not asked for that, but I can see how that may be desirable.

Please import these features into the core of the module for drupal 6. Let me know when this is done and I will be happy to port this feature into Drupal 7 as well.

Thanks!

robmilne’s picture

Thanks for the patch submission. I'm unable to review it at this moment because of my own schedule. I'll do my best to get back to you next week some time.

mr.baileys’s picture

Status: Active » Needs work

Hi jadowd,

Thanks for your work on this.

When your patch is ready for testing, feel free to change the status to "Patch (code needs review)" (CNR for friends). I've done a quick review of your patch since I'm evaluating Web File Manager at the moment, and here are some comments:

  1. I had some problems applying the patch, one of the reasons being that you seem to have created the patch from the modules-directory root. Patches should be created from the module root itself (see http://drupal.org/patch/create);
  2. There seem to be excess spaces/tab in the patch, which causes the statements in the patched files to be all over the places. From the coding standards: Use an indent of 2 spaces, with no tabs. No trailing whitespace.
  3. Optional: you might want to add descriptions to the tables & columns you add to the schema (Schema API)
  4. Have you thought about a more specific name as requested in #9?
  5. error_log and other debug-related statements should be removed before a patch is submitted
  6. SQL table-names should be wrapped in curly quotes "{webfm_statistics}" (see SQL coding conventions). There is at least one occurance where this isn't the case:
    $query = "SELECT a.sid, a.uid, a.fid, a.dl_time, b.name, b.mail, c.fpath, d.nid, e.title
      FROM webfm_statistics a
      LEFT OUTER JOIN users b ON a.uid = b.uid
      LEFT OUTER JOIN webfm_file c ON a.fid = c.fid
      LEFT OUTER JOIN webfm_attach d ON a.fid = c.fid
      LEFT OUTER JOIN node e ON d.nid = e.nid";
    
  7. Reserverd words in SQL statements should be uppercase;
    SELECT count(*) AS count FROM {webfm_statistics};
    

    instead of:

    SELECT count(*) as count from webfm_statistics;
    
  8. If you just need a count value from a query, take a look at Drupal's db_result API-function
    $count_query = 'SELECT count(*) as count from webfm_statistics;';
    $result = db_fetch_object(db_query($count_query));
    

    becomes

    $count = db_result(db_query('SELECT count(*) AS count FROM {webfm_statistics}'));
    
  9. When using t(), you should use placeholders instead of concatenation strings. Doing this makes it easier to read and translate:
    t('<br>A total of '.$result->count.' rows were returned.');
    

    should be

    t('<br>A total of !count rows were returned.', array('!count' => $result->count));
    

Based on these comments, I've set this patch to CNW

jadowd’s picture

All excellent feedback. I will make the necessary changes and resubmit. Thank you so much for your helpful insight.

Regards,

jadowd’s picture

StatusFileSize
new9.05 KB

1. Done
2. I didn't see any tabs in the file, but I did clean out some of my non-drupal conforming spacing. I hope I got it all...
3. optional: maybe at a later time
4. I expect to expand on this feature as time goes on, so I am thinking that a more generic name is appropriate at this time.
5. Done
6. Done
7. DONE
8. done
9. done

Thanks again... Do let me know if you see anything else.

robmilne’s picture

The more I think about what you are doing the more I am inclined toward a plugin module ala cck. My intent is to create a 'modules' subdir of the WebFM module where plugins can be contributed and allow users a finer grained control of functionality. Separation into modules also permits contributors to more easily maintain their work.

This weekend I created a mp3 player module for the contextmenu (not released but viewable on the demo site) and I'll be making it an option that can be enabled inside admin/build/modules ala cck or views. I've recently ported webfm_images (Andre Molnar's module) to 6.x and I will be adding it as well.

Can you try your hand at transforming this into a separate module? I think it would be a cinch considering that you generally are not modifying existing functions but adding new ones. The only issue might be your small mod of webfm_send_file() which would argue for the addition of a 'module_invoke_all' hook...
module_invoke_all('webfm_send')
...something I could use for other purposes like alternative file streaming.

jadowd’s picture

StatusFileSize
new9.07 KB

I have a slight error in my query... attached is the revised patch.

I don't know how to use the module_invoke_all hook, but I will look into it. My hope was to simply have a bit of feedback for who has downloaded each file. To me it seems better placed within the webfm module itself. I don't really know how the modules sub directory process works, so if you want me to do that, I will need you to tell me how to go about it.

Thanks,

jadowd’s picture

I have my module constructed, I simply need the changes that you would need to make in your module so that I can know when webfm_file_send function is called. Thanks,

robmilne’s picture

Thanks Jeff. I'm going to commit webfm_images and webfm_mp3 tonight as well as the hook you'll need for your statistics module. This hook...
module_invoke_all('webfm_send', $f);
...is placed inside the webfm_send_file() just before the file is sent out.

Inside your module (for the sake of this example I'm calling it webfm_statistics) you have access to the file object being downloaded inside your 'webfm_send' hook function...
webfm_statistics_webfm_send($file) {...

jadowd’s picture

Thanks Rob,

I have linked it up and it works as it did before. I have requested a CVS account, if it gets approved, I think we will be done here.

jadowd’s picture

I have released this project in development, pending feedback from a few users/testers. If you are interested in using it and can offer some feedback as to its applications, please let me know...

the module can be found here:

http://drupal.org/project/webfm_statistics

Thanks,

nhck’s picture

Status: Needs work » Closed (fixed)

Nice - added a link to the module to the front page. Thank you for doing this!