diff options
author | Frank Karlitschek <frank@owncloud.org> | 2013-11-28 03:46:42 -0800 |
---|---|---|
committer | Frank Karlitschek <frank@owncloud.org> | 2013-11-28 03:46:42 -0800 |
commit | dab3629ff5c65de91813cde6e9adda769ece2609 (patch) | |
tree | 45d825c0bcd44ffd306b9d662b758ad7720449fd | |
parent | 30b2ed588b76544142fade70f9b849043d54e05a (diff) | |
parent | bc64931cd06a6839e3ecde58e1f671abd44e08db (diff) | |
download | nextcloud-server-dab3629ff5c65de91813cde6e9adda769ece2609.tar.gz nextcloud-server-dab3629ff5c65de91813cde6e9adda769ece2609.zip |
Merge pull request #6089 from owncloud/files-mimetyperefreshafterrename
Redetect mime type whenever extension is renamed
-rw-r--r-- | apps/files/js/filelist.js | 19 | ||||
-rw-r--r-- | apps/files/lib/app.php | 17 | ||||
-rw-r--r-- | apps/files/tests/ajax_rename.php | 63 | ||||
-rw-r--r-- | lib/private/files/cache/updater.php | 6 | ||||
-rw-r--r-- | tests/lib/files/cache/updater.php | 8 |
5 files changed, 87 insertions, 26 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 66453740f5d..b8ae00ac494 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -422,12 +422,27 @@ var FileList={ } tr.find('.fileactions').effect('highlight', {}, 5000); tr.effect('highlight', {}, 5000); + // remove loading mark and recover old image + td.css('background-image', oldBackgroundImage); + } + else { + var fileInfo = result.data; + tr.attr('data-mime', fileInfo.mime); + tr.attr('data-etag', fileInfo.etag); + if (fileInfo.isPreviewAvailable) { + Files.lazyLoadPreview(fileInfo.directory + '/' + fileInfo.name, result.data.mime, function(previewpath) { + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); + }, null, null, result.data.etag); + } + else { + tr.find('td.filename').removeClass('preview').attr('style','background-image:url('+fileInfo.icon+')'); + } } // reinsert row tr.detach(); FileList.insertElement( tr.attr('data-file'), tr.attr('data-type'),tr ); - // remove loading mark and recover old image - td.css('background-image', oldBackgroundImage); + // update file actions in case the extension changed + FileActions.display( tr.find('td.filename'), true); } }); } diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php index f5ac11b2168..ea94ea43ef3 100644 --- a/apps/files/lib/app.php +++ b/apps/files/lib/app.php @@ -76,12 +76,19 @@ class App { $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname) ) { // successful rename - $result['success'] = true; - $result['data'] = array( - 'dir' => $dir, - 'file' => $oldname, - 'newname' => $newname + $meta = $this->view->getFileInfo($dir . '/' . $newname); + $fileinfo = array( + 'id' => $meta['fileid'], + 'mime' => $meta['mimetype'], + 'size' => $meta['size'], + 'etag' => $meta['etag'], + 'directory' => $dir, + 'name' => $newname, + 'isPreviewAvailable' => \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']), + 'icon' => \OCA\Files\Helper::determineIcon($meta) ); + $result['success'] = true; + $result['data'] = $fileinfo; } else { // rename failed $result['data'] = array( diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index 3735b0a49c8..350ff5d3687 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -38,13 +38,14 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $l10nMock->expects($this->any()) ->method('t') ->will($this->returnArgument(0)); - $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath'), array(), '', false); + $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath', 'getFileInfo'), array(), '', false); $viewMock->expects($this->any()) ->method('normalizePath') ->will($this->returnArgument(0)); $viewMock->expects($this->any()) ->method('rename') ->will($this->returnValue(true)); + $this->viewMock = $viewMock; $this->files = new \OCA\Files\App($viewMock, $l10nMock); } @@ -79,17 +80,28 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $oldname = 'Shared'; $newname = 'new_name'; + $this->viewMock->expects($this->any()) + ->method('getFileInfo') + ->will($this->returnValue(array( + 'fileid' => 123, + 'type' => 'dir', + 'mimetype' => 'httpd/unix-directory', + 'size' => 18, + 'etag' => 'abcdef', + 'directory' => '/', + 'name' => 'new_name', + ))); + $result = $this->files->rename($dir, $oldname, $newname); - $expected = array( - 'success' => true, - 'data' => array( - 'dir' => $dir, - 'file' => $oldname, - 'newname' => $newname - ) - ); - $this->assertEquals($expected, $result); + $this->assertTrue($result['success']); + $this->assertEquals(123, $result['data']['id']); + $this->assertEquals('new_name', $result['data']['name']); + $this->assertEquals('/test', $result['data']['directory']); + $this->assertEquals(18, $result['data']['size']); + $this->assertEquals('httpd/unix-directory', $result['data']['mime']); + $this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']); + $this->assertFalse($result['data']['isPreviewAvailable']); } /** @@ -117,16 +129,29 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $oldname = 'oldname'; $newname = 'newname'; + $this->viewMock->expects($this->any()) + ->method('getFileInfo') + ->will($this->returnValue(array( + 'fileid' => 123, + 'type' => 'dir', + 'mimetype' => 'httpd/unix-directory', + 'size' => 18, + 'etag' => 'abcdef', + 'directory' => '/', + 'name' => 'new_name', + ))); + + $result = $this->files->rename($dir, $oldname, $newname); - $expected = array( - 'success' => true, - 'data' => array( - 'dir' => $dir, - 'file' => $oldname, - 'newname' => $newname - ) - ); - $this->assertEquals($expected, $result); + $this->assertTrue($result['success']); + $this->assertEquals(123, $result['data']['id']); + $this->assertEquals('newname', $result['data']['name']); + $this->assertEquals('/', $result['data']['directory']); + $this->assertEquals(18, $result['data']['size']); + $this->assertEquals('httpd/unix-directory', $result['data']['mime']); + $this->assertEquals('abcdef', $result['data']['etag']); + $this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']); + $this->assertFalse($result['data']['isPreviewAvailable']); } } diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index d45c5e17fc8..9ef147aa157 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -86,6 +86,12 @@ class Updater { if ($storageFrom === $storageTo) { $cache = $storageFrom->getCache($internalFrom); $cache->move($internalFrom, $internalTo); + if (pathinfo($internalFrom, PATHINFO_EXTENSION) !== pathinfo($internalTo, PATHINFO_EXTENSION)) { + // redetect mime type change + $mimeType = $storageTo->getMimeType($internalTo); + $fileId = $storageTo->getCache()->getId($internalTo); + $storageTo->getCache()->update($fileId, array('mimetype' => $mimeType)); + } $cache->correctFolderSize($internalFrom); $cache->correctFolderSize($internalTo); self::correctFolder($from, time()); diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index e3d3aae818d..91e384e12af 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -202,6 +202,14 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); } + public function testRenameExtension() { + $fooCachedData = $this->cache->get('foo.txt'); + $this->assertEquals('text/plain', $fooCachedData['mimetype']); + Filesystem::rename('foo.txt', 'foo.abcd'); + $fooCachedData = $this->cache->get('foo.abcd'); + $this->assertEquals('application/octet-stream', $fooCachedData['mimetype']); + } + public function testRenameWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); |