+ /**
+ * Perform a contact update if the contact is outdated
+ *
+ * @param integer $id contact id
+ * @return bool
+ */
+ public static function updateByIdIfNeeded(int $id): bool
+ {
+ $contact = self::selectFirst(['url'], ["`id` = ? AND `next-update` < ?", $id, DateTimeFormat::utcNow()]);
+ if (empty($contact['url'])) {
+ return false;
+ }
+
+ if (self::isLocal($contact['url'])) {
+ return true;
+ }
+
+ $stamp = (float)microtime(true);
+ self::updateFromProbe($id);
+ Logger::debug('Contact data is updated.', ['duration' => round((float)microtime(true) - $stamp, 3), 'id' => $id, 'url' => $contact['url'], 'callstack' => System::callstack(20)]);
+ return true;
+ }
+
+ /**
+ * Perform a contact update if the contact is outdated
+ *
+ * @param string $url contact url
+ * @return bool
+ */
+ public static function updateByUrlIfNeeded(string $url): bool
+ {
+ $id = self::getIdForURL($url, 0, false);
+ if (!empty($id)) {
+ return self::updateByIdIfNeeded($id);
+ }
+ return (bool)self::getIdForURL($url);
+ }
+