More replaced "q" calls

This commit is contained in:
Michael 2021-10-07 05:53:16 +00:00
parent 24ffee74d7
commit 16d7eafd41
4 changed files with 181 additions and 265 deletions

View File

@ -14,6 +14,7 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Notification;
use Friendica\Model\User;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
@ -50,60 +51,49 @@ function public_server_cron($a, $b)
{
Logger::log("public_server: cron start");
$r = q("SELECT * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND
`account_expires_on` > '%s' AND
`expire_notification_sent` <= '%s'",
DBA::NULL_DATETIME, DBA::NULL_DATETIME);
$users = DBA::selectToArray('user', [], ["`account_expires_on` < UTC_TIMESTAMP() + INTERVAL ? DAY AND
`account_expires_on` > ? AND `expire_notification_sent` <= ?", 5, DBA::NULL_DATETIME, DBA::NULL_DATETIME]);
foreach ($users as $rr) {
notification([
'type' => Notification\Type::SYSTEM,
'uid' => $rr['uid'],
'system_type' => 'public_server_expire',
'source_name' => DI::l10n()->t('Administrator'),
'source_link' => DI::baseUrl()->get(),
'source_photo' => DI::baseUrl()->get() . '/images/person-80.jpg',
]);
if (DBA::isResult($r)) {
foreach ($r as $rr) {
notification([
'type' => Notification\Type::SYSTEM,
'uid' => $rr['uid'],
'system_type' => 'public_server_expire',
'source_name' => DI::l10n()->t('Administrator'),
'source_link' => DI::baseUrl()->get(),
'source_photo' => DI::baseUrl()->get() . '/images/person-80.jpg',
]);
$fields = ['expire_notification_sent' => DateTimeFormat::utcNow()];
DBA::update('user', $fields, ['uid' => $rr['uid']]);
}
$fields = ['expire_notification_sent' => DateTimeFormat::utcNow()];
DBA::update('user', $fields, ['uid' => $rr['uid']]);
}
$nologin = DI::config()->get('public_server', 'nologin', false);
if ($nologin) {
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'",
DBA::NULL_DATETIME, intval($nologin), DBA::NULL_DATETIME);
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
DBA::update('user', $fields, ['uid' => $rr['uid']]);
}
$users = DBA::selectToArray('user', [], ["NOT `account_expired` AND `login_date` <= ? AND `register_date` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `account_expires_on` <= ?",
DBA::NULL_DATETIME, $nologin, DBA::NULL_DATETIME]);
foreach ($users as $rr) {
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
DBA::update('user', $fields, ['uid' => $rr['uid']]);
}
}
$flagusers = DI::config()->get('public_server', 'flagusers', false);
if ($flagusers) {
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' AND `page-flags` = 0",
intval($flagusers), DBA::NULL_DATETIME);
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
DBA::update('user', $fields, ['uid' => $rr['uid']]);
}
$users = DBA::selectToArray('user', [], ["NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `account_expires_on` <= ? AND `page-flags` = ?",
$flagusers, DBA::NULL_DATETIME, User::PAGE_FLAGS_NORMAL]);
foreach ($users as $rr) {
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
DBA::update('user', $fields, ['uid' => $rr['uid']]);
}
}
$flagposts = DI::config()->get('public_server', 'flagposts');
$flagpostsexpire = DI::config()->get('public_server', 'flagpostsexpire');
if ($flagposts && $flagpostsexpire) {
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' and `expire` = 0 AND `page-flags` = 0",
intval($flagposts), DBA::NULL_DATETIME);
if (DBA::isResult($r)) {
foreach ($r as $rr) {
DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]);
}
$users = DBA::selectToArray('user', [], ["NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `account_expires_on` <= ? AND NOT `expire` AND `page-flags` = ?",
$flagposts, DBA::NULL_DATETIME, User::PAGE_FLAGS_NORMAL]);
foreach ($users as $rr) {
DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]);
}
}

View File

@ -767,12 +767,10 @@ function statusnet_cron(App $a, $b)
}
Logger::notice('statusnet: cron_start');
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() ");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::notice('statusnet: fetching for user ' . $rr['uid']);
statusnet_fetchtimeline($a, $rr['uid']);
}
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'statusnet', 'k' => 'mirror_posts', 'v' => true]);
foreach ($pconfigs as $rr) {
Logger::notice('statusnet: fetching for user ' . $rr['uid']);
statusnet_fetchtimeline($a, $rr['uid']);
}
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
@ -782,20 +780,17 @@ function statusnet_cron(App $a, $b)
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` ORDER BY RAND()");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
if ($abandon_days != 0) {
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
if (!DBA::isResult($user)) {
Logger::notice('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported');
continue;
}
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'statusnet', 'k' => 'import', 'v' => true]);
foreach ($pconfigs as $rr) {
if ($abandon_days != 0) {
if (!DBA::exists('user', ["`uid` = ? AND `login_date` >= ?", $rr['uid'], $abandon_limit])) {
Logger::notice('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported');
continue;
}
Logger::notice('statusnet: importing timeline from user ' . $rr['uid']);
statusnet_fetchhometimeline($a, $rr["uid"], $rr["v"]);
}
Logger::notice('statusnet: importing timeline from user ' . $rr['uid']);
statusnet_fetchhometimeline($a, $rr["uid"], $rr["v"]);
}
Logger::notice('statusnet: cron_end');
@ -929,112 +924,89 @@ function statusnet_fetch_contact($uid, $contact, $create_user)
return -1;
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)), DBA::escape(Protocol::STATUSNET));
$contact_record = Contact::selectFirst([],
['alias' => Strings::normaliseLink($contact->statusnet_profile_url), 'uid' => $uid, 'network' => Protocol::STATUSNET]);
if (!DBA::isResult($r) && !$create_user) {
if (!DBA::isResult($contact_record) && !$create_user) {
return 0;
}
if (DBA::isResult($r) && ($r[0]["readonly"] || $r[0]["blocked"])) {
Logger::info("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.");
if (DBA::isResult($contact_record) && ($contact_record["readonly"] || $contact_record["blocked"])) {
Logger::info("statusnet_fetch_contact: Contact '" . $contact_record["nick"] . "' is blocked or readonly.");
return -1;
}
if (!DBA::isResult($r)) {
if (!DBA::isResult($contact_record)) {
// create contact record
q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
`name`, `nick`, `photo`, `network`, `rel`, `priority`,
`location`, `about`, `writable`, `blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0 ) ",
intval($uid),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($contact->statusnet_profile_url),
DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
DBA::escape(statusnet_address($contact)),
DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
DBA::escape(''),
DBA::escape(''),
DBA::escape($contact->name),
DBA::escape($contact->screen_name),
DBA::escape($contact->profile_image_url),
DBA::escape(Protocol::STATUSNET),
intval(Contact::FRIEND),
intval(1),
DBA::escape($contact->location),
DBA::escape($contact->description),
intval(1)
);
$fields['uid'] = $uid;
$fields['created'] = DateTimeFormat::utcNow();
$fields['url'] = $contact->statusnet_profile_url;
$fields['nurl'] = Strings::normaliseLink($contact->statusnet_profile_url);
$fields['addr'] = statusnet_address($contact);
$fields['alias'] = Strings::normaliseLink($contact->statusnet_profile_url);
$fields['notify'] = '';
$fields['poll'] = '';
$fields['name'] = $contact->name;
$fields['nick'] = $contact->screen_name;
$fields['photo'] = $contact->profile_image_url;
$fields['network'] = Protocol::STATUSNET;
$fields['rel'] = Contact::FRIEND;
$fields['priority'] = 1;
$fields['location'] = $contact->location;
$fields['about'] = $contact->description;
$fields['writable'] = true;
$fields['blocked'] = false;
$fields['readonly'] = false;
$fields['pending'] = false;
$r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1",
DBA::escape($contact->statusnet_profile_url),
intval($uid),
DBA::escape(Protocol::STATUSNET));
if (!DBA::isResult($r)) {
if (!Contact::insert($fields)) {
return false;
}
$contact_id = $r[0]['id'];
$contact_record = Contact::selectFirst([],
['alias' => Strings::normaliseLink($contact->statusnet_profile_url), 'uid' => $uid, 'network' => Protocol::STATUSNET]);
if (!DBA::isResult($contact_record)) {
return false;
}
$contact_id = $contact_record['id'];
Group::addMember(User::getDefaultGroup($uid), $contact_id);
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $contact_id);
q("UPDATE `contact` SET `photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d",
DBA::escape($photos[0]),
DBA::escape($photos[1]),
DBA::escape($photos[2]),
DBA::escape(DateTimeFormat::utcNow()),
intval($contact_id)
);
Contact::update(['photo' => $photos[0], 'thumb' => $photos[1],
'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()], ['id' => $contact_id]);
} else {
// update profile photos once every two weeks as we have no notification of when they change.
//$update_photo = (($r[0]['avatar-date'] < DateTimeFormat::convert('now -2 days', '', '', )) ? true : false);
$update_photo = ($r[0]['avatar-date'] < DateTimeFormat::utc('now -12 hours'));
//$update_photo = (($contact_record['avatar-date'] < DateTimeFormat::convert('now -2 days', '', '', )) ? true : false);
$update_photo = ($contact_record['avatar-date'] < DateTimeFormat::utc('now -12 hours'));
// check that we have all the photos, this has been known to fail on occasion
if ((!$r[0]['photo']) || (!$r[0]['thumb']) || (!$r[0]['micro']) || ($update_photo)) {
if ((!$contact_record['photo']) || (!$contact_record['thumb']) || (!$contact_record['micro']) || ($update_photo)) {
Logger::info("statusnet_fetch_contact: Updating contact " . $contact->screen_name);
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $r[0]['id']);
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $contact_record['id']);
q("UPDATE `contact` SET `photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s',
`url` = '%s',
`nurl` = '%s',
`addr` = '%s',
`name` = '%s',
`nick` = '%s',
`location` = '%s',
`about` = '%s'
WHERE `id` = %d",
DBA::escape($photos[0]),
DBA::escape($photos[1]),
DBA::escape($photos[2]),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($contact->statusnet_profile_url),
DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
DBA::escape(statusnet_address($contact)),
DBA::escape($contact->name),
DBA::escape($contact->screen_name),
DBA::escape($contact->location),
DBA::escape($contact->description),
intval($r[0]['id'])
);
Contact::update([
'photo' => $photos[0],
'thumb' => $photos[1],
'micro' => $photos[2],
'name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(),
'avatar-date' => DateTimeFormat::utcNow(),
'url' => $contact->statusnet_profile_url,
'nurl' => Strings::normaliseLink($contact->statusnet_profile_url),
'addr' => statusnet_address($contact),
'name' => $contact->name,
'nick' => $contact->screen_name,
'location' => $contact->location,
'about' => $contact->description
], ['id' => $contact_record['id']]);
}
}
return $r[0]["id"];
return $contact_record["id"];
}
function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
@ -1051,12 +1023,8 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
$cb->setConsumerKey($ckey, $csecret);
$cb->setToken($otoken, $osecret);
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid));
if (DBA::isResult($r)) {
$self = $r[0];
} else {
$self = Contact::selectFirst([], ['self' => true, 'uid' => $uid]);
if (!DBA::isResult($self)) {
return;
}
@ -1128,15 +1096,13 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
$own_url = DI::pConfig()->get($uid, 'statusnet', 'own_url');
if ($content->user->id == $own_url) {
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid));
$self = DBA::selectFirst([], ['self' => true, 'uid' => $uid]);
if (DBA::isResult($self)) {
$contactid = $self["id"];
if (DBA::isResult($r)) {
$contactid = $r[0]["id"];
$postarray['owner-name'] = $r[0]["name"];
$postarray['owner-link'] = $r[0]["url"];
$postarray['owner-avatar'] = $r[0]["photo"];
$postarray['owner-name'] = $self["name"];
$postarray['owner-link'] = $self["url"];
$postarray['owner-avatar'] = $self["photo"];
} else {
return [];
}
@ -1230,30 +1196,22 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
return;
}
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($own_contact),
intval($uid));
if (DBA::isResult($r)) {
$nick = $r[0]["nick"];
$contact = Contact::selectFirst([], ['id' => $own_contact, 'uid' => $uid]);
if (DBA::isResult($contact)) {
$nick = $contact["nick"];
} else {
Logger::info("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid);
return;
}
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid));
if (DBA::isResult($r)) {
$self = $r[0];
} else {
$self = Contact::selectFirst([], ['self' => true, 'uid' => $uid]);
if (!DBA::isResult($self)) {
Logger::info("statusnet_fetchhometimeline: Own contact not found for user " . $uid);
return;
}
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
intval($uid));
if (!DBA::isResult($u)) {
$user = User::getById($uid);
if (!DBA::isResult($user)) {
Logger::info("statusnet_fetchhometimeline: Own user not found for user " . $uid);
return;
}
@ -1519,10 +1477,9 @@ function statusnet_fetch_own_contact(App $a, $uid)
$contact_id = statusnet_fetch_contact($uid, $user, true);
} else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
intval($uid), DBA::escape($own_url));
if (DBA::isResult($r)) {
$contact_id = $r[0]["id"];
$contact = Contact::selectFirst([], ['uid' => $uid, 'alias' => $own_url]);
if (DBA::isResult($contact)) {
$contact_id = $contact["id"];
} else {
DI::pConfig()->delete($uid, 'statusnet', 'own_url');
}

View File

@ -43,42 +43,29 @@ function testdrive_register_account($a,$b) {
if(! $days)
return;
$r = q("UPDATE user set account_expires_on = '%s' where uid = %d",
DBA::escape(DateTimeFormat::convert('now +' . $days . ' days')),
intval($uid)
);
DBA::update('user', ['account_expires_on' => DateTimeFormat::convert('now +' . $days . ' days')], ['uid' => $uid]);
};
function testdrive_cron($a,$b) {
$r = q("select * from user where account_expires_on < UTC_TIMESTAMP() + INTERVAL 5 DAY and
expire_notification_sent = '0000-00-00 00:00:00' ");
$users = DBA::selectToArray('user', [], ["`account_expires_on` < UTC_TIMESTAMP() + INTERVAL ? DAY AND `expire_notification_sent` <= ?",
5, DBA::NULL_DATETIME]);
foreach($users as $rr) {
notification([
'type' => Notification\Type::SYSTEM,
'uid' => $rr['uid'],
'system_type' => 'testdrive_expire',
'source_name' => DI::l10n()->t('Administrator'),
'source_link' => DI::baseUrl()->get(),
'source_photo' => DI::baseUrl()->get() . '/images/person-80.jpg',
]);
if(count($r)) {
foreach($r as $rr) {
notification([
'type' => Notification\Type::SYSTEM,
'uid' => $rr['uid'],
'system_type' => 'testdrive_expire',
'source_name' => DI::l10n()->t('Administrator'),
'source_link' => DI::baseUrl()->get(),
'source_photo' => DI::baseUrl()->get() . '/images/person-80.jpg',
]);
q("update user set expire_notification_sent = '%s' where uid = %d",
DBA::escape(DateTimeFormat::utcNow()),
intval($rr['uid'])
);
}
DBA::update('user', ['expire_notification_sent' => DateTimeFormat::utcNow()], ['uid' => $rr['uid']]);
}
$r = q("select * from user where account_expired = 1 and account_expires_on < UTC_TIMESTAMP() - INTERVAL 5 DAY ");
if(count($r)) {
foreach($r as $rr) {
User::remove($rr['uid']);
}
$users = DBA::selectToArray('user', [], ["`account_expired` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL ? DAY", 5]);
foreach($users as $rr) {
User::remove($rr['uid']);
}
}

View File

@ -126,15 +126,11 @@ function twitter_load_config(App $a, ConfigFileLoader $loader)
function twitter_check_item_notification(App $a, array &$notification_data)
{
$own_id = DI::pConfig()->get($notification_data["uid"], 'twitter', 'own_id');
$own_user = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
intval($notification_data["uid"]),
DBA::escape("twitter::".$own_id)
);
$own_id = DI::pConfig()->get($notification_data['uid'], 'twitter', 'own_id');
$own_user = Contact::selectFirst(['url'], ['uid' => $notification_data['uid'], 'alias' => 'twitter::'.$own_id]);
if ($own_user) {
$notification_data["profiles"][] = $own_user[0]["url"];
$notification_data['profiles'][] = $own_user['url'];
}
}
@ -525,7 +521,7 @@ function twitter_probe_detect(App $a, array &$hookData)
function twitter_api_post(string $apiPath, string $pid, int $uid)
{
if (empty($pid)) {
return;
return false;
}
$ckey = DI::config()->get('twitter', 'consumerkey');
@ -829,12 +825,10 @@ function twitter_cron(App $a)
}
Logger::notice('twitter: cron_start');
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'mirror_posts' AND `v` = '1'");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::notice('Fetching', ['user' => $rr['uid']]);
Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']);
}
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'mirror_posts', 'v' => true]);
foreach ($pconfigs as $rr) {
Logger::notice('Fetching', ['user' => $rr['uid']]);
Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']);
}
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
@ -844,34 +838,31 @@ function twitter_cron(App $a)
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1'");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
if ($abandon_days != 0) {
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
if (!DBA::isResult($user)) {
Logger::notice('abandoned account: timeline from user will not be imported', ['user' => $rr['uid']]);
continue;
}
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'import', 'v' => true]);
foreach ($pconfigs as $rr) {
if ($abandon_days != 0) {
if (!DBA::exists('user', ["`uid` = ? AND `login_date` >= ?", $rr['uid'], $abandon_limit])) {
Logger::notice('abandoned account: timeline from user will not be imported', ['user' => $rr['uid']]);
continue;
}
Logger::notice('importing timeline', ['user' => $rr['uid']]);
Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 2, (int) $rr['uid']);
/*
// To-Do
// check for new contacts once a day
$last_contact_check = DI::pConfig()->get($rr['uid'],'pumpio','contact_check');
if($last_contact_check)
$next_contact_check = $last_contact_check + 86400;
else
$next_contact_check = 0;
if($next_contact_check <= time()) {
pumpio_getallusers($a, $rr["uid"]);
DI::pConfig()->set($rr['uid'],'pumpio','contact_check',time());
}
*/
}
Logger::notice('importing timeline', ['user' => $rr['uid']]);
Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 2, (int) $rr['uid']);
/*
// To-Do
// check for new contacts once a day
$last_contact_check = DI::pConfig()->get($rr['uid'],'pumpio','contact_check');
if($last_contact_check)
$next_contact_check = $last_contact_check + 86400;
else
$next_contact_check = 0;
if($next_contact_check <= time()) {
pumpio_getallusers($a, $rr["uid"]);
DI::pConfig()->set($rr['uid'],'pumpio','contact_check',time());
}
*/
}
Logger::notice('twitter: cron_end');
@ -900,12 +891,10 @@ function twitter_expire(App $a)
Logger::notice('Start expiry');
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::notice('twitter_expire', ['user' => $rr['uid']]);
Item::expire($rr['uid'], $days, Protocol::TWITTER, true);
}
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'import', 'v' => true]);
foreach ($pconfigs as $rr) {
Logger::notice('twitter_expire', ['user' => $rr['uid']]);
Item::expire($rr['uid'], $days, Protocol::TWITTER, true);
}
Logger::notice('End expiry');
@ -1279,7 +1268,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
}
if (!empty($cid)) {
DBA::update('contact', $fields, ['id' => $cid]);
Contact::update($fields, ['id' => $cid]);
Contact::updateAvatar($cid, $avatar);
} else {
Logger::warning('No contact found', ['fields' => $fields]);
@ -1308,7 +1297,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
$fields['readonly'] = false;
$fields['pending'] = false;
if (!DBA::insert('contact', $fields)) {
if (!Contact::insert($fields)) {
return false;
}
@ -1350,7 +1339,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
if ($update) {
$fields['updated'] = DateTimeFormat::utcNow();
DBA::update('contact', $fields, ['id' => $contact['id']]);
Contact::update($fields, ['id' => $contact['id']]);
Logger::info('Updated contact', ['id' => $contact['id'], 'nick' => $data->screen_name]);
}
}
@ -1663,15 +1652,13 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
$own_id = DI::pConfig()->get($uid, 'twitter', 'own_id');
if ($post->user->id_str == $own_id) {
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid));
$self = Contact::selectFirst(['id', 'name', 'url', 'photo'], ['self' => true, 'uid' => $uid]);
if (DBA::isResult($self)) {
$contactid = $self['id'];
if (DBA::isResult($r)) {
$contactid = $r[0]["id"];
$postarray['owner-name'] = $r[0]["name"];
$postarray['owner-link'] = $r[0]["url"];
$postarray['owner-avatar'] = $r[0]["photo"];
$postarray['owner-name'] = $self['name'];
$postarray['owner-link'] = $self['url'];
$postarray['owner-avatar'] = $self['photo'];
} else {
Logger::error('No self contact found', ['uid' => $uid]);
return [];
@ -1910,12 +1897,9 @@ function twitter_fetchhometimeline(App $a, $uid)
return;
}
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($own_contact),
intval($uid));
if (DBA::isResult($r)) {
$own_id = $r[0]["nick"];
$contact = Contact::selectFirst(['nick'], ['id' => $own_contact, 'uid' => $uid]);
if (DBA::isResult($contact)) {
$own_id = $contact['nick'];
} else {
Logger::warning('Own twitter contact not found', ['uid' => $uid]);
return;
@ -2093,11 +2077,9 @@ function twitter_fetch_own_contact(App $a, $uid)
$contact_id = twitter_fetch_contact($uid, $user, true);
} else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
intval($uid),
DBA::escape("twitter::" . $own_id));
if (DBA::isResult($r)) {
$contact_id = $r[0]["id"];
$contact = Contact::selectFirst(['id'], ['uid' => $uid, 'alias' => 'twitter::' . $own_id]);
if (DBA::isResult($contact)) {
$contact_id = $contact['id'];
} else {
DI::pConfig()->delete($uid, 'twitter', 'own_id');
}