Fixed Batch update users broken in 2.2.12

K a M a L

Well-known member
Affected version
2.2.12
Since 2.2.12 .. batch update users feature is broken due to this weird change at XF\Job\UserAction
PHP:
        $customTitle = $this->getActionValue('custom_title');
        if ($customTitle !== '')
        {
            $user->custom_title = $customTitle;
        }

where $customTitle will never be an empty string because the method getActionValue returns null for empty values
This sets user title to null and causes the user entity save process to fail silently at the method verifyCustomTitle where null will never equal empty string
PHP:
        if ($title !== $this->app()->stringFormatter()->censorText($title))
        {
            $this->error(\XF::phrase('please_enter_custom_title_that_does_not_contain_any_censored_words'), 'custom_title');
            return false;
        }
 
Last edited:
Since 2.2.12 .. batch update users feature is broken due to this weird change at XF\Job\UserAction
PHP:
        $customTitle = $this->getActionValue('custom_title');
        if ($customTitle !== '')
        {
            $user->custom_title = $customTitle;
        }

where $customTitle will never be an empty string because the method getActionValue returns null for empty values
This sets user title to null and causes the user entity save process to fail silently at the method verifyCustomTitle where null will never equal empty string
PHP:
        if ($title !== $this->app()->stringFormatter()->censorText($title))
        {
            $this->error(\XF::phrase('please_enter_custom_title_that_does_not_contain_any_censored_words'), 'custom_title');
            return false;
        }
Did you solve this problem?
 
Did you solve this problem?
you can just revert the last fix
change
PHP:
        $customTitle = $this->getActionValue('custom_title');
        if ($customTitle !== '')
        {
            $user->custom_title = $customTitle;
        }
to
PHP:
        if ($customTitle = $this->getActionValue('custom_title'))
        {
            $user->custom_title = $customTitle;
        }
 
which template?
you can just revert the last fix
change
PHP:
        $customTitle = $this->getActionValue('custom_title');
        if ($customTitle !== '')
        {
            $user->custom_title = $customTitle;
        }
to
PHP:
        if ($customTitle = $this->getActionValue('custom_title'))
        {
            $user->custom_title = $customTitle;
        }
 
Now I get the error when I say ban bulk user (17)
Code:
Mutemet Forum I Uzman Mutemet
LogicException: Attempted to set 'is_banned' while a save was pending without forceSet in src/XF/Mvc/Entity/Entity.php at line 605
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 577
XF\Mvc\Entity\Entity->__set() in src/XF/Entity/UserBan.php at line 66
XF\Entity\UserBan->setIsBanned() in src/XF/Entity/UserBan.php at line 48
XF\Entity\UserBan->_postSave() in src/XF/Mvc/Entity/Entity.php at line 1277
XF\Mvc\Entity\Entity->save() in src/XF/Repository/Banning.php at line 53
XF\Repository\Banning->banUser() in src/XF/Job/UserAction.php at line 163
XF\Job\UserAction->applyExternalUserChange() in src/XF/Job/UserAction.php at line 32
XF\Job\UserAction->executeAction() in src/XF/Job/AbstractUserCriteriaJob.php at line 61
XF\Job\AbstractUserCriteriaJob->run() in src/XF/Job/Manager.php at line 260
XF\Job\Manager->runJobInternal() in src/XF/Job/Manager.php at line 202
XF\Job\Manager->runJobEntry() in src/XF/Job/Manager.php at line 118
XF\Job\Manager->runByIds() in src/XF/Admin/Controller/Tools.php at line 122
XF\Admin\Controller\Tools->actionRunJob() in src/XF/Mvc/Dispatcher.php at line 352
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 259
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 115
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 57
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2483
XF\App->run() in src/XF.php at line 524
XF::runApp() in admin.php at line 13
 
Since 2.2.12 .. batch update users feature is broken due to this weird change at XF\Job\UserAction
PHP:
        $customTitle = $this->getActionValue('custom_title');
        if ($customTitle !== '')
        {
            $user->custom_title = $customTitle;
        }

where $customTitle will never be an empty string because the method getActionValue returns null for empty values
This sets user title to null and causes the user entity save process to fail silently at the method verifyCustomTitle where null will never equal empty string
PHP:
        if ($title !== $this->app()->stringFormatter()->censorText($title))
        {
            $this->error(\XF::phrase('please_enter_custom_title_that_does_not_contain_any_censored_words'), 'custom_title');
            return false;
        }

So is there a fix to this that we can go code ourselves - I just converted from VB and really need to do a lot of batch updates.... Having to weed through 170,000 members and manually having to move them is ugly.

I wonder if I can grab the code from an earlier Xenforo and replace the existing?
 
Last edited:
It's an open bug report, the weekend, and the Xmas break.

It will be addressed in due course and fixed for the next release.

Continuously bumping bug reports doesn't achieve anything.
 
Will there be an answer on this subject?

I can get it to work... it means editing a template which is not cool but, if you can't wait for the official fix (which I recommend that you do), here are code changes that you need to do. WARNING - DO NOT USE THESE EDITS IF YOU USE CUSTOM TITLES

Ok... if you really need to do this
1. Make a backup of /src/Xf/XfJob/UserAction.php to something like /src/Xf/XfJob/UserAction-original.php
2 Edit /src/Xf/XfJob/UserAction.php
3. Around line 143, you'll see this code:

Code:
        $customTitle = $this->getActionValue('custom_title');
        if ($customTitle !== '')
        {
            $user->custom_title = $customTitle;
        }
}

Replace it with this:
Comment out the original code with //
Code:
//        $customTitle = $this->getActionValue('custom_title');
//        if ($customTitle !== '')
//        {
//            $user->custom_title = $customTitle;
//        }
$customTitle='';                 //two new lines added here
$user->custom_title = ''
}

Save the file, then go run your user batch update

Again: WARNING - I DON'T RECOMMEND DOING THIS - do this at your own risk - I'm not responsible if you don't make a backup, or something weird happens (like your barn catches fire) but I just converted from VB to XF and had 170,000 users that I need to fix their secondary_group_ids and there was no way I was going to manually edit each one.

Good Luck
 
Last edited:
So is there a fix to this that we can go code ourselves - I just converted from VB and really need to do a lot of batch updates.... Having to weed through 170,000 members and manually having to move them is ugly.

I wonder if I can grab the code from an earlier Xenforo and replace the existing?

This worked for me - it will most likely work for you:
I made a backup of of /src/Xf/Job/UserAction.php
Then grabbed an earlier Xenforo verson - I grabbed a v2.10 version
Copied the UserAction.php from that version to the current version
and then ran the Batch update users.... BINGO.... it works.
No issues, no errors, batch completed like it is supposed to - was able to mass update 170,000 users.

Not sure what version is the best to grab, I grabbed the 2.10 version because I had access to it. Later versions will probably work too (like maybe 2.2.11 ?) or whenever version it was when it last worked before 2.2.12. If I was doing this again, I'd probably try a version closer to 2.2.12.

ymmv

btw: After running vb for 10 years, I am loving xenforo admin functions, and my members, usually freaking out over even the simplest of changes, have all, 100% of them, are loving it too. Why did I wait so long? (y)
 
I don't understand, if the whole issue is that custom title may be null then why doesn't anyone just simply fix the if statement as the work-around?


PHP:
if ($customTitle !== '')

Change to

if ($customTitle != null && $customTitle !== '')
 
I don't understand, if the whole issue is that custom title may be null then why doesn't anyone just simply fix the if statement as the work-around?


PHP:
if ($customTitle !== '')

Change to

if ($customTitle != null && $customTitle !== '')
The custom title is not the issue - the actual issue is deeper in the code. Others mentioned commenting out the IF but doing that caused errors. I added the code I did so the script would not fail.

A better solution that seems to work is making a backup of your original, then replace it with an earlier version - I tried 2.2.11 and it worked fine without any code changes except for changing the STATE of the users - I wanted to change the STATE to "bounced email" and that only did the change on about 80 of the 1500 I needed it to.
 
Back
Top Bottom