Problem:
If multiple users start the download of a single file at the same time, only one will be logged.
Solution:
Replace this line: $db->query('UPDATE file SET visits = :visits WHERE id = :id', array('visits' => $this->visits, 'id' => $this->id));
to this: $db->query('UPDATE file SET visits = visits + 1 WHERE id = :id', array('id' => $this->id));
in the file.class.php
Details:
The updateVisitors() method in the file class add +1 to $this->visits and then saves the value in the database without using transactions.
$this->visits is loaded in the beginning and updateVisitors() is called by the stats class at the end of the download when using pure php to serve the downloads.
Example and how to reproduce:
User A starts downloading file 1. $this->visits = 0.
User B starts downloading file 1. $this->visits = 0.
User A finish the download. $this->visits++; mysql query saving 1 to the visits field.
User B finish the download. $this->visits++; mysql query saving 1 to the visits field. Data from user A is lost.
If multiple users start the download of a single file at the same time, only one will be logged.
Solution:
Replace this line: $db->query('UPDATE file SET visits = :visits WHERE id = :id', array('visits' => $this->visits, 'id' => $this->id));
to this: $db->query('UPDATE file SET visits = visits + 1 WHERE id = :id', array('id' => $this->id));
in the file.class.php
Details:
The updateVisitors() method in the file class add +1 to $this->visits and then saves the value in the database without using transactions.
$this->visits is loaded in the beginning and updateVisitors() is called by the stats class at the end of the download when using pure php to serve the downloads.
Example and how to reproduce:
User A starts downloading file 1. $this->visits = 0.
User B starts downloading file 1. $this->visits = 0.
User A finish the download. $this->visits++; mysql query saving 1 to the visits field.
User B finish the download. $this->visits++; mysql query saving 1 to the visits field. Data from user A is lost.