Also add metadata for postDelete hooks triggered from the view
This commit is contained in:
parent
8d218bf3ef
commit
0062888aaf
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
namespace OC\Files\Node;
|
namespace OC\Files\Node;
|
||||||
|
|
||||||
|
use OCP\Files\FileInfo;
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
use OCP\Files\FileInfo;
|
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
class HookConnector {
|
class HookConnector {
|
||||||
|
@ -37,6 +37,11 @@ class HookConnector {
|
||||||
*/
|
*/
|
||||||
private $view;
|
private $view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FileInfo[]
|
||||||
|
*/
|
||||||
|
private $deleteMetaCache = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HookConnector constructor.
|
* HookConnector constructor.
|
||||||
*
|
*
|
||||||
|
@ -90,11 +95,13 @@ class HookConnector {
|
||||||
|
|
||||||
public function delete($arguments) {
|
public function delete($arguments) {
|
||||||
$node = $this->getNodeForPath($arguments['path']);
|
$node = $this->getNodeForPath($arguments['path']);
|
||||||
|
$this->deleteMetaCache[$node->getPath()] = $node->getFileInfo();
|
||||||
$this->root->emit('\OC\Files', 'preDelete', [$node]);
|
$this->root->emit('\OC\Files', 'preDelete', [$node]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postDelete($arguments) {
|
public function postDelete($arguments) {
|
||||||
$node = $this->getNodeForPath($arguments['path']);
|
$node = $this->getNodeForPath($arguments['path']);
|
||||||
|
unset($this->deleteMetaCache[$node->getPath()]);
|
||||||
$this->root->emit('\OC\Files', 'postDelete', [$node]);
|
$this->root->emit('\OC\Files', 'postDelete', [$node]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,11 +142,17 @@ class HookConnector {
|
||||||
private function getNodeForPath($path) {
|
private function getNodeForPath($path) {
|
||||||
$info = Filesystem::getView()->getFileInfo($path);
|
$info = Filesystem::getView()->getFileInfo($path);
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
|
|
||||||
$fullPath = Filesystem::getView()->getAbsolutePath($path);
|
$fullPath = Filesystem::getView()->getAbsolutePath($path);
|
||||||
if (Filesystem::is_dir($path)) {
|
if (isset($this->deleteMetaCache[$fullPath])) {
|
||||||
return new NonExistingFolder($this->root, $this->view, $fullPath);
|
$info = $this->deleteMetaCache[$fullPath];
|
||||||
} else {
|
} else {
|
||||||
return new NonExistingFile($this->root, $this->view, $fullPath);
|
$info = null;
|
||||||
|
}
|
||||||
|
if (Filesystem::is_dir($path)) {
|
||||||
|
return new NonExistingFolder($this->root, $this->view, $fullPath, $info);
|
||||||
|
} else {
|
||||||
|
return new NonExistingFile($this->root, $this->view, $fullPath, $info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($info->getType() === FileInfo::TYPE_FILE) {
|
if ($info->getType() === FileInfo::TYPE_FILE) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ use Test\Traits\UserTrait;
|
||||||
* Class HookConnector
|
* Class HookConnector
|
||||||
*
|
*
|
||||||
* @group DB
|
* @group DB
|
||||||
*
|
*
|
||||||
* @package Test\Files\Node
|
* @package Test\Files\Node
|
||||||
*/
|
*/
|
||||||
class HookConnector extends TestCase {
|
class HookConnector extends TestCase {
|
||||||
|
@ -180,4 +180,24 @@ class HookConnector extends TestCase {
|
||||||
$this->assertEquals('/' . $this->userId . '/files/source', $hookSourceNode->getPath());
|
$this->assertEquals('/' . $this->userId . '/files/source', $hookSourceNode->getPath());
|
||||||
$this->assertEquals('/' . $this->userId . '/files/target', $hookTargetNode->getPath());
|
$this->assertEquals('/' . $this->userId . '/files/target', $hookTargetNode->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPostDeleteMeta() {
|
||||||
|
$connector = new \OC\Files\Node\HookConnector($this->root, $this->view);
|
||||||
|
$connector->viewToNode();
|
||||||
|
$hookCalled = false;
|
||||||
|
/** @var Node $hookNode */
|
||||||
|
$hookNode = null;
|
||||||
|
|
||||||
|
$this->root->listen('\OC\Files', 'postDelete', function ($node) use (&$hookNode, &$hookCalled) {
|
||||||
|
$hookCalled = true;
|
||||||
|
$hookNode = $node;
|
||||||
|
});
|
||||||
|
|
||||||
|
Filesystem::file_put_contents('test.txt', 'asd');
|
||||||
|
$info = Filesystem::getFileInfo('test.txt');
|
||||||
|
Filesystem::unlink('test.txt');
|
||||||
|
|
||||||
|
$this->assertTrue($hookCalled);
|
||||||
|
$this->assertEquals($hookNode->getId(), $info->getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue