]> git.mxchange.org Git - friendica.git/commitdiff
Move Contact::ACCOUNT_TYPE_* constants to User::ACCOUNT_TYPE_*
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 6 Jan 2019 22:08:35 +0000 (17:08 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 21 Jan 2019 15:56:27 +0000 (10:56 -0500)
- Keep Contact::TYPE_* constants for comparison with contact.contact-type

12 files changed:
mod/admin.php
mod/community.php
mod/noscrape.php
src/Model/Contact.php
src/Model/User.php
src/Network/Probe.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/OStatus.php
src/Worker/Delivery.php
src/Worker/Queue.php

index e20e9c341f7aca4e9d62b6a7df7e087e1447bd67..8ff3089d9c540d1081120df8313aabe97ada5ce8 100644 (file)
@@ -1995,10 +1995,11 @@ function admin_page_users(App $a)
                        User::PAGE_FLAGS_PRVGROUP  => L10n::t('Private Forum')
                ];
                $account_types = [
-                       Contact::ACCOUNT_TYPE_PERSON       => L10n::t('Personal Page'),
-                       Contact::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
-                       Contact::ACCOUNT_TYPE_NEWS         => L10n::t('News Page'),
-                       Contact::ACCOUNT_TYPE_COMMUNITY    => L10n::t('Community Forum')
+                       User::ACCOUNT_TYPE_PERSON       => L10n::t('Personal Page'),
+                       User::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
+                       User::ACCOUNT_TYPE_NEWS         => L10n::t('News Page'),
+                       User::ACCOUNT_TYPE_COMMUNITY    => L10n::t('Community Forum'),
+                       User::ACCOUNT_TYPE_RELAY        => L10n::t('Relay'),
                ];
 
                $e['page_flags_raw'] = $e['page-flags'];
index 063e1c693eafcd5d9d5a49d0b0f9b0eecd67d981..3c621f4261accf229c4230020a9b5d8832597847 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\User;
 
 function community_init(App $a)
 {
@@ -44,16 +45,16 @@ function community_content(App $a, $update = 0)
        if ($a->argc > 2) {
                switch ($a->argv[2]) {
                        case 'person':
-                               $accounttype = Contact::ACCOUNT_TYPE_PERSON;
+                               $accounttype = User::ACCOUNT_TYPE_PERSON;
                                break;
                        case 'organisation':
-                               $accounttype = Contact::ACCOUNT_TYPE_ORGANISATION;
+                               $accounttype = User::ACCOUNT_TYPE_ORGANISATION;
                                break;
                        case 'news':
-                               $accounttype = Contact::ACCOUNT_TYPE_NEWS;
+                               $accounttype = User::ACCOUNT_TYPE_NEWS;
                                break;
                        case 'community':
-                               $accounttype = Contact::ACCOUNT_TYPE_COMMUNITY;
+                               $accounttype = User::ACCOUNT_TYPE_COMMUNITY;
                                break;
                }
        }
index 3528a2f118d1862bdba1f13adb31fc64d919f1c8..5761df3ff902be078a0d91d0baec9cdbd8a4f5e0 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
+use Friendica\Model\User;
 
 function noscrape_init(App $a)
 {
@@ -32,7 +33,7 @@ function noscrape_init(App $a)
                'guid'         => $a->profile['guid'],
                'key'          => $a->profile['pubkey'],
                'homepage'     => System::baseUrl()."/profile/{$which}",
-               'comm'         => ($a->profile['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY),
+               'comm'         => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
                'account-type' => $a->profile['account-type'],
        ];
 
index 745bbacaddfa828b15dd16c12e6896db76360979..8937f198c772256fe2599b48e4c6e3b3f31f2b7f 100644 (file)
@@ -74,27 +74,30 @@ class Contact extends BaseObject
        /**
         * @name account types
         *
-        * ACCOUNT_TYPE_PERSON - the account belongs to a person
+        * TYPE_UNKNOWN - the account has been imported from gcontact where this is the default type value
+        *
+        * TYPE_PERSON - the account belongs to a person
         *      Associated page types: PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE
         *
-        * ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
+        * TYPE_ORGANISATION - the account belongs to an organisation
         *      Associated page type: PAGE_SOAPBOX
         *
-        * ACCOUNT_TYPE_NEWS - the account is a news reflector
+        * TYPE_NEWS - the account is a news reflector
         *      Associated page type: PAGE_SOAPBOX
         *
-        * ACCOUNT_TYPE_COMMUNITY - the account is community forum
+        * TYPE_COMMUNITY - the account is community forum
         *      Associated page types: PAGE_COMMUNITY, PAGE_PRVGROUP
         *
-        * ACCOUNT_TYPE_RELAY - the account is a relay
+        * TYPE_RELAY - the account is a relay
         *      This will only be assigned to contacts, not to user accounts
         * @{
         */
-       const ACCOUNT_TYPE_PERSON =       0;
-       const ACCOUNT_TYPE_ORGANISATION = 1;
-       const ACCOUNT_TYPE_NEWS =         2;
-       const ACCOUNT_TYPE_COMMUNITY =    3;
-       const ACCOUNT_TYPE_RELAY =        4;
+       const TYPE_UNKNOWN =     -1;
+       const TYPE_PERSON =       User::ACCOUNT_TYPE_PERSON;
+       const TYPE_ORGANISATION = User::ACCOUNT_TYPE_ORGANISATION;
+       const TYPE_NEWS =         User::ACCOUNT_TYPE_NEWS;
+       const TYPE_COMMUNITY =    User::ACCOUNT_TYPE_COMMUNITY;
+       const TYPE_RELAY =        User::ACCOUNT_TYPE_RELAY;
        /**
         * @}
         */
@@ -740,7 +743,7 @@ class Contact extends BaseObject
                DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]);
 
                if (!empty($contact['batch'])) {
-                       $condition = ['batch' => $contact['batch'], 'contact-type' => self::ACCOUNT_TYPE_RELAY];
+                       $condition = ['batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
                        DBA::update('contact', $fields, $condition);
                }
        }
@@ -1436,7 +1439,7 @@ class Contact extends BaseObject
                        $sql = "`item`.`uid` = ?";
                }
 
-               $contact_field = ($contact["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
+               $contact_field = ($contact["contact-type"] == self::TYPE_COMMUNITY ? 'owner-id' : 'author-id');
 
                if ($thread_mode) {
                        $condition = ["`$contact_field` = ? AND `gravity` = ? AND " . $sql,
@@ -1492,9 +1495,9 @@ class Contact extends BaseObject
                        || (isset($contact['prv']) && intval($contact['prv']))
                        || (isset($contact['community']) && intval($contact['community']))
                ) {
-                       $type = self::ACCOUNT_TYPE_COMMUNITY;
+                       $type = self::TYPE_COMMUNITY;
                } else {
-                       $type = self::ACCOUNT_TYPE_PERSON;
+                       $type = self::TYPE_PERSON;
                }
 
                // The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above.
@@ -1507,15 +1510,15 @@ class Contact extends BaseObject
                }
 
                switch ($type) {
-                       case self::ACCOUNT_TYPE_ORGANISATION:
+                       case self::TYPE_ORGANISATION:
                                $account_type = L10n::t("Organisation");
                                break;
 
-                       case self::ACCOUNT_TYPE_NEWS:
+                       case self::TYPE_NEWS:
                                $account_type = L10n::t('News');
                                break;
 
-                       case self::ACCOUNT_TYPE_COMMUNITY:
+                       case self::TYPE_COMMUNITY:
                                $account_type = L10n::t("Forum");
                                break;
 
index dd754fb46e5a0343169a94e3933925d05a980162..c33092a0fc7e844dbff75b3ddf23900e50672929 100644 (file)
@@ -48,6 +48,35 @@ class User
        /**
         * @}
         */
+
+       /**
+        * Account types
+        *
+        * ACCOUNT_TYPE_PERSON - the account belongs to a person
+        *      Associated page types: PAGE_FLAGS_NORMAL, PAGE_FLAGS_SOAPBOX, PAGE_FLAGS_FREELOVE
+        *
+        * ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
+        *      Associated page type: PAGE_FLAGS_SOAPBOX
+        *
+        * ACCOUNT_TYPE_NEWS - the account is a news reflector
+        *      Associated page type: PAGE_FLAGS_SOAPBOX
+        *
+        * ACCOUNT_TYPE_COMMUNITY - the account is community forum
+        *      Associated page types: PAGE_COMMUNITY, PAGE_FLAGS_PRVGROUP
+        *
+        * ACCOUNT_TYPE_RELAY - the account is a relay
+        *      This will only be assigned to contacts, not to user accounts
+        * @{
+        */
+       const ACCOUNT_TYPE_PERSON =       0;
+       const ACCOUNT_TYPE_ORGANISATION = 1;
+       const ACCOUNT_TYPE_NEWS =         2;
+       const ACCOUNT_TYPE_COMMUNITY =    3;
+       const ACCOUNT_TYPE_RELAY =        4;
+       /**
+        * @}
+        */
+
        /**
         * Returns true if a user record exists with the provided id
         *
index 9515db728a6f2a8ac2ed20e4c7aafbb8db47acd2..1a0607bf1223877dbbdfc0d5a07b047ed29a0a51 100644 (file)
@@ -417,7 +417,7 @@ class Probe
                                // This doesn't cover the case when a community isn't a community anymore
                                if (!empty($data['community']) && $data['community']) {
                                        $fields['community'] = $data['community'];
-                                       $fields['contact-type'] = Contact::ACCOUNT_TYPE_COMMUNITY;
+                                       $fields['contact-type'] = Contact::TYPE_COMMUNITY;
                                }
 
                                $fieldnames = [];
index 7f67bab7f58194c9497bc688d0792ff8a8554c0d..0ab2619412b16967d18dad05ff500c79bb5300c5 100644 (file)
@@ -503,13 +503,13 @@ class Receiver
 
                                // Check if the potential receiver is following the actor
                                // Exception: The receiver is targetted via "to" or this is a comment
-                               if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY)) {
+                               if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
                                        $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
                                        $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
                                                'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
 
                                        // Forum posts are only accepted from forum contacts
-                                       if ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
+                                       if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
                                                $condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
                                        }
 
@@ -576,7 +576,7 @@ class Receiver
 
                // When the possible receiver isn't a community, then it is no valid receiver
                $owner = User::getOwnerDataById($contact['uid']);
-               if (empty($owner) || ($owner['contact-type'] != Contact::ACCOUNT_TYPE_COMMUNITY)) {
+               if (empty($owner) || ($owner['contact-type'] != Contact::TYPE_COMMUNITY)) {
                        return false;
                }
 
index 550f5e07f17202dd85270733e4bafa2468a080f6..2dc5976b1dd5f71471754a88a3240bad305c9e58 100644 (file)
@@ -2878,7 +2878,7 @@ class DFRN
                                DBA::update('contact', ['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]);
                        }
                        // A forum contact can either have set "forum" or "prv" - but not both
-                       if ($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) {
+                       if ($accounttype == User::ACCOUNT_TYPE_COMMUNITY) {
                                // It's a forum, so either set the public or private forum flag
                                $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']];
                                DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);
index 9a29edaaf6355014c8bd5baf82674f16a3d727f9..beaf42c6c11db13e30a42e06b682b23e2185dfa0 100644 (file)
@@ -147,7 +147,7 @@ class Diaspora
 
                // Fetch the relay contact
                $condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
-                       'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
+                       'contact-type' => Contact::TYPE_RELAY];
                $contact = DBA::selectFirst('contact', $fields, $condition);
 
                if (DBA::isResult($contact)) {
@@ -187,7 +187,7 @@ class Diaspora
                $fields = array_merge($fields, $network_fields);
 
                $condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
-                       'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
+                       'contact-type' => Contact::TYPE_RELAY];
 
                if (DBA::exists('contact', $condition)) {
                        unset($fields['created']);
@@ -3165,7 +3165,7 @@ class Diaspora
                Logger::log("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
 
                if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) {
-                       if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) {
+                       if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) {
                                Logger::log("queue message");
                                // queue message for redelivery
                                Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid);
index a62e1266295adc87c78073c9d27136bdb253bce0..2196fb7726492cdc273b0a1655b172896d4ee3e9 100644 (file)
@@ -1349,7 +1349,7 @@ class OStatus
                $attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"];
                XML::addElement($doc, $root, "link", "", $attributes);
 
-               if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
+               if ($owner['account-type'] == Contact::TYPE_COMMUNITY) {
                        $condition = ['uid' => $owner['uid'], 'self' => false, 'pending' => false,
                                        'archive' => false, 'hidden' => false, 'blocked' => false];
                        $members = DBA::count('contact', $condition);
@@ -1461,7 +1461,7 @@ class OStatus
                $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
                $author = $doc->createElement("author");
                XML::addElement($doc, $author, "id", $owner["url"]);
-               if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
+               if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
                        XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
                } else {
                        XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
@@ -1945,7 +1945,7 @@ class OStatus
                                $title = sprintf("New note by %s", $owner["nick"]);
                        }
 
-                       if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
+                       if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
                                $contact = self::contactEntry($item['author-link'], $owner);
                                $author = self::addAuthor($doc, $contact, false);
                                $entry->appendChild($author);
@@ -2108,8 +2108,8 @@ class OStatus
                foreach ($mentioned as $mention) {
                        $condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($mention)];
                        $contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition);
-                       if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) ||
-                               ($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) {
+                       if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::TYPE_COMMUNITY) ||
+                               ($contact['self'] && ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY))) {
                                XML::addElement($doc, $entry, "link", "",
                                        [
                                                "rel" => "mentioned",
@@ -2126,7 +2126,7 @@ class OStatus
                        }
                }
 
-               if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
+               if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
                        XML::addElement($doc, $entry, "link", "", [
                                "rel" => "mentioned",
                                "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
@@ -2236,7 +2236,7 @@ class OStatus
                        $condition[] = ACTIVITY_OBJ_COMMENT;
                }
 
-               if ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY) {
+               if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
                        $condition[0] .= " AND `contact-id` = ? AND `author-id` = ?";
                        $condition[] = $owner["id"];
                        $condition[] = $authorid;
index 49fe47c54c2b2a977a885832ecb5e66fa38460ef..18654d5ed41dec45f1697e6ee99fcf2be2d7ecc1 100644 (file)
@@ -301,7 +301,7 @@ class Delivery extends BaseObject
                // Se we transmit with the new method and via Diaspora as a fallback
                if (!empty($items) && (($items[0]['uid'] == 0) || ($contact['uid'] == 0))) {
                        // Transmit in public if it's a relay post
-                       $public_dfrn = ($contact['contact-type'] == Contact::ACCOUNT_TYPE_RELAY);
+                       $public_dfrn = ($contact['contact-type'] == Contact::TYPE_RELAY);
 
                        $deliver_status = DFRN::transmit($owner, $contact, $atom, $public_dfrn);
 
@@ -359,7 +359,7 @@ class Delivery extends BaseObject
        private static function deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup)
        {
                // We don't treat Forum posts as "wall-to-wall" to be able to post them via Diaspora
-               $walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY);
+               $walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY);
 
                if ($public_message) {
                        $loc = 'public batch ' . $contact['batch'];
index 704ac00b4ebd21a250beef5408a144c4732f3736..48e962f03647d7a95290c296f53445894868e48d 100644 (file)
@@ -138,7 +138,7 @@ class Queue
                                $deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true, 'Queue:' . $q_item['id'], true);
 
                                if ((($deliver_status >= 200) && ($deliver_status <= 299)) ||
-                                       ($contact['contact-type'] == Contact::ACCOUNT_TYPE_RELAY)) {
+                                       ($contact['contact-type'] == Contact::TYPE_RELAY)) {
                                        QueueModel::removeItem($q_item['id']);
                                } else {
                                        QueueModel::updateTime($q_item['id']);