summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/amazons3.php
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-10-16 14:50:39 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-10-27 13:01:36 +0100
commitb5ab3d7fc0253446ec26551e9dda6816dbce2bc2 (patch)
treeecfbeb02a8fa159f2e48096f9baea9e39e5af4f0 /apps/files_external/lib/amazons3.php
parente1e501b17f6d4dd2c13d2b6c36d26d2f7f7c1112 (diff)
downloadnextcloud-server-b5ab3d7fc0253446ec26551e9dda6816dbce2bc2.tar.gz
nextcloud-server-b5ab3d7fc0253446ec26551e9dda6816dbce2bc2.zip
fix files_external storage id migration
Diffstat (limited to 'apps/files_external/lib/amazons3.php')
-rw-r--r--apps/files_external/lib/amazons3.php23
1 files changed, 20 insertions, 3 deletions
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index bbb1b14f848..d3a37a77db0 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -148,11 +148,28 @@ class AmazonS3 extends \OC\Files\Storage\Common {
* @param array $params
*/
public function updateLegacyId (array $params) {
+ $oldId = 'amazon::' . $params['key'] . md5($params['secret']);
+
+ // find by old id or bucket
$stmt = \OC::$server->getDatabaseConnection()->prepare(
- 'UPDATE `*PREFIX*storages` SET `id` = ? WHERE `id` = ?'
+ 'SELECT `numeric_id`, `id` FROM `*PREFIX*storages` WHERE `id` IN (?, ?)'
);
- $oldId = 'amazon::' . $params['key'] . md5($params['secret']);
- $stmt->execute(array($this->id, $oldId));
+ $stmt->execute(array($oldId, $this->id));
+ while ($row = $stmt->fetch()) {
+ $storages[$row['id']] = $row['numeric_id'];
+ }
+
+ if (isset($storages[$this->id]) && isset($storages[$oldId])) {
+ // if both ids exist, delete the old storage and corresponding filecache entries
+ \OC\Files\Cache\Storage::remove($oldId);
+ } else if (isset($storages[$oldId])) {
+ // if only the old id exists do an update
+ $stmt = \OC::$server->getDatabaseConnection()->prepare(
+ 'UPDATE `*PREFIX*storages` SET `id` = ? WHERE `id` = ?'
+ );
+ $stmt->execute(array($this->id, $oldId));
+ }
+ // only the bucket based id may exist, do nothing
}
/**