From 1c6f6a6fb5cb7c50975db3100739659b037b9e67 Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Sat, 16 Nov 2024 16:20:31 +0100 Subject: [PATCH] #31950 [Ticket] fix: unwanted join for sql request ticket stats --- htdocs/core/boxes/box_last_modified_ticket.php | 4 ---- htdocs/core/boxes/box_last_ticket.php | 4 ---- htdocs/public/ticket/list.php | 6 +----- htdocs/ticket/class/ticket.class.php | 10 +--------- htdocs/ticket/index.php | 8 +------- 5 files changed, 3 insertions(+), 29 deletions(-) diff --git a/htdocs/core/boxes/box_last_modified_ticket.php b/htdocs/core/boxes/box_last_modified_ticket.php index f5c5c6b49d333..87ccefc3cf30d 100644 --- a/htdocs/core/boxes/box_last_modified_ticket.php +++ b/htdocs/core/boxes/box_last_modified_ticket.php @@ -77,12 +77,8 @@ public function loadBox($max = 5) if ($user->hasRight('ticket', 'read')) { $sql = "SELECT t.rowid as id, t.ref, t.track_id, t.fk_soc, t.fk_user_create, t.fk_user_assign, t.subject, t.message, t.fk_statut as status, t.type_code, t.category_code, t.severity_code, t.datec, t.tms as datem, t.date_read, t.date_close, t.origin_email "; - $sql .= ", type.label as type_label, category.label as category_label, severity.label as severity_label"; $sql .= ", s.nom as company_name, s.email as socemail, s.client, s.fournisseur"; $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc"; $sql .= " WHERE t.entity IN (".getEntity('ticket').')'; diff --git a/htdocs/core/boxes/box_last_ticket.php b/htdocs/core/boxes/box_last_ticket.php index 8910aed5aa4cb..dc5d31c002765 100644 --- a/htdocs/core/boxes/box_last_ticket.php +++ b/htdocs/core/boxes/box_last_ticket.php @@ -77,12 +77,8 @@ public function loadBox($max = 5) if ($user->hasRight('ticket', 'read')) { $sql = "SELECT t.rowid as id, t.ref, t.track_id, t.fk_soc, t.fk_user_create, t.fk_user_assign, t.subject, t.message, t.fk_statut as status, t.type_code, t.category_code, t.severity_code, t.datec, t.date_read, t.date_close, t.origin_email,"; - $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label,"; $sql .= " s.nom as company_name, s.email as socemail, s.client, s.fournisseur"; $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc"; $sql .= " WHERE t.entity IN (".getEntity('ticket').")"; // $sql.= " AND e.rowid = er.fk_event"; diff --git a/htdocs/public/ticket/list.php b/htdocs/public/ticket/list.php index 2bd597ca1180f..1ed0ba74813f6 100644 --- a/htdocs/public/ticket/list.php +++ b/htdocs/public/ticket/list.php @@ -374,8 +374,7 @@ $sql .= " t.datec,"; $sql .= " t.date_read,"; $sql .= " t.date_close,"; - $sql .= " t.tms,"; - $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label"; + $sql .= " t.tms"; // Add fields for extrafields if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { @@ -383,9 +382,6 @@ } } $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code = t.type_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code = t.category_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code = t.severity_code"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid = t.fk_user_create"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON ua.rowid = t.fk_user_assign"; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index aafe16ca86894..27e362351fbad 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -705,11 +705,7 @@ public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '') $sql .= " t.model_pdf,"; $sql .= " t.extraparams,"; $sql .= " t.ip,"; - $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label"; $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); @@ -837,8 +833,7 @@ public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $lim $sql .= " t.date_read,"; $sql .= " t.date_last_msg_sent,"; $sql .= " t.date_close,"; - $sql .= " t.tms,"; - $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label"; + $sql .= " t.tms"; // Add fields for extrafields if ($extrafields->attributes[$this->table_element]['count'] > 0) { foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) { @@ -846,9 +841,6 @@ public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $lim } } $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code = t.type_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code = t.category_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code = t.severity_code"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid = t.fk_user_create"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON ua.rowid = t.fk_user_assign"; diff --git a/htdocs/ticket/index.php b/htdocs/ticket/index.php index 0187ae7504bbc..3f462ff7826f1 100644 --- a/htdocs/ticket/index.php +++ b/htdocs/ticket/index.php @@ -332,14 +332,8 @@ * Latest unread tickets */ - $sql = "SELECT t.rowid, t.ref, t.track_id, t.datec, t.subject, t.type_code, t.category_code, t.severity_code, t.fk_statut as status, t.progress,"; - $sql .= " type.code as type_code, type.label as type_label,"; - $sql .= " category.code as category_code, category.label as category_label,"; - $sql .= " severity.code as severity_code, severity.label as severity_label"; + $sql = "SELECT t.rowid, t.ref, t.track_id, t.datec, t.subject, t.type_code, t.category_code, t.severity_code, t.fk_statut as status, t.progress"; $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code"; if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; }