Consolidate group creation into static function in User_group
This commit is contained in:
parent
8f2db3820f
commit
199ccdb53f
|
@ -117,61 +117,13 @@ class ApiGroupCreateAction extends ApiAuthAction
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$group = new User_group();
|
$group = User_group::register(array('nickname' => $this->nickname,
|
||||||
|
'fullname' => $this->fullname,
|
||||||
$group->query('BEGIN');
|
'homepage' => $this->homepage,
|
||||||
|
'description' => $this->description,
|
||||||
$group->nickname = $this->nickname;
|
'location' => $this->location,
|
||||||
$group->fullname = $this->fullname;
|
'aliases' => $this->aliases,
|
||||||
$group->homepage = $this->homepage;
|
'userid' => $this->user->id));
|
||||||
$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');
|
|
||||||
|
|
||||||
switch($this->format) {
|
switch($this->format) {
|
||||||
case 'xml':
|
case 'xml':
|
||||||
$this->showSingleXmlGroup($group);
|
$this->showSingleXmlGroup($group);
|
||||||
|
|
|
@ -186,45 +186,13 @@ class NewgroupAction extends Action
|
||||||
|
|
||||||
assert(!is_null($cur));
|
assert(!is_null($cur));
|
||||||
|
|
||||||
$group = new User_group();
|
$group = User_group::register(array('nickname' => $nickname,
|
||||||
|
'fullname' => $fullname,
|
||||||
$group->query('BEGIN');
|
'homepage' => $homepage,
|
||||||
|
'description' => $description,
|
||||||
$group->nickname = $nickname;
|
'location' => $location,
|
||||||
$group->fullname = $fullname;
|
'aliases' => $aliases,
|
||||||
$group->homepage = $homepage;
|
'userid' => $cur->id));
|
||||||
$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');
|
|
||||||
|
|
||||||
common_redirect($group->homeUrl(), 303);
|
common_redirect($group->homeUrl(), 303);
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,4 +354,66 @@ class User_group extends Memcached_DataObject
|
||||||
|
|
||||||
return $xs->getString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user