Merge pull request #5129 from owncloud/remove_deleted_shares_from_db

remove deleted files from oc_share
This commit is contained in:
Björn Schießle 2013-10-07 02:07:11 -07:00
commit 981608cf6b
3 changed files with 36 additions and 7 deletions

View File

@ -68,11 +68,21 @@ if (version_compare($installedVersion, '0.3', '<')) {
// $query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`'); // $query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`');
// $query->execute(); // $query->execute();
} }
if (version_compare($installedVersion, '0.3.3', '<')) {
OC_User::useBackend(new OC_User_Database()); // clean up oc_share table from files which are no longer exists
OC_App::loadApps(array('authentication')); if (version_compare($installedVersion, '0.3.4', '<')) {
$users = OC_User::getUsers();
foreach ($users as $user) { // get all shares where the original file no longer exists
// OC_FileCache::delete('Shared', '/'.$user.'/files/'); $findShares = \OC_DB::prepare('SELECT `file_source` FROM `*PREFIX*share` LEFT JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `*PREFIX*filecache`.`fileid` IS NULL');
$sharesFound = $findShares->execute(array())->fetchAll();
// delete those shares from the oc_share table
if (is_array($sharesFound) && !empty($sharesFound)) {
$delArray = array();
foreach ($sharesFound as $share) {
$delArray[] = $share['file_source'];
}
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (?)');
$result = $removeShares->execute(array(implode(',', $delArray)));
} }
} }

View File

@ -1 +1 @@
0.3.3 0.3.4

View File

@ -57,6 +57,23 @@ class Shared_Updater {
} }
} }
/**
* @brief remove all shares for a given file if the file was deleted
*
* @param string $path
*/
private static function removeShare($path) {
$fileInfo = \OC\Files\Filesystem::getFileInfo($path);
$fileSource = $fileInfo['fileid'];
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source`=?');
try {
\OC_DB::executeAudited($query, array($fileSource));
} catch (\Exception $e) {
\OCP\Util::writeLog('files_sharing', "can't remove share: " . $e->getMessage(), \OCP\Util::WARN);
}
}
/** /**
* @param array $params * @param array $params
*/ */
@ -77,8 +94,10 @@ class Shared_Updater {
*/ */
static public function deleteHook($params) { static public function deleteHook($params) {
self::correctFolders($params['path']); self::correctFolders($params['path']);
self::removeShare($params['path']);
} }
/** /**
* @param array $params * @param array $params
*/ */