2012-07-13 17:17:36 +04:00
|
|
|
<?php
|
2014-04-14 17:04:27 +04:00
|
|
|
|
2012-09-10 02:29:47 +04:00
|
|
|
$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
|
2014-05-27 13:05:31 +04:00
|
|
|
|
|
|
|
if (version_compare($installedVersion, '0.5', '<')) {
|
|
|
|
updateFilePermissions();
|
|
|
|
}
|
|
|
|
|
2014-04-14 17:04:27 +04:00
|
|
|
if (version_compare($installedVersion, '0.4', '<')) {
|
2014-04-16 19:43:02 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 13:05:31 +04:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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 " . $id . " THEN " . $permission . " ";
|
|
|
|
}
|
|
|
|
$statement .= ' END WHERE `id` IN (' . $ids . ')';
|
|
|
|
|
|
|
|
$query = OCP\DB::prepare($statement);
|
|
|
|
$query->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
/**
|
|
|
|
* 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) {
|
2014-04-14 17:04:27 +04:00
|
|
|
$query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
|
2012-09-10 02:29:47 +04:00
|
|
|
$result = $query->execute();
|
2014-04-14 17:04:27 +04:00
|
|
|
$view = new \OC\Files\View('/');
|
|
|
|
$users = array();
|
|
|
|
$shares = array();
|
|
|
|
//we need to set up user backends
|
2012-09-25 13:47:45 +04:00
|
|
|
OC_User::useBackend(new OC_User_Database());
|
|
|
|
OC_Group::useBackend(new OC_Group_Database());
|
|
|
|
OC_App::loadApps(array('authentication'));
|
2014-04-14 17:04:27 +04:00
|
|
|
//we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
|
2012-09-10 02:29:47 +04:00
|
|
|
while ($row = $result->fetchRow()) {
|
2014-04-14 17:04:27 +04:00
|
|
|
//collect all user shares
|
2014-04-16 19:43:02 +04:00
|
|
|
if ((int)$row['share_type'] === 0 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
|
2014-04-14 17:04:27 +04:00
|
|
|
$users[] = $row['share_with'];
|
|
|
|
$shares[$row['id']] = $row['file_target'];
|
2014-04-16 19:43:02 +04:00
|
|
|
} else if ((int)$row['share_type'] === 1 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
|
2014-04-15 22:26:04 +04:00
|
|
|
//collect all group shares
|
2014-04-14 17:04:27 +04:00
|
|
|
$users = array_merge($users, \OC_group::usersInGroup($row['share_with']));
|
|
|
|
$shares[$row['id']] = $row['file_target'];
|
2014-04-16 19:43:02 +04:00
|
|
|
} else if ((int)$row['share_type'] === 2) {
|
2014-04-14 17:04:27 +04:00
|
|
|
$shares[$row['id']] = $row['file_target'];
|
2012-08-29 10:42:49 +04:00
|
|
|
}
|
2012-07-13 17:17:36 +04:00
|
|
|
}
|
2014-04-14 17:04:27 +04:00
|
|
|
|
|
|
|
$unique_users = array_unique($users);
|
|
|
|
|
|
|
|
if (!empty($unique_users) && !empty($shares)) {
|
|
|
|
|
|
|
|
// create folder Shared for each user
|
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
if ($mkdirs) {
|
|
|
|
foreach ($unique_users as $user) {
|
|
|
|
\OC\Files\Filesystem::initMountPoints($user);
|
|
|
|
if (!$view->file_exists('/' . $user . '/files/Shared')) {
|
|
|
|
$view->mkdir('/' . $user . '/files/Shared');
|
|
|
|
}
|
2014-04-14 17:04:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
$chunkedShareList = array_chunk($shares, $chunkSize, true);
|
2014-04-14 17:04:27 +04:00
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
foreach ($chunkedShareList as $subList) {
|
2014-04-15 22:26:04 +04:00
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
$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 . ')';
|
2014-04-15 22:26:04 +04:00
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
$query = OCP\DB::prepare($statement);
|
2014-04-14 17:04:27 +04:00
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
$query->execute(array());
|
|
|
|
}
|
2013-10-07 12:59:09 +04:00
|
|
|
|
2014-04-16 19:43:02 +04:00
|
|
|
}
|
2012-10-27 01:05:02 +04:00
|
|
|
}
|