Passed
Push — master ( 35b910...9e1c36 )
by Roeland
15:34 queued 15s
created
apps/files_trashbin/lib/Storage.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -43,220 +43,220 @@
 block discarded – undo
43 43
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
44 44
 
45 45
 class Storage extends Wrapper {
46
-	/** @var IMountPoint */
47
-	private $mountPoint;
46
+    /** @var IMountPoint */
47
+    private $mountPoint;
48 48
 
49
-	/** @var  IUserManager */
50
-	private $userManager;
49
+    /** @var  IUserManager */
50
+    private $userManager;
51 51
 
52
-	/** @var ILogger */
53
-	private $logger;
52
+    /** @var ILogger */
53
+    private $logger;
54 54
 
55
-	/** @var EventDispatcherInterface */
56
-	private $eventDispatcher;
55
+    /** @var EventDispatcherInterface */
56
+    private $eventDispatcher;
57 57
 
58
-	/** @var IRootFolder */
59
-	private $rootFolder;
58
+    /** @var IRootFolder */
59
+    private $rootFolder;
60 60
 
61
-	/** @var ITrashManager */
62
-	private $trashManager;
61
+    /** @var ITrashManager */
62
+    private $trashManager;
63 63
 
64
-	private $trashEnabled = true;
64
+    private $trashEnabled = true;
65 65
 
66
-	/**
67
-	 * Storage constructor.
68
-	 *
69
-	 * @param array $parameters
70
-	 * @param ITrashManager $trashManager
71
-	 * @param IUserManager|null $userManager
72
-	 * @param ILogger|null $logger
73
-	 * @param EventDispatcherInterface|null $eventDispatcher
74
-	 * @param IRootFolder|null $rootFolder
75
-	 */
76
-	public function __construct(
77
-		$parameters,
78
-		ITrashManager $trashManager = null,
79
-		IUserManager $userManager = null,
80
-		ILogger $logger = null,
81
-		EventDispatcherInterface $eventDispatcher = null,
82
-		IRootFolder $rootFolder = null
83
-	) {
84
-		$this->mountPoint = $parameters['mountPoint'];
85
-		$this->trashManager = $trashManager;
86
-		$this->userManager = $userManager;
87
-		$this->logger = $logger;
88
-		$this->eventDispatcher = $eventDispatcher;
89
-		$this->rootFolder = $rootFolder;
90
-		parent::__construct($parameters);
91
-	}
66
+    /**
67
+     * Storage constructor.
68
+     *
69
+     * @param array $parameters
70
+     * @param ITrashManager $trashManager
71
+     * @param IUserManager|null $userManager
72
+     * @param ILogger|null $logger
73
+     * @param EventDispatcherInterface|null $eventDispatcher
74
+     * @param IRootFolder|null $rootFolder
75
+     */
76
+    public function __construct(
77
+        $parameters,
78
+        ITrashManager $trashManager = null,
79
+        IUserManager $userManager = null,
80
+        ILogger $logger = null,
81
+        EventDispatcherInterface $eventDispatcher = null,
82
+        IRootFolder $rootFolder = null
83
+    ) {
84
+        $this->mountPoint = $parameters['mountPoint'];
85
+        $this->trashManager = $trashManager;
86
+        $this->userManager = $userManager;
87
+        $this->logger = $logger;
88
+        $this->eventDispatcher = $eventDispatcher;
89
+        $this->rootFolder = $rootFolder;
90
+        parent::__construct($parameters);
91
+    }
92 92
 
93
-	/**
94
-	 * Deletes the given file by moving it into the trashbin.
95
-	 *
96
-	 * @param string $path path of file or folder to delete
97
-	 *
98
-	 * @return bool true if the operation succeeded, false otherwise
99
-	 */
100
-	public function unlink($path) {
101
-		if ($this->trashEnabled) {
102
-			try {
103
-				return $this->doDelete($path, 'unlink');
104
-			} catch (GenericEncryptionException $e) {
105
-				// in case of a encryption exception we delete the file right away
106
-				$this->logger->info(
107
-					"Can't move file " . $path .
108
-					" to the trash bin, therefore it was deleted right away");
93
+    /**
94
+     * Deletes the given file by moving it into the trashbin.
95
+     *
96
+     * @param string $path path of file or folder to delete
97
+     *
98
+     * @return bool true if the operation succeeded, false otherwise
99
+     */
100
+    public function unlink($path) {
101
+        if ($this->trashEnabled) {
102
+            try {
103
+                return $this->doDelete($path, 'unlink');
104
+            } catch (GenericEncryptionException $e) {
105
+                // in case of a encryption exception we delete the file right away
106
+                $this->logger->info(
107
+                    "Can't move file " . $path .
108
+                    " to the trash bin, therefore it was deleted right away");
109 109
 
110
-				return $this->storage->unlink($path);
111
-			}
112
-		} else {
113
-			return $this->storage->unlink($path);
114
-		}
115
-	}
110
+                return $this->storage->unlink($path);
111
+            }
112
+        } else {
113
+            return $this->storage->unlink($path);
114
+        }
115
+    }
116 116
 
117
-	/**
118
-	 * Deletes the given folder by moving it into the trashbin.
119
-	 *
120
-	 * @param string $path path of folder to delete
121
-	 *
122
-	 * @return bool true if the operation succeeded, false otherwise
123
-	 */
124
-	public function rmdir($path) {
125
-		if ($this->trashEnabled) {
126
-			return $this->doDelete($path, 'rmdir');
127
-		} else {
128
-			return $this->storage->rmdir($path);
129
-		}
130
-	}
117
+    /**
118
+     * Deletes the given folder by moving it into the trashbin.
119
+     *
120
+     * @param string $path path of folder to delete
121
+     *
122
+     * @return bool true if the operation succeeded, false otherwise
123
+     */
124
+    public function rmdir($path) {
125
+        if ($this->trashEnabled) {
126
+            return $this->doDelete($path, 'rmdir');
127
+        } else {
128
+            return $this->storage->rmdir($path);
129
+        }
130
+    }
131 131
 
132
-	/**
133
-	 * check if it is a file located in data/user/files only files in the
134
-	 * 'files' directory should be moved to the trash
135
-	 *
136
-	 * @param $path
137
-	 * @return bool
138
-	 */
139
-	protected function shouldMoveToTrash($path) {
140
-		$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
141
-		$parts = explode('/', $normalized);
142
-		if (count($parts) < 4 || strpos($normalized, '/appdata_') === 0) {
143
-			return false;
144
-		}
132
+    /**
133
+     * check if it is a file located in data/user/files only files in the
134
+     * 'files' directory should be moved to the trash
135
+     *
136
+     * @param $path
137
+     * @return bool
138
+     */
139
+    protected function shouldMoveToTrash($path) {
140
+        $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
141
+        $parts = explode('/', $normalized);
142
+        if (count($parts) < 4 || strpos($normalized, '/appdata_') === 0) {
143
+            return false;
144
+        }
145 145
 
146
-		// check if there is a app which want to disable the trash bin for this file
147
-		$fileId = $this->storage->getCache()->getId($path);
148
-		$owner = $this->storage->getOwner($path);
149
-		if ($owner === false || $this->storage->instanceOfStorage(\OCA\Files_Sharing\External\Storage::class)) {
150
-			$nodes = $this->rootFolder->getById($fileId);
151
-		} else {
152
-			$nodes = $this->rootFolder->getUserFolder($owner)->getById($fileId);
153
-		}
146
+        // check if there is a app which want to disable the trash bin for this file
147
+        $fileId = $this->storage->getCache()->getId($path);
148
+        $owner = $this->storage->getOwner($path);
149
+        if ($owner === false || $this->storage->instanceOfStorage(\OCA\Files_Sharing\External\Storage::class)) {
150
+            $nodes = $this->rootFolder->getById($fileId);
151
+        } else {
152
+            $nodes = $this->rootFolder->getUserFolder($owner)->getById($fileId);
153
+        }
154 154
 
155
-		foreach ($nodes as $node) {
156
-			$event = $this->createMoveToTrashEvent($node);
157
-			$this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
158
-			if ($event->shouldMoveToTrashBin() === false) {
159
-				return false;
160
-			}
161
-		}
155
+        foreach ($nodes as $node) {
156
+            $event = $this->createMoveToTrashEvent($node);
157
+            $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event);
158
+            if ($event->shouldMoveToTrashBin() === false) {
159
+                return false;
160
+            }
161
+        }
162 162
 
163
-		if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) {
164
-			return true;
165
-		}
163
+        if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) {
164
+            return true;
165
+        }
166 166
 
167
-		return false;
168
-	}
167
+        return false;
168
+    }
169 169
 
170
-	/**
171
-	 * get move to trash event
172
-	 *
173
-	 * @param Node $node
174
-	 * @return MoveToTrashEvent
175
-	 */
176
-	protected function createMoveToTrashEvent(Node $node) {
177
-		return new MoveToTrashEvent($node);
178
-	}
170
+    /**
171
+     * get move to trash event
172
+     *
173
+     * @param Node $node
174
+     * @return MoveToTrashEvent
175
+     */
176
+    protected function createMoveToTrashEvent(Node $node) {
177
+        return new MoveToTrashEvent($node);
178
+    }
179 179
 
180
-	/**
181
-	 * Run the delete operation with the given method
182
-	 *
183
-	 * @param string $path path of file or folder to delete
184
-	 * @param string $method either "unlink" or "rmdir"
185
-	 *
186
-	 * @return bool true if the operation succeeded, false otherwise
187
-	 */
188
-	private function doDelete($path, $method) {
189
-		if (
190
-			!\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')
191
-			|| (pathinfo($path, PATHINFO_EXTENSION) === 'part')
192
-			|| $this->shouldMoveToTrash($path) === false
193
-		) {
194
-			return call_user_func([$this->storage, $method], $path);
195
-		}
180
+    /**
181
+     * Run the delete operation with the given method
182
+     *
183
+     * @param string $path path of file or folder to delete
184
+     * @param string $method either "unlink" or "rmdir"
185
+     *
186
+     * @return bool true if the operation succeeded, false otherwise
187
+     */
188
+    private function doDelete($path, $method) {
189
+        if (
190
+            !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')
191
+            || (pathinfo($path, PATHINFO_EXTENSION) === 'part')
192
+            || $this->shouldMoveToTrash($path) === false
193
+        ) {
194
+            return call_user_func([$this->storage, $method], $path);
195
+        }
196 196
 
197
-		// check permissions before we continue, this is especially important for
198
-		// shared files
199
-		if (!$this->isDeletable($path)) {
200
-			return false;
201
-		}
197
+        // check permissions before we continue, this is especially important for
198
+        // shared files
199
+        if (!$this->isDeletable($path)) {
200
+            return false;
201
+        }
202 202
 
203
-		$isMovedToTrash = $this->trashManager->moveToTrash($this, $path);
204
-		if (!$isMovedToTrash) {
205
-			return call_user_func([$this->storage, $method], $path);
206
-		} else {
207
-			return true;
208
-		}
209
-	}
203
+        $isMovedToTrash = $this->trashManager->moveToTrash($this, $path);
204
+        if (!$isMovedToTrash) {
205
+            return call_user_func([$this->storage, $method], $path);
206
+        } else {
207
+            return true;
208
+        }
209
+    }
210 210
 
211
-	/**
212
-	 * Setup the storate wrapper callback
213
-	 */
214
-	public static function setupStorage() {
215
-		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
216
-			return new \OCA\Files_Trashbin\Storage(
217
-				['storage' => $storage, 'mountPoint' => $mountPoint],
218
-				\OC::$server->query(ITrashManager::class),
219
-				\OC::$server->getUserManager(),
220
-				\OC::$server->getLogger(),
221
-				\OC::$server->getEventDispatcher(),
222
-				\OC::$server->getLazyRootFolder()
223
-			);
224
-		}, 1);
225
-	}
211
+    /**
212
+     * Setup the storate wrapper callback
213
+     */
214
+    public static function setupStorage() {
215
+        \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) {
216
+            return new \OCA\Files_Trashbin\Storage(
217
+                ['storage' => $storage, 'mountPoint' => $mountPoint],
218
+                \OC::$server->query(ITrashManager::class),
219
+                \OC::$server->getUserManager(),
220
+                \OC::$server->getLogger(),
221
+                \OC::$server->getEventDispatcher(),
222
+                \OC::$server->getLazyRootFolder()
223
+            );
224
+        }, 1);
225
+    }
226 226
 
227
-	public function getMountPoint() {
228
-		return $this->mountPoint;
229
-	}
227
+    public function getMountPoint() {
228
+        return $this->mountPoint;
229
+    }
230 230
 
231
-	public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
232
-		$sourceIsTrashbin = $sourceStorage->instanceOfStorage(Storage::class);
233
-		try {
234
-			// the fallback for moving between storage involves a copy+delete
235
-			// we don't want to trigger the trashbin when doing the delete
236
-			if ($sourceIsTrashbin) {
237
-				/** @var Storage $sourceStorage */
238
-				$sourceStorage->disableTrash();
239
-			}
240
-			$result = parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
241
-			if ($sourceIsTrashbin) {
242
-				/** @var Storage $sourceStorage */
243
-				$sourceStorage->enableTrash();
244
-			}
245
-			return $result;
246
-		} catch (\Exception $e) {
247
-			if ($sourceIsTrashbin) {
248
-				/** @var Storage $sourceStorage */
249
-				$sourceStorage->enableTrash();
250
-			}
251
-			throw $e;
252
-		}
253
-	}
231
+    public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
232
+        $sourceIsTrashbin = $sourceStorage->instanceOfStorage(Storage::class);
233
+        try {
234
+            // the fallback for moving between storage involves a copy+delete
235
+            // we don't want to trigger the trashbin when doing the delete
236
+            if ($sourceIsTrashbin) {
237
+                /** @var Storage $sourceStorage */
238
+                $sourceStorage->disableTrash();
239
+            }
240
+            $result = parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
241
+            if ($sourceIsTrashbin) {
242
+                /** @var Storage $sourceStorage */
243
+                $sourceStorage->enableTrash();
244
+            }
245
+            return $result;
246
+        } catch (\Exception $e) {
247
+            if ($sourceIsTrashbin) {
248
+                /** @var Storage $sourceStorage */
249
+                $sourceStorage->enableTrash();
250
+            }
251
+            throw $e;
252
+        }
253
+    }
254 254
 
255
-	protected function disableTrash() {
256
-		$this->trashEnabled = false;
257
-	}
255
+    protected function disableTrash() {
256
+        $this->trashEnabled = false;
257
+    }
258 258
 
259
-	protected function enableTrash() {
260
-		$this->trashEnabled = true;
261
-	}
259
+    protected function enableTrash() {
260
+        $this->trashEnabled = true;
261
+    }
262 262
 }
Please login to merge, or discard this patch.