]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Conversation.php
utf8mb4 conversion on database with index adjusts
[quix0rs-gnu-social.git] / classes / Conversation.php
index c8d922a2f0f50d6ef504b73a4b8da45cecdd9210..343668cc49d95e6632488c77f87668ed690aaecf 100644 (file)
@@ -35,7 +35,7 @@ class Conversation extends Managed_DataObject
 {
     public $__table = 'conversation';        // table name
     public $id;                              // int(4)  primary_key not_null
-    public $uri;                             // varchar(255)  unique_key
+    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
 
@@ -44,7 +44,7 @@ class Conversation extends Managed_DataObject
         return array(
             'fields' => array(
                 'id' => array('type' => 'int', 'not null' => true, 'description' => 'should be set from root notice id (since 2014-03-01 commit)'),
-                'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'URI of the conversation'),
+                'uri' => array('type' => 'varchar', 'not null'=>true, 'length' => 191, 'description' => 'URI of the conversation'),
                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
             ),
@@ -63,7 +63,7 @@ class Conversation extends Managed_DataObject
      *
      * @return Conversation the new conversation DO
      */
-    static function create(Notice $notice)
+    static function create(Notice $notice, $uri=null)
     {
         if (empty($notice->id)) {
             throw new ServerException(_('Tried to create conversation for not yet inserted notice'));
@@ -71,10 +71,11 @@ class Conversation extends Managed_DataObject
         $conv = new Conversation();
         $conv->created = common_sql_now();
         $conv->id = $notice->id;
-        $conv->uri = sprintf('%s%s=%d:%s=%s',
+        $conv->uri = $uri ?: sprintf('%s%s=%d:%s=%s:%s=%x',
                              TagURI::mint(),
                              'noticeId', $notice->id,
-                             'objectType', 'thread');
+                             'objectType', 'thread',
+                             'crc32', crc32($notice->content));
         $result = $conv->insert();
 
         if ($result === false) {