1<?php 2 3declare(strict_types=1); 4/** 5 * @copyright Copyright (c) 2020 Daniel Rudolf <nextcloud.com@daniel-rudolf.de> 6 * 7 * @author Daniel Rudolf <nextcloud.com@daniel-rudolf.de> 8 * 9 * @license GNU AGPL version 3 or any later version 10 * 11 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Affero General Public License as 13 * published by the Free Software Foundation, either version 3 of the 14 * License, or (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Affero General Public License for more details. 20 * 21 * You should have received a copy of the GNU Affero General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. 23 * 24 */ 25 26namespace OCA\Talk\Command\Room; 27 28use OC\Core\Command\Base; 29use OCA\Talk\Exceptions\RoomNotFoundException; 30use OCA\Talk\Room; 31use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; 32use Symfony\Component\Console\Input\InputArgument; 33use Symfony\Component\Console\Input\InputInterface; 34use Symfony\Component\Console\Output\OutputInterface; 35 36class Delete extends Base { 37 use TRoomCommand; 38 39 protected function configure(): void { 40 $this 41 ->setName('talk:room:delete') 42 ->setDescription('Deletes a room') 43 ->addArgument( 44 'token', 45 InputArgument::REQUIRED, 46 'Token of the room to delete' 47 ); 48 } 49 50 protected function execute(InputInterface $input, OutputInterface $output): int { 51 $token = $input->getArgument('token'); 52 53 try { 54 $room = $this->manager->getRoomByToken($token); 55 } catch (RoomNotFoundException $e) { 56 $output->writeln('<error>Room not found.</error>'); 57 return 1; 58 } 59 60 if (!in_array($room->getType(), [Room::TYPE_GROUP, Room::TYPE_PUBLIC], true)) { 61 $output->writeln('<error>Room is no group call.</error>'); 62 return 1; 63 } 64 65 $room->deleteRoom(); 66 67 $output->writeln('<info>Room successfully deleted.</info>'); 68 return 0; 69 } 70 71 public function completeArgumentValues($argumentName, CompletionContext $context) { 72 switch ($argumentName) { 73 case 'token': 74 return $this->completeTokenValues($context); 75 } 76 77 return parent::completeArgumentValues($argumentName, $context); 78 } 79} 80