Initialise.

@param Entity\Entity $entity
180774
public function initialize(Entity\Entity $entity)
    {
        $this->setupContenttype($entity);
        $this->setupContainer($entity);
    }
253508
public function apply(Builder $builder, Entity $entity): void
    {
        $eagerLoads = $builder->getEagerLoads();

        // If there is any eagerload matching the eav key, we will replace it with
        // all the registered properties for the entity. We'll simulate as if the
        // user has manually added all of these withs in purpose when querying.
        if (array_key_exists('eav', $eagerLoads)) {
            $eagerLoads = array_merge($eagerLoads, $entity->getEntityAttributeRelations());

            $builder->setEagerLoads(array_except($eagerLoads, 'eav'));
        }
    }
1312742
protected function updateField(Entity $entity, $field) {
		if ($entity->dirty($field)) {
			return;
		}

		$entity->set($field, $this->getUserId());
	}
1143355
public function moveBefore($entity)
    {
        if ($this->parent_id == $entity->parent_id) {
            $this->position = $entity->position - 1;
            $this->save();
        } else {
            $this->moveTo($entity->position - 1, $entity->parent_id);
        }
    }
571090
public function init($request)
    {
        $oGenerator = oxNew(\OxidEsales\Eshop\Core\DbMetaDataHandler::class);
        $oGenerator->updateViews();
    }
932934
public function setupContenttype(Entity\Entity $entity)
    {
        $contentType = $entity->getContenttype();
        if (is_string($contentType)) {
            $contentTypeData = $this->app['storage']->getContenttype($contentType);
            if ($contentTypeData instanceof ContentType) {
                $contentTypeObject = $contentTypeData;
            } else {
                $contentTypeObject = new ContentType($contentType, $contentTypeData);
            }
            $entity->contenttype = $contentTypeObject;
        }
    }
969369
public function destroy(Entity $entity)
    {
        if ($entity->isExists()) {

            // enable logical delete ?
            if ($entity->hasAttribute('active')) {
                $attributes = [];
                $attributes['active'] = 0;
                if ($entity->hasAttribute('deleted_at')) $attributes['deleted_at'] = time();
                $this->update($attributes, $entity->getPrimaryValue());
            } else {
                $this->delete($entity->getPrimaryValue());
            }
        }
    }
639545
protected function _insertParent($entity) {
		extract($this->_config);
		$parent = $this->_getById($entity->$parent);
		if ($parent) {
			$r = $parent->$right;
			$this->_update($r, '+', 2, $this->_scope($entity));
			$entity->set([
				$left => $r,
				$right => $r + 1
			]);
		}
	}
397904
public function update(EntityInterface $entity): void
    {
        $uri = $this->getEntityEndpointUri($entity->id());
        $response = $this->getClient()->put(
            $uri,
            $this->getEntitySerializer()->serialize($entity, 'json')
        );
        $this->getEntitySerializer()->setPropertiesFromResponse($response, $entity);
    }
879340
public function stashEntity($entity)
    {
        $className = $this->getClassName($entity);
        $entityId  = $this->getEntityId($entity);

        if (!isset($this->stashedEntities[$className])) {
            $this->stashedEntities[$className] = [];
        }

        $this->stashedEntities[$className][$entityId] = $entity;
    }
1349436
public function saveEntity($entity)
    {
        if (!$this->entityManager->contains($entity)) {
            $this->entityManager->persist($entity);
        }

        $this->entityManager->flush();
        return true;
    }
1287990
public function save(EntityInterface $entity)
    {
        $entity = $this->beforeSave($entity);

        $this->getEntityManager()->persist($entity);
        $this->getEntityManager()->flush($entity);

        $this->afterSave($entity);
    }
279742
public function associate($entity)
    {
        $this->parent->setEntityAttribute($this->foreignKey, $entity->getEntityAttribute($this->otherKey));
    }
478894
protected function deleteEntity($entity)
    {
        $this->checkEntityType($entity);

        $delete = new Delete($this->aggregate($entity), $this->newQueryBuilder());

        $delete->execute();
    }
1143165
public function handle(Entity $entity): void
    {
        $this->trash = $entity->getEntityAttributeValueTrash();

        // Wrap the whole process inside database transaction
        $connection = $entity->getConnection();
        $connection->beginTransaction();

        try {
            foreach ($entity->getEntityAttributes() as $attribute) {
                if ($entity->relationLoaded($relation = $attribute->getAttribute('slug'))) {
                    $relationValue = $entity->getRelationValue($relation);

                    if ($relationValue instanceof ValueCollection) {
                        foreach ($relationValue as $value) {
                            // Set attribute value's entity_id since it's always null,
                            // because when RelationBuilder::build is called very early
                            $value->setAttribute('entity_id', $entity->getKey());
                            $this->saveOrTrashValue($value);
                        }
                    } elseif (! is_null($relationValue)) {
                        // Set attribute value's entity_id since it's always null,
                        // because when RelationBuilder::build is called very early
                        $relationValue->setAttribute('entity_id', $entity->getKey());
                        $this->saveOrTrashValue($relationValue);
                    }
                }
            }

            if ($this->trash->count()) {
                // Fetch the first item's class to know the model used for deletion
                $class = get_class($this->trash->first());

                // Let's batch delete all the values based on their ids
                $class::whereIn('id', $this->trash->pluck('id'))->delete();

                // Now, empty the trash
                $this->trash = collect([]);
            }
        } catch (Exception $e) {
            // Rollback transaction on failure
            $connection->rollBack();

            throw $e;
        }

        // Commit transaction on success
        $connection->commit();
    }
605952
public function processEntityMigration($entity)
    {
        if ($entity) {
            $reflection = ClassUtils::newReflectionObject($entity);
            if ($this->hasEncryptionEnabled($reflection) && !$entity->isEncrypted()) {
                $encryptionEnabledFields = $this->getEncryptionEnabledFields($reflection);

                // Normalize the field
                foreach ($encryptionEnabledFields as $field) {
                    $fieldNormalizer = $this->getFieldNormalizer($field, $reflection);
                    $value = $this->getFieldValue($entity, $field);
                    $processedValue = $fieldNormalizer->normalize($value);
                    $this->setFieldValue($entity, $field, $processedValue);
                }

                $entity->setMigrated(true);
            }
        }
    }
258211
private function detachAndPersist($entity)
    {
        $this->em->detach($entity);
        $this->em->persist($entity);
    }