summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-05-16 11:37:12 +0200
committerGitHub <noreply@github.com>2018-05-16 11:37:12 +0200
commit0011bfb64bedbfa412ffd2190433fe0b51830ce9 (patch)
tree4584d571aeacae0e7ceffe7b9643d623c92525e1
parent7de6c06c66df859f6e5ffcd4e0c85580b3c4d365 (diff)
parent39bb9c06d165af8b39ba2c3cdcd8d4f9727e6afd (diff)
downloadnextcloud-server-0011bfb64bedbfa412ffd2190433fe0b51830ce9.tar.gz
nextcloud-server-0011bfb64bedbfa412ffd2190433fe0b51830ce9.zip
Merge pull request #9475 from nextcloud/bug/9469/delete_preview_on_version_restore
Delete the previews when a version is restored
-rw-r--r--apps/files_versions/lib/Storage.php8
-rw-r--r--lib/private/Preview/Watcher.php10
-rw-r--r--lib/private/Preview/WatcherConnector.php2
3 files changed, 20 insertions, 0 deletions
diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php
index 217bf02fd39..401544cc5d7 100644
--- a/apps/files_versions/lib/Storage.php
+++ b/apps/files_versions/lib/Storage.php
@@ -337,6 +337,9 @@ class Storage {
return false;
}
+ // Fetch the userfolder to trigger view hooks
+ $userFolder = \OC::$server->getUserFolder($uid);
+
$users_view = new View('/'.$uid);
$files_view = new View('/'. User::getUser().'/files');
@@ -375,9 +378,14 @@ class Storage {
if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) {
$files_view->touch($file, $revision);
Storage::scheduleExpire($uid, $file);
+
+ $node = $userFolder->get($file);
+
+ // TODO: move away from those legacy hooks!
\OC_Hook::emit('\OCP\Versions', 'rollback', array(
'path' => $filename,
'revision' => $revision,
+ 'node' => $node,
));
return true;
} else if ($versionCreated) {
diff --git a/lib/private/Preview/Watcher.php b/lib/private/Preview/Watcher.php
index be462d9c935..0c0531dff94 100644
--- a/lib/private/Preview/Watcher.php
+++ b/lib/private/Preview/Watcher.php
@@ -49,6 +49,10 @@ class Watcher {
}
public function postWrite(Node $node) {
+ $this->deleteNode($node);
+ }
+
+ protected function deleteNode(Node $node) {
// We only handle files
if ($node instanceof Folder) {
return;
@@ -61,4 +65,10 @@ class Watcher {
//Nothing to do
}
}
+
+ public function versionRollback(array $data) {
+ if (isset($data['node'])) {
+ $this->deleteNode($data['node']);
+ }
+ }
}
diff --git a/lib/private/Preview/WatcherConnector.php b/lib/private/Preview/WatcherConnector.php
index bf9e6c29e4f..f374b909d8f 100644
--- a/lib/private/Preview/WatcherConnector.php
+++ b/lib/private/Preview/WatcherConnector.php
@@ -60,6 +60,8 @@ class WatcherConnector {
$this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
$this->getWatcher()->postWrite($node);
});
+
+ \OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback');
}
}
}