From 7a97a9d1968a5ccd7f2ace4beafab762f4075555 Mon Sep 17 00:00:00 2001 From: DanieL Date: Wed, 27 Jul 2022 12:38:32 -0300 Subject: [PATCH] Adding add usergroup to all users and videos --- install/addAllUsersIntoUserGroup.php | 51 +++++++++++++++++++++++++++ install/addAllVideosIntoUserGroup.php | 42 ++++++++++++++++++++++ objects/include_config.php | 33 ----------------- objects/user.php | 4 +-- objects/userGroups.php | 13 +++---- 5 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 install/addAllUsersIntoUserGroup.php create mode 100644 install/addAllVideosIntoUserGroup.php diff --git a/install/addAllUsersIntoUserGroup.php b/install/addAllUsersIntoUserGroup.php new file mode 100644 index 0000000000..868c3d7d5b --- /dev/null +++ b/install/addAllUsersIntoUserGroup.php @@ -0,0 +1,51 @@ + $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(); diff --git a/install/addAllVideosIntoUserGroup.php b/install/addAllVideosIntoUserGroup.php new file mode 100644 index 0000000000..81c8ff4a65 --- /dev/null +++ b/install/addAllVideosIntoUserGroup.php @@ -0,0 +1,42 @@ + $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)) { + + $videos = Video::getAllVideosLight(''); + + foreach ($videos as $value) { + if(UserGroups::updateVideoGroups($value['id'], $userGroup, true)){ + echo "Success: saved video [{$value['id']}] {$value['title']} :". json_encode($addToUG).PHP_EOL; + }else{ + echo "**ERROR: saving video [{$value['id']}] {$value['title']} :". json_encode($addToUG).PHP_EOL; + } + } +} +echo "Bye"; +echo "\n"; +die(); diff --git a/objects/include_config.php b/objects/include_config.php index cfb17dc348..646c8bf820 100644 --- a/objects/include_config.php +++ b/objects/include_config.php @@ -60,12 +60,6 @@ ini_set('error_log', $global['logfile']); global $global, $config, $advancedCustom, $advancedCustomUser; require_once $global['systemRootPath'] . 'objects/functions.php'; -if(isCommandLineInterface()){ - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - error_reporting(E_ALL); - echo 'Include config line '.__LINE__.PHP_EOL; -} if (empty($doNotConnectDatabaseIncludeConfig)) { _mysql_connect(); } else { @@ -75,9 +69,6 @@ require_once $global['systemRootPath'] . 'objects/mysql_dal.php'; require_once $global['systemRootPath'] . 'objects/configuration.php'; require_once $global['systemRootPath'] . 'objects/security.php'; -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} // for update config from old versions 2020-05-11 if (empty($global['webSiteRootPath']) || $global['configurationVersion'] < 3.1) { Configuration::rewriteConfigFile(); @@ -106,17 +97,11 @@ if (empty($doNotStartSessionbaseIncludeConfig)) { session_start(); } -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} // DDOS protection can be disabled in video/configuration.php if (!empty($global['enableDDOSprotection'])) { ddosProtection(); } -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} // set the referrer for aVideo $url1['host'] = ''; $global['HTTP_REFERER'] = ''; @@ -156,17 +141,11 @@ if (!empty($url1['host']) && !empty($url2['host']) && $url1['host'] !== $url2['h $_SESSION['LAST_HTTP_REFERER'] = $global['HTTP_REFERER']; //var_dump($global['HTTP_REFERER'], $url1);exit; -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} _ob_end_clean(); //$output = _ob_get_clean(); _ob_start(true); //echo $output; -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} $_SESSION['lastUpdate'] = time(); $_SESSION['savedQuerys'] = 0; require_once $global['systemRootPath'] . 'objects/Object.php'; @@ -198,18 +177,12 @@ if (empty($global['avideo_resolutions'])) { $global['avideo_resolutions'] = [240, 360, 480, 540, 720, 1080, 1440, 2160]; } -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} sort($global['avideo_resolutions']); if (!empty($doNotConnectDatabaseIncludeConfig)) { return false; } $advancedCustom = AVideoPlugin::getObjectData('CustomizeAdvanced'); -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} if (empty($global['disableTimeFix'])) { /* $now = new DateTime(); @@ -224,18 +197,12 @@ if (empty($global['disableTimeFix'])) { ObjectYPT::setGlobalTimeZone(); } -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} $avideoLayout = AVideoPlugin::getObjectData('Layout'); $avideoCustomizeUser = $advancedCustomUser = AVideoPlugin::getObjectData('CustomizeUser'); $avideoCustomize = $customizePlugin = AVideoPlugin::getObjectData('Customize'); $avideoPermissions = $permissionsPlugin = AVideoPlugin::getObjectData('Permissions'); $avideoPlayerSkins = AVideoPlugin::getObjectData('PlayerSkins'); -if(isCommandLineInterface()){ - echo 'Include config line '.__LINE__.PHP_EOL; -} if (!empty($_GET['type'])) { $metaDescription = " {$_GET['type']}"; } elseif (!empty($_GET['showOnly'])) { diff --git a/objects/user.php b/objects/user.php index a2c979bcb1..104b7cfc41 100644 --- a/objects/user.php +++ b/objects/user.php @@ -616,12 +616,12 @@ if (typeof gtag !== \"function\") { //echo "u:" . $this->user . "|p:" . strlen($this->password); if (empty($this->user)) { //echo "u:" . $this->user . "|p:" . strlen($this->password); - _error_log('Error : 1 ' . __("You need a user and passsword to register")); + _error_log('Error : 1 ' . __("You need a user to register")); return false; } if (empty($this->password)) { //echo "u:" . $this->user . "|p:" . strlen($this->password); - _error_log('Error : 2 ' . __("You need a user and passsword to register")); + _error_log('Error : 2 ' . __("You need a passsword to register")); return false; } diff --git a/objects/userGroups.php b/objects/userGroups.php index 90836b39ce..c1cbad63f0 100644 --- a/objects/userGroups.php +++ b/objects/userGroups.php @@ -213,9 +213,8 @@ class UserGroups // for users - public static function updateUserGroups($users_id, $array_groups_id, $byPassAdmin=false, $mergeWithCurrentUserGroups=false) - { - if (!$byPassAdmin && !Permissions::canAdminUsers()) { + public static function updateUserGroups($users_id, $array_groups_id, $byPassAdmin=false, $mergeWithCurrentUserGroups=false){ + if (!$byPassAdmin && !Permissions::canAdminUsers() && !isCommandLineInterface()) { return false; } if (!is_array($array_groups_id)) { @@ -383,18 +382,20 @@ class UserGroups public static function updateVideoGroups($videos_id, $array_groups_id, $mergeWithCurrentUserGroups=false) { - if (!User::canUpload()) { + if (empty($array_groups_id) || (!isCommandLineInterface() && !User::canUpload())) { return false; } if (!is_array($array_groups_id)) { - return false; + $array_groups_id = array($array_groups_id); } if ($mergeWithCurrentUserGroups) { $current_user_groups = self::getVideosAndCategoriesUserGroups($videos_id); foreach ($current_user_groups as $value) { if (!in_array($value['id'], $array_groups_id)) { - $array_groups_id[] = $value['id']; + if($value['isVideoUserGroup']){ + $array_groups_id[] = $value['id']; + } } } }