summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_versions/command/expire.php48
-rw-r--r--apps/files_versions/lib/storage.php27
2 files changed, 70 insertions, 5 deletions
diff --git a/apps/files_versions/command/expire.php b/apps/files_versions/command/expire.php
new file mode 100644
index 00000000000..1036741c791
--- /dev/null
+++ b/apps/files_versions/command/expire.php
@@ -0,0 +1,48 @@
+<?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);
+ }
+}
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index 60a4c463fd5..40f6ad7e77d 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -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::expire($filename, $versionsSize, $neededSpace);
+ self::scheduleExpire($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::expire($newpath);
+ self::scheduleExpire($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::expire($file);
+ Storage::scheduleExpire($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
*/
- private static function expire($filename, $versionsSize = null, $offset = 0) {
+ public 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);