]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11853/11867: Fix reshare of public posts
authorMichael <heluecht@pirati.ca>
Sat, 27 Aug 2022 21:22:49 +0000 (21:22 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 27 Aug 2022 21:22:49 +0000 (21:22 +0000)
src/Database/Database.php
src/Model/FContact.php
src/Model/Item.php
src/Module/Item/Activity.php
src/Protocol/ActivityPub/Processor.php

index cd2803c0fc5c88368766a76c991beba2a94c8acd..fde5bd9f10133b20fd63f8bc4a12add3a8e77d99 100644 (file)
@@ -68,7 +68,7 @@ class Database
        protected $connection;
        protected $driver = '';
        protected $pdo_emulate_prepares = false;
-       private $error          = false;
+       private $error          = '';
        private $errorno        = 0;
        private $affected_rows  = 0;
        protected $in_transaction = false;
@@ -558,8 +558,8 @@ class Database
                                if (count($args) == 0) {
                                        if (!$retval = $this->connection->query($this->replaceParameters($sql, $args))) {
                                                $errorInfo     = $this->connection->errorInfo();
-                                               $this->error   = $errorInfo[2];
-                                               $this->errorno = (int) $errorInfo[1];
+                                               $this->error   = (string)$errorInfo[2];
+                                               $this->errorno = (int)$errorInfo[1];
                                                $retval        = false;
                                                $is_error      = true;
                                                break;
@@ -571,8 +571,8 @@ class Database
                                /** @var $stmt mysqli_stmt|PDOStatement */
                                if (!$stmt = $this->connection->prepare($sql)) {
                                        $errorInfo     = $this->connection->errorInfo();
-                                       $this->error   = $errorInfo[2];
-                                       $this->errorno = (int) $errorInfo[1];
+                                       $this->error   = (string)$errorInfo[2];
+                                       $this->errorno = (int)$errorInfo[1];
                                        $retval        = false;
                                        $is_error      = true;
                                        break;
@@ -591,8 +591,8 @@ class Database
 
                                if (!$stmt->execute()) {
                                        $errorInfo     = $stmt->errorInfo();
-                                       $this->error   = $errorInfo[2];
-                                       $this->errorno = (int) $errorInfo[1];
+                                       $this->error   = (string)$errorInfo[2];
+                                       $this->errorno = (int)$errorInfo[1];
                                        $retval        = false;
                                        $is_error      = true;
                                } else {
@@ -610,8 +610,8 @@ class Database
                                if (!$can_be_prepared || (count($args) == 0)) {
                                        $retval = $this->connection->query($this->replaceParameters($sql, $args));
                                        if ($this->connection->errno) {
-                                               $this->error   = $this->connection->error;
-                                               $this->errorno = $this->connection->errno;
+                                               $this->error   = (string)$this->connection->error;
+                                               $this->errorno = (int)$this->connection->errno;
                                                $retval        = false;
                                                $is_error      = true;
                                        } else {
@@ -627,8 +627,8 @@ class Database
                                $stmt = $this->connection->stmt_init();
 
                                if (!$stmt->prepare($sql)) {
-                                       $this->error   = $stmt->error;
-                                       $this->errorno = $stmt->errno;
+                                       $this->error   = (string)$stmt->error;
+                                       $this->errorno = (int)$stmt->errno;
                                        $retval        = false;
                                        $is_error      = true;
                                        break;
@@ -658,8 +658,8 @@ class Database
                                }
 
                                if (!$stmt->execute()) {
-                                       $this->error   = $this->connection->error;
-                                       $this->errorno = $this->connection->errno;
+                                       $this->error   = (string)$this->connection->error;
+                                       $this->errorno = (int)$this->connection->errno;
                                        $retval        = false;
                                        $is_error      = true;
                                } else {
@@ -726,8 +726,8 @@ class Database
                                }
                        }
 
-                       $this->error   = $error;
-                       $this->errorno = (int) $errorno;
+                       $this->error   = (string)$error;
+                       $this->errorno = (int)$errorno;
                }
 
                $this->profiler->stopRecording();
index 62e609fbee600bba8df99117910eda1e498ade00..8bc696a4668d2493c1d386ec3af68f037d8d051f 100644 (file)
@@ -24,6 +24,7 @@ namespace Friendica\Model;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
@@ -125,6 +126,7 @@ class FContact
 
                $condition = ['url' => $arr['url'], 'network' => $arr['network']];
 
+               $fields = DI::dbaDefinition()->truncateFieldsForTable('fcontact', $fields);
                DBA::update('fcontact', $fields, $condition, true);
        }
 
index 741594f228a3ae8d2d774c4249a8059ede7b412e..598fca84073fb4df2db22bfc936d499e51867ce3 100644 (file)
@@ -33,7 +33,6 @@ use Friendica\Model\Tag;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\Post;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Diaspora;
@@ -2545,7 +2544,7 @@ class Item
                }
 
                // Retrieve the current logged in user's public contact
-               $author_id = Contact::getIdForURL($owner['url']);
+               $author_id = Contact::getPublicIdByUserId($uid);
                if (empty($author_id)) {
                        Logger::info('Empty public contact');
                        return false;
@@ -2652,7 +2651,7 @@ class Item
                $new_item = [
                        'guid'          => System::createUUID(),
                        'uri'           => self::newURI(),
-                       'uid'           => $item['uid'],
+                       'uid'           => $uid,
                        'contact-id'    => $owner['id'],
                        'wall'          => $item['wall'],
                        'origin'        => 1,
@@ -2680,17 +2679,13 @@ class Item
                        $new_item['diaspora_signed_text'] = json_encode($signed);
                }
 
-               $new_item_id = self::insert($new_item);
+               self::insert($new_item, true);
 
                // If the parent item isn't visible then set it to visible
+               // @todo Check if this is still needed
                if (!$item['visible']) {
                        self::update(['visible' => true], ['id' => $item['id']]);
                }
-
-               $new_item['id'] = $new_item_id;
-
-               Hook::callAll('post_local_end', $new_item);
-
                return true;
        }
 
index 648ebfa08cdfe97e774bc869fb5eb15e40a6f51e..9f0b91786947858eac48257b1522335dcc2ece03 100644 (file)
@@ -51,9 +51,9 @@ class Activity extends BaseModule
                $itemId =  $this->parameters['id'];
 
                if (in_array($verb, ['announce', 'unannounce'])) {
-                       $item = Post::selectFirst(['network', 'uri-id', 'uid'], ['id' => $itemId]);
+                       $item = Post::selectFirst(['network', 'uri-id'], ['id' => $itemId, 'uid' => [local_user(), 0]]);
                        if ($item['network'] == Protocol::DIASPORA) {
-                               Diaspora::performReshare($item['uri-id'], $item['uid']);
+                               Diaspora::performReshare($item['uri-id'], local_user());
                        }
                }
 
index 61f625f597fc2f380c9d323262462cac490122b6..668b8a5b89b5e56d07f879e8d45fe12589aacd5e 100644 (file)
@@ -228,7 +228,7 @@ class Processor
        {
                $item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type', 'private'], ['uri' => $activity['id']]);
                if (!DBA::isResult($item)) {
-                       Logger::warning('No existing item, item will be created', ['uri' => $activity['id']]);
+                       Logger::notice('No existing item, item will be created', ['uri' => $activity['id']]);
                        $item = self::createItem($activity, false);
                        if (empty($item)) {
                                Queue::remove($activity);