aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions/lib')
-rw-r--r--apps/files_versions/lib/AppInfo/Application.php49
-rw-r--r--apps/files_versions/lib/BackgroundJob/ExpireVersions.php (renamed from apps/files_versions/lib/backgroundjob/expireversions.php)0
-rw-r--r--apps/files_versions/lib/Capabilities.php (renamed from apps/files_versions/lib/capabilities.php)0
-rw-r--r--apps/files_versions/lib/Command/CleanUp.php114
-rw-r--r--apps/files_versions/lib/Command/Expire.php64
-rw-r--r--apps/files_versions/lib/Expiration.php (renamed from apps/files_versions/lib/expiration.php)0
-rw-r--r--apps/files_versions/lib/Hooks.php (renamed from apps/files_versions/lib/hooks.php)0
-rw-r--r--apps/files_versions/lib/Storage.php (renamed from apps/files_versions/lib/storage.php)0
8 files changed, 227 insertions, 0 deletions
diff --git a/apps/files_versions/lib/AppInfo/Application.php b/apps/files_versions/lib/AppInfo/Application.php
new file mode 100644
index 00000000000..b32cf54729d
--- /dev/null
+++ b/apps/files_versions/lib/AppInfo/Application.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ * @author Victor Dubiniuk <dubiniuk@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_Versions\AppInfo;
+
+use OCP\AppFramework\App;
+use OCA\Files_Versions\Expiration;
+
+class Application extends App {
+ public function __construct(array $urlParams = array()) {
+ parent::__construct('files_versions', $urlParams);
+
+ $container = $this->getContainer();
+
+ /*
+ * Register capabilities
+ */
+ $container->registerCapability('OCA\Files_Versions\Capabilities');
+
+ /*
+ * Register expiration
+ */
+ $container->registerService('Expiration', function($c) {
+ return new Expiration(
+ $c->query('ServerContainer')->getConfig(),
+ $c->query('OCP\AppFramework\Utility\ITimeFactory')
+ );
+ });
+ }
+}
diff --git a/apps/files_versions/lib/backgroundjob/expireversions.php b/apps/files_versions/lib/BackgroundJob/ExpireVersions.php
index 8e14e65b9a7..8e14e65b9a7 100644
--- a/apps/files_versions/lib/backgroundjob/expireversions.php
+++ b/apps/files_versions/lib/BackgroundJob/ExpireVersions.php
diff --git a/apps/files_versions/lib/capabilities.php b/apps/files_versions/lib/Capabilities.php
index 441b2adfba3..441b2adfba3 100644
--- a/apps/files_versions/lib/capabilities.php
+++ b/apps/files_versions/lib/Capabilities.php
diff --git a/apps/files_versions/lib/Command/CleanUp.php b/apps/files_versions/lib/Command/CleanUp.php
new file mode 100644
index 00000000000..1abf62763b1
--- /dev/null
+++ b/apps/files_versions/lib/Command/CleanUp.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * @author Björn Schießle <schiessle@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_Versions\Command;
+
+
+use OCP\Files\IRootFolder;
+use OCP\IUserBackend;
+use OCP\IUserManager;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class CleanUp extends Command {
+
+ /** @var IUserManager */
+ protected $userManager;
+
+ /** @var IRootFolder */
+ protected $rootFolder;
+
+ /**
+ * @param IRootFolder $rootFolder
+ * @param IUserManager $userManager
+ */
+ function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
+ parent::__construct();
+ $this->userManager = $userManager;
+ $this->rootFolder = $rootFolder;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('versions:cleanup')
+ ->setDescription('Delete versions')
+ ->addArgument(
+ 'user_id',
+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
+ 'delete versions of the given user(s), if no user is given all versions will be deleted'
+ );
+ }
+
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+
+ $users = $input->getArgument('user_id');
+ if (!empty($users)) {
+ foreach ($users as $user) {
+ if ($this->userManager->userExists($user)) {
+ $output->writeln("Delete versions of <info>$user</info>");
+ $this->deleteVersions($user);
+ } else {
+ $output->writeln("<error>Unknown user $user</error>");
+ }
+ }
+ } else {
+ $output->writeln('Delete all versions');
+ foreach ($this->userManager->getBackends() as $backend) {
+ $name = get_class($backend);
+
+ if ($backend instanceof IUserBackend) {
+ $name = $backend->getBackendName();
+ }
+
+ $output->writeln("Delete versions for users on backend <info>$name</info>");
+
+ $limit = 500;
+ $offset = 0;
+ do {
+ $users = $backend->getUsers('', $limit, $offset);
+ foreach ($users as $user) {
+ $output->writeln(" <info>$user</info>");
+ $this->deleteVersions($user);
+ }
+ $offset += $limit;
+ } while (count($users) >= $limit);
+ }
+ }
+ }
+
+
+ /**
+ * delete versions for the given user
+ *
+ * @param string $user
+ */
+ protected function deleteVersions($user) {
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($user);
+ if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) {
+ $this->rootFolder->get('/' . $user . '/files_versions')->delete();
+ }
+ }
+
+}
diff --git a/apps/files_versions/lib/Command/Expire.php b/apps/files_versions/lib/Command/Expire.php
new file mode 100644
index 00000000000..b1f72980633
--- /dev/null
+++ b/apps/files_versions/lib/Command/Expire.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+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 string
+ */
+ private $user;
+
+ /**
+ * @param string $user
+ * @param string $fileName
+ */
+ function __construct($user, $fileName) {
+ $this->user = $user;
+ $this->fileName = $fileName;
+ }
+
+
+ public function handle() {
+ $userManager = \OC::$server->getUserManager();
+ if (!$userManager->userExists($this->user)) {
+ // User has been deleted already
+ return;
+ }
+
+ \OC_Util::setupFS($this->user);
+ Storage::expire($this->fileName);
+ \OC_Util::tearDownFS();
+ }
+}
diff --git a/apps/files_versions/lib/expiration.php b/apps/files_versions/lib/Expiration.php
index ffc7640e7f9..ffc7640e7f9 100644
--- a/apps/files_versions/lib/expiration.php
+++ b/apps/files_versions/lib/Expiration.php
diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/Hooks.php
index beaf81c7471..beaf81c7471 100644
--- a/apps/files_versions/lib/hooks.php
+++ b/apps/files_versions/lib/Hooks.php
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/Storage.php
index 3c23f2f730a..3c23f2f730a 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/Storage.php