Passed
Push — master ( aeb32e...81302f )
by Christoph
15:20 queued 10s
created
core/Command/Db/AddMissingPrimaryKeys.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -45,132 +45,132 @@
 block discarded – undo
45 45
  */
46 46
 class AddMissingPrimaryKeys extends Command {
47 47
 
48
-	/** @var Connection */
49
-	private $connection;
50
-
51
-	/** @var EventDispatcherInterface */
52
-	private $dispatcher;
53
-
54
-	public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
55
-		parent::__construct();
56
-
57
-		$this->connection = $connection;
58
-		$this->dispatcher = $dispatcher;
59
-	}
60
-
61
-	protected function configure() {
62
-		$this
63
-			->setName('db:add-missing-primary-keys')
64
-			->setDescription('Add missing primary keys to the database tables');
65
-	}
66
-
67
-	protected function execute(InputInterface $input, OutputInterface $output): int {
68
-		$this->addCorePrimaryKeys($output);
69
-
70
-		// Dispatch event so apps can also update indexes if needed
71
-		$event = new GenericEvent($output);
72
-		$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_PRIMARY_KEYS_EVENT, $event);
73
-		return 0;
74
-	}
75
-
76
-	/**
77
-	 * add missing indices to the share table
78
-	 *
79
-	 * @param OutputInterface $output
80
-	 * @throws \Doctrine\DBAL\Schema\SchemaException
81
-	 */
82
-	private function addCorePrimaryKeys(OutputInterface $output) {
83
-		$output->writeln('<info>Check primary keys.</info>');
84
-
85
-		$schema = new SchemaWrapper($this->connection);
86
-		$updated = false;
87
-
88
-		if ($schema->hasTable('federated_reshares')) {
89
-			$table = $schema->getTable('federated_reshares');
90
-			if (!$table->hasPrimaryKey()) {
91
-				$output->writeln('<info>Adding primary key to the federated_reshares table, this can take some time...</info>');
92
-				$table->setPrimaryKey(['share_id'], 'federated_res_pk');
93
-				if ($table->hasIndex('share_id_index')) {
94
-					$table->dropIndex('share_id_index');
95
-				}
96
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
97
-				$updated = true;
98
-				$output->writeln('<info>federated_reshares table updated successfully.</info>');
99
-			}
100
-		}
101
-
102
-		if ($schema->hasTable('systemtag_object_mapping')) {
103
-			$table = $schema->getTable('systemtag_object_mapping');
104
-			if (!$table->hasPrimaryKey()) {
105
-				$output->writeln('<info>Adding primary key to the systemtag_object_mapping table, this can take some time...</info>');
106
-				$table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
107
-				if ($table->hasIndex('mapping')) {
108
-					$table->dropIndex('mapping');
109
-				}
110
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
111
-				$updated = true;
112
-				$output->writeln('<info>systemtag_object_mapping table updated successfully.</info>');
113
-			}
114
-		}
115
-
116
-		if ($schema->hasTable('comments_read_markers')) {
117
-			$table = $schema->getTable('comments_read_markers');
118
-			if (!$table->hasPrimaryKey()) {
119
-				$output->writeln('<info>Adding primary key to the comments_read_markers table, this can take some time...</info>');
120
-				$table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
121
-				if ($table->hasIndex('comments_marker_index')) {
122
-					$table->dropIndex('comments_marker_index');
123
-				}
124
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
125
-				$updated = true;
126
-				$output->writeln('<info>comments_read_markers table updated successfully.</info>');
127
-			}
128
-		}
129
-
130
-		if ($schema->hasTable('collres_resources')) {
131
-			$table = $schema->getTable('collres_resources');
132
-			if (!$table->hasPrimaryKey()) {
133
-				$output->writeln('<info>Adding primary key to the collres_resources table, this can take some time...</info>');
134
-				$table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
135
-				if ($table->hasIndex('collres_unique_res')) {
136
-					$table->dropIndex('collres_unique_res');
137
-				}
138
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
139
-				$updated = true;
140
-				$output->writeln('<info>collres_resources table updated successfully.</info>');
141
-			}
142
-		}
143
-
144
-		if ($schema->hasTable('collres_accesscache')) {
145
-			$table = $schema->getTable('collres_accesscache');
146
-			if (!$table->hasPrimaryKey()) {
147
-				$output->writeln('<info>Adding primary key to the collres_accesscache table, this can take some time...</info>');
148
-				$table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
149
-				if ($table->hasIndex('collres_unique_user')) {
150
-					$table->dropIndex('collres_unique_user');
151
-				}
152
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
153
-				$updated = true;
154
-				$output->writeln('<info>collres_accesscache table updated successfully.</info>');
155
-			}
156
-		}
157
-
158
-		if ($schema->hasTable('filecache_extended')) {
159
-			$table = $schema->getTable('filecache_extended');
160
-			if (!$table->hasPrimaryKey()) {
161
-				$output->writeln('<info>Adding primary key to the filecache_extended table, this can take some time...</info>');
162
-				$table->setPrimaryKey(['fileid'], 'fce_pk');
163
-				if ($table->hasIndex('fce_fileid_idx')) {
164
-					$table->dropIndex('fce_fileid_idx');
165
-				}
166
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
167
-				$updated = true;
168
-				$output->writeln('<info>filecache_extended table updated successfully.</info>');
169
-			}
170
-		}
171
-
172
-		if (!$updated) {
173
-			$output->writeln('<info>Done.</info>');
174
-		}
175
-	}
48
+    /** @var Connection */
49
+    private $connection;
50
+
51
+    /** @var EventDispatcherInterface */
52
+    private $dispatcher;
53
+
54
+    public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
55
+        parent::__construct();
56
+
57
+        $this->connection = $connection;
58
+        $this->dispatcher = $dispatcher;
59
+    }
60
+
61
+    protected function configure() {
62
+        $this
63
+            ->setName('db:add-missing-primary-keys')
64
+            ->setDescription('Add missing primary keys to the database tables');
65
+    }
66
+
67
+    protected function execute(InputInterface $input, OutputInterface $output): int {
68
+        $this->addCorePrimaryKeys($output);
69
+
70
+        // Dispatch event so apps can also update indexes if needed
71
+        $event = new GenericEvent($output);
72
+        $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_PRIMARY_KEYS_EVENT, $event);
73
+        return 0;
74
+    }
75
+
76
+    /**
77
+     * add missing indices to the share table
78
+     *
79
+     * @param OutputInterface $output
80
+     * @throws \Doctrine\DBAL\Schema\SchemaException
81
+     */
82
+    private function addCorePrimaryKeys(OutputInterface $output) {
83
+        $output->writeln('<info>Check primary keys.</info>');
84
+
85
+        $schema = new SchemaWrapper($this->connection);
86
+        $updated = false;
87
+
88
+        if ($schema->hasTable('federated_reshares')) {
89
+            $table = $schema->getTable('federated_reshares');
90
+            if (!$table->hasPrimaryKey()) {
91
+                $output->writeln('<info>Adding primary key to the federated_reshares table, this can take some time...</info>');
92
+                $table->setPrimaryKey(['share_id'], 'federated_res_pk');
93
+                if ($table->hasIndex('share_id_index')) {
94
+                    $table->dropIndex('share_id_index');
95
+                }
96
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
97
+                $updated = true;
98
+                $output->writeln('<info>federated_reshares table updated successfully.</info>');
99
+            }
100
+        }
101
+
102
+        if ($schema->hasTable('systemtag_object_mapping')) {
103
+            $table = $schema->getTable('systemtag_object_mapping');
104
+            if (!$table->hasPrimaryKey()) {
105
+                $output->writeln('<info>Adding primary key to the systemtag_object_mapping table, this can take some time...</info>');
106
+                $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
107
+                if ($table->hasIndex('mapping')) {
108
+                    $table->dropIndex('mapping');
109
+                }
110
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
111
+                $updated = true;
112
+                $output->writeln('<info>systemtag_object_mapping table updated successfully.</info>');
113
+            }
114
+        }
115
+
116
+        if ($schema->hasTable('comments_read_markers')) {
117
+            $table = $schema->getTable('comments_read_markers');
118
+            if (!$table->hasPrimaryKey()) {
119
+                $output->writeln('<info>Adding primary key to the comments_read_markers table, this can take some time...</info>');
120
+                $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
121
+                if ($table->hasIndex('comments_marker_index')) {
122
+                    $table->dropIndex('comments_marker_index');
123
+                }
124
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
125
+                $updated = true;
126
+                $output->writeln('<info>comments_read_markers table updated successfully.</info>');
127
+            }
128
+        }
129
+
130
+        if ($schema->hasTable('collres_resources')) {
131
+            $table = $schema->getTable('collres_resources');
132
+            if (!$table->hasPrimaryKey()) {
133
+                $output->writeln('<info>Adding primary key to the collres_resources table, this can take some time...</info>');
134
+                $table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
135
+                if ($table->hasIndex('collres_unique_res')) {
136
+                    $table->dropIndex('collres_unique_res');
137
+                }
138
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
139
+                $updated = true;
140
+                $output->writeln('<info>collres_resources table updated successfully.</info>');
141
+            }
142
+        }
143
+
144
+        if ($schema->hasTable('collres_accesscache')) {
145
+            $table = $schema->getTable('collres_accesscache');
146
+            if (!$table->hasPrimaryKey()) {
147
+                $output->writeln('<info>Adding primary key to the collres_accesscache table, this can take some time...</info>');
148
+                $table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
149
+                if ($table->hasIndex('collres_unique_user')) {
150
+                    $table->dropIndex('collres_unique_user');
151
+                }
152
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
153
+                $updated = true;
154
+                $output->writeln('<info>collres_accesscache table updated successfully.</info>');
155
+            }
156
+        }
157
+
158
+        if ($schema->hasTable('filecache_extended')) {
159
+            $table = $schema->getTable('filecache_extended');
160
+            if (!$table->hasPrimaryKey()) {
161
+                $output->writeln('<info>Adding primary key to the filecache_extended table, this can take some time...</info>');
162
+                $table->setPrimaryKey(['fileid'], 'fce_pk');
163
+                if ($table->hasIndex('fce_fileid_idx')) {
164
+                    $table->dropIndex('fce_fileid_idx');
165
+                }
166
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
167
+                $updated = true;
168
+                $output->writeln('<info>filecache_extended table updated successfully.</info>');
169
+            }
170
+        }
171
+
172
+        if (!$updated) {
173
+            $output->writeln('<info>Done.</info>');
174
+        }
175
+    }
176 176
 }
Please login to merge, or discard this patch.
core/Command/Db/ConvertMysqlToMB4.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -37,59 +37,59 @@
 block discarded – undo
37 37
 use Symfony\Component\Console\Output\OutputInterface;
38 38
 
39 39
 class ConvertMysqlToMB4 extends Command {
40
-	/** @var IConfig */
41
-	private $config;
40
+    /** @var IConfig */
41
+    private $config;
42 42
 
43
-	/** @var IDBConnection */
44
-	private $connection;
43
+    /** @var IDBConnection */
44
+    private $connection;
45 45
 
46
-	/** @var IURLGenerator */
47
-	private $urlGenerator;
46
+    /** @var IURLGenerator */
47
+    private $urlGenerator;
48 48
 
49
-	/** @var ILogger */
50
-	private $logger;
49
+    /** @var ILogger */
50
+    private $logger;
51 51
 
52
-	/**
53
-	 * @param IConfig $config
54
-	 * @param IDBConnection $connection
55
-	 * @param IURLGenerator $urlGenerator
56
-	 * @param ILogger $logger
57
-	 */
58
-	public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) {
59
-		$this->config = $config;
60
-		$this->connection = $connection;
61
-		$this->urlGenerator = $urlGenerator;
62
-		$this->logger = $logger;
63
-		parent::__construct();
64
-	}
52
+    /**
53
+     * @param IConfig $config
54
+     * @param IDBConnection $connection
55
+     * @param IURLGenerator $urlGenerator
56
+     * @param ILogger $logger
57
+     */
58
+    public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) {
59
+        $this->config = $config;
60
+        $this->connection = $connection;
61
+        $this->urlGenerator = $urlGenerator;
62
+        $this->logger = $logger;
63
+        parent::__construct();
64
+    }
65 65
 
66
-	protected function configure() {
67
-		$this
68
-			->setName('db:convert-mysql-charset')
69
-			->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4');
70
-	}
66
+    protected function configure() {
67
+        $this
68
+            ->setName('db:convert-mysql-charset')
69
+            ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4');
70
+    }
71 71
 
72
-	protected function execute(InputInterface $input, OutputInterface $output): int {
73
-		if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
74
-			$output->writeln("This command is only valid for MySQL/MariaDB databases.");
75
-			return 1;
76
-		}
72
+    protected function execute(InputInterface $input, OutputInterface $output): int {
73
+        if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
74
+            $output->writeln("This command is only valid for MySQL/MariaDB databases.");
75
+            return 1;
76
+        }
77 77
 
78
-		$tools = new MySqlTools();
79
-		if (!$tools->supports4ByteCharset($this->connection)) {
80
-			$url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4');
81
-			$output->writeln("The database is not properly setup to use the charset utf8mb4.");
82
-			$output->writeln("For more information please read the documentation at $url");
83
-			return 1;
84
-		}
78
+        $tools = new MySqlTools();
79
+        if (!$tools->supports4ByteCharset($this->connection)) {
80
+            $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4');
81
+            $output->writeln("The database is not properly setup to use the charset utf8mb4.");
82
+            $output->writeln("For more information please read the documentation at $url");
83
+            return 1;
84
+        }
85 85
 
86
-		// enable charset
87
-		$this->config->setSystemValue('mysql.utf8mb4', true);
86
+        // enable charset
87
+        $this->config->setSystemValue('mysql.utf8mb4', true);
88 88
 
89
-		// run conversion
90
-		$coll = new Collation($this->config, $this->logger, $this->connection, false);
91
-		$coll->run(new ConsoleOutput($output));
89
+        // run conversion
90
+        $coll = new Collation($this->config, $this->logger, $this->connection, false);
91
+        $coll->run(new ConsoleOutput($output));
92 92
 
93
-		return 0;
94
-	}
93
+        return 0;
94
+    }
95 95
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/ExecuteCommand.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -36,90 +36,90 @@
 block discarded – undo
36 36
 
37 37
 class ExecuteCommand extends Command implements CompletionAwareInterface {
38 38
 
39
-	/** @var Connection */
40
-	private $connection;
41
-
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	/**
46
-	 * ExecuteCommand constructor.
47
-	 *
48
-	 * @param Connection $connection
49
-	 * @param IConfig $config
50
-	 */
51
-	public function __construct(Connection $connection, IConfig $config) {
52
-		$this->connection = $connection;
53
-		$this->config = $config;
54
-
55
-		parent::__construct();
56
-	}
57
-
58
-	protected function configure() {
59
-		$this
60
-			->setName('migrations:execute')
61
-			->setDescription('Execute a single migration version manually.')
62
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
63
-			->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
64
-
65
-		parent::configure();
66
-	}
67
-
68
-	/**
69
-	 * @param InputInterface $input
70
-	 * @param OutputInterface $output
71
-	 * @return int
72
-	 */
73
-	public function execute(InputInterface $input, OutputInterface $output): int {
74
-		$appName = $input->getArgument('app');
75
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
76
-		$version = $input->getArgument('version');
77
-
78
-		if ($this->config->getSystemValue('debug', false) === false) {
79
-			$olderVersions = $ms->getMigratedVersions();
80
-			$olderVersions[] = '0';
81
-			$olderVersions[] = 'prev';
82
-			if (in_array($version,  $olderVersions, true)) {
83
-				$output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
84
-				return 1;
85
-			}
86
-		}
87
-
88
-
89
-		$ms->executeStep($version);
90
-		return 0;
91
-	}
92
-
93
-	/**
94
-	 * @param string $optionName
95
-	 * @param CompletionContext $context
96
-	 * @return string[]
97
-	 */
98
-	public function completeOptionValues($optionName, CompletionContext $context) {
99
-		return [];
100
-	}
101
-
102
-	/**
103
-	 * @param string $argumentName
104
-	 * @param CompletionContext $context
105
-	 * @return string[]
106
-	 */
107
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
108
-		if ($argumentName === 'app') {
109
-			$allApps = \OC_App::getAllApps();
110
-			return array_diff($allApps, \OC_App::getEnabledApps(true, true));
111
-		}
112
-
113
-		if ($argumentName === 'version') {
114
-			$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
115
-
116
-			$ms = new MigrationService($appName, $this->connection);
117
-			$migrations = $ms->getAvailableVersions();
118
-
119
-			array_unshift($migrations, 'next', 'latest');
120
-			return $migrations;
121
-		}
122
-
123
-		return [];
124
-	}
39
+    /** @var Connection */
40
+    private $connection;
41
+
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    /**
46
+     * ExecuteCommand constructor.
47
+     *
48
+     * @param Connection $connection
49
+     * @param IConfig $config
50
+     */
51
+    public function __construct(Connection $connection, IConfig $config) {
52
+        $this->connection = $connection;
53
+        $this->config = $config;
54
+
55
+        parent::__construct();
56
+    }
57
+
58
+    protected function configure() {
59
+        $this
60
+            ->setName('migrations:execute')
61
+            ->setDescription('Execute a single migration version manually.')
62
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
63
+            ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
64
+
65
+        parent::configure();
66
+    }
67
+
68
+    /**
69
+     * @param InputInterface $input
70
+     * @param OutputInterface $output
71
+     * @return int
72
+     */
73
+    public function execute(InputInterface $input, OutputInterface $output): int {
74
+        $appName = $input->getArgument('app');
75
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
76
+        $version = $input->getArgument('version');
77
+
78
+        if ($this->config->getSystemValue('debug', false) === false) {
79
+            $olderVersions = $ms->getMigratedVersions();
80
+            $olderVersions[] = '0';
81
+            $olderVersions[] = 'prev';
82
+            if (in_array($version,  $olderVersions, true)) {
83
+                $output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
84
+                return 1;
85
+            }
86
+        }
87
+
88
+
89
+        $ms->executeStep($version);
90
+        return 0;
91
+    }
92
+
93
+    /**
94
+     * @param string $optionName
95
+     * @param CompletionContext $context
96
+     * @return string[]
97
+     */
98
+    public function completeOptionValues($optionName, CompletionContext $context) {
99
+        return [];
100
+    }
101
+
102
+    /**
103
+     * @param string $argumentName
104
+     * @param CompletionContext $context
105
+     * @return string[]
106
+     */
107
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
108
+        if ($argumentName === 'app') {
109
+            $allApps = \OC_App::getAllApps();
110
+            return array_diff($allApps, \OC_App::getEnabledApps(true, true));
111
+        }
112
+
113
+        if ($argumentName === 'version') {
114
+            $appName = $context->getWordAtIndex($context->getWordIndex() - 1);
115
+
116
+            $ms = new MigrationService($appName, $this->connection);
117
+            $migrations = $ms->getAvailableVersions();
118
+
119
+            array_unshift($migrations, 'next', 'latest');
120
+            return $migrations;
121
+        }
122
+
123
+        return [];
124
+    }
125 125
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/StatusCommand.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -36,111 +36,111 @@
 block discarded – undo
36 36
 
37 37
 class StatusCommand extends Command implements CompletionAwareInterface {
38 38
 
39
-	/** @var Connection */
40
-	private $connection;
41
-
42
-	public function __construct(Connection $connection) {
43
-		$this->connection = $connection;
44
-		parent::__construct();
45
-	}
46
-
47
-	protected function configure() {
48
-		$this
49
-			->setName('migrations:status')
50
-			->setDescription('View the status of a set of migrations.')
51
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on');
52
-	}
53
-
54
-	public function execute(InputInterface $input, OutputInterface $output): int {
55
-		$appName = $input->getArgument('app');
56
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
57
-
58
-		$infos = $this->getMigrationsInfos($ms);
59
-		foreach ($infos as $key => $value) {
60
-			if (is_array($value)) {
61
-				$output->writeln("    <comment>>></comment> $key:");
62
-				foreach ($value as $subKey => $subValue) {
63
-					$output->writeln("        <comment>>></comment> $subKey: " . str_repeat(' ', 46 - strlen($subKey)) . $subValue);
64
-				}
65
-			} else {
66
-				$output->writeln("    <comment>>></comment> $key: " . str_repeat(' ', 50 - strlen($key)) . $value);
67
-			}
68
-		}
69
-		return 0;
70
-	}
71
-
72
-	/**
73
-	 * @param string $optionName
74
-	 * @param CompletionContext $context
75
-	 * @return string[]
76
-	 */
77
-	public function completeOptionValues($optionName, CompletionContext $context) {
78
-		return [];
79
-	}
80
-
81
-	/**
82
-	 * @param string $argumentName
83
-	 * @param CompletionContext $context
84
-	 * @return string[]
85
-	 */
86
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
87
-		if ($argumentName === 'app') {
88
-			$allApps = \OC_App::getAllApps();
89
-			return array_diff($allApps, \OC_App::getEnabledApps(true, true));
90
-		}
91
-		return [];
92
-	}
93
-
94
-	/**
95
-	 * @param MigrationService $ms
96
-	 * @return array associative array of human readable info name as key and the actual information as value
97
-	 */
98
-	public function getMigrationsInfos(MigrationService $ms) {
99
-		$executedMigrations = $ms->getMigratedVersions();
100
-		$availableMigrations = $ms->getAvailableVersions();
101
-		$executedUnavailableMigrations = array_diff($executedMigrations, array_keys($availableMigrations));
102
-
103
-		$numExecutedUnavailableMigrations = count($executedUnavailableMigrations);
104
-		$numNewMigrations = count(array_diff(array_keys($availableMigrations), $executedMigrations));
105
-		$pending = $ms->describeMigrationStep('lastest');
106
-
107
-		$infos = [
108
-			'App' => $ms->getApp(),
109
-			'Version Table Name' => $ms->getMigrationsTableName(),
110
-			'Migrations Namespace' => $ms->getMigrationsNamespace(),
111
-			'Migrations Directory' => $ms->getMigrationsDirectory(),
112
-			'Previous Version' => $this->getFormattedVersionAlias($ms, 'prev'),
113
-			'Current Version' => $this->getFormattedVersionAlias($ms, 'current'),
114
-			'Next Version' => $this->getFormattedVersionAlias($ms, 'next'),
115
-			'Latest Version' => $this->getFormattedVersionAlias($ms, 'latest'),
116
-			'Executed Migrations' => count($executedMigrations),
117
-			'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations,
118
-			'Available Migrations' => count($availableMigrations),
119
-			'New Migrations' => $numNewMigrations,
120
-			'Pending Migrations' => count($pending) ? $pending : 'None'
121
-		];
122
-
123
-		return $infos;
124
-	}
125
-
126
-	/**
127
-	 * @param MigrationService $migrationService
128
-	 * @param string $alias
129
-	 * @return mixed|null|string
130
-	 */
131
-	private function getFormattedVersionAlias(MigrationService $migrationService, $alias) {
132
-		$migration = $migrationService->getMigration($alias);
133
-		//No version found
134
-		if ($migration === null) {
135
-			if ($alias === 'next') {
136
-				return 'Already at latest migration step';
137
-			}
138
-
139
-			if ($alias === 'prev') {
140
-				return 'Already at first migration step';
141
-			}
142
-		}
143
-
144
-		return $migration;
145
-	}
39
+    /** @var Connection */
40
+    private $connection;
41
+
42
+    public function __construct(Connection $connection) {
43
+        $this->connection = $connection;
44
+        parent::__construct();
45
+    }
46
+
47
+    protected function configure() {
48
+        $this
49
+            ->setName('migrations:status')
50
+            ->setDescription('View the status of a set of migrations.')
51
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on');
52
+    }
53
+
54
+    public function execute(InputInterface $input, OutputInterface $output): int {
55
+        $appName = $input->getArgument('app');
56
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
57
+
58
+        $infos = $this->getMigrationsInfos($ms);
59
+        foreach ($infos as $key => $value) {
60
+            if (is_array($value)) {
61
+                $output->writeln("    <comment>>></comment> $key:");
62
+                foreach ($value as $subKey => $subValue) {
63
+                    $output->writeln("        <comment>>></comment> $subKey: " . str_repeat(' ', 46 - strlen($subKey)) . $subValue);
64
+                }
65
+            } else {
66
+                $output->writeln("    <comment>>></comment> $key: " . str_repeat(' ', 50 - strlen($key)) . $value);
67
+            }
68
+        }
69
+        return 0;
70
+    }
71
+
72
+    /**
73
+     * @param string $optionName
74
+     * @param CompletionContext $context
75
+     * @return string[]
76
+     */
77
+    public function completeOptionValues($optionName, CompletionContext $context) {
78
+        return [];
79
+    }
80
+
81
+    /**
82
+     * @param string $argumentName
83
+     * @param CompletionContext $context
84
+     * @return string[]
85
+     */
86
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
87
+        if ($argumentName === 'app') {
88
+            $allApps = \OC_App::getAllApps();
89
+            return array_diff($allApps, \OC_App::getEnabledApps(true, true));
90
+        }
91
+        return [];
92
+    }
93
+
94
+    /**
95
+     * @param MigrationService $ms
96
+     * @return array associative array of human readable info name as key and the actual information as value
97
+     */
98
+    public function getMigrationsInfos(MigrationService $ms) {
99
+        $executedMigrations = $ms->getMigratedVersions();
100
+        $availableMigrations = $ms->getAvailableVersions();
101
+        $executedUnavailableMigrations = array_diff($executedMigrations, array_keys($availableMigrations));
102
+
103
+        $numExecutedUnavailableMigrations = count($executedUnavailableMigrations);
104
+        $numNewMigrations = count(array_diff(array_keys($availableMigrations), $executedMigrations));
105
+        $pending = $ms->describeMigrationStep('lastest');
106
+
107
+        $infos = [
108
+            'App' => $ms->getApp(),
109
+            'Version Table Name' => $ms->getMigrationsTableName(),
110
+            'Migrations Namespace' => $ms->getMigrationsNamespace(),
111
+            'Migrations Directory' => $ms->getMigrationsDirectory(),
112
+            'Previous Version' => $this->getFormattedVersionAlias($ms, 'prev'),
113
+            'Current Version' => $this->getFormattedVersionAlias($ms, 'current'),
114
+            'Next Version' => $this->getFormattedVersionAlias($ms, 'next'),
115
+            'Latest Version' => $this->getFormattedVersionAlias($ms, 'latest'),
116
+            'Executed Migrations' => count($executedMigrations),
117
+            'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations,
118
+            'Available Migrations' => count($availableMigrations),
119
+            'New Migrations' => $numNewMigrations,
120
+            'Pending Migrations' => count($pending) ? $pending : 'None'
121
+        ];
122
+
123
+        return $infos;
124
+    }
125
+
126
+    /**
127
+     * @param MigrationService $migrationService
128
+     * @param string $alias
129
+     * @return mixed|null|string
130
+     */
131
+    private function getFormattedVersionAlias(MigrationService $migrationService, $alias) {
132
+        $migration = $migrationService->getMigration($alias);
133
+        //No version found
134
+        if ($migration === null) {
135
+            if ($alias === 'next') {
136
+                return 'Already at latest migration step';
137
+            }
138
+
139
+            if ($alias === 'prev') {
140
+                return 'Already at first migration step';
141
+            }
142
+        }
143
+
144
+        return $migration;
145
+    }
146 146
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/GenerateCommand.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 use Symfony\Component\Console\Output\OutputInterface;
39 39
 
40 40
 class GenerateCommand extends Command implements CompletionAwareInterface {
41
-	protected static $_templateSimple =
42
-		'<?php
41
+    protected static $_templateSimple =
42
+        '<?php
43 43
 
44 44
 declare(strict_types=1);
45 45
 
@@ -83,129 +83,129 @@  discard block
 block discarded – undo
83 83
 }
84 84
 ';
85 85
 
86
-	/** @var Connection */
87
-	protected $connection;
88
-
89
-	/** @var IAppManager */
90
-	protected $appManager;
91
-
92
-	/**
93
-	 * @param Connection $connection
94
-	 * @param IAppManager $appManager
95
-	 */
96
-	public function __construct(Connection $connection, IAppManager $appManager) {
97
-		$this->connection = $connection;
98
-		$this->appManager = $appManager;
99
-
100
-		parent::__construct();
101
-	}
102
-
103
-	protected function configure() {
104
-		$this
105
-			->setName('migrations:generate')
106
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
107
-			->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
108
-		;
109
-
110
-		parent::configure();
111
-	}
112
-
113
-	public function execute(InputInterface $input, OutputInterface $output): int {
114
-		$appName = $input->getArgument('app');
115
-		$version = $input->getArgument('version');
116
-
117
-		if (!preg_match('/^\d{1,16}$/',$version)) {
118
-			$output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
119
-			return 1;
120
-		}
121
-
122
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
123
-
124
-		$date = date('YmdHis');
125
-		$path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
126
-
127
-		$output->writeln("New migration class has been generated to <info>$path</info>");
128
-		return 0;
129
-	}
130
-
131
-	/**
132
-	 * @param string $optionName
133
-	 * @param CompletionContext $context
134
-	 * @return string[]
135
-	 */
136
-	public function completeOptionValues($optionName, CompletionContext $context) {
137
-		return [];
138
-	}
139
-
140
-	/**
141
-	 * @param string $argumentName
142
-	 * @param CompletionContext $context
143
-	 * @return string[]
144
-	 */
145
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
146
-		if ($argumentName === 'app') {
147
-			$allApps = \OC_App::getAllApps();
148
-			return array_diff($allApps, \OC_App::getEnabledApps(true, true));
149
-		}
150
-
151
-		if ($argumentName === 'version') {
152
-			$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
153
-
154
-			$version = explode('.', $this->appManager->getAppVersion($appName));
155
-			return [$version[0] . sprintf('%1$03d', $version[1])];
156
-		}
157
-
158
-		return [];
159
-	}
160
-
161
-	/**
162
-	 * @param MigrationService $ms
163
-	 * @param string $className
164
-	 * @param string $schemaBody
165
-	 * @return string
166
-	 */
167
-	protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
168
-		if ($schemaBody === '') {
169
-			$schemaBody = "\t\t" . 'return null;';
170
-		}
171
-
172
-
173
-		$placeHolders = [
174
-			'{{namespace}}',
175
-			'{{classname}}',
176
-			'{{schemabody}}',
177
-		];
178
-		$replacements = [
179
-			$ms->getMigrationsNamespace(),
180
-			$className,
181
-			$schemaBody,
182
-		];
183
-		$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
184
-		$dir = $ms->getMigrationsDirectory();
185
-
186
-		$this->ensureMigrationDirExists($dir);
187
-		$path = $dir . '/' . $className . '.php';
188
-
189
-		if (file_put_contents($path, $code) === false) {
190
-			throw new RuntimeException('Failed to generate new migration step.');
191
-		}
192
-
193
-		return $path;
194
-	}
195
-
196
-	protected function ensureMigrationDirExists($directory) {
197
-		if (file_exists($directory) && is_dir($directory)) {
198
-			return;
199
-		}
200
-
201
-		if (file_exists($directory)) {
202
-			throw new \RuntimeException("Could not create folder \"$directory\"");
203
-		}
204
-
205
-		$this->ensureMigrationDirExists(dirname($directory));
206
-
207
-		if (!@mkdir($directory) && !is_dir($directory)) {
208
-			throw new \RuntimeException("Could not create folder \"$directory\"");
209
-		}
210
-	}
86
+    /** @var Connection */
87
+    protected $connection;
88
+
89
+    /** @var IAppManager */
90
+    protected $appManager;
91
+
92
+    /**
93
+     * @param Connection $connection
94
+     * @param IAppManager $appManager
95
+     */
96
+    public function __construct(Connection $connection, IAppManager $appManager) {
97
+        $this->connection = $connection;
98
+        $this->appManager = $appManager;
99
+
100
+        parent::__construct();
101
+    }
102
+
103
+    protected function configure() {
104
+        $this
105
+            ->setName('migrations:generate')
106
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
107
+            ->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches')
108
+        ;
109
+
110
+        parent::configure();
111
+    }
112
+
113
+    public function execute(InputInterface $input, OutputInterface $output): int {
114
+        $appName = $input->getArgument('app');
115
+        $version = $input->getArgument('version');
116
+
117
+        if (!preg_match('/^\d{1,16}$/',$version)) {
118
+            $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
119
+            return 1;
120
+        }
121
+
122
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
123
+
124
+        $date = date('YmdHis');
125
+        $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date);
126
+
127
+        $output->writeln("New migration class has been generated to <info>$path</info>");
128
+        return 0;
129
+    }
130
+
131
+    /**
132
+     * @param string $optionName
133
+     * @param CompletionContext $context
134
+     * @return string[]
135
+     */
136
+    public function completeOptionValues($optionName, CompletionContext $context) {
137
+        return [];
138
+    }
139
+
140
+    /**
141
+     * @param string $argumentName
142
+     * @param CompletionContext $context
143
+     * @return string[]
144
+     */
145
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
146
+        if ($argumentName === 'app') {
147
+            $allApps = \OC_App::getAllApps();
148
+            return array_diff($allApps, \OC_App::getEnabledApps(true, true));
149
+        }
150
+
151
+        if ($argumentName === 'version') {
152
+            $appName = $context->getWordAtIndex($context->getWordIndex() - 1);
153
+
154
+            $version = explode('.', $this->appManager->getAppVersion($appName));
155
+            return [$version[0] . sprintf('%1$03d', $version[1])];
156
+        }
157
+
158
+        return [];
159
+    }
160
+
161
+    /**
162
+     * @param MigrationService $ms
163
+     * @param string $className
164
+     * @param string $schemaBody
165
+     * @return string
166
+     */
167
+    protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') {
168
+        if ($schemaBody === '') {
169
+            $schemaBody = "\t\t" . 'return null;';
170
+        }
171
+
172
+
173
+        $placeHolders = [
174
+            '{{namespace}}',
175
+            '{{classname}}',
176
+            '{{schemabody}}',
177
+        ];
178
+        $replacements = [
179
+            $ms->getMigrationsNamespace(),
180
+            $className,
181
+            $schemaBody,
182
+        ];
183
+        $code = str_replace($placeHolders, $replacements, self::$_templateSimple);
184
+        $dir = $ms->getMigrationsDirectory();
185
+
186
+        $this->ensureMigrationDirExists($dir);
187
+        $path = $dir . '/' . $className . '.php';
188
+
189
+        if (file_put_contents($path, $code) === false) {
190
+            throw new RuntimeException('Failed to generate new migration step.');
191
+        }
192
+
193
+        return $path;
194
+    }
195
+
196
+    protected function ensureMigrationDirExists($directory) {
197
+        if (file_exists($directory) && is_dir($directory)) {
198
+            return;
199
+        }
200
+
201
+        if (file_exists($directory)) {
202
+            throw new \RuntimeException("Could not create folder \"$directory\"");
203
+        }
204
+
205
+        $this->ensureMigrationDirExists(dirname($directory));
206
+
207
+        if (!@mkdir($directory) && !is_dir($directory)) {
208
+            throw new \RuntimeException("Could not create folder \"$directory\"");
209
+        }
210
+    }
211 211
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -37,170 +37,170 @@
 block discarded – undo
37 37
 
38 38
 class GenerateFromSchemaFileCommand extends GenerateCommand {
39 39
 
40
-	/** @var IConfig */
41
-	protected $config;
40
+    /** @var IConfig */
41
+    protected $config;
42 42
 
43
-	public function __construct(IConfig $config, IAppManager $appManager, Connection $connection) {
44
-		parent::__construct($connection, $appManager);
45
-		$this->config = $config;
46
-	}
43
+    public function __construct(IConfig $config, IAppManager $appManager, Connection $connection) {
44
+        parent::__construct($connection, $appManager);
45
+        $this->config = $config;
46
+    }
47 47
 
48 48
 
49
-	protected function configure() {
50
-		parent::configure();
49
+    protected function configure() {
50
+        parent::configure();
51 51
 
52
-		$this->setName('migrations:generate-from-schema');
53
-	}
52
+        $this->setName('migrations:generate-from-schema');
53
+    }
54 54
 
55
-	public function execute(InputInterface $input, OutputInterface $output): int {
56
-		$appName = $input->getArgument('app');
57
-		$version = $input->getArgument('version');
55
+    public function execute(InputInterface $input, OutputInterface $output): int {
56
+        $appName = $input->getArgument('app');
57
+        $version = $input->getArgument('version');
58 58
 
59
-		if (!preg_match('/^\d{1,16}$/',$version)) {
60
-			$output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
61
-			return 1;
62
-		}
59
+        if (!preg_match('/^\d{1,16}$/',$version)) {
60
+            $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
61
+            return 1;
62
+        }
63 63
 
64
-		$schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml';
65
-		if (!file_exists($schemaFile)) {
66
-			$output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>');
67
-			return 2;
68
-		}
64
+        $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml';
65
+        if (!file_exists($schemaFile)) {
66
+            $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>');
67
+            return 2;
68
+        }
69 69
 
70
-		$reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform());
71
-		$schema = new Schema();
72
-		$reader->loadSchemaFromFile($schemaFile, $schema);
70
+        $reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform());
71
+        $schema = new Schema();
72
+        $reader->loadSchemaFromFile($schemaFile, $schema);
73 73
 
74
-		$schemaBody = $this->schemaToMigration($schema);
74
+        $schemaBody = $this->schemaToMigration($schema);
75 75
 
76
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
76
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
77 77
 
78
-		$date = date('YmdHis');
79
-		$path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody);
78
+        $date = date('YmdHis');
79
+        $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody);
80 80
 
81
-		$output->writeln("New migration class has been generated to <info>$path</info>");
82
-		return 0;
83
-	}
81
+        $output->writeln("New migration class has been generated to <info>$path</info>");
82
+        return 0;
83
+    }
84 84
 
85
-	/**
86
-	 * @param Schema $schema
87
-	 * @return string
88
-	 */
89
-	protected function schemaToMigration(Schema $schema) {
90
-		$content = <<<'EOT'
85
+    /**
86
+     * @param Schema $schema
87
+     * @return string
88
+     */
89
+    protected function schemaToMigration(Schema $schema) {
90
+        $content = <<<'EOT'
91 91
 		/** @var ISchemaWrapper $schema */
92 92
 		$schema = $schemaClosure();
93 93
 
94 94
 EOT;
95 95
 
96
-		foreach ($schema->getTables() as $table) {
97
-			$content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT'
96
+        foreach ($schema->getTables() as $table) {
97
+            $content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT'
98 98
 
99 99
 		if (!$schema->hasTable('{{table-name}}')) {
100 100
 			$table = $schema->createTable('{{table-name}}');
101 101
 
102 102
 EOT
103
-			);
103
+            );
104 104
 
105
-			foreach ($table->getColumns() as $column) {
106
-				$content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT'
105
+            foreach ($table->getColumns() as $column) {
106
+                $content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT'
107 107
 			$table->addColumn('{{name}}', '{{type}}', [
108 108
 
109 109
 EOT
110
-				);
111
-				if ($column->getAutoincrement()) {
112
-					$content .= <<<'EOT'
110
+                );
111
+                if ($column->getAutoincrement()) {
112
+                    $content .= <<<'EOT'
113 113
 				'autoincrement' => true,
114 114
 
115 115
 EOT;
116
-				}
117
-				$content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT'
116
+                }
117
+                $content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT'
118 118
 				'notnull' => {{notnull}},
119 119
 
120 120
 EOT
121
-				);
122
-				if ($column->getLength() !== null) {
123
-					$content .= str_replace('{{length}}', $column->getLength(), <<<'EOT'
121
+                );
122
+                if ($column->getLength() !== null) {
123
+                    $content .= str_replace('{{length}}', $column->getLength(), <<<'EOT'
124 124
 				'length' => {{length}},
125 125
 
126 126
 EOT
127
-					);
128
-				}
129
-				$default = $column->getDefault();
130
-				if ($default !== null) {
131
-					if (is_string($default)) {
132
-						$default = "'$default'";
133
-					} elseif (is_bool($default)) {
134
-						$default = ($default === true) ? 'true' : 'false';
135
-					}
136
-					$content .= str_replace('{{default}}', $default, <<<'EOT'
127
+                    );
128
+                }
129
+                $default = $column->getDefault();
130
+                if ($default !== null) {
131
+                    if (is_string($default)) {
132
+                        $default = "'$default'";
133
+                    } elseif (is_bool($default)) {
134
+                        $default = ($default === true) ? 'true' : 'false';
135
+                    }
136
+                    $content .= str_replace('{{default}}', $default, <<<'EOT'
137 137
 				'default' => {{default}},
138 138
 
139 139
 EOT
140
-					);
141
-				}
142
-				if ($column->getUnsigned()) {
143
-					$content .= <<<'EOT'
140
+                    );
141
+                }
142
+                if ($column->getUnsigned()) {
143
+                    $content .= <<<'EOT'
144 144
 				'unsigned' => true,
145 145
 
146 146
 EOT;
147
-				}
147
+                }
148 148
 
149
-				$content .= <<<'EOT'
149
+                $content .= <<<'EOT'
150 150
 			]);
151 151
 
152 152
 EOT;
153
-			}
153
+            }
154 154
 
155
-			$content .= <<<'EOT'
155
+            $content .= <<<'EOT'
156 156
 
157 157
 EOT;
158 158
 
159
-			$primaryKey = $table->getPrimaryKey();
160
-			if ($primaryKey !== null) {
161
-				$content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT'
159
+            $primaryKey = $table->getPrimaryKey();
160
+            if ($primaryKey !== null) {
161
+                $content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT'
162 162
 			$table->setPrimaryKey(['{{columns}}']);
163 163
 
164 164
 EOT
165
-				);
166
-			}
167
-
168
-			foreach ($table->getIndexes() as $index) {
169
-				if ($index->isPrimary()) {
170
-					continue;
171
-				}
172
-
173
-				if ($index->isUnique()) {
174
-					$content .= str_replace(
175
-						['{{columns}}', '{{name}}'],
176
-						[implode('\', \'', $index->getUnquotedColumns()), $index->getName()],
177
-						<<<'EOT'
165
+                );
166
+            }
167
+
168
+            foreach ($table->getIndexes() as $index) {
169
+                if ($index->isPrimary()) {
170
+                    continue;
171
+                }
172
+
173
+                if ($index->isUnique()) {
174
+                    $content .= str_replace(
175
+                        ['{{columns}}', '{{name}}'],
176
+                        [implode('\', \'', $index->getUnquotedColumns()), $index->getName()],
177
+                        <<<'EOT'
178 178
 			$table->addUniqueIndex(['{{columns}}'], '{{name}}');
179 179
 
180 180
 EOT
181
-					);
182
-				} else {
183
-					$content .= str_replace(
184
-						['{{columns}}', '{{name}}'],
185
-						[implode('\', \'', $index->getUnquotedColumns()), $index->getName()],
186
-						<<<'EOT'
181
+                    );
182
+                } else {
183
+                    $content .= str_replace(
184
+                        ['{{columns}}', '{{name}}'],
185
+                        [implode('\', \'', $index->getUnquotedColumns()), $index->getName()],
186
+                        <<<'EOT'
187 187
 			$table->addIndex(['{{columns}}'], '{{name}}');
188 188
 
189 189
 EOT
190
-					);
191
-				}
192
-			}
190
+                    );
191
+                }
192
+            }
193 193
 
194
-			$content .= <<<'EOT'
194
+            $content .= <<<'EOT'
195 195
 		}
196 196
 
197 197
 EOT;
198
-		}
198
+        }
199 199
 
200
-		$content .= <<<'EOT'
200
+        $content .= <<<'EOT'
201 201
 		return $schema;
202 202
 EOT;
203 203
 
204
-		return $content;
205
-	}
204
+        return $content;
205
+    }
206 206
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/MigrateCommand.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -34,66 +34,66 @@
 block discarded – undo
34 34
 
35 35
 class MigrateCommand extends Command implements CompletionAwareInterface {
36 36
 
37
-	/** @var Connection */
38
-	private $connection;
37
+    /** @var Connection */
38
+    private $connection;
39 39
 
40
-	/**
41
-	 * @param Connection $connection
42
-	 */
43
-	public function __construct(Connection $connection) {
44
-		$this->connection = $connection;
45
-		parent::__construct();
46
-	}
40
+    /**
41
+     * @param Connection $connection
42
+     */
43
+    public function __construct(Connection $connection) {
44
+        $this->connection = $connection;
45
+        parent::__construct();
46
+    }
47 47
 
48
-	protected function configure() {
49
-		$this
50
-			->setName('migrations:migrate')
51
-			->setDescription('Execute a migration to a specified version or the latest available version.')
52
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
53
-			->addArgument('version', InputArgument::OPTIONAL, 'The version number (YYYYMMDDHHMMSS) or alias (first, prev, next, latest) to migrate to.', 'latest');
48
+    protected function configure() {
49
+        $this
50
+            ->setName('migrations:migrate')
51
+            ->setDescription('Execute a migration to a specified version or the latest available version.')
52
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
53
+            ->addArgument('version', InputArgument::OPTIONAL, 'The version number (YYYYMMDDHHMMSS) or alias (first, prev, next, latest) to migrate to.', 'latest');
54 54
 
55
-		parent::configure();
56
-	}
55
+        parent::configure();
56
+    }
57 57
 
58
-	public function execute(InputInterface $input, OutputInterface $output): int {
59
-		$appName = $input->getArgument('app');
60
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
61
-		$version = $input->getArgument('version');
58
+    public function execute(InputInterface $input, OutputInterface $output): int {
59
+        $appName = $input->getArgument('app');
60
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
61
+        $version = $input->getArgument('version');
62 62
 
63
-		$ms->migrate($version);
64
-		return 0;
65
-	}
63
+        $ms->migrate($version);
64
+        return 0;
65
+    }
66 66
 
67
-	/**
68
-	 * @param string $optionName
69
-	 * @param CompletionContext $context
70
-	 * @return string[]
71
-	 */
72
-	public function completeOptionValues($optionName, CompletionContext $context) {
73
-		return [];
74
-	}
67
+    /**
68
+     * @param string $optionName
69
+     * @param CompletionContext $context
70
+     * @return string[]
71
+     */
72
+    public function completeOptionValues($optionName, CompletionContext $context) {
73
+        return [];
74
+    }
75 75
 
76
-	/**
77
-	 * @param string $argumentName
78
-	 * @param CompletionContext $context
79
-	 * @return string[]
80
-	 */
81
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
82
-		if ($argumentName === 'app') {
83
-			$allApps = \OC_App::getAllApps();
84
-			return array_diff($allApps, \OC_App::getEnabledApps(true, true));
85
-		}
76
+    /**
77
+     * @param string $argumentName
78
+     * @param CompletionContext $context
79
+     * @return string[]
80
+     */
81
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
82
+        if ($argumentName === 'app') {
83
+            $allApps = \OC_App::getAllApps();
84
+            return array_diff($allApps, \OC_App::getEnabledApps(true, true));
85
+        }
86 86
 
87
-		if ($argumentName === 'version') {
88
-			$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
87
+        if ($argumentName === 'version') {
88
+            $appName = $context->getWordAtIndex($context->getWordIndex() - 1);
89 89
 
90
-			$ms = new MigrationService($appName, $this->connection);
91
-			$migrations = $ms->getAvailableVersions();
90
+            $ms = new MigrationService($appName, $this->connection);
91
+            $migrations = $ms->getAvailableVersions();
92 92
 
93
-			array_unshift($migrations, 'next', 'latest');
94
-			return $migrations;
95
-		}
93
+            array_unshift($migrations, 'next', 'latest');
94
+            return $migrations;
95
+        }
96 96
 
97
-		return [];
98
-	}
97
+        return [];
98
+    }
99 99
 }
Please login to merge, or discard this patch.
core/Command/Db/ConvertFilecacheBigInt.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -43,91 +43,91 @@
 block discarded – undo
43 43
 
44 44
 class ConvertFilecacheBigInt extends Command {
45 45
 
46
-	/** @var Connection */
47
-	private $connection;
48
-
49
-	/**
50
-	 * @param Connection $connection
51
-	 */
52
-	public function __construct(Connection $connection) {
53
-		$this->connection = $connection;
54
-		parent::__construct();
55
-	}
56
-
57
-	protected function configure() {
58
-		$this
59
-			->setName('db:convert-filecache-bigint')
60
-			->setDescription('Convert the ID columns of the filecache to BigInt');
61
-	}
62
-
63
-	protected function getColumnsByTable() {
64
-		// also update in CheckSetupController::hasBigIntConversionPendingColumns()
65
-		return [
66
-			'activity' => ['activity_id', 'object_id'],
67
-			'activity_mq' => ['mail_id'],
68
-			'authtoken' => ['id'],
69
-			'bruteforce_attempts' => ['id'],
70
-			'federated_reshares' => ['share_id'],
71
-			'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
72
-			'filecache_extended' => ['fileid'],
73
-			'files_trash' => ['auto_id'],
74
-			'file_locks' => ['id'],
75
-			'jobs' => ['id'],
76
-			'mimetypes' => ['id'],
77
-			'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
78
-			'share_external' => ['id', 'parent'],
79
-			'storages' => ['numeric_id'],
80
-		];
81
-	}
82
-
83
-	protected function execute(InputInterface $input, OutputInterface $output): int {
84
-		$schema = new SchemaWrapper($this->connection);
85
-		$isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
86
-		$updates = [];
87
-
88
-		$tables = $this->getColumnsByTable();
89
-		foreach ($tables as $tableName => $columns) {
90
-			if (!$schema->hasTable($tableName)) {
91
-				continue;
92
-			}
93
-
94
-			$table = $schema->getTable($tableName);
95
-
96
-			foreach ($columns as $columnName) {
97
-				$column = $table->getColumn($columnName);
98
-				$isAutoIncrement = $column->getAutoincrement();
99
-				$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
100
-				if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
101
-					$column->setType(Type::getType(Types::BIGINT));
102
-					$column->setOptions(['length' => 20]);
103
-
104
-					$updates[] = '* ' . $tableName . '.' . $columnName;
105
-				}
106
-			}
107
-		}
108
-
109
-		if (empty($updates)) {
110
-			$output->writeln('<info>All tables already up to date!</info>');
111
-			return 0;
112
-		}
113
-
114
-		$output->writeln('<comment>Following columns will be updated:</comment>');
115
-		$output->writeln('');
116
-		$output->writeln($updates);
117
-		$output->writeln('');
118
-		$output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>');
119
-
120
-		if ($input->isInteractive()) {
121
-			$helper = $this->getHelper('question');
122
-			$question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false);
123
-
124
-			if (!$helper->ask($input, $output, $question)) {
125
-				return 1;
126
-			}
127
-		}
128
-
129
-		$this->connection->migrateToSchema($schema->getWrappedSchema());
130
-
131
-		return 0;
132
-	}
46
+    /** @var Connection */
47
+    private $connection;
48
+
49
+    /**
50
+     * @param Connection $connection
51
+     */
52
+    public function __construct(Connection $connection) {
53
+        $this->connection = $connection;
54
+        parent::__construct();
55
+    }
56
+
57
+    protected function configure() {
58
+        $this
59
+            ->setName('db:convert-filecache-bigint')
60
+            ->setDescription('Convert the ID columns of the filecache to BigInt');
61
+    }
62
+
63
+    protected function getColumnsByTable() {
64
+        // also update in CheckSetupController::hasBigIntConversionPendingColumns()
65
+        return [
66
+            'activity' => ['activity_id', 'object_id'],
67
+            'activity_mq' => ['mail_id'],
68
+            'authtoken' => ['id'],
69
+            'bruteforce_attempts' => ['id'],
70
+            'federated_reshares' => ['share_id'],
71
+            'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
72
+            'filecache_extended' => ['fileid'],
73
+            'files_trash' => ['auto_id'],
74
+            'file_locks' => ['id'],
75
+            'jobs' => ['id'],
76
+            'mimetypes' => ['id'],
77
+            'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'],
78
+            'share_external' => ['id', 'parent'],
79
+            'storages' => ['numeric_id'],
80
+        ];
81
+    }
82
+
83
+    protected function execute(InputInterface $input, OutputInterface $output): int {
84
+        $schema = new SchemaWrapper($this->connection);
85
+        $isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
86
+        $updates = [];
87
+
88
+        $tables = $this->getColumnsByTable();
89
+        foreach ($tables as $tableName => $columns) {
90
+            if (!$schema->hasTable($tableName)) {
91
+                continue;
92
+            }
93
+
94
+            $table = $schema->getTable($tableName);
95
+
96
+            foreach ($columns as $columnName) {
97
+                $column = $table->getColumn($columnName);
98
+                $isAutoIncrement = $column->getAutoincrement();
99
+                $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
100
+                if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) {
101
+                    $column->setType(Type::getType(Types::BIGINT));
102
+                    $column->setOptions(['length' => 20]);
103
+
104
+                    $updates[] = '* ' . $tableName . '.' . $columnName;
105
+                }
106
+            }
107
+        }
108
+
109
+        if (empty($updates)) {
110
+            $output->writeln('<info>All tables already up to date!</info>');
111
+            return 0;
112
+        }
113
+
114
+        $output->writeln('<comment>Following columns will be updated:</comment>');
115
+        $output->writeln('');
116
+        $output->writeln($updates);
117
+        $output->writeln('');
118
+        $output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>');
119
+
120
+        if ($input->isInteractive()) {
121
+            $helper = $this->getHelper('question');
122
+            $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false);
123
+
124
+            if (!$helper->ask($input, $output, $question)) {
125
+                return 1;
126
+            }
127
+        }
128
+
129
+        $this->connection->migrateToSchema($schema->getWrappedSchema());
130
+
131
+        return 0;
132
+    }
133 133
 }
Please login to merge, or discard this patch.
core/Command/Db/AddMissingIndices.php 1 patch
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -52,267 +52,267 @@
 block discarded – undo
52 52
  */
53 53
 class AddMissingIndices extends Command {
54 54
 
55
-	/** @var Connection */
56
-	private $connection;
57
-
58
-	/** @var EventDispatcherInterface */
59
-	private $dispatcher;
60
-
61
-	public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
62
-		parent::__construct();
63
-
64
-		$this->connection = $connection;
65
-		$this->dispatcher = $dispatcher;
66
-	}
67
-
68
-	protected function configure() {
69
-		$this
70
-			->setName('db:add-missing-indices')
71
-			->setDescription('Add missing indices to the database tables');
72
-	}
73
-
74
-	protected function execute(InputInterface $input, OutputInterface $output): int {
75
-		$this->addCoreIndexes($output);
76
-
77
-		// Dispatch event so apps can also update indexes if needed
78
-		$event = new GenericEvent($output);
79
-		$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
80
-		return 0;
81
-	}
82
-
83
-	/**
84
-	 * add missing indices to the share table
85
-	 *
86
-	 * @param OutputInterface $output
87
-	 * @throws \Doctrine\DBAL\Schema\SchemaException
88
-	 */
89
-	private function addCoreIndexes(OutputInterface $output) {
90
-		$output->writeln('<info>Check indices of the share table.</info>');
91
-
92
-		$schema = new SchemaWrapper($this->connection);
93
-		$updated = false;
94
-
95
-		if ($schema->hasTable('share')) {
96
-			$table = $schema->getTable('share');
97
-			if (!$table->hasIndex('share_with_index')) {
98
-				$output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>');
99
-				$table->addIndex(['share_with'], 'share_with_index');
100
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
101
-				$updated = true;
102
-				$output->writeln('<info>Share table updated successfully.</info>');
103
-			}
104
-
105
-			if (!$table->hasIndex('parent_index')) {
106
-				$output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>');
107
-				$table->addIndex(['parent'], 'parent_index');
108
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
109
-				$updated = true;
110
-				$output->writeln('<info>Share table updated successfully.</info>');
111
-			}
112
-
113
-			if (!$table->hasIndex('owner_index')) {
114
-				$output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>');
115
-				$table->addIndex(['uid_owner'], 'owner_index');
116
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
117
-				$updated = true;
118
-				$output->writeln('<info>Share table updated successfully.</info>');
119
-			}
120
-
121
-			if (!$table->hasIndex('initiator_index')) {
122
-				$output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>');
123
-				$table->addIndex(['uid_initiator'], 'initiator_index');
124
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
125
-				$updated = true;
126
-				$output->writeln('<info>Share table updated successfully.</info>');
127
-			}
128
-		}
129
-
130
-		$output->writeln('<info>Check indices of the filecache table.</info>');
131
-		if ($schema->hasTable('filecache')) {
132
-			$table = $schema->getTable('filecache');
133
-			if (!$table->hasIndex('fs_mtime')) {
134
-				$output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>');
135
-				$table->addIndex(['mtime'], 'fs_mtime');
136
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
137
-				$updated = true;
138
-				$output->writeln('<info>Filecache table updated successfully.</info>');
139
-			}
140
-			if (!$table->hasIndex('fs_size')) {
141
-				$output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
142
-				$table->addIndex(['size'], 'fs_size');
143
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
144
-				$updated = true;
145
-				$output->writeln('<info>Filecache table updated successfully.</info>');
146
-			}
147
-		}
148
-
149
-		$output->writeln('<info>Check indices of the twofactor_providers table.</info>');
150
-		if ($schema->hasTable('twofactor_providers')) {
151
-			$table = $schema->getTable('twofactor_providers');
152
-			if (!$table->hasIndex('twofactor_providers_uid')) {
153
-				$output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
154
-				$table->addIndex(['uid'], 'twofactor_providers_uid');
155
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
156
-				$updated = true;
157
-				$output->writeln('<info>Twofactor_providers table updated successfully.</info>');
158
-			}
159
-		}
160
-
161
-		$output->writeln('<info>Check indices of the login_flow_v2 table.</info>');
162
-		if ($schema->hasTable('login_flow_v2')) {
163
-			$table = $schema->getTable('login_flow_v2');
164
-			if (!$table->hasIndex('poll_token')) {
165
-				$output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>');
166
-
167
-				foreach ($table->getIndexes() as $index) {
168
-					$columns = $index->getColumns();
169
-					if ($columns === ['poll_token'] ||
170
-						$columns === ['login_token'] ||
171
-						$columns === ['timestamp']) {
172
-						$table->dropIndex($index->getName());
173
-					}
174
-				}
175
-
176
-				$table->addUniqueIndex(['poll_token'], 'poll_token');
177
-				$table->addUniqueIndex(['login_token'], 'login_token');
178
-				$table->addIndex(['timestamp'], 'timestamp');
179
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
180
-				$updated = true;
181
-				$output->writeln('<info>login_flow_v2 table updated successfully.</info>');
182
-			}
183
-		}
184
-
185
-		$output->writeln('<info>Check indices of the whats_new table.</info>');
186
-		if ($schema->hasTable('whats_new')) {
187
-			$table = $schema->getTable('whats_new');
188
-			if (!$table->hasIndex('version')) {
189
-				$output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>');
190
-
191
-				foreach ($table->getIndexes() as $index) {
192
-					if ($index->getColumns() === ['version']) {
193
-						$table->dropIndex($index->getName());
194
-					}
195
-				}
196
-
197
-				$table->addUniqueIndex(['version'], 'version');
198
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
199
-				$updated = true;
200
-				$output->writeln('<info>whats_new table updated successfully.</info>');
201
-			}
202
-		}
203
-
204
-		$output->writeln('<info>Check indices of the cards table.</info>');
205
-		$cardsUpdated = false;
206
-		if ($schema->hasTable('cards')) {
207
-			$table = $schema->getTable('cards');
208
-
209
-			if ($table->hasIndex('addressbookid_uri_index')) {
210
-				$output->writeln('<info>Renaming addressbookid_uri_index index to  to the cards table, this can take some time...</info>');
211
-
212
-				foreach ($table->getIndexes() as $index) {
213
-					if ($index->getColumns() === ['addressbookid', 'uri']) {
214
-						$table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
215
-					}
216
-				}
217
-
218
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
219
-				$cardsUpdated = true;
220
-			}
221
-
222
-			if (!$table->hasIndex('cards_abid')) {
223
-				$output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
224
-
225
-				foreach ($table->getIndexes() as $index) {
226
-					if ($index->getColumns() === ['addressbookid']) {
227
-						$table->dropIndex($index->getName());
228
-					}
229
-				}
230
-
231
-				$table->addIndex(['addressbookid'], 'cards_abid');
232
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
233
-				$cardsUpdated = true;
234
-			}
235
-
236
-			if (!$table->hasIndex('cards_abiduri')) {
237
-				$output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
238
-
239
-				foreach ($table->getIndexes() as $index) {
240
-					if ($index->getColumns() === ['addressbookid', 'uri']) {
241
-						$table->dropIndex($index->getName());
242
-					}
243
-				}
244
-
245
-				$table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
246
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
247
-				$cardsUpdated = true;
248
-			}
249
-
250
-			if ($cardsUpdated) {
251
-				$updated = true;
252
-				$output->writeln('<info>cards table updated successfully.</info>');
253
-			}
254
-		}
255
-
256
-		$output->writeln('<info>Check indices of the cards_properties table.</info>');
257
-		if ($schema->hasTable('cards_properties')) {
258
-			$table = $schema->getTable('cards_properties');
259
-			if (!$table->hasIndex('cards_prop_abid')) {
260
-				$output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>');
261
-
262
-				foreach ($table->getIndexes() as $index) {
263
-					if ($index->getColumns() === ['addressbookid']) {
264
-						$table->dropIndex($index->getName());
265
-					}
266
-				}
267
-
268
-				$table->addIndex(['addressbookid'], 'cards_prop_abid');
269
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
270
-				$updated = true;
271
-				$output->writeln('<info>cards_properties table updated successfully.</info>');
272
-			}
273
-		}
274
-
275
-		$output->writeln('<info>Check indices of the calendarobjects_props table.</info>');
276
-		if ($schema->hasTable('calendarobjects_props')) {
277
-			$table = $schema->getTable('calendarobjects_props');
278
-			if (!$table->hasIndex('calendarobject_calid_index')) {
279
-				$output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>');
280
-
281
-				$table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index');
282
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
283
-				$updated = true;
284
-				$output->writeln('<info>calendarobjects_props table updated successfully.</info>');
285
-			}
286
-		}
287
-
288
-		$output->writeln('<info>Check indices of the schedulingobjects table.</info>');
289
-		if ($schema->hasTable('schedulingobjects')) {
290
-			$table = $schema->getTable('schedulingobjects');
291
-			if (!$table->hasIndex('schedulobj_principuri_index')) {
292
-				$output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>');
293
-
294
-				$table->addIndex(['principaluri'], 'schedulobj_principuri_index');
295
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
296
-				$updated = true;
297
-				$output->writeln('<info>schedulingobjects table updated successfully.</info>');
298
-			}
299
-		}
300
-
301
-		$output->writeln('<info>Check indices of the oc_properties table.</info>');
302
-		if ($schema->hasTable('properties')) {
303
-			$table = $schema->getTable('properties');
304
-			if (!$table->hasIndex('properties_path_index')) {
305
-				$output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>');
306
-
307
-				$table->addIndex(['userid', 'propertypath'], 'properties_path_index');
308
-				$this->connection->migrateToSchema($schema->getWrappedSchema());
309
-				$updated = true;
310
-				$output->writeln('<info>oc_properties table updated successfully.</info>');
311
-			}
312
-		}
313
-
314
-		if (!$updated) {
315
-			$output->writeln('<info>Done.</info>');
316
-		}
317
-	}
55
+    /** @var Connection */
56
+    private $connection;
57
+
58
+    /** @var EventDispatcherInterface */
59
+    private $dispatcher;
60
+
61
+    public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
62
+        parent::__construct();
63
+
64
+        $this->connection = $connection;
65
+        $this->dispatcher = $dispatcher;
66
+    }
67
+
68
+    protected function configure() {
69
+        $this
70
+            ->setName('db:add-missing-indices')
71
+            ->setDescription('Add missing indices to the database tables');
72
+    }
73
+
74
+    protected function execute(InputInterface $input, OutputInterface $output): int {
75
+        $this->addCoreIndexes($output);
76
+
77
+        // Dispatch event so apps can also update indexes if needed
78
+        $event = new GenericEvent($output);
79
+        $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
80
+        return 0;
81
+    }
82
+
83
+    /**
84
+     * add missing indices to the share table
85
+     *
86
+     * @param OutputInterface $output
87
+     * @throws \Doctrine\DBAL\Schema\SchemaException
88
+     */
89
+    private function addCoreIndexes(OutputInterface $output) {
90
+        $output->writeln('<info>Check indices of the share table.</info>');
91
+
92
+        $schema = new SchemaWrapper($this->connection);
93
+        $updated = false;
94
+
95
+        if ($schema->hasTable('share')) {
96
+            $table = $schema->getTable('share');
97
+            if (!$table->hasIndex('share_with_index')) {
98
+                $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>');
99
+                $table->addIndex(['share_with'], 'share_with_index');
100
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
101
+                $updated = true;
102
+                $output->writeln('<info>Share table updated successfully.</info>');
103
+            }
104
+
105
+            if (!$table->hasIndex('parent_index')) {
106
+                $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>');
107
+                $table->addIndex(['parent'], 'parent_index');
108
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
109
+                $updated = true;
110
+                $output->writeln('<info>Share table updated successfully.</info>');
111
+            }
112
+
113
+            if (!$table->hasIndex('owner_index')) {
114
+                $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>');
115
+                $table->addIndex(['uid_owner'], 'owner_index');
116
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
117
+                $updated = true;
118
+                $output->writeln('<info>Share table updated successfully.</info>');
119
+            }
120
+
121
+            if (!$table->hasIndex('initiator_index')) {
122
+                $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>');
123
+                $table->addIndex(['uid_initiator'], 'initiator_index');
124
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
125
+                $updated = true;
126
+                $output->writeln('<info>Share table updated successfully.</info>');
127
+            }
128
+        }
129
+
130
+        $output->writeln('<info>Check indices of the filecache table.</info>');
131
+        if ($schema->hasTable('filecache')) {
132
+            $table = $schema->getTable('filecache');
133
+            if (!$table->hasIndex('fs_mtime')) {
134
+                $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>');
135
+                $table->addIndex(['mtime'], 'fs_mtime');
136
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
137
+                $updated = true;
138
+                $output->writeln('<info>Filecache table updated successfully.</info>');
139
+            }
140
+            if (!$table->hasIndex('fs_size')) {
141
+                $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
142
+                $table->addIndex(['size'], 'fs_size');
143
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
144
+                $updated = true;
145
+                $output->writeln('<info>Filecache table updated successfully.</info>');
146
+            }
147
+        }
148
+
149
+        $output->writeln('<info>Check indices of the twofactor_providers table.</info>');
150
+        if ($schema->hasTable('twofactor_providers')) {
151
+            $table = $schema->getTable('twofactor_providers');
152
+            if (!$table->hasIndex('twofactor_providers_uid')) {
153
+                $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
154
+                $table->addIndex(['uid'], 'twofactor_providers_uid');
155
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
156
+                $updated = true;
157
+                $output->writeln('<info>Twofactor_providers table updated successfully.</info>');
158
+            }
159
+        }
160
+
161
+        $output->writeln('<info>Check indices of the login_flow_v2 table.</info>');
162
+        if ($schema->hasTable('login_flow_v2')) {
163
+            $table = $schema->getTable('login_flow_v2');
164
+            if (!$table->hasIndex('poll_token')) {
165
+                $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>');
166
+
167
+                foreach ($table->getIndexes() as $index) {
168
+                    $columns = $index->getColumns();
169
+                    if ($columns === ['poll_token'] ||
170
+                        $columns === ['login_token'] ||
171
+                        $columns === ['timestamp']) {
172
+                        $table->dropIndex($index->getName());
173
+                    }
174
+                }
175
+
176
+                $table->addUniqueIndex(['poll_token'], 'poll_token');
177
+                $table->addUniqueIndex(['login_token'], 'login_token');
178
+                $table->addIndex(['timestamp'], 'timestamp');
179
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
180
+                $updated = true;
181
+                $output->writeln('<info>login_flow_v2 table updated successfully.</info>');
182
+            }
183
+        }
184
+
185
+        $output->writeln('<info>Check indices of the whats_new table.</info>');
186
+        if ($schema->hasTable('whats_new')) {
187
+            $table = $schema->getTable('whats_new');
188
+            if (!$table->hasIndex('version')) {
189
+                $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>');
190
+
191
+                foreach ($table->getIndexes() as $index) {
192
+                    if ($index->getColumns() === ['version']) {
193
+                        $table->dropIndex($index->getName());
194
+                    }
195
+                }
196
+
197
+                $table->addUniqueIndex(['version'], 'version');
198
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
199
+                $updated = true;
200
+                $output->writeln('<info>whats_new table updated successfully.</info>');
201
+            }
202
+        }
203
+
204
+        $output->writeln('<info>Check indices of the cards table.</info>');
205
+        $cardsUpdated = false;
206
+        if ($schema->hasTable('cards')) {
207
+            $table = $schema->getTable('cards');
208
+
209
+            if ($table->hasIndex('addressbookid_uri_index')) {
210
+                $output->writeln('<info>Renaming addressbookid_uri_index index to  to the cards table, this can take some time...</info>');
211
+
212
+                foreach ($table->getIndexes() as $index) {
213
+                    if ($index->getColumns() === ['addressbookid', 'uri']) {
214
+                        $table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
215
+                    }
216
+                }
217
+
218
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
219
+                $cardsUpdated = true;
220
+            }
221
+
222
+            if (!$table->hasIndex('cards_abid')) {
223
+                $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
224
+
225
+                foreach ($table->getIndexes() as $index) {
226
+                    if ($index->getColumns() === ['addressbookid']) {
227
+                        $table->dropIndex($index->getName());
228
+                    }
229
+                }
230
+
231
+                $table->addIndex(['addressbookid'], 'cards_abid');
232
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
233
+                $cardsUpdated = true;
234
+            }
235
+
236
+            if (!$table->hasIndex('cards_abiduri')) {
237
+                $output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
238
+
239
+                foreach ($table->getIndexes() as $index) {
240
+                    if ($index->getColumns() === ['addressbookid', 'uri']) {
241
+                        $table->dropIndex($index->getName());
242
+                    }
243
+                }
244
+
245
+                $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
246
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
247
+                $cardsUpdated = true;
248
+            }
249
+
250
+            if ($cardsUpdated) {
251
+                $updated = true;
252
+                $output->writeln('<info>cards table updated successfully.</info>');
253
+            }
254
+        }
255
+
256
+        $output->writeln('<info>Check indices of the cards_properties table.</info>');
257
+        if ($schema->hasTable('cards_properties')) {
258
+            $table = $schema->getTable('cards_properties');
259
+            if (!$table->hasIndex('cards_prop_abid')) {
260
+                $output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>');
261
+
262
+                foreach ($table->getIndexes() as $index) {
263
+                    if ($index->getColumns() === ['addressbookid']) {
264
+                        $table->dropIndex($index->getName());
265
+                    }
266
+                }
267
+
268
+                $table->addIndex(['addressbookid'], 'cards_prop_abid');
269
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
270
+                $updated = true;
271
+                $output->writeln('<info>cards_properties table updated successfully.</info>');
272
+            }
273
+        }
274
+
275
+        $output->writeln('<info>Check indices of the calendarobjects_props table.</info>');
276
+        if ($schema->hasTable('calendarobjects_props')) {
277
+            $table = $schema->getTable('calendarobjects_props');
278
+            if (!$table->hasIndex('calendarobject_calid_index')) {
279
+                $output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>');
280
+
281
+                $table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index');
282
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
283
+                $updated = true;
284
+                $output->writeln('<info>calendarobjects_props table updated successfully.</info>');
285
+            }
286
+        }
287
+
288
+        $output->writeln('<info>Check indices of the schedulingobjects table.</info>');
289
+        if ($schema->hasTable('schedulingobjects')) {
290
+            $table = $schema->getTable('schedulingobjects');
291
+            if (!$table->hasIndex('schedulobj_principuri_index')) {
292
+                $output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>');
293
+
294
+                $table->addIndex(['principaluri'], 'schedulobj_principuri_index');
295
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
296
+                $updated = true;
297
+                $output->writeln('<info>schedulingobjects table updated successfully.</info>');
298
+            }
299
+        }
300
+
301
+        $output->writeln('<info>Check indices of the oc_properties table.</info>');
302
+        if ($schema->hasTable('properties')) {
303
+            $table = $schema->getTable('properties');
304
+            if (!$table->hasIndex('properties_path_index')) {
305
+                $output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>');
306
+
307
+                $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
308
+                $this->connection->migrateToSchema($schema->getWrappedSchema());
309
+                $updated = true;
310
+                $output->writeln('<info>oc_properties table updated successfully.</info>');
311
+            }
312
+        }
313
+
314
+        if (!$updated) {
315
+            $output->writeln('<info>Done.</info>');
316
+        }
317
+    }
318 318
 }
Please login to merge, or discard this patch.