]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add metadata to post delete hooks
authorRobin Appelman <icewind@owncloud.com>
Tue, 1 Dec 2015 12:22:58 +0000 (13:22 +0100)
committerRobin Appelman <icewind@owncloud.com>
Tue, 1 Dec 2015 12:22:58 +0000 (13:22 +0100)
lib/private/files/node/file.php
lib/private/files/node/folder.php
lib/private/files/node/nonexistingfile.php
lib/private/files/node/nonexistingfolder.php
tests/lib/files/node/file.php
tests/lib/files/node/folder.php

index f66f87bfc2d512e9b82c8ee6b10bd86d6897975d..735bee3fd595bc6adf7762378c1a3a5762ba9eff 100644 (file)
@@ -99,8 +99,9 @@ class File extends Node implements \OCP\Files\File {
        public function delete() {
                if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
                        $this->sendHooks(array('preDelete'));
+                       $fileInfo = $this->getFileInfo();
                        $this->view->unlink($this->path);
-                       $nonExisting = new NonExistingFile($this->root, $this->view, $this->path);
+                       $nonExisting = new NonExistingFile($this->root, $this->view, $this->path, $fileInfo);
                        $this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
                        $this->exists = false;
                        $this->fileInfo = null;
index 9032c2bfb9d718b82f247bbc446903365294bcd1..be76b70b2ce9337065ab4fc8f8dc485e0d735f3a 100644 (file)
@@ -295,8 +295,9 @@ class Folder extends Node implements \OCP\Files\Folder {
        public function delete() {
                if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
                        $this->sendHooks(array('preDelete'));
+                       $fileInfo = $this->getFileInfo();
                        $this->view->rmdir($this->path);
-                       $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path);
+                       $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo);
                        $this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
                        $this->exists = false;
                } else {
index b1de15d0535cb820a18969b4e3aa32f85d578968..68fb7d1b6f94904df9b0523d5d4fa8d24fff20c6 100644 (file)
@@ -46,7 +46,11 @@ class NonExistingFile extends File {
        }
 
        public function getId() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getId();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function stat() {
@@ -54,35 +58,67 @@ class NonExistingFile extends File {
        }
 
        public function getMTime() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getMTime();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getSize() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getSize();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getEtag() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getEtag();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getPermissions() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getPermissions();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isReadable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isReadable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isUpdateable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isUpdateable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isDeletable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isDeletable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isShareable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isShareable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getContent() {
@@ -94,7 +130,11 @@ class NonExistingFile extends File {
        }
 
        public function getMimeType() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getMimeType();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function fopen($mode) {
index be58103da90e8957639e4880baf65ae52715cf83..5044eb524f5c4416d38fc414c684d168402a0cd9 100644 (file)
@@ -47,7 +47,11 @@ class NonExistingFolder extends Folder {
        }
 
        public function getId() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getId();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function stat() {
@@ -55,35 +59,67 @@ class NonExistingFolder extends Folder {
        }
 
        public function getMTime() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getMTime();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getSize() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getSize();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getEtag() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getEtag();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function getPermissions() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::getPermissions();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isReadable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isReadable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isUpdateable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isUpdateable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isDeletable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isDeletable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function isShareable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isShareable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 
        public function get($path) {
@@ -127,6 +163,10 @@ class NonExistingFolder extends Folder {
        }
 
        public function isCreatable() {
-               throw new NotFoundException();
+               if ($this->fileInfo) {
+                       return parent::isCreatable();
+               } else {
+                       throw new NotFoundException();
+               }
        }
 }
index c431a2eb36678e078ad7b44c63899da96275d6e3..d0072949c7f1fbe2bcb269838844e463c334cfc3 100644 (file)
@@ -76,6 +76,8 @@ class File extends \Test\TestCase {
                        $test->assertInstanceOf('\OC\Files\Node\NonExistingFile', $node);
                        $test->assertEquals('foo', $node->getInternalPath());
                        $test->assertEquals('/bar/foo', $node->getPath());
+                       $test->assertEquals(1, $node->getId());
+                       $test->assertEquals('text/plain', $node->getMimeType());
                        $hooksRun++;
                };
 
@@ -94,7 +96,7 @@ class File extends \Test\TestCase {
                $view->expects($this->any())
                        ->method('getFileInfo')
                        ->with('/bar/foo')
-                       ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
+                       ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'))));
 
                $view->expects($this->once())
                        ->method('unlink')
index 2c9339bb6dce724e51a31d4c38af5371ea1614e3..d95e1b5d2b21d729de5df4eeeeb2b8903487fa5c 100644 (file)
@@ -82,6 +82,7 @@ class Folder extends \Test\TestCase {
                        $test->assertInstanceOf('\OC\Files\Node\NonExistingFolder', $node);
                        $test->assertEquals('foo', $node->getInternalPath());
                        $test->assertEquals('/bar/foo', $node->getPath());
+                       $test->assertEquals(1, $node->getId());
                        $hooksRun++;
                };