Skip to content

Commit

Permalink
Dolibarr#31950 [Ticket] fix: unwanted join for sql request ticket stats
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Nov 16, 2024
1 parent 7a84561 commit 1c6f6a6
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 29 deletions.
4 changes: 0 additions & 4 deletions htdocs/core/boxes/box_last_modified_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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').')';
Expand Down
4 changes: 0 additions & 4 deletions htdocs/core/boxes/box_last_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 1 addition & 5 deletions htdocs/public/ticket/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,14 @@
$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) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
}
}
$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";
Expand Down
10 changes: 1 addition & 9 deletions htdocs/ticket/class/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -837,18 +833,14 @@ 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) {
$sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? ",ef.".$key." as options_".$key : '');
}
}
$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";
Expand Down
8 changes: 1 addition & 7 deletions htdocs/ticket/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down

0 comments on commit 1c6f6a6

Please sign in to comment.