aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/config.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/config.php')
-rw-r--r--apps/files_external/lib/config.php51
1 files changed, 26 insertions, 25 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index ddfab439879..deeedb98551 100644
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -32,6 +32,10 @@ class OC_Mount_Config {
const MOUNT_TYPE_USER = 'user';
const MOUNT_TYPE_PERSONAL = 'personal';
+ // getBackendStatus return types
+ const STATUS_SUCCESS = 0;
+ const STATUS_ERROR = 1;
+
// whether to skip backend test (for unit tests, as this static class is not mockable)
public static $skipTest = false;
@@ -143,15 +147,9 @@ class OC_Mount_Config {
$mountPoints = array();
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
- $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
$backends = self::getBackends();
- //move config file to it's new position
- if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
- rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
- }
-
// Load system mount points
$mountConfig = self::readData();
@@ -349,6 +347,8 @@ class OC_Mount_Config {
$mountPoint = substr($mountPoint, 13);
$config = array(
+ 'id' => (int) $mount['id'],
+ 'storage_id' => (int) $mount['storage_id'],
'class' => $mount['class'],
'mountpoint' => $mountPoint,
'backend' => $backends[$mount['class']]['backend'],
@@ -383,6 +383,8 @@ class OC_Mount_Config {
// Remove '/$user/files/' from mount point
$mountPoint = substr($mountPoint, 13);
$config = array(
+ 'id' => (int) $mount['id'],
+ 'storage_id' => (int) $mount['storage_id'],
'class' => $mount['class'],
'mountpoint' => $mountPoint,
'backend' => $backends[$mount['class']]['backend'],
@@ -425,6 +427,8 @@ class OC_Mount_Config {
}
$mount['options'] = self::decryptPasswords($mount['options']);
$personal[] = array(
+ 'id' => (int) $mount['id'],
+ 'storage_id' => (int) $mount['storage_id'],
'class' => $mount['class'],
// Remove '/uid/files/' from mount point
'mountpoint' => substr($mountPoint, strlen($uid) + 8),
@@ -442,11 +446,11 @@ class OC_Mount_Config {
*
* @param string $class backend class name
* @param array $options backend configuration options
- * @return bool true if the connection succeeded, false otherwise
+ * @return int see self::STATUS_*
*/
- private static function getBackendStatus($class, $options, $isPersonal) {
+ public static function getBackendStatus($class, $options, $isPersonal) {
if (self::$skipTest) {
- return true;
+ return self::STATUS_SUCCESS;
}
foreach ($options as &$option) {
$option = self::setUserVars(OCP\User::getUser(), $option);
@@ -454,13 +458,14 @@ class OC_Mount_Config {
if (class_exists($class)) {
try {
$storage = new $class($options);
- return $storage->test($isPersonal);
+ if ($storage->test($isPersonal)) {
+ return self::STATUS_SUCCESS;
+ }
} catch (Exception $exception) {
\OCP\Util::logException('files_external', $exception);
- return false;
}
}
- return false;
+ return self::STATUS_ERROR;
}
/**
@@ -474,6 +479,8 @@ class OC_Mount_Config {
* @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page
* @param int|null $priority Mount point priority, null for default
* @return boolean
+ *
+ * @deprecated use StoragesService#addStorage() instead
*/
public static function addMountPoint($mountPoint,
$class,
@@ -537,7 +544,7 @@ class OC_Mount_Config {
self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints);
$result = self::getBackendStatus($class, $classOptions, $isPersonal);
- if ($result && $isNew) {
+ if ($result === self::STATUS_SUCCESS && $isNew) {
\OC_Hook::emit(
\OC\Files\Filesystem::CLASSNAME,
\OC\Files\Filesystem::signal_create_mount,
@@ -558,6 +565,8 @@ class OC_Mount_Config {
* @param string $applicable User or group to remove mount from
* @param bool $isPersonal Personal or system mount point
* @return bool
+ *
+ * @deprecated use StoragesService#removeStorage() instead
*/
public static function removeMountPoint($mountPoint, $mountType, $applicable, $isPersonal = false) {
// Verify that the mount point applies for the current user
@@ -622,13 +631,10 @@ class OC_Mount_Config {
* @param string|null $user If not null, personal for $user, otherwise system
* @return array
*/
- private static function readData($user = null) {
- $parser = new \OC\ArrayParser();
+ public static function readData($user = null) {
if (isset($user)) {
- $phpFile = OC_User::getHome($user) . '/mount.php';
$jsonFile = OC_User::getHome($user) . '/mount.json';
} else {
- $phpFile = OC::$SERVERROOT . '/config/mount.php';
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
$jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
}
@@ -637,11 +643,6 @@ class OC_Mount_Config {
if (is_array($mountPoints)) {
return $mountPoints;
}
- } elseif (is_file($phpFile)) {
- $mountPoints = $parser->parsePHP(file_get_contents($phpFile));
- if (is_array($mountPoints)) {
- return $mountPoints;
- }
}
return array();
}
@@ -652,7 +653,7 @@ class OC_Mount_Config {
* @param string|null $user If not null, personal for $user, otherwise system
* @param array $data Mount points
*/
- private static function writeData($user, $data) {
+ public static function writeData($user, $data) {
if (isset($user)) {
$file = OC_User::getHome($user) . '/mount.json';
} else {
@@ -769,7 +770,7 @@ class OC_Mount_Config {
* @param array $options mount options
* @return array updated options
*/
- private static function encryptPasswords($options) {
+ public static function encryptPasswords($options) {
if (isset($options['password'])) {
$options['password_encrypted'] = self::encryptPassword($options['password']);
// do not unset the password, we want to keep the keys order
@@ -785,7 +786,7 @@ class OC_Mount_Config {
* @param array $options mount options
* @return array updated options
*/
- private static function decryptPasswords($options) {
+ public static function decryptPasswords($options) {
// note: legacy options might still have the unencrypted password in the "password" field
if (isset($options['password_encrypted'])) {
$options['password'] = self::decryptPassword($options['password_encrypted']);