Commit da16fbe8 authored by Quentin Ribac's avatar Quentin Ribac
Browse files

FIX #17703 TIME 0:15 calling removeOrphanedEntities in EntityModelAbstract,...

FIX #17703 TIME 0:15 calling removeOrphanedEntities in EntityModelAbstract, GroupController, AdministrationController
parent ec3dc757
......@@ -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,21 @@ 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'];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment