Add soft delete to the where clause if the entity supports it

@param ApiInterface $entity
@param string $alias

@return void
770681
public function addSoftDelete(ApiInterface $entity, $alias) {
        $reflectionClass = new \ReflectionClass(SoftDelete::class);
        $reflectionMethod = $reflectionClass->getMethod("getOptions");
        $reflectionMethod->setAccessible(true);

        /** @var SoftDelete[] $softDeleteBehaviors */
        $softDeleteBehaviors = $entity->getAllBehaviorsByClassName(SoftDelete::class);

        foreach($softDeleteBehaviors as $softDeleteBehavior) {
            $options = $reflectionMethod->invoke($softDeleteBehavior);
            $sql = $alias . '.' . $options["field"] . '!=?0';
            $params = [$options["value"]];
            $this->getCriteriaHelper()->andWhere($sql, $params);
        }
    }
644681
public function beforeEntityDelete($entity, &$idx)
    {
        $this->undeleteReasons = [];

        $entityMetadata = $this->em->getClassMetadata(get_class($entity));

        $associations = $entityMetadata->getAssociationMappings();

        foreach ($associations as $association) {
            if (in_array('remove', $association['cascade'])) {
                continue; // Skip of cascading enabled
            }

            if (!in_array($association['type'], [ClassMetadata::ONE_TO_MANY])) {
                continue; // Handling only _TO_MANY relations
            }

            $propertyAccessor = new PropertyAccessor();
            $associationData = $propertyAccessor->getValue($entity, $association['fieldName']);

            if ($associationData instanceof Collection) {
                if ($associationData->count() > 0) {
                    $this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
                }
            } elseif ($associationData !== null) {
                $this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
            }
        }

        return $this->undeleteReasons;
    }
602523
public boolean deleteEntity(Entity entity) {
        String entityName = entity.getName();
        checkEntityIsEmpty(entityName);
        QueryPart<Entity> queryPart = new Query<Entity>("entities")
                .path(entityName, true);
        return httpClientManager.updateMetaData(queryPart, delete());
    }
590379
public function afterSave(Event $event, EntityInterface $entity)
    {
        $property = $this->versionAssociation()->getProperty();
        $entity->unsetProperty($property);
    }
803647
public function forceDelete(Entity $entity = null, Repository $repository = null)
    {
        $entity = $this->getEntityIfEmpty($entity);
        $repository = $entity->getRepositoryIfEmpty($repository);

        $this->trigger(['saving', 'deleting']);

        $delete = $repository->delete($this, $entity);

        $this->trigger(['deleted', 'saved']);

        return $delete;
    }
625646
private function addJoin(ApiInterface $entity, $alias, $forceFind) {
        if(in_array($alias, $entity->getParentRelationships())) {
            $referencedModel = $entity->addJoin($this->getCriteriaHelper(), $alias);
            return new $referencedModel();
        } else {
            if($forceFind) {
                throw new Exception('Could Not Find Part in current entity: ' . $alias, 400);
            }
            return false;
        }
    }
706727
public function afterDelete(Event $event, Entity $entity, ArrayObject $options)
    {
        if ($this->getCacheName()) {
            Cache::clear(false, $this->getCacheName());
        }
    }
1246023
public function remove(EntityInterface $entity)
    {
        $reflection = $this->getEntityClassReflection();
        
        if ($reflection->isInstance($entity)) {
            
            // trigger event for entity and dispatcher on before remove
            $this->dispatchEvent(ORMEvents::beforeRemove, new EntityLifecycleEvent($this, $entity));
            
            // needed variables
            $metadata = $this->getEntityMetadata();
            $remover = $this->createRemover();
            $identifier = $this->getEntityIdentifier();
            $connection = $this->getConnection();
            $propertyIdentifier = $metadata->getName($identifier, Metadata::CAMILIZED);
            
            // refinement of the request
            $remover->addConditions($identifier, $entity->getByProperty($propertyIdentifier));
            $remover->setLimit(1)->setOffset(0);
            
            // open transaction and try to execute sql
            $connection->transaction(function () use ($connection, $remover) {
                $connection->execute($remover->toSQL());
            });
            
            // reset identifier for removed entity
            $entity->setByProperty($propertyIdentifier, null);
            
            // trigger event for entity and dispatcher on after remove and all actions
            $this->dispatchEvent(ORMEvents::afterRemove, new EntityLifecycleEvent($this, $entity));
            
            return $this;
        }
        
        throw new NotSupportedException(sprintf('Unable to remove entity! Actual entity "%s" expected entity "%s"',
            get_class($entity), $this->getEntityName()));
    }
659855
public function delete($entity)
    {
        $eloquentModel = $this->getEloquentModel($entity, true);

        $this->updateRelations($eloquentModel, 'delete');

        $eloquentModel->delete();
    }
632851
public function delete(EntityInterface $entity)
    {
        $this->entity = $entity;
        $primaryKey = $this->getDescriptor()->getPrimaryKey()->getName();
        $table = $this->getDescriptor()->getTableName();
        $sql = Sql::createSql($this->getAdapter());

        $this->triggerBeforeDelete($entity);

        $this->setUpdateCriteria(
            $sql->delete($table),
            $primaryKey,
            $table
        )->execute();

        $this->triggerAfterDelete($entity);
        $this->removeEntity($entity);
        return $this;
    }
642714
public function delete($id)
    {
        $this->beforeDelete($id);
        $this->entity->delete($id);
        $this->afterDelete($id);
    }
1079435
public function deleteEntity(SearchableEntityInterface $entity)
    {
        foreach ($this->locales as $locale) {
            $uid       = $this->getDocUid($entity, $locale);
            $indexType = $this->indexType;
            $this->searchProvider->deleteDocument($this->indexName, $indexType, $uid);
        }
    }
175792
protected function updateRow(AbstractEntity $entity)
    {
        $values = $entity->getDbValues();

        $query = $this->getSqlObject()
            ->update()
            ->set($values)
            ->where($this->getPrimaryKeyWheres($entity));

        $this->execute($query);
    }
791874
public function delete($entity)
    {
        $identifier   = $this->getIdentifier($entity);
        $affectedRows = $this->connection->delete($this->tableName, $identifier);

        if ($affectedRows == 0) {
            throw new OrmException("Entity not found.");
        }
    }
739238
public function cascadeDelete(EntityInterface $entity, array $options = [])
    {
        if (!$this->getDependent()) {
            return true;
        }
        $foreignKey = (array)$this->getForeignKey();
        $bindingKey = (array)$this->getBindingKey();
        $conditions = [];

        if (!empty($bindingKey)) {
            $conditions = array_combine($foreignKey, $entity->extract($bindingKey));
        }

        $table = $this->junction();
        $hasMany = $this->getSource()->getAssociation($table->getAlias());
        if ($this->_cascadeCallbacks) {
            foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) {
                $table->delete($related, $options);
            }

            return true;
        }

        $conditions = array_merge($conditions, $hasMany->getConditions());

        $table->deleteAll($conditions);

        return true;
    }
151110
public function trash(EntityInterface $entity, array $options = [])
    {
        $primaryKey = (array)$this->_table->getPrimaryKey();

        foreach ($primaryKey as $field) {
            if (!$entity->has($field)) {
                throw new RuntimeException();
            }
        }

        foreach ($this->_table->associations() as $association) {
            if ($this->_isRecursable($association, $this->_table)) {
                $association->cascadeDelete($entity, ['_primary' => false] + $options);
            }
        }

        $data = [$this->getTrashField(false) => new Time()];
        $entity->set($data, ['guard' => false]);

        if ($this->_table->save($entity, $options)) {
            return true;
        }

        return false;
    }
1199281
public function remove(AbstractEntity $entity)
    {
        if ($this->prepareEntityForRemove($entity)) {
            $this->getRepository()->remove($entity);
        }
    }