rsanchez / json

Output ExpressionEngine data in JSON format.
http://devot-ee.com/add-ons/json/
100 stars 236 forks source link

Support for EE4 #63

Open pixelclef opened 6 years ago

pixelclef commented 6 years ago

Would love some discussion on making this work in EE4.

I've made the modifications in Support for EE3. That resolves installing the plugin as before, but there is a new error being thrown as a result of the database structure changes.

error-message

Zignature commented 4 years ago

I got it working on EE 4.3.8 :)

I'm not much of a PHP programmer or a SQL master let alone an EE developer, so it took me all day...

The SQL SELECT statement on line 117 in pi.json.php is obsolete. There have been database changes since EE 2.11.9, so the SQL statement queries fields that aren't present anymore. The original SQL statement queried two tables with a single JOIN. The SQL statement I created queries four (!) tables with three (!) joins.

To make it work on EE 4.3.8: First you need to apply the modifications mentioned here: Support for EE3

Then you need to replace this code that starts around line 117: $this->entries_custom_fields = ee()->db->select('channel_fields.*, channels.channel_id') ->from('channel_fields') ->join('channels', 'channel_fields.group_id = channels.field_group') ->where('channels.site_id', ee()->config->item('site_id')) ->where_in('channels.channel_name', explode('|', ee()->TMPL->fetch_param('channel'))) ->get() ->result_array();

With: $this->entries_custom_fields = ee()->db->select('channel_fields.*') ->from('channel_fields') ->join('channel_field_groups_fields', 'channel_fields.field_id = channel_field_groups_fields.field_id') ->join('channels_channel_field_groups', 'channel_field_groups_fields.group_id = channels_channel_field_groups.group_id') ->join('channels', 'channels_channel_field_groups.channel_id = channels.channel_id') ->where('channels.site_id', ee()->config->item('site_id')) ->where_in('channels.channel_name', explode('|', ee()->TMPL->fetch_param('channel'))) ->get() ->result_array();

It works like a charm so far on my EE 4.3.8 box. It may even work for EE5.

Since I haven't done any thorough testing I do not recommend using this on a production site, and I certainly won't accept any liability for any damages or what have you.

I'd love to get feedback on this, cause it may be improved by some better developer/coder than me :)