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', dirname(__DIR__));
22 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
24 $shortoptions = 'g:n:';
25 $longoptions = array('nickname=', 'group=');
27 $helptext = <<<END_OF_MAKEGROUPADMIN_HELP
28 makegroupadmin.php [options]
29 makes a user the admin of a group
31 -g --group group to add an admin to
32 -n --nickname nickname of the new admin
34 END_OF_MAKEGROUPADMIN_HELP;
36 require_once INSTALLDIR.'/scripts/commandline.inc';
38 $nickname = get_option_value('n', 'nickname');
39 $groupname = get_option_value('g', 'group');
41 if (empty($nickname) || empty($groupname)) {
42 print "Must provide a nickname and group.\n";
48 $user = User::getKV('nickname', $nickname);
51 throw new Exception("No user named '$nickname'.");
54 $group = User_group::getKV('nickname', $groupname);
57 throw new Exception("No group named '$groupname'.");
60 $member = Group_member::pkeyGet(array('group_id' => $group->id,
61 'profile_id' => $user->id));
64 $member = new Group_member();
66 $member->group_id = $group->id;
67 $member->profile_id = $user->id;
68 $member->created = common_sql_now();
70 if (!$member->insert()) {
71 throw new Exception("Can't add '$nickname' to '$groupname'.");
75 if ($member->is_admin) {
76 throw new Exception("'$nickname' is already an admin of '$groupname'.");
79 $orig = clone($member);
81 $member->is_admin = 1;
83 if (!$member->update($orig)) {
84 throw new Exception("Can't make '$nickname' admin of '$groupname'.");
87 } catch (Exception $e) {
88 print $e->getMessage() . "\n";