delete cached preview when rolling back file's version
add random number using OC.parseQueryString and _.extend() version rollback: add missing prefix to OC\Preview::post_delete add test to assure that the rollback hook is called
This commit is contained in:
parent
bbd1e99605
commit
b3ff773bbf
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1300,6 +1300,13 @@ class Preview {
|
|||
self::post_delete($args, 'files/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
*/
|
||||
public static function post_delete_versions($args) {
|
||||
self::post_delete($args, 'files/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @param string $prefix
|
||||
|
|
Loading…
Reference in New Issue