/** * Create a share object from an database row * * @param mixed[] $data * @return Share */ private function createShare($data) { $share = new Share(); $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setShareTime((int) $data['stime'])->setMailSend((bool) $data['mail_send']); if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { $share->setSharedWith($this->userManager->get($data['share_with'])); } else { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { $share->setSharedWith($this->groupManager->get($data['share_with'])); } else { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { $share->setPassword($data['share_with']); $share->setToken($data['token']); } else { $share->setSharedWith($data['share_with']); } } } $share->setSharedBy($this->userManager->get($data['uid_owner'])); // TODO: getById can return an array. How to handle this properly?? $path = $this->userFolder->getById((int) $data['file_source']); $path = $path[0]; $share->setPath($path); $owner = $path->getStorage()->getOwner('.'); if ($owner !== false) { $share->setShareOwner($this->userManager->get($owner)); } if ($data['expiration'] !== null) { $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); $share->setExpirationDate($expiration); } return $share; }
/** * Returns the resource identified by the given ID * * @param int $resourceId * * @return Node * * @throws NotFoundEnvException */ public function getResourceFromId($resourceId) { $resourcesArray = $this->userFolder->getById($resourceId); if ($resourcesArray[0] === null) { throw new NotFoundEnvException('Could not locate file linked to ID: ' . $resourceId); } return $resourcesArray[0]; }
/** * Get all files for the given tag * * @param array $tagName tag name to filter by * @return FileInfo[] list of matching files * @throws \Exception if the tag does not exist */ public function getFilesByTag($tagName) { try { $fileIds = $this->tagger->getIdsForTag($tagName); } catch (\Exception $e) { return []; } $fileInfos = []; foreach ($fileIds as $fileId) { $nodes = $this->homeFolder->getById((int) $fileId); foreach ($nodes as $node) { /** @var \OC\Files\Node\Node $node */ $fileInfos[] = $node->getFileInfo(); } } return $fileInfos; }
/** * Get all files for the given tag * * @param string $tagName tag name to filter by * @return Node[] list of matching files * @throws \Exception if the tag does not exist */ public function getFilesByTag($tagName) { try { $fileIds = $this->tagger->getIdsForTag($tagName); } catch (\Exception $e) { return []; } $allNodes = []; foreach ($fileIds as $fileId) { $allNodes = array_merge($allNodes, $this->homeFolder->getById((int) $fileId)); } return $allNodes; }
/** * @NoAdminRequired * @NoCSRFRequired */ public function cover() { // we no longer need the session to be kept open session_write_close(); $albumId = $this->getIdFromSlug($this->params('albumIdOrSlug')); $album = $this->albumBusinessLayer->find($albumId, $this->userId); $nodes = $this->userFolder->getById($album->getCoverFileId()); if (count($nodes) > 0) { // get the first valid node $node = $nodes[0]; $mime = $node->getMimeType(); $content = $node->getContent(); return new FileResponse(array('mimetype' => $mime, 'content' => $content)); } $r = new Response(); $r->setStatus(Http::STATUS_NOT_FOUND); return $r; }
/** * {@inheritDoc} */ public function getFilePath($itemSource, $uidOwner) { try { $calendar = $this->calendars->find($itemSource, $uidOwner); $fileId = $calendar->getFileId(); if ($fileId === null) { return false; } $files = $this->userFolder->getById($fileId); if (!$files || empty($files)) { return false; } else { return $files[0]->getPath(); } } catch (BusinessLayer\Exception $ex) { return false; } }
/** * {@inheritDoc} */ public function getFilePath($itemSource, $uidOwner) { try { if (substr_count($itemSource, '::') === 0) { return false; } list($calendarId) = explode('::', $itemSource, 1); $calendar = $this->calendars->find($calendarId, $uidOwner); $fileId = $calendar->getFileId(); if ($fileId === null) { return false; } $files = $this->userFolder->getById($fileId); if (!$files || empty($files)) { return false; } else { return $files[0]->getPath(); } } catch (BusinessLayer\Exception $ex) { return false; } }
/** * Checks if a child-node with the specified name exists * * @param string $name * @return bool */ function childExists($name) { $nodes = $this->fileRoot->getById(intval($name)); return !empty($nodes); }
/** * @param Folder $folder * @param int $id * @throws NoteDoesNotExistException * @return \OCP\Files\File */ private function getFileById($folder, $id) { $file = $folder->getById($id); if (count($file) <= 0 || !$this->isNote($file[0])) { throw new NoteDoesNotExistException(); } return $file[0]; }
/** * @param Folder $folder * @param int $id * @throws NoteDoesNotExistException * @return \OCP\Files\File */ private function getFileById($folder, $id) { $file = $folder->getById($id); if (count($file) <= 0 || $file[0]->getMimeType() !== 'text/plain') { throw new NoteDoesNotExistException(); } return $file[0]; }
/** * Returns the resource found in a specific folder and identified by the given ID * * @param Folder $folder * @param int $resourceId * * @return Node * @throws NotFoundEnvException */ private function getResourceFromFolderAndId($folder, $resourceId) { $resourcesArray = $folder->getById($resourceId); if ($resourcesArray[0] === null) { throw new NotFoundEnvException('Could not locate node linked to ID: ' . $resourceId); } return $resourcesArray[0]; }