X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FFeed.php;h=821de8c33580556f3d8675531a65ee5f6782a5b5;hb=4fbd0a46b58cae1f04059b1ab9b0df654940cba7;hp=ed3598e641655510586bc890e5e633fd8dc02baa;hpb=a7e0a1f7de82bc8f0919c2ea61258a3ae09e4eba;p=friendica.git diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index ed3598e641..821de8c335 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -29,6 +29,7 @@ use Friendica\Content\Text\HTML; use Friendica\Core\Cache\Duration; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -502,7 +503,10 @@ class Feed $items[] = $item; break; } elseif (!Item::isValid($item)) { - Logger::info('Feed is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); + Logger::info('Feed item is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); + continue; + } elseif (Item::isTooOld($item)) { + Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); continue; } @@ -602,7 +606,7 @@ class Feed // Additionally we have to avoid conflicts with identical URI between imported feeds and these items. if ($notify) { $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname()); - unset($item['uri']); + $item['uri'] = Item::newURI($item['uid'], $item['guid']); unset($item['thr-parent']); unset($item['parent-uri']); @@ -610,16 +614,21 @@ class Feed $notify = PRIORITY_MEDIUM; } - $postings[] = ['item' => $item, 'notify' => $notify, - 'taglist' => $taglist, 'attachments' => $attachments]; + if (!Post\Delayed::exists($item["uri"])) { + $postings[] = ['item' => $item, 'notify' => $notify, + 'taglist' => $taglist, 'attachments' => $attachments]; + } else { + Logger::info('Post already exists in the delayed posts queue', ['uri' => $item["uri"]]); + } } if (!empty($postings)) { + $min_posting = DI::config()->get('system', 'minimum_posting_interval', 0); $total = count($postings); if ($total > 1) { // Posts shouldn't be delayed more than a day - $interval = max(1440, self::getPollInterval($contact)); - $delay = round(($interval * 60) / $total); + $interval = min(1440, self::getPollInterval($contact)); + $delay = max(round(($interval * 60) / $total), 60 * $min_posting); Logger::notice('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]); } else { $delay = 0; @@ -629,25 +638,26 @@ class Feed foreach ($postings as $posting) { if ($delay > 0) { - $publish_at = DateTimeFormat::utc('now + ' . $post_delay . ' minute'); - Logger::notice('Got publishing date', ['delay' => $delay, 'publish_at' => $publish_at, 'cid' => $contact['id'], 'url' => $contact['url']]); + $publish_time = time() + $post_delay; + Logger::notice('Got publishing date', ['delay' => $delay, 'cid' => $contact['id'], 'url' => $contact['url']]); $post_delay += $delay; + } else { + $publish_time = time(); } - $id = Item::insert($posting['item'], $posting['notify']); - - Logger::notice("Feed for contact " . $contact["url"] . " stored under id " . $id); - - if (!empty($id) && (!empty($posting['taglist']) || !empty($posting['attachments']))) { - $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]); - foreach ($posting['taglist'] as $tag) { - Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag); - } - foreach ($posting['attachments'] as $attachment) { - $attachment['uri-id'] = $feeditem['uri-id']; - Post\Media::insert($attachment); - } + $last_publish = DI::pConfig()->get($posting['item']['uid'], 'system', 'last_publish', 0, true); + $next_publish = max($last_publish + (60 * $min_posting), time()); + if ($publish_time < $next_publish) { + Logger::notice('Adapting publish time', + ['last' => date(DateTimeFormat::MYSQL, $last_publish), + 'next' => date(DateTimeFormat::MYSQL, $next_publish), + 'publish' => date(DateTimeFormat::MYSQL, $publish_time)]); + $publish_time = $next_publish; } + $publish_at = date(DateTimeFormat::MYSQL, $publish_time); + + Post\Delayed::add($publish_at, $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']); + DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish); } }