X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fschemaupdater.php;h=1960a0693001c6948191dcf629b71c1bab38945e;hb=700018fd09be222d9ec163965fd1a3f277d2b931;hp=b872b0d5785443317cac587461ca145d451c4d82;hpb=e7c7fd39fc948f1169512916077185dd29973b60;p=quix0rs-gnu-social.git diff --git a/lib/schemaupdater.php b/lib/schemaupdater.php index b872b0d578..1960a06930 100644 --- a/lib/schemaupdater.php +++ b/lib/schemaupdater.php @@ -37,19 +37,28 @@ class SchemaUpdater public function __construct($schema) { $this->schema = $schema; - $this->conn = $conn; $this->checksums = $this->getChecksums(); } /** - * @param array $tableDefs + * @param string $tableName + * @param array $tableDef + */ + public function register($tableName, array $tableDef) + { + $this->tables[$tableName] = $tableDef; + } + + /** + * Go ping em! + * * @fixme handle tables that belong on different database servers...? */ - public function checkTables(array $tableDefs) + public function checkSchema() { $checksums = $this->checksums; - foreach ($tableDefs as $table => $def) { - $checksum = $this->tableChecksum($def); + foreach ($this->tables as $table => $def) { + $checksum = $this->checksum($def); if (empty($checksums[$table])) { common_log(LOG_DEBUG, "No previous schema_version for $table: updating to $checksum"); } else if ($checksums[$table] == $checksum) { @@ -58,10 +67,10 @@ class SchemaUpdater } else { common_log(LOG_DEBUG, "Last schema_version for $table is {$checksums[$table]}: updating to $checksum"); } - $this->conn->query('BEGIN'); + //$this->conn->query('BEGIN'); $this->schema->ensureTable($table, $def); $this->saveChecksum($table, $checksum); - $this->conn->commit(); + //$this->conn->commit(); } } @@ -86,11 +95,20 @@ class SchemaUpdater { $checksums = array(); - $sv = new Schema_version(); - $sv->find(); - while ($sv->fetch()) { - $checksums[$sv->table_name] = $sv->checksum; + PEAR::pushErrorHandling(PEAR_ERROR_EXCEPTION); + try { + $sv = new Schema_version(); + $sv->find(); + while ($sv->fetch()) { + $checksums[$sv->table_name] = $sv->checksum; + } + + return $checksums; + } catch (Exception $e) { + // no dice! + common_log(LOG_DEBUG, "Possibly schema_version table doesn't exist yet."); } + PEAR::popErrorHandling(); return $checksums; } @@ -103,15 +121,22 @@ class SchemaUpdater */ protected function saveChecksum($table, $checksum) { - $sv = new Schema_version(); - $sv->table_name = $table; - $sv->checksum = $checksum; - $sv->modified = common_sql_now(); - if (isset($this->checksums[$table])) { - $sv->update(); - } else { - $sv->insert(); + PEAR::pushErrorHandling(PEAR_ERROR_EXCEPTION); + try { + $sv = new Schema_version(); + $sv->table_name = $table; + $sv->checksum = $checksum; + $sv->modified = common_sql_now(); + if (isset($this->checksums[$table])) { + $sv->update(); + } else { + $sv->insert(); + } + } catch (Exception $e) { + // no dice! + common_log(LOG_DEBUG, "Possibly schema_version table doesn't exist yet."); } + PEAR::popErrorHandling(); $this->checksums[$table] = $checksum; } }