summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-03-17 10:32:11 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-05-04 10:42:32 +0200
commit67ee02574fea4e6a3360abf4790a1a366a5fd8ce (patch)
treea9360a972bb4fb43e4a9b731a37d7092f58c8c53
parent6a6acd2a465e6d5f4c831a0a8107b89f3acc91e8 (diff)
downloadnextcloud-server-67ee02574fea4e6a3360abf4790a1a366a5fd8ce.tar.gz
nextcloud-server-67ee02574fea4e6a3360abf4790a1a366a5fd8ce.zip
Use insertIfNotExists() instead of manual logic
-rw-r--r--apps/files_sharing/lib/external/manager.php55
1 files changed, 31 insertions, 24 deletions
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php
index eb030656894..592cfc4f9c1 100644
--- a/apps/files_sharing/lib/external/manager.php
+++ b/apps/files_sharing/lib/external/manager.php
@@ -66,7 +66,7 @@ class Manager {
* @param boolean $accepted
* @param string $user
* @param int $remoteId
- * @return mixed
+ * @return Mount|null
*/
public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
@@ -74,32 +74,41 @@ class Manager {
$accepted = $accepted ? 1 : 0;
$name = Filesystem::normalizePath('/' . $name);
- if ($accepted) {
- $mountPoint = Files::buildNotExistingFileName('/', $name);
- $mountPoint = Filesystem::normalizePath('/' . $mountPoint);
- $hash = md5($mountPoint);
- } else {
+ if (!$accepted) {
// To avoid conflicts with the mount point generation later,
// we only use a temporary mount point name here. The real
// mount point name will be generated when accepting the share,
// using the original share item name.
- $tmpMountPointName = Filesystem::normalizePath('/TemporaryMountPointName-' . $name);
+ $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}';
$mountPoint = $tmpMountPointName;
$hash = md5($tmpMountPointName);
-
- $query = $this->connection->prepare('SELECT `id` FROM `*PREFIX*share_external` WHERE `user` = ? AND `mountpoint_hash` = ?', 1);
- $query->execute([$user, $hash]);
+ $data = [
+ 'remote' => $remote,
+ 'share_token' => $token,
+ 'password' => $password,
+ 'name' => $name,
+ 'owner' => $owner,
+ 'user' => $user,
+ 'mountpoint' => $mountPoint,
+ 'mountpoint_hash' => $hash,
+ 'accepted' => $accepted,
+ 'remote_id' => $remoteId,
+ ];
$i = 1;
- while ($query->fetch()) {
+ while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) {
// The external share already exists for the user
- $mountPoint = $tmpMountPointName . '-' . $i;
- $hash = md5($mountPoint);
- $query->execute([$user, $hash]);
+ $data['mountpoint'] = $tmpMountPointName . '-' . $i;
+ $data['mountpoint_hash'] = md5($data['mountpoint']);
$i++;
}
+ return null;
}
+ $mountPoint = Files::buildNotExistingFileName('/', $name);
+ $mountPoint = Filesystem::normalizePath('/' . $mountPoint);
+ $hash = md5($mountPoint);
+
$query = $this->connection->prepare('
INSERT INTO `*PREFIX*share_external`
(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
@@ -107,16 +116,14 @@ class Manager {
');
$query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
- if ($accepted) {
- $options = array(
- 'remote' => $remote,
- 'token' => $token,
- 'password' => $password,
- 'mountpoint' => $mountPoint,
- 'owner' => $owner
- );
- return $this->mountShare($options);
- }
+ $options = array(
+ 'remote' => $remote,
+ 'token' => $token,
+ 'password' => $password,
+ 'mountpoint' => $mountPoint,
+ 'owner' => $owner
+ );
+ return $this->mountShare($options);
}
private function setupMounts() {