]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/leavegroup.php
Make attachment fit better in notice: drop text and link
[quix0rs-gnu-social.git] / scripts / leavegroup.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2012 StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 define('INSTALLDIR', dirname(__DIR__));
21 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
22
23 $shortoptions = 'i:n:g:G:';
24 $longoptions = array('id=', 'nickname=', 'group=', 'group-id=');
25
26 $helptext = <<<END_OF_HELP
27 leavegroup.php [options]
28
29 Removes a local user from a local group.
30
31   -i --id       ID of user to remove
32   -n --nickname nickname of the user to remove
33   -g --group    nickname or alias of group
34   -G --group-id ID of group
35
36 END_OF_HELP;
37
38 require_once INSTALLDIR.'/scripts/commandline.inc';
39
40 try {
41     $user = getUser();
42     $lgroup = null;
43     if (have_option('G', 'group-id')) {
44         $gid = get_option_value('G', 'group-id');
45         $lgroup = Local_group::getKV('group_id', $gid);
46     } else if (have_option('g', 'group')) {
47         $gnick = get_option_value('g', 'group');
48         $lgroup = Local_group::getKV('nickname', $gnick);
49     }
50     if (!$lgroup instanceof Local_group) {
51         throw new Exception("No such local group: $gnick");
52     }
53     $group = User_group::getKV('id', $lgroup->group_id);
54     $user->leaveGroup($group);
55     print "OK\n";
56 } catch (Exception $e) {
57     print $e->getMessage()."\n";
58     exit(1);
59 }