diff options
-rw-r--r-- | phpBB/download/file.php | 10 | ||||
-rw-r--r-- | phpBB/includes/functions_download.php | 21 |
2 files changed, 23 insertions, 8 deletions
diff --git a/phpBB/download/file.php b/phpBB/download/file.php index f360132b0f..cec4aa55b3 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -407,10 +407,7 @@ if ($attachment) else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHMENT_CATEGORY_IMAGE*/) && !$attachment['is_orphan'] && !phpbb_http_byte_range($attachment['filesize'])) { // Update download count - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET download_count = download_count + 1 - WHERE attach_id = ' . $attachment['attach_id']; - $db->sql_query($sql); + phpbb_increment_downloads($db, $attachment['attach_id']); } if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && ((strpos(strtolower($user->browser), 'msie') !== false) && (strpos(strtolower($user->browser), 'msie 8.0') === false))) @@ -443,10 +440,7 @@ if ($attachment) if ($attachments) { - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET download_count = download_count + 1 - WHERE ' . $db->sql_in_set('attach_id', $attach_ids); - $db->sql_query($sql); + phpbb_increment_downloads($db, $attach_ids); if (!in_array($archive, compress::methods())) { diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 1486113013..b01712357d 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -592,3 +592,24 @@ function phpbb_parse_range_request($request_array, $filesize) ); } } + +/** +* Increments the download count of all provided attachments +* +* @param dbal $db The database object +* @param array|int $ids The attach_id of each attachment +* +* @return null +*/ +function phpbb_increment_downloads($db, $ids) +{ + if (!is_array($ids)) + { + $ids = array($ids); + } + + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET download_count = download_count + 1 + WHERE ' . $db->sql_in_set('attach_id', $ids); + $db->sql_query($sql); +} |