From cd688acceb131312e10a219700ba21d4a3566695 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 21 Aug 2009 06:13:41 -0400 Subject: allow configurable length for user group description --- actions/newgroup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actions/newgroup.php') diff --git a/actions/newgroup.php b/actions/newgroup.php index 0289e77c2..71647d834 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -146,8 +146,8 @@ class NewgroupAction extends Action } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { $this->showForm(_('Full name is too long (max 255 chars).')); return; - } else if (!is_null($description) && mb_strlen($description) > 140) { - $this->showForm(_('description is too long (max 140 chars).')); + } else if (User_group::descriptionTooLong($description)) { + $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription())); return; } else if (!is_null($location) && mb_strlen($location) > 255) { $this->showForm(_('Location is too long (max 255 chars).')); -- cgit v1.2.3-54-g00ecf From 4f5badda94071d9debc8dacfbc9072be3c2ee73d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Oct 2009 17:38:27 -0400 Subject: remove inboxes option --- README | 41 ++----------------- actions/apigroupcreate.php | 9 ----- actions/editgroup.php | 5 --- actions/groupbyid.php | 5 --- actions/groupdesignsettings.php | 5 --- actions/grouplogo.php | 5 --- actions/grouprss.php | 5 --- actions/joingroup.php | 5 --- actions/leavegroup.php | 5 --- actions/newgroup.php | 5 --- actions/showgroup.php | 5 --- classes/Notice.php | 89 ++++++++++++++++++----------------------- classes/User.php | 58 ++++----------------------- lib/default.php | 2 +- 14 files changed, 51 insertions(+), 193 deletions(-) (limited to 'actions/newgroup.php') diff --git a/README b/README index 486656a3b..037027d43 100644 --- a/README +++ b/README @@ -839,40 +839,8 @@ to update it. Notice inboxes -------------- -Before version 0.6.2, the page showing all notices from people the -user is subscribed to ("so-and-so with friends") was calculated at run -time. Starting with 0.6.2, we have a new data structure for holding a -user's "notice inbox". (Note: distinct from the "message inbox", which -is the "inbox" tab in the UI. The notice inbox appears under the -"Personal" tab.) - -Notices are added to the inbox when they're created. This speeds up -the query considerably, and also allows us the opportunity, in the -future, to add different kind of notices to an inbox -- like @-replies -or subscriptions to search terms or hashtags. - -Notice inboxes are enabled by default for new installations. If you -are upgrading an existing site, this means that your users will see -empty "Personal" pages. The following steps will help you fix the -problem. - -0. $config['inboxes']['enabled'] can be set to one of three values. If - you set it to 'false', the site will work as before. Support for this - will probably be dropped in future versions. -1. Setting the flag to 'transitional' means that you're in transition. - In this mode, the code will run the "new query" or the "old query" - based on whether the user's inbox has been updated. -2. After setting the flag to "transitional", you can run the - fixup_inboxes.php script to create the inboxes. You may want to set - the memory limit high. You can re-run it without ill effect. -3. When fixup_inboxes is finished, you can set the enabled flag to - 'true'. - -NOTE: As of version 0.8.1 notice inboxes are automatically trimmed back - to ~1000 notices every once in a while. - -NOTE: we will drop support for non-inboxed sites in the 0.9.x version -of StatusNet. It's time to switch now! +Notice inboxes are now required. If you don't have inboxes enabled, +StatusNet will no longer run. UTF-8 Database -------------- @@ -1308,9 +1276,8 @@ inboxes For notice inboxes. -enabled: A three-valued flag for whether to use notice inboxes (see - upgrading info above for notes about this change). Can be - 'false', 'true', or '"transitional"'. +enabled: No longer used. If you set this to something other than true, + StatusNet will no longer run. throttle -------- diff --git a/actions/apigroupcreate.php b/actions/apigroupcreate.php index cdb2afb5b..f66e83073 100644 --- a/actions/apigroupcreate.php +++ b/actions/apigroupcreate.php @@ -99,15 +99,6 @@ class ApiGroupCreateAction extends ApiAuthAction { parent::handle($args); - if (!common_config('inboxes', 'enabled')) { - $this->serverError( - _('Inboxes must be enabled for groups to work'), - 400, - $this->format - ); - return false; - } - if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError( _('This method requires a POST.'), diff --git a/actions/editgroup.php b/actions/editgroup.php index 5dd039f8a..cf1608035 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -64,11 +64,6 @@ class EditgroupAction extends GroupDesignAction { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - if (!common_logged_in()) { $this->clientError(_('You must be logged in to create a group.')); return false; diff --git a/actions/groupbyid.php b/actions/groupbyid.php index 52cfaddfc..f65bf511a 100644 --- a/actions/groupbyid.php +++ b/actions/groupbyid.php @@ -68,11 +68,6 @@ class GroupbyidAction extends Action { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - $id = $this->arg('id'); if (!$id) { diff --git a/actions/groupdesignsettings.php b/actions/groupdesignsettings.php index cd86e3b05..b87b7d156 100644 --- a/actions/groupdesignsettings.php +++ b/actions/groupdesignsettings.php @@ -64,11 +64,6 @@ class GroupDesignSettingsAction extends DesignSettingsAction { parent::prepare($args); - if (!common_config('inboxes', 'enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - if (!common_logged_in()) { $this->clientError(_('You must be logged in to edit a group.')); return false; diff --git a/actions/grouplogo.php b/actions/grouplogo.php index 63ba769c7..a9dc7eb1d 100644 --- a/actions/grouplogo.php +++ b/actions/grouplogo.php @@ -66,11 +66,6 @@ class GrouplogoAction extends GroupDesignAction { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - if (!common_logged_in()) { $this->clientError(_('You must be logged in to create a group.')); return false; diff --git a/actions/grouprss.php b/actions/grouprss.php index 6a6b55e78..50e48a67e 100644 --- a/actions/grouprss.php +++ b/actions/grouprss.php @@ -76,11 +76,6 @@ class groupRssAction extends Rss10Action { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); diff --git a/actions/joingroup.php b/actions/joingroup.php index 0209dd43f..bf69b2ad1 100644 --- a/actions/joingroup.php +++ b/actions/joingroup.php @@ -56,11 +56,6 @@ class JoingroupAction extends Action { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - if (!common_logged_in()) { $this->clientError(_('You must be logged in to join a group.')); return false; diff --git a/actions/leavegroup.php b/actions/leavegroup.php index 60b22e147..08fce1509 100644 --- a/actions/leavegroup.php +++ b/actions/leavegroup.php @@ -56,11 +56,6 @@ class LeavegroupAction extends Action { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work.')); - return false; - } - if (!common_logged_in()) { $this->clientError(_('You must be logged in to leave a group.')); return false; diff --git a/actions/newgroup.php b/actions/newgroup.php index a2cf72528..80da9861a 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -61,11 +61,6 @@ class NewgroupAction extends Action { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - if (!common_logged_in()) { $this->clientError(_('You must be logged in to create a group.')); return false; diff --git a/actions/showgroup.php b/actions/showgroup.php index a67765ce5..bfe45ddad 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -101,11 +101,6 @@ class ShowgroupAction extends GroupDesignAction { parent::prepare($args); - if (!common_config('inboxes','enabled')) { - $this->serverError(_('Inboxes must be enabled for groups to work')); - return false; - } - $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $nickname_arg = $this->arg('nickname'); diff --git a/classes/Notice.php b/classes/Notice.php index ba2227c0a..cd3906ca1 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -111,10 +111,9 @@ class Notice extends Memcached_DataObject 'Fave', 'Notice_tag', 'Group_inbox', - 'Queue_item'); - if (common_config('inboxes', 'enabled')) { - $related[] = 'Notice_inbox'; - } + 'Queue_item', + 'Notice_inbox'); + foreach ($related as $cls) { $inst = new $cls(); $inst->notice_id = $this->id; @@ -883,66 +882,61 @@ class Notice extends Memcached_DataObject function addToInboxes() { - $enabled = common_config('inboxes', 'enabled'); + // XXX: loads constants - if ($enabled === true || $enabled === 'transitional') { + $inbox = new Notice_inbox(); - // XXX: loads constants + $users = $this->getSubscribedUsers(); - $inbox = new Notice_inbox(); + // FIXME: kind of ignoring 'transitional'... + // we'll probably stop supporting inboxless mode + // in 0.9.x - $users = $this->getSubscribedUsers(); + $ni = array(); - // FIXME: kind of ignoring 'transitional'... - // we'll probably stop supporting inboxless mode - // in 0.9.x + foreach ($users as $id) { + $ni[$id] = NOTICE_INBOX_SOURCE_SUB; + } - $ni = array(); + $groups = $this->saveGroups(); + foreach ($groups as $group) { + $users = $group->getUserMembers(); foreach ($users as $id) { - $ni[$id] = NOTICE_INBOX_SOURCE_SUB; - } - - $groups = $this->saveGroups(); - - foreach ($groups as $group) { - $users = $group->getUserMembers(); - foreach ($users as $id) { - if (!array_key_exists($id, $ni)) { - $ni[$id] = NOTICE_INBOX_SOURCE_GROUP; - } + if (!array_key_exists($id, $ni)) { + $ni[$id] = NOTICE_INBOX_SOURCE_GROUP; } } + } - $cnt = 0; - - $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES '; - $qry = $qryhdr; + $cnt = 0; - foreach ($ni as $id => $source) { - if ($cnt > 0) { - $qry .= ', '; - } - $qry .= '('.$id.', '.$this->id.', '.$source.", '".$this->created. "') "; - $cnt++; - if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) { - // FIXME: Causes lag in replicated servers - // Notice_inbox::gc($id); - } - if ($cnt >= MAX_BOXCARS) { - $inbox = new Notice_inbox(); - $inbox->query($qry); - $qry = $qryhdr; - $cnt = 0; - } - } + $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES '; + $qry = $qryhdr; + foreach ($ni as $id => $source) { if ($cnt > 0) { + $qry .= ', '; + } + $qry .= '('.$id.', '.$this->id.', '.$source.", '".$this->created. "') "; + $cnt++; + if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) { + // FIXME: Causes lag in replicated servers + // Notice_inbox::gc($id); + } + if ($cnt >= MAX_BOXCARS) { $inbox = new Notice_inbox(); $inbox->query($qry); + $qry = $qryhdr; + $cnt = 0; } } + if ($cnt > 0) { + $inbox = new Notice_inbox(); + $inbox->query($qry); + } + return; } @@ -977,11 +971,6 @@ class Notice extends Memcached_DataObject { $groups = array(); - $enabled = common_config('inboxes', 'enabled'); - if ($enabled !== true && $enabled !== 'transitional') { - return $groups; - } - /* extract all !group */ $count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/', strtolower($this->content), diff --git a/classes/User.php b/classes/User.php index 48df0cdd7..0a70c9801 100644 --- a/classes/User.php +++ b/classes/User.php @@ -227,11 +227,9 @@ class User extends Memcached_DataObject } } - $inboxes = common_config('inboxes', 'enabled'); + // This flag is ignored but still set to 1 - if ($inboxes === true || $inboxes == 'transitional') { - $user->inboxed = 1; - } + $user->inboxed = 1; $user->created = common_sql_now(); $user->uri = common_user_uri($user); @@ -433,55 +431,16 @@ class User extends Memcached_DataObject function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $enabled = common_config('inboxes', 'enabled'); - - // Complicated code, depending on whether we support inboxes yet - // XXX: make this go away when inboxes become mandatory - - if ($enabled === false || - ($enabled == 'transitional' && $this->inboxed == 0)) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' . - 'WHERE subscription.subscriber = %d ' . - 'AND notice.is_local != ' . Notice::GATEWAY; - return Notice::getStream(sprintf($qry, $this->id), - 'user:notices_with_friends:' . $this->id, - $offset, $limit, $since_id, $before_id, - $order, $since); - } else if ($enabled === true || - ($enabled == 'transitional' && $this->inboxed == 1)) { - - $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); + $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); - return Notice::getStreamByIds($ids); - } + return Notice::getStreamByIds($ids); } function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $enabled = common_config('inboxes', 'enabled'); - - // Complicated code, depending on whether we support inboxes yet - // XXX: make this go away when inboxes become mandatory + $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); - if ($enabled === false || - ($enabled == 'transitional' && $this->inboxed == 0)) { - $qry = - 'SELECT notice.* ' . - 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' . - 'WHERE subscription.subscriber = %d '; - return Notice::getStream(sprintf($qry, $this->id), - 'user:notices_with_friends:' . $this->id, - $offset, $limit, $since_id, $before_id, - $order, $since); - } else if ($enabled === true || - ($enabled == 'transitional' && $this->inboxed == 1)) { - - $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); - - return Notice::getStreamByIds($ids); - } + return Notice::getStreamByIds($ids); } function blowFavesCache() @@ -752,12 +711,9 @@ class User extends Memcached_DataObject 'Remember_me', 'Foreign_link', 'Invitation', + 'Notice_inbox', ); - if (common_config('inboxes', 'enabled')) { - $related[] = 'Notice_inbox'; - } - foreach ($related as $cls) { $inst = new $cls(); $inst->user_id = $this->id; diff --git a/lib/default.php b/lib/default.php index 329b041e9..9f3d4b1f9 100644 --- a/lib/default.php +++ b/lib/default.php @@ -157,7 +157,7 @@ $default = 'ping' => array('notify' => array()), 'inboxes' => - array('enabled' => true), # on by default for new sites + array('enabled' => true), # ignored after 0.9.x 'newuser' => array('default' => null, 'welcome' => null), -- cgit v1.2.3-54-g00ecf From 199ccdb53fbd732eeced3edf734e39687729da9b Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Wed, 18 Nov 2009 15:53:33 -0500 Subject: Consolidate group creation into static function in User_group --- actions/apigroupcreate.php | 62 ++++++---------------------------------------- actions/newgroup.php | 46 ++++++---------------------------- classes/User_group.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 94 deletions(-) (limited to 'actions/newgroup.php') diff --git a/actions/apigroupcreate.php b/actions/apigroupcreate.php index 895dfb7ab..8827d1c5c 100644 --- a/actions/apigroupcreate.php +++ b/actions/apigroupcreate.php @@ -117,61 +117,13 @@ class ApiGroupCreateAction extends ApiAuthAction return; } - $group = new User_group(); - - $group->query('BEGIN'); - - $group->nickname = $this->nickname; - $group->fullname = $this->fullname; - $group->homepage = $this->homepage; - $group->description = $this->description; - $group->location = $this->location; - $group->created = common_sql_now(); - - $result = $group->insert(); - - if (!$result) { - common_log_db_error($group, 'INSERT', __FILE__); - $this->serverError( - _('Could not create group.'), - 500, - $this->format - ); - return; - } - - $result = $group->setAliases($this->aliases); - - if (!$result) { - $this->serverError( - _('Could not create aliases.'), - 500, - $this->format - ); - return; - } - - $member = new Group_member(); - - $member->group_id = $group->id; - $member->profile_id = $this->user->id; - $member->is_admin = 1; - $member->created = $group->created; - - $result = $member->insert(); - - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); - $this->serverError( - _('Could not set group membership.'), - 500, - $this->format - ); - return; - } - - $group->query('COMMIT'); - + $group = User_group::register(array('nickname' => $this->nickname, + 'fullname' => $this->fullname, + 'homepage' => $this->homepage, + 'description' => $this->description, + 'location' => $this->location, + 'aliases' => $this->aliases, + 'userid' => $this->user->id)); switch($this->format) { case 'xml': $this->showSingleXmlGroup($group); diff --git a/actions/newgroup.php b/actions/newgroup.php index 80da9861a..25da7f8fc 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -186,45 +186,13 @@ class NewgroupAction extends Action assert(!is_null($cur)); - $group = new User_group(); - - $group->query('BEGIN'); - - $group->nickname = $nickname; - $group->fullname = $fullname; - $group->homepage = $homepage; - $group->description = $description; - $group->location = $location; - $group->created = common_sql_now(); - - $result = $group->insert(); - - if (!$result) { - common_log_db_error($group, 'INSERT', __FILE__); - $this->serverError(_('Could not create group.')); - } - - $result = $group->setAliases($aliases); - - if (!$result) { - $this->serverError(_('Could not create aliases.')); - } - - $member = new Group_member(); - - $member->group_id = $group->id; - $member->profile_id = $cur->id; - $member->is_admin = 1; - $member->created = $group->created; - - $result = $member->insert(); - - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); - $this->serverError(_('Could not set group membership.')); - } - - $group->query('COMMIT'); + $group = User_group::register(array('nickname' => $nickname, + 'fullname' => $fullname, + 'homepage' => $homepage, + 'description' => $description, + 'location' => $location, + 'aliases' => $aliases, + 'userid' => $cur->id)); common_redirect($group->homeUrl(), 303); } diff --git a/classes/User_group.php b/classes/User_group.php index b92638f7a..c86eadf8f 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -354,4 +354,66 @@ class User_group extends Memcached_DataObject return $xs->getString(); } + + static function register($fields) { + + // MAGICALLY put fields into current scope + + extract($fields); + + $group = new User_group(); + + $group->query('BEGIN'); + + $group->nickname = $nickname; + $group->fullname = $fullname; + $group->homepage = $homepage; + $group->description = $description; + $group->location = $location; + $group->created = common_sql_now(); + + $result = $group->insert(); + + if (!$result) { + common_log_db_error($group, 'INSERT', __FILE__); + $this->serverError( + _('Could not create group.'), + 500, + $this->format + ); + return; + } + $result = $group->setAliases($aliases); + + if (!$result) { + $this->serverError( + _('Could not create aliases.'), + 500, + $this->format + ); + return; + } + + $member = new Group_member(); + + $member->group_id = $group->id; + $member->profile_id = $userid; + $member->is_admin = 1; + $member->created = $group->created; + + $result = $member->insert(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + $this->serverError( + _('Could not set group membership.'), + 500, + $this->format + ); + return; + } + + $group->query('COMMIT'); + return $group; + } } -- cgit v1.2.3-54-g00ecf