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..7e7ebd795a 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) { @@ -196,19 +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']; - } return array_map(function (array $data) { - return new CacheEntry($data); + return self::cacheEntryFromData($data, $this->mimetypeLoader);; }, $files); } else { return array(); @@ -601,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); } @@ -633,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); } @@ -659,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`, ' . @@ -686,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); }