From 0f3cf7fee880e61e104a1b27d386e9c3bffc92d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Fortier?= Date: Mon, 20 Feb 2017 22:07:37 -0500 Subject: [PATCH 1/2] Typecast filecache 'storage' as int to return it as documented, fixes #3461 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Frédéric Fortier --- apps/files_sharing/lib/SharedMount.php | 2 +- lib/private/Files/Cache/Cache.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 2ef5e15b77..d5ae303390 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -253,7 +253,7 @@ class SharedMount extends MountPoint implements MoveableMount { $row = $result->fetch(); $result->closeCursor(); if ($row) { - return $row['storage']; + return (int)$row['storage']; } return -1; } diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index a966d621c5..689a3ad809 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -163,6 +163,7 @@ class Cache implements ICache { $data['encryptedVersion'] = (int)$data['encrypted']; $data['encrypted'] = (bool)$data['encrypted']; $data['storage_id'] = $data['storage']; + $data['storage'] = (int)$data['storage']; $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']); $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']); if ($data['storage_mtime'] == 0) { @@ -206,6 +207,7 @@ class Cache implements ICache { $file['mtime'] = (int)$file['mtime']; $file['storage_mtime'] = (int)$file['storage_mtime']; $file['size'] = 0 + $file['size']; + $file['storage'] = (int)$file['storage']; } return array_map(function (array $data) { return new CacheEntry($data); From 198cd4f83e4b968c8eced9c8287ea8721614a695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Fortier?= Date: Wed, 22 Feb 2017 20:03:32 -0500 Subject: [PATCH 2/2] Refactor files' CacheEntry object creation to call cacheEntryFromData() all the time thus allowing proper casts to be done MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Frédéric Fortier --- lib/private/Files/Cache/Cache.php | 52 ++++++++++--------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 689a3ad809..7e7ebd795a 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -197,20 +197,8 @@ class Cache implements ICache { FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC'; $result = $this->connection->executeQuery($sql, [$fileId]); $files = $result->fetchAll(); - foreach ($files as &$file) { - $file['mimetype'] = $this->mimetypeLoader->getMimetypeById($file['mimetype']); - $file['mimepart'] = $this->mimetypeLoader->getMimetypeById($file['mimepart']); - if ($file['storage_mtime'] == 0) { - $file['storage_mtime'] = $file['mtime']; - } - $file['permissions'] = (int)$file['permissions']; - $file['mtime'] = (int)$file['mtime']; - $file['storage_mtime'] = (int)$file['storage_mtime']; - $file['size'] = 0 + $file['size']; - $file['storage'] = (int)$file['storage']; - } return array_map(function (array $data) { - return new CacheEntry($data); + return self::cacheEntryFromData($data, $this->mimetypeLoader);; }, $files); } else { return array(); @@ -603,22 +591,18 @@ class Cache implements ICache { $sql = ' SELECT `fileid`, `storage`, `path`, `parent`, `name`, - `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, - `etag`, `permissions`, `checksum` + `mimetype`, `storage_mtime`, `mimepart`, `size`, `mtime`, + `encrypted`, `etag`, `permissions`, `checksum` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `name` ILIKE ?'; $result = $this->connection->executeQuery($sql, [$this->getNumericStorageId(), $pattern] ); - $files = []; - while ($row = $result->fetch()) { - $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']); - $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); - $files[] = $row; - } + $files = $result->fetchAll(); + return array_map(function(array $data) { - return new CacheEntry($data); + return self::cacheEntryFromData($data, $this->mimetypeLoader); }, $files); } @@ -635,18 +619,15 @@ class Cache implements ICache { } else { $where = '`mimepart` = ?'; } - $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum` FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'; $mimetype = $this->mimetypeLoader->getId($mimetype); $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); - $files = array(); - while ($row = $result->fetch()) { - $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']); - $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); - $files[] = $row; - } + + $files = $result->fetchAll(); + return array_map(function (array $data) { - return new CacheEntry($data); + return self::cacheEntryFromData($data, $this->mimetypeLoader); }, $files); } @@ -661,7 +642,7 @@ class Cache implements ICache { */ public function searchByTag($tag, $userId) { $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . - '`mimetype`, `mimepart`, `size`, `mtime`, ' . + '`mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`, ' . '`encrypted`, `etag`, `permissions`, `checksum` ' . 'FROM `*PREFIX*filecache` `file`, ' . '`*PREFIX*vcategory_to_object` `tagmap`, ' . @@ -688,12 +669,11 @@ class Cache implements ICache { $tag ] ); - $files = array(); - while ($row = $result->fetch()) { - $files[] = $row; - } + + $files = $result->fetchAll(); + return array_map(function (array $data) { - return new CacheEntry($data); + return self::cacheEntryFromData($data, $this->mimetypeLoader); }, $files); }