summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/appinfo/update.php
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-04-14 15:04:27 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-04-23 12:54:26 +0200
commitaae22b2d6a5be03fca8de68e43305373dc07b3c4 (patch)
tree24b4583935ebdecd2d84da4cdab4dbdf294f754d /apps/files_sharing/appinfo/update.php
parentbffcbac7a78c8b88b581489cca9bb44795cf81eb (diff)
downloadnextcloud-server-aae22b2d6a5be03fca8de68e43305373dc07b3c4.tar.gz
nextcloud-server-aae22b2d6a5be03fca8de68e43305373dc07b3c4.zip
update script, create Shared folder and adjust target path for the shares
Diffstat (limited to 'apps/files_sharing/appinfo/update.php')
-rw-r--r--apps/files_sharing/appinfo/update.php103
1 files changed, 43 insertions, 60 deletions
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php
index ab32108ea25..ebeeae10d2c 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -1,73 +1,56 @@
<?php
+
$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
-if (version_compare($installedVersion, '0.3', '<')) {
- $update_error = false;
- $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*sharing`');
+if (version_compare($installedVersion, '0.4', '<')) {
+ $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $query->execute();
- $groupShares = array();
- //we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
+ $view = new \OC\Files\View('/');
+ $users = array();
+ $shares = array();
+ //we need to set up user backends
OC_User::useBackend(new OC_User_Database());
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
- $rootView = new \OC\Files\View('');
+ //we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
while ($row = $result->fetchRow()) {
- $meta = $rootView->getFileInfo($$row['source']);
- $itemSource = $meta['fileid'];
- if ($itemSource != -1) {
- $file = $meta;
- if ($file['mimetype'] == 'httpd/unix-directory') {
- $itemType = 'folder';
- } else {
- $itemType = 'file';
- }
- if ($row['permissions'] == 0) {
- $permissions = OCP\PERMISSION_READ | OCP\PERMISSION_SHARE;
- } else {
- $permissions = OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_SHARE;
- if ($itemType == 'folder') {
- $permissions |= OCP\PERMISSION_CREATE;
- }
- }
- $pos = strrpos($row['uid_shared_with'], '@');
- if ($pos !== false && OC_Group::groupExists(substr($row['uid_shared_with'], $pos + 1))) {
- $shareType = OCP\Share::SHARE_TYPE_GROUP;
- $shareWith = substr($row['uid_shared_with'], 0, $pos);
- if (isset($groupShares[$shareWith][$itemSource])) {
- continue;
- } else {
- $groupShares[$shareWith][$itemSource] = true;
- }
- } else if ($row['uid_shared_with'] == 'public') {
- $shareType = OCP\Share::SHARE_TYPE_LINK;
- $shareWith = null;
- } else {
- $shareType = OCP\Share::SHARE_TYPE_USER;
- $shareWith = $row['uid_shared_with'];
- }
- OCP\JSON::checkUserExists($row['uid_owner']);
- OC_User::setUserId($row['uid_owner']);
- //we need to setup the filesystem for the user, otherwise OC_FileSystem::getRoot will fail and break
- OC_Util::setupFS($row['uid_owner']);
- try {
- OCP\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions);
- }
- catch (Exception $e) {
- $update_error = true;
- OCP\Util::writeLog('files_sharing',
- 'Upgrade Routine: Skipping sharing "'.$row['source'].'" to "'.$shareWith
- .'" (error is "'.$e->getMessage().'")',
- OCP\Util::WARN);
- }
- OC_Util::tearDownFS();
+ //collect all user shares
+ if ($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')) {
+ //collect all group sharesX
+ $users = array_merge($users, \OC_group::usersInGroup($row['share_with']));
+ $shares[$row['id']] = $row['file_target'];
+ } else if ($row['share_type'] === "2") {
+ $shares[$row['id']] = $row['file_target'];
}
}
- OC_User::setUserId(null);
- if ($update_error) {
- OCP\Util::writeLog('files_sharing', 'There were some problems upgrading the sharing of files', OCP\Util::ERROR);
+
+ $unique_users = array_unique($users);
+
+ if (!empty($unique_users) && !empty($shares)) {
+
+ // 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');
+ }
+ }
+
+ $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 . ')';
+
+ $query = OCP\DB::prepare($statement);
+ $query->execute(array());
}
- // NOTE: Let's drop the table after more testing
-// $query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`');
-// $query->execute();
+
}
// clean up oc_share table from files which are no longer exists