Ward againt contact_id = 0 in UpdateContact worker

- Add parameter validation in Worker\UpdateContact::add
- Address https://github.com/friendica/friendica/issues/12487#issuecomment-1366833644
This commit is contained in:
Hypolite Petovan 2022-12-28 19:09:34 -05:00
parent 5af956b92f
commit e563de4de7
5 changed files with 71 additions and 17 deletions

View file

@ -63,15 +63,21 @@ class UpdateContacts
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);