vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   DataManager: Problem changing username before deleting user (https://vborg.vbsupport.ru/showthread.php?t=279459)

PleaseHelp 03-02-2012 11:02 PM

DataManager: Problem changing username before deleting user
 
Hello,

We want to change the username of all users we delete prior to their deletion so that all their "Guest" posts contain the new username.

We have the DataManager code for both changing the username and deleting a user, and each works fine independently. The change username code correctly changes the username of the user and the change is correctly reflected in all of that user's posts and threads. Likewise, the delete user completely deletes the user and changes all the user's posts to the "Guest" title.

However, when run together, one right after the other, they cause a problem. The code below does NOT change the username of all the posts of the user, even though it does change the user's username and then deletes him, leaving all his posts with his original username (not the new username):

PHP Code:

include("global.php");

$newusername 'DeletedUser1';

//change username
$vbulletin->GPC['userid'] = $userid;
$userdm =& datamanager_init('User'$vbulletinERRTYPE_CP);
$userdm->adminoverride true;
$userinfo fetch_userinfo($vbulletin->GPC['userid']);
$userdm->set_existing($userinfo);
$userdm->set('username'$newusername);  //usergroupid
$changeuser $userdm->save();  //returns 1 on success
echo $changeuser;
unset(
$userdm);
    
//delete user
if ($changeuser == 1) {
      
$vbulletin->GPC['userid'] = $userid;
      
$userinfo fetch_userinfo($userid);
      
$userdm =& datamanager_init('User'$vbulletinERRTYPE_CP);
      
$userdm->set_existing($userinfo);
      
$deleteuser $userdm->delete();
      echo 
$deleteuser //returns 1 on success



Both $changeuser and $deleteuser return 1, so they are executing correctly. However, as mentioned above, when the script is done deleting the user, all his deleted posts contain the original username, not the new username changed in the script.

However, if we split the code above into two separate scripts (one to change the username and the other to delete the user), and run one after the other, then it works and correctly changes the username of all the user's posts such that after he is deleted, it displays the new username in all his posts (together with the "Guest" title).

This tells us that when it is run together, something either in the SESSION vars or some GLOBAL var is not being updated with the new username, so that when the delete part comes along, it still has the old username in memory and that's why it is not changing the username in the posts (or something to that effect). (We should add that it DOES change the username in the threads, but NOT the posts, which is very strange.)

So how can we resolve this so we don't have to run it as 2 scripts? Is there some way of "refreshing" whatever variable might be causing this?

Thanks!

kh99 03-03-2012 12:19 PM

I think it might be that fetch_userinfo() reads cached information, so you could try this before the delete call:

Code:

$userinfo = fetch_userinfo($userid, 0, 0, 1); // the 4th parameter is "nocache"


All times are GMT. The time now is 09:20 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00985 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete