Merge pull request #6183 from MrPetovan/bug/6135-hide-follower-only-birthdays

Hide follower-only birthday reminders
This commit is contained in:
Michael Vogel 2018-11-24 15:55:43 +01:00 committed by GitHub
commit 3f4636d490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 142 additions and 174 deletions

View file

@ -740,7 +740,7 @@ class Contact extends BaseObject
// "bd" always contains the upcoming birthday of a contact.
// "birthday" might contain the birthday including the year of birth.
if ($profile["birthday"] > '0001-01-01') {
if ($profile["birthday"] > DBA::NULL_DATE) {
$bd_timestamp = strtotime($profile["birthday"]);
$month = date("m", $bd_timestamp);
$day = date("d", $bd_timestamp);
@ -757,7 +757,7 @@ class Contact extends BaseObject
$profile["bd"] = ( ++$current_year) . "-" . $month . "-" . $day;
}
} else {
$profile["bd"] = '0001-01-01';
$profile["bd"] = DBA::NULL_DATE;
}
} else {
$profile = $default;
@ -794,7 +794,7 @@ class Contact extends BaseObject
$profile["location"] = "";
$profile["about"] = "";
$profile["gender"] = "";
$profile["birthday"] = '0001-01-01';
$profile["birthday"] = DBA::NULL_DATE;
}
$cache[$url][$uid] = $profile;
@ -1962,44 +1962,33 @@ class Contact extends BaseObject
*/
public static function updateBirthdays()
{
// This only handles foreign or alien networks where a birthday has been provided.
// In-network birthdays are handled within local_delivery
$condition = [
'`bd` != ""
AND `bd` > "0001-01-01"
AND SUBSTRING(`bd`, 1, 4) != `bdyear`
AND (`contact`.`rel` = ? OR `contact`.`rel` = ?)
AND NOT `contact`.`pending`
AND NOT `contact`.`hidden`
AND NOT `contact`.`blocked`
AND NOT `contact`.`archive`
AND NOT `contact`.`deleted`',
Contact::SHARING,
Contact::FRIEND
];
$r = q("SELECT * FROM `contact` WHERE `bd` != '' AND `bd` > '0001-01-01' AND SUBSTRING(`bd`, 1, 4) != `bdyear` ");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::log('update_contact_birthday: ' . $rr['bd']);
$contacts = DBA::select('contact', ['id', 'uid', 'name', 'url', 'bd'], $condition);
$nextbd = DateTimeFormat::utcNow('Y') . substr($rr['bd'], 4);
while ($contact = DBA::fetch($contacts)) {
Logger::log('update_contact_birthday: ' . $contact['bd']);
/*
* Add new birthday event for this person
*
* $bdtext is just a readable placeholder in case the event is shared
* with others. We will replace it during presentation to our $importer
* to contain a sparkle link and perhaps a photo.
*/
// Check for duplicates
$condition = ['uid' => $rr['uid'], 'cid' => $rr['id'],
'start' => DateTimeFormat::utc($nextbd), 'type' => 'birthday'];
if (DBA::exists('event', $condition)) {
continue;
}
$bdtext = L10n::t('%s\'s birthday', $rr['name']);
$bdtext2 = L10n::t('Happy Birthday %s', ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]');
q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ", intval($rr['uid']), intval($rr['id']),
DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utc($nextbd)),
DBA::escape(DateTimeFormat::utc($nextbd . ' + 1 day ')), DBA::escape($bdtext), DBA::escape($bdtext2), DBA::escape('birthday'),
intval(0)
);
$nextbd = DateTimeFormat::utcNow('Y') . substr($contact['bd'], 4);
if (Event::createBirthday($contact, $nextbd)) {
// update bdyear
q("UPDATE `contact` SET `bdyear` = '%s', `bd` = '%s' WHERE `uid` = %d AND `id` = %d", DBA::escape(substr($nextbd, 0, 4)),
DBA::escape($nextbd), intval($rr['uid']), intval($rr['id'])
DBA::update(
'contact',
['bdyear' => substr($nextbd, 0, 4), 'bd' => $nextbd],
['id' => $contact['id']]
);
}
}