Merge pull request #15098 from owncloud/fix_preview_versions_revert_issue

fix issue with version rollback and thumbnails
This commit is contained in:
Thomas Müller 2015-09-24 21:06:27 +02:00
commit e7bc2a10e3
4 changed files with 49 additions and 1 deletions

View File

@ -315,6 +315,9 @@ class Storage {
if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) { if (self::copyFileContents($users_view, 'files_versions' . $filename . '.v' . $revision, 'files' . $filename)) {
$files_view->touch($file, $revision); $files_view->touch($file, $revision);
Storage::scheduleExpire($uid, $file); Storage::scheduleExpire($uid, $file);
\OC_Hook::emit('\OCP\Versions', 'rollback', array(
'path' => $filename,
));
return true; return true;
} else if ($versionCreated) { } else if ($versionCreated) {
self::deleteVersion($users_view, $version); self::deleteVersion($users_view, $version);

View File

@ -580,6 +580,35 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->doTestRestore(); $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() { private function doTestRestore() {
$filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt'; $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt';
$this->rootView->file_put_contents($filePath, 'test file'); $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)); $this->assertEquals('test file', $this->rootView->file_get_contents($filePath));
$info1 = $this->rootView->getFileInfo($filePath); $info1 = $this->rootView->getFileInfo($filePath);
$params = array();
$this->connectMockHooks('rollback', $params);
\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2); \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)); $this->assertEquals('version2', $this->rootView->file_get_contents($filePath));
$info2 = $this->rootView->getFileInfo($filePath); $info2 = $this->rootView->getFileInfo($filePath);

View File

@ -803,8 +803,9 @@ class OC {
OC_Hook::connect('\OCP\Versions', 'preDelete', 'OC\Preview', 'prepare_delete'); OC_Hook::connect('\OCP\Versions', 'preDelete', 'OC\Preview', 'prepare_delete');
OC_Hook::connect('\OCP\Trashbin', '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('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\Trashbin', 'delete', 'OC\Preview', 'post_delete');
OC_Hook::connect('\OCP\Versions', 'rollback', 'OC\Preview', 'post_delete_versions');
} }
/** /**

View File

@ -1294,6 +1294,13 @@ class Preview {
self::post_delete($args, 'files/'); self::post_delete($args, 'files/');
} }
/**
* @param array $args
*/
public static function post_delete_versions($args) {
self::post_delete($args, 'files/');
}
/** /**
* @param array $args * @param array $args
* @param string $prefix * @param string $prefix