We have moved to Github. Please open tickets there.

Opened 13 months ago

Closed 11 months ago

Last modified 11 months ago

#4504 closed Defect (fixed)

Groups and Users are duplicated in lists in json view

Reported by: sembrestels Owned by: sembrestels
Priority: normal Milestone: Elgg 1.9.0
Component: API Version: 1.8
Severity: major Keywords: json, export
Cc: brett@…, sembrestels Difficulty:

Description

It works correct for any ElggObject, but for ElggGroups and ElggUsers there are duplicates in the lists.

You can see it in:
http://YOURELGGSITE/members?view=json
http://YOURELGGSITE/groups/all?view=json

Change History (13)

comment:1 Changed 13 months ago by sembrestels

JSON in elgg views are created adding entities, annotations or items to $jsonexport global variable. This is what do views/json/page/default:

header("Content-Type: application/json");

global $jsonexport;
echo json_encode($jsonexport);

This is a piece of code in views/json/export/entity:

global $jsonexport;
$jsonexport[$entity->getType()][$entity->getSubtype()][] = $export;

Using a variable to get the data across the views is dangerous. Things like this can happen:

/engine/lib/views.php, lines 869-875:

	$contents = '';
	if (elgg_view_exists("$entity_type/$subtype")) {
		$contents = elgg_view("$entity_type/$subtype", $vars, $bypass, $debug);
	}
	if (empty($contents)) {
		$contents = elgg_view("$entity_type/default", $vars, $bypass, $debug);
	}

Entities are loaded twice because $contents are not overriden when working with $jsonexport variable.

comment:2 Changed 13 months ago by sembrestels

  • Severity changed from minor to major

I set a bigger severity because it blocks some ajax applications.

comment:3 Changed 13 months ago by sembrestels

  • Owner set to sembrestels
  • Status changed from new to assigned

Entities are loaded twice because $type/$subtype view do not return anything in json viewtype. This can be solved if view returns something (true).

https://github.com/Elgg/Elgg/pull/213

comment:4 Changed 13 months ago by sembrestels

  • Cc sembrestels added

comment:5 Changed 12 months ago by ewinslow

  • Milestone changed from Needs Review to Elgg 1.8.x

comment:6 Changed 11 months ago by cash

  • Milestone changed from Elgg 1.8.x to Elgg 1.8.7

comment:7 Changed 11 months ago by Sem

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixes #4504. Entity duplicates in json views.

Changeset: 0445dd4543ba5dbe7cbb9880a18c70194fcac6ba

comment:8 Changed 11 months ago by Cash Costello

Merge pull request #213 from sembrestels/json-lists

Fixes #4504. Entity duplicates in json views.

Changeset: e3c88cba477760a812a44247f604534cb8244a80

comment:9 Changed 11 months ago by Sem

Fixes #4504. Entity duplicates in json views.

Changeset: 8ec596b8a5ffad878d830342b5f0212ad892fbeb

comment:10 Changed 11 months ago by Cash Costello

Refs #4504 made it easier to detect any problems caused by hack for json duplicate issue

Changeset: 1d9613b682ad331d2de3b1a838a26dd36c821490

comment:11 Changed 11 months ago by cash

  • Milestone changed from Elgg 1.8.7 to Elgg 1.9.0
  • Resolution fixed deleted
  • Status changed from closed to reopened

Pulled this in for 1.8. For 1.9, I'd like to change the checks in elgg_view_entity() to go by existence of the view rather then checking content. Then in a future version fix the json issue completely.

comment:12 Changed 11 months ago by Sem

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixes #4504. Entity duplicates in json views.

Changeset: 8ec596b8a5ffad878d830342b5f0212ad892fbeb

comment:13 Changed 11 months ago by Cash Costello

Fixes #4504 depending on existence of a view rather than content returned

Changeset: 36ff8bef39b9d6f98451f5d90311d13354114b82

Note: See TracTickets for help on using tickets.