Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-03-09 17:13:32 +0300
committerJoas Schilling <coding@schilljs.com>2018-03-09 17:13:32 +0300
commit49942460ffc60f1233b27e937be827d9a08a3cef (patch)
treefb434f14cbf7082d44201662d4d5ac4f4a3999fe /lib/BackgroundJob
parentd1237a4ba046f7953a6016956794bd7cdc80714b (diff)
Add a background job to delete empty rooms
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/BackgroundJob')
-rw-r--r--lib/BackgroundJob/RemoveEmptyRooms.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/BackgroundJob/RemoveEmptyRooms.php b/lib/BackgroundJob/RemoveEmptyRooms.php
new file mode 100644
index 000000000..b5af43ad6
--- /dev/null
+++ b/lib/BackgroundJob/RemoveEmptyRooms.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Spreed\BackgroundJob;
+
+use OC\BackgroundJob\TimedJob;
+use OCA\Spreed\Manager;
+use OCA\Spreed\Room;
+use OCP\ILogger;
+
+/**
+ * Class RemoveEmptyRooms
+ *
+ * @package OCA\Spreed\BackgroundJob
+ */
+class RemoveEmptyRooms extends TimedJob {
+
+ /** @var Manager */
+ protected $manager;
+
+ /** @var ILogger */
+ protected $logger;
+
+ public function __construct(Manager $manager, ILogger $logger) {
+ // Every 5 minutes
+ $this->setInterval(60 * 5);
+
+ $this->manager = $manager;
+ $this->logger = $logger;
+ }
+
+ protected function run($argument) {
+ $numDeletedRooms = 0;
+ $this->manager->forAllRooms(function(Room $room) use (&$numDeletedRooms) {
+ if ($room->getType() === Room::ONE_TO_ONE_CALL && $room->getNumberOfParticipants(false) <= 1) {
+ $room->deleteRoom();
+ $numDeletedRooms++;
+ } else if ($room->getNumberOfParticipants(false) === 0) {
+ $room->deleteRoom();
+ $numDeletedRooms++;
+ }
+ });
+
+ if ($numDeletedRooms) {
+ $this->logger->info('Deleted {numDeletedRooms} rooms because they were empty', [
+ 'numDeletedRooms' => $numDeletedRooms,
+ 'app' => 'spreed',
+ ]);
+ }
+ }
+}