]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/schemaupdater.php
Merge branch 'master' into nightly
[quix0rs-gnu-social.git] / lib / schemaupdater.php
index 64f7c596d44d7ca11b0f71854dedf35ac0ec0b3c..ae746c10b546a4919fde4ab68f63a6943c5194cc 100644 (file)
@@ -28,9 +28,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 class SchemaUpdater
 {
@@ -46,6 +44,11 @@ class SchemaUpdater
      */
     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;
     }
 
@@ -95,11 +98,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;
     }
@@ -112,15 +124,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;
     }
 }