Browse Source

Allow to read get old versions

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
pull/9353/head
Roeland Jago Douma 8 years ago
parent
commit
5401732cd2
No known key found for this signature in database GPG Key ID: F941078878347C0C
  1. 2
      apps/files_versions/lib/Sabre/VersionCollection.php
  2. 22
      apps/files_versions/lib/Sabre/VersionFile.php

2
apps/files_versions/lib/Sabre/VersionCollection.php

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

22
apps/files_versions/lib/Sabre/VersionFile.php

@ -24,16 +24,23 @@ declare(strict_types=1);
namespace OCA\Files_Versions\Sabre;
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\NotFound;
use Sabre\DAV\IFile;
class VersionFile implements IFile {
/** @var array */
private $data;
public function __construct(array $data) {
/** @var Folder */
private $userRoot;
public function __construct(array $data, Folder $userRoot) {
$this->data = $data;
$this->userRoot = $userRoot;
}
public function put($data) {
@ -41,7 +48,16 @@ class VersionFile implements IFile {
}
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 {

Loading…
Cancel
Save