From: Hypolite Petovan Date: Thu, 22 Nov 2018 05:15:44 +0000 (-0500) Subject: Add contact conditions to getBirthdays/updateBirthdays X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=14df030f4463f9738a969c27292224d1d614849c;p=friendica.git Add contact conditions to getBirthdays/updateBirthdays --- diff --git a/src/Model/Contact.php b/src/Model/Contact.php index f43a14e626..717bd2d15e 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1957,44 +1957,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 - - $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']); - - $nextbd = DateTimeFormat::utcNow('Y') . substr($rr['bd'], 4); - - /* - * 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) - ); - + $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 + ]; + + $contacts = DBA::select('contact', ['id', 'uid', 'name', 'url', 'bd'], $condition); + + while ($contact = DBA::fetch($contacts)) { + Logger::log('update_contact_birthday: ' . $contact['bd']); + + $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']] ); } } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index df4c8d3c6d..61357ef77a 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -572,9 +572,18 @@ class Profile if (is_null($r)) { $s = DBA::p( "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event` - INNER JOIN `contact` ON `contact`.`id` = `event`.`cid` + INNER JOIN `contact` + ON `contact`.`id` = `event`.`cid` + 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` WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ? ORDER BY `start` ASC ", + Contact::SHARING, + Contact::FRIEND, local_user(), DateTimeFormat::utc('now + 6 days'), DateTimeFormat::utcNow()