mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
[Tags performance] Improve event view
This commit is contained in:
parent
453fb3f67b
commit
aceb67dd69
@ -723,6 +723,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
|
|||||||
$condition = '';
|
$condition = '';
|
||||||
$group_conditions = array();
|
$group_conditions = array();
|
||||||
|
|
||||||
|
$without_tags = array();
|
||||||
$has_secondary = enterprise_hook('agents_is_using_secondary_groups');
|
$has_secondary = enterprise_hook('agents_is_using_secondary_groups');
|
||||||
// The acltags array contains the groups with the acl propagation applied
|
// The acltags array contains the groups with the acl propagation applied
|
||||||
// after the changes done into the 'tags_get_user_groups_and_tags' function.
|
// after the changes done into the 'tags_get_user_groups_and_tags' function.
|
||||||
@ -736,13 +737,21 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
|
|||||||
$agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join);
|
$agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join);
|
||||||
}
|
}
|
||||||
$group_conditions[] = $agent_condition;
|
$group_conditions[] = $agent_condition;
|
||||||
|
} else {
|
||||||
|
$without_tags[] = $group_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($group_conditions)) {
|
if (!empty($group_conditions)) {
|
||||||
$condition = implode(' OR ', $group_conditions);
|
$condition = implode(' OR ', $group_conditions);
|
||||||
}
|
}
|
||||||
|
if (!empty($without_tags)) {
|
||||||
|
if (!empty($condition)) {
|
||||||
|
$condition .= ' OR ';
|
||||||
|
}
|
||||||
|
$in_group = implode(",",$without_tags);
|
||||||
|
$condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))',$in_group,$in_group);
|
||||||
|
}
|
||||||
$condition = !empty($condition) ? "($condition)" : '';
|
$condition = !empty($condition) ? "($condition)" : '';
|
||||||
|
|
||||||
return $condition;
|
return $condition;
|
||||||
@ -825,101 +834,49 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group
|
|||||||
// Get all tags of the system
|
// Get all tags of the system
|
||||||
$all_tags = tags_get_all_tags(false);
|
$all_tags = tags_get_all_tags(false);
|
||||||
|
|
||||||
// Juanma (08/05/2014) Fix : Will have all groups retrieved (also propagated ones)
|
$without_tags = array();
|
||||||
$_groups_not_in = '';
|
|
||||||
|
|
||||||
foreach ($acltags as $group_id => $group_tags) {
|
foreach ($acltags as $group_id => $group_tags) {
|
||||||
|
// NO check if there is not tag associated with groups
|
||||||
|
if (empty($group_tags)) {
|
||||||
|
$without_tags []= $group_id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Group condition (The module belongs to an agent of the group X)
|
// Group condition (The module belongs to an agent of the group X)
|
||||||
$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
|
//$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));
|
||||||
//$_groups_not_in .= implode(',', array_values(groups_get_id_recursive($group_id))) . ',';
|
$group_condition = "(id_grupo = $group_id OR id_group = $group_id)";
|
||||||
|
|
||||||
// Tags condition (The module has at least one of the restricted tags)
|
// Tags condition (The module has at least one of the restricted tags)
|
||||||
$tags_condition = '';
|
$tags_condition = '';
|
||||||
if (empty($group_tags)) {
|
$tags_condition_array = array();
|
||||||
// FIXME: Not properly way to increse performance
|
|
||||||
if(enterprise_hook('agents_is_using_secondary_groups')){
|
|
||||||
$tags_condition = "id_grupo = ".$group_id . " OR id_group = " . $group_id;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$tags_condition = "id_grupo = ".$group_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!is_array($group_tags)) {
|
|
||||||
$group_tags = explode(',', $group_tags);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($group_tags as $tag) {
|
foreach ($group_tags as $tag) {
|
||||||
// If the tag ID doesnt exist, ignore
|
// If the tag ID doesnt exist, ignore
|
||||||
if (!isset($all_tags[$tag])) {
|
if (!isset($all_tags[$tag])) continue;
|
||||||
continue;
|
|
||||||
|
$tags_condition_array[] = $force_equal
|
||||||
|
? sprintf('tags = "%s"',io_safe_input($all_tags[$tag]))
|
||||||
|
: "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tags_condition != '') {
|
// If there is not tag currently in Pandora, block the group info
|
||||||
$tags_condition .= " OR \n";
|
if (empty($tags_condition_array)) {
|
||||||
|
$tags_condition_array[] = "1=0";
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ // Add as condition all the posibilities of the serialized tags
|
$tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")";
|
||||||
//~ $tags_condition .= sprintf('tags LIKE "%s,%%"',io_safe_input($all_tags[$tag]));
|
$condition[] = "($tags_condition)\n";
|
||||||
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s,%%"',io_safe_input($all_tags[$tag]));
|
}
|
||||||
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s"',io_safe_input($all_tags[$tag]));
|
if (empty($condition)) {
|
||||||
//~ $tags_condition .= sprintf(' OR tags LIKE "%s %%"',io_safe_input($all_tags[$tag]));
|
return " 1=1 ";
|
||||||
//~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s %%"',io_safe_input($all_tags[$tag]));
|
}
|
||||||
|
$condition = implode(' OR ', $condition);
|
||||||
|
|
||||||
if ($force_group_and_tag) {
|
if (!empty($without_tags)) {
|
||||||
if (!empty($all_tags[$tag])) {
|
|
||||||
if ($force_equal) {
|
|
||||||
$tags_condition .= sprintf('(tags = "%s"',io_safe_input($all_tags[$tag]));
|
|
||||||
} else {
|
|
||||||
$tags_condition .= "(tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
|
|
||||||
}
|
|
||||||
$childrens = groups_get_childrens($group_id, null, true);
|
|
||||||
|
|
||||||
if (empty($childrens)) {
|
|
||||||
$tags_condition .= sprintf(' AND id_grupo = %d )', $group_id);
|
|
||||||
} else {
|
|
||||||
$childrens_ids[] = $group_id;
|
|
||||||
foreach ($childrens as $child) {
|
|
||||||
$childrens_ids[] = (int)$child['id_grupo'];
|
|
||||||
}
|
|
||||||
$ids_str = implode(',', $childrens_ids);
|
|
||||||
|
|
||||||
$tags_condition .= sprintf(' AND id_grupo IN (%s) )', $ids_str);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$tags_condition .= "id_grupo = ".$group_id;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($force_equal) {
|
|
||||||
$tags_condition .= sprintf('tags = "%s"',io_safe_input($all_tags[$tag]));
|
|
||||||
} else {
|
|
||||||
$tags_condition .= "tags LIKE '%".io_safe_input($all_tags[$tag])."%'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is not tag condition ignore
|
|
||||||
if (empty($tags_condition)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($condition != '') {
|
|
||||||
$condition .= ' OR ';
|
$condition .= ' OR ';
|
||||||
|
$in_group = implode(",",$without_tags);
|
||||||
|
$condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition .= "($tags_condition)\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Commented because ACLs propagation don't work
|
|
||||||
/*
|
|
||||||
if (!empty($condition)) {
|
|
||||||
// Juanma (08/05/2014) Fix : Also add events of other groups (taking care of propagate ACLs func!)
|
|
||||||
if (!empty($_groups_not_in))
|
|
||||||
$condition = sprintf("\n((%s) OR id_grupo NOT IN (%s))", $condition, rtrim($_groups_not_in, ','));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return $condition;
|
return $condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2413,7 +2370,7 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric
|
|||||||
|
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ($acls as $acl) {
|
foreach ($acls as $acl) {
|
||||||
$return[$acl["id_grupo"]] = $acl["tags"][get_acl_column($access)];
|
$return[$acl["id_grupo"]] = implode(",",$acl["tags"][get_acl_column($access)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -208,21 +208,8 @@ function groups_combine_acl($acl_group_a, $acl_group_b){
|
|||||||
"tags" => 1,
|
"tags" => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($acl_group_a['tags']) users_get_explode_tags($acl_group_a);
|
|
||||||
if ($acl_group_b['tags']) users_get_explode_tags($acl_group_b);
|
|
||||||
|
|
||||||
if (is_array($acl_group_a['tags']) && is_array($acl_group_b['tags'])) {
|
|
||||||
foreach ($acl_group_a['tags'] as $key => $value) {
|
foreach ($acl_group_a['tags'] as $key => $value) {
|
||||||
$acl_group_b['tags'][$key] = implode(
|
$acl_group_b['tags'][$key] = array_merge($value, $acl_group_b['tags'][$key]);
|
||||||
',',
|
|
||||||
array_merge(
|
|
||||||
$value,
|
|
||||||
$acl_group_b['tags'][$key]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (is_array($acl_group_a['tags'])) {
|
|
||||||
$acl_group_b['tags'] = $acl_group_a['tags'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($acl_list as $acl => $aux) {
|
foreach ($acl_list as $acl => $aux) {
|
||||||
@ -289,6 +276,8 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup
|
|||||||
|
|
||||||
foreach ($raw_forest as $g) {
|
foreach ($raw_forest as $g) {
|
||||||
// XXX, following code must be remade (TAG)
|
// XXX, following code must be remade (TAG)
|
||||||
|
users_get_explode_tags($g);
|
||||||
|
|
||||||
if (!isset($forest_acl[$g["id_grupo"]] )) {
|
if (!isset($forest_acl[$g["id_grupo"]] )) {
|
||||||
$forest_acl[$g["id_grupo"]] = $g;
|
$forest_acl[$g["id_grupo"]] = $g;
|
||||||
}
|
}
|
||||||
@ -1073,8 +1062,16 @@ function users_get_strict_mode_groups($id_user, $return_group_all) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function users_get_explode_tags(&$group) {
|
function users_get_explode_tags(&$group) {
|
||||||
if (is_array($group['tags'])) return;
|
|
||||||
|
|
||||||
|
if (empty($group['tags'])) {
|
||||||
|
$group['tags'] = array();
|
||||||
|
$group['tags']['agent_view'] = array();
|
||||||
|
$group['tags']['agent_edit'] = array();
|
||||||
|
$group['tags']['agent_disable'] = array();
|
||||||
|
$group['tags']['event_view'] = array();
|
||||||
|
$group['tags']['event_edit'] = array();
|
||||||
|
$group['tags']['event_management'] = array();
|
||||||
|
} else {
|
||||||
$aux = explode(',', $group['tags']);
|
$aux = explode(',', $group['tags']);
|
||||||
$group['tags'] = array();
|
$group['tags'] = array();
|
||||||
$group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array();
|
$group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array();
|
||||||
@ -1085,4 +1082,6 @@ function users_get_explode_tags(&$group) {
|
|||||||
$group['tags']['event_management'] = ($group['event_management']) ? $aux : array();
|
$group['tags']['event_management'] = ($group['event_management']) ? $aux : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user