diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 0408ea78a..6a5769399 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -3321,7 +3321,7 @@ class Contact continue; } $contact = self::getByURL($url, false, ['id', 'updated']); - if (empty($contact['id'])) { + if (empty($contact['id']) && Network::isValidHttpUrl($url)) { Worker::add(PRIORITY_LOW, 'AddContact', 0, $url); ++$added; } elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) { diff --git a/src/Model/ItemURI.php b/src/Model/ItemURI.php index 75d9cdc70..a19662735 100644 --- a/src/Model/ItemURI.php +++ b/src/Model/ItemURI.php @@ -21,8 +21,10 @@ namespace Friendica\Model; +use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\Database\DBA; +use Friendica\DI; class ItemURI { @@ -35,14 +37,16 @@ class ItemURI */ public static function insert(array $fields) { + $fields = DI::dbaDefinition()->truncateFieldsForTable('item-uri', $fields); + if (!DBA::exists('item-uri', ['uri' => $fields['uri']])) { - DBA::insert('item-uri', $fields, Database::INSERT_UPDATE); + DBA::insert('item-uri', $fields, Database::INSERT_IGNORE); } $itemuri = DBA::selectFirst('item-uri', ['id', 'guid'], ['uri' => $fields['uri']]); - if (!DBA::isResult($itemuri)) { // This shouldn't happen + Logger::warning('Item-uri not found', $fields); return null; } @@ -77,22 +81,4 @@ class ItemURI return $itemuri['id'] ?? 0; } - - /** - * Searched for an id of a given guid. - * - * @param string $guid - * @return integer item-uri id - * @throws \Exception - */ - public static function getIdByGUID(string $guid): int - { - $itemuri = DBA::selectFirst('item-uri', ['id'], ['guid' => $guid]); - - if (!DBA::isResult($itemuri)) { - return 0; - } - - return $itemuri['id']; - } } diff --git a/src/Module/ActivityPub/Objects.php b/src/Module/ActivityPub/Objects.php index d52c02bef..96b3f638e 100644 --- a/src/Module/ActivityPub/Objects.php +++ b/src/Module/ActivityPub/Objects.php @@ -98,7 +98,7 @@ class Objects extends BaseModule Network::checkEtagModified($etag, $last_modified); if (empty($this->parameters['activity']) && ($item['gravity'] != GRAVITY_ACTIVITY)) { - $activity = ActivityPub\Transmitter::createActivityFromItem($item['id'], true); + $activity = ActivityPub\Transmitter::createCachedActivityFromItem($item['id'], false, true); if (empty($activity['type'])) { throw new HTTPException\NotFoundException(); } @@ -115,7 +115,7 @@ class Objects extends BaseModule } elseif (empty($this->parameters['activity']) || in_array($this->parameters['activity'], ['Create', 'Announce', 'Update', 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'Follow', 'Add'])) { - $data = ActivityPub\Transmitter::createActivityFromItem($item['id']); + $data = ActivityPub\Transmitter::createCachedActivityFromItem($item['id']); if (empty($data)) { throw new HTTPException\NotFoundException(); } diff --git a/src/Module/Settings/Account.php b/src/Module/Settings/Account.php index dcbb1861f..373f1614d 100644 --- a/src/Module/Settings/Account.php +++ b/src/Module/Settings/Account.php @@ -38,6 +38,7 @@ use Friendica\Model\Verb; use Friendica\Module\BaseSettings; use Friendica\Network\HTTPException; use Friendica\Protocol\Activity; +use Friendica\Util\Network; use Friendica\Util\Temporal; use Friendica\Worker\Delivery; @@ -373,7 +374,7 @@ class Account extends BaseSettings // or the handle of the account, therefore we check for either // "http" or "@" to be present in the string. // All other fields from the row will be ignored - if ((strpos($csvRow[0], '@') !== false) || in_array(parse_url($csvRow[0], PHP_URL_SCHEME), ['http', 'https'])) { + if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) { Worker::add(PRIORITY_MEDIUM, 'AddContact', local_user(), $csvRow[0]); } else { Logger::notice('Invalid account', ['url' => $csvRow[0]]); diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 18d0cc65f..162745c39 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1185,9 +1185,9 @@ class Transmitter * @return array|false activity or false on failure * @throws \Exception */ - public static function createCachedActivityFromItem(int $item_id, bool $force = false) + public static function createCachedActivityFromItem(int $item_id, bool $force = false, bool $object_mode = false) { - $cachekey = 'APDelivery:createActivity:' . $item_id; + $cachekey = 'APDelivery:createActivity:' . $item_id . ':' . (int)$object_mode; if (!$force) { $data = DI::cache()->get($cachekey); @@ -1196,7 +1196,7 @@ class Transmitter } } - $data = self::createActivityFromItem($item_id); + $data = self::createActivityFromItem($item_id, $object_mode); DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR); return $data; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index bd5cdd93e..9f1ab1585 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -795,7 +795,7 @@ return [ "conversation" => ["type" => "varbinary(383)", "comment" => ""], "type" => ["type" => "varchar(64)", "comment" => "Type of the activity"], "object-type" => ["type" => "varchar(64)", "comment" => "Type of the object activity"], - "object-object-type" => ["type" => "varchar(64)", "comment" => "Type of the object's object activity"], + "object-object-type" => ["type" => "varchar(64)", "comment" => "Type of the object's object activity"], "received" => ["type" => "datetime", "comment" => "Receiving date"], "activity" => ["type" => "mediumtext", "comment" => "The JSON activity"], "signer" => ["type" => "varchar(255)", "comment" => ""], diff --git a/static/defaults.config.php b/static/defaults.config.php index 926cdd7d3..7625de0bd 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -643,7 +643,7 @@ return [ 'worker_load_exponent' => 3, // worker_processes_cooldown (Integer) - // Maximum number pro processes that causes a cooldown before each worker function call. + // Maximum number per processes that causes a cooldown before each worker function call. 'worker_processes_cooldown' => 0, // worker_multiple_fetch (Boolean)