Merge pull request #4391 from MrPetovan/bug/4390-convert-last-updated-to-mysql

Convert Atom last updated date to MySQL format
This commit is contained in:
Michael Vogel 2018-02-04 16:46:42 +01:00 committed by GitHub
commit b0e8bedb8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

View file

@ -114,19 +114,13 @@ class DBM
/** /**
* Checks Converts any date string into a SQL compatible date string * Checks Converts any date string into a SQL compatible date string
* *
* @deprecated since version 3.6
* @param string $date a date string in any format * @param string $date a date string in any format
* *
* @return string SQL style date string * @return string SQL style date string
*/ */
public static function date($date = 'now') public static function date($date = 'now')
{ {
$timestamp = strtotime($date); return DateTimeFormat::utc($date);
// Don't allow lower date strings as '0001-01-01 00:00:00'
if ($timestamp < -62135596800) {
$timestamp = -62135596800;
}
return date(DateTimeFormat::MYSQL, (int)$timestamp);
} }
} }

View file

@ -502,14 +502,16 @@ class PortableContact
$last_updated = ""; $last_updated = "";
foreach ($entries as $entry) { foreach ($entries as $entry) {
$published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; $published = DateTimeFormat::utc($xpath->query('atom:published/text()', $entry)->item(0)->nodeValue);
$updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; $updated = DateTimeFormat::utc($xpath->query('atom:updated/text()' , $entry)->item(0)->nodeValue);
if ($last_updated < $published) if ($last_updated < $published) {
$last_updated = $published; $last_updated = $published;
}
if ($last_updated < $updated) if ($last_updated < $updated) {
$last_updated = $updated; $last_updated = $updated;
}
} }
// Maybe there aren't any entries. Then check if it is a valid feed // Maybe there aren't any entries. Then check if it is a valid feed
@ -518,7 +520,8 @@ class PortableContact
$last_updated = NULL_DATE; $last_updated = NULL_DATE;
} }
} }
$fields = ['updated' => DBM::date($last_updated), 'last_contact' => DBM::date()];
$fields = ['updated' => $last_updated, 'last_contact' => DateTimeFormat::utcNow()];
dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
if (($gcontacts[0]["generation"] == 0)) { if (($gcontacts[0]["generation"] == 0)) {
@ -528,7 +531,7 @@ class PortableContact
logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG); logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
return($last_updated); return $last_updated;
} }
public static function updateNeeded($created, $updated, $last_failure, $last_contact) public static function updateNeeded($created, $updated, $last_failure, $last_contact)