summaryrefslogtreecommitdiffstats
path: root/apps/files/command
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-04-07 11:44:34 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-04-08 10:23:56 +0200
commitcefdcea02171672d6340d9db57a54ffac78c5ab8 (patch)
treef02fdc5b93cf0ec398d10da8136291933f4bf1e1 /apps/files/command
parent1fbf5d86df7ba4001ca826d9dfb8fad073924fde (diff)
downloadnextcloud-server-cefdcea02171672d6340d9db57a54ffac78c5ab8.tar.gz
nextcloud-server-cefdcea02171672d6340d9db57a54ffac78c5ab8.zip
[command] delete orphaned file cache entries
* ./occ files:cleanup * delete file cache entries without an existing storage
Diffstat (limited to 'apps/files/command')
-rw-r--r--apps/files/command/deleteorphanedfiles.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/apps/files/command/deleteorphanedfiles.php b/apps/files/command/deleteorphanedfiles.php
new file mode 100644
index 00000000000..0dc9c29f4f7
--- /dev/null
+++ b/apps/files/command/deleteorphanedfiles.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2015, 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\Command;
+
+use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
+use Doctrine\DBAL\Platforms\SqlitePlatform;
+use OCP\IDBConnection;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Delete all file entries that have no matching entries in the storage table.
+ */
+class DeleteOrphanedFiles extends Command {
+
+ /**
+ * @var IDBConnection
+ */
+ protected $connection;
+
+ public function __construct(IDBConnection $connection) {
+ $this->connection = $connection;
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('files:cleanup')
+ ->setDescription('cleanup filecache');
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output) {
+
+ $sql =
+ 'DELETE FROM `*PREFIX*filecache` ' .
+ 'WHERE NOT EXISTS ' .
+ '(SELECT 1 FROM `*PREFIX*storages` WHERE `storage` = `numeric_id`)';
+
+ $deletedEntries = $this->connection->executeUpdate($sql);
+ $output->writeln("$deletedEntries orphaned file cache entries deleted");
+ }
+
+}