Skip to content
Snippets Groups Projects
Commit 1a9d7ce9 authored by Quentin Ribac's avatar Quentin Ribac
Browse files

FIX #17703 TIME 3 filtering out orphaned entities in admin panel, entity tree...

FIX #17703 TIME 3 filtering out orphaned entities in admin panel, entity tree in entity admin, group indexing parameters, autocomplete
parent 90a3d737
No related branches found
No related tags found
No related merge requests found
......@@ -59,10 +59,11 @@ class AdministrationController
if (PrivilegeController::hasPrivilege(['privilegeId' => 'manage_entities', 'userId' => $GLOBALS['id']])) {
$entities = EntityModel::get([
'select' => [1],
'select' => ['entity_id', 'parent_entity_id'],
'where' => ['enabled = ?'],
'data' => ['Y']
]);
$entities = EntityModel::removeOrphanedEntities($entities);
$count['entities'] = count($entities);
}
......
......@@ -395,6 +395,7 @@ abstract class EntityModelAbstract
'data' => ['Y'],
'orderBy' => ['e1.parent_entity_id']
]);
$allEntities = EntityModel::removeOrphanedEntities($allEntities);
foreach ($allEntities as $key => $value) {
$allEntities[$key]['serialId'] = $value['id'];
......@@ -494,4 +495,20 @@ abstract class EntityModelAbstract
return EntityModel::getEntityPathByEntityId(['entityId' => $entity['parent_entity_id'], 'path' => $args['path']]);
}
public static function removeOrphanedEntities(array $entities) {
if (!isset($entities[0]['parent_entity_id']) || !isset($entities[0]['entity_id'])) {
return $entities;
}
do {
$entitiesCount = count($entities);
$entitiesIds = array_column($entities, 'entity_id');
$entities = array_values(array_filter($entities, function($entity) use ($entitiesIds) {
return empty($entity['parent_entity_id']) || ($entity['parent_entity_id'] != $entity['entity_id'] && in_array($entity['parent_entity_id'], $entitiesIds));
}));
} while (count($entities) != $entitiesCount);
return $entities;
}
}
......@@ -249,12 +249,13 @@ class GroupController
$allActions = ActionModel::get(['select' => ['id', 'label_action'], 'where' => ['component in (?)'], 'data' => [GroupController::INDEXING_ACTIONS]]);
$allEntities = EntityModel::get([
'select' => ['e1.id', 'e1.entity_id', 'e1.entity_label', 'e2.id as parent_id'],
'select' => ['e1.id', 'e1.entity_id', 'e1.entity_label', 'e1.parent_entity_id', 'e2.id as parent_id'],
'table' => ['entities e1', 'entities e2'],
'left_join' => ['e1.parent_entity_id = e2.entity_id'],
'where' => ['e1.enabled = ?'],
'data' => ['Y']
]);
$allEntities = EntityModel::removeOrphanedEntities($allEntities);
foreach ($allEntities as $key => $value) {
$allEntities[$key]['id'] = $value['id'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment