* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
class SchemaUpdater
{
public function __construct($schema)
{
$this->schema = $schema;
- $this->conn = $conn;
$this->checksums = $this->getChecksums();
}
*/
public function register($tableName, array $tableDef)
{
+ // Check if the table we're registering is related to a Managed_DataObject
+ if (is_a(ucfirst($tableName), 'Managed_DataObject', true)) {
+ call_user_func("{$tableName}::beforeSchemaUpdate");
+ }
+
$this->tables[$tableName] = $tableDef;
}
/**
+ * Go ping em!
+ *
* @fixme handle tables that belong on different database servers...?
*/
- public function checkTables()
+ public function checkSchema()
{
$checksums = $this->checksums;
foreach ($this->tables as $table => $def) {
- $checksum = $this->tableChecksum($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) {
} 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();
}
}
{
$checksums = array();
- $sv = new Schema_version();
- $sv->find();
- while ($sv->fetch()) {
- $checksums[$sv->table_name] = $sv->checksum;
+ 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.");
}
return $checksums;
*/
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();
+ 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.");
}
$this->checksums[$table] = $checksum;
}