Allow to read get old versions

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-04-30 21:18:49 +02:00
parent dd47ebb062
commit 5401732cd2
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 20 additions and 4 deletions

View File

@ -71,7 +71,7 @@ class VersionCollection implements ICollection {
$versions = Storage::getVersions($this->userId, $this->userFolder->getRelativePath($this->file->getPath())); $versions = Storage::getVersions($this->userId, $this->userFolder->getRelativePath($this->file->getPath()));
return array_map(function (array $data) { return array_map(function (array $data) {
return new VersionFile($data); return new VersionFile($data, $this->userFolder->getParent());
}, $versions); }, $versions);
} }

View File

@ -24,16 +24,23 @@ declare(strict_types=1);
namespace OCA\Files_Versions\Sabre; namespace OCA\Files_Versions\Sabre;
use OCA\Files_Versions\Storage; use OCA\Files_Versions\Storage;
use OCP\Files\FileInfo; use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IFile; use Sabre\DAV\IFile;
class VersionFile implements IFile { class VersionFile implements IFile {
/** @var array */ /** @var array */
private $data; private $data;
public function __construct(array $data) { /** @var Folder */
private $userRoot;
public function __construct(array $data, Folder $userRoot) {
$this->data = $data; $this->data = $data;
$this->userRoot = $userRoot;
} }
public function put($data) { public function put($data) {
@ -41,7 +48,16 @@ class VersionFile implements IFile {
} }
public function get() { public function get() {
throw new Forbidden(); try {
/** @var Folder $versions */
$versions = $this->userRoot->get('files_versions');
/** @var File $version */
$version = $versions->get($this->data['path'].'.v'.$this->data['version']);
} catch (NotFoundException $e) {
throw new NotFound();
}
return $version->fopen('rb');
} }
public function getContentType(): string { public function getContentType(): string {