]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
authorEvan Prodromou <evan@status.net>
Thu, 25 Feb 2010 17:10:57 +0000 (12:10 -0500)
committerEvan Prodromou <evan@status.net>
Thu, 25 Feb 2010 17:10:57 +0000 (12:10 -0500)
19 files changed:
actions/apigroupcreate.php
actions/apigrouplistall.php
actions/blockedfromgroup.php
actions/editgroup.php
actions/foafgroup.php
actions/groupdesignsettings.php
actions/grouplogo.php
actions/groupmembers.php
actions/grouprss.php
actions/groups.php
actions/joingroup.php
actions/leavegroup.php
actions/newgroup.php
actions/showgroup.php
classes/Local_group.php [new file with mode: 0644]
classes/User_group.php
classes/statusnet.ini
db/statusnet.sql
lib/api.php

index 028d76a7822a99c5bf2f3b6a46d9743280a4054a..145806356c77d2b74224635ed19cc854e92d9629 100644 (file)
@@ -123,7 +123,9 @@ class ApiGroupCreateAction extends ApiAuthAction
                                             'description' => $this->description,
                                             'location' => $this->location,
                                             'aliases'  => $this->aliases,
-                                            'userid'   => $this->user->id));
+                                            'userid'   => $this->user->id,
+                                            'local'    => true));
+
         switch($this->format) {
         case 'xml':
             $this->showSingleXmlGroup($group);
@@ -306,9 +308,9 @@ class ApiGroupCreateAction extends ApiAuthAction
 
     function groupNicknameExists($nickname)
     {
-        $group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
 
-        if (!empty($group)) {
+        if (!empty($local)) {
             return true;
         }
 
index d2ef2978aa5427cf1e0ec5dfb6b65b8332e48e2e..e1b54a83229ae1bcf985444d8ceebde0b572ace1 100644 (file)
@@ -134,13 +134,13 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
 
     function getGroups()
     {
-        $groups = array();
-
-        // XXX: Use the $page, $count, $max_id, $since_id, and $since parameters
+        $qry = 'SELECT user_group.* '.
+          'from user_group join local_group on user_group.id = local_group.group_id '.
+          'order by created desc ';
 
         $group = new User_group();
-        $group->orderBy('created DESC');
-        $group->find();
+
+        $group->query($qry);
 
         while ($group->fetch()) {
             $groups[] = clone($group);
index 0b4caf5bf34e742928bba6aed4e3651a271e2a43..a0598db270e64767f3432fd3ff5e18cf1d4601fe 100644 (file)
@@ -74,7 +74,14 @@ class BlockedfromgroupAction extends GroupDesignAction
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
index ad0b6e185dcfe97c801a0787e382a4982bb21be6..d486db0c0aa3ba2bace92761e0443e6a30978046 100644 (file)
@@ -86,10 +86,14 @@ class EditgroupAction extends GroupDesignAction
         }
 
         $groupid = $this->trimmed('groupid');
+
         if ($groupid) {
             $this->group = User_group::staticGet('id', $groupid);
         } else {
-            $this->group = User_group::staticGet('nickname', $nickname);
+            $local = Local_group::staticGet('nickname', $nickname);
+            if ($local) {
+                $this->group = User_group::staticGet('id', $local->group_id);
+            }
         }
 
         if (!$this->group) {
@@ -245,6 +249,7 @@ class EditgroupAction extends GroupDesignAction
         $this->group->homepage    = $homepage;
         $this->group->description = $description;
         $this->group->location    = $location;
+        $this->group->mainpage    = common_local_url('showgroup', array('nickname' => $nickname));
 
         $result = $this->group->update($orig);
 
@@ -259,6 +264,12 @@ class EditgroupAction extends GroupDesignAction
             $this->serverError(_('Could not create aliases.'));
         }
 
+        if ($nickname != $orig->nickname) {
+            common_log(LOG_INFO, "Saving local group info.");
+            $local = Local_group::staticGet('group_id', $this->group->id);
+            $local->setNickname($nickname);
+        }
+
         $this->group->query('COMMIT');
 
         if ($this->group->nickname != $orig->nickname) {
@@ -272,7 +283,7 @@ class EditgroupAction extends GroupDesignAction
 
     function nicknameExists($nickname)
     {
-        $group = User_group::staticGet('nickname', $nickname);
+        $group = Local_group::staticGet('nickname', $nickname);
 
         if (!empty($group) &&
             $group->id != $this->group->id) {
index f5fd7fe885e993adb4e2fa1fe64b468a3d6bdb81..ebdf1cee2567555748fe04e9423203f4f1a7131b 100644 (file)
@@ -56,7 +56,14 @@ class FoafGroupAction extends Action
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $this->nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
@@ -113,7 +120,7 @@ class FoafGroupAction extends Action
         if ($this->group->homepage_logo) {
             $this->element('depiction', array('rdf:resource' => $this->group->homepage_logo));
         }
-        
+
         $members = $this->group->getMembers();
         $member_details = array();
         while ($members->fetch()) {
@@ -123,7 +130,7 @@ class FoafGroupAction extends Action
                                         );
             $this->element('member', array('rdf:resource' => $member_uri));
         }
-        
+
         $admins = $this->group->getAdmins();
         while ($admins->fetch()) {
             $admin_uri = common_local_url('userbyid', array('id'=>$admins->id));
@@ -132,7 +139,7 @@ class FoafGroupAction extends Action
         }
 
         $this->elementEnd('Group');
-        
+
         ksort($member_details);
         foreach ($member_details as $uri => $details) {
             if ($details['is_admin'])
@@ -158,7 +165,7 @@ class FoafGroupAction extends Action
                                         ));
             }
         }
-        
+
         $this->elementEnd('rdf:RDF');
         $this->endXML();
     }
index e290ba5141e270ac8d4295bba1eb88872f0d53fd..526226a285715914486ffc3eb0905f60c4ebf13c 100644 (file)
@@ -90,7 +90,10 @@ class GroupDesignSettingsAction extends DesignSettingsAction
         if ($groupid) {
             $this->group = User_group::staticGet('id', $groupid);
         } else {
-            $this->group = User_group::staticGet('nickname', $nickname);
+            $local = Local_group::staticGet('nickname', $nickname);
+            if ($local) {
+                $this->group = User_group::staticGet('id', $local->group_id);
+            }
         }
 
         if (!$this->group) {
index 3c9b562962e34944ab7864b8f96157de90d114b7..f414a23cc31369665abd68eb0b69e8b899c95b07 100644 (file)
@@ -92,7 +92,10 @@ class GrouplogoAction extends GroupDesignAction
         if ($groupid) {
             $this->group = User_group::staticGet('id', $groupid);
         } else {
-            $this->group = User_group::staticGet('nickname', $nickname);
+            $local = Local_group::staticGet('nickname', $nickname);
+            if ($local) {
+                $this->group = User_group::staticGet('id', $local->group_id);
+            }
         }
 
         if (!$this->group) {
index f16e972a4194a6eee1a0fd60e2c4fad70881b36d..a16debd7b068ecd4e69deec35d61e42475f83752 100644 (file)
@@ -77,7 +77,14 @@ class GroupmembersAction extends GroupDesignAction
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
index 866fc66eb117685ef60c8ee6b21563d594097e63..490f6f945cac57b509f968b3f771aea5b3f3c5c5 100644 (file)
@@ -92,7 +92,14 @@ class groupRssAction extends Rss10Action
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
index 10a1d5964d374ac2d18118223b3f297ca5211ed5..8aacff8b0ecd1cd2efe86de5b35a6a7b90312f03 100644 (file)
@@ -109,17 +109,21 @@ class GroupsAction extends Action
         }
 
         $offset = ($this->page-1) * GROUPS_PER_PAGE;
-        $limit =  GROUPS_PER_PAGE + 1;
+        $limit  = GROUPS_PER_PAGE + 1;
+
+        $qry = 'SELECT user_group.* '.
+          'from user_group join local_group on user_group.id = local_group.group_id '.
+          'order by user_group.created desc '.
+          'limit ' . $limit . ' offset ' . $offset;
 
         $groups = new User_group();
-        $groups->orderBy('created DESC');
-        $groups->limit($offset, $limit);
 
         $cnt = 0;
-        if ($groups->find()) {
-            $gl = new GroupList($groups, null, $this);
-            $cnt = $gl->show();
-        }
+
+        $groups->query($qry);
+
+        $gl = new GroupList($groups, null, $this);
+        $cnt = $gl->show();
 
         $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
                           $this->page, 'groups');
index 235e5ab4c2c8ea792de834ce745079bd7c7dc45c..ba642f71293b13743b8f86df5511cb7d5e26c770 100644 (file)
@@ -77,7 +77,14 @@ class JoingroupAction extends Action
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
index 9b9d83b6caae243befbd9e43a43eb6b137be53f5..222d4c1b438a9b844e6efe3e1bb1398678937816 100644 (file)
@@ -77,7 +77,14 @@ class LeavegroupAction extends Action
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $this->clientError(_('No such group.'), 404);
index 25da7f8fc75ebcf679c88bb83bd4d8e9f94571fe..75bc293ec63e15e4df92af789e115e8a997b2cc2 100644 (file)
@@ -180,6 +180,8 @@ class NewgroupAction extends Action
             }
         }
 
+        $mainpage = common_local_url('showgroup', array('nickname' => $nickname));
+
         $cur = common_current_user();
 
         // Checked in prepare() above
@@ -192,16 +194,18 @@ class NewgroupAction extends Action
                                             'description' => $description,
                                             'location' => $location,
                                             'aliases'  => $aliases,
-                                            'userid'   => $cur->id));
+                                            'userid'   => $cur->id,
+                                            'mainpage' => $mainpage,
+                                            'local'    => true));
 
         common_redirect($group->homeUrl(), 303);
     }
 
     function nicknameExists($nickname)
     {
-        $group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
 
-        if (!empty($group)) {
+        if (!empty($local)) {
             return true;
         }
 
index eb12389029a096dd0373ae7ed523ddc517092d62..0139ba157de75ca00496a695813d655931027ff5 100644 (file)
@@ -122,7 +122,15 @@ class ShowgroupAction extends GroupDesignAction
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
+
+        if (!$local) {
+            common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
+        $this->group = User_group::staticGet('id', $local->group_id);
 
         if (!$this->group) {
             $alias = Group_alias::staticGet('alias', $nickname);
diff --git a/classes/Local_group.php b/classes/Local_group.php
new file mode 100644 (file)
index 0000000..42312ec
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Table Definition for local_group
+ */
+
+class Local_group extends Memcached_DataObject
+{
+    ###START_AUTOCODE
+    /* the code below is auto generated do not remove the above tag */
+
+    public $__table = 'local_group';                     // table name
+    public $group_id;                        // int(4)  primary_key not_null
+    public $nickname;                        // varchar(64)  unique_key
+    public $created;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
+    public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
+
+    /* Static get */
+    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Local_group',$k,$v); }
+
+    /* the code above is auto generated do not remove the tag below */
+    ###END_AUTOCODE
+
+    function sequenceKey()
+    {
+        return array(false, false, false);
+    }
+
+    function setNickname($nickname)
+    {
+        $this->decache();
+        $qry = 'UPDATE local_group set nickname = "'.$nickname.'" where group_id = ' . $this->group_id;
+
+        $result = $this->query($qry);
+
+        if ($result) {
+            $this->nickname = $nickname;
+            $this->fixupTimestamps();
+            $this->encache();
+        } else {
+            common_log_db_error($local, 'UPDATE', __FILE__);
+            throw new ServerException(_('Could not update local group.'));
+        }
+
+        return $result;
+    }
+}
index 1382aa407c7f74eb585ba7a98a6a88d755cfdce0..0592c56f8451476a1ddfe5929eb4a46eaf08185e 100644 (file)
@@ -10,21 +10,23 @@ class User_group extends Memcached_DataObject
 
     public $__table = 'user_group';                      // table name
     public $id;                              // int(4)  primary_key not_null
-    public $nickname;                        // varchar(64)  unique_key
+    public $nickname;                        // varchar(64)
     public $fullname;                        // varchar(255)
     public $homepage;                        // varchar(255)
-    public $description;                     // text()
+    public $description;                     // text
     public $location;                        // varchar(255)
     public $original_logo;                   // varchar(255)
     public $homepage_logo;                   // varchar(255)
     public $stream_logo;                     // varchar(255)
     public $mini_logo;                       // varchar(255)
     public $design_id;                       // int(4)
-    public $created;                         // datetime()   not_null
-    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
+    public $created;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
+    public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
+    public $uri;                             // varchar(255)  unique_key
+    public $mainpage;                        // varchar(255)
 
     /* Static get */
-    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_group',$k,$v); }
+    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('User_group',$k,$v); }
 
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
@@ -41,8 +43,13 @@ class User_group extends Memcached_DataObject
     {
         $url = null;
         if (Event::handle('StartUserGroupHomeUrl', array($this, &$url))) {
-            $url = common_local_url('showgroup',
-                                    array('nickname' => $this->nickname));
+            // normally stored in mainpage, but older ones may be null
+            if (!empty($this->mainpage)) {
+                $url = $this->mainpage;
+            } else {
+                $url = common_local_url('showgroup',
+                                        array('nickname' => $this->nickname));
+            }
         }
         Event::handle('EndUserGroupHomeUrl', array($this, &$url));
         return $url;
@@ -413,28 +420,31 @@ class User_group extends Memcached_DataObject
         $group->homepage    = $homepage;
         $group->description = $description;
         $group->location    = $location;
+        $group->uri         = $uri;
+        $group->mainpage    = $mainpage;
         $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;
+            throw new ServerException(_('Could not create group.'));
         }
+
+        if (!isset($uri) || empty($uri)) {
+            $orig = clone($group);
+            $group->uri = common_local_url('groupbyid', array('id' => $group->id));
+            $result = $group->update($orig);
+            if (!$result) {
+                common_log_db_error($group, 'UPDATE', __FILE__);
+                throw new ServerException(_('Could not set group uri.'));
+            }
+        }
+
         $result = $group->setAliases($aliases);
 
         if (!$result) {
-            $this->serverError(
-                _('Could not create aliases.'),
-                500,
-                $this->format
-            );
-            return;
+            throw new ServerException(_('Could not create aliases.'));
         }
 
         $member = new Group_member();
@@ -448,12 +458,22 @@ class User_group extends Memcached_DataObject
 
         if (!$result) {
             common_log_db_error($member, 'INSERT', __FILE__);
-            $this->serverError(
-                _('Could not set group membership.'),
-                500,
-                $this->format
-            );
-            return;
+            throw new ServerException(_('Could not set group membership.'));
+        }
+
+        if ($local) {
+            $local_group = new Local_group();
+
+            $local_group->group_id = $group->id;
+            $local_group->nickname = $nickname;
+            $local_group->created  = common_sql_now();
+
+            $result = $local_group->insert();
+
+            if (!$result) {
+                common_log_db_error($local_group, 'INSERT', __FILE__);
+                throw new ServerException(_('Could not save local group info.'));
+            }
         }
 
         $group->query('COMMIT');
index 81c1b68b236eedc1b5994c12d7cd96aec11ff0cc..719dbedf57cedbe7d3231d90b2ba51258e90b47a 100644 (file)
@@ -55,7 +55,6 @@ modified = 384
 
 [conversation__keys]
 id = N
-uri = U
 
 [deleted_notice]
 id = 129
@@ -103,7 +102,6 @@ modified = 384
 
 [file__keys]
 id = N
-url = U
 
 [file_oembed]
 file_id = 129
@@ -245,13 +243,6 @@ modified = 384
 group_id = K
 profile_id = K
 
-[invitation]
-code = 130
-user_id = 129
-address = 130
-address_type = 130
-created = 142
-
 [inbox]
 user_id = 129
 notice_ids = 66
@@ -259,9 +250,26 @@ notice_ids = 66
 [inbox__keys]
 user_id = K
 
+[invitation]
+code = 130
+user_id = 129
+address = 130
+address_type = 130
+created = 142
+
 [invitation__keys]
 code = K
 
+[local_group]
+group_id = 129
+nickname = 2
+created = 142
+modified = 384
+
+[local_group__keys]
+group_id = K
+nickname = U
+
 [location_namespace]
 id = 129
 description = 2
@@ -369,7 +377,7 @@ icon = 130
 source_url = 2
 organization = 2
 homepage = 2
-callback_url = 130
+callback_url = 2
 type = 17
 access_type = 17
 created = 142
@@ -377,7 +385,6 @@ modified = 384
 
 [oauth_application__keys]
 id = N
-name = U
 
 [oauth_application_user]
 profile_id = 129
@@ -440,13 +447,13 @@ tag = K
 
 [queue_item]
 id = 129
-frame = 66
+frame = 194
 transport = 130
 created = 142
 claimed = 14
 
 [queue_item__keys]
-id = K
+id = N
 
 [related_group]
 group_id = 129
@@ -593,10 +600,11 @@ mini_logo = 2
 design_id = 1
 created = 142
 modified = 384
+uri = 2
+mainpage = 2
 
 [user_group__keys]
 id = N
-nickname = U
 
 [user_openid]
 canonical = 130
@@ -627,4 +635,3 @@ modified = 384
 
 [user_location_prefs__keys]
 user_id = K
-
index 97117c80aab6b69898012f695d0902eb6ee1554c..4158f0167db2a9f9def64f29ac8fff1fef574382 100644 (file)
@@ -406,7 +406,7 @@ create table profile_block (
 create table user_group (
     id integer auto_increment primary key comment 'unique identifier',
 
-    nickname varchar(64) unique key comment 'nickname for addressing',
+    nickname varchar(64) comment 'nickname for addressing',
     fullname varchar(255) comment 'display name',
     homepage varchar(255) comment 'URL, cached so we dont regenerate',
     description text comment 'group description',
@@ -421,6 +421,9 @@ create table user_group (
     created datetime not null comment 'date this record was created',
     modified timestamp comment 'date this record was modified',
 
+    uri varchar(255) unique key comment 'universal identifier',
+    mainpage varchar(255) comment 'page for group info to link to',
+
     index user_group_nickname_idx (nickname)
 
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
@@ -641,3 +644,13 @@ create table conversation (
     modified timestamp comment 'date this record was modified'
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
+create table local_group (
+
+   group_id integer primary key comment 'group represented' references user_group (id),
+   nickname varchar(64) unique key comment 'group represented',
+
+   created datetime not null comment 'date this record was created',
+   modified timestamp comment 'date this record was modified'
+
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
index 0bcf4cc21afbdc870aee26b5e307b62ccc66db8a..d79dc327edef80a7b1eecb3886f3b2364e0ffbd5 100644 (file)
@@ -1218,7 +1218,12 @@ class ApiAction extends Action
                 return User_group::staticGet($this->arg('id'));
             } else if ($this->arg('id')) {
                 $nickname = common_canonical_nickname($this->arg('id'));
-                return User_group::staticGet('nickname', $nickname);
+                $local = Local_group::staticGet('nickname', $nickname);
+                if (empty($local)) {
+                    return null;
+                } else {
+                    return User_group::staticGet('id', $local->id);
+                }
             } else if ($this->arg('group_id')) {
                 // This is to ensure that a non-numeric user_id still
                 // overrides screen_name even if it doesn't get used
@@ -1227,14 +1232,24 @@ class ApiAction extends Action
                 }
             } else if ($this->arg('group_name')) {
                 $nickname = common_canonical_nickname($this->arg('group_name'));
-                return User_group::staticGet('nickname', $nickname);
+                $local = Local_group::staticGet('nickname', $nickname);
+                if (empty($local)) {
+                    return null;
+                } else {
+                    return User_group::staticGet('id', $local->id);
+                }
             }
 
         } else if (is_numeric($id)) {
             return User_group::staticGet($id);
         } else {
             $nickname = common_canonical_nickname($id);
-            return User_group::staticGet('nickname', $nickname);
+            $local = Local_group::staticGet('nickname', $nickname);
+            if (empty($local)) {
+                return null;
+            } else {
+                return User_group::staticGet('id', $local->id);
+            }
         }
     }