public function delete()
{
if (!($id = $this->_id)) {
throw new Exception("The document cannot be deleted because it doesn't exist");
}
$disableEvents = self::$_disableEvents;
if (!$disableEvents) {
if (false === $this->fireEventCancel("beforeDelete")) {
return false;
}
}
if (true === $this->_skipped) {
return true;
}
$connection = $this->getConnection();
$source = $this->getSource();
if (empty($source)) {
throw new Exception("Method getSource() returns empty string");
}
/**
* Get the Collection
*
* @var AdapterCollection $collection
*/
$collection = $connection->selectCollection($source);
if (is_object($id)) {
$mongoId = $id;
} else {
if ($this->_modelsManager->isUsingImplicitObjectIds($this)) {
$mongoId = new ObjectID($id);
} else {
$mongoId = $id;
}
}
$success = false;
/**
* Remove the instance
*/
$status = $collection->deleteOne(['_id' => $mongoId], ['w' => true]);
if ($status->isAcknowledged()) {
$success = true;
$this->fireEvent("afterDelete");
}
return $success;
}