<commit_before><?php
/**
 * @file src/Worker/OnePoll.php
 */
namespace Friendica\Worker;

use Friendica\Content\Text\BBCode;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Protocol\Email;
use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\XML;
use dba;

require_once 'include/dba.php';

class OnePoll
{
	public static function execute($contact_id = 0, $command = '') {
		global $a;

		require_once 'include/items.php';

		logger('start');

		$manual_id  = 0;
		$generation = 0;
		$hub_update = false;
		$force      = false;
		$restart    = false;

		if ($command == "force") {
			$force = true;
		}

		if (!$contact_id) {
			logger('no contact');
			return;
		}

		$d = DateTimeFormat::utcNow();

		$contact = dba::selectFirst('contact', [], ['id' => $contact_id]);
		if (!DBM::is_result($contact)) {
			logger('Contact not found or cannot be used.');
			return;
		}

		$importer_uid = $contact['uid'];

		// load current friends if possible.
		if (($contact['poco'] != "") && ($contact['success_update'] > $contact['failure_update'])) {
			$r = q("SELECT count(*) AS total FROM glink
				WHERE `cid` = %d AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
				intval($contact['id'])
			);
			if (DBM::is_result($r)) {
				if (!$r[0]['total']) {
					PortableContact::loadWorker($contact['id'], $importer_uid, 0, $contact['poco']);
				}
			}
		}

		// Diaspora users, archived users and followers are only checked if they still exist.
		if ($contact['archive'] || ($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
			$last_updated = PortableContact::lastUpdated($contact["url"], true);
			$updated = DateTimeFormat::utcNow();
			if ($last_updated) {
				logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);

				// The last public item can be older than the last item we got
				if ($last_updated < $contact['last-item']) {
					$last_updated = $contact['last-item'];
				}

				$fields = ['last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated];
				self::updateContact($contact, $fields);
				Contact::unmarkForArchival($contact);
			} else {
				self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
				Contact::markForArchival($contact);
				logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
			}
			return;
		}

		$xml = false;

		$t = $contact['last-update'];

		if ($contact['subhub']) {
			$poll_interval = Config::get('system', 'pushpoll_frequency', 3);
			$contact['priority'] = intval($poll_interval);
			$hub_update = false;

			if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 day")) {
				$hub_update = true;
			}
		} else {
			$hub_update = false;
		}

		$last_update = (($contact['last-update'] <= NULL_DATE)
			? DateTimeFormat::utc('now - 7 days', DateTimeFormat::ATOM)
			: DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM)
		);<commit_msg>Avoid SQL error with wrong formatted datetime value<commit_after><?php
/**
 * @file src/Worker/OnePoll.php
 */
namespace Friendica\Worker;

use Friendica\Content\Text\BBCode;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Protocol\Email;
use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\XML;
use dba;

require_once 'include/dba.php';

class OnePoll
{
	public static function execute($contact_id = 0, $command = '') {
		global $a;

		require_once 'include/items.php';

		logger('start');

		$manual_id  = 0;
		$generation = 0;
		$hub_update = false;
		$force      = false;
		$restart    = false;

		if ($command == "force") {
			$force = true;
		}

		if (!$contact_id) {
			logger('no contact');
			return;
		}

		$d = DateTimeFormat::utcNow();

		$contact = dba::selectFirst('contact', [], ['id' => $contact_id]);
		if (!DBM::is_result($contact)) {
			logger('Contact not found or cannot be used.');
			return;
		}

		$importer_uid = $contact['uid'];

		// load current friends if possible.
		if (($contact['poco'] != "") && ($contact['success_update'] > $contact['failure_update'])) {
			$r = q("SELECT count(*) AS total FROM glink
				WHERE `cid` = %d AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
				intval($contact['id'])
			);
			if (DBM::is_result($r)) {
				if (!$r[0]['total']) {
					PortableContact::loadWorker($contact['id'], $importer_uid, 0, $contact['poco']);
				}
			}
		}

		// Diaspora users, archived users and followers are only checked if they still exist.
		if ($contact['archive'] || ($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
			$last_updated = PortableContact::lastUpdated($contact["url"], true);
			$updated = DateTimeFormat::utcNow();
			if ($last_updated) {
				logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);

				// The last public item can be older than the last item we got
				if ($last_updated < $contact['last-item']) {
					$last_updated = $contact['last-item'];
				}

				$fields = ['last-item' => DateTimeFormat::utc($last_updated), 'last-update' => $updated, 'success_update' => $updated];
				self::updateContact($contact, $fields);
				Contact::unmarkForArchival($contact);
			} else {
				self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
				Contact::markForArchival($contact);
				logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
			}
			return;
		}

		$xml = false;

		$t = $contact['last-update'];

		if ($contact['subhub']) {
			$poll_interval = Config::get('system', 'pushpoll_frequency', 3);
			$contact['priority'] = intval($poll_interval);
			$hub_update = false;

			if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 day")) {
				$hub_update = true;
			}
		} else {
			$hub_update = false;
		}

		$last_update = (($contact['last-update'] <= NULL_DATE)
			? DateTimeFormat::utc('now - 7 days', DateTimeFormat::ATOM)
			: DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM)
		);
{'fraction_non_alphanumeric': 0.17983219882855786, 'fraction_numerical': 0.0028494538546778533, 'mean_word_length': 4.204283360790774, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3270338', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2093, 'n_words': 461}