diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 50b3c5522856..d8215b66da8c 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -461,6 +461,7 @@ public static function getVersions($uid, $filename, $userFullPath = '') { $versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename); $versions[$key]['name'] = $versionedFile; $versions[$key]['size'] = $view->filesize($dir . '/' . $entryName); + $versions[$key]['storage_location'] = "$dir/$entryName"; } } } diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 1c56606f9610..6657ccefa622 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -62,7 +62,7 @@ * Some \OC\Files\Storage\Common methods call functions which are first defined * in classes which extend it, e.g. $this->stat() . */ -abstract class Common implements Storage, ILockingStorage { +abstract class Common implements Storage, ILockingStorage, IVersionedStorage { use LocalTempFileTrait; @@ -684,4 +684,41 @@ public function getAvailability() { public function setAvailability($isAvailable) { $this->getStorageCache()->setAvailability($isAvailable); } + public function getVersions($internalPath) { + // KISS implementation + if (!\OC_App::isEnabled('files_versions')) { + return []; + } + if (strpos($internalPath, 'files/') !== 0) { + return []; + } + $internalPath = substr($internalPath, 6); + return array_values( + \OCA\Files_Versions\Storage::getVersions($this->getOwner($internalPath), $internalPath)); + } + + public function getVersion($internalPath, $versionId) { + $versions = $this->getVersions($internalPath); + $versions = array_filter($versions, function ($version) use($versionId){ + return $version['version'] === $versionId; + }); + return array_shift($versions); + } + + public function getContentOfVersion($internalPath, $versionId) { + $v = $this->getVersion($internalPath, $versionId); + return $this->file_get_contents($v['storage_location']); + } + + public function restoreVersion($internalPath, $versionId) { + // KISS implementation + if (!\OC_App::isEnabled('files_versions')) { + return; + } + if (strpos($internalPath, 'files/') !== 0) { + return; + } + $internalPath = substr($internalPath, 6); + \OCA\Files_Versions\Storage::rollback($internalPath, $versionId); + } } diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index d1cc475225b5..180d354e9f08 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -41,7 +41,7 @@ /** * for local filestore, we only have to map the paths */ -class Local extends \OC\Files\Storage\Common { +class Local extends Common { protected $datadir; protected $dataDirLength; @@ -412,7 +412,7 @@ public function getETag($path) { * @param string $targetInternalPath * @return bool */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')) { /** * @var \OC\Files\Storage\Local $sourceStorage @@ -420,7 +420,7 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern $rootStorage = new Local(['datadir' => '/']); return $rootStorage->copy($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); } else { - return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } }