Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
981608cf
Commit
981608cf
authored
11 years ago
by
Björn Schießle
Browse files
Options
Downloads
Plain Diff
Merge pull request #5129 from owncloud/remove_deleted_shares_from_db
remove deleted files from oc_share
parents
46fdb449
288f01bf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/files_sharing/appinfo/update.php
+16
-6
16 additions, 6 deletions
apps/files_sharing/appinfo/update.php
apps/files_sharing/appinfo/version
+1
-1
1 addition, 1 deletion
apps/files_sharing/appinfo/version
apps/files_sharing/lib/updater.php
+19
-0
19 additions, 0 deletions
apps/files_sharing/lib/updater.php
with
36 additions
and
7 deletions
apps/files_sharing/appinfo/update.php
+
16
−
6
View file @
981608cf
...
@@ -68,11 +68,21 @@ if (version_compare($installedVersion, '0.3', '<')) {
...
@@ -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
)));
}
}
}
}
This diff is collapsed.
Click to expand it.
apps/files_sharing/appinfo/version
+
1
−
1
View file @
981608cf
0.3.3
0.3.4
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/files_sharing/lib/updater.php
+
19
−
0
View file @
981608cf
...
@@ -57,6 +57,23 @@ class Shared_Updater {
...
@@ -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 {
...
@@ -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
*/
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment