summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-09-24 21:06:27 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-09-24 21:06:27 +0200
commite7bc2a10e3ffd16cda8d15ff06dcbc870e34a627 (patch)
tree975e247e53378834d6b59b06ae3a76b5bb60a217
parent320a4eb149150144e755914c39281653cf2a2130 (diff)
parentb3ff773bbf363e4d7d44d7c6ce7ae2eec8250cfb (diff)
downloadnextcloud-server-e7bc2a10e3ffd16cda8d15ff06dcbc870e34a627.tar.gz
nextcloud-server-e7bc2a10e3ffd16cda8d15ff06dcbc870e34a627.zip
Merge pull request #15098 from owncloud/fix_preview_versions_revert_issue
fix issue with version rollback and thumbnails
-rw-r--r--apps/files_versions/lib/storage.php3
-rw-r--r--apps/files_versions/tests/versions.php37
-rw-r--r--lib/base.php3
-rw-r--r--lib/private/preview.php7
4 files changed, 49 insertions, 1 deletions
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 6aa58c55e9b..bdf1811c5f9 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -315,6 +315,9 @@ class Storage {
if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
$files_view->touch($file, $revision);
Storage::scheduleExpire($uid, $file);
+ \OC_Hook::emit('\OCP\Versions', 'rollback', array(
+ 'path' => $filename,
+ ));
return true;
} else if ($versionCreated) {
self::deleteVersion($users_view, $version);
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php
index da214ead60a..d4a85c8bffe 100644
--- a/apps/files_versions/tests/versions.php
+++ b/apps/files_versions/tests/versions.php
@@ -580,6 +580,35 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->doTestRestore();
}
+ /**
+ * @param string $hookName name of hook called
+ * @param string $params variable to recieve parameters provided by hook
+ */
+ private function connectMockHooks($hookName, &$params) {
+ if ($hookName === null) {
+ return;
+ }
+
+ $eventHandler = $this->getMockBuilder('\stdclass')
+ ->setMethods(['callback'])
+ ->getMock();
+
+ $eventHandler->expects($this->any())
+ ->method('callback')
+ ->will($this->returnCallback(
+ function($p) use (&$params) {
+ $params = $p;
+ }
+ ));
+
+ \OCP\Util::connectHook(
+ '\OCP\Versions',
+ $hookName,
+ $eventHandler,
+ 'callback'
+ );
+ }
+
private function doTestRestore() {
$filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt';
$this->rootView->file_put_contents($filePath, 'test file');
@@ -608,7 +637,15 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->assertEquals('test file', $this->rootView->file_get_contents($filePath));
$info1 = $this->rootView->getFileInfo($filePath);
+ $params = array();
+ $this->connectMockHooks('rollback', $params);
+
\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2);
+ $expectedParams = array(
+ 'path' => '/sub/test.txt',
+ );
+
+ $this->assertEquals($expectedParams, $params);
$this->assertEquals('version2', $this->rootView->file_get_contents($filePath));
$info2 = $this->rootView->getFileInfo($filePath);
diff --git a/lib/base.php b/lib/base.php
index 3624a3fbaf9..f99acaaa80a 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -803,8 +803,9 @@ class OC {
OC_Hook::connect('\OCP\Versions', 'preDelete', 'OC\Preview', 'prepare_delete');
OC_Hook::connect('\OCP\Trashbin', 'preDelete', 'OC\Preview', 'prepare_delete');
OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC\Preview', 'post_delete_files');
- OC_Hook::connect('\OCP\Versions', 'delete', 'OC\Preview', 'post_delete');
+ OC_Hook::connect('\OCP\Versions', 'delete', 'OC\Preview', 'post_delete_versions');
OC_Hook::connect('\OCP\Trashbin', 'delete', 'OC\Preview', 'post_delete');
+ OC_Hook::connect('\OCP\Versions', 'rollback', 'OC\Preview', 'post_delete_versions');
}
/**
diff --git a/lib/private/preview.php b/lib/private/preview.php
index 978da1161c2..de964b72df2 100644
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -1296,6 +1296,13 @@ class Preview {
/**
* @param array $args
+ */
+ public static function post_delete_versions($args) {
+ self::post_delete($args, 'files/');
+ }
+
+ /**
+ * @param array $args
* @param string $prefix
*/
public static function post_delete($args, $prefix = '') {