1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

Adding add usergroup to all users and videos

This commit is contained in:
DanieL 2022-07-27 12:38:32 -03:00
parent aad532e381
commit 7a97a9d196
5 changed files with 102 additions and 41 deletions

View file

@ -0,0 +1,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();