]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fixes to Deleted_notice
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 3 Oct 2015 14:07:19 +0000 (16:07 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 3 Oct 2015 14:07:19 +0000 (16:07 +0200)
plugins/ActivityModeration/classes/Deleted_notice.php

index 7c58f5b4553da912bd10dea24109885f7a72b603..f74ea331eef6ee9a17275dad4b3a91b163279b84 100644 (file)
@@ -37,7 +37,7 @@ class Deleted_notice extends Managed_DataObject
     {
         return array(
             'fields' => array(
-                'id' => array('type' => 'int', 'not null' => true, 'description' => 'identity of notice'),
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'notice ID'),
                 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'author of the notice'),
                 'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI of the deleted notice'),
                 'act_uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'URI of the delete activity, may exist in notice table'),
@@ -46,6 +46,7 @@ class Deleted_notice extends Managed_DataObject
             ),
             'primary key' => array('id'),
             'unique keys' => array(
+                'deleted_notice_uri_key' => array('uri'),
                 'deleted_notice_act_uri_key' => array('act_uri'),
             ),
             'indexes' => array(
@@ -99,7 +100,7 @@ class Deleted_notice extends Managed_DataObject
     {
         $class = get_called_class();
         $object = new $class;
-        $object->act_uri = $stored->getUri();
+        $object->uri = $stored->getUri();   // Lookup by delete activity's URI! (that's what is _stored_ in our db!)
         if (!$object->find(true)) {
             throw new NoResultException($object);
         }
@@ -111,6 +112,11 @@ class Deleted_notice extends Managed_DataObject
         return Profile::getByID($this->profile_id);
     }
 
+    public function getActorObject()
+    {
+        return $this->getActor()->asActivityObject();
+    }
+
     static public function getObjectType()
     {
         return 'activity';
@@ -166,11 +172,14 @@ class Deleted_notice extends Managed_DataObject
 
     static public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
+        // the original notice is deleted, but we have stored some important data
+        $object = self::fromStored($stored);
+
         $act->target = new ActivityObject();
-        $act->target->id = $stored->getUri();
+        $act->target->id = $object->getTargetUri();
         $act->objects = array(clone($act->target));
 
-        $act->context->replyToID = $stored->getUri();
+        $act->context->replyToID = $object->getTargetUri();
         $act->title = ActivityUtils::verbToTitle($act->verb);
     }
 
@@ -201,8 +210,8 @@ class Deleted_notice extends Managed_DataObject
         }
         echo "\nFound old $table table, upgrading it to contain 'act_uri' and 'act_created' field...";
 
-        $schemadef['fields']['act_uri'] = array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'URI of the delete activity, may exist in notice table');
-        $schemadef['fields']['act_created'] = array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created');
+        $schemadef['fields']['act_uri'] = array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'URI of the deleted notice');
+        $schemadef['fields']['act_created'] = array('type' => 'datetime', 'not null' => true, 'description' => 'datetime the notice record was created');
         unset($schemadef['unique keys']);
         $schema->ensureTable($table, $schemadef);
 
@@ -216,12 +225,14 @@ class Deleted_notice extends Managed_DataObject
         while($deleted->fetch()) {
             $orig = clone($deleted);
             $deleted->act_uri = $deleted->uri;
-            // this is a fake URI just to have something to put there to avoid NULL
-            $deleted->uri = TagURI::mint(strtolower(get_called_class()).':%d:%s:%s:%s',
+            // this is a fake URI just to have something to put there to avoid NULL. crc32 of uri is to avoid collisions
+            $deleted->uri = TagURI::mint(strtolower(get_called_class()).':%d:%s:%s:%s:crc32=%x',
                                 $deleted->profile_id,
                                 ActivityUtils::resolveUri(self::getObjectType(), true),
                                 'unknown',
-                                common_date_iso8601($deleted->created));
+                                common_date_iso8601($deleted->created),
+                                crc32($deleted->act_uri)
+                            );
             $deleted->act_created = $deleted->created;  // we don't actually know when the notice was created
             $deleted->updateWithKeys($orig, 'id');
             print ".";