]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/schemaupdater.php
Introduced isCurrentProfileInScope() which shall check if current profile is
[quix0rs-gnu-social.git] / lib / schemaupdater.php
index 9577bceebf46b8eb5ac02125e1e959d1034a5ae9..d336135464a54c6ff083411f5ee12056334f416a 100644 (file)
@@ -37,7 +37,6 @@ class SchemaUpdater
     public function __construct($schema)
     {
         $this->schema = $schema;
-        $this->conn = $conn;
         $this->checksums = $this->getChecksums();
     }
 
@@ -51,25 +50,27 @@ class SchemaUpdater
     }
 
     /**
+     * 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");
+                common_debug("No previous schema_version for $table: updating to $checksum");
             } else if ($checksums[$table] == $checksum) {
-                common_log(LOG_DEBUG, "Last schema_version for $table up to date: $checksum");
+                common_debug("Last schema_version for $table up to date: $checksum");
                 continue;
             } else {
-                common_log(LOG_DEBUG, "Last schema_version for $table is {$checksums[$table]}: updating to $checksum");
+                common_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();
         }
     }
 
@@ -94,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_debug("Possibly schema_version table doesn't exist yet.");
         }
+        PEAR::popErrorHandling();
 
         return $checksums;
     }
@@ -111,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_debug("Possibly schema_version table doesn't exist yet.");
         }
+        PEAR::popErrorHandling();
         $this->checksums[$table] = $checksum;
     }
 }