Skip to content

Conversation

@cconard96
Copy link
Contributor

Remove raw SQL to improve future compatibility.
Requires glpi-project/glpi#14970 for INSERT INTO ... SELECT support.

@cedric-anne cedric-anne self-requested a review June 21, 2023 06:11
@cconard96 cconard96 force-pushed the db/remove_raw_sql branch from cdc5eb5 to e56ffcd Compare June 22, 2023 20:27
'remove_delete_watcher_group_btn' => 1,
'remove_delete_assign_group_btn' => 0,
'remove_delete_assign_supplier_btn' => 1,
'use_filter_assign_group' => 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was 0 on previous code.

Suggested change
'use_filter_assign_group' => 1,
'use_filter_assign_group' => 0,

Comment on lines 210 to 211
$status = CommonITILObject::INCOMING.", ".CommonITILObject::PLANNED.", ".
CommonITILObject::ASSIGNED.", ".CommonITILObject::WAITING;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be converted into an array of values.

Suggested change
$status = CommonITILObject::INCOMING.", ".CommonITILObject::PLANNED.", ".
CommonITILObject::ASSIGNED.", ".CommonITILObject::WAITING;
$status = [
CommonITILObject::INCOMING,
CommonITILObject::PLANNED,
CommonITILObject::ASSIGNED,
CommonITILObject::WAITING,
];

if (!$res = $DB->query($query_users)) {
$res = $DB->insert('glpi_tickets_user', new QuerySubQuery([
'SELECT' => [
new QueryExpression("'' AS " . $DB::quoteName('id')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new QueryExpression("'' AS " . $DB::quoteName('id')),
new QueryExpression($DB::quoteValue('') . " AS " . $DB::quoteName('id')),

if (!$res = $DB->query($query_groups)) {
$res = $DB->insert('glpi_tickets_user', new QuerySubQuery([
'SELECT' => [
new QueryExpression("'' AS " . $DB::quoteName('id')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new QueryExpression("'' AS " . $DB::quoteName('id')),
new QueryExpression($DB::quoteValue('') . " AS " . $DB::quoteName('id')),

if (! $res = $DB->query($query_docs)) {
$res = $DB->insert('glpi_documents_items', new QuerySubQuery([
'SELECT' => [
new QueryExpression("'' AS " . $DB::quoteName('id')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new QueryExpression("'' AS " . $DB::quoteName('id')),
new QueryExpression($DB::quoteValue('') . " AS " . $DB::quoteName('id')),

Comment on lines +91 to +92
getEntitiesRestrictCriteria('glpi_groups', '', $entity, true, true)
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had an issue recently on treeview plugin with this because getEntitiesRestrictCriteria() can return an empty array. See pluginsGLPI/treeview#49.

Suggested change
getEntitiesRestrictCriteria('glpi_groups', '', $entity, true, true)
],
] + getEntitiesRestrictCriteria('glpi_groups', '', $entity, true, true),


if ($filter) {
$query .= "AND ($filter)";
$criteria['WHERE'][] = new QueryExpression($filter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is used only at 2 distinct places, please transform $filter into an array in order to also remove raw SQL in caller method.

Suggested change
$criteria['WHERE'][] = new QueryExpression($filter);
$criteria['WHERE'][] = $filter;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants