Merge pull request #8562 from owncloud/better-addmountpoint

Extract mount point merging logic into separate function
This commit is contained in:
Vincent Petry 2014-05-13 12:19:41 +02:00
commit 6d00675d69
1 changed files with 25 additions and 11 deletions

View File

@ -400,19 +400,11 @@ class OC_Mount_Config {
'options' => self::encryptPasswords($classOptions))
)
);
$mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
// Merge the new mount point into the current mount points
if (isset($mountPoints[$mountType])) {
if (isset($mountPoints[$mountType][$applicable])) {
$mountPoints[$mountType][$applicable]
= array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]);
} else {
$mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount);
}
} else {
$mountPoints[$mountType] = $mount;
}
$mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType);
self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
return self::getBackendStatus($class, $classOptions, $isPersonal);
}
@ -689,6 +681,28 @@ class OC_Mount_Config {
return $cipher->decrypt($binaryPassword);
}
/**
* Merges mount points
* @param array $data Existing mount points
* @param array $mountPoint New mount point
* @param string $mountType
* @return array
*/
private static function mergeMountPoints($data, $mountPoint, $mountType) {
$applicable = key($mountPoint);
if (isset($data[$mountType])) {
if (isset($data[$mountType][$applicable])) {
$data[$mountType][$applicable]
= array_merge($data[$mountType][$applicable], $mountPoint[$applicable]);
} else {
$data[$mountType] = array_merge($data[$mountType], $mountPoint);
}
} else {
$data[$mountType] = $mountPoint;
}
return $data;
}
/**
* Returns the encryption cipher
*/