public function upsert(array $data, array $where) { $entityClass = $this->entity(); $entity = new $entityClass($data); $result = $this->insert($entity); // Unique constraint produces a validation error if ($result === false && $entity->hasErrors()) { $dataUpdate = array_diff_key($data, $where); $existingEntity = $this->first($where); if (!$existingEntity) { return $entity; } $existingEntity->data($dataUpdate); $entity = $existingEntity; $result = $this->update($entity); } return $entity; }
public function hookUpdateSearchIndex(\Spot\Mapper $mapper) { $result = $mapper->upsert('Entity_Event_Search', array('event_id' => $this->id, 'body' => $this->title . ' ' . $this->description), array('event_id' => $this->id)); }