Trouble parsing JSON

apathy

Well-known member
Hey guys, I'm writing an addon for my site that parses several JSON files from a game server I run and stores that info in various Entities I have created.
The cron script I wrote for fetching Ban data works perfectly fine, however a similar one that parses Reserved Slot info does not.

Ban job (which works)
Reserved slot job (which does not work)

The IDs in the json for the reserved slots are all stored in a field on xf_user called ap_steam_id. The problem is that it seems to only find my own account, despite the fact that every other ID in the json is registered on my forum with that ID set in ap_steam_id.

Here is what happens when I dump($uid):

XaFLoa3.png


as you can see, there is data found for Steam ID 68118554 / User ID 2, but all other entries return null. I know for a fact that each of these accounts have ap_steam_id populated so I don't know why only 1 row is returning... my only guess is because the structure of both JSON files is slightly different

Any help here would be greatly appreciated.
 
Last edited:

Jeremy P

XenForo developer
Staff member
At a glance, you should move $finder = \XF::finder('...') into the loop. Finders are mutable objects, so calling $finder->where('...') in a loop will continue appending conditions (ie. WHERE ap_steam_id = 1 AND ap_steam_id = 2) which will never return a result.
 

apathy

Well-known member
At a glance, you should move $finder = \XF::finder('...') into the loop. Finders are mutable objects, so calling $finder->where('...') in a loop will continue appending conditions (ie. WHERE ap_steam_id = 1 AND ap_steam_id = 2) which will never return a result.
That did the trick alright, I thought the way I was doing it would be more performance friendly but what you're saying makes a lot of sense. Thanks a lot for the help!
 
Top