]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Replace reference to post plink by author base URL
[friendica.git] / src / Model / User.php
index 742b8555d7d309963a7e555dde9ed0d4674d5765..af7a81a15dccc4a2ad22879d68beae7cb5eea192 100644 (file)
@@ -37,6 +37,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Module;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Image;
@@ -132,6 +133,17 @@ class User
                return null;
        }
 
+       /**
+        * Get the Uri-Id of the system account
+        *
+        * @return integer
+        */
+       public static function getSystemUriId(): int
+       {
+               $system = self::getSystemAccount();
+               return $system['uri-id'] ?? 0;
+       }
+
        /**
         * Fetch the system account
         *
@@ -869,6 +881,20 @@ class User
                ]);
        }
 
+       /**
+        * Returns if the given uid is valid and a moderator
+        *
+        * @param int $uid
+        *
+        * @return bool
+        * @throws Exception
+        */
+       public static function isModerator(int $uid): bool
+       {
+               // @todo Replace with a moderator check in the future
+               return self::isSiteAdmin($uid);
+       }
+
        /**
         * Checks if a nickname is in the list of the forbidden nicknames
         *
@@ -1227,7 +1253,7 @@ class User
                DBA::update('user', $fields, ['uid' => $uid]);
 
                $def_gid_groups = Circle::create($uid, DI::l10n()->t('Groups'));
-               if (!$def_gid_groups) {
+               if ($def_gid_groups) {
                        DI::pConfig()->set($uid, 'system', 'default-group-gid', $def_gid_groups);
                }
 
@@ -1303,33 +1329,18 @@ class User
        /**
         * Update a user entry and distribute the changes if needed
         *
-        * @param array $fields
+        * @param array   $fields
         * @param integer $uid
         * @return boolean
+        * @throws Exception
         */
        public static function update(array $fields, int $uid): bool
        {
-               $old_owner = self::getOwnerDataById($uid);
-               if (empty($old_owner)) {
-                       return false;
-               }
-
                if (!DBA::update('user', $fields, ['uid' => $uid])) {
                        return false;
                }
 
-               $update = Contact::updateSelfFromUserID($uid);
-
-               $owner = self::getOwnerDataById($uid);
-               if (empty($owner)) {
-                       return false;
-               }
-
-               if ($old_owner['name'] != $owner['name']) {
-                       Profile::update(['name' => $owner['name']], $uid);
-               }
-
-               if ($update) {
+               if (Contact::updateSelfFromUserID($uid)) {
                        Profile::publishUpdate($uid);
                }