sbj
Well-known member
Hey,
I want to insert value_id X of a custom thread field to ALL threads of a node.
Basically I have hundeds, or thousands of threads and I don't want to manually update all of them. Too tiresome to do this for hundreds of threads using the overlays on front-end. The batch-update of XF doesn't have that function sadly.
Someone friendly helped me, but it doesn't work right now. Don't want to steal his time anymore so I thought I ask it publicly.
What I have so far is this:
These queries ran successfully in phpmyadmin, but on XF I was getting this error:
Now after I got that error, I got told to do this to all OTHER existing CTFs in that node. For each of them:
Still the error is happening and I don't see the Custom Thread Field with those values appearing on frontend. Of course I rebuilt the threads but no luck.
Anybody any idea? Or do I need a PHP part to update the threads successfully? Thanks.
I want to insert value_id X of a custom thread field to ALL threads of a node.
Basically I have hundeds, or thousands of threads and I don't want to manually update all of them. Too tiresome to do this for hundreds of threads using the overlays on front-end. The batch-update of XF doesn't have that function sadly.
Someone friendly helped me, but it doesn't work right now. Don't want to steal his time anymore so I thought I ask it publicly.
What I have so far is this:
SQL:
DELETE xf FROM xf_thread_field_value xf
LEFT JOIN xf_thread xt ON xt.thread_id = xf.thread_id
WHERE xt.node_id = 2
AND xf.field_id = 'CTF1'
SQL:
INSERT INTO xf_thread_field_value (thread_id, field_id, field_value)
SELECT thread_id, 'CTF1', 'value_id_x'
FROM xf_thread
WHERE node_id = 2
These queries ran successfully in phpmyadmin, but on XF I was getting this error:
PHP:
Server error log
ErrorException: Template error: Invalid argument supplied for foreach() src\XF\CustomField\Definition.php:31
Generated by: xxx 25 April 2019 at 13:20
Stack trace
#0 src\XF\CustomField\Definition.php(31): XF\Template\Templater->handleTemplateError(2, 'Invalid argumen...', 'C:\\xampp\\htdocs...', 31, Array)
#1 [internal function]: XF\CustomField\Definition->getFormattedValue(false)
#2 src\XF\Template\Templater.php(985): call_user_func_array(Array, Array)
#3 internal_data\code_cache\templates\l1\s2\public\custom_fields_macros.php(115): XF\Template\Templater->method(Object(XF\CustomField\Definition), 'getFormattedVal...', Array)
#4 src\XF\Template\Templater.php(701): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, Array)
#5 internal_data\code_cache\templates\l1\s2\public\custom_fields_macros.php(69): XF\Template\Templater->callMacro('custom_fields_m...', 'custom_field_va...', Array, Array)
#6 src\XF\Template\Templater.php(701): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, Array)
#7 internal_data\code_cache\templates\l1\s2\public\custom_fields_macros.php(28): XF\Template\Templater->callMacro('custom_fields_m...', 'custom_fields_v...', Array, Array)
#8 src\XF\Template\Templater.php(701): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, Array)
#9 internal_data\code_cache\templates\l1\s2\public\thread_view.php(476): XF\Template\Templater->callMacro('custom_fields_m...', 'custom_fields_v...', Array, Array)
#10 src\XF\Template\Templater.php(1301): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array)
#11 src\XF\Template\Template.php(24): XF\Template\Templater->renderTemplate('thread_view', Array)
#12 src\XF\Mvc\Renderer\Html.php(48): XF\Template\Template->render()
#13 src\XF\Mvc\Dispatcher.php(418): XF\Mvc\Renderer\Html->renderView('XF:Thread\\View', 'public:thread_v...', Array)
#14 src\XF\Mvc\Dispatcher.php(400): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#15 src\XF\Mvc\Dispatcher.php(360): XF\Mvc\Dispatcher->renderReply(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#16 src\XF\Mvc\Dispatcher.php(53): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#17 src\XF\App.php(2177): XF\Mvc\Dispatcher->run()
#18 src\XF.php(390): XF\App->run()
#19 index.php(20): XF::runApp('XF\\Pub\\App')
#20 {main}
Request state
array(4) {
["url"] => string(144) "/forum/xxx.51168/"
["referrer"] => string(60) "http://localhost/_forum_/xxx.36/"
["_GET"] => array(0) {
}
["_POST"] => array(0) {
}
}
Now after I got that error, I got told to do this to all OTHER existing CTFs in that node. For each of them:
SQL:
INSERT INTO xf_thread_field_value (thread_id, field_id, field_value)
SELECT thread_id, 'CTF2', ''
FROM xf_thread
WHERE node_id = 2
ON DUPLICATE KEY update field_id = field_id
Still the error is happening and I don't see the Custom Thread Field with those values appearing on frontend. Of course I rebuilt the threads but no luck.
Anybody any idea? Or do I need a PHP part to update the threads successfully? Thanks.
Last edited: