From af9c377b71bb5177017c9b07b4bf30bfe93ec6f0 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Mon, 19 Oct 2020 18:05:50 +0200 Subject: [PATCH] FEAT #13271 TIME 0:20 fix error when search is empty + search on freezed attachment --- .../search/controllers/SearchController.php | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/app/search/controllers/SearchController.php b/src/app/search/controllers/SearchController.php index 86f3b12343a..702cee2f2ea 100644 --- a/src/app/search/controllers/SearchController.php +++ b/src/app/search/controllers/SearchController.php @@ -314,7 +314,7 @@ class SearchController if ($body['meta']['values'][0] == '"' && $body['meta']['values'][strlen($body['meta']['values']) - 1] == '"') { $quick = trim($body['meta']['values'], '"'); $quickWhere = "subject = ? OR alt_identifier = ? OR barcode = ?"; - $quickWhere .= " OR res_id in (select res_id_master from res_attachments where (title = ? OR identifier = ?) and status in ('TRA', 'A_TRA'))"; + $quickWhere .= " OR res_id in (select res_id_master from res_attachments where (title = ? OR identifier = ?) and status in ('TRA', 'A_TRA', 'FRZ'))"; if (ctype_digit($quick)) { $quickWhere .= ' OR res_id = ?'; $args['searchData'][] = $quick; @@ -348,7 +348,7 @@ class SearchController $args['searchData'] = array_merge($args['searchData'], $requestDataDocument['data']); } if (!empty($requestDataAttachment['where'])) { - $whereClause[] = 'res_id in (select res_id_master from res_attachments where (' . implode(' OR ', $requestDataAttachment['where']) . ') and status in (\'TRA\', \'A_TRA\'))'; + $whereClause[] = 'res_id in (select res_id_master from res_attachments where (' . implode(' OR ', $requestDataAttachment['where']) . ') and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $args['searchData'] = array_merge($args['searchData'], $requestDataAttachment['data']); } @@ -375,7 +375,7 @@ class SearchController if (!empty($body['subject']) && !empty($body['subject']['values']) && is_string($body['subject']['values'])) { if ($body['subject']['values'][0] == '"' && $body['subject']['values'][strlen($body['subject']['values']) - 1] == '"') { - $args['searchWhere'][] = "(subject = ? OR res_id in (select res_id_master from res_attachments where title = ? and status in ('TRA', 'A_TRA')))"; + $args['searchWhere'][] = "(subject = ? OR res_id in (select res_id_master from res_attachments where title = ? and status in ('TRA', 'A_TRA', 'FRZ')))"; $subject = trim($body['subject']['values'], '"'); $args['searchData'][] = $subject; $args['searchData'][] = $subject; @@ -391,7 +391,7 @@ class SearchController ]); $subjectGlue = implode(' AND ', $requestData['where']); $attachmentField = AutoCompleteController::getUnsensitiveFieldsForRequest(['fields' => ['title']]); - $subjectGlue = "(($subjectGlue) OR res_id in (select res_id_master from res_attachments where {$attachmentField} and status in ('TRA', 'A_TRA')))"; + $subjectGlue = "(($subjectGlue) OR res_id in (select res_id_master from res_attachments where {$attachmentField} and status in ('TRA', 'A_TRA', 'FRZ')))"; $args['searchWhere'][] = $subjectGlue; $args['searchData'] = array_merge($args['searchData'], $requestData['data']); @@ -399,7 +399,7 @@ class SearchController } } if (!empty($body['chrono']) && !empty($body['chrono']['values']) && is_string($body['chrono']['values'])) { - $args['searchWhere'][] = '(alt_identifier ilike ? OR res_id in (select res_id_master from res_attachments where identifier ilike ? and status in (\'TRA\', \'A_TRA\')))'; + $args['searchWhere'][] = '(alt_identifier ilike ? OR res_id in (select res_id_master from res_attachments where identifier ilike ? and status in (\'TRA\', \'A_TRA\', \'FRZ\')))'; $args['searchData'][] = "%{$body['chrono']['values']}%"; $args['searchData'][] = "%{$body['chrono']['values']}%"; } @@ -726,16 +726,16 @@ class SearchController } if (!empty($body['attachment_type']) && !empty($body['attachment_type']['values']) && is_array($body['attachment_type']['values'])) { - $args['searchWhere'][] = 'res_id in (select DISTINCT res_id_master from res_attachments where attachment_type in (?) and status in (\'TRA\', \'A_TRA\'))'; + $args['searchWhere'][] = 'res_id in (select DISTINCT res_id_master from res_attachments where attachment_type in (?) and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $args['searchData'][] = $body['attachment_type']['values']; } if (!empty($body['attachment_creationDate']) && !empty($body['attachment_creationDate']['values']) && is_array($body['attachment_creationDate']['values'])) { if (Validator::date()->notEmpty()->validate($body['attachment_creationDate']['values']['start'])) { - $args['searchWhere'][] = 'res_id in (select DISTINCT res_id_master from res_attachments where creation_date >= ? and status in (\'TRA\', \'A_TRA\'))'; + $args['searchWhere'][] = 'res_id in (select DISTINCT res_id_master from res_attachments where creation_date >= ? and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $args['searchData'][] = $body['attachment_creationDate']['values']['start']; } if (Validator::date()->notEmpty()->validate($body['attachment_creationDate']['values']['end'])) { - $args['searchWhere'][] = 'res_id in (select DISTINCT res_id_master from res_attachments where creation_date <= ? and status in (\'TRA\', \'A_TRA\'))'; + $args['searchWhere'][] = 'res_id in (select DISTINCT res_id_master from res_attachments where creation_date <= ? and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $args['searchData'][] = TextFormatModel::getEndDayDate(['date' => $body['attachment_creationDate']['values']['end']]); } } @@ -1150,7 +1150,7 @@ class SearchController $idMasterDatas = AttachmentModel::get([ 'select' => ['DISTINCT res_id_master'], 'where' => ['res_id in (?)', 'status in (?)'], - 'data' => [$listIds, ['A_TRA', 'TRA']] + 'data' => [$listIds, ['A_TRA', 'FRZ', 'TRA']] ]); $listIds = array_column($idMasterDatas, 'res_id_master'); @@ -1747,6 +1747,25 @@ class SearchController ]; } + if (empty($priorities['values'])) { + $priorities['values'] = []; + } + if (empty($categories['values'])) { + $categories['values'] = []; + } + if (empty($statuses['values'])) { + $statuses['values'] = []; + } + if (empty($docTypes['values'])) { + $docTypes['values'] = []; + } + if (empty($entities['values'])) { + $entities['values'] = []; + } + if (empty($folders['values'])) { + $folders['values'] = []; + } + usort($priorities['values'], ['Resource\controllers\ResourceListController', 'compareSortOnLabel']); usort($categories['values'], ['Resource\controllers\ResourceListController', 'compareSortOnLabel']); usort($statuses['values'], ['Resource\controllers\ResourceListController', 'compareSortOnLabel']); @@ -1770,12 +1789,12 @@ class SearchController if (!empty($body['subject']) && !empty($body['subject']['values']) && is_string($body['subject']['values'])) { if ($body['subject']['values'][0] == '"' && $body['subject']['values'][strlen($body['subject']['values']) - 1] == '"') { - $wherePlus = 'res_id in (select res_id_master from res_attachments where title = ? and status in (\'TRA\', \'A_TRA\'))'; + $wherePlus = 'res_id in (select res_id_master from res_attachments where title = ? and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $subject = trim($body['subject']['values'], '"'); $data[] = $subject; } else { $attachmentField = AutoCompleteController::getUnsensitiveFieldsForRequest(['fields' => ['title']]); - $wherePlus = "res_id in (select res_id_master from res_attachments where {$attachmentField} and status in ('TRA', 'A_TRA'))"; + $wherePlus = "res_id in (select res_id_master from res_attachments where {$attachmentField} and status in ('TRA', 'A_TRA', 'FRZ'))"; $data[] = "%{$body['subject']['values']}%"; } } @@ -1783,7 +1802,7 @@ class SearchController if (!empty($wherePlus)) { $wherePlus .= ' OR '; } - $wherePlus .= 'res_id in (select res_id_master from res_attachments where identifier ilike ? and status in (\'TRA\', \'A_TRA\'))'; + $wherePlus .= 'res_id in (select res_id_master from res_attachments where identifier ilike ? and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $data[] = "%{$body['chrono']['values']}%"; } if (!empty($body['meta']) && !empty($body['meta']['values']) && is_string($body['meta']['values'])) { @@ -1792,7 +1811,7 @@ class SearchController $wherePlus .= ' OR '; } $quick = trim($body['meta']['values'], '"'); - $wherePlus .= "res_id in (select res_id_master from res_attachments where (title = ? OR identifier = ?) and status in ('TRA', 'A_TRA'))"; + $wherePlus .= "res_id in (select res_id_master from res_attachments where (title = ? OR identifier = ?) and status in ('TRA', 'A_TRA', 'FRZ'))"; $data[] = $quick; $data[] = $quick; } else { @@ -1811,7 +1830,7 @@ class SearchController $wherePlus .= ' OR '; } - $wherePlus .= 'res_id in (select res_id_master from res_attachments where (' . implode(' OR ', $requestDataAttachment['where']) . ') and status in (\'TRA\', \'A_TRA\'))'; + $wherePlus .= 'res_id in (select res_id_master from res_attachments where (' . implode(' OR ', $requestDataAttachment['where']) . ') and status in (\'TRA\', \'A_TRA\', \'FRZ\'))'; $data = array_merge($data, $requestDataAttachment['data']); } } -- GitLab