diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-04-09 00:18:53 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-04-09 00:18:53 +0200 |
commit | 56f1ffe820383ac82c208552213848c6a8deec6d (patch) | |
tree | 1c039368ddc962348f595755962d65afd27cd394 /apps/files_sharing/lib/deleteorphanedsharesjob.php | |
parent | 9c76d068c3f0c57f667359ac65a296e72db721c2 (diff) | |
parent | 4acf6747d285bd4a15717c2c6a73c5a308134131 (diff) | |
download | nextcloud-server-56f1ffe820383ac82c208552213848c6a8deec6d.tar.gz nextcloud-server-56f1ffe820383ac82c208552213848c6a8deec6d.zip |
Merge pull request #14676 from owncloud/deleteorphanedshares
Delete orphaned shares in a background job
Diffstat (limited to 'apps/files_sharing/lib/deleteorphanedsharesjob.php')
-rw-r--r-- | apps/files_sharing/lib/deleteorphanedsharesjob.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/deleteorphanedsharesjob.php b/apps/files_sharing/lib/deleteorphanedsharesjob.php new file mode 100644 index 00000000000..f39078b778f --- /dev/null +++ b/apps/files_sharing/lib/deleteorphanedsharesjob.php @@ -0,0 +1,59 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Vincent Petry <pvince81@owncloud.com> + * + * @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_sharing\Lib; + +use Doctrine\DBAL\Platforms\SqlitePlatform; +use OCP\IDBConnection; +use OC\BackgroundJob\TimedJob; + +/** + * Delete all share entries that have no matching entries in the file cache table. + */ +class DeleteOrphanedSharesJob extends TimedJob { + + /** + * Default interval in minutes + * + * @var int $defaultIntervalMin + **/ + protected $defaultIntervalMin = 15; + + /** + * Makes the background job do its work + * + * @param array $argument unused argument + */ + public function run($argument) { + $connection = \OC::$server->getDatabaseConnection(); + $logger = \OC::$server->getLogger(); + + $sql = + 'DELETE FROM `*PREFIX*share` ' . + 'WHERE `item_type` in (\'file\', \'folder\') ' . + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; + + $deletedEntries = $connection->executeUpdate($sql); + $logger->info("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); + } + +} |