|
1 | 1 | # Insert explained |
2 | 2 |
|
3 | | -- Converter |
4 | | -- ElasticSearch point of view |
5 | | -TODO |
| 3 | +## \Spameri\Elastic\Model\Insert\PrepareEntityArray |
| 4 | +- This class is responsible for converting ElasticSearch entity to array that can be then saved to ElasticSearch. |
| 5 | +- Configuring is done by implementing [interfaces](04_data_interfaces.md), no need for annotations or neon. |
| 6 | + |
| 7 | +### ::prepare(\Spameri\Elastic\Entity\IElasticEntity $entity) |
| 8 | +- This method is here for last before convert modifications. |
| 9 | +- If implemented `\Spameri\Elastic\Entity\ITrackedEntity` interface for entity tracking (and properties specified), |
| 10 | +this method adds timestamp and user who edited/created entity. |
| 11 | +- Then calling iterateVariables to prepare rest of entity array. |
| 12 | + |
| 13 | +### ::iterateVariables(array $variables) |
| 14 | +This method accepts entity variables and based on their type performs converting to array to ready entity for insert. |
| 15 | +There are 9 types of property handled: |
| 16 | +1. **\Spameri\Elastic\Entity\IElasticEntity** in this case service locator comes to play and locates service for related |
| 17 | +entity and saves connected entity. And prepares related entity's id to property. Because to ElasticSearch goes only |
| 18 | +string id. |
| 19 | + |
| 20 | +2. **\Spameri\Elastic\Entity\IEntity** this is structural entity and is saved directly to parent entity. Its properties |
| 21 | +are iterated with `::iterateVariables($property->entityVariables())` |
| 22 | + |
| 23 | +3. **\Spameri\Elastic\Entity\IValue** raw value in object, directly converted to array. |
| 24 | + |
| 25 | +4. **\Spameri\Elastic\Entity\IEntityCollection** Collection of structural class **IEntity**, iterate and act as step 2. |
| 26 | + |
| 27 | +5. **\Spameri\Elastic\Entity\IElasticEntityCollection** Collection of ElasticSearch entities **IElasticEntity**, |
| 28 | +iterate and act as step 1. |
| 29 | + |
| 30 | +6. **\Spameri\Elastic\Entity\IValueCollection** Collection of **IValue**, iterate and act as step 3. |
| 31 | + |
| 32 | +7. Scalar values **string**, **int**, **bool** or **NULL**, no action just pass to array. |
| 33 | + |
| 34 | +8. **\Spameri\Elastic\Entity\DateTimeInterface** Date interface with specified format by this library so ElasticSearch |
| 35 | +can save it without problems. |
| 36 | +- **\Spameri\Elastic\Entity\Property\Date** for `Y-m-d` format |
| 37 | +- **\Spameri\Elastic\Entity\Property\DateTime** for `Y-m-d\TH:i:s` format |
| 38 | + |
| 39 | +9. **\DateTime** All other Dates are converted to `Y-m-d\TH:i:s` |
| 40 | + |
| 41 | +10. Exception thrown property is none of above. |
0 commit comments