Code Duplication    Length = 21-24 lines in 3 locations

apps/files_sharing/lib/Helper.php 1 location

@@ 213-233 (lines=21) @@
210
	 * @return array
211
	 * @throws \OC\User\NoUserException
212
	 */
213
	public static function getUidAndFilename($filename) {
214
		$uid = Filesystem::getOwner($filename);
215
		$userManager = \OC::$server->getUserManager();
216
		// if the user with the UID doesn't exists, e.g. because the UID points
217
		// to a remote user with a federated cloud ID we use the current logged-in
218
		// user. We need a valid local user to create the share
219
		if (!$userManager->userExists($uid)) {
220
			$uid = User::getUser();
221
		}
222
		Filesystem::initMountPoints($uid);
223
		if ( $uid != User::getUser() ) {
224
			$info = Filesystem::getFileInfo($filename);
225
			$ownerView = new View('/'.$uid.'/files');
226
			try {
227
				$filename = $ownerView->getPath($info['fileid']);
228
			} catch (NotFoundException $e) {
229
				$filename = null;
230
			}
231
		}
232
		return [$uid, $filename];
233
	}
234
235
	/**
236
	 * Format a path to be relative to the /user/files/ directory

apps/files_trashbin/lib/Trashbin.php 1 location

@@ 81-101 (lines=21) @@
78
	 * @return array
79
	 * @throws \OC\User\NoUserException
80
	 */
81
	public static function getUidAndFilename($filename) {
82
		$uid = Filesystem::getOwner($filename);
83
		$userManager = \OC::$server->getUserManager();
84
		// if the user with the UID doesn't exists, e.g. because the UID points
85
		// to a remote user with a federated cloud ID we use the current logged-in
86
		// user. We need a valid local user to move the file to the right trash bin
87
		if (!$userManager->userExists($uid)) {
88
			$uid = User::getUser();
89
		}
90
		Filesystem::initMountPoints($uid);
91
		if ($uid != User::getUser()) {
92
			$info = Filesystem::getFileInfo($filename);
93
			$ownerView = new View('/' . $uid . '/files');
94
			try {
95
				$filename = $ownerView->getPath($info['fileid']);
96
			} catch (NotFoundException $e) {
97
				$filename = null;
98
			}
99
		}
100
		return [$uid, $filename];
101
	}
102
103
	/**
104
	 * get original location of files for user

apps/files_versions/lib/Storage.php 1 location

@@ 92-115 (lines=24) @@
89
	 * @return array
90
	 * @throws \OC\User\NoUserException
91
	 */
92
	public static function getUidAndFilename($filename) {
93
		$uid = Filesystem::getOwner($filename);
94
		$userManager = \OC::$server->getUserManager();
95
		// if the user with the UID doesn't exists, e.g. because the UID points
96
		// to a remote user with a federated cloud ID we use the current logged-in
97
		// user. We need a valid local user to create the versions
98
		if (!$userManager->userExists($uid)) {
99
			$uid = User::getUser();
100
		}
101
		Filesystem::initMountPoints($uid);
102
		if ( $uid != User::getUser() ) {
103
			$info = Filesystem::getFileInfo($filename);
104
			$ownerView = new View('/'.$uid.'/files');
105
			try {
106
				$filename = $ownerView->getPath($info['fileid']);
107
				// make sure that the file name doesn't end with a trailing slash
108
				// can for example happen single files shared across servers
109
				$filename = rtrim($filename, '/');
110
			} catch (NotFoundException $e) {
111
				$filename = null;
112
			}
113
		}
114
		return [$uid, $filename];
115
	}
116
117
	/**
118
	 * Remember the owner and the owner path of the source file