Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cascading of AND/OR operator in dbiterator #5428

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions ajax/autocompletion.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@
'SELECT DISTINCT' => $_GET['field'],
'FROM' => $table,
'WHERE' => [
$_GET['field'] => ['LIKE', $_GET['term'] . '%'],
'AND' => [
$_GET['field'] => ['<>', $_GET['term']]
]
[$_GET['field'] => ['LIKE', $_GET['term'] . '%']],
[$_GET['field'] => ['<>', $_GET['term']]]
] + $entity,
'ORDER' => $_GET['field']
]);
Expand Down
6 changes: 2 additions & 4 deletions inc/api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ public function initApi() {
'OR' => [
'ipv4_range_start' => null,
[
'AND' => [
'ipv4_range_start' => ['<=', $this->ipnum],
'ipv4_range_end' => ['>=', $this->ipnum]
]
'ipv4_range_start' => ['<=', $this->ipnum],
'ipv4_range_end' => ['>=', $this->ipnum]
]
]
];
Expand Down
4 changes: 2 additions & 2 deletions inc/commondbrelation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1545,8 +1545,8 @@ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBT
}
$WHERE = [
'OR' => [
['AND' => $WHERE],
['AND' => $ORWHERE]
$WHERE,
$ORWHERE
]
];
}
Expand Down
10 changes: 4 additions & 6 deletions inc/computer_softwareversion.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,9 @@ class='submit'>";
'glpi_softwareversions' => 'id',
'glpi_softwarelicenses' => 'softwareversions_id_use',
[
'OR' => [
'AND' => [
'glpi_softwarelicenses.softwareversions_id_use' => 0,
'glpi_softwarelicenses.softwareversions_id_buy' => new \QueryExpression(DBmysql::quoteName('glpi_softwareversions.id')),
]
'AND' => [
'glpi_softwarelicenses.softwareversions_id_use' => 0,
'glpi_softwarelicenses.softwareversions_id_buy' => new \QueryExpression(DBmysql::quoteName('glpi_softwareversions.id')),
]
]
]
Expand Down Expand Up @@ -1040,7 +1038,7 @@ private static function softsByCategory($data, $computers_id, $withtemplate, $ca
'glpi_computers_softwarelicenses.computers_id' => $computers_id,
'OR' => [
'glpi_softwarelicenses.softwareversions_id_use' => $verid,
'AND' => [
[
'glpi_softwarelicenses.softwareversions_id_use' => 0,
'glpi_softwarelicenses.softwareversions_id_buy' => $verid
]
Expand Down
4 changes: 2 additions & 2 deletions inc/dbmysqliterator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public function analyseCrit ($crit, $bool = "AND") {
$ret .= $value->getQuery();
} else {
// No Key case => recurse.
$ret .= "(" . $this->analyseCrit($value, $bool) . ")";
$ret .= "(" . $this->analyseCrit($value) . ")";
}

} else if (($name === "OR") || ($name === "AND")) {
Expand All @@ -503,7 +503,7 @@ public function analyseCrit ($crit, $bool = "AND") {

} else if ($name === "NOT") {
// Uninary logicial operator
$ret .= " NOT (" . $this->analyseCrit($value, "AND") . ")";
$ret .= " NOT (" . $this->analyseCrit($value) . ")";

} else if ($name === "FKEY" || $name === 'ON') {
// Foreign Key condition
Expand Down
12 changes: 6 additions & 6 deletions inc/dbutils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,12 @@ public function getEntitiesRestrictCriteria($table = '', $field = '', $value = '
$crit = ['OR' => [$field => $value + $ancestors]];
} else {
$recur = (empty($table) ? 'is_recursive' : "$table.is_recursive");
$crit = ['OR' => [$field => $value,
'AND' => [$recur => 1,
$field => $ancestors]]];
$crit = [
'OR' => [
$field => $value,
[$recur => 1, $field => $ancestors]
]
];
}
}
}
Expand Down Expand Up @@ -1919,9 +1922,6 @@ public function getDateCriteria($field, $begin, $end) {
$criteria[] = [$field => ['<=', $end_expr]];
}

if (count($criteria)) {
$criteria = ['AND' => $criteria];
}
return $criteria;
}

Expand Down
10 changes: 5 additions & 5 deletions inc/document_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ static function showListForItem(CommonDBTM $item, $withtemplate = 0, $options =
unset($o2where['glpi_documents_items.items_id']);
$criteria['WHERE'] = [
'OR' => [
['AND' => $owhere],
['AND' => $o2where]
$owhere,
$o2where
]
];
}
Expand Down Expand Up @@ -965,7 +965,7 @@ static function getRelationMassiveActionsSpecificities() {
protected static function getTypeItemsQueryParams($items_id, $itemtype, $noent = false, $where = []) {
$commonwhere = ['OR' => [
static::getTable() . '.' . static::$items_id_1 => $items_id,
'AND' => [
[
static::getTable() . '.itemtype' => static::$itemtype_1,
static::getTable() . '.' . static::$items_id_2 => $items_id
]
Expand Down Expand Up @@ -1029,7 +1029,7 @@ protected static function getListForItemParams(CommonDBTM $item, $noent = false)
public static function getDistinctTypesParams($items_id, $extra_where = []) {
$commonwhere = ['OR' => [
static::getTable() . '.' . static::$items_id_1 => $items_id,
'AND' => [
[
static::getTable() . '.itemtype' => static::$itemtype_1,
static::getTable() . '.' . static::$items_id_2 => $items_id
]
Expand All @@ -1038,7 +1038,7 @@ public static function getDistinctTypesParams($items_id, $extra_where = []) {
$params = parent::getDistinctTypesParams($items_id, $extra_where);
$params['WHERE'] = $commonwhere;
if (count($extra_where)) {
$params['WHERE'] += ['AND' => $extra_where];
$params['WHERE'][] = $extra_where;
}

return $params;
Expand Down
2 changes: 1 addition & 1 deletion inc/dropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3047,7 +3047,7 @@ public static function getDropdownConnect($post, $json = true) {
} else {
$where[] = [
'OR' => [
'AND' => [
[
'glpi_computers_items.id' => null
] + $where_used,
"$table.is_global" => 1
Expand Down
2 changes: 1 addition & 1 deletion inc/group.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function getDataItems(array $types, $field, $tree, $user, $start, array &$res) {
$ufield = str_replace('groups', 'users', $field);
$groups_criteria['OR'] = [
$field => $groups_ids,
'AND' => [
[
$field => 0,
$ufield => new QuerySubQuery(
[
Expand Down
6 changes: 2 additions & 4 deletions inc/group_user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,8 @@ static function showForUser(User $user) {
'OR' => [
['entities_id' => $_SESSION['glpiactive_entity']],
[
'AND' => [
'entities_id' => array_merge([0], $_SESSION['glpiactiveentities']),
'is_recursive' => 1
]
'entities_id' => array_merge([0], $_SESSION['glpiactiveentities']),
'is_recursive' => 1
]
]
]
Expand Down
12 changes: 4 additions & 8 deletions inc/item_devices.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,16 +920,12 @@ function getTableGroup(CommonDBTM $item, HTMLTableMain $table, array $options,
'WHERE' => [
'OR' => [
[
'AND' => [
'itemtype' => $this->getType(),
'items_id' => $link['id']
]
'itemtype' => $this->getType(),
'items_id' => $link['id']
],
[
'AND' => [
'itemtype' => $this->getDeviceType(),
'items_id' => $link[$this->getDeviceForeignKey()]
]
'itemtype' => $this->getDeviceType(),
'items_id' => $link[$this->getDeviceForeignKey()]
]
]
],
Expand Down
5 changes: 2 additions & 3 deletions inc/item_ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,8 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if ($_SESSION['glpishow_count_on_tabs']) {
//$nb = self::countForMainItem($item);
$nb = countElementsInTable('glpi_items_tickets',
['AND' => ['tickets_id' => $item->getID() ],
['itemtype' => $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]]
]);
['tickets_id' => $item->getID(),
'itemtype' => $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]]);
}
return self::createTabEntry(_n('Item', 'Items', Session::getPluralNumber()), $nb);
}
Expand Down
8 changes: 4 additions & 4 deletions inc/knowbaseitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ static public function getVisibilityCriteria($forceall = false) {

if (Session::getLoginUserID()) {
$restrict = getEntitiesRestrictCriteria('glpi_groups_knowbaseitems', '', '', true, true);
$where['OR'][] = ['AND' => [
$where['OR'][] = [
'glpi_groups_knowbaseitems.groups_id' => count($_SESSION["glpigroups"])
? $_SESSION["glpigroups"]
: [-1],
'OR' => [
'glpi_groups_knowbaseitems.entities_id' => ['<', '0'],
] + $restrict
]];
];
}
}

Expand All @@ -564,13 +564,13 @@ static public function getVisibilityCriteria($forceall = false) {
&& isset($_SESSION["glpiactiveprofile"]['id']))) {

if (Session::getLoginUserID()) {
$where['OR'][] = ['AND' => [
$where['OR'][] = [
'glpi_knowbaseitems_profiles.profiles_id' => $_SESSION["glpiactiveprofile"]['id'],
'OR' => [
'glpi_knowbaseitems_profiles.entities_id' => ['<', '0'],
getEntitiesRestrictCriteria('glpi_knowbaseitems_profiles', '', '', true, true)
]
]];
];
}
}

Expand Down
2 changes: 1 addition & 1 deletion inc/knowbaseitem_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static function getItems(CommonDBTM $item, $start = 0, $limit = 0, $used = false
}

if (count($where)) {
$options['AND'] = [$id_field => $items_id, 'AND' => $where];
$options['AND'] = [$id_field => $items_id, $where];
} else {
$options['AND'] = [$id_field => $items_id];
}
Expand Down
6 changes: 3 additions & 3 deletions inc/log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ static function convertFiltersValuesToSqlCriteria(array $filters) {
if (isset($filters['affected_fields']) && !empty($filters['affected_fields'])) {
$affected_field_crit = [];
foreach ($filters['affected_fields'] as $index => $affected_field) {
$affected_field_crit[$index] = ['AND' => []];
$affected_field_crit[$index] = [];
foreach (explode(";", $affected_field) as $var) {
if (1 === preg_match('/^(?P<key>.+):(?P<operator>.*):(?P<values>.+)$/', $var, $matches)) {
$key = $matches['key'];
Expand All @@ -1179,9 +1179,9 @@ static function convertFiltersValuesToSqlCriteria(array $filters) {
}

if (!empty($operator)) {
$affected_field_crit[$index]['AND'][$operator][$key] = $values;
$affected_field_crit[$index][$operator][$key] = $values;
} else {
$affected_field_crit[$index]['AND'][$key] = $values;
$affected_field_crit[$index][$key] = $values;
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions inc/migration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,8 @@ public function addRight($name, $rights = ALLSTANDARDRIGHT, $requiredrights = ['
$where = [];
foreach ($requiredrights as $reqright => $reqvalue) {
$where['OR'][] = [
'AND' => [
'name' => $reqright,
new QueryExpression("{$DB->quoteName('rights')} & $reqvalue = $reqvalue")
]
'name' => $reqright,
new QueryExpression("{$DB->quoteName('rights')} & $reqvalue = $reqvalue")
];
}

Expand Down
10 changes: 4 additions & 6 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,9 @@ static function getUnderActiveProfileRestrictCriteria() {
&& (Session::getCurrentInterface() == 'central'
|| in_array($key, self::$helpdesk_rights))) {
$right_subqueries[] = [
'AND' => [
'glpi_profilerights.name' => $key,
'RAW' => [
'(' . DBmysql::quoteName('glpi_profilerights.rights') . ' | ' . DBmysql::quoteValue($val) . ')' => $val
]
'glpi_profilerights.name' => $key,
'RAW' => [
'(' . DBmysql::quoteName('glpi_profilerights.rights') . ' | ' . DBmysql::quoteValue($val) . ')' => $val
]
];
}
Expand All @@ -469,7 +467,7 @@ static function getUnderActiveProfileRestrictCriteria() {
return [
'OR' => [
'glpi_profiles.interface' => 'helpdesk',
'AND' => [$criteria]
$criteria
]
];
}
Expand Down
6 changes: 3 additions & 3 deletions inc/project.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,17 @@ static public function getVisibilityCriteria($forceall = false) {
$teamtable = 'glpi_projectteams';
$where['OR'] = [
'glpi_projects.users_id' => Session::getLoginUserID(),
'AND' => [
[
"$teamtable.itemtype" => 'User',
"$teamtable.items_id" => Session::getLoginUserID()
]
];
if (count($_SESSION['glpigroups'])) {
$where['OR']['glpi_projects.groups_id'] = $_SESSION['glpigroups'];
$where['OR'][] = ['AND' => [
$where['OR'][] = [
"$teamtable.itemtype" => 'Group',
"$teamtable.items_id" => $_SESSION['glpigroups']
]];
];
}

$criteria = [
Expand Down
8 changes: 4 additions & 4 deletions inc/reminder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ static public function getVisibilityCriteria($forceall = false) {
if (count($restrict)) {
$or = $or + $restrict;
}
$where['OR'][] = ['AND' => [
$where['OR'][] = [
'glpi_groups_reminders.groups_id' => count($_SESSION["glpigroups"])
? $_SESSION["glpigroups"]
: [-1],
'OR' => $or
]];
];
}

// Profiles
Expand All @@ -300,10 +300,10 @@ static public function getVisibilityCriteria($forceall = false) {
if (count($restrict)) {
$or = $or + $restrict;
}
$where['OR'][] = ['AND' => [
$where['OR'][] = [
'glpi_profiles_reminders.profiles_id' => $_SESSION["glpiactiveprofile"]['id'],
'OR' => $or
]];
];
}

// Entities
Expand Down
10 changes: 4 additions & 6 deletions inc/rssfeed.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ static public function getVisibilityCriteria($forceall = false) {

if (isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"])) {
$restrict = getEntitiesRestrictCriteria('glpi_groups_rssfeeds', '', '', true);
$orwhere[] = ['AND' => [
$orwhere[] = [
'glpi_groups_rssfeeds.groups_id' => count($_SESSION["glpigroups"])
? $_SESSION["glpigroups"]
: [-1],
'OR' => [
'glpi_groups_rssfeeds.entities_id' => ['<', '0'],
] + $restrict
]];
];
}

// Profiles
Expand All @@ -322,10 +322,8 @@ static public function getVisibilityCriteria($forceall = false) {
];

$orwhere[] = [
'AND' => [
'glpi_profiles_rssfeeds.profiles_id' => $_SESSION["glpiactiveprofile"]['id'],
'OR' => $ors
]
'glpi_profiles_rssfeeds.profiles_id' => $_SESSION["glpiactiveprofile"]['id'],
'OR' => $ors
];
}

Expand Down
2 changes: 1 addition & 1 deletion inc/savedsearch.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ static public function getVisibilityCriteria($forceall = false) {
if (Session::haveRight(self::$rightname, READ)) {
$restrict = [
'OR' => [
'AND' => $restrict,
$restrict,
self::getTable() . '.is_private' => 0
]
];
Expand Down
Loading