-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathResetWatch.php
More file actions
60 lines (47 loc) · 1.51 KB
/
ResetWatch.php
File metadata and controls
60 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Polls\Command\Db;
use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V7\IndexManager;
use OCA\Polls\Db\V7\TableManager;
use OCA\Polls\Db\Watch;
use OCA\Polls\Migration\V7\TableSchema;
use OCP\IDBConnection;
/**
* @psalm-api
*/
class ResetWatch extends Command {
protected string $name = parent::NAME_PREFIX . 'db:reset-watch';
protected string $description = 'Resets the Watch table';
protected array $operationHints = [
'Removes and recreates the watch table to set ids to zero',
];
public function __construct(
private IndexManager $indexManager,
private TableManager $tableManager,
private IDBConnection $connection,
private Schema $schema,
) {
parent::__construct();
}
protected function runCommands(): int {
$tableName = Watch::TABLE;
$messages = $this->tableManager->removeWatch();
$this->printInfo($messages, ' - ');
$this->schema = $this->connection->createSchema();
$this->indexManager->setSchema($this->schema);
$this->tableManager->setSchema($this->schema);
$messages = $this->tableManager->createTable($tableName);
foreach (TableSchema::UNIQUE_INDICES[$tableName] as $name => $definition) {
$messages[] = $this->indexManager->createIndex($tableName, $name, $definition['columns'], true);
}
$this->connection->migrateToSchema($this->schema);
$this->printInfo($messages, ' - ');
return 0;
}
}