-
Notifications
You must be signed in to change notification settings - Fork 978
/
Copy pathaddAllUsersIntoUserGroup.php
51 lines (42 loc) · 1.27 KB
/
addAllUsersIntoUserGroup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
//streamer config
require_once '../videos/configuration.php';
if (!isCommandLineInterface()) {
return die('Command Line only');
}
$rows = UserGroups::getAllUsersGroupsArray();
if(empty($rows)){
die('You do not have any user group');
}
foreach ($rows as $key => $value) {
echo "[$key] {$value}".PHP_EOL;
}
$_REQUEST['rowCount'] = 999999;
echo "Enter the user group number or press enter to skip:".PHP_EOL;
ob_flush();
$userGroup = trim(readline(""));
if(empty($rows[$userGroup])){
die('This user group does not exists');
}
if (!empty($userGroup)) {
$users = User::getAllUsers(true);
foreach ($users as $value) {
$user = new User($value['id']);
$addToUG = array($userGroup);
$currentUG =UserGroups::getUserGroups($value['id']);
if(!empty($currentUG)){
foreach ($currentUG as $ug) {
$addToUG[] = $ug["users_groups_id"];
}
}
$user->setUserGroups($addToUG);
if($user->save(true)){
echo "Success: saved user [{$value['id']}] {$value['user']} :". json_encode($addToUG).PHP_EOL;
}else{
echo "**ERROR: saving user [{$value['id']}] {$value['user']} :". json_encode($addToUG).PHP_EOL;
}
}
}
echo "Bye";
echo "\n";
die();