Change php user group

Change User Group Via PHP

I don’t think the XenForo Class Proxy works properly when you’re loading classes from outside XenForo. I had an issue similar to this when working on something a couple weeks ago. Perhaps @Chris D can chime in on this?

The specific issue I had was with DataWriter classes extending XenForo_DataWriter_User not running when I called XenForo_DataWriter_User from outside of XenForo while using Kotomi.

Chris D

XenForo developer

I can’t speak on behalf of how the Kotomi bridge works, but generally there should be no problem with XF accessing extended classes.

This is pretty much all you need to instantiate XF and have access to pretty much everything (at the code level, at least):

setupAutoloader($fileDir . '/library'); XenForo_Application::initialize($fileDir . '/library', $fileDir); XenForo_Application::set('page_start_time', $startTime); $dependencies = new XenForo_Dependencies_Public(); $dependencies->preLoadData(); $visitor = XenForo_Visitor::getInstance(); $user_id = $visitor->getUserId(); $userModel = XenForo_Model::create('XenForo_Model_User'); $userModel->removeUserGroupChange($user_id, 'RANDOM_STRING'); $userModel->addUserGroupChange($user_id, 'RANDOM_STRING', 10);

Jake B.

Well-known member

I can’t speak on behalf of how the Kotomi bridge works, but generally there should be no problem with XF accessing extended classes.

This is pretty much all you need to instantiate XF and have access to pretty much everything (at the code level, at least):

setupAutoloader($fileDir . '/library'); XenForo_Application::initialize($fileDir . '/library', $fileDir); XenForo_Application::set('page_start_time', $startTime); $dependencies = new XenForo_Dependencies_Public(); $dependencies->preLoadData(); $visitor = XenForo_Visitor::getInstance(); $user_id = $visitor->getUserId(); $userModel = XenForo_Model::create('XenForo_Model_User'); $userModel->removeUserGroupChange($user_id, 'RANDOM_STRING'); $userModel->addUserGroupChange($user_id, 'RANDOM_STRING', 10);
$fileDir = $forumPath; $startTime = microtime(true); require($fileDir . '/library/XenForo/Autoloader.php'); XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library'); XenForo_Application::initialize($fileDir . '/library', $fileDir); XenForo_Session::startPublicSession();

and when I created a DataWriter using XenForo_DataWriter::create(‘XenForo_DataWriter_User’) it did not load any of the classes that extend XenForo_DataWriter_User, so even if I put a die; in _preSave() or _getFields() that never happened, it continued to try to save the user, but missing any custom fields added by add-ons.

Читайте также:  Python определить время суток

I’ll try to get more details on this issue when I have some time, but it seems like the XF Class Proxy doesn’t actually do anything when it’s called from outside of XenForo, which seemed odd.

Chris D

XenForo developer
$dependencies = new XenForo_Dependencies_Public(); $dependencies->preLoadData();

stefanstp

Member

Is it possible to change the secondary_group_ids with one mysql command like (this works fine in vbulletion for secondary_group; but work not in xenforo):

UPDATE xf_user SET secondary_group_ids= secondary_group_ids+ 23 WHERE NOT (secondary_group_ids & 23);

Dan Allen

Active member

I don’t know how it has to be done back in 2012, when Chris offered the solution above. But in most recent versions of XenForo the programatic addition (or removal) of a user group to a user account is very easy (assuming we are in a controller):

$userModel = XenForo_Model::create('XenForo_Model_User'); $userModel->addUserGroupChange($userId, 'any_id_you_like', $groupId); $userModel->removeUserGroupChange($userId, 'any_id_you_like');

Regarding your comments @Dan Allen :
It won’t get better. Modern software is object orientated and follows the MVC model and data writers. It makes it in fact easier to expand the code and the create large applications with a very small bug rate (like XenForo).

External login and registration is also very easy to implement in an add-on. Thanks to MVC and data writers. you should get comfortable with it.

@HWS, Would it be reasonable to adapt what you have provided to use on a bulk update user group assignments? I’ve been advised there are warranty and support implications, basically, if it gets messed up it cannot be supported by XF and it is strongly discouraged by XF.

I also am wondering if you can comment on an observation I have seen posted and seen myself, which is an apparent lack of working examples that can make understanding the technology easier. In other words, since it is simple and easy to implement external login, where are the several examples available for download and if they are not available that way, why not? It seems common enough to be able to find working examples of all kinds of code, XF modifications not packaged as addons being an exception.

Источник

How to change PHP-User/Group from Root|Root to Nobody|Nogroup?

When using TYPO3, you can configure which group should be set for created or uploaded files. You have to set the following configuration variable.

$GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = 'nogroup'; 

However, this only works for uploads that are actually handled by the TYPO3 api. Have a look at

\TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move() 

to get an impression on how TYPO3 handles file uploads.

More Answer

  • How to change user email in PHP Firebase using CORE PHP not any framework
  • Using bash, how to change the name of a file based on feedback from PHP script?
  • How to fix Undefined index if user removes name attr from sign up form php
  • how to use a user input defined in one html page in another php page to fetch data from oracle database
  • how to get current date/time in PHP from user
  • How to remove unwanted HTML tags from user input but keep text inside the tags in PHP using DOMDocument
  • How to restrict user to change the URL in PHP
  • How to get the values from a $.ajax using php
  • How to clear PHP APC from a Selenium test?
  • How to override settings in php.ini and httpd.conf from my php application
  • How to take the current key from array? PHP
  • how show the data from array list in php
  • How do I prevent a user from logging in from 2 locations at the same time?
  • How to take a value from a JavaScript file and send it to a PHP file?
  • How to access a plugin model from a regular controller in PHP Cake 1.1
  • How do I get this php statement that gets all the values from database and outputs as checkboxes to work? (PHP/Mysql)
  • How to pass variable from JavaScript to PHP using jQuery POST
  • How to change list to CSV, and vice versa, in PHP
  • How to stop PHP source from being printed to my browser?
  • how to change the output encoding, while displaying a file through php
  • How to execute a command line from php
  • how to access memcache item created in php from java
  • How can I see what variables are sent from flash to a PHP script?
  • how to handle 1 value returned from sql in php
  • PHP SOAP : How can I return objects from PHP using SOAP?
  • How do I write a converter to change a PHP file into a Bash file?
  • how do i copy/upload file from S3 to EC2 in PHP
  • How to send emails with PHP from a heavily firewalled network?
  • How do I post to GraphQL from PHP
  • How to delete items from cart through SESSION & AJAX in php
  • How to hide url from get method in php
  • PHP — How to edit Array Elements from JSON File?
  • Php 8, how to ignore supressed errors from logging?
  • How to copy files from S3 bucket to S3 bucket in PHP (AWS SDK for PHP)?
  • How to get timestamp of: current year quarter start/end, last quarter start/end, from specified date in PHP
  • How to add Javascript date from browser inside a PHP link
  • how to remove Yiddish scoring from a string in PHP
  • How to get and pass a XML string on php to java script from mysql
  • How to get result from database based on the user with laravel
  • How to handle if a client change some data attributes from the client side?
  • how to create a json array with data from a foreach loop in php
  • how to get value using get method from php
  • How to change the zoom level of a Google Sheet in PHP
  • How to retreive data from url using SLUG php mysql
  • How to remove specific element from array in php
  • How to send POST request from Flutter app to PHP server
  • How to run Node.Js server from php
  • How to get values from array object in PHP
  • php — how to get meta tags from url
  • How to pass a variable in PHP from a Python file?

More answer with same ag

  • Parsing version number of Linux distro to PHP variable
  • Is it possible to convert .cer and a .key files to .pem by only using php openssl functions?
  • php — echo require code passed in variable
  • How to use PHP in the header of a drupal view?
  • How to add CSS class to element on a Symfony generated form?
  • How to clear a session cookie
  • PHP Regex completely remove HTML Anchor link from string in PHP
  • Postiton an echo on the page in PHP or incorporate it with CSS
  • Unable to exec(«java -version») in php osx
  • Strip out ad from html string
  • Loop in switch or switch in loop
  • How to generate a url for the first test of Payum Payment Bundle with symfony2.8
  • jquery post php undefined index
  • PHP: var_dump while loop
  • what does test_input mean in pregmatch when validating input data?
  • How to combine an array of keys with corresponding values from another array?
  • Why the string to variable conversion doesn’t work for the _GET variable from another file?
  • PHP Paypal intergration with instant feedback
  • Mpdf remove footer and use it’s space for content
  • Converting Binary Data to ASCII with PHP, Any Possibility?
  • php : is this if condition correct?
  • Accessing Firebase using PHP
  • WAMP — phppgadmin — 403 Forbidden
  • laravel 5.1 it’s Call to a member function where() on string
  • Update two tables using laravel
  • Are Numbers As Validated Password Reset Is It Safe?
  • Group json data with common fields on php
  • How should I create global function base on this situation php?
  • How to evaluate the json response from google’s JSON/Atom Custom Search API by using php?
  • Facebook PHP SDK upgrade v4 to v5 and OpenGraph session
  • Using foreach and unset() to keep only a specific set of data in a php array
  • Php upload file then crop
  • PHP — Same structure arrays not working with function
  • Yii2 afterDelete won’t get called
  • How to stop setInterval when all Ajax calls are finished?
  • How to rewrite URL and return `404` for original links?
  • Fat Free Framework routing cannot not differentiate parameters from URI
  • PHP replace urls with Anchor text
  • How to add word from input to another input form
  • Call Javascript function and execute PHP at the same time?
  • Promises in array forEach loop
  • how to convert datetime from mysql to doctrine2 odm in zf2?
  • SimpleXML and php — get a node that contains text that matches another node
  • Stripe — Pay order error : Cannot charge a customer that has no active card
  • php memcache not working with mvc
  • PHP: Upload images from client machine to the server
  • Getting array data from PHP to jQuery for outputting
  • PHP oci8 installation fails on Ubuntu 18
  • Filter array where key value equals as string with PHP
  • How to add watermark to an image at the bottom right in PHP?

Источник

Оцените статью