Typecast shared mount's storage_id to int as documented + some refactor to avoid similar bugs
This commit is contained in:
Lukas Reschke 2017-02-24 17:25:21 +01:00 committed by GitHub
commit dd6d2893a6
2 changed files with 18 additions and 36 deletions

View file

@ -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;
}

View file

@ -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);
}