]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Local_group and User are now assumed to be in same namespace
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 16 Oct 2013 23:16:03 +0000 (01:16 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 16 Oct 2013 23:27:01 +0000 (01:27 +0200)
15 files changed:
actions/apichecknickname.php
actions/apigroupcreate.php
actions/apigroupprofileupdate.php
actions/editgroup.php
actions/newgroup.php
actions/profilesettings.php
classes/Group_alias.php
classes/Local_group.php
classes/User.php
classes/User_group.php
lib/groupnoprofileexception.php
lib/nickname.php
lib/noprofileexception.php
lib/pluginqueuehandler.php
plugins/TwitterBridge/actions/twitterauthorization.php

index 6867a428cf55334a34300e4b2084130c240310aa..1d9c6842f3934f43b64ac5c3a87cf622767e05a1 100644 (file)
@@ -62,10 +62,4 @@ class ApiCheckNicknameAction extends ApiAction
         $this->showJsonObjects($nickname_ok);
         $this->endDocument('json');
     }
-    
-    function nicknameExists($nickname)
-    {
-        $user = User::staticGet('nickname', $nickname);
-        return ($user instanceof User);
-    }
 }
index 2dd0e9db1b570a9f31ed25a5e1f63b740b50544e..1e36f3e7b90404b2462a974bb43a19261856d746 100644 (file)
@@ -71,7 +71,7 @@ class ApiGroupCreateAction extends ApiAuthAction
     {
         parent::prepare($args);
 
-        $this->nickname    = Nickname::normalize($this->arg('nickname'));
+        $this->nickname    = Nickname::normalize($this->arg('nickname'), true);
         $this->fullname    = $this->arg('full_name');
         $this->homepage    = $this->arg('homepage');
         $this->description = $this->arg('description');
@@ -130,22 +130,13 @@ class ApiGroupCreateAction extends ApiAuthAction
      */
     function validateParams()
     {
-        if ($this->groupNicknameExists($this->nickname)) {
-            // TRANS: Client error trying to create a group with a nickname this is already in use.
-            $this->clientError(_('Nickname already in use. Try another one.'), 403);
-
-        } elseif (!User_group::allowedNickname($this->nickname)) {
-            // TRANS: Client error in form for group creation.
-            $this->clientError(_('Not a valid nickname.'), 403);
-
-        } elseif (!is_null($this->homepage)
+        if (!is_null($this->homepage)
                 && strlen($this->homepage) > 0
                 && !common_valid_http_url($this->homepage)) {
             // TRANS: Client error in form for group creation.
             $this->clientError(_('Homepage is not a valid URL.'), 403);
 
-        } elseif (
-                !is_null($this->fullname)
+        } elseif (!is_null($this->fullname)
                 && mb_strlen($this->fullname) > 255) {
             // TRANS: Client error in form for group creation.
             $this->clientError(_('Full name is too long (maximum 255 characters).'), 403);
@@ -165,7 +156,7 @@ class ApiGroupCreateAction extends ApiAuthAction
 
         if (!empty($this->aliasstring)) {
             $this->aliases = array_map(
-                'common_canonical_nickname',
+                array('Nickname', 'normalize'), // static call to Nickname::normalize
                 array_unique(preg_split('/[\s,]+/', $this->aliasstring))
             );
         } else {
@@ -183,53 +174,8 @@ class ApiGroupCreateAction extends ApiAuthAction
                 403);
         }
 
-        foreach ($this->aliases as $alias) {
-
-            if (!Nickname::isValid($alias)) {
-                // TRANS: Client error shown when providing an invalid alias during group creation.
-                // TRANS: %s is the invalid alias.
-                $this->clientError(sprintf(_('Invalid alias: "%s".'), $alias), 403);
-            }
-            if ($this->groupNicknameExists($alias)) {
-                // TRANS: Client error displayed when trying to use an alias during group creation that is already in use.
-                // TRANS: %s is the alias that is already in use.
-                $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), $alias), 403);
-            }
-
-            // XXX assumes alphanum nicknames
-
-            if (strcmp($alias, $this->nickname) == 0) {
-                // TRANS: Client error displayed when trying to use an alias during group creation that is the same as the group's nickname.
-                $this->clientError(_('Alias can\'t be the same as nickname.'), 403);
-            }
-        }
-
         // Everything looks OK
 
         return true;
     }
-
-    /**
-     * Check to see whether a nickname is already in use by a group
-     *
-     * @param String $nickname The nickname in question
-     *
-     * @return boolean true or false
-     */
-    function groupNicknameExists($nickname)
-    {
-        $local = Local_group::getKV('nickname', $nickname);
-
-        if (!empty($local)) {
-            return true;
-        }
-
-        $alias = Group_alias::getKV('alias', $nickname);
-
-        if (!empty($alias)) {
-            return true;
-        }
-
-        return false;
-    }
 }
index 14ec84326967ccafc8a2ba667579e2ad1fa3ad5d..2f4d07b7a4f4287e8abe278646cfebed92c91d28 100644 (file)
@@ -107,13 +107,18 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
         try {
 
             if (!empty($this->nickname)) {
-                if ($this->validateNickname()) {
-                    $this->group->nickname = $this->nickname;
-                    $this->group->mainpage = common_local_url(
-                        'showgroup',
-                        array('nickname' => $this->nickname)
-                    );
+                try {
+                    $this->group->nickname = Nickname::normalize($this->nickname, true);
+                } catch (NicknameTakenException $e) {
+                    // Abort only if the nickname is occupied by _another_ local group
+                    if ($e->profile->id != $this->group->id) {
+                        throw new ApiValidationException($e->getMessage());
+                    }
+                } catch (NicknameException $e) {
+                    throw new ApiValidationException($e->getMessage());
                 }
+                $this->group->mainpage = common_local_url('showgroup',
+                                            array('nickname' => $this->group->nickname));
             }
 
             if (!empty($this->fullname)) {
@@ -123,7 +128,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
 
             if (!empty($this->homepage)) {
                 $this->validateHomepage();
-                $this->group->homepage = $this->hompage;
+                $this->group->homepage = $this->homepage;
             }
 
             if (!empty($this->description)) {
@@ -137,7 +142,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
             }
 
         } catch (ApiValidationException $ave) {
-            $this->clientError($ave->getMessage(), 403);
+            $this->clientError($ave->getMessage(), 400);
         }
 
         $result = $this->group->update($orig);
@@ -154,7 +159,6 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
             if (!empty($this->aliasstring)) {
                 $aliases = $this->validateAliases();
             }
-
         } catch (ApiValidationException $ave) {
             $this->clientError($ave->getMessage(), 403);
         }
@@ -187,54 +191,6 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
         }
     }
 
-    function nicknameExists($nickname)
-    {
-        $group = Local_group::getKV('nickname', $nickname);
-
-        if (!empty($group) &&
-            $group->group_id != $this->group->id) {
-            return true;
-        }
-
-        $alias = Group_alias::getKV('alias', $nickname);
-
-        if (!empty($alias) &&
-            $alias->group_id != $this->group->id) {
-            return true;
-        }
-
-        return false;
-    }
-
-    function validateNickname()
-    {
-        if (!Validate::string(
-            $this->nickname, array(
-                'min_length' => 1,
-                'max_length' => 64,
-                'format' => NICKNAME_FMT
-                )
-            )
-        ) {
-            throw new ApiValidationException(
-                // TRANS: API validation exception thrown when nickname does not validate.
-                _('Nickname must have only lowercase letters and numbers and no spaces.')
-            );
-        } else if ($this->nicknameExists($this->nickname)) {
-            throw new ApiValidationException(
-                // TRANS: API validation exception thrown when nickname is already used.
-                _('Nickname already in use. Try another one.')
-            );
-        } else if (!User_group::allowedNickname($this->nickname)) {
-            throw new ApiValidationException(
-                // TRANS: API validation exception thrown when nickname does not validate.
-                _('Not a valid nickname.')
-            );
-        }
-
-               return true;
-    }
-
     function validateHomepage()
     {
         if (!is_null($this->homepage)
@@ -281,14 +237,12 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
 
     function validateAliases()
     {
-        $aliases = array_map(
-            'common_canonical_nickname',
-            array_unique(
-                preg_split('/[\s,]+/',
-                $this->aliasstring
-                )
-            )
-        );
+        try {
+            $aliases = array_map(array('Nickname', 'normalize'),
+                            array_unique(preg_split('/[\s,]+/', $this->aliasstring)));
+        } catch (NicknameException $e) {
+            throw new ApiValidationException(sprintf('Error processing aliases: %s', $e->getMessage()));
+        }
 
         if (count($aliases) > common_config('group', 'maxaliases')) {
             // TRANS: API validation exception thrown when aliases do not validate.
@@ -299,43 +253,6 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
                                                      common_config('group', 'maxaliases')));
         }
 
-        foreach ($aliases as $alias) {
-            if (!Validate::string(
-                $alias, array(
-                    'min_length' => 1,
-                    'max_length' => 64,
-                    'format' => NICKNAME_FMT)
-                )
-            ) {
-                throw new ApiValidationException(
-                    sprintf(
-                        // TRANS: API validation exception thrown when aliases does not validate.
-                        // TRANS: %s is the invalid alias.
-                        _('Invalid alias: "%s".'),
-                        $alias
-                    )
-                );
-            }
-
-            if ($this->nicknameExists($alias)) {
-                throw new ApiValidationException(
-                    sprintf(
-                        // TRANS: API validation exception thrown when aliases is already used.
-                        // TRANS: %s is the already used alias.
-                        _('Alias "%s" already in use. Try another one.'),
-                        $alias)
-                );
-            }
-
-            // XXX assumes alphanum nicknames
-            if (strcmp($alias, $this->nickname) == 0) {
-                throw new ApiValidationException(
-                    // TRANS: API validation exception thrown when alias is the same as nickname.
-                    _('Alias cannot be the same as nickname.')
-                );
-            }
-        }
-
         return $aliases;
     }
 }
index b73f1f13f77208bec321cd4cb1a4b7c2cfbe8d89..10ce4a211236e33e1bf14ac651e3584f79afdf56 100644 (file)
@@ -168,12 +168,25 @@ class EditgroupAction extends GroupAction
         if (!$cur->isAdmin($this->group)) {
             // TRANS: Client error displayed trying to edit a group while not being a group admin.
             $this->clientError(_('You must be an admin to edit the group.'), 403);
-            return;
         }
 
         if (Event::handle('StartGroupSaveForm', array($this))) {
 
-            $nickname    = Nickname::normalize($this->trimmed('newnickname'));
+            $nickname = $this->trimmed('newnickname');
+            try {
+                $nickname = Nickname::normalize($nickname, true);
+            } catch (NicknameTakenException $e) {
+                // Abort only if the nickname is occupied by _another_ group
+                if ($e->profile->id != $this->group->id) {
+                    $this->showForm($e->getMessage());
+                    return;
+                }
+                $nickname = Nickname::normalize($nickname); // without in-use check this time
+            } catch (NicknameException $e) {
+                $this->showForm($e->getMessage());
+                return;
+            }
+
             $fullname    = $this->trimmed('fullname');
             $homepage    = $this->trimmed('homepage');
             $description = $this->trimmed('description');
@@ -189,15 +202,7 @@ class EditgroupAction extends GroupAction
                 $join_policy = User_group::JOIN_POLICY_OPEN;
             }
 
-            if ($this->nicknameExists($nickname)) {
-                // TRANS: Group edit form validation error.
-                $this->showForm(_('Nickname already in use. Try another one.'));
-                return;
-            } else if (!User_group::allowedNickname($nickname)) {
-                // TRANS: Group edit form validation error.
-                $this->showForm(_('Not a valid nickname.'));
-                return;
-            } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
+            if (!is_null($homepage) && (strlen($homepage) > 0) &&
                        !common_valid_http_url($homepage)) {
                 // TRANS: Group edit form validation error.
                 $this->showForm(_('Homepage is not a valid URL.'));
@@ -221,7 +226,8 @@ class EditgroupAction extends GroupAction
             }
 
             if (!empty($aliasstring)) {
-                $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring)));
+                $aliases = array_map(array('Nickname', 'normalize'),
+                                     array_unique(preg_split('/[\s,]+/', $aliasstring)));
             } else {
                 $aliases = array();
             }
@@ -236,26 +242,6 @@ class EditgroupAction extends GroupAction
                 return;
             }
 
-            foreach ($aliases as $alias) {
-                if (!Nickname::isValid($alias)) {
-                    // TRANS: Group edit form validation error.
-                    $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
-                    return;
-                }
-                if ($this->nicknameExists($alias)) {
-                    // TRANS: Group edit form validation error.
-                    $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'),
-                                            $alias));
-                    return;
-                }
-                // XXX assumes alphanum nicknames
-                if (strcmp($alias, $nickname) == 0) {
-                    // TRANS: Group edit form validation error.
-                    $this->showForm(_('Alias can\'t be the same as nickname.'));
-                    return;
-                }
-            }
-
             $this->group->query('BEGIN');
 
             $orig = clone($this->group);
@@ -271,7 +257,7 @@ class EditgroupAction extends GroupAction
 
             $result = $this->group->update($orig);
 
-            if (!$result) {
+            if ($result === false) {
                 common_log_db_error($this->group, 'UPDATE', __FILE__);
                 // TRANS: Server error displayed when editing a group fails.
                 $this->serverError(_('Could not update group.'));
@@ -304,23 +290,4 @@ class EditgroupAction extends GroupAction
             $this->showForm(_('Options saved.'));
         }
     }
-
-    function nicknameExists($nickname)
-    {
-        $group = Local_group::getKV('nickname', $nickname);
-
-        if (!empty($group) &&
-            $group->group_id != $this->group->id) {
-            return true;
-        }
-
-        $alias = Group_alias::getKV('alias', $nickname);
-
-        if (!empty($alias) &&
-            $alias->group_id != $this->group->id) {
-            return true;
-        }
-
-        return false;
-    }
 }
index a1c58c5c0f5bfb03a7c99e8ca2033f619e7b03be..b20267a4968fd3c14a6f5f6df86a3beabcc5d42d 100644 (file)
@@ -86,7 +86,7 @@ class NewgroupAction extends FormAction
         parent::handlePost();
 
         if (Event::handle('StartGroupSaveForm', array($this))) {
-            $nickname = Nickname::normalize($this->trimmed('newnickname'));
+            $nickname = Nickname::normalize($this->trimmed('newnickname'), true);
 
             $fullname    = $this->trimmed('fullname');
             $homepage    = $this->trimmed('homepage');
@@ -95,13 +95,7 @@ class NewgroupAction extends FormAction
             $private     = $this->boolean('private');
             $aliasstring = $this->trimmed('aliases');
 
-            if ($this->nicknameExists($nickname)) {
-                // TRANS: Group create form validation error.
-                throw new ClientException(_('Nickname already in use. Try another one.'));
-            } else if (!User_group::allowedNickname($nickname)) {
-                // TRANS: Group create form validation error.
-                throw new ClientException(_('Not a valid nickname.'));
-            } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
+            if (!is_null($homepage) && (strlen($homepage) > 0) &&
                        !common_valid_http_url($homepage)) {
                 // TRANS: Group create form validation error.
                 throw new ClientException(_('Homepage is not a valid URL.'));
@@ -121,7 +115,7 @@ class NewgroupAction extends FormAction
             }
 
             if (!empty($aliasstring)) {
-                $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring)));
+                $aliases = array_map(array('Nickname', 'normalize'), array_unique(preg_split('/[\s,]+/', $aliasstring)));
             } else {
                 $aliases = array();
             }
@@ -136,24 +130,6 @@ class NewgroupAction extends FormAction
                 return;
             }
 
-            foreach ($aliases as $alias) {
-                if (!Nickname::isValid($alias)) {
-                    // TRANS: Group create form validation error.
-                    // TRANS: %s is the invalid alias.
-                    throw new ClientException(sprintf(_('Invalid alias: "%s"'), $alias));
-                }
-                if ($this->nicknameExists($alias)) {
-                    // TRANS: Group create form validation error. %s is the already used alias.
-                    throw new ClientException(sprintf(_('Alias "%s" already in use. Try another one.'),
-                                            $alias));
-                }
-                // XXX assumes alphanum nicknames
-                if (strcmp($alias, $nickname) == 0) {
-                    // TRANS: Group create form validation error.
-                    throw new ClientException(_('Alias cannot be the same as nickname.'));
-                }
-            }
-
             if ($private) {
                 $force_scope = 1;
                 $join_policy = User_group::JOIN_POLICY_MODERATE;
@@ -183,21 +159,4 @@ class NewgroupAction extends FormAction
             common_redirect($group->homeUrl(), 303);
         }
     }
-
-    function nicknameExists($nickname)
-    {
-        $local = Local_group::getKV('nickname', $nickname);
-
-        if (!empty($local)) {
-            return true;
-        }
-
-        $alias = Group_alias::getKV('alias', $nickname);
-
-        if (!empty($alias)) {
-            return true;
-        }
-
-        return false;
-    }
 }
index b2c9a3c01490a27def8513fdf16a26f7781f3811..71bc40ce9add95abfa53ebf42767ed0582880000 100644 (file)
@@ -243,8 +243,8 @@ class ProfilesettingsAction extends SettingsAction
             try {
                 $nickname = Nickname::normalize($nickname, true);
             } catch (NicknameTakenException $e) {
-                // Abort only if the nickname is occupied by another user
-                if ($e->byuser->id != $this->scoped->id) {
+                // Abort only if the nickname is occupied by another local profile
+                if ($e->profile->id != $this->scoped->id) {
                     $this->showForm($e->getMessage());
                     return;
                 }
index 5a70c1c9ae75b82b74d9859f13f52f9213bcb46e..d8bb63cdbdcfed0ed8e8709fc8d0e1d0428e4847 100644 (file)
@@ -53,4 +53,13 @@ class Group_alias extends Managed_DataObject
             ),
         );
     }
+
+    public function getProfile()
+    {
+        $group = User_group::getKV('id', $this->group_id);
+        if (!($group instanceof User_group)) {
+            return null;    // TODO: Throw exception when other code is ready
+        }
+        return $group->getProfile();
+    }
 }
index 9136c461ba2c07ceb58d5d10b93bef08f2ee49b3..95182a7c8f4a2b81665d0321fc4272fa9a9fc2dd 100644 (file)
@@ -38,6 +38,15 @@ class Local_group extends Managed_DataObject
         );
     }
 
+    public function getProfile()
+    {
+        $group = User_group::getKV('id', $this->group_id);
+        if (!($group instanceof User_group)) {
+            return null;    // TODO: Throw exception when other code is ready
+        }
+        return $group->getProfile();
+    }
+
     function setNickname($nickname)
     {
         $this->decache();
index 33fabf829621860366992e7b335501d2fb6fe526..7b53877a31f60234833be5cbde9541dd2cef1b5b 100644 (file)
@@ -685,6 +685,11 @@ class User extends Managed_DataObject
 
     function delete()
     {
+        if (empty($this->id)) {
+            common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
+            return parent::delete();
+        }
+
         try {
             $profile = $this->getProfile();
             $profile->delete();
index 1d15b78841d804034fb413d4e3e9772c03e215e2..92092588746b10d2b0e70cbc45a0c450383f38a7 100644 (file)
@@ -73,6 +73,25 @@ class User_group extends Managed_DataObject
         );
     }
 
+    protected $_profile = null;
+
+    /**
+     * @return Profile
+     *
+     * @throws UserNoProfileException if user has no profile
+     */
+    public function getProfile()
+    {
+        if (!($this->_profile instanceof Profile)) {
+            $this->_profile = Profile::getKV('id', $this->profile_id);
+            if (!($this->_profile instanceof Profile)) {
+                throw new GroupNoProfileException($this);
+            }
+        }
+
+        return $this->_profile;
+    }
+
     public static function defaultLogo($size)
     {
         static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
@@ -130,13 +149,6 @@ class User_group extends Managed_DataObject
         return $stream->getNotices($offset, $limit, $since_id, $max_id);
     }
 
-
-    function allowedNickname($nickname)
-    {
-        static $blacklist = array('new');
-        return !in_array($nickname, $blacklist);
-    }
-
     function getMembers($offset=0, $limit=null) {
         $ids = null;
         if (is_null($limit) || $offset + $limit > User_group::CACHE_WINDOW) {
@@ -392,7 +404,10 @@ class User_group extends Managed_DataObject
         }
 
         foreach ($to_insert as $insalias) {
-            $alias->alias = $insalias;
+            if ($insalias === $this->nickname) {
+                continue;
+            }
+            $alias->alias = Nickname::normalize($insalias, true);
             $result = $alias->insert();
             if (!$result) {
                 common_log_db_error($alias, 'INSERT', __FILE__);
@@ -405,7 +420,7 @@ class User_group extends Managed_DataObject
 
     static function getForNickname($nickname, $profile=null)
     {
-        $nickname = common_canonical_nickname($nickname);
+        $nickname = Nickname::normalize($nickname);
 
         // Are there any matching remote groups this profile's in?
         if ($profile) {
@@ -566,6 +581,8 @@ class User_group extends Managed_DataObject
             }
         }
 
+        $fields['nickname'] = Nickname::normalize($fields['nickname']);
+
         // MAGICALLY put fields into current scope
         // @fixme kill extract(); it makes debugging absurdly hard
 
@@ -585,8 +602,6 @@ class User_group extends Managed_DataObject
 
         $group = new User_group();
 
-        $group->query('BEGIN');
-
         if (empty($uri)) {
             // fill in later...
             $uri = null;
@@ -595,14 +610,33 @@ class User_group extends Managed_DataObject
             $mainpage = common_local_url('showgroup', array('nickname' => $nickname));
         }
 
-        $group->nickname    = $nickname;
-        $group->fullname    = $fullname;
-        $group->homepage    = $homepage;
-        $group->description = $description;
-        $group->location    = $location;
-        $group->uri         = $uri;
-        $group->mainpage    = $mainpage;
-        $group->created     = common_sql_now();
+        // We must create a new, incrementally assigned profile_id
+        $profile = new Profile();
+        $profile->nickname   = $nickname;
+        $profile->fullname   = $fullname;
+        $profile->profileurl = $mainpage;
+        $profile->homepage   = $homepage;
+        $profile->bio        = $description;
+        $profile->location   = $location;
+        $profile->created    = common_sql_now();
+
+        $group->nickname    = $profile->nickname;
+        $group->fullname    = $profile->fullname;
+        $group->homepage    = $profile->homepage;
+        $group->description = $profile->bio;
+        $group->location    = $profile->location;
+        $group->mainpage    = $profile->profileurl;
+        $group->created     = $profile->created;
+
+        $profile->query('BEGIN');
+        $id = $profile->insert();
+        if (empty($id)) {
+            $profile->query('ROLLBACK');
+            throw new ServerException(_('Profile insertion failed'));
+        }
+
+        $group->profile_id = $id;
+        $group->uri        = $uri;
 
         if (isset($fields['join_policy'])) {
             $group->join_policy = intval($fields['join_policy']);
@@ -677,11 +711,11 @@ class User_group extends Managed_DataObject
                 }
             }
 
-            $group->query('COMMIT');
-
             Event::handle('EndGroupSave', array($group));
         }
 
+        $profile->query('COMMIT');
+
         return $group;
     }
 
@@ -695,51 +729,57 @@ class User_group extends Managed_DataObject
      */
     function delete()
     {
-        if ($this->id) {
+        if (empty($this->id)) {
+            common_log(LOG_WARNING, "Ambiguous User_group->delete(); skipping related tables.");
+            return parent::delete();
+        }
 
-            // Safe to delete in bulk for now
+        try {
+            $profile = $this->getProfile();
+            $profile->delete();
+        } catch (GroupNoProfileException $unp) {
+            common_log(LOG_INFO, "Group {$this->nickname} has no profile; continuing deletion.");
+        }
 
-            $related = array('Group_inbox',
-                             'Group_block',
-                             'Group_member',
-                             'Related_group');
+        // Safe to delete in bulk for now
 
-            Event::handle('UserGroupDeleteRelated', array($this, &$related));
+        $related = array('Group_inbox',
+                         'Group_block',
+                         'Group_member',
+                         'Related_group');
 
-            foreach ($related as $cls) {
+        Event::handle('UserGroupDeleteRelated', array($this, &$related));
 
-                $inst = new $cls();
-                $inst->group_id = $this->id;
+        foreach ($related as $cls) {
+            $inst = new $cls();
+            $inst->group_id = $this->id;
 
-                if ($inst->find()) {
-                    while ($inst->fetch()) {
-                        $dup = clone($inst);
-                        $dup->delete();
-                    }
+            if ($inst->find()) {
+                while ($inst->fetch()) {
+                    $dup = clone($inst);
+                    $dup->delete();
                 }
             }
+        }
 
-            // And related groups in the other direction...
-            $inst = new Related_group();
-            $inst->related_group_id = $this->id;
-            $inst->delete();
-
-            // Aliases and the local_group entry need to be cleared explicitly
-            // or we'll miss clearing some cache keys; that can make it hard
-            // to create a new group with one of those names or aliases.
-            $this->setAliases(array());
-            $local = Local_group::getKV('group_id', $this->id);
-            if ($local) {
-                $local->delete();
-            }
+        // And related groups in the other direction...
+        $inst = new Related_group();
+        $inst->related_group_id = $this->id;
+        $inst->delete();
+
+        // Aliases and the local_group entry need to be cleared explicitly
+        // or we'll miss clearing some cache keys; that can make it hard
+        // to create a new group with one of those names or aliases.
+        $this->setAliases(array());
+        $local = Local_group::getKV('group_id', $this->id);
+        if ($local instanceof Local_group) {
+            $local->delete();
+        }
 
-            // blow the cached ids
-            self::blow('user_group:notice_ids:%d', $this->id);
+        // blow the cached ids
+        self::blow('user_group:notice_ids:%d', $this->id);
 
-        } else {
-            common_log(LOG_WARNING, "Ambiguous user_group->delete(); skipping related tables.");
-        }
-        parent::delete();
+        return parent::delete();
     }
 
     function isPrivate()
index cd9ff812b7183b6dee89c89b817bf3bebb849288..6d8b6a424810d0472590f1a441b8eeb1847e08a9 100644 (file)
@@ -41,7 +41,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 class GroupNoProfileException extends NoProfileException
 {
-    public $group = null;
+    protected $group = null;
 
     /**
      * constructor
@@ -53,8 +53,8 @@ class GroupNoProfileException extends NoProfileException
     {
         $this->group = $group;
 
-        // TRANS: Exception text shown when no profile can be found for a user.
-        // TRANS: %1$s is a user nickname, $2$d is a user ID (number).
+        // TRANS: Exception text shown when no profile can be found for a group.
+        // TRANS: %1$s is a group nickname, $2$d is a group profile_id (number).
         $message = sprintf(_('User %1$s (%2$d) has no profile record.'),
                            $group->nickname, $group->id);
 
index 2792d32fd50494900a01e4cbf09a55617d1fab5c..d0cb08c63bb1f67d217bbc9c312d487df7fc416c 100644 (file)
@@ -126,9 +126,10 @@ class Nickname
             throw new NicknameBlacklistedException();
         } elseif (self::isSystemPath($str)) {
             throw new NicknamePathCollisionException();
-        } elseif ($checkuse && $user = self::isTaken($str)) {
-            if ($user instanceof User) {
-                throw new NicknameTakenException($user);
+        } elseif ($checkuse) {
+            $profile = self::isTaken($str);
+            if ($profile instanceof Profile) {
+                throw new NicknameTakenException($profile);
             }
         }
 
@@ -191,12 +192,26 @@ class Nickname
      * Is the nickname already in use locally? Checks the User table.
      *
      * @param   string $str
-     * @return  User|null   Returns null if no such user, otherwise a User object
+     * @return  Profile|null   Returns Profile if nickname found, otherwise null
      */
     public static function isTaken($str)
     {
-        $user = User::getKV('nickname', $str);
-        return $user;   // null if no such User entry
+        $found = User::getKV('nickname', $str);
+        if ($found instanceof User) {
+            return $found->getProfile();
+        }
+
+        $found = Local_group::getKV('nickname', $str);
+        if ($found instanceof Local_group) {
+            return $found->getProfile();
+        }
+
+        $found = Group_alias::getKV('alias', $str);
+        if ($found instanceof Group_alias) {
+            return $found->getProfile();
+        }
+
+        return null;
     }
 }
 
@@ -281,11 +296,11 @@ class NicknamePathCollisionException extends NicknameException
 
 class NicknameTakenException extends NicknameException
 {
-    public $user = null;    // the User which occupies the nickname
+    public $profile = null;    // the Profile which occupies the nickname
 
-    public function __construct(User $user, $msg=null, $code=400)
+    public function __construct(Profile $profile, $msg=null, $code=400)
     {
-        $this->byuser = $user;
+        $this->profile = $profile;
 
         if ($msg === null) {
             $msg = $this->defaultMessage();
index eebdc3bafee7baff1c6437c807ae233885bd8c00..49b0a7e1176a7fdee24cf5d72ae6e7af883ba2ff 100644 (file)
@@ -39,19 +39,18 @@ if (!defined('GNUSOCIAL')) { exit(1); }
  * @link     http://status.net/
  */
 
-class NoProfileException extends NoProfileException
+class NoProfileException extends ServerException
 {
     public $profile_id = null;
 
     public function __construct($profile_id, $msg=null)
     {
-        $this->id = (int)$profile_id;
+        $this->id = $profile_id;
 
         if ($msg === null) {
             // TRANS: Exception text shown when no profile can be found for a user.
             // TRANS: %1$s is a user nickname, $2$d is a user ID (number).
-            $msg = sprintf(_('User %1$s (%2$d) has no profile record.'),
-                           $group->nickname, $group->id);
+            $msg = sprintf(_('There is no profile with id==%u'), $this->id);
         }
 
         parent::__construct($msg, 404);
index c2d74f48404b152ca4fea338d2693e32908a0644..dcd07d7208800bbf1fe2e907bc3ce0e5e85e4a8a 100644 (file)
@@ -17,9 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Queue handler for letting plugins handle stuff.
@@ -46,7 +44,7 @@ class PluginQueueHandler extends QueueHandler
     {
         try {
             Event::handle('HandleQueuedNotice', array(&$notice));
-        } catch (UserNoProfileException $unp) {
+        } catch (NoProfileException $unp) {
             // We can't do anything about this, so just skip
             return true;
         }
index 653326e1f823eced353dc2d5e19577163bb3214d..3c95d243c40c5cdc658cf3015e4fe98c5f45d5b7 100644 (file)
@@ -679,7 +679,7 @@ class TwitterauthorizationAction extends Action
         try {
             return Nickname::normalize($this->tw_fields['fullname'], true);
         } catch (NicknameException $e) {
-            return null
+            return null;
         }
     }
 }