X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FUpdateContact.php;h=c2e443282056381cae6594c1c88d7a618e1d7e1f;hb=f609e38600f54fe8465d1194008d823103f41baa;hp=ae3b06b5067dc5ee2b0e22293ac2c5a2d8bf6387;hpb=00071abf51bf37d5153e5742b5676c9d9e51aca9;p=friendica.git diff --git a/src/Worker/UpdateContact.php b/src/Worker/UpdateContact.php index ae3b06b506..c2e4432820 100644 --- a/src/Worker/UpdateContact.php +++ b/src/Worker/UpdateContact.php @@ -1,28 +1,71 @@ . + * */ namespace Friendica\Worker; use Friendica\Core\Logger; +use Friendica\Core\Worker; use Friendica\Model\Contact; -use Friendica\Util\DateTimeFormat; -use Friendica\Database\DBA; +use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Util\Network; class UpdateContact { - public static function execute($contact_id) + /** + * Update contact data via probe + * + * @param int $contact_id Contact ID + * @return void + * @throws InternalServerErrorException + * @throws \ImagickException + */ + public static function execute(int $contact_id) { - $success = Contact::updateFromProbe($contact_id); - // Update the "updated" field if the contact could be probed. - // We don't do this in the function above, since we don't want to - // update the contact whenever that function is called from anywhere. - if ($success) { - DBA::update('contact', ['updated' => DateTimeFormat::utcNow()], ['id' => $contact_id]); + // Silently dropping the task if the contact is blocked + if (Contact::isBlocked($contact_id)) { + return; } + $success = Contact::updateFromProbe($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'); + } + + // Dropping the task if the contact is blocked + if (Contact::isBlocked($contact_id)) { + return 0; + } + + return Worker::add($run_parameters, 'UpdateContact', $contact_id); + } }