aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/Listener/FileEventsListener.php9
-rw-r--r--apps/files_versions/lib/Versions/LegacyVersionsBackend.php12
-rw-r--r--apps/files_versions/tests/VersioningTest.php10
3 files changed, 20 insertions, 11 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index d847c60ec64..4b7385d6e2d 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -36,6 +36,7 @@ use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
+use OCP\Files\NotFoundException;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
@@ -250,7 +251,7 @@ class FileEventsListener implements IEventListener {
/**
* Erase versions of deleted file
*
- * This function is connected to the delete signal of OC_Filesystem
+ * This function is connected to the NodeDeletedEvent event
* cleanup the versions directory if the actual file gets deleted
*/
public function remove_hook(Node $node): void {
@@ -282,7 +283,7 @@ class FileEventsListener implements IEventListener {
/**
* rename/move versions of renamed/moved files
*
- * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
+ * This function is connected to the NodeRenamedEvent event and adjust the name and location
* of the stored versions along the actual file
*/
public function rename_hook(Node $source, Node $target): void {
@@ -301,7 +302,7 @@ class FileEventsListener implements IEventListener {
/**
* copy versions of copied files
*
- * This function is connected to the copy signal of OC_Filesystem and copies the
+ * This function is connected to the NodeCopiedEvent event and copies the
* the stored versions to the new location
*/
public function copy_hook(Node $source, Node $target): void {
@@ -378,7 +379,7 @@ class FileEventsListener implements IEventListener {
try {
$owner = $node->getOwner()?->getUid();
- } catch (\OCP\Files\NotFoundException) {
+ } catch (NotFoundException) {
$owner = null;
}
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
index 92b326b6cd3..59a10a0775d 100644
--- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
+++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
@@ -367,16 +367,20 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
* @inheritdoc
*/
public function clearVersionsForFile(IUser $user, Node $source, Node $target): void {
- $userFolder = $this->rootFolder->getUserFolder($user->getUID());
+ $userId = $user->getUID();
+ $userFolder = $this->rootFolder->getUserFolder($userId);
$relativePath = $userFolder->getRelativePath($source->getPath());
if ($relativePath === null) {
throw new Exception('Relative path not found for node with path: ' . $source->getPath());
}
- $versions = Storage::getVersions($user->getUID(), $relativePath);
- /** @var Folder versionFolder */
- $versionFolder = $this->rootFolder->get('admin/files_versions');
+ $versionFolder = $this->rootFolder->get($userId . '/files_versions');
+ if (!$versionFolder instanceof Folder) {
+ throw new Exception('User versions folder does not exist');
+ }
+
+ $versions = Storage::getVersions($userId, $relativePath);
foreach ($versions as $version) {
$versionFolder->get($version['path'] . '.v' . (int)$version['version'])->delete();
}
diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php
index f294390a593..7d027ca566f 100644
--- a/apps/files_versions/tests/VersioningTest.php
+++ b/apps/files_versions/tests/VersioningTest.php
@@ -83,7 +83,10 @@ class VersioningTest extends \Test\TestCase {
parent::setUp();
$config = Server::get(IConfig::class);
- $mockConfig = $this->createMock(IConfig::class);
+ $mockConfig = $this->getMockBuilder(AllConfig::class)
+ ->onlyMethods(['getSystemValue'])
+ ->setConstructorArgs([Server::get(\OC\SystemConfig::class)])
+ ->getMock();
$mockConfig->expects($this->any())
->method('getSystemValue')
->willReturnCallback(function ($key, $default) use ($config) {
@@ -427,8 +430,9 @@ class VersioningTest extends \Test\TestCase {
$this->rootView->file_put_contents($v2, 'version2');
// move file into the shared folder as recipient
- Filesystem::rename('/test.txt', '/folder1/test.txt');
+ $success = Filesystem::rename('/test.txt', '/folder1/test.txt');
+ $this->assertTrue($success);
$this->assertFalse($this->rootView->file_exists($v1));
$this->assertFalse($this->rootView->file_exists($v2));
@@ -808,7 +812,7 @@ class VersioningTest extends \Test\TestCase {
$eventDispatcher = Server::get(IEventDispatcher::class);
$eventFired = false;
- $eventDispatcher->addListener(VersionRestoredEvent::class, function ($event) use (&$eventFired, $t2) {
+ $eventDispatcher->addListener(VersionRestoredEvent::class, function ($event) use (&$eventFired, $t2): void {
$eventFired = true;
$this->assertEquals('/sub/test.txt', $event->getVersion()->getVersionPath());
$this->assertTrue($event->getVersion()->getRevisionId() > 0);