Skip to content

Commit

Permalink
Delete the previews when a version is restored
Browse files Browse the repository at this point in the history
Fixes #9469

When a version of a file is restored the previews are no longer valid.
Thus we should remove them so they are regenerated.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed May 14, 2018
1 parent 0dcb6b2 commit 39bb9c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ public static function rollback($file, $revision) {
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');

Expand Down Expand Up @@ -375,9 +378,14 @@ public static function rollback($file, $revision) {
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) {
Expand Down
10 changes: 10 additions & 0 deletions lib/private/Preview/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function __construct(IAppData $appData) {
}

public function postWrite(Node $node) {
$this->deleteNode($node);
}

protected function deleteNode(Node $node) {
// We only handle files
if ($node instanceof Folder) {
return;
Expand All @@ -61,4 +65,10 @@ public function postWrite(Node $node) {
//Nothing to do
}
}

public function versionRollback(array $data) {
if (isset($data['node'])) {
$this->deleteNode($data['node']);
}
}
}
2 changes: 2 additions & 0 deletions lib/private/Preview/WatcherConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function connectWatcher() {
$this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
$this->getWatcher()->postWrite($node);
});

\OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback');
}
}
}

0 comments on commit 39bb9c0

Please sign in to comment.