Download & Extend

Details Page empty / Sparkline Graphs not working

Project:Download Count
Version:6.x-2.0
Component:User interface
Category:bug report
Priority:major
Assigned:Unassigned
Status:needs review

Issue Summary

I don't know why, but the details Pages for the individual Downloads are not working.

It displays no Statistics, Graphs etc.
Just an empty with no content.:

It's the same if I enable sparkline graphs on the statistics page - or not.

Any idea why this is not working?

I've also tryed several Versions of the Sparkline Plugin. It's not really clear which Version to take.
(1.3 because of jQuery 1.3.2 of Drupal or the latest?)

Greets,
Simon

Comments

#1

I'll attach 2 Screenshots to describe the problem:

AttachmentSize
2011-02-22 20 08 10.png 13.64 KB
2011-02-22 20 08 27.png 11.92 KB

#2

I think I've found the problem:

The module saves the statistics into the SQL Table "download_counter"
But the Detail Site tryes to load the statistics from the table "download_counter_statistics" which does exist but is empty.
It also tries to sort the tables by datestamp, which exists in the (old?) "download_counter_statistics" table, but not in "download_counter"

How is that?

Simon

#3

the download count statistics table is populated via cron. If it's empty, check and make sure the cron is running successfully.

#4

No, `download_count_statistics` is still empty. Cron does run multiple times a day.

Statistics are not displayed.

#5

I'm getting the same thing on my end. Even after running cron manually, download_count and download_count_statistics are both empty.

#6

@zckzck your problem is probably not the same-- since download_count is empty, download_count_statistics will never have data. You need to first make sure download_count is getting populated with counts before you can determine if download_count_statistics is having a problem.

@fannon-- just saying cron runs multiple times a day doesn't actually tell me anything. Which cron? unix cron? drupal cron? is drupal cron completing successfully? Are there any error messages or download_count messages in the watchdog table after a cron run?

#7

Yes, Drupal Cron is running sucessfully. I've triggered it manually several times too. There are no error message in the watchdog.

Greets,
Simon

#8

I guess the problem is in there:

/**
* Implementation of hook_cron().
*/
function download_count_statistics_cron() {
  $today = format_date(time(), 'custom', 'Y-m-d');
  $last_processed_day = variable_get('download_count_statistics_last_processed_day', '0');
  if ($today > $last_processed_day) {
    $files = db_query("SELECT fid, DATE(FROM_UNIXTIME(timestamp)) as date, COUNT(dcid) as count FROM {download_count} WHERE DATE(FROM_UNIXTIME(timestamp)) > '$last_processed_day' AND DATE(FROM_UNIXTIME(timestamp)) < '$today' GROUP BY DATE(FROM_UNIXTIME(timestamp)), fid ORDER BY DATE(FROM_UNIXTIME(timestamp)) ASC");
    while ($row = db_fetch_object($files)) {
      $result = db_query("INSERT INTO {download_count_statistics} VALUES ($row->fid, UNIX_TIMESTAMP('$row->date'), $row->count)");
      if (!$result) {
        watchdog('download_count_statistics', 'Download count for fid %fid was unable to be included in the download count statisitcs for %today.', array('%fid' => $row->fid, '%today' => $today), WATCHDOG_ERROR);
      }
    }
    watchdog('download_count_statistics', 'Download count statistics processed for %day.', array('%day' => $today), WATCHDOG_NOTICE);
    variable_set('download_count_statistics_last_processed_day', $today);
  }

I've tryed to manually run this code.
This condition is not met: if ($today > $last_processed_day) {

When i run the code anyway inside the if statement, it d oes create the watchdog entry but still doesn't populate the database. Strange.

I'm not very good at PHP so I've got no idea why this is not working.

Greets,
Simon

#9

One thing that looks strange:

$files = db_query("SELECT fid, DATE(FROM_UNIXTIME(timestamp)) as date, COUNT(dcid) as count FROM {download_count}

$result = db_query("INSERT INTO {download_count_statistics} VALUES ($row->fid, UNIX_TIMESTAMP('$row->date'), $row->count)");

It is always refering to 'date' in the download_count_statistics table. download_count_statistics got no 'date' but 'datetime' row in my Database. Maybe this is helping you a somehow?

I've renamed datestamp to date in my Database and now my download_count_statistics table is populated!
Statistics are not working, still because they are refering to datestamp.

So the Bug is there: UNIX_TIMESTAMP('$row->date') and DATE(FROM_UNIXTIME(timestamp)) as date

It should be 'datestamp' instead of 'date' right?

#10

Subscribing. I have this problem as well. Downloads are counting but with a blank details page. Any updates?

#11

I've had no luck replicating this problem. As with the op, a blank details page probably means the download_count_statistics table is not being populated (you can check the db directly to see). It's done via a simple cron function (posted above) so the first thing to check is that cron is running and completing successfully. Also check the watchdog table to see if you're receiving the download_count messages.

@9 -- the code is correct. I create the date 'field' in the query (the part that says DATE(FROM_UNIXTIME(timestamp)) as date) and its value is merely placed in the 'datestamp' field of the download_count_statistics table.

Keep in mind it processes by day and will only process downloads between yesterday and the last time you ran it. It looks at the download_count_statistics_last_processed_day variable in the variables table (try deleting that also to reset it).

#12

#11 - Deleting the download_count_statistics_last_processed_day variable works for me! Now the statistics table is populated correctly.
Thanks!
I'll keep my eye if its going to be populated without resetting this Value again.

#13

#11 +1

Deleting the download_count_statistics_last_processed_day variable works for me as well. Thanks!

#14

Problem: The Statistics Table is still not updated now. Last entry is from deleting the download_count_statistics_last_processed_day variable. After that day, nothing more is added to this table with cron runs.

So I guess the Problem is with that variable and the checking for new Statistics to process?

#15

I made the following changes : extracting $row values access from query string :

FROM
$result = db_query("INSERT INTO {download_count_statistics} VALUES ($row->fid, UNIX_TIMESTAMP('$row->date'), $row->count)");

TO :
$result = db_query("INSERT INTO {download_count_statistics} VALUES (".$row->fid.", UNIX_TIMESTAMP('".$row->date."'), ".$row->count.")");

Seems to work.

#16

Well, the previous changes does not work well in fact. After sometimes I noticed data were outdated.

#17

I'm still experiencing blank graphs and outdated data as well.

#18

Having the exact same problem. Blank Graphs. I've run cron multiple times. Everything else is working properly. I uploaded all the appropriate scripts as well.

#19

Context : I'm running my Drupal 6 site publicly since June 2011, download count statistics stop working at middle of June (with 2 downloads logged) and I was waiting for it to update automatically. Today, 2 months and a half have past so I decide to dig into this issue.

#11: I did reset the last date by deleting the field "download_count_statistics_last_processed_day", then run the cron: it does not work at all.

--> then instead, I changed the date to the last time shown by download count statistic page, which was 16 June 2011: when running the drupal cron job it works and generates all statistics from June to yesterday, this is great.

Hopefully it will now work automatically, if not I'll come tell it here.

Edit: It doesn't work, cron doesn't update download-count statistics.

I've made some changes to the DB query and that seems to work, at least, without changing the date in the variables table the cron update statistics.
I'll know tomorrow and double post here if it resolves this issue, but basically I invert the logic with UNIX_TIMESTAMP.

#20

Status:active» needs review

Okay, I think I get it. A small change in the WHERE statement seems enough.
It needs to be tested though, perhaps I also didn't get something. I explain why I do, so you can also see if I'm wrong there.

The full code is quoted in comment #8

The variable 'download_count_statistics_last_processed_day' is assigned at the end of the cron with the variable $today, which is a DATE() to say it is without hours, and which is today (If I get it, it should be yesterday).
The DB query has a WHERE condition:
DATE(FROM_UNIXTIME(timestamp)) > '$last_processed_day' AND DATE(FROM_UNIXTIME(timestamp)) < '$today'

if I convert it by taking tomorrow(2011-08-22) as test date and a file from today(2011-08-21), SQL reads it like this:
'2011-08-21' > '2011-08-21' AND '2011-08-21' < '2011-08-22'
the 1st condition making it never resolves, unless there is at least 2 days between '$last processed_day' and the file download timestamp.
If only 1 day between the 2 dates, then the condition is never met and the $today date goes feed the Drupal variables table, making it never happens for the next day.

So to resolve it we can replace this condition WHERE by:
DATE(FROM_UNIXTIME(timestamp)) >= '$last_processed_day' AND DATE(FROM_UNIXTIME(timestamp)) < '$today'

So only adding = next to the >. It should fit to a DATE() comparison.

Perhaps it could also work without this modification by comparing directly 'timestamp' field with $last_processed_day and $today converted to unix timestamp.

#21

I'm having the same issue.

#22

Since the change I've made on 21 august, everything works correctly (post #20). Here is a try to explain it better.

Open the file download_count_statistics.module, it should be in ./sites/all/download_count/ .

search this string:
WHERE DATE(FROM_UNIXTIME(timestamp)) > '$last_processed_day' AND DATE(FROM_UNIXTIME(timestamp)) < '$today' GROUP BY

replace it with:
WHERE DATE(FROM_UNIXTIME(timestamp)) >= '$last_processed_day' AND DATE(FROM_UNIXTIME(timestamp)) < '$today' GROUP BY



Now, launch the cron job via this link modified with your host provider: http://your-site-address.com/admin/reports/status/run-cron.

It will fill each missing date from the last processed date to today, and continue to fill them day by day each time the cron job is launched.

#23

Thanks AvvAdeh, that seems to work (had to delete the variable as well, then run cron).

#24

Version:6.x-2.0-beta1» 6.x-2.0

This issue needs to be fixed on 6.x-2.0