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
2436d019
Commit
2436d019
authored
12 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
calculate trashbin size per user
parent
c24ec867
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_trashbin/appinfo/database.xml
+26
-0
26 additions, 0 deletions
apps/files_trashbin/appinfo/database.xml
apps/files_trashbin/appinfo/version
+1
-1
1 addition, 1 deletion
apps/files_trashbin/appinfo/version
apps/files_trashbin/lib/trash.php
+44
-8
44 additions, 8 deletions
apps/files_trashbin/lib/trash.php
with
71 additions
and
9 deletions
apps/files_trashbin/appinfo/database.xml
+
26
−
0
View file @
2436d019
...
@@ -89,4 +89,30 @@
...
@@ -89,4 +89,30 @@
</table>
</table>
<table>
<name>
*dbprefix*files_trashsize
</name>
<declaration>
<field>
<name>
user
</name>
<type>
text
</type>
<default></default>
<notnull>
true
</notnull>
<length>
50
</length>
</field>
<field>
<name>
size
</name>
<type>
text
</type>
<default></default>
<notnull>
true
</notnull>
<length>
50
</length>
</field>
</declaration>
</table>
</database>
</database>
This diff is collapsed.
Click to expand it.
apps/files_trashbin/appinfo/version
+
1
−
1
View file @
2436d019
0.
1
0.
3
This diff is collapsed.
Click to expand it.
apps/files_trashbin/lib/trash.php
+
44
−
8
View file @
2436d019
...
@@ -53,7 +53,8 @@ class Trashbin {
...
@@ -53,7 +53,8 @@ class Trashbin {
$type
=
'file'
;
$type
=
'file'
;
}
}
if
(
(
$trashbinSize
=
\OCP\Config
::
getAppValue
(
'files_trashbin'
,
'size'
))
===
null
)
{
$trashbinSize
=
self
::
getTrashbinSize
(
$user
);
if
(
$trashbinSize
===
false
||
$trashbinSize
<
0
)
{
$trashbinSize
=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/files_trashbin'
));
$trashbinSize
=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/files_trashbin'
));
$trashbinSize
+=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/versions_trashbin'
));
$trashbinSize
+=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/versions_trashbin'
));
}
}
...
@@ -89,7 +90,7 @@ class Trashbin {
...
@@ -89,7 +90,7 @@ class Trashbin {
$quota
=
\OCP\Util
::
computerFileSize
(
\OC_Appconfig
::
getValue
(
'files'
,
'default_quota'
));
$quota
=
\OCP\Util
::
computerFileSize
(
\OC_Appconfig
::
getValue
(
'files'
,
'default_quota'
));
}
}
if
(
$quota
==
null
)
{
if
(
$quota
==
null
)
{
$quota
=
\OC\Files\Filesystem
::
free_space
(
'/'
);
$quota
=
\OC\Files\Filesystem
::
free_space
(
'/'
)
/
count
(
\OCP\User
::
getUsers
())
;
}
}
// calculate available space for trash bin
// calculate available space for trash bin
...
@@ -102,7 +103,8 @@ class Trashbin {
...
@@ -102,7 +103,8 @@ class Trashbin {
}
}
$trashbinSize
-=
self
::
expire
(
$availableSpace
);
$trashbinSize
-=
self
::
expire
(
$availableSpace
);
\OCP\Config
::
setAppValue
(
'files_trashbin'
,
'size'
,
$trashbinSize
);
self
::
setTrashbinSize
(
$user
,
$trashbinSize
);
}
}
...
@@ -116,7 +118,8 @@ class Trashbin {
...
@@ -116,7 +118,8 @@ class Trashbin {
$user
=
\OCP\User
::
getUser
();
$user
=
\OCP\User
::
getUser
();
$view
=
new
\OC_FilesystemView
(
'/'
.
$user
);
$view
=
new
\OC_FilesystemView
(
'/'
.
$user
);
if
(
(
$trashbinSize
=
\OCP\Config
::
getAppValue
(
'files_trashbin'
,
'size'
))
===
null
)
{
$trashbinSize
=
self
::
getTrashbinSize
(
$user
);
if
(
$trashbinSize
===
false
||
$trashbinSize
<
0
)
{
$trashbinSize
=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/files_trashbin'
));
$trashbinSize
=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/files_trashbin'
));
$trashbinSize
+=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/versions_trashbin'
));
$trashbinSize
+=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/versions_trashbin'
));
}
}
...
@@ -185,7 +188,8 @@ class Trashbin {
...
@@ -185,7 +188,8 @@ class Trashbin {
$query
->
execute
(
array
(
$user
,
$filename
,
$timestamp
));
$query
->
execute
(
array
(
$user
,
$filename
,
$timestamp
));
}
}
\OCP\Config
::
setAppValue
(
'files_trashbin'
,
'size'
,
$trashbinSize
);
self
::
setTrashbinSize
(
$user
,
$trashbinSize
);
return
true
;
return
true
;
}
else
{
}
else
{
\OC_Log
::
write
(
'files_trashbin'
,
'Couldn\'t restore file from trash bin, '
.
$filename
,
\OC_log
::
ERROR
);
\OC_Log
::
write
(
'files_trashbin'
,
'Couldn\'t restore file from trash bin, '
.
$filename
,
\OC_log
::
ERROR
);
...
@@ -205,7 +209,8 @@ class Trashbin {
...
@@ -205,7 +209,8 @@ class Trashbin {
$view
=
new
\OC_FilesystemView
(
'/'
.
$user
);
$view
=
new
\OC_FilesystemView
(
'/'
.
$user
);
$size
=
0
;
$size
=
0
;
if
(
(
$trashbinSize
=
\OCP\Config
::
getAppValue
(
'files_trashbin'
,
'size'
))
===
null
)
{
$trashbinSize
=
self
::
getTrashbinSize
(
$user
);
if
(
$trashbinSize
===
false
||
$trashbinSize
<
0
)
{
$trashbinSize
=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/files_trashbin'
));
$trashbinSize
=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/files_trashbin'
));
$trashbinSize
+=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/versions_trashbin'
));
$trashbinSize
+=
self
::
calculateSize
(
new
\OC_FilesystemView
(
'/'
.
$user
.
'/versions_trashbin'
));
}
}
...
@@ -242,7 +247,7 @@ class Trashbin {
...
@@ -242,7 +247,7 @@ class Trashbin {
}
}
$view
->
unlink
(
'/files_trashbin/'
.
$file
);
$view
->
unlink
(
'/files_trashbin/'
.
$file
);
$trashbinSize
-=
$size
;
$trashbinSize
-=
$size
;
\OCP\Config
::
setAppValue
(
'files_trashbin'
,
'size'
,
$trashbinSize
);
self
::
setTrashbinSize
(
$user
,
$trashbinSize
);
return
$size
;
return
$size
;
}
}
...
@@ -430,4 +435,35 @@ class Trashbin {
...
@@ -430,4 +435,35 @@ class Trashbin {
return
$size
;
return
$size
;
}
}
/**
* get current size of trash bin from a given user
*
* @param $user user who owns the trash bin
* @return mixed trash bin size or false if no trash bin size is stored
*/
private
static
function
getTrashbinSize
(
$user
)
{
$query
=
\OC_DB
::
prepare
(
'SELECT size FROM *PREFIX*files_trashsize WHERE user=?'
);
$result
=
$query
->
execute
(
array
(
$user
))
->
fetchAll
();
if
(
$result
)
{
return
$result
[
0
][
'size'
];
}
return
false
;
}
/**
* write to the database how much space is in use for the trash bin
*
* @param $user owner of the trash bin
* @param $size size of the trash bin
*/
private
static
function
setTrashbinSize
(
$user
,
$size
)
{
if
(
self
::
getTrashbinSize
(
$user
)
===
false
)
{
$query
=
\OC_DB
::
prepare
(
'INSERT INTO *PREFIX*files_trashsize (size, user) VALUES (?, ?)'
);
}
else
{
$query
=
\OC_DB
::
prepare
(
'UPDATE *PREFIX*files_trashsize SET size=? WHERE user=?'
);
}
$query
->
execute
(
array
(
$size
,
$user
));
}
}
}
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