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 raw sql #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

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
'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