Skip to content

Commit

Permalink
Minimalistic implementation of versions integration - needs change in…
Browse files Browse the repository at this point in the history
… the future
  • Loading branch information
DeepDiver1975 committed Oct 17, 2017
1 parent 069cb3e commit 5f49a5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}
Expand Down
40 changes: 39 additions & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IVersionedStorage;
use OCP\Lock\ILockingProvider;

/**
Expand All @@ -62,7 +63,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;

Expand Down Expand Up @@ -684,4 +685,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);
}
}
6 changes: 3 additions & 3 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -412,15 +412,15 @@ 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
*/
$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);
}
}

Expand Down

0 comments on commit 5f49a5a

Please sign in to comment.