Merge pull request #9622 from nextcloud/backport/9475/stable13

[stable13] Delete the previews when a version is restored
This commit is contained in:
Morris Jobke 2018-05-28 11:20:18 +02:00 committed by GitHub
commit 8889220f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -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) {

View File

@ -52,6 +52,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;
@ -101,4 +105,10 @@ class Watcher {
}
}
}
public function versionRollback(array $data) {
if (isset($data['node'])) {
$this->deleteNode($data['node']);
}
}
}

View File

@ -67,6 +67,8 @@ class WatcherConnector {
$this->root->listen('\OC\Files', 'postDelete', function (Node $node) {
$this->getWatcher()->postDelete($node);
});
\OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback');
}
}
}