/** * Check and repair tables. * * @return CheckResponse */ public function repairTables() { // When repairing tables we want to start with an empty flashbag. Otherwise we get another // 'repair your DB'-notice, right after we're done repairing. $this->app['logger.flash']->clear(); $response = new CheckResponse(); $currentTables = $this->getTableObjects(); /** @var $schemaManager AbstractSchemaManager */ $schemaManager = $this->app['db']->getSchemaManager(); $comparator = new Comparator(); $tables = $this->getTablesSchema(); /** @var $table Table */ foreach ($tables as $table) { $tableName = $table->getName(); // Create the users table. if (!isset($currentTables[$tableName])) { /** @var $platform AbstractPlatform */ $platform = $this->app['db']->getDatabasePlatform(); $queries = $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES | AbstractPlatform::CREATE_FOREIGNKEYS); foreach ($queries as $query) { $this->app['db']->query($query); } $response->addTitle($tableName, sprintf('Created table `%s`.', $tableName)); } else { $diff = $comparator->diffTable($currentTables[$tableName], $table); if ($diff) { $diff = $this->cleanupTableDiff($diff); // diff may be just deleted columns which we have reset above // only exec and add output if does really alter anything if ($this->app['db']->getDatabasePlatform()->getAlterTableSQL($diff)) { $schemaManager->alterTable($diff); $response->addTitle($tableName, sprintf('Updated `%s` table to match current schema.', $tableName)); } } } } return $response; }