• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[Solved] Safest way to refresh data registry nodeTypes row

Bloodcinder

Well-known member
#1
I'm working on an add-on that provides a new node type in XenForo. The add-on itself is working and ready to release except... I don't know how to automate the installation yet.

Here are the manual steps I took in the database (what I'm trying to automate).
  1. Added an entry to the xf_node_type table with all appropriate details.
  2. Added a corresponding record into the serialized array in the nodeTypes row of the xf_data_registry table by manipulating the BLOB very meticulously.
When I go to write my installer for the add-on, step 1 is easy to automate with an SQL query. So here's my question: what's the safest way to automate step 2 above?

I've read that it may be safe to just delete the nodeTypes row and wait for XenForo to regenerate it in the registry, but that seems either irresponsible or unreliable to me, and I wouldn't want to do it without a clear understanding of the consequences.

Obviously it's possible to unserialize the BLOB array, add in what's necessary, and then push it back to the row via SQL, but that seems really cumbersome.

Is there a canonical way to update the row I need to update or the whole registry?

For reference, even after completing step 1 my add-on would not work until I completed step 2; XF did not automatically update the registry for me.

Hopefully this isn't a really obscure question.
 

Chris D

XenForo developer
Staff member
#2
Sorry a bit vague but basically there will be s function somewhere that rebuilds the data registry entry for node types.

Find that and call that and it will do it for you.

You should never need to edit the data registry directly.
 

Bloodcinder

Well-known member
#3
Thanks for pointing me in the right direction, @Chris D. We've got a bingo. Here's the solution.

After adding a node type row to the xf_node_type table via SQL (step 1 above), the following statement will rebuild the nodeTypes row of xf_data_registry to synchronize the cached version (step 2 above):
Code:
XenForo_Model::create('XenForo_Model_Node')->rebuildNodeTypeCache();
To be clear, I tested it and it works.