*/
private $numericId;
+ private $mimetypeIds = array();
+ private $mimetypes = array();
+
/**
* @param \OC\Files\Storage\Storage|string $storage
*/
return $this->numericId;
}
+ /**
+ * normalize mimetypes
+ *
+ * @param string $mime
+ * @return int
+ */
+ public function getMimetypeId($mime) {
+ if (!isset($this->mimetypeIds[$mime])) {
+ $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
+ $result = $query->execute(array($mime));
+ if ($row = $result->fetchRow()) {
+ $this->mimetypeIds[$mime] = $row['id'];
+ } else {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)');
+ $query->execute(array($mime));
+ $this->mimetypeIds[$mime] = \OC_DB::insertid('*PREFIX*mimetypes');
+ }
+ $this->mimetypes[$this->mimetypeIds[$mime]] = $mime;
+ }
+ return $this->mimetypeIds[$mime];
+ }
+
+ public function getMimetype($id) {
+ if (!isset($this->mimetypes[$id])) {
+ $query = \OC_DB::prepare('SELECT `mimetype` FROM `*PREFIX*mimetypes` WHERE `id` = ?');
+ $result = $query->execute(array($id));
+ if ($row = $result->fetchRow()) {
+ $this->mimetypes[$id] = $row['mimetype'];
+ } else {
+ return null;
+ }
+ }
+ return $this->mimetypes[$id];
+ }
+
/**
* get the stored metadata of a file or folder
*
$data['size'] = (int)$data['size'];
$data['mtime'] = (int)$data['mtime'];
$data['encrypted'] = (bool)$data['encrypted'];
+ $data['mimetype'] = $this->getMimetype($data['mimetype']);
+ $data['mimepart'] = $this->getMimetype($data['mimepart']);
}
return $data;
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
FROM `*PREFIX*filecache` WHERE parent = ? ORDER BY `name` ASC');
$result = $query->execute(array($fileId));
- return $result->fetchAll();
+ $files = $result->fetchAll();
+ foreach ($files as &$file) {
+ $file['mimetype'] = $this->getMimetype($file['mimetype']);
+ $file['mimepart'] = $this->getMimetype($file['mimepart']);
+ }
+ return $files;
} else {
return array();
}
* @param array $data
* @return array
*/
- static function buildParts(array $data) {
+ function buildParts(array $data) {
$fields = array('path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'encrypted');
$params = array();
$queryParts = array();
foreach ($data as $name => $value) {
if (array_search($name, $fields) !== false) {
- $params[] = $value;
- $queryParts[] = '`' . $name . '`';
if ($name === 'path') {
$params[] = md5($value);
$queryParts[] = '`path_hash`';
} elseif ($name === 'mimetype') {
- $params[] = substr($value, 0, strpos($value, '/'));
+ $params[] = $this->getMimetypeId(substr($value, 0, strpos($value, '/')));
$queryParts[] = '`mimepart`';
+ $value = $this->getMimetypeId($value);
}
+ $params[] = $value;
+ $queryParts[] = '`' . $name . '`';
}
}
return array($queryParts, $params);
$result = $query->execute(array($pattern, $this->numericId));
$files = array();
while ($row = $result->fetchRow()) {
+ $row['mimetype'] = $this->getMimetype($row['mimetype']);
+ $row['mimepart'] = $this->getMimetype($row['mimepart']);
$files[] = $row;
}
return $files;
SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'
);
+ $mimetype = $this->getMimetypeId($mimetype);
$result = $query->execute(array($mimetype, $this->numericId));
return $result->fetchAll();
}