public function testReindexOneNotInConfig() { $esi = new ElasticSearchIndexer([]); $entity = $this->makeEntityMock(); $entity->shouldReceive('addToIndex')->once(); $esi->reindexOne($entity); }
public function detachAll(ElasticSearchIndexer $searchIndexer, $id) { $parent = $this->findParentEntity($id); $this->checkPermission(static::class . '@detachAll', ['model' => $parent]); $reindexItems = $searchIndexer->getAllItemsFromRelations($parent, [$this->relationName]); $this->getRelation($parent)->detach(); // Reindex parent entity $searchIndexer->reindexOne($parent, []); // Reindex all detached entities $searchIndexer->reindexMany($reindexItems, []); return $this->getResponse()->noContent(); }
/** * Patch an entity. * * @param string $id * @param Request $request * @return ApiResponse */ public function patchOne(Request $request, ElasticSearchIndexer $searchIndexer, $id) { $this->checkEntityIdMatchesRoute($request, $id, $this->getModel(), false); $model = $this->findOrFailEntity($id); $requestEntity = $request->json()->all(); $this->validateRequest($requestEntity, $this->getValidationRules($id, $requestEntity), $model); $this->fillModel($model, $request->json()->all()); $this->checkPermission(static::class . '@patchOne', ['model' => $model]); $model->save(); $searchIndexer->reindexOne($model); return $this->getResponse()->noContent(); }
/** * Patch many entites. * * @param string $id * @param Request $request * @return ApiResponse */ public function patchMany(Request $request, ElasticSearchIndexer $searchIndexer, $id) { $requestCollection = $request->json()->all(); $this->validateRequestCollection($requestCollection, $this->getChildModel(), true); $parent = $this->findParentEntity($id); $existingModels = $this->findOrFailChildrenCollection($requestCollection, $parent); $childModels = $this->fillModels($this->getChildModel(), $existingModels, $requestCollection); $this->checkPermission(static::class . '@patchMany', ['model' => $parent, 'children' => $childModels]); $this->getRelation($parent)->saveMany($childModels); // Parent should be reindexed itself $searchIndexer->reindexOne($parent, []); // We need to reindex all items with relations $searchIndexer->reindexMany($childModels); return $this->getResponse()->noContent(); }