git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit a54eb094 authored by Brion Vibber's avatar Brion Vibber

Tweaking request_queue -> group_join_queue, easier to deal with the indexes...

Tweaking request_queue -> group_join_queue, easier to deal with the indexes and keys and caching this way.
parent 541dfa04
...@@ -4,20 +4,19 @@ ...@@ -4,20 +4,19 @@
*/ */
require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Request_queue extends Managed_DataObject class Group_join_queue extends Managed_DataObject
{ {
###START_AUTOCODE ###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */ /* the code below is auto generated do not remove the above tag */
public $__table = 'request_queue'; // table name public $__table = 'group_join_queue'; // table name
public $subscriber; public $profile_id;
public $subscribed;
public $group_id; public $group_id;
public $created; public $created;
/* Static get */ /* Static get */
function staticGet($k,$v=null) function staticGet($k,$v=null)
{ return Memcached_DataObject::staticGet('Confirm_address',$k,$v); } { return Memcached_DataObject::staticGet('Group_join_queue',$k,$v); }
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
...@@ -25,26 +24,31 @@ class Request_queue extends Managed_DataObject ...@@ -25,26 +24,31 @@ class Request_queue extends Managed_DataObject
public static function schemaDef() public static function schemaDef()
{ {
return array( return array(
'description' => 'Holder for subscription & group join requests awaiting moderation.', 'description' => 'Holder for group join requests awaiting moderation.',
'fields' => array( 'fields' => array(
'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'), 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
'subscribed' => array('type' => 'int', 'description' => 'remote or local profile to subscribe to, if any'),
'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'), 'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
), ),
'unique key' => array( 'primary key' => array('profile_id', 'group_id'),
'request_queue_subscriber_subscribed_group_id' => array('subscriber', 'subscribed', 'group_id'),
),
'indexes' => array( 'indexes' => array(
'request_queue_subscriber_created_idx' => array('subscriber', 'created'), 'group_join_queue_profile_id_created_idx' => array('profile_id', 'created'),
'request_queue_subscribed_created_idx' => array('subscriber', 'created'), 'group_join_queue_group_id_created_idx' => array('group_id', 'created'),
'request_queue_group_id_created_idx' => array('group_id', 'created'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'request_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')), 'group_join_queue_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'request_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')), 'group_join_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
'request_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
) )
); );
} }
public static function saveNew(Profile $profile, User_group $group)
{
$rq = new Group_join_queue();
$rq->profile_id = $profile->id;
$rq->group_id = $group->id;
$rq->created = common_sql_now();
$rq->insert();
return $rq;
}
} }
...@@ -93,6 +93,7 @@ abstract class Managed_DataObject extends Memcached_DataObject ...@@ -93,6 +93,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
function keyTypes() function keyTypes()
{ {
$table = call_user_func(array(get_class($this), 'schemaDef')); $table = call_user_func(array(get_class($this), 'schemaDef'));
$keys = array();
if (!empty($table['unique keys'])) { if (!empty($table['unique keys'])) {
foreach ($table['unique keys'] as $idx => $fields) { foreach ($table['unique keys'] as $idx => $fields) {
......
...@@ -344,14 +344,18 @@ class Profile extends Memcached_DataObject ...@@ -344,14 +344,18 @@ class Profile extends Memcached_DataObject
* May throw exceptions on failure. * May throw exceptions on failure.
* *
* @param User_group $group * @param User_group $group
* @return Group_member * @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
*/ */
function joinGroup(User_group $group) function joinGroup(User_group $group)
{ {
$ok = null; $ok = null;
if (Event::handle('StartJoinGroup', array($group, $this))) { if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
$ok = Group_member::join($group->id, $this->id); $ok = Group_join_queue::saveNew($this, $group);
Event::handle('EndJoinGroup', array($group, $this)); } else {
if (Event::handle('StartJoinGroup', array($group, $this))) {
$ok = Group_member::join($group->id, $this->id);
Event::handle('EndJoinGroup', array($group, $this));
}
} }
return $ok; return $ok;
} }
...@@ -363,9 +367,9 @@ class Profile extends Memcached_DataObject ...@@ -363,9 +367,9 @@ class Profile extends Memcached_DataObject
*/ */
function leaveGroup(User_group $group) function leaveGroup(User_group $group)
{ {
if (Event::handle('StartLeaveGroup', array($this->group, $this))) { if (Event::handle('StartLeaveGroup', array($group, $this))) {
Group_member::leave($this->group->id, $this->id); Group_member::leave($group->id, $this->id);
Event::handle('EndLeaveGroup', array($this->group, $this)); Event::handle('EndLeaveGroup', array($group, $this));
} }
} }
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
class User_group extends Memcached_DataObject class User_group extends Memcached_DataObject
{ {
const JOIN_POLICY_OPEN = 0;
const JOIN_POLICY_MODERATE = 1;
###START_AUTOCODE ###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */ /* the code below is auto generated do not remove the above tag */
......
...@@ -1027,4 +1027,4 @@ $schema['schema_version'] = array( ...@@ -1027,4 +1027,4 @@ $schema['schema_version'] = array(
'primary key' => array('table_name'), 'primary key' => array('table_name'),
); );
$schema['request_queue'] = Request_queue::schemaDef(); $schema['group_join_queue'] = Group_join_queue::schemaDef();
...@@ -189,11 +189,11 @@ class GroupEditForm extends Form ...@@ -189,11 +189,11 @@ class GroupEditForm extends Form
$this->out->elementStart('li'); $this->out->elementStart('li');
$this->out->dropdown('join_policy', $this->out->dropdown('join_policy',
_('Membership policy'), _('Membership policy'),
array(0 => _('Open to all'), array(User_group::JOIN_POLICY_OPEN => _('Open to all'),
1 => _('Admin must approve all members')), User_group::JOIN_POLICY_MODERATE => _('Admin must approve all members')),
_('Whether admin approval is required to join this group.'), _('Whether admin approval is required to join this group.'),
false, false,
(empty($this->group->join_policy)) ? 0 : $this->group->join_policy); (empty($this->group->join_policy)) ? User_group::JOIN_POLICY_OPEN : $this->group->join_policy);
$this->out->elementEnd('li'); $this->out->elementEnd('li');
Event::handle('EndGroupEditFormData', array($this)); Event::handle('EndGroupEditFormData', array($this));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment