/** * Retrieves all files and sub-folders contained in a folder * * If we can't find anything in the current folder, we throw an exception as there is no point * in doing any more work, but if we're looking at a sub-folder, we return an empty array so * that it can be simply ignored * * @param Folder $folder * @param int $subDepth * * @return array * * @throws NotFoundServiceException */ protected function getNodes($folder, $subDepth) { try { $nodes = $folder->getDirectoryListing(); } catch (\Exception $exception) { $nodes = $this->recoverFromGetNodesError($subDepth, $exception); } return $nodes; }
/** * remove the users avatar * @return void */ public function remove() { $regex = '/^avatar\\.([0-9]+\\.)?(jpg|png)$/'; $avatars = $this->folder->getDirectoryListing(); foreach ($avatars as $avatar) { if (preg_match($regex, $avatar->getName())) { $avatar->delete(); } } $this->user->triggerChange('avatar'); }
/** * @param \OCP\Files\Folder $folder * @return \OC_OCS_Result */ private function getSharesInDir($folder) { if (!$folder instanceof \OCP\Files\Folder) { return new \OC_OCS_Result(null, 400, "not a directory"); } $nodes = $folder->getDirectoryListing(); /** @var \OCP\Share\IShare[] $shares */ $shares = []; foreach ($nodes as $node) { $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); } } $formatted = []; foreach ($shares as $share) { try { $formatted[] = $this->formatShare($share); } catch (NotFoundException $e) { //Ignore this share } } return new \OC_OCS_Result($formatted); }
/** * @param \OCP\Files\Folder $folder * @return \OC_OCS_Result */ private function getSharesInDir($folder) { if (!$folder instanceof \OCP\Files\Folder) { return new \OC_OCS_Result(null, 400, "not a directory"); } $nodes = $folder->getDirectoryListing(); /** @var IShare[] $shares */ $shares = []; foreach ($nodes as $node) { $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); //TODO: Add federated shares } $formatted = []; foreach ($shares as $share) { $formatted[] = $this->formatShare($share); } return new \OC_OCS_Result($formatted); }