/** * Add details of the table differences to the response object. * * @param string $tableName * @param TableDiff|false $diff * @param CheckResponse $response */ protected function addResponseDiff($tableName, $diff, CheckResponse $response) { if ($diff === false) { return; } $diff = $this->cleanupTableDiff($diff); if ($details = $this->app['db']->getDatabasePlatform()->getAlterTableSQL($diff)) { $response->addTitle($tableName, sprintf('Table `%s` is not the correct schema:', $tableName)); $response->checkDiff($tableName, $diff); // For debugging we keep the diffs $response->addDiffDetail($details); } }
/** * Check if all required tables and columns are present in the DB. * * @param boolean $hinting Return hints if true * * @return CheckResponse */ public function checkTablesIntegrity($hinting = false) { $response = new CheckResponse($hinting); $comparator = new Comparator(); $currentTables = $this->getTableObjects(); $tables = $this->getTablesSchema(); $valid = true; /** @var $table Table */ foreach ($tables as $table) { $tableName = $table->getName(); // Create the users table. if (!isset($currentTables[$tableName])) { $response->addTitle($tableName, sprintf('Table `%s` is not present.', $tableName)); } else { $diff = $comparator->diffTable($currentTables[$tableName], $table); if ($diff) { $diff = $this->cleanupTableDiff($diff); } if ($diff && ($details = $this->app['db']->getDatabasePlatform()->getAlterTableSQL($diff))) { $response->addTitle($tableName, sprintf('Table `%s` is not the correct schema:', $tableName)); $response->checkDiff($tableName, $this->cleanupTableDiff($diff)); // For debugging we keep the diffs $response->addDiffDetail($details); } } // If a table still has messages, we want to unset the valid state $valid = !$response->hasResponses(); // If we are using the debug logger, log the diffs foreach ($response->getDiffDetails() as $diff) { $this->app['logger.system']->debug('Database update required', $diff); } } // If there were no messages, update the timer, so we don't check it again. // If there _are_ messages, keep checking until it's fixed. if ($valid) { $this->markValid(); } return $response; }