]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/ActivityModeration/classes/Deleted_notice.php
newUri might as well be put in Managed_DataObject
[quix0rs-gnu-social.git] / plugins / ActivityModeration / classes / Deleted_notice.php
index 790e2ab38d6b3562e80738b6dfcc16d0257e312d..254d4107211a66b52138fa72830f8f1ffab40b8f 100644 (file)
@@ -30,15 +30,15 @@ class Deleted_notice extends Managed_DataObject
     public $profile_id;                      // int(4)   not_null
     public $uri;                             // varchar(191)  unique_key   not 255 because utf8mb4 takes more space
     public $act_uri;                         // varchar(191)  unique_key   not 255 because utf8mb4 takes more space
+    public $act_created;                     // datetime()   not_null
     public $created;                         // datetime()   not_null
-    public $deleted;                         // datetime()   not_null
 
     public static function schemaDef()
     {
         return array(
             'fields' => array(
-                'id' => array('type' => 'int', 'not null' => true, 'description' => 'identity of notice'),
-                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'author of the notice'),
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'notice ID'),
+                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile that deleted 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'),
                 'act_created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
@@ -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(
@@ -66,13 +67,9 @@ class Deleted_notice extends Managed_DataObject
         }
 
         $act = new Activity();
-        $act->type = ActivityObject::ACTIVITY;
         $act->verb = ActivityVerb::DELETE;
         $act->time = time();
-        $act->id   = TagURI::mint('deleted_notice:%d:%d:%s',
-                            $actor->getID(),
-                            $notice->getID(),
-                            common_date_iso8601(common_sql_now()));
+        $act->id   = $notice->getUri();
 
         $act->content = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice <a href="%3$s">{{%4$s}}</a>.'),
                             htmlspecialchars($actor->getUrl()),
@@ -84,6 +81,7 @@ class Deleted_notice extends Managed_DataObject
         $act->actor = $actor->asActivityObject();
         $act->target = new ActivityObject();    // We don't save the notice object, as it's supposed to be removed!
         $act->target->id = $notice->getUri();
+        $act->target->type = $notice->getObjectType();
         $act->objects = array(clone($act->target));
 
         $url = $notice->getUrl();
@@ -102,18 +100,25 @@ 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);
         }
         return $object;
     }
 
+    // The one who deleted the notice, not the notice's author
     public function getActor()
     {
         return Profile::getByID($this->profile_id);
     }
 
+    // As above: The one who deleted the notice, not the notice's author
+    public function getActorObject()
+    {
+        return $this->getActor()->asActivityObject();
+    }
+
     static public function getObjectType()
     {
         return 'activity';
@@ -123,36 +128,27 @@ class Deleted_notice extends Managed_DataObject
 
     public function getStored()
     {
-        $uri = $this->getTargetUri();
+        $uri = $this->getUri();
         if (!isset($this->_stored[$uri])) {
-            $stored = new Notice();
-            $stored->uri = $uri;
-            if (!$stored->find(true)) {
-                throw new NoResultException($stored);
-            }
-            $this->_stored[$uri] = $stored;
+            $this->_stored[$uri] = Notice::getByPK('uri', $uri);
         }
         return $this->_stored[$uri];
     }
 
-    public function getTargetUri()
-    {
-        return $this->uri;
-    }
-
     public function getUri()
     {
-        return $this->act_uri;
+        return $this->uri;
     }
 
     public function asActivityObject(Profile $scoped=null)
     {
         $actobj = new ActivityObject();
         $actobj->id = $this->getUri();
-        $actobj->type = ActivityUtils::resolveUri(self::getObjectType());
+        $actobj->type = ActivityObject::ACTIVITY;
         $actobj->actor = $this->getActorObject();
         $actobj->target = new ActivityObject();
-        $actobj->target->id = $this->getTargetUri();
+        $actobj->target->id = $this->getUri();
+        // FIXME: actobj->target->type? as in extendActivity, and actobj->target->actor maybe?
         $actobj->objects = array(clone($actobj->target));
         $actobj->verb = ActivityVerb::DELETE;
         $actobj->title = ActivityUtils::verbToTitle($actobj->verb);
@@ -161,22 +157,22 @@ class Deleted_notice extends Managed_DataObject
         $actobj->content = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice {{%3$s}}.'),
                             htmlspecialchars($actor->getUrl()),
                             htmlspecialchars($actor->getBestName()),
-                            htmlspecialchars($actor->getTargetUri())
+                            htmlspecialchars($this->getUri())
                            );
 
         return $actobj;
     }
 
-    static function newUri(Profile $actor, Managed_DataObject $object, $created=null)
+    static public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
-        if (is_null($created)) {
-            $created = common_sql_now();
-        }
-        return TagURI::mint(strtolower(get_called_class()).':%d:%s:%d:%s',
-                                        $actor->getID(),
-                                        ActivityUtils::resolveUri(self::getObjectType(), true),
-                                        $object->getID(),
-                                        common_date_iso8601($created));
+        // the original notice id and type is still stored in the Notice table
+        // so we use that information to describe the delete activity
+        $act->target = new ActivityObject();
+        $act->target->id = $stored->getUri();
+        $act->target->type = $stored->getObjectType();
+        $act->objects = array(clone($act->target));
+
+        $act->title = ActivityUtils::verbToTitle($act->verb);
     }
 
     static public function beforeSchemaUpdate()
@@ -194,8 +190,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);
 
@@ -209,12 +205,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 ".";