]> git.mxchange.org Git - friendica.git/commitdiff
Move DFRN::birthdayEvent() to Event::createBirthday
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 22 Nov 2018 05:15:09 +0000 (00:15 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 22 Nov 2018 05:15:09 +0000 (00:15 -0500)
src/Model/Event.php
src/Protocol/DFRN.php

index 735638287144e6b83454b55b53bdbe9be25919b8..886f124153ac0a41bbbd1e7f58f6f4907aeba085 100644 (file)
@@ -322,43 +322,48 @@ class Event extends BaseObject
                        // New event. Store it.
                        DBA::insert('event', $event);
 
-                       $event['id'] = DBA::lastInsertId();
-
-                       $item_arr = [];
-
-                       $item_arr['uid']           = $event['uid'];
-                       $item_arr['contact-id']    = $event['cid'];
-                       $item_arr['uri']           = $event['uri'];
-                       $item_arr['parent-uri']    = $event['uri'];
-                       $item_arr['guid']          = $event['guid'];
-                       $item_arr['plink']         = defaults($arr, 'plink', '');
-                       $item_arr['post-type']     = Item::PT_EVENT;
-                       $item_arr['wall']          = $event['cid'] ? 0 : 1;
-                       $item_arr['contact-id']    = $contact['id'];
-                       $item_arr['owner-name']    = $contact['name'];
-                       $item_arr['owner-link']    = $contact['url'];
-                       $item_arr['owner-avatar']  = $contact['thumb'];
-                       $item_arr['author-name']   = $contact['name'];
-                       $item_arr['author-link']   = $contact['url'];
-                       $item_arr['author-avatar'] = $contact['thumb'];
-                       $item_arr['title']         = '';
-                       $item_arr['allow_cid']     = $event['allow_cid'];
-                       $item_arr['allow_gid']     = $event['allow_gid'];
-                       $item_arr['deny_cid']      = $event['deny_cid'];
-                       $item_arr['deny_gid']      = $event['deny_gid'];
-                       $item_arr['private']       = $private;
-                       $item_arr['visible']       = 1;
-                       $item_arr['verb']          = ACTIVITY_POST;
-                       $item_arr['object-type']   = ACTIVITY_OBJ_EVENT;
-                       $item_arr['origin']        = $event['cid'] === 0 ? 1 : 0;
-                       $item_arr['body']          = self::getBBCode($event);
-                       $item_arr['event-id']      = $event['id'];
-
-                       $item_arr['object']  = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
-                       $item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
-                       $item_arr['object'] .= '</object>' . "\n";
-
-                       $item_id = Item::insert($item_arr);
+                       $item_id = 0;
+
+                       // Don't create an item for birthday events
+                       if ($event['type'] == 'event') {
+                               $event['id'] = DBA::lastInsertId();
+
+                               $item_arr = [];
+
+                               $item_arr['uid']           = $event['uid'];
+                               $item_arr['contact-id']    = $event['cid'];
+                               $item_arr['uri']           = $event['uri'];
+                               $item_arr['parent-uri']    = $event['uri'];
+                               $item_arr['guid']          = $event['guid'];
+                               $item_arr['plink']         = defaults($arr, 'plink', '');
+                               $item_arr['post-type']     = Item::PT_EVENT;
+                               $item_arr['wall']          = $event['cid'] ? 0 : 1;
+                               $item_arr['contact-id']    = $contact['id'];
+                               $item_arr['owner-name']    = $contact['name'];
+                               $item_arr['owner-link']    = $contact['url'];
+                               $item_arr['owner-avatar']  = $contact['thumb'];
+                               $item_arr['author-name']   = $contact['name'];
+                               $item_arr['author-link']   = $contact['url'];
+                               $item_arr['author-avatar'] = $contact['thumb'];
+                               $item_arr['title']         = '';
+                               $item_arr['allow_cid']     = $event['allow_cid'];
+                               $item_arr['allow_gid']     = $event['allow_gid'];
+                               $item_arr['deny_cid']      = $event['deny_cid'];
+                               $item_arr['deny_gid']      = $event['deny_gid'];
+                               $item_arr['private']       = $private;
+                               $item_arr['visible']       = 1;
+                               $item_arr['verb']          = ACTIVITY_POST;
+                               $item_arr['object-type']   = ACTIVITY_OBJ_EVENT;
+                               $item_arr['origin']        = $event['cid'] === 0 ? 1 : 0;
+                               $item_arr['body']          = self::getBBCode($event);
+                               $item_arr['event-id']      = $event['id'];
+
+                               $item_arr['object']  = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
+                               $item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
+                               $item_arr['object'] .= '</object>' . "\n";
+
+                               $item_id = Item::insert($item_arr);
+                       }
 
                        Addon::callHooks("event_created", $event['id']);
                }
@@ -981,4 +986,47 @@ class Event extends BaseObject
 
                return $location;
        }
+
+       /**
+        * @brief Add new birthday event for this person
+        *
+        * @param array  $contact  Contact array, expects: id, uid, url, name
+        * @param string $birthday Birthday of the contact
+        * @return bool
+        */
+       public static function createBirthday($contact, $birthday)
+       {
+               // Check for duplicates
+               $condition = [
+                       'uid' => $contact['uid'],
+                       'cid' => $contact['id'],
+                       'start' => DateTimeFormat::utc($birthday),
+                       'type' => 'birthday'
+               ];
+               if (DBA::exists('event', $condition)) {
+                       return false;
+               }
+
+               /*
+                * Add new birthday event for this person
+                *
+                * summary 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.
+                */
+               $values = [
+                       'uid'     => $contact['uid'],
+                       'cid'     => $contact['id'],
+                       'start'   => DateTimeFormat::utc($birthday),
+                       'finish'  => DateTimeFormat::utc($birthday . ' + 1 day '),
+                       'summary' => L10n::t('%s\'s birthday', $contact['name']),
+                       'desc'    => L10n::t('Happy Birthday %s', ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'),
+                       'type'    => 'birthday',
+                       'adjust'  => 0
+               ];
+
+               self::store($values);
+
+               return true;
+       }
 }
index 7c03a218394e980e1adab0036f8079bd867c9be4..b67b7c021fc76d5a10f85e00202db00fee54b3c6 100644 (file)
@@ -1509,43 +1509,6 @@ class DFRN
                return intval($res->status);
        }
 
-       /**
-        * @brief Add new birthday event for this person
-        *
-        * @param array  $contact  Contact record
-        * @param string $birthday Birthday of the contact
-        * @return void
-        * @todo Add array type-hint for $contact
-        */
-       private static function birthdayEvent($contact, $birthday)
-       {
-               // Check for duplicates
-               $condition = ['uid' => $contact['uid'], 'cid' => $contact['id'],
-                       'start' => DateTimeFormat::utc($birthday), 'type' => 'birthday'];
-               if (DBA::exists('event', $condition)) {
-                       return;
-               }
-
-               Logger::log('updating birthday: ' . $birthday . ' for contact ' . $contact['id']);
-
-               $bdtext = L10n::t('%s\'s birthday', $contact['name']);
-               $bdtext2 = L10n::t('Happy Birthday %s', ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]');
-
-               $r = q(
-                       "INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
-                       VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
-                       intval($contact['uid']),
-                       intval($contact['id']),
-                       DBA::escape(DateTimeFormat::utcNow()),
-                       DBA::escape(DateTimeFormat::utcNow()),
-                       DBA::escape(DateTimeFormat::utc($birthday)),
-                       DBA::escape(DateTimeFormat::utc($birthday . ' + 1 day ')),
-                       DBA::escape($bdtext),
-                       DBA::escape($bdtext2),
-                       DBA::escape('birthday')
-               );
-       }
-
        /**
         * @brief Fetch the author data from head or entry items
         *
@@ -1736,7 +1699,7 @@ class DFRN
                        $contact = array_merge($contact_old, $poco);
 
                        if ($contact_old["bdyear"] != $contact["bdyear"]) {
-                               self::birthdayEvent($contact, $birthday);
+                               Event::createBirthday($contact, $birthday);
                        }
 
                        // Get all field names