4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
23 $shortoptions = 'g:n:';
24 $longoptions = array('nickname=', 'group=');
26 $helptext = <<<END_OF_MAKEGROUPADMIN_HELP
27 makegroupadmin.php [options]
28 makes a user the admin of a group
30 -g --group group to add an admin to
31 -n --nickname nickname of the new admin
33 END_OF_MAKEGROUPADMIN_HELP;
35 require_once INSTALLDIR.'/scripts/commandline.inc';
37 $nickname = get_option_value('n', 'nickname');
38 $groupname = get_option_value('g', 'group');
40 if (empty($nickname) || empty($groupname)) {
41 print "Must provide a nickname and group.\n";
47 $user = User::getKV('nickname', $nickname);
50 throw new Exception("No user named '$nickname'.");
53 $group = User_group::getKV('nickname', $groupname);
56 throw new Exception("No group named '$groupname'.");
59 $member = Group_member::pkeyGet(array('group_id' => $group->id,
60 'profile_id' => $user->id));
63 $member = new Group_member();
65 $member->group_id = $group->id;
66 $member->profile_id = $user->id;
67 $member->created = common_sql_now();
69 if (!$member->insert()) {
70 throw new Exception("Can't add '$nickname' to '$groupname'.");
74 if ($member->is_admin) {
75 throw new Exception("'$nickname' is already an admin of '$groupname'.");
78 $orig = clone($member);
80 $member->is_admin = 1;
82 if (!$member->update($orig)) {
83 throw new Exception("Can't make '$nickname' admin of '$groupname'.");
86 } catch (Exception $e) {
87 print $e->getMessage() . "\n";