]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Conversation entries where id==0 would screw up the "re-auto-increment" sequencing
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 6 Jan 2016 21:26:17 +0000 (22:26 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 6 Jan 2016 21:26:17 +0000 (22:26 +0100)
classes/Conversation.php

index 3bad400174f116d01e345d718f6ffba231c4ddd5..1dba2c1f4a346ae6db4decc850376d53fed7581d 100644 (file)
@@ -34,7 +34,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 class Conversation extends Managed_DataObject
 {
     public $__table = 'conversation';        // table name
-    public $id;                              // int(4)  primary_key not_null
+    public $id;                              // int(4)  primary_key not_null auto_increment
     public $uri;                             // varchar(191)  unique_key   not 255 because utf8mb4 takes more space
     public $created;                         // datetime   not_null
     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
@@ -55,6 +55,32 @@ class Conversation extends Managed_DataObject
         );
     }
 
+    static public function beforeSchemaUpdate()
+    {
+        $table = strtolower(get_called_class());
+        $schema = Schema::get();
+        $schemadef = $schema->getTableDef($table);
+
+        // 2016-01-06 We have to make sure there is no conversation with id==0 since it will screw up auto increment resequencing
+        if ($schemadef['fields']['id']['auto_increment']) {
+            // since we already have auto incrementing ('serial') we can continue
+            return;
+        }
+
+        // The conversation will be recreated in upgrade.php, which will
+        // generate a new URI, but that's collateral damage for you.
+        $conv = new Conversation();
+        $conv->id = 0;
+        if ($conv->find()) {
+            while ($conv->fetch()) {
+                // Since we have filtered on 0 this only deletes such entries
+                // which I have been afraid wouldn't work, but apparently does!
+                // (I thought it would act as null or something and find _all_ conversation entries)
+                $conv->delete();
+            }
+        }
+    }
+
     /**
      * Factory method for creating a new conversation.
      *