mirror of
https://github.com/friendica/friendica
synced 2025-05-05 22:24:11 +02:00
Refactor datetime_convert into Temporal::convert
- Changed parameter order to save space - Refactor select_timezone into Temporal::getTimezoneSelect - Refactor field_timezone into Temporal::getTimezoneField
This commit is contained in:
parent
d478ef6c6d
commit
dc366bf1f7
62 changed files with 512 additions and 432 deletions
|
@ -8,6 +8,7 @@ use Friendica\Core\Addon;
|
|||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Util\Temporal;
|
||||
use dba;
|
||||
|
||||
require_once 'include/dba.php';
|
||||
|
@ -70,7 +71,7 @@ Class Cron {
|
|||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
$d1 = Config::get('system', 'last_expire_day');
|
||||
$d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd'));
|
||||
$d2 = intval(Temporal::convert('now', 'UTC', 'UTC', 'd'));
|
||||
|
||||
if ($d2 != intval($d1)) {
|
||||
|
||||
|
@ -141,7 +142,7 @@ Class Cron {
|
|||
|
||||
Addon::reload();
|
||||
|
||||
$d = datetime_convert();
|
||||
$d = Temporal::convert();
|
||||
|
||||
// Only poll from those with suitable relationships,
|
||||
// and which have a polling address and ignore Diaspora since
|
||||
|
@ -217,33 +218,33 @@ Class Cron {
|
|||
*/
|
||||
switch ($contact['priority']) {
|
||||
case 5:
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + 1 month")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + 1 week")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + 1 day")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + 12 hour")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + 1 hour")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + ".$min_poll_interval." minute")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + ".$min_poll_interval." minute")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace Friendica\Worker;
|
|||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Util\Temporal;
|
||||
|
||||
Class CronHooks {
|
||||
public static function execute($hook = '') {
|
||||
|
@ -44,7 +45,7 @@ Class CronHooks {
|
|||
|
||||
logger('cronhooks: start');
|
||||
|
||||
$d = datetime_convert();
|
||||
$d = Temporal::convert();
|
||||
|
||||
if (is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $hook) {
|
||||
|
|
|
@ -12,6 +12,7 @@ use Friendica\Model\GContact;
|
|||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\PortableContact;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Temporal;
|
||||
|
||||
require_once 'include/datetime.php';
|
||||
|
||||
|
@ -197,7 +198,7 @@ class DiscoverPoCo {
|
|||
}
|
||||
} else {
|
||||
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($user["url"])));
|
||||
dbesc(Temporal::convert()), dbesc(normalise_link($user["url"])));
|
||||
}
|
||||
|
||||
// Quit the loop after 3 minutes
|
||||
|
|
|
@ -14,6 +14,7 @@ use Friendica\Protocol\Email;
|
|||
use Friendica\Protocol\PortableContact;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\XML;
|
||||
use Friendica\Util\Temporal;
|
||||
use dba;
|
||||
|
||||
require_once 'include/dba.php';
|
||||
|
@ -43,7 +44,7 @@ class OnePoll
|
|||
return;
|
||||
}
|
||||
|
||||
$d = datetime_convert();
|
||||
$d = Temporal::convert();
|
||||
|
||||
$contact = dba::selectFirst('contact', [], ['id' => $contact_id]);
|
||||
if (!DBM::is_result($contact)) {
|
||||
|
@ -69,7 +70,7 @@ class OnePoll
|
|||
// 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 = datetime_convert();
|
||||
$updated = Temporal::convert();
|
||||
if ($last_updated) {
|
||||
logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);
|
||||
|
||||
|
@ -98,7 +99,7 @@ class OnePoll
|
|||
$contact['priority'] = intval($poll_interval);
|
||||
$hub_update = false;
|
||||
|
||||
if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
|
||||
if (Temporal::convert('now') > Temporal::convert($t . " + 1 day")) {
|
||||
$hub_update = true;
|
||||
}
|
||||
} else {
|
||||
|
@ -106,8 +107,8 @@ class OnePoll
|
|||
}
|
||||
|
||||
$last_update = (($contact['last-update'] <= NULL_DATE)
|
||||
? datetime_convert('UTC', 'UTC', 'now - 7 days', ATOM_TIME)
|
||||
: datetime_convert('UTC', 'UTC', $contact['last-update'], ATOM_TIME)
|
||||
? Temporal::convert('now - 7 days', 'UTC', 'UTC', ATOM_TIME)
|
||||
: Temporal::convert($contact['last-update'], 'UTC', 'UTC', ATOM_TIME)
|
||||
);
|
||||
|
||||
// Update the contact entry
|
||||
|
@ -116,7 +117,7 @@ class OnePoll
|
|||
logger("Skipping probably dead contact ".$contact['url']);
|
||||
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -125,7 +126,7 @@ class OnePoll
|
|||
logger('Contact is marked dead');
|
||||
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
return;
|
||||
} else {
|
||||
Contact::unmarkForArchival($contact);
|
||||
|
@ -136,7 +137,7 @@ class OnePoll
|
|||
logger('Ignore public contacts');
|
||||
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -148,7 +149,7 @@ class OnePoll
|
|||
logger('No self contact for user '.$importer_uid);
|
||||
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -184,7 +185,7 @@ class OnePoll
|
|||
|
||||
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
Contact::markForArchival($contact);
|
||||
return;
|
||||
}
|
||||
|
@ -206,7 +207,7 @@ class OnePoll
|
|||
Contact::markForArchival($contact);
|
||||
|
||||
// set the last-update so we don't keep polling
|
||||
$fields = ['last-update' => datetime_convert(), 'failure_update' => datetime_convert()];
|
||||
$fields = ['last-update' => Temporal::convert(), 'failure_update' => Temporal::convert()];
|
||||
self::updateContact($contact, $fields);
|
||||
return;
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ class OnePoll
|
|||
|
||||
Contact::markForArchival($contact);
|
||||
|
||||
$fields = ['last-update' => datetime_convert(), 'failure_update' => datetime_convert()];
|
||||
$fields = ['last-update' => Temporal::convert(), 'failure_update' => Temporal::convert()];
|
||||
self::updateContact($contact, $fields);
|
||||
return;
|
||||
}
|
||||
|
@ -229,7 +230,7 @@ class OnePoll
|
|||
|
||||
// we may not be friends anymore. Will keep trying for one month.
|
||||
// set the last-update so we don't keep polling
|
||||
$fields = ['last-update' => datetime_convert(), 'failure_update' => datetime_convert()];
|
||||
$fields = ['last-update' => Temporal::convert(), 'failure_update' => Temporal::convert()];
|
||||
self::updateContact($contact, $fields);
|
||||
|
||||
Contact::markForArchival($contact);
|
||||
|
@ -240,7 +241,7 @@ class OnePoll
|
|||
|
||||
if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -275,7 +276,7 @@ class OnePoll
|
|||
logger('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
|
||||
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
Contact::markForArchival($contact);
|
||||
return;
|
||||
}
|
||||
|
@ -310,7 +311,7 @@ class OnePoll
|
|||
|
||||
if ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) {
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -320,7 +321,7 @@ class OnePoll
|
|||
|
||||
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
Contact::markForArchival($contact);
|
||||
return;
|
||||
}
|
||||
|
@ -334,7 +335,7 @@ class OnePoll
|
|||
$mail_disabled = ((function_exists('imap_open') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1);
|
||||
if ($mail_disabled) {
|
||||
// set the last-update so we don't keep polling
|
||||
dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]);
|
||||
dba::update('contact', ['last-update' => Temporal::convert()], ['id' => $contact['id']]);
|
||||
Contact::markForArchival($contact);
|
||||
return;
|
||||
}
|
||||
|
@ -354,7 +355,7 @@ class OnePoll
|
|||
unset($password);
|
||||
logger("Mail: Connect to " . $mailconf['user']);
|
||||
if ($mbox) {
|
||||
$fields = ['last_check' => datetime_convert()];
|
||||
$fields = ['last_check' => Temporal::convert()];
|
||||
dba::update('mailacct', $fields, ['id' => $mailconf['id']]);
|
||||
logger("Mail: Connected to " . $mailconf['user']);
|
||||
} else {
|
||||
|
@ -394,7 +395,7 @@ class OnePoll
|
|||
// Only delete when mails aren't automatically moved or deleted
|
||||
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
|
||||
if ($meta->deleted && ! $item['deleted']) {
|
||||
$fields = ['deleted' => true, 'changed' => datetime_convert()];
|
||||
$fields = ['deleted' => true, 'changed' => Temporal::convert()];
|
||||
dba::update('item', $fields, ['id' => $item['id']]);
|
||||
}
|
||||
|
||||
|
@ -458,7 +459,7 @@ class OnePoll
|
|||
$datarray['title'] = notags(trim($datarray['title']));
|
||||
|
||||
//$datarray['title'] = notags(trim($meta->subject));
|
||||
$datarray['created'] = datetime_convert('UTC', 'UTC', $meta->date);
|
||||
$datarray['created'] = Temporal::convert($meta->date);
|
||||
|
||||
// Is it a reply?
|
||||
$reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") ||
|
||||
|
@ -571,7 +572,7 @@ class OnePoll
|
|||
if (!strstr($xml, '<')) {
|
||||
logger('post_handshake: response from ' . $url . ' did not contain XML.');
|
||||
|
||||
$fields = ['last-update' => datetime_convert(), 'failure_update' => datetime_convert()];
|
||||
$fields = ['last-update' => Temporal::convert(), 'failure_update' => Temporal::convert()];
|
||||
self::updateContact($contact, $fields);
|
||||
Contact::markForArchival($contact);
|
||||
return;
|
||||
|
@ -615,19 +616,19 @@ class OnePoll
|
|||
}
|
||||
}
|
||||
|
||||
$updated = datetime_convert();
|
||||
$updated = Temporal::convert();
|
||||
|
||||
self::updateContact($contact, ['last-update' => $updated, 'success_update' => $updated]);
|
||||
dba::update('gcontact', ['last_contact' => $updated], ['nurl' => $contact['nurl']]);
|
||||
Contact::unmarkForArchival($contact);
|
||||
} elseif (in_array($contact["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_FEED])) {
|
||||
$updated = datetime_convert();
|
||||
$updated = Temporal::convert();
|
||||
|
||||
self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
|
||||
dba::update('gcontact', ['last_failure' => $updated], ['nurl' => $contact['nurl']]);
|
||||
Contact::markForArchival($contact);
|
||||
} else {
|
||||
$updated = datetime_convert();
|
||||
$updated = Temporal::convert();
|
||||
dba::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file src/Worker/UpdateGcontact.php
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\PortableContact;
|
||||
use Friendica\Util\Temporal;
|
||||
|
||||
class UpdateGContact {
|
||||
public static function execute($contact_id) {
|
||||
class UpdateGContact
|
||||
{
|
||||
public static function execute($contact_id)
|
||||
{
|
||||
global $a;
|
||||
|
||||
logger('update_gcontact: start');
|
||||
|
@ -33,25 +37,30 @@ class UpdateGContact {
|
|||
$data = Probe::uri($r[0]["url"]);
|
||||
|
||||
if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
|
||||
if ($r[0]["server_url"] != "")
|
||||
if ($r[0]["server_url"] != "") {
|
||||
PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]);
|
||||
}
|
||||
|
||||
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
|
||||
dbesc(datetime_convert()), intval($contact_id));
|
||||
dbesc(Temporal::convert()), intval($contact_id));
|
||||
return;
|
||||
}
|
||||
|
||||
if (($data["name"] == "") && ($r[0]['name'] != ""))
|
||||
if (($data["name"] == "") && ($r[0]['name'] != "")) {
|
||||
$data["name"] = $r[0]['name'];
|
||||
}
|
||||
|
||||
if (($data["nick"] == "") && ($r[0]['nick'] != ""))
|
||||
if (($data["nick"] == "") && ($r[0]['nick'] != "")) {
|
||||
$data["nick"] = $r[0]['nick'];
|
||||
}
|
||||
|
||||
if (($data["addr"] == "") && ($r[0]['addr'] != ""))
|
||||
if (($data["addr"] == "") && ($r[0]['addr'] != "")) {
|
||||
$data["addr"] = $r[0]['addr'];
|
||||
}
|
||||
|
||||
if (($data["photo"] == "") && ($r[0]['photo'] != ""))
|
||||
if (($data["photo"] == "") && ($r[0]['photo'] != "")) {
|
||||
$data["photo"] = $r[0]['photo'];
|
||||
}
|
||||
|
||||
|
||||
q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
|
||||
|
@ -60,8 +69,8 @@ class UpdateGContact {
|
|||
dbesc($data["nick"]),
|
||||
dbesc($data["addr"]),
|
||||
dbesc($data["photo"]),
|
||||
intval($contact_id)
|
||||
);
|
||||
intval($contact_id)
|
||||
);
|
||||
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
|
||||
WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
|
||||
|
@ -70,12 +79,12 @@ class UpdateGContact {
|
|||
dbesc($data["addr"]),
|
||||
dbesc($data["photo"]),
|
||||
dbesc(normalise_link($data["url"]))
|
||||
);
|
||||
);
|
||||
|
||||
q("UPDATE `contact` SET `addr` = '%s'
|
||||
WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
|
||||
dbesc($data["addr"]),
|
||||
dbesc(normalise_link($data["url"]))
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue