Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
7ec8f12a
Commit
7ec8f12a
authored
10 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
expire versions in a background command
parent
39dbf950
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_versions/command/expire.php
+48
-0
48 additions, 0 deletions
apps/files_versions/command/expire.php
apps/files_versions/lib/storage.php
+22
-5
22 additions, 5 deletions
apps/files_versions/lib/storage.php
with
70 additions
and
5 deletions
apps/files_versions/command/expire.php
0 → 100644
+
48
−
0
View file @
7ec8f12a
<?php
/**
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace
OCA\Files_Versions\Command
;
use
OC\Command\FileAccess
;
use
OCA\Files_Versions
\Storage
;
use
OCP\Command\ICommand
;
class
Expire
implements
ICommand
{
use
FileAccess
;
/**
* @var string
*/
private
$fileName
;
/**
* @var int|null
*/
private
$versionsSize
;
/**
* @var int
*/
private
$neededSpace
=
0
;
/**
* @param string $fileName
* @param int|null $versionsSize
* @param int $neededSpace
*/
function
__construct
(
$fileName
,
$versionsSize
=
null
,
$neededSpace
=
0
)
{
$this
->
fileName
=
$fileName
;
$this
->
versionsSize
=
$versionsSize
;
$this
->
neededSpace
=
$neededSpace
;
}
public
function
handle
(){
Storage
::
expire
(
$this
->
fileName
,
$this
->
versionsSize
,
$this
->
neededSpace
);
}
}
This diff is collapsed.
Click to expand it.
apps/files_versions/lib/storage.php
+
22
−
5
View file @
7ec8f12a
...
...
@@ -15,6 +15,8 @@
namespace
OCA\Files_Versions
;
use
OCA\Files_Versions
\Command\Expire
;
class
Storage
{
const
DEFAULTENABLED
=
true
;
...
...
@@ -132,7 +134,7 @@ class Storage {
// 1.5 times as large as the current version -> 2.5
$neededSpace
=
$files_view
->
filesize
(
$filename
)
*
2.5
;
self
::
e
xpire
(
$filename
,
$versionsSize
,
$neededSpace
);
self
::
scheduleE
xpire
(
$filename
,
$versionsSize
,
$neededSpace
);
// disable proxy to prevent multiple fopen calls
$proxyStatus
=
\OC_FileProxy
::
$enabled
;
...
...
@@ -237,7 +239,7 @@ class Storage {
}
if
(
!
$files_view
->
is_dir
(
$newpath
))
{
self
::
e
xpire
(
$newpath
);
self
::
scheduleE
xpire
(
$newpath
);
}
}
...
...
@@ -272,7 +274,7 @@ class Storage {
// rollback
if
(
@
$users_view
->
rename
(
'files_versions'
.
$filename
.
'.v'
.
$revision
,
'files'
.
$filename
)
)
{
$files_view
->
touch
(
$file
,
$revision
);
Storage
::
e
xpire
(
$file
);
Storage
::
scheduleE
xpire
(
$file
);
return
true
;
}
else
if
(
$versionCreated
)
{
...
...
@@ -476,9 +478,24 @@ class Storage {
}
/**
* Erase a file's versions which exceed the set quota
* @param string $fileName
* @param int|null $versionsSize
* @param int $neededSpace
*/
private
static
function
scheduleExpire
(
$fileName
,
$versionsSize
=
null
,
$neededSpace
=
0
)
{
$command
=
new
Expire
(
$fileName
,
$versionsSize
,
$neededSpace
);
\OC
::
$server
->
getCommandBus
()
->
push
(
$command
);
}
/**
* Expire versions which exceed the quota
*
* @param $filename
* @param int|null $versionsSize
* @param int $offset
* @return bool|int|null
*/
p
rivate
static
function
expire
(
$filename
,
$versionsSize
=
null
,
$offset
=
0
)
{
p
ublic
static
function
expire
(
$filename
,
$versionsSize
=
null
,
$offset
=
0
)
{
$config
=
\OC
::
$server
->
getConfig
();
if
(
$config
->
getSystemValue
(
'files_versions'
,
Storage
::
DEFAULTENABLED
)
==
'true'
)
{
list
(
$uid
,
$filename
)
=
self
::
getUidAndFilename
(
$filename
);
...
...
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