For the sake of the upload.module!

Body

I've created an issue with a patch to add the file downloads count to the upload.module, If the author kindly accepts it, I'll be moving away from the old filestore.module and start using the upload module.
As I love posting code, Here's the patch.

--- /home/mohammed/drupal-4.5/drupal-4.5.1/modules/upload.module 2004-10-20 18:57:50.000000000 +0200
+++ upload.module 2005-01-02 16:08:50.000000000 +0200
@@ -95,6 +95,8 @@
       $name = mime_header_encode($file->filename);
       // Serve images and text inline for the browser to display rather than download.
       $disposition = ereg('^(text/|image/)', $file->filemime) ? 'inline' : 'attachment';
+// We increase the downloads by one.
+db_query("UPDATE {files} SET downloads=downloads+1 WHERE fid=$file->fid");
       return array('Content-Type: '. $file->filemime .'; name='. $name,
                    'Content-Length: '. $file->filesize,
                    'Content-Disposition: '. $disposition .'; filename='. $name);
@@ -209,7 +211,7 @@
       break;
     case 'view':
       if ($node->files && user_access('view uploaded files')) {
-        $header = array(t('Attachment'), t('Size'));
+        $header = array(t('Attachment'), t('Size'), t('Downloads'));
         $rows = array();
         $previews = array();

@@ -218,7 +220,7 @@
           if ($file->list) {
             $rows[] = array(
               '<a href="/'. ($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()))) . '">'. $file->filename .'</a>',
-              format_size($file->filesize)
+              format_size($file->filesize), ($file->downloads ? $file->downloads : 0 )
             );
             // We save the list of files still in preview for later
             if (!$file->fid) {
@@ -276,15 +278,15 @@
function upload_save($node) {
   foreach ((array)$node->files as $key => $file) {
     if ($file->source && !$file->remove) {
+      // Insert new files:
+      $fid = db_next_id('{files}_fid');
+      $file = file_save_upload($file, $file->filename);
+
       // Clean up the session:
       unset($_SESSION['file_uploads'][$file->source]);

-      // Insert new files:
-      if ($file = file_save_upload($file, $file->filename)) {
-        $fid = db_next_id('{files}_fid');
-        db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)",
-                 $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
-      }
+      db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, downloads, list) VALUES (%d, %d, '%s', '%s', '%s', %d, 0, %d)",
+               $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
     }
     else {
       // Remove or update existing files:

You can find the proposed table change if you read the issue.

Add new comment

The content of this field is kept private and will not be shown publicly.