/** * @param \obo\Entity $entity * @param bool $triggerEvents * @return void * @throws \obo\Exceptions\EntityIsNotInitializedException */ public static function deleteEntity(\obo\Entity $entity, $triggerEvents = true) { if (!$entity->isInitialized()) { throw new \obo\Exceptions\EntityIsNotInitializedException("Cannot delete entity which is not initialized"); } $entity->setDeletingInProgress(); if ($triggerEvents) { \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("beforeDelete", $entity); } if (($propertyNameForSoftDelete = $entity->entityInformation()->propertyNameForSoftDelete) === "") { $entity->dataStorage()->removeEntity($entity); } else { $entity->discardNonPersistedChanges(); $entity->setValueForPropertyWithName(true, $propertyNameForSoftDelete); self::saveEntity($entity, true, false); } $entity->setDeleted(true); if ($triggerEvents) { \obo\Services::serviceWithName(\obo\obo::EVENT_MANAGER)->notifyEventForEntity("afterDelete", $entity); } $entity->setDeletingInProgress(false); }