Page MenuHomePhabricator

Replace EntityFactory::newEmpty() with ChangeOpDeserializer::createEntity( $changeRequest )
Closed, ResolvedPublic


Some kinds of entities (e.g. Lexemes) cannot be "empty" - in other words, they have required constructor parameters.

In order to construct such entities from the data provided by a client (e.g. in a call to wbeditentity), we need code that can construct an Entity of a given type based on constructor parameters encoded in a JSON structure.

This is conceptually very similar to what ChangeOpDeserializer already does for modifications of entities (by constructing the respective ChangeOps from the a JSON structure provided by the client in an API call). The same should now be done for constructing an entity.

Note: constructor arguments will need to have the same validation applied that would be applied by ChangeOps for the respective fields. The ChangeOpDeserializer should already have access to any services required for this, since it is a factory for the ChangeOps that would perform the check.

Note: EntitySavingHelper will need to be changed quite a bit so it can use ChangeOpDeserializer::createEntity() instead of EntityFactory::newEmpty(). Once this is done, the EntityFactory class can be removed.

Note: Most API modules that use EntitySavingHelper do not get sufficient information from the client to construct a non-empty entity. Automatic create-on-edit for "virtual" entities only works for entity types that do not have any required fields (other than the ID).

See for rationale and discussion