Completed
Push — master ( e0f925...4ad272 )
by Morris
84:55 queued 70:47
created
apps/files_trashbin/lib/Sabre/AbstractTrash.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -28,63 +28,63 @@
 block discarded – undo
28 28
 use OCP\IUser;
29 29
 
30 30
 abstract class AbstractTrash implements ITrash {
31
-	/** @var ITrashItem */
32
-	protected $data;
31
+    /** @var ITrashItem */
32
+    protected $data;
33 33
 
34
-	/** @var ITrashManager */
35
-	protected $trashManager;
34
+    /** @var ITrashManager */
35
+    protected $trashManager;
36 36
 
37
-	public function __construct(ITrashManager $trashManager, ITrashItem $data) {
38
-		$this->trashManager = $trashManager;
39
-		$this->data = $data;
40
-	}
37
+    public function __construct(ITrashManager $trashManager, ITrashItem $data) {
38
+        $this->trashManager = $trashManager;
39
+        $this->data = $data;
40
+    }
41 41
 
42
-	public function getFilename(): string {
43
-		return $this->data->getName();
44
-	}
42
+    public function getFilename(): string {
43
+        return $this->data->getName();
44
+    }
45 45
 
46
-	public function getDeletionTime(): int {
47
-		return $this->data->getDeletedTime();
48
-	}
46
+    public function getDeletionTime(): int {
47
+        return $this->data->getDeletedTime();
48
+    }
49 49
 
50
-	public function getFileId(): int {
51
-		return $this->data->getId();
52
-	}
50
+    public function getFileId(): int {
51
+        return $this->data->getId();
52
+    }
53 53
 
54
-	public function getFileInfo(): FileInfo {
55
-		return $this->data;
56
-	}
54
+    public function getFileInfo(): FileInfo {
55
+        return $this->data;
56
+    }
57 57
 
58
-	public function getSize(): int {
59
-		return $this->data->getSize();
60
-	}
58
+    public function getSize(): int {
59
+        return $this->data->getSize();
60
+    }
61 61
 
62
-	public function getLastModified(): int {
63
-		return $this->data->getMtime();
64
-	}
62
+    public function getLastModified(): int {
63
+        return $this->data->getMtime();
64
+    }
65 65
 
66
-	public function getContentType(): string {
67
-		return $this->data->getMimetype();
68
-	}
66
+    public function getContentType(): string {
67
+        return $this->data->getMimetype();
68
+    }
69 69
 
70
-	public function getETag(): string {
71
-		return $this->data->getEtag();
72
-	}
70
+    public function getETag(): string {
71
+        return $this->data->getEtag();
72
+    }
73 73
 
74
-	public function getName(): string {
75
-		return $this->data->getName();
76
-	}
74
+    public function getName(): string {
75
+        return $this->data->getName();
76
+    }
77 77
 
78
-	public function getOriginalLocation(): string {
79
-		return $this->data->getOriginalLocation();
80
-	}
78
+    public function getOriginalLocation(): string {
79
+        return $this->data->getOriginalLocation();
80
+    }
81 81
 
82
-	public function delete() {
83
-		$this->trashManager->removeItem($this->data);
84
-	}
82
+    public function delete() {
83
+        $this->trashManager->removeItem($this->data);
84
+    }
85 85
 
86
-	public function restore(): bool {
87
-		$this->trashManager->restoreItem($this->data);
88
-		return true;
89
-	}
86
+    public function restore(): bool {
87
+        $this->trashManager->restoreItem($this->data);
88
+        return true;
89
+    }
90 90
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/RestoreFolder.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -31,48 +31,48 @@
 block discarded – undo
31 31
 
32 32
 
33 33
 class RestoreFolder implements ICollection, IMoveTarget {
34
-	public function createFile($name, $data = null) {
35
-		throw new Forbidden();
36
-	}
34
+    public function createFile($name, $data = null) {
35
+        throw new Forbidden();
36
+    }
37 37
 
38
-	public function createDirectory($name) {
39
-		throw new Forbidden();
40
-	}
38
+    public function createDirectory($name) {
39
+        throw new Forbidden();
40
+    }
41 41
 
42
-	public function getChild($name) {
43
-		return null;
44
-	}
42
+    public function getChild($name) {
43
+        return null;
44
+    }
45 45
 
46
-	public function delete() {
47
-		throw new Forbidden();
48
-	}
46
+    public function delete() {
47
+        throw new Forbidden();
48
+    }
49 49
 
50
-	public function getName() {
51
-		return 'restore';
52
-	}
50
+    public function getName() {
51
+        return 'restore';
52
+    }
53 53
 
54
-	public function setName($name) {
55
-		throw new Forbidden();
56
-	}
54
+    public function setName($name) {
55
+        throw new Forbidden();
56
+    }
57 57
 
58
-	public function getLastModified(): int {
59
-		return 0;
60
-	}
58
+    public function getLastModified(): int {
59
+        return 0;
60
+    }
61 61
 
62
-	public function getChildren(): array {
63
-		return [];
64
-	}
62
+    public function getChildren(): array {
63
+        return [];
64
+    }
65 65
 
66
-	public function childExists($name): bool {
67
-		return false;
68
-	}
66
+    public function childExists($name): bool {
67
+        return false;
68
+    }
69 69
 
70
-	public function moveInto($targetName, $sourcePath, INode $sourceNode): bool {
71
-		if (!($sourceNode instanceof ITrash)) {
72
-			return false;
73
-		}
70
+    public function moveInto($targetName, $sourcePath, INode $sourceNode): bool {
71
+        if (!($sourceNode instanceof ITrash)) {
72
+            return false;
73
+        }
74 74
 
75
-		return $sourceNode->restore();
76
-	}
75
+        return $sourceNode->restore();
76
+    }
77 77
 
78 78
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/TrashFolder.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 
26 26
 
27 27
 class TrashFolder extends AbstractTrashFolder {
28
-	public function getName(): string {
29
-		return $this->data->getName() . '.d' . $this->getLastModified();
30
-	}
28
+    public function getName(): string {
29
+        return $this->data->getName() . '.d' . $this->getLastModified();
30
+    }
31 31
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,6 +26,6 @@
 block discarded – undo
26 26
 
27 27
 class TrashFolder extends AbstractTrashFolder {
28 28
 	public function getName(): string {
29
-		return $this->data->getName() . '.d' . $this->getLastModified();
29
+		return $this->data->getName().'.d'.$this->getLastModified();
30 30
 	}
31 31
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/AbstractTrashFile.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,11 +26,11 @@
 block discarded – undo
26 26
 use Sabre\DAV\IFile;
27 27
 
28 28
 abstract class AbstractTrashFile extends AbstractTrash implements IFile , ITrash{
29
-	public function put($data) {
30
-		throw new Forbidden();
31
-	}
29
+    public function put($data) {
30
+        throw new Forbidden();
31
+    }
32 32
 
33
-	public function setName($name) {
34
-		throw new Forbidden();
35
-	}
33
+    public function setName($name) {
34
+        throw new Forbidden();
35
+    }
36 36
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 use Sabre\DAV\Exception\Forbidden;
26 26
 use Sabre\DAV\IFile;
27 27
 
28
-abstract class AbstractTrashFile extends AbstractTrash implements IFile , ITrash{
28
+abstract class AbstractTrashFile extends AbstractTrash implements IFile, ITrash{
29 29
 	public function put($data) {
30 30
 		throw new Forbidden();
31 31
 	}
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/TrashRoot.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -33,72 +33,72 @@
 block discarded – undo
33 33
 
34 34
 class TrashRoot implements ICollection {
35 35
 
36
-	/** @var IUser */
37
-	private $user;
38
-
39
-	/** @var ITrashManager  */
40
-	private $trashManager;
41
-
42
-	public function __construct(IUser $user, ITrashManager $trashManager) {
43
-		$this->user = $user;
44
-		$this->trashManager = $trashManager;
45
-	}
46
-
47
-	public function delete() {
48
-		\OCA\Files_Trashbin\Trashbin::deleteAll();
49
-	}
50
-
51
-	public function getName(): string {
52
-		return 'trash';
53
-	}
54
-
55
-	public function setName($name) {
56
-		throw new Forbidden('Permission denied to rename this trashbin');
57
-	}
58
-
59
-	public function createFile($name, $data = null) {
60
-		throw new Forbidden('Not allowed to create files in the trashbin');
61
-	}
62
-
63
-	public function createDirectory($name) {
64
-		throw new Forbidden('Not allowed to create folders in the trashbin');
65
-	}
66
-
67
-	public function getChildren(): array {
68
-		$entries = $this->trashManager->listTrashRoot($this->user);
69
-
70
-		$children = array_map(function (ITrashItem $entry) {
71
-			if ($entry->getType() === FileInfo::TYPE_FOLDER) {
72
-				return new TrashFolder($this->trashManager, $entry);
73
-			}
74
-			return new TrashFile($this->trashManager, $entry);
75
-		}, $entries);
76
-
77
-		return $children;
78
-	}
79
-
80
-	public function getChild($name): ITrash {
81
-		$entries = $this->getChildren();
82
-
83
-		foreach ($entries as $entry) {
84
-			if ($entry->getName() === $name) {
85
-				return $entry;
86
-			}
87
-		}
88
-
89
-		throw new NotFound();
90
-	}
91
-
92
-	public function childExists($name): bool {
93
-		try {
94
-			$this->getChild($name);
95
-			return true;
96
-		} catch (NotFound $e) {
97
-			return false;
98
-		}
99
-	}
100
-
101
-	public function getLastModified(): int {
102
-		return 0;
103
-	}
36
+    /** @var IUser */
37
+    private $user;
38
+
39
+    /** @var ITrashManager  */
40
+    private $trashManager;
41
+
42
+    public function __construct(IUser $user, ITrashManager $trashManager) {
43
+        $this->user = $user;
44
+        $this->trashManager = $trashManager;
45
+    }
46
+
47
+    public function delete() {
48
+        \OCA\Files_Trashbin\Trashbin::deleteAll();
49
+    }
50
+
51
+    public function getName(): string {
52
+        return 'trash';
53
+    }
54
+
55
+    public function setName($name) {
56
+        throw new Forbidden('Permission denied to rename this trashbin');
57
+    }
58
+
59
+    public function createFile($name, $data = null) {
60
+        throw new Forbidden('Not allowed to create files in the trashbin');
61
+    }
62
+
63
+    public function createDirectory($name) {
64
+        throw new Forbidden('Not allowed to create folders in the trashbin');
65
+    }
66
+
67
+    public function getChildren(): array {
68
+        $entries = $this->trashManager->listTrashRoot($this->user);
69
+
70
+        $children = array_map(function (ITrashItem $entry) {
71
+            if ($entry->getType() === FileInfo::TYPE_FOLDER) {
72
+                return new TrashFolder($this->trashManager, $entry);
73
+            }
74
+            return new TrashFile($this->trashManager, $entry);
75
+        }, $entries);
76
+
77
+        return $children;
78
+    }
79
+
80
+    public function getChild($name): ITrash {
81
+        $entries = $this->getChildren();
82
+
83
+        foreach ($entries as $entry) {
84
+            if ($entry->getName() === $name) {
85
+                return $entry;
86
+            }
87
+        }
88
+
89
+        throw new NotFound();
90
+    }
91
+
92
+    public function childExists($name): bool {
93
+        try {
94
+            $this->getChild($name);
95
+            return true;
96
+        } catch (NotFound $e) {
97
+            return false;
98
+        }
99
+    }
100
+
101
+    public function getLastModified(): int {
102
+        return 0;
103
+    }
104 104
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 	public function getChildren(): array {
68 68
 		$entries = $this->trashManager->listTrashRoot($this->user);
69 69
 
70
-		$children = array_map(function (ITrashItem $entry) {
70
+		$children = array_map(function(ITrashItem $entry) {
71 71
 			if ($entry->getType() === FileInfo::TYPE_FOLDER) {
72 72
 				return new TrashFolder($this->trashManager, $entry);
73 73
 			}
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -29,49 +29,49 @@
 block discarded – undo
29 29
 use Sabre\DAV\ICollection;
30 30
 
31 31
 abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
32
-	public function getChildren(): array {
33
-		$entries = $this->trashManager->listTrashFolder($this->data);
32
+    public function getChildren(): array {
33
+        $entries = $this->trashManager->listTrashFolder($this->data);
34 34
 
35
-		$children = array_map(function (ITrashItem $entry) {
36
-			if ($entry->getType() === FileInfo::TYPE_FOLDER) {
37
-				return new TrashFolderFolder($this->trashManager, $entry);
38
-			}
39
-			return new TrashFolderFile($this->trashManager, $entry);
40
-		}, $entries);
35
+        $children = array_map(function (ITrashItem $entry) {
36
+            if ($entry->getType() === FileInfo::TYPE_FOLDER) {
37
+                return new TrashFolderFolder($this->trashManager, $entry);
38
+            }
39
+            return new TrashFolderFile($this->trashManager, $entry);
40
+        }, $entries);
41 41
 
42
-		return $children;
43
-	}
42
+        return $children;
43
+    }
44 44
 
45
-	public function getChild($name): ITrash {
46
-		$entries = $this->getChildren();
45
+    public function getChild($name): ITrash {
46
+        $entries = $this->getChildren();
47 47
 
48
-		foreach ($entries as $entry) {
49
-			if ($entry->getName() === $name) {
50
-				return $entry;
51
-			}
52
-		}
48
+        foreach ($entries as $entry) {
49
+            if ($entry->getName() === $name) {
50
+                return $entry;
51
+            }
52
+        }
53 53
 
54
-		throw new NotFound();
55
-	}
54
+        throw new NotFound();
55
+    }
56 56
 
57
-	public function childExists($name): bool {
58
-		try {
59
-			$this->getChild($name);
60
-			return true;
61
-		} catch (NotFound $e) {
62
-			return false;
63
-		}
64
-	}
57
+    public function childExists($name): bool {
58
+        try {
59
+            $this->getChild($name);
60
+            return true;
61
+        } catch (NotFound $e) {
62
+            return false;
63
+        }
64
+    }
65 65
 
66
-	public function setName($name) {
67
-		throw new Forbidden();
68
-	}
66
+    public function setName($name) {
67
+        throw new Forbidden();
68
+    }
69 69
 
70
-	public function createFile($name, $data = null) {
71
-		throw new Forbidden();
72
-	}
70
+    public function createFile($name, $data = null) {
71
+        throw new Forbidden();
72
+    }
73 73
 
74
-	public function createDirectory($name) {
75
-		throw new Forbidden();
76
-	}
74
+    public function createDirectory($name) {
75
+        throw new Forbidden();
76
+    }
77 77
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 	public function getChildren(): array {
33 33
 		$entries = $this->trashManager->listTrashFolder($this->data);
34 34
 
35
-		$children = array_map(function (ITrashItem $entry) {
35
+		$children = array_map(function(ITrashItem $entry) {
36 36
 			if ($entry->getType() === FileInfo::TYPE_FOLDER) {
37 37
 				return new TrashFolderFolder($this->trashManager, $entry);
38 38
 			}
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/RootCollection.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -31,41 +31,41 @@
 block discarded – undo
31 31
 use Sabre\DAVACL\PrincipalBackend;
32 32
 
33 33
 class RootCollection extends AbstractPrincipalCollection {
34
-	/** @var ITrashManager */
35
-	private $trashManager;
34
+    /** @var ITrashManager */
35
+    private $trashManager;
36 36
 
37
-	public function __construct(
38
-		ITrashManager $trashManager,
39
-		PrincipalBackend\BackendInterface $principalBackend,
40
-		IConfig $config
41
-	) {
42
-		parent::__construct($principalBackend, 'principals/users');
37
+    public function __construct(
38
+        ITrashManager $trashManager,
39
+        PrincipalBackend\BackendInterface $principalBackend,
40
+        IConfig $config
41
+    ) {
42
+        parent::__construct($principalBackend, 'principals/users');
43 43
 
44
-		$this->trashManager = $trashManager;
45
-		$this->disableListing = !$config->getSystemValue('debug', false);
46
-	}
44
+        $this->trashManager = $trashManager;
45
+        $this->disableListing = !$config->getSystemValue('debug', false);
46
+    }
47 47
 
48
-	/**
49
-	 * This method returns a node for a principal.
50
-	 *
51
-	 * The passed array contains principal information, and is guaranteed to
52
-	 * at least contain a uri item. Other properties may or may not be
53
-	 * supplied by the authentication backend.
54
-	 *
55
-	 * @param array $principalInfo
56
-	 * @return INode
57
-	 */
58
-	public function getChildForPrincipal(array $principalInfo): TrashHome {
59
-		list(, $name) = \Sabre\Uri\split($principalInfo['uri']);
60
-		$user = \OC::$server->getUserSession()->getUser();
61
-		if (is_null($user) || $name !== $user->getUID()) {
62
-			throw new \Sabre\DAV\Exception\Forbidden();
63
-		}
64
-		return new TrashHome($principalInfo, $this->trashManager, $user);
65
-	}
48
+    /**
49
+     * This method returns a node for a principal.
50
+     *
51
+     * The passed array contains principal information, and is guaranteed to
52
+     * at least contain a uri item. Other properties may or may not be
53
+     * supplied by the authentication backend.
54
+     *
55
+     * @param array $principalInfo
56
+     * @return INode
57
+     */
58
+    public function getChildForPrincipal(array $principalInfo): TrashHome {
59
+        list(, $name) = \Sabre\Uri\split($principalInfo['uri']);
60
+        $user = \OC::$server->getUserSession()->getUser();
61
+        if (is_null($user) || $name !== $user->getUID()) {
62
+            throw new \Sabre\DAV\Exception\Forbidden();
63
+        }
64
+        return new TrashHome($principalInfo, $this->trashManager, $user);
65
+    }
66 66
 
67
-	public function getName(): string {
68
-		return 'trashbin';
69
-	}
67
+    public function getName(): string {
68
+        return 'trashbin';
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Sabre/TrashFile.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,11 +25,11 @@
 block discarded – undo
25 25
 namespace OCA\Files_Trashbin\Sabre;
26 26
 
27 27
 class TrashFile extends AbstractTrashFile {
28
-	public function get() {
29
-		return $this->data->getStorage()->fopen($this->data->getInternalPath() . '.d' . $this->getLastModified(), 'rb');
30
-	}
28
+    public function get() {
29
+        return $this->data->getStorage()->fopen($this->data->getInternalPath() . '.d' . $this->getLastModified(), 'rb');
30
+    }
31 31
 
32
-	public function getName(): string {
33
-		return $this->data->getName() . '.d' . $this->getLastModified();
34
-	}
32
+    public function getName(): string {
33
+        return $this->data->getName() . '.d' . $this->getLastModified();
34
+    }
35 35
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@
 block discarded – undo
26 26
 
27 27
 class TrashFile extends AbstractTrashFile {
28 28
 	public function get() {
29
-		return $this->data->getStorage()->fopen($this->data->getInternalPath() . '.d' . $this->getLastModified(), 'rb');
29
+		return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb');
30 30
 	}
31 31
 
32 32
 	public function getName(): string {
33
-		return $this->data->getName() . '.d' . $this->getLastModified();
33
+		return $this->data->getName().'.d'.$this->getLastModified();
34 34
 	}
35 35
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Storage.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -41,173 +41,173 @@
 block discarded – undo
41 41
 use Symfony\Component\EventDispatcher\EventDispatcher;
42 42
 
43 43
 class Storage extends Wrapper {
44
-	/** @var IMountPoint */
45
-	private $mountPoint;
46
-
47
-	/** @var  IUserManager */
48
-	private $userManager;
49
-
50
-	/** @var ILogger */
51
-	private $logger;
52
-
53
-	/** @var EventDispatcher */
54
-	private $eventDispatcher;
55
-
56
-	/** @var IRootFolder */
57
-	private $rootFolder;
58
-
59
-	/** @var ITrashManager */
60
-	private $trashManager;
61
-
62
-	/**
63
-	 * Storage constructor.
64
-	 *
65
-	 * @param array $parameters
66
-	 * @param ITrashManager $trashManager
67
-	 * @param IUserManager|null $userManager
68
-	 * @param ILogger|null $logger
69
-	 * @param EventDispatcher|null $eventDispatcher
70
-	 * @param IRootFolder|null $rootFolder
71
-	 */
72
-	public function __construct(
73
-		$parameters,
74
-		ITrashManager $trashManager = null,
75
-		IUserManager $userManager = null,
76
-		ILogger $logger = null,
77
-		EventDispatcher $eventDispatcher = null,
78
-		IRootFolder $rootFolder = null
79
-	) {
80
-		$this->mountPoint = $parameters['mountPoint'];
81
-		$this->trashManager = $trashManager;
82
-		$this->userManager = $userManager;
83
-		$this->logger = $logger;
84
-		$this->eventDispatcher = $eventDispatcher;
85
-		$this->rootFolder = $rootFolder;
86
-		parent::__construct($parameters);
87
-	}
88
-
89
-	/**
90
-	 * Deletes the given file by moving it into the trashbin.
91
-	 *
92
-	 * @param string $path path of file or folder to delete
93
-	 *
94
-	 * @return bool true if the operation succeeded, false otherwise
95
-	 */
96
-	public function unlink($path) {
97
-		try {
98
-			return $this->doDelete($path, 'unlink');
99
-		} catch (GenericEncryptionException $e) {
100
-			// in case of a encryption exception we delete the file right away
101
-			$this->logger->info(
102
-				"Can't move file" . $path .
103
-				"to the trash bin, therefore it was deleted right away");
104
-
105
-			return $this->storage->unlink($path);
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * Deletes the given folder by moving it into the trashbin.
111
-	 *
112
-	 * @param string $path path of folder to delete
113
-	 *
114
-	 * @return bool true if the operation succeeded, false otherwise
115
-	 */
116
-	public function rmdir($path) {
117
-		return $this->doDelete($path, 'rmdir');
118
-	}
119
-
120
-	/**
121
-	 * check if it is a file located in data/user/files only files in the
122
-	 * 'files' directory should be moved to the trash
123
-	 *
124
-	 * @param $path
125
-	 * @return bool
126
-	 */
127
-	protected function shouldMoveToTrash($path) {
128
-
129
-		// check if there is a app which want to disable the trash bin for this file
130
-		$fileId = $this->storage->getCache()->getId($path);
131
-		$nodes = $this->rootFolder->getById($fileId);
132
-		foreach ($nodes as $node) {
133
-			$event = $this->createMoveToTrashEvent($node);
134
-			$this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
135
-			if ($event->shouldMoveToTrashBin() === false) {
136
-				return false;
137
-			}
138
-		}
139
-
140
-		$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
141
-		$parts = explode('/', $normalized);
142
-		if (count($parts) < 4) {
143
-			return false;
144
-		}
145
-
146
-		if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) {
147
-			return true;
148
-		}
149
-
150
-		return false;
151
-	}
152
-
153
-	/**
154
-	 * get move to trash event
155
-	 *
156
-	 * @param Node $node
157
-	 * @return MoveToTrashEvent
158
-	 */
159
-	protected function createMoveToTrashEvent(Node $node) {
160
-		return new MoveToTrashEvent($node);
161
-	}
162
-
163
-	/**
164
-	 * Run the delete operation with the given method
165
-	 *
166
-	 * @param string $path path of file or folder to delete
167
-	 * @param string $method either "unlink" or "rmdir"
168
-	 *
169
-	 * @return bool true if the operation succeeded, false otherwise
170
-	 */
171
-	private function doDelete($path, $method) {
172
-		if (
173
-			!\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')
174
-			|| (pathinfo($path, PATHINFO_EXTENSION) === 'part')
175
-			|| $this->shouldMoveToTrash($path) === false
176
-		) {
177
-			return call_user_func([$this->storage, $method], $path);
178
-		}
179
-
180
-		// check permissions before we continue, this is especially important for
181
-		// shared files
182
-		if (!$this->isDeletable($path)) {
183
-			return false;
184
-		}
185
-
186
-		$isMovedToTrash = $this->trashManager->moveToTrash($this, $path);
187
-		if (!$isMovedToTrash) {
188
-			return call_user_func([$this->storage, $method], $path);
189
-		} else {
190
-			return true;
191
-		}
192
-	}
193
-
194
-	/**
195
-	 * Setup the storate wrapper callback
196
-	 */
197
-	public static function setupStorage() {
198
-		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
199
-			return new \OCA\Files_Trashbin\Storage(
200
-				['storage' => $storage, 'mountPoint' => $mountPoint],
201
-				\OC::$server->query(ITrashManager::class),
202
-				\OC::$server->getUserManager(),
203
-				\OC::$server->getLogger(),
204
-				\OC::$server->getEventDispatcher(),
205
-				\OC::$server->getLazyRootFolder()
206
-			);
207
-		}, 1);
208
-	}
209
-
210
-	public function getMountPoint() {
211
-		return $this->mountPoint;
212
-	}
44
+    /** @var IMountPoint */
45
+    private $mountPoint;
46
+
47
+    /** @var  IUserManager */
48
+    private $userManager;
49
+
50
+    /** @var ILogger */
51
+    private $logger;
52
+
53
+    /** @var EventDispatcher */
54
+    private $eventDispatcher;
55
+
56
+    /** @var IRootFolder */
57
+    private $rootFolder;
58
+
59
+    /** @var ITrashManager */
60
+    private $trashManager;
61
+
62
+    /**
63
+     * Storage constructor.
64
+     *
65
+     * @param array $parameters
66
+     * @param ITrashManager $trashManager
67
+     * @param IUserManager|null $userManager
68
+     * @param ILogger|null $logger
69
+     * @param EventDispatcher|null $eventDispatcher
70
+     * @param IRootFolder|null $rootFolder
71
+     */
72
+    public function __construct(
73
+        $parameters,
74
+        ITrashManager $trashManager = null,
75
+        IUserManager $userManager = null,
76
+        ILogger $logger = null,
77
+        EventDispatcher $eventDispatcher = null,
78
+        IRootFolder $rootFolder = null
79
+    ) {
80
+        $this->mountPoint = $parameters['mountPoint'];
81
+        $this->trashManager = $trashManager;
82
+        $this->userManager = $userManager;
83
+        $this->logger = $logger;
84
+        $this->eventDispatcher = $eventDispatcher;
85
+        $this->rootFolder = $rootFolder;
86
+        parent::__construct($parameters);
87
+    }
88
+
89
+    /**
90
+     * Deletes the given file by moving it into the trashbin.
91
+     *
92
+     * @param string $path path of file or folder to delete
93
+     *
94
+     * @return bool true if the operation succeeded, false otherwise
95
+     */
96
+    public function unlink($path) {
97
+        try {
98
+            return $this->doDelete($path, 'unlink');
99
+        } catch (GenericEncryptionException $e) {
100
+            // in case of a encryption exception we delete the file right away
101
+            $this->logger->info(
102
+                "Can't move file" . $path .
103
+                "to the trash bin, therefore it was deleted right away");
104
+
105
+            return $this->storage->unlink($path);
106
+        }
107
+    }
108
+
109
+    /**
110
+     * Deletes the given folder by moving it into the trashbin.
111
+     *
112
+     * @param string $path path of folder to delete
113
+     *
114
+     * @return bool true if the operation succeeded, false otherwise
115
+     */
116
+    public function rmdir($path) {
117
+        return $this->doDelete($path, 'rmdir');
118
+    }
119
+
120
+    /**
121
+     * check if it is a file located in data/user/files only files in the
122
+     * 'files' directory should be moved to the trash
123
+     *
124
+     * @param $path
125
+     * @return bool
126
+     */
127
+    protected function shouldMoveToTrash($path) {
128
+
129
+        // check if there is a app which want to disable the trash bin for this file
130
+        $fileId = $this->storage->getCache()->getId($path);
131
+        $nodes = $this->rootFolder->getById($fileId);
132
+        foreach ($nodes as $node) {
133
+            $event = $this->createMoveToTrashEvent($node);
134
+            $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
135
+            if ($event->shouldMoveToTrashBin() === false) {
136
+                return false;
137
+            }
138
+        }
139
+
140
+        $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
141
+        $parts = explode('/', $normalized);
142
+        if (count($parts) < 4) {
143
+            return false;
144
+        }
145
+
146
+        if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) {
147
+            return true;
148
+        }
149
+
150
+        return false;
151
+    }
152
+
153
+    /**
154
+     * get move to trash event
155
+     *
156
+     * @param Node $node
157
+     * @return MoveToTrashEvent
158
+     */
159
+    protected function createMoveToTrashEvent(Node $node) {
160
+        return new MoveToTrashEvent($node);
161
+    }
162
+
163
+    /**
164
+     * Run the delete operation with the given method
165
+     *
166
+     * @param string $path path of file or folder to delete
167
+     * @param string $method either "unlink" or "rmdir"
168
+     *
169
+     * @return bool true if the operation succeeded, false otherwise
170
+     */
171
+    private function doDelete($path, $method) {
172
+        if (
173
+            !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')
174
+            || (pathinfo($path, PATHINFO_EXTENSION) === 'part')
175
+            || $this->shouldMoveToTrash($path) === false
176
+        ) {
177
+            return call_user_func([$this->storage, $method], $path);
178
+        }
179
+
180
+        // check permissions before we continue, this is especially important for
181
+        // shared files
182
+        if (!$this->isDeletable($path)) {
183
+            return false;
184
+        }
185
+
186
+        $isMovedToTrash = $this->trashManager->moveToTrash($this, $path);
187
+        if (!$isMovedToTrash) {
188
+            return call_user_func([$this->storage, $method], $path);
189
+        } else {
190
+            return true;
191
+        }
192
+    }
193
+
194
+    /**
195
+     * Setup the storate wrapper callback
196
+     */
197
+    public static function setupStorage() {
198
+        \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
199
+            return new \OCA\Files_Trashbin\Storage(
200
+                ['storage' => $storage, 'mountPoint' => $mountPoint],
201
+                \OC::$server->query(ITrashManager::class),
202
+                \OC::$server->getUserManager(),
203
+                \OC::$server->getLogger(),
204
+                \OC::$server->getEventDispatcher(),
205
+                \OC::$server->getLazyRootFolder()
206
+            );
207
+        }, 1);
208
+    }
209
+
210
+    public function getMountPoint() {
211
+        return $this->mountPoint;
212
+    }
213 213
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		} catch (GenericEncryptionException $e) {
100 100
 			// in case of a encryption exception we delete the file right away
101 101
 			$this->logger->info(
102
-				"Can't move file" . $path .
102
+				"Can't move file".$path.
103 103
 				"to the trash bin, therefore it was deleted right away");
104 104
 
105 105
 			return $this->storage->unlink($path);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			}
138 138
 		}
139 139
 
140
-		$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
140
+		$normalized = Filesystem::normalizePath($this->mountPoint.'/'.$path);
141 141
 		$parts = explode('/', $normalized);
142 142
 		if (count($parts) < 4) {
143 143
 			return false;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * Setup the storate wrapper callback
196 196
 	 */
197 197
 	public static function setupStorage() {
198
-		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
198
+		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function($mountPoint, $storage) {
199 199
 			return new \OCA\Files_Trashbin\Storage(
200 200
 				['storage' => $storage, 'mountPoint' => $mountPoint],
201 201
 				\OC::$server->query(ITrashManager::class),
Please login to merge, or discard this patch.