XF 2.2 Custom thread field not updating -> help

Dannymh

Active member
Hi all,

I have a series of custom fields that get updated during a specific process All fields but one continue to get updated and I can not figure out why.

The code I have is

PHP:
 //Update thread details and close thread
            $theThread->custom_fields->set('otbOrderState', 'bin', 'admin', true);
            $theThread->custom_fields->set('otbPurchaseType', 'bin', 'admin', true);
            //this following field wont update
            $theThread->custom_fields->set('otbAuctionEndTimeStamp', time(), 'admin', true);
            
            $theThread->custom_fields->set('otbLeader_id', \XF::visitor()->user_id, 'admin', true);
            $theThread->save();

All the other fields update correctly during this process, however the TimeStamp does not (this is a single line text field with no validations on it that I use for background tasks and reporting.

Code:
$theThread->custom_fields->set('otbAuctionEndTimeStamp', time(), 'admin', true);

There are no restrictions or formatting on that field. any ideas as to what may be preventing this? Is there a way to output any errors or logging that may be going on with it?
 
I added a new field to see if that would work, and this updates in the same process correctly if I have the following line directly under it

Code:
$theThread->custom_fields->set('otbETS', time(), 'admin', true);

THe field has the exact same settings
 
See XF\Service\Thread\EditorService::setCustomFields() for how to update custom fields. They're not updated directly on the property like that. You'd need to use the thread editor service to edit the the thread, set the fields and save.

PHP:
$editor = $this->service('XF:Thread\Editor', $thread);

$editor->setCustomFields($fieldValues);

$editor->save();

Something closer to that.
 
See XF\Service\Thread\EditorService::setCustomFields() for how to update custom fields. They're not updated directly on the property like that. You'd need to use the thread editor service to edit the the thread, set the fields and save.

PHP:
$editor = $this->service('XF:Thread\Editor', $thread);

$editor->setCustomFields($fieldValues);

$editor->save();

Something closer to that.
I will give it a go, however all the other fields are updating, its only this one that doesn't want to update using the method above
 
Probably just the wrong field name or an invalid value then, it wouldn't do anything differently for one field over the others if it's a valid field for that content type.
 
Probably just the wrong field name or an invalid value then, it wouldn't do anything differently for one field over the others if it's a valid field for that content type.
Found it, I forgot I had another entity in a related addon overwriting that field, I just needed to wrap that in some checks and that fixed it
 
Back
Top Bottom