nextcloud/apps/files_sharing/appinfo/update.php

62 lines
2.1 KiB
PHP
Raw Normal View History

2012-07-13 17:17:36 +04:00
<?php
$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
if (version_compare($installedVersion, '0.4', '<')) {
$query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $query->execute();
$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'));
//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')) {
$users[] = $row['share_with'];
$shares[$row['id']] = $row['file_target'];
} else if ($row['share_type'] === "1" && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
2014-04-15 22:26:04 +04:00
//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") {
$shares[$row['id']] = $row['file_target'];
2012-08-29 10:42:49 +04:00
}
2012-07-13 17:17:36 +04:00
}
$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);
2014-04-15 22:26:04 +04:00
$query->execute(array());
2014-04-15 22:26:04 +04:00
}
}
// 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();
2012-10-27 01:05:02 +04:00
}