public function delete(EntityInterface $entity, $options = [])
{
if (!$entity->has('id')) {
$msg = 'Deleting requires an "id" value.';
throw new InvalidArgumentException($msg);
}
$options += ['checkRules' => true];
$options = new ArrayObject($options);
$event = $this->dispatchEvent('Model.beforeDelete', ['entity' => $entity, 'options' => $options]);
if ($event->isStopped()) {
return $event->result;
}
if (!$this->checkRules($entity, RulesChecker::DELETE, $options)) {
return false;
}
$data = $entity->toArray();
unset($data['id']);
$doc = new ElasticaDocument($entity->id, $data);
$type = $this->connection()->getIndex()->getType($this->name());
$result = $type->deleteDocument($doc);
$this->dispatchEvent('Model.afterDelete', ['entity' => $entity, 'options' => $options]);
return $result->isOk();
}