From acf4bcc22c0a4dab21937782de7ff9dbdca88f31 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 25 May 2017 20:38:02 +0300 Subject: [PATCH 1/4] Remove filename from storageFiles --- controllers/ItemsController.php | 31 +------ model/Attachments.inc.php | 6 +- model/Storage.inc.php | 141 +++++++++++++++++++++----------- 3 files changed, 99 insertions(+), 79 deletions(-) diff --git a/controllers/ItemsController.php b/controllers/ItemsController.php index 0a1d86dfa..ff392a7b2 100644 --- a/controllers/ItemsController.php +++ b/controllers/ItemsController.php @@ -961,7 +961,7 @@ private function _handleFileRequest($item) { Zotero_DB::query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); Zotero_DB::beginTransaction(); - // See if file exists with this filename + // See if file exists with this hash and zip flag $localInfo = Zotero_Storage::getLocalFileInfo($info); if ($localInfo) { $storageFileID = $localInfo['storageFileID']; @@ -970,34 +970,11 @@ private function _handleFileRequest($item) { if ($localInfo['size'] != $info->size) { throw new Exception( "Specified file size incorrect for existing file " - . $info->hash . "/" . $info->filename + . $info->hash . " ({$localInfo['size']} != {$info->size})" ); } } - // If not found, see if there's a copy with a different name - else { - $oldStorageFileID = Zotero_Storage::getFileByHash($info->hash, $info->zip); - if ($oldStorageFileID) { - // Verify file size - $localInfo = Zotero_Storage::getFileInfoByID($oldStorageFileID); - if ($localInfo['size'] != $info->size) { - throw new Exception( - "Specified file size incorrect for duplicated file " - . $info->hash . "/" . $info->filename - . " ({$localInfo['size']} != {$info->size})" - ); - } - - // Create new file on S3 with new name - $storageFileID = Zotero_Storage::duplicateFile( - $oldStorageFileID, - $info->filename, - $info->zip, - $contentTypeHeader - ); - } - } // If we already have a file, add/update storageFileItems row and stop if (!empty($storageFileID)) { @@ -1102,13 +1079,13 @@ private function _handleFileRequest($item) { else { $remoteInfo = Zotero_Storage::getRemoteFileInfo($info); if (!$remoteInfo) { - error_log("Remote file {$info->hash}/{$info->filename} not found"); + error_log("Remote file {$info->hash} not found"); $this->e400("Remote file not found"); } if ($remoteInfo->size != $info->size) { error_log("Uploaded file size does not match " . "({$remoteInfo->size} != {$info->size}) " - . "for file {$info->hash}/{$info->filename}"); + . "for file {$info->hash}"); } } diff --git a/model/Attachments.inc.php b/model/Attachments.inc.php index 8e63cd2c0..3bd495d65 100644 --- a/model/Attachments.inc.php +++ b/model/Attachments.inc.php @@ -189,15 +189,15 @@ public static function getTemporaryURL(Zotero_Item $item, $localOnly=false) { throw new Exception("Unable to create directory '$downloadDir'"); } if ($zip) { - $response = Zotero_Storage::downloadFile($info, $downloadDir); + $response = Zotero_Storage::downloadFile($info, $downloadDir, '1.zip'); } else { $response = Zotero_Storage::downloadFile($info, $downloadDir, $realFilename); } if ($response) { if ($zip) { - $success = self::extractZip($downloadDir . $info['filename'], $dir); - unlink($downloadDir . $info['filename']); + $success = self::extractZip($downloadDir . '1.zip', $dir); + unlink($downloadDir . '1.zip'); rmdir($downloadDir); // Make sure charset is just a string with no spaces or newlines diff --git a/model/Storage.inc.php b/model/Storage.inc.php index 8a38234df..407ab1835 100644 --- a/model/Storage.inc.php +++ b/model/Storage.inc.php @@ -51,7 +51,6 @@ public static function getDownloadDetails($item) { else { return array( 'url' => $url, - 'filename' => $info['filename'], 'size' => $info['size'] ); } @@ -88,18 +87,23 @@ public static function getDownloadURL(Zotero_Item $item, $ttl=60) { // http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#headobject, // but returning NotFound if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { - // Try legacy key format, with zip flag and filename + // Try legacy key format, with zip flag try { - $key = self::getPathPrefix($info['hash'], $info['zip']) . $info['filename']; - $s3Client->headObject([ + $key = self::getPathPrefix($info['hash'], $info['zip']); + $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'Key' => $key + 'MaxKeys' => 1, + 'Prefix' => $key, ]); - } - catch (\Aws\S3\Exception\S3Exception $e) { - if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { + + $contents = $result->get('Contents'); + if (!$contents || count($contents) < 1) { return false; } + + $key = $contents[0]['Key']; + } + catch (\Aws\S3\Exception\S3Exception $e) { throw $e; } } @@ -116,8 +120,7 @@ public static function getDownloadURL(Zotero_Item $item, $ttl=60) { return (string) $s3Client->createPresignedRequest($cmd, "+$ttl seconds")->getUri(); } - - public static function downloadFile(array $localFileItemInfo, $savePath, $filename=false) { + public static function downloadFile(array $localFileItemInfo, $savePath, $filename) { if (!file_exists($savePath)) { throw new Exception("Path '$savePath' does not exist"); } @@ -131,24 +134,42 @@ public static function downloadFile(array $localFileItemInfo, $savePath, $filena return $s3Client->getObject([ 'Bucket' => Z_CONFIG::$S3_BUCKET, 'Key' => $localFileItemInfo['hash'], - 'SaveAs' => $savePath . "/" . ($filename ? $filename : $localFileItemInfo['filename']) + 'SaveAs' => $savePath . "/" . $filename ]); } catch (\Aws\S3\Exception\S3Exception $e) { if ($e->getAwsErrorCode() == 'NoSuchKey') { // Try legacy key format, with zip flag and filename try { - return $s3Client->getObject([ + $key = self::getPathPrefix($localFileItemInfo['hash'], $localFileItemInfo['zip']); + $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'Key' => self::getPathPrefix($localFileItemInfo['hash'], $localFileItemInfo['zip']) - . $localFileItemInfo['filename'], - 'SaveAs' => $savePath . "/" . ($filename ? $filename : $localFileItemInfo['filename']) + 'MaxKeys' => 1, + 'Prefix' => $key, ]); - } - catch (\Aws\S3\Exception\S3Exception $e) { - if ($e->getAwsErrorCode() == 'NoSuchKey') { + + $contents = $result->get('Contents'); + if (!$contents || count($contents) < 1) { return false; } + $key = $contents[0]['Key']; + + try { + return $s3Client->getObject([ + 'Bucket' => Z_CONFIG::$S3_BUCKET, + 'Key' => $key, + 'SaveAs' => $savePath . "/" . $filename + ]); + } + catch (\Aws\S3\Exception\S3Exception $e) { + if ($e->getAwsErrorCode() == 'NoSuchKey') { + return false; + } + throw $e; + } + + } + catch (\Aws\S3\Exception\S3Exception $e) { throw $e; } } @@ -164,12 +185,11 @@ public static function logDownload($item, $downloadUserID, $ipAddress) { $info = self::getLocalFileItemInfo($item); $storageFileID = $info['storageFileID']; - $filename = $info['filename']; $size = $info['size']; $sql = "INSERT INTO storageDownloadLog - (ownerUserID, downloadUserID, ipAddress, storageFileID, filename, size) - VALUES (?, ?, INET_ATON(?), ?, ?, ?)"; + (ownerUserID, downloadUserID, ipAddress, storageFileID, size) + VALUES (?, ?, INET_ATON(?), ?, ?)"; Zotero_DB::query( $sql, [ @@ -177,7 +197,6 @@ public static function logDownload($item, $downloadUserID, $ipAddress) { $downloadUserID, $ipAddress, $storageFileID, - $filename, $size ], 0, @@ -267,16 +286,15 @@ public static function logUpload($uploadUserID, $item, $key, $ipAddress) { $info = self::getLocalFileItemInfo($item); $storageFileID = $info['storageFileID']; - $filename = $info['filename']; $size = $info['size']; $sql = "DELETE FROM storageUploadQueue WHERE uploadKey=?"; Zotero_DB::query($sql, $key); $sql = "INSERT INTO storageUploadLog - (ownerUserID, uploadUserID, ipAddress, storageFileID, filename, size) - VALUES (?, ?, INET_ATON(?), ?, ?, ?)"; - Zotero_DB::query($sql, array($ownerUserID, $uploadUserID, $ipAddress, $storageFileID, $filename, $size)); + (ownerUserID, uploadUserID, ipAddress, storageFileID, `size`) + VALUES (?, ?, INET_ATON(?), ?, ?)"; + Zotero_DB::query($sql, array($ownerUserID, $uploadUserID, $ipAddress, $storageFileID, $size)); } @@ -413,23 +431,41 @@ public static function duplicateFile($storageFileID, $newName, $zip, $contentTyp catch (\Aws\S3\Exception\S3Exception $e) { if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { try { - $s3Client->copyObject([ + $key = self::getPathPrefix($localInfo['hash'], $localInfo['zip']); + $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'CopySource' => Z_CONFIG::$S3_BUCKET . '/' - . urlencode(self::getPathPrefix($localInfo['hash'], $localInfo['zip']) - . $localInfo['filename']), - 'Key' => $localInfo['hash'], - 'ACL' => 'private' + 'MaxKeys' => 1, + 'Prefix' => $key, ]); - } - catch (\Aws\S3\Exception\S3Exception $e) { - if ($e->getAwsErrorCode() == 'NoSuchKey') { + + $contents = $result->get('Contents'); + if (!$contents || count($contents) < 1) { return false; } - else { - throw $e; + + $key = $contents[0]['Key']; + + try { + $s3Client->copyObject([ + 'Bucket' => Z_CONFIG::$S3_BUCKET, + 'CopySource' => Z_CONFIG::$S3_BUCKET . '/' + . urlencode($key), + 'Key' => $localInfo['hash'], + 'ACL' => 'private' + ]); + } + catch (\Aws\S3\Exception\S3Exception $e) { + if ($e->getAwsErrorCode() == 'NoSuchKey') { + return false; + } + else { + throw $e; + } } } + catch (\Aws\S3\Exception\S3Exception $e) { + throw $e; + } } else { throw $e; @@ -440,7 +476,7 @@ public static function duplicateFile($storageFileID, $newName, $zip, $contentTyp foreach ($localInfo as $key => $val) { $info->$key = $val; } - $info->filename = $newName; + return self::addFile($info); } @@ -456,8 +492,8 @@ public static function getFileInfoByID($storageFileID) { } public static function getLocalFileInfo(Zotero_StorageFileInfo $info) { - $sql = "SELECT * FROM storageFiles WHERE hash=? AND filename=? AND zip=?"; - return Zotero_DB::rowQuery($sql, array($info->hash, $info->filename, (int) $info->zip)); + $sql = "SELECT * FROM storageFiles WHERE hash=? AND zip=? ORDER BY storageFileID LIMIT 1"; + return Zotero_DB::rowQuery($sql, array($info->hash, (int)$info->zip)); } public static function getRemoteFileInfo(Zotero_StorageFileInfo $info) { @@ -467,20 +503,27 @@ public static function getRemoteFileInfo(Zotero_StorageFileInfo $info) { 'Bucket' => Z_CONFIG::$S3_BUCKET, 'Key' => $info->hash ]); + $size = $result['ContentLength']; } catch (\Aws\S3\Exception\S3Exception $e) { if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { - // Try legacy key format, with zip flag and filename + // Try legacy key format, with zip flag try { - $result = $s3Client->headObject([ + $key = self::getPathPrefix($info->hash, $info->zip); + $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'Key' => self::getPathPrefix($info->hash, $info->zip) . $info->filename + 'MaxKeys' => 1, + 'Prefix' => $key, ]); - } - catch (\Aws\S3\Exception\S3Exception $e) { - if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { + + $contents = $result->get('Contents'); + if (!$contents || count($contents) < 1) { return false; } + + $size = $contents[0]['Size']; + } + catch (\Aws\S3\Exception\S3Exception $e) { throw $e; } } @@ -490,7 +533,7 @@ public static function getRemoteFileInfo(Zotero_StorageFileInfo $info) { } $storageFileInfo = new Zotero_StorageFileInfo; - $storageFileInfo->size = $result['ContentLength']; + $storageFileInfo->size = $size; return $storageFileInfo; } @@ -531,8 +574,8 @@ public static function getFileItems($hash, $filename, $zip) { public static function addFile(Zotero_StorageFileInfo $info) { - $sql = "INSERT INTO storageFiles (hash, filename, size, zip) VALUES (?,?,?,?)"; - return Zotero_DB::query($sql, array($info->hash, $info->filename, $info->size, (int) $info->zip)); + $sql = "INSERT INTO storageFiles (hash, `size`, zip) VALUES (?,?,?)"; + return Zotero_DB::query($sql, array($info->hash, $info->size, (int)$info->zip)); } From 58c089d78a45eb6166546aa9306bba4815aa4e5d Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 31 May 2017 16:02:05 +0300 Subject: [PATCH 2/4] Small fixes --- model/Attachments.inc.php | 8 ++++---- model/Storage.inc.php | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/model/Attachments.inc.php b/model/Attachments.inc.php index 3bd495d65..278f44bcb 100644 --- a/model/Attachments.inc.php +++ b/model/Attachments.inc.php @@ -66,7 +66,6 @@ public static function getTemporaryURL(Zotero_Item $item, $localOnly=false) { $info = Zotero_Storage::getLocalFileItemInfo($item); $storageFileID = $info['storageFileID']; - $filename = $info['filename']; $mtime = $info['mtime']; $zip = $info['zip']; $realFilename = preg_replace("/^storage:/", "", $item->attachmentPath); @@ -188,16 +187,17 @@ public static function getTemporaryURL(Zotero_Item $item, $localOnly=false) { if (!mkdir($downloadDir, 0777, true)) { throw new Exception("Unable to create directory '$downloadDir'"); } + $archiveFilename = 'archive.zip'; if ($zip) { - $response = Zotero_Storage::downloadFile($info, $downloadDir, '1.zip'); + $response = Zotero_Storage::downloadFile($info, $downloadDir, $archiveFilename); } else { $response = Zotero_Storage::downloadFile($info, $downloadDir, $realFilename); } if ($response) { if ($zip) { - $success = self::extractZip($downloadDir . '1.zip', $dir); - unlink($downloadDir . '1.zip'); + $success = self::extractZip($downloadDir . $archiveFilename, $dir); + unlink($downloadDir . $archiveFilename); rmdir($downloadDir); // Make sure charset is just a string with no spaces or newlines diff --git a/model/Storage.inc.php b/model/Storage.inc.php index 407ab1835..5386ca7ad 100644 --- a/model/Storage.inc.php +++ b/model/Storage.inc.php @@ -188,7 +188,7 @@ public static function logDownload($item, $downloadUserID, $ipAddress) { $size = $info['size']; $sql = "INSERT INTO storageDownloadLog - (ownerUserID, downloadUserID, ipAddress, storageFileID, size) + (ownerUserID, downloadUserID, ipAddress, storageFileID, `size`) VALUES (?, ?, INET_ATON(?), ?, ?)"; Zotero_DB::query( $sql, @@ -480,7 +480,9 @@ public static function duplicateFile($storageFileID, $newName, $zip, $contentTyp return self::addFile($info); } - + // TODO: Remove + // Was previously used in ItemController to find a file with a different name, + // if not found with the given filename. Now getLocalFileInfo does the same. public static function getFileByHash($hash, $zip) { $sql = "SELECT storageFileID FROM storageFiles WHERE hash=? AND zip=? LIMIT 1"; return Zotero_DB::valueQuery($sql, array($hash, (int) $zip)); @@ -493,7 +495,7 @@ public static function getFileInfoByID($storageFileID) { public static function getLocalFileInfo(Zotero_StorageFileInfo $info) { $sql = "SELECT * FROM storageFiles WHERE hash=? AND zip=? ORDER BY storageFileID LIMIT 1"; - return Zotero_DB::rowQuery($sql, array($info->hash, (int)$info->zip)); + return Zotero_DB::rowQuery($sql, array($info->hash, (int) $info->zip)); } public static function getRemoteFileInfo(Zotero_StorageFileInfo $info) { @@ -575,7 +577,7 @@ public static function getFileItems($hash, $filename, $zip) { public static function addFile(Zotero_StorageFileInfo $info) { $sql = "INSERT INTO storageFiles (hash, `size`, zip) VALUES (?,?,?)"; - return Zotero_DB::query($sql, array($info->hash, $info->size, (int)$info->zip)); + return Zotero_DB::query($sql, array($info->hash, $info->size, (int) $info->zip)); } From 3d84586d8e7218cdef871cdcea5caacc80c8d12f Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 30 May 2018 10:43:47 +0300 Subject: [PATCH 3/4] Remove 'duplicateFile'; remove S3 key prefixing depending on 'zip' field; remove 'getFileByHash' remove unnecessary backticks; remove any 'storageFiles' filtering on 'zip' or 'filename' fields --- model/Storage.inc.php | 114 ++++++------------------------------------ 1 file changed, 14 insertions(+), 100 deletions(-) diff --git a/model/Storage.inc.php b/model/Storage.inc.php index 5386ca7ad..305dd7685 100644 --- a/model/Storage.inc.php +++ b/model/Storage.inc.php @@ -87,13 +87,12 @@ public static function getDownloadURL(Zotero_Item $item, $ttl=60) { // http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#headobject, // but returning NotFound if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { - // Try legacy key format, with zip flag + // Try to find a legacy file: hash/filename or hash/c/filename try { - $key = self::getPathPrefix($info['hash'], $info['zip']); $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, 'MaxKeys' => 1, - 'Prefix' => $key, + 'Prefix' => $info['hash'], ]); $contents = $result->get('Contents'); @@ -139,13 +138,12 @@ public static function downloadFile(array $localFileItemInfo, $savePath, $filena } catch (\Aws\S3\Exception\S3Exception $e) { if ($e->getAwsErrorCode() == 'NoSuchKey') { - // Try legacy key format, with zip flag and filename + // Try to find a legacy file: hash/filename or hash/c/filename try { - $key = self::getPathPrefix($localFileItemInfo['hash'], $localFileItemInfo['zip']); $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, 'MaxKeys' => 1, - 'Prefix' => $key, + 'Prefix' => $localFileItemInfo['hash'], ]); $contents = $result->get('Contents'); @@ -188,7 +186,7 @@ public static function logDownload($item, $downloadUserID, $ipAddress) { $size = $info['size']; $sql = "INSERT INTO storageDownloadLog - (ownerUserID, downloadUserID, ipAddress, storageFileID, `size`) + (ownerUserID, downloadUserID, ipAddress, storageFileID, size) VALUES (?, ?, INET_ATON(?), ?, ?)"; Zotero_DB::query( $sql, @@ -292,7 +290,7 @@ public static function logUpload($uploadUserID, $item, $key, $ipAddress) { Zotero_DB::query($sql, $key); $sql = "INSERT INTO storageUploadLog - (ownerUserID, uploadUserID, ipAddress, storageFileID, `size`) + (ownerUserID, uploadUserID, ipAddress, storageFileID, size) VALUES (?, ?, INET_ATON(?), ?, ?)"; Zotero_DB::query($sql, array($ownerUserID, $uploadUserID, $ipAddress, $storageFileID, $size)); } @@ -410,92 +408,14 @@ public static function patchFile($item, $info, $algorithm, $patch) { return $storageFileID; } - public static function duplicateFile($storageFileID, $newName, $zip, $contentType=null) { - if (strlen($newName) == 0) { - throw new Exception("New name not provided"); - } - - $localInfo = self::getFileInfoByID($storageFileID); - if (!$localInfo) { - throw new Exception("File $storageFileID not found"); - } - - $s3Client = Z_Core::$AWS->createS3(); - try { - $s3Client->headObject([ - 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'Key' => $localInfo['hash'] - ]); - } - // If file doesn't already exist named with just hash, copy it over - catch (\Aws\S3\Exception\S3Exception $e) { - if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { - try { - $key = self::getPathPrefix($localInfo['hash'], $localInfo['zip']); - $result = $s3Client->listObjects([ - 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'MaxKeys' => 1, - 'Prefix' => $key, - ]); - - $contents = $result->get('Contents'); - if (!$contents || count($contents) < 1) { - return false; - } - - $key = $contents[0]['Key']; - - try { - $s3Client->copyObject([ - 'Bucket' => Z_CONFIG::$S3_BUCKET, - 'CopySource' => Z_CONFIG::$S3_BUCKET . '/' - . urlencode($key), - 'Key' => $localInfo['hash'], - 'ACL' => 'private' - ]); - } - catch (\Aws\S3\Exception\S3Exception $e) { - if ($e->getAwsErrorCode() == 'NoSuchKey') { - return false; - } - else { - throw $e; - } - } - } - catch (\Aws\S3\Exception\S3Exception $e) { - throw $e; - } - } - else { - throw $e; - } - } - - $info = new Zotero_StorageFileInfo; - foreach ($localInfo as $key => $val) { - $info->$key = $val; - } - - return self::addFile($info); - } - - // TODO: Remove - // Was previously used in ItemController to find a file with a different name, - // if not found with the given filename. Now getLocalFileInfo does the same. - public static function getFileByHash($hash, $zip) { - $sql = "SELECT storageFileID FROM storageFiles WHERE hash=? AND zip=? LIMIT 1"; - return Zotero_DB::valueQuery($sql, array($hash, (int) $zip)); - } - public static function getFileInfoByID($storageFileID) { $sql = "SELECT * FROM storageFiles WHERE storageFileID=?"; return Zotero_DB::rowQuery($sql, $storageFileID); } public static function getLocalFileInfo(Zotero_StorageFileInfo $info) { - $sql = "SELECT * FROM storageFiles WHERE hash=? AND zip=? ORDER BY storageFileID LIMIT 1"; - return Zotero_DB::rowQuery($sql, array($info->hash, (int) $info->zip)); + $sql = "SELECT * FROM storageFiles WHERE hash=? ORDER BY storageFileID LIMIT 1"; + return Zotero_DB::rowQuery($sql, array($info->hash)); } public static function getRemoteFileInfo(Zotero_StorageFileInfo $info) { @@ -509,13 +429,12 @@ public static function getRemoteFileInfo(Zotero_StorageFileInfo $info) { } catch (\Aws\S3\Exception\S3Exception $e) { if ($e->getAwsErrorCode() == 'NoSuchKey' || $e->getAwsErrorCode() == 'NotFound') { - // Try legacy key format, with zip flag + // Try to find a legacy file: hash/filename or hash/c/filename try { - $key = self::getPathPrefix($info->hash, $info->zip); $result = $s3Client->listObjects([ 'Bucket' => Z_CONFIG::$S3_BUCKET, 'MaxKeys' => 1, - 'Prefix' => $key, + 'Prefix' => $info->hash, ]); $contents = $result->get('Contents'); @@ -562,12 +481,12 @@ public static function getLocalFileItemInfo($item) { /** * Get items associated with a unique file on S3 */ - public static function getFileItems($hash, $filename, $zip) { + public static function getFileItems($hash) { throw new Exception("Unimplemented"); // would need to work across shards $sql = "SELECT itemID FROM storageFiles JOIN storageFileItems USING (storageFileID) - WHERE hash=? AND filename=? AND zip=?"; - $itemIDs = Zotero_DB::columnQuery($sql, array($hash, $filename, (int) $zip)); + WHERE hash=?"; + $itemIDs = Zotero_DB::columnQuery($sql, array($hash)); if (!$itemIDs) { return array(); } @@ -576,7 +495,7 @@ public static function getFileItems($hash, $filename, $zip) { public static function addFile(Zotero_StorageFileInfo $info) { - $sql = "INSERT INTO storageFiles (hash, `size`, zip) VALUES (?,?,?)"; + $sql = "INSERT INTO storageFiles (hash, size, zip) VALUES (?,?,?)"; return Zotero_DB::query($sql, array($info->hash, $info->size, (int) $info->zip)); } @@ -677,11 +596,6 @@ public static function deleteFileLibraryReference($storageFileID, $libraryID) { } - public static function getPathPrefix($hash, $zip=false) { - return "$hash/" . ($zip ? "c/" : ''); - } - - public static function getUploadPOSTData($item, Zotero_StorageFileInfo $info) { $params = self::generateUploadPOSTParams($item, $info); $boundary = "---------------------------" . md5(uniqid()); From 0d6b96be645974bdff56f25388fe40c21765a2b7 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 30 May 2018 10:57:58 +0300 Subject: [PATCH 4/4] Fix comment --- controllers/ItemsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/ItemsController.php b/controllers/ItemsController.php index ff392a7b2..eb3abd4e7 100644 --- a/controllers/ItemsController.php +++ b/controllers/ItemsController.php @@ -961,7 +961,7 @@ private function _handleFileRequest($item) { Zotero_DB::query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); Zotero_DB::beginTransaction(); - // See if file exists with this hash and zip flag + // See if file exists with this hash $localInfo = Zotero_Storage::getLocalFileInfo($info); if ($localInfo) { $storageFileID = $localInfo['storageFileID'];