From 7fccbf5fd1919a9c8ae14d2f39a55de8eee64de5 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 21 May 2015 18:40:22 +0200 Subject: Calc correct total size for history with duplicate hashes Signed-off-by: Florian Pritz --- application/service/files.php | 3 ++- application/test/tests/test_api_v1.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'application') diff --git a/application/service/files.php b/application/service/files.php index ef1de2911..5e0dd140b 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -30,10 +30,11 @@ class files { $total_size = $CI->db->query(" SELECT coalesce(sum(filesize), 0) sum FROM ( - SELECT DISTINCT hash, filesize + SELECT DISTINCT `".$CI->db->dbprefix."file_storage`.id, filesize FROM `".$CI->db->dbprefix."file_storage` JOIN `".$CI->db->dbprefix."files` ON `".$CI->db->dbprefix."file_storage`.id = `".$CI->db->dbprefix."files`.file_storage_id WHERE user = ? + ) sub ", array($user))->row_array(); diff --git a/application/test/tests/test_api_v1.php b/application/test/tests/test_api_v1.php index cdac30544..bc311f8e5 100644 --- a/application/test/tests/test_api_v1.php +++ b/application/test/tests/test_api_v1.php @@ -278,6 +278,26 @@ class test_api_v1 extends \test\Test { ), $ret, "expected reply"); } + public function test_history_notEmptyAfterUploadSameMD5() + { + $apikey = $this->createUserAndApikey(); + $this->CallEndpoint("POST", "file/upload", array( + "apikey" => $apikey, + "file[1]" => curl_file_create("data/tests/message1.bin"), + "file[2]" => curl_file_create("data/tests/message2.bin"), + )); + $expected_filesize = filesize("data/tests/message1.bin") + filesize("data/tests/message2.bin"); + + $ret = $this->CallEndpoint("POST", "file/history", array( + "apikey" => $apikey, + )); + $this->expectSuccess("history not empty after upload", $ret); + + $this->t->ok(!empty($ret["data"]["items"]), "history not empty after upload (items)"); + $this->t->ok(empty($ret["data"]["multipaste_items"]), "didn't upload multipaste"); + $this->t->is($ret["data"]["total_size"], $expected_filesize, "total_size == uploaded files"); + } + public function test_history_notEmptyAfterUpload() { $apikey = $this->createUserAndApikey(); -- cgit v1.2.3-24-g4f1b