summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-10-21 10:14:55 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-10-21 10:14:55 (GMT)
commitd4c7234ef275d7f4648807ce2751503656f2fbb1 (patch)
treeb2b538b718c0f17b45d3dd02002607907155296f
parent5dec283fdc2ce03f6299af6f6e06d365e3d1358b (diff)
downloadkolab-chwala-d4c7234ef275d7f4648807ce2751503656f2fbb1.tar.gz
Implement mount point rename, fix Kolab object update in folder_auth
-rw-r--r--lib/api/folder_auth.php19
-rw-r--r--lib/api/folder_move.php45
-rw-r--r--lib/file_api_core.php6
3 files changed, 50 insertions, 20 deletions
diff --git a/lib/api/folder_auth.php b/lib/api/folder_auth.php
index feb8113..224b303 100644
--- a/lib/api/folder_auth.php
+++ b/lib/api/folder_auth.php
@@ -35,20 +35,14 @@ class file_api_folder_auth extends file_api_common
throw new Exception("Missing folder name", file_api_core::ERROR_CODE);
}
- $drivers = $this->api->get_drivers();
+ list($driver, $path, $driver_config) = $this->api->get_driver($this->args['folder']);
- foreach ($drivers as $driver_config) {
- if ($driver_config['title'] === $this->args['folder']) {
- $driver = $this->api->get_driver_object($driver_config);
- $meta = $driver->driver_metadata();
- }
- }
-
- if (empty($driver)) {
+ if (empty($driver) || $driver->title() === '') {
throw new Exception("Unknown folder", file_api_core::ERROR_CODE);
}
// check if authentication works
+ $meta = $driver->driver_metadata();
$data = array_fill_keys(array_keys($meta['form']), '');
$data = array_merge($data, $this->args);
$data = $driver->driver_validate($data);
@@ -59,18 +53,17 @@ class file_api_folder_auth extends file_api_common
}
else {
unset($data['password']);
+ unset($driver_config['password']);
}
// save changed data
foreach (array_keys($meta['form']) as $key) {
if ($meta['form_values'][$key] != $data[$key]) {
// update driver config
- $data['title'] = $driver_config['title'];
- $data['driver'] = $driver_config['driver'];
- $data['enabled'] = 1;
+ $driver_config = array_merge($driver_config, $data);
$backend = $this->api->get_backend();
- $backend->driver_update($this->args['folder'], $data);
+ $backend->driver_update($this->args['folder'], $driver_config);
break;
}
}
diff --git a/lib/api/folder_move.php b/lib/api/folder_move.php
index 22eced0..a06a05a 100644
--- a/lib/api/folder_move.php
+++ b/lib/api/folder_move.php
@@ -43,14 +43,19 @@ class file_api_folder_move extends file_api_common
return;
}
- list($src_driver, $src_path) = $this->api->get_driver($this->args['folder']);
- list($dst_driver, $dst_path) = $this->api->get_driver($this->args['new']);
+ list($src_driver, $src_path, $cfg) = $this->api->get_driver($this->args['folder']);
+ list($dst_driver, $dst_path) = $this->api->get_driver($this->args['new']);
// source folder is a mount point (driver title)...
if ($src_driver->title() === $this->args['folder']) {
- // ... rename
+ // ...rename
if (strpos($this->args['new'], file_storage::SEPARATOR) === false) {
- // @TODO
+ // destination folder is an existing mount point
+ if (!strlen($dst_path)) {
+ throw new Exception("Destination folder already exists", file_api_core::ERROR_CODE);
+ }
+
+ return $this->driver_rename($src_driver, $this->args['new'], $cfg);
}
throw new Exception("Unsupported operation", file_api_core::ERROR_CODE);
@@ -143,4 +148,36 @@ class file_api_folder_move extends file_api_common
fclose($fp);
}
+
+ /**
+ * External storage (mount point) rename
+ */
+ protected function driver_rename($driver, $new_name, $config)
+ {
+ $backend = $this->api->get_backend();
+ $folders = $backend->folder_list();
+
+ // first check if destination folder not exists
+ if (in_array($new_name, $folders)) {
+ throw new Exception("Destination folder already exists", file_api_core::ERROR_CODE);
+ }
+
+ $title = $driver->title();
+ $config['title'] = $new_name;
+
+ // store passwords if it was already stored
+ if (empty($config['password']) || $config['password'] != '%u') {
+ unset($config['password']);
+ }
+
+ $backend->driver_update($title, $config);
+
+ // authenticate again to set session password
+ if (empty($config['password']) || $config['password'] != '%u') {
+ $auth = $driver->auth_info();
+ list($driver) = $this->api->get_driver($new_name);
+
+ $driver->authenticate($auth['username'], $auth['password']);
+ }
+ }
}
diff --git a/lib/file_api_core.php b/lib/file_api_core.php
index 27ccc94..cefd261 100644
--- a/lib/file_api_core.php
+++ b/lib/file_api_core.php
@@ -118,7 +118,7 @@ class file_api_core extends file_locale
*
* @param string $path Folder/file path
*
- * @return array Storage driver object and modified path
+ * @return array Storage driver object, modified path, driver config
*/
public function get_driver($path)
{
@@ -139,7 +139,7 @@ class file_api_core extends file_locale
$path = substr($path, strlen($selected['title']) + 1);
- return array($this->get_driver_object($selected), $path);
+ return array($this->get_driver_object($selected), $path, $selected);
}
/**
@@ -242,7 +242,7 @@ class file_api_core extends file_locale
protected function supported_mimetypes()
{
$mimetypes = array();
- $dir = __DIR__ . '/lib/viewers';
+ $dir = __DIR__ . '/viewers';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {