summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/appinfo
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-04-16 17:43:02 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-04-23 12:54:26 +0200
commitb102222fed33245c6da8a39c28f0d0a570d0dbea (patch)
tree5d0ac0a691deee88bcf735d49b35c87930f66cf5 /apps/files_sharing/appinfo
parent93469ca46865d02d33710a2f70f7f6092c8f5c58 (diff)
downloadnextcloud-server-b102222fed33245c6da8a39c28f0d0a570d0dbea.tar.gz
nextcloud-server-b102222fed33245c6da8a39c28f0d0a570d0dbea.zip
split-up the update script and add unit tests for it
Diffstat (limited to 'apps/files_sharing/appinfo')
-rw-r--r--apps/files_sharing/appinfo/update.php58
1 files changed, 37 insertions, 21 deletions
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php
index c79a2291e92..bc8cda42313 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -2,6 +2,21 @@
$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
if (version_compare($installedVersion, '0.4', '<')) {
+ removeSharedFolder();
+}
+
+// clean up oc_share table from files which are no longer exists
+if (version_compare($installedVersion, '0.3.5.6', '<')) {
+ \OC\Files\Cache\Shared_Updater::fixBrokenSharesOnAppUpdate();
+}
+
+
+/**
+ * update script for the removal of the logical "Shared" folder, we create physical "Shared" folder and
+ * update the users file_target so that it doesn't make any difference for the user
+ * @note parameters are just for testing, please ignore them
+ */
+function removeSharedFolder($mkdirs = true, $chunkSize = 99) {
$query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $query->execute();
$view = new \OC\Files\View('/');
@@ -14,14 +29,14 @@ if (version_compare($installedVersion, '0.4', '<')) {
//we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
while ($row = $result->fetchRow()) {
//collect all user shares
- if ($row['share_type'] === "0" && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
+ if ((int)$row['share_type'] === 0 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
$users[] = $row['share_with'];
$shares[$row['id']] = $row['file_target'];
- } else if ($row['share_type'] === "1" && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
+ } else if ((int)$row['share_type'] === 1 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
//collect all group shares
$users = array_merge($users, \OC_group::usersInGroup($row['share_with']));
$shares[$row['id']] = $row['file_target'];
- } else if ($row['share_type'] === "2") {
+ } else if ((int)$row['share_type'] === 2) {
$shares[$row['id']] = $row['file_target'];
}
}
@@ -32,30 +47,31 @@ if (version_compare($installedVersion, '0.4', '<')) {
// create folder Shared for each user
- foreach ($unique_users as $user) {
- \OC\Files\Filesystem::initMountPoints($user);
- if (!$view->file_exists('/' . $user . '/files/Shared')) {
- $view->mkdir('/' . $user . '/files/Shared');
+ if ($mkdirs) {
+ foreach ($unique_users as $user) {
+ \OC\Files\Filesystem::initMountPoints($user);
+ if (!$view->file_exists('/' . $user . '/files/Shared')) {
+ $view->mkdir('/' . $user . '/files/Shared');
+ }
}
}
- $statement = "UPDATE `*PREFIX*share` SET `file_target` = CASE id ";
- //update share table
- $ids = implode(',', array_keys($shares));
- foreach ($shares as $id => $target) {
- $statement .= "WHEN " . $id . " THEN '/Shared" . $target . "' ";
- }
- $statement .= ' END WHERE `id` IN (' . $ids . ')';
+ $chunkedShareList = array_chunk($shares, $chunkSize, true);
- $query = OCP\DB::prepare($statement);
+ foreach ($chunkedShareList as $subList) {
- $query->execute(array());
+ $statement = "UPDATE `*PREFIX*share` SET `file_target` = CASE `id` ";
+ //update share table
+ $ids = implode(',', array_keys($subList));
+ foreach ($subList as $id => $target) {
+ $statement .= "WHEN " . $id . " THEN '/Shared" . $target . "' ";
+ }
+ $statement .= ' END WHERE `id` IN (' . $ids . ')';
- }
+ $query = OCP\DB::prepare($statement);
-}
+ $query->execute(array());
+ }
-// clean up oc_share table from files which are no longer exists
-if (version_compare($installedVersion, '0.3.5.6', '<')) {
- \OC\Files\Cache\Shared_Updater::fixBrokenSharesOnAppUpdate();
+ }
}