Blame view
sources/apps/files_sharing/appinfo/update.php
3.97 KB
|
03e52840d
|
1 |
<?php |
|
6d9380f96
|
2 |
|
|
03e52840d
|
3 |
$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
|
|
6d9380f96
|
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
if (version_compare($installedVersion, '0.5', '<')) {
updateFilePermissions();
}
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();
}
/**
* it is no longer possible to share single files with delete permissions. User
* should only be able to unshare single files but never to delete them.
*/
function updateFilePermissions($chunkSize = 99) {
$query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `item_type` = ?');
$result = $query->execute(array('file'));
$updatedRows = array();
while ($row = $result->fetchRow()) {
if ($row['permissions'] & \OCP\PERMISSION_DELETE) {
$updatedRows[$row['id']] = (int)$row['permissions'] & ~\OCP\PERMISSION_DELETE;
}
}
$connection = \OC_DB::getConnection();
$chunkedPermissionList = array_chunk($updatedRows, $chunkSize, true);
foreach ($chunkedPermissionList as $subList) {
$statement = "UPDATE `*PREFIX*share` SET `permissions` = CASE `id` ";
//update share table
$ids = implode(',', array_keys($subList));
foreach ($subList as $id => $permission) {
$statement .= "WHEN " . $connection->quote($id, \PDO::PARAM_INT) . " THEN " . $permission . " ";
}
$statement .= ' END WHERE `id` IN (' . $ids . ')';
$query = OCP\DB::prepare($statement);
$query->execute();
}
}
/**
* 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`');
|
|
03e52840d
|
60 |
$result = $query->execute(); |
|
6d9380f96
|
61 62 63 64 |
$view = new \OC\Files\View('/');
$users = array();
$shares = array();
//we need to set up user backends
|
|
03e52840d
|
65 66 67 |
OC_User::useBackend(new OC_User_Database());
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
|
|
6d9380f96
|
68 |
//we need to set up user backends, otherwise creating the shares will fail with "because user does not exist" |
|
03e52840d
|
69 |
while ($row = $result->fetchRow()) {
|
|
6d9380f96
|
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
//collect all user shares
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 ((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 ((int)$row['share_type'] === 2) {
$shares[$row['id']] = $row['file_target'];
}
}
$unique_users = array_unique($users);
if (!empty($unique_users) && !empty($shares)) {
// create folder Shared for each user
if ($mkdirs) {
foreach ($unique_users as $user) {
\OC\Files\Filesystem::initMountPoints($user);
if (!$view->file_exists('/' . $user . '/files/Shared')) {
$view->mkdir('/' . $user . '/files/Shared');
|
|
03e52840d
|
94 |
} |
|
03e52840d
|
95 |
} |
|
03e52840d
|
96 |
} |
|
03e52840d
|
97 |
|
|
6d9380f96
|
98 99 100 101 |
$chunkedShareList = array_chunk($shares, $chunkSize, true);
$connection = \OC_DB::getConnection();
foreach ($chunkedShareList as $subList) {
|
|
03e52840d
|
102 |
|
|
6d9380f96
|
103 104 105 106 107 108 109 |
$statement = "UPDATE `*PREFIX*share` SET `file_target` = CASE `id` ";
//update share table
$ids = implode(',', array_keys($subList));
foreach ($subList as $id => $target) {
$statement .= "WHEN " . $connection->quote($id, \PDO::PARAM_INT) . " THEN " . $connection->quote('/Shared' . $target, \PDO::PARAM_STR);
}
$statement .= ' END WHERE `id` IN (' . $ids . ')';
|
|
03e52840d
|
110 |
|
|
6d9380f96
|
111 112 113 |
$query = OCP\DB::prepare($statement); $query->execute(array()); |
|
03e52840d
|
114 |
} |
|
6d9380f96
|
115 |
|
|
f7d878ff1
|
116 117 |
// set config to keep the Shared folder as the default location for new shares
\OCA\Files_Sharing\Helper::setShareFolder('/Shared');
|
|
03e52840d
|
118 119 |
} } |