get('entityType'); $this->addImportEntityJoin($entity, $relationName, $params); return $this->getEntityManager()->getRepository($entityType)->find($params); } protected function addImportEntityJoin(Entity $entity, string $link, array &$params) { $entityType = $entity->get('entityType'); $param = null; switch ($link) { case 'imported': $param = 'isImported'; break; case 'duplicates': $param = 'isDuplicate'; break; case 'updated': $param = 'isUpdated'; break; default: return; } $params['joins'] = $params['joins'] ?? []; $params['joins'][] = [ 'ImportEntity', 'importEntity', [ 'importEntity.importId' => $entity->id, 'importEntity.entityType' => $entityType, 'importEntity.entityId:' => $entityType . '.id', 'importEntity.' . $param => true, ], ]; } public function countRelated(Entity $entity, string $relationName, array $params = []) : int { $entityType = $entity->get('entityType'); $this->addImportEntityJoin($entity, $relationName, $params); return $this->getEntityManager()->getRepository($entityType)->count($params); } protected function afterRemove(Entity $entity, array $options = []) { if ($entity->get('fileId')) { $attachment = $this->getEntityManager()->getEntity('Attachment', $entity->get('fileId')); if ($attachment) { $this->getEntityManager()->removeEntity($attachment); } } $sql = $this->getEntityManager()->getQuery()->createDeleteQuery('ImportEntity', [ 'whereClause' => [ 'importId' => $entity->id, ] ]); $this->getEntityManager()->getPDO()->query($sql); parent::afterRemove($entity, $options); } }