|
12 | 12 | namespace OCA\FilesLock\Command; |
13 | 13 |
|
14 | 14 | use OC\Core\Command\Base; |
| 15 | +use OC\DB\Connection; |
| 16 | +use OC\DB\SchemaWrapper; |
15 | 17 | use OC\User\NoUserException; |
16 | 18 | use OCA\FilesLock\Db\LocksRequest; |
17 | 19 | use OCA\FilesLock\Exceptions\LockNotFoundException; |
|
26 | 28 | use OCP\Files\Lock\ILock; |
27 | 29 | use OCP\Files\Lock\LockContext; |
28 | 30 | use OCP\Files\NotFoundException; |
| 31 | +use OCP\IDBConnection; |
29 | 32 | use OCP\IUserManager; |
30 | 33 | use Symfony\Component\Console\Exception\InvalidArgumentException; |
31 | 34 | use Symfony\Component\Console\Input\InputArgument; |
|
35 | 38 | use Symfony\Component\Console\Question\ConfirmationQuestion; |
36 | 39 |
|
37 | 40 | class Lock extends Base { |
38 | | - /** @var IUserManager */ |
39 | | - private $userManager; |
40 | | - |
41 | | - /** @var LocksRequest */ |
42 | | - private $locksRequest; |
43 | | - |
44 | | - /** @var FileService */ |
45 | | - private $fileService; |
46 | | - |
47 | | - /** @var LockService */ |
48 | | - private $lockService; |
49 | | - |
50 | | - /** @var ConfigService */ |
51 | | - private $configService; |
52 | | - |
53 | | - |
54 | | - /** |
55 | | - * CacheUpdate constructor. |
56 | | - * |
57 | | - * @param IUserManager $userManager |
58 | | - * @param FileService $fileService |
59 | | - * @param LockService $lockService |
60 | | - * @param LocksRequest $locksRequest |
61 | | - * @param ConfigService $configService |
62 | | - */ |
63 | 41 | public function __construct( |
64 | | - IUserManager $userManager, LocksRequest $locksRequest, FileService $fileService, |
65 | | - LockService $lockService, ConfigService $configService, |
| 42 | + private IUserManager $userManager, |
| 43 | + private LocksRequest $locksRequest, |
| 44 | + private FileService $fileService, |
| 45 | + private LockService $lockService, |
| 46 | + private ConfigService $configService, |
| 47 | + private IDBConnection $connection, |
66 | 48 | ) { |
67 | 49 | parent::__construct(); |
68 | | - |
69 | | - $this->userManager = $userManager; |
70 | | - $this->locksRequest = $locksRequest; |
71 | | - $this->fileService = $fileService; |
72 | | - $this->lockService = $lockService; |
73 | | - $this->configService = $configService; |
74 | 50 | } |
75 | 51 |
|
76 | | - |
77 | | - /** |
78 | | - * |
79 | | - */ |
80 | 52 | protected function configure() { |
81 | 53 | parent::configure(); |
82 | 54 | $this->setName('files:lock') |
@@ -241,4 +213,42 @@ private function uninstallApp(InputInterface $input, OutputInterface $output) { |
241 | 213 |
|
242 | 214 | throw new SuccessException(); |
243 | 215 | } |
| 216 | + |
| 217 | + |
| 218 | + /** |
| 219 | + * |
| 220 | + */ |
| 221 | + public function uninstall(): void { |
| 222 | + $this->uninstallAppTables(); |
| 223 | + $this->removeFromJobs(); |
| 224 | + $this->removeFromMigrations(); |
| 225 | + } |
| 226 | + |
| 227 | + public function uninstallAppTables() { |
| 228 | + $dbConn = \OCP\Server::get(Connection::class); |
| 229 | + $schema = new SchemaWrapper($dbConn); |
| 230 | + |
| 231 | + foreach (array_keys(self::$tables) as $table) { |
| 232 | + if ($schema->hasTable($table)) { |
| 233 | + $schema->dropTable($table); |
| 234 | + } |
| 235 | + } |
| 236 | + |
| 237 | + $schema->performDropTableCalls(); |
| 238 | + } |
| 239 | + |
| 240 | + public function removeFromMigrations() { |
| 241 | + $qb = $this->connection->getQueryBuilder(); |
| 242 | + $qb->delete('migrations'); |
| 243 | + $qb->where($qb->expr()->eq('app', 'files_lock')); |
| 244 | + |
| 245 | + $qb->executeStatement(); |
| 246 | + } |
| 247 | + |
| 248 | + public function removeFromJobs() { |
| 249 | + $qb = $this->connection->getQueryBuilder(); |
| 250 | + $qb->delete('jobs'); |
| 251 | + $qb->where($qb->expr()->eq('class', 'OCA\FilesLock\Cron\Unlock')); |
| 252 | + $qb->executeStatement(); |
| 253 | + } |
244 | 254 | } |
0 commit comments