use Friendica\Util\Network;
use Friendica\Util\Proxy;
use Friendica\Util\Strings;
+use Friendica\Worker\UpdateContact;
/**
* functions for interacting with a contact
// Update the contact in the background if needed
if ($background_update && !self::isLocal($url) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
- Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
+ try {
+ UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['contact' => $contact]);
+ }
}
// Remove the internal fields
$background_update = DI::config()->get('system', 'update_active_contacts') ? $contact['local-data'] : true;
if ($background_update && !self::isLocal($url) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
- Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
+ try {
+ UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['contact' => $contact]);
+ }
}
if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) {
if ($probed) {
self::updateFromProbeArray($contact_id, $ret);
} else {
- Worker::add(Worker::PRIORITY_HIGH, 'UpdateContact', $contact_id);
+ try {
+ UpdateContact::add(Worker::PRIORITY_HIGH, $contact['id']);
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['contact' => $contact]);
+ }
}
$result['success'] = Protocol::follow($uid, $contact, $protocol);
Worker::add(Worker::PRIORITY_LOW, 'AddContact', 0, $url);
++$added;
} elseif (!empty($contact['network']) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
- Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']);
- ++$updated;
+ try {
+ UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
+ ++$updated;
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['contact' => $contact]);
+ }
} else {
++$unchanged;
}
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
+use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
+use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Worker\UpdateContact;
/**
* Manages and show Contacts and their content
// pull feed and consume it, which should subscribe to the hub.
Worker::add(Worker::PRIORITY_HIGH, 'OnePoll', $contact_id, 'force');
} else {
- Worker::add(Worker::PRIORITY_HIGH, 'UpdateContact', $contact_id);
+ try {
+ UpdateContact::add(Worker::PRIORITY_HIGH, $contact_id);
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['contact' => $contact, 'callstack' => System::callstack()]);
+ }
}
}
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy;
+use Friendica\Worker\UpdateContact;
/**
* Photo Module
Logger::debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
}
if ($update) {
- Logger::info('Invalid file, contact update initiated', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
- Worker::add(Worker::PRIORITY_LOW, 'UpdateContact', $id);
+ try {
+ UpdateContact::add(Worker::PRIORITY_LOW, $id);
+ Logger::info('Invalid file, contact update initiated', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['id' => $id, 'contact' => $contact]);
+ }
} else {
Logger::info('Invalid file', ['cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
}
namespace Friendica\Worker;
use Friendica\Core\Logger;
+use Friendica\Core\Worker;
use Friendica\Model\Contact;
+use Friendica\Network\HTTPException\InternalServerErrorException;
class UpdateContact
{
/**
* Update contact data via probe
*
- * @param int $contact_id Contact ID
+ * @param int $contact_id Contact ID
* @return void
+ * @throws InternalServerErrorException
+ * @throws \ImagickException
*/
public static function execute(int $contact_id)
{
Logger::info('Updated from probe', ['id' => $contact_id, 'success' => $success]);
}
+
+ /**
+ * @param array|int $run_parameters Priority constant or array of options described in Worker::add
+ * @param int $contact_id
+ * @return int
+ * @throws InternalServerErrorException
+ */
+ public static function add($run_parameters, int $contact_id): int
+ {
+ if (!$contact_id) {
+ throw new \InvalidArgumentException('Invalid value provided for contact_id');
+ }
+
+ return Worker::add($run_parameters, 'UpdateContact', $contact_id);
+ }
}
if (Contact::isLocal($contact['url'])) {
continue;
}
- if ((!empty($contact['gsid']) || !empty($contact['baseurl'])) && GServer::reachable($contact)) {
- $stamp = (float)microtime(true);
- $success = Contact::updateFromProbe($contact['id']);
- Logger::debug('Direct update', ['id' => $contact['id'], 'count' => $count, 'duration' => round((float)microtime(true) - $stamp, 3), 'success' => $success]);
- ++$count;
- } elseif (Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id'])) {
- Logger::debug('Update by worker', ['id' => $contact['id'], 'count' => $count]);
- ++$count;
+
+ try {
+ if ((!empty($contact['gsid']) || !empty($contact['baseurl'])) && GServer::reachable($contact)) {
+ $stamp = (float)microtime(true);
+ $success = Contact::updateFromProbe($contact['id']);
+ Logger::debug('Direct update', ['id' => $contact['id'], 'count' => $count, 'duration' => round((float)microtime(true) - $stamp, 3), 'success' => $success]);
+ ++$count;
+ } elseif (UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id'])) {
+ Logger::debug('Update by worker', ['id' => $contact['id'], 'count' => $count]);
+ ++$count;
+ }
+ } catch (\InvalidArgumentException $e) {
+ Logger::notice($e->getMessage(), ['contact' => $contact]);
}
+
Worker::coolDown();
}
DBA::close($contacts);