Dear PKP staffs and Forum members,
I am currently operating OPS3.3.0.8 (PHP8.1).
I have encountered an issue in the ”preprint_details.tpl” of our OPS system where the getTotalGalleyViews
function results in double counting the galley view counts. This problem occurs when multiple galley_id
s are associated with the same submission_file_id
.
The getTotalGalleyViews
function currently calculates galley views as follows:
function getTotalGalleyViews() {
$application = Application::get();
$publications = $this->getPublishedPublications();
$views = 0;
foreach ($publications as $publication) {
foreach ((array) $publication->getData('galleys') as $galley) {
$file = $galley->getFile();
if (!$galley->getRemoteUrl() && $file) {
$views = $views + $application->getPrimaryMetricByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $file->getId());
}
}
}
return $views;
}
In this function, if the same submission_file_id
is associated with multiple galley_id
s, the views are counted for each galley_id
, resulting in double counting.
To prevent duplicate counting, I propose modifying the function to count views only once per submission_file_id
. The following code includes a check for duplicate file IDs and counts each file’s views only once:
function getTotalGalleyViews() {
$application = Application::get();
$publications = $this->getPublishedPublications();
$views = 0;
$processedFiles = [];
foreach ($publications as $publication) {
foreach ((array) $publication->getData('galleys') as $galley) {
$file = $galley->getFile();
if (!$galley->getRemoteUrl() && $file) {
$fileId = $file->getId();
if (!in_array($fileId, $processedFiles)) {
$views += $application->getPrimaryMetricByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $fileId);
$processedFiles[] = $fileId;
} else {
// Debug log for duplicate file IDs
error_log("Duplicate file ID: " . $fileId);
}
}
}
}
return $views;
}
Additionally, to identify all submission_file_id
s with multiple galley_id
s, the following query can be used:
SELECT submission_file_id, COUNT(galley_id) AS galley_count
FROM publication_galleys
GROUP BY submission_file_id
HAVING COUNT(galley_id) > 1;
I would appreciate any feedback or suggestions for improvements on this fix. It would be great if this bug fix could be incorporated into the community version.
Thank you for your assistance.
Minoru Tanabe.