summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-05-12 09:48:53 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-12 09:48:53 +0200
commitd5dee805806c1af5774040e3a1f40e7d1914758e (patch)
tree4d4a7da9dead751f52c3cb92927bbdf52a0ef7e3 /apps/files_trashbin/lib
parent56f4c4bed98eef9e422e7283e9c77cce15c312fd (diff)
downloadnextcloud-server-d5dee805806c1af5774040e3a1f40e7d1914758e.tar.gz
nextcloud-server-d5dee805806c1af5774040e3a1f40e7d1914758e.zip
Move files_trashbin to PSR-4 (#24570)
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r--apps/files_trashbin/lib/AppInfo/Application.php48
-rw-r--r--apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php (renamed from apps/files_trashbin/lib/backgroundjob/expiretrash.php)0
-rw-r--r--apps/files_trashbin/lib/Capabilities.php (renamed from apps/files_trashbin/lib/capabilities.php)0
-rw-r--r--apps/files_trashbin/lib/Command/CleanUp.php119
-rw-r--r--apps/files_trashbin/lib/Command/Expire.php59
-rw-r--r--apps/files_trashbin/lib/Exceptions/CopyRecursiveException.php (renamed from apps/files_trashbin/lib/exceptions/copyrecursiveexception.php)0
-rw-r--r--apps/files_trashbin/lib/Expiration.php (renamed from apps/files_trashbin/lib/expiration.php)0
-rw-r--r--apps/files_trashbin/lib/Helper.php (renamed from apps/files_trashbin/lib/helper.php)0
-rw-r--r--apps/files_trashbin/lib/Hooks.php (renamed from apps/files_trashbin/lib/hooks.php)0
-rw-r--r--apps/files_trashbin/lib/Storage.php (renamed from apps/files_trashbin/lib/storage.php)0
-rw-r--r--apps/files_trashbin/lib/Trashbin.php (renamed from apps/files_trashbin/lib/trashbin.php)0
11 files changed, 226 insertions, 0 deletions
diff --git a/apps/files_trashbin/lib/AppInfo/Application.php b/apps/files_trashbin/lib/AppInfo/Application.php
new file mode 100644
index 00000000000..841c9d90f1b
--- /dev/null
+++ b/apps/files_trashbin/lib/AppInfo/Application.php
@@ -0,0 +1,48 @@
+<?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_Trashbin\AppInfo;
+
+use OCP\AppFramework\App;
+use OCA\Files_Trashbin\Expiration;
+
+class Application extends App {
+ public function __construct (array $urlParams = []) {
+ parent::__construct('files_trashbin', $urlParams);
+
+ $container = $this->getContainer();
+ /*
+ * Register capabilities
+ */
+ $container->registerCapability('OCA\Files_Trashbin\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_trashbin/lib/backgroundjob/expiretrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
index 8a4e2d41fec..8a4e2d41fec 100644
--- a/apps/files_trashbin/lib/backgroundjob/expiretrash.php
+++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
diff --git a/apps/files_trashbin/lib/capabilities.php b/apps/files_trashbin/lib/Capabilities.php
index 43daa8cfa47..43daa8cfa47 100644
--- a/apps/files_trashbin/lib/capabilities.php
+++ b/apps/files_trashbin/lib/Capabilities.php
diff --git a/apps/files_trashbin/lib/Command/CleanUp.php b/apps/files_trashbin/lib/Command/CleanUp.php
new file mode 100644
index 00000000000..cffe7f7d1dd
--- /dev/null
+++ b/apps/files_trashbin/lib/Command/CleanUp.php
@@ -0,0 +1,119 @@
+<?php
+/**
+ * @author Björn Schießle <schiessle@owncloud.com>
+ * @author Joas Schilling <nickvergessen@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_Trashbin\Command;
+
+use OCP\Files\IRootFolder;
+use OCP\IDBConnection;
+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;
+
+ /** @var \OCP\IDBConnection */
+ protected $dbConnection;
+
+ /**
+ * @param IRootFolder $rootFolder
+ * @param IUserManager $userManager
+ * @param IDBConnection $dbConnection
+ */
+ function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection) {
+ parent::__construct();
+ $this->userManager = $userManager;
+ $this->rootFolder = $rootFolder;
+ $this->dbConnection = $dbConnection;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('trashbin:cleanup')
+ ->setDescription('Remove deleted files')
+ ->addArgument(
+ 'user_id',
+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
+ 'remove deleted files of the given user(s), if no user is given all deleted files will be removed'
+ );
+ }
+
+ 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("Remove deleted files of <info>$user</info>");
+ $this->removeDeletedFiles($user);
+ } else {
+ $output->writeln("<error>Unknown user $user</error>");
+ }
+ }
+ } else {
+ $output->writeln('Remove all deleted files');
+ foreach ($this->userManager->getBackends() as $backend) {
+ $name = get_class($backend);
+ if ($backend instanceof IUserBackend) {
+ $name = $backend->getBackendName();
+ }
+ $output->writeln("Remove deleted files 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->removeDeletedFiles($user);
+ }
+ $offset += $limit;
+ } while (count($users) >= $limit);
+ }
+ }
+ }
+
+ /**
+ * remove deleted files for the given user
+ *
+ * @param string $uid
+ */
+ protected function removeDeletedFiles($uid) {
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($uid);
+ if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) {
+ $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete();
+ $query = $this->dbConnection->getQueryBuilder();
+ $query->delete('files_trash')
+ ->where($query->expr()->eq('user', $query->createParameter('uid')))
+ ->setParameter('uid', $uid);
+ $query->execute();
+ }
+ }
+
+}
diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php
new file mode 100644
index 00000000000..9e0f58e12ce
--- /dev/null
+++ b/apps/files_trashbin/lib/Command/Expire.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Vincent Petry <pvince81@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_Trashbin\Command;
+
+use OC\Command\FileAccess;
+use OCA\Files_Trashbin\Trashbin;
+use OCP\Command\ICommand;
+
+class Expire implements ICommand {
+ use FileAccess;
+
+ /**
+ * @var string
+ */
+ private $user;
+
+ /**
+ * @param string $user
+ */
+ function __construct($user) {
+ $this->user = $user;
+ }
+
+ public function handle() {
+ $userManager = \OC::$server->getUserManager();
+ if (!$userManager->userExists($this->user)) {
+ // User has been deleted already
+ return;
+ }
+
+ \OC_Util::tearDownFS();
+ \OC_Util::setupFS($this->user);
+ Trashbin::expire($this->user);
+ \OC_Util::tearDownFS();
+ }
+}
diff --git a/apps/files_trashbin/lib/exceptions/copyrecursiveexception.php b/apps/files_trashbin/lib/Exceptions/CopyRecursiveException.php
index 8ebc8dfbfe1..8ebc8dfbfe1 100644
--- a/apps/files_trashbin/lib/exceptions/copyrecursiveexception.php
+++ b/apps/files_trashbin/lib/Exceptions/CopyRecursiveException.php
diff --git a/apps/files_trashbin/lib/expiration.php b/apps/files_trashbin/lib/Expiration.php
index e5a37b88b49..e5a37b88b49 100644
--- a/apps/files_trashbin/lib/expiration.php
+++ b/apps/files_trashbin/lib/Expiration.php
diff --git a/apps/files_trashbin/lib/helper.php b/apps/files_trashbin/lib/Helper.php
index 815522a909e..815522a909e 100644
--- a/apps/files_trashbin/lib/helper.php
+++ b/apps/files_trashbin/lib/Helper.php
diff --git a/apps/files_trashbin/lib/hooks.php b/apps/files_trashbin/lib/Hooks.php
index 89063bcb33e..89063bcb33e 100644
--- a/apps/files_trashbin/lib/hooks.php
+++ b/apps/files_trashbin/lib/Hooks.php
diff --git a/apps/files_trashbin/lib/storage.php b/apps/files_trashbin/lib/Storage.php
index c4c523810ac..c4c523810ac 100644
--- a/apps/files_trashbin/lib/storage.php
+++ b/apps/files_trashbin/lib/Storage.php
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index 52692950a65..52692950a65 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php