Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix update to remove shares where file doesn't exist on postgres #6016

Closed
17 changes: 3 additions & 14 deletions apps/files_sharing/appinfo/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,7 @@

// clean up oc_share table from files which are no longer exists
if (version_compare($installedVersion, '0.3.5', '<')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to increase the version number to 0.3.5.6 here and in apps/files_sharing/appinfo/version to make sure that the fixed update gets executed


// get all shares where the original file no longer exists
$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 AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\')');
$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)));
}
// delete all shares where the original file no longer exists
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (SELECT `file_source` FROM `*PREFIX*share` LEFT JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `*PREFIX*filecache`.`fileid` IS NULL AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\'))');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delete query should be using the primary key, i.e. id.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is way too long. Even too long to do a proper review.

$result = $removeShares->execute();
}