Total Complexity | 132 |
Total Lines | 747 |
Duplicated Lines | 0 % |
Changes | 9 | ||
Bugs | 3 | Features | 1 |
Complex classes like AdvancedSearchListModule often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdvancedSearchListModule, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class AdvancedSearchListModule extends ListModule { |
||
6 | /** |
||
7 | * Constructor. |
||
8 | * |
||
9 | * @param int $id unique id |
||
10 | * @param array $data list of all actions |
||
11 | */ |
||
12 | public function __construct($id, $data) { |
||
13 | parent::__construct($id, $data); |
||
14 | // TODO: create a new method in Properties class that will return only the properties we |
||
15 | // need for search list (and perhaps for preview???) |
||
16 | $this->properties = $GLOBALS["properties"]->getMailListProperties(); |
||
17 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getAppointmentListProperties()); |
||
18 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getContactListProperties()); |
||
19 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getStickyNoteListProperties()); |
||
20 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getTaskListProperties()); |
||
21 | $this->properties = array_merge($this->properties, [ |
||
22 | 'body' => PR_BODY, |
||
23 | 'html_body' => PR_HTML, |
||
24 | 'startdate' => "PT_SYSTIME:PSETID_Appointment:" . PidLidAppointmentStartWhole, |
||
25 | 'duedate' => "PT_SYSTIME:PSETID_Appointment:" . PidLidAppointmentEndWhole, |
||
26 | 'creation_time' => PR_CREATION_TIME, |
||
27 | "task_duedate" => "PT_SYSTIME:PSETID_Task:" . PidLidTaskDueDate, |
||
28 | ]); |
||
29 | $this->properties = getPropIdsFromStrings($GLOBALS["mapisession"]->getDefaultMessageStore(), $this->properties); |
||
30 | $this->sort = [ |
||
31 | PR_MESSAGE_DELIVERY_TIME => TABLE_SORT_DESCEND, |
||
32 | ]; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Executes all the actions in the $data variable. |
||
37 | */ |
||
38 | #[Override] |
||
39 | public function execute() { |
||
40 | foreach ($this->data as $actionType => $action) { |
||
41 | if (isset($actionType)) { |
||
42 | try { |
||
43 | $store = $this->getActionStore($action); |
||
44 | $parententryid = $this->getActionParentEntryID($action); |
||
|
|||
45 | $entryid = $this->getActionEntryID($action); |
||
46 | |||
47 | switch ($actionType) { |
||
48 | case "list": |
||
49 | case "updatelist": |
||
50 | $this->getDelegateFolderInfo($store); |
||
51 | $this->messageList($store, $entryid, $action, $actionType); |
||
52 | break; |
||
53 | |||
54 | case "search": |
||
55 | $this->search($store, $entryid, $action, $actionType); |
||
56 | break; |
||
57 | |||
58 | case "updatesearch": |
||
59 | $this->updatesearch($store, $entryid, $action); |
||
60 | break; |
||
61 | |||
62 | case "stopsearch": |
||
63 | $this->stopSearch($store, $entryid, $action); |
||
64 | break; |
||
65 | |||
66 | case "delete_searchfolder": |
||
67 | $this->deleteSearchFolder($store, $entryid, $action); |
||
68 | break; |
||
69 | } |
||
70 | } |
||
71 | catch (MAPIException $e) { |
||
72 | // This is a very nasty hack that makes sure that grommunio Web doesn't show an error message when |
||
73 | // search wants to throw an error. This is only done because a proper fix for this bug has not |
||
74 | // been found yet. When WA-9161 is really solved, this should be removed again. |
||
75 | if ($actionType !== 'search' && $actionType !== 'updatesearch' && $actionType !== 'stopsearch') { |
||
76 | $this->processException($e, $actionType); |
||
77 | } |
||
78 | else { |
||
79 | if (DEBUG_LOADER === 0) { |
||
80 | // Log all info we can get about this error to the error log of the web server |
||
81 | error_log("Error in search: \n" . var_export($e, true) . "\n\n" . var_export(debug_backtrace(), true)); |
||
82 | } |
||
83 | // Send success feedback without data, as if nothing strange happened... |
||
84 | $this->sendFeedback(true); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Function which retrieves a list of messages in a folder. |
||
93 | * |
||
94 | * @param object $store MAPI Message Store Object |
||
95 | * @param string $entryid entryid of the folder |
||
96 | * @param array $action the action data, sent by the client |
||
97 | * @param string $actionType the action type, sent by the client |
||
98 | */ |
||
99 | #[Override] |
||
182 | } |
||
183 | } |
||
184 | |||
185 | private function initFtsFilterState() { |
||
186 | return [ |
||
187 | 'message_classes' => [], |
||
188 | 'date_start' => null, |
||
189 | 'date_end' => null, |
||
190 | 'unread' => false, |
||
191 | 'has_attachments' => false, |
||
192 | ]; |
||
193 | } |
||
194 | |||
195 | private function mergeFtsFilterState(array $base, array $delta) { |
||
207 | } |
||
208 | |||
209 | private function buildFtsDescriptor($restriction) { |
||
210 | [$ast, $filters] = $this->convertRestrictionToAst($restriction); |
||
211 | |||
212 | $filters['message_classes'] = array_values(array_unique($filters['message_classes'])); |
||
213 | |||
214 | return [ |
||
215 | 'ast' => $ast, |
||
216 | 'message_classes' => $filters['message_classes'], |
||
217 | 'date_start' => $filters['date_start'], |
||
218 | 'date_end' => $filters['date_end'], |
||
219 | 'unread' => $filters['unread'], |
||
220 | 'has_attachments' => $filters['has_attachments'], |
||
221 | ]; |
||
222 | } |
||
223 | |||
224 | private function convertRestrictionToAst($restriction, $context = null) { |
||
381 | } |
||
382 | } |
||
383 | |||
384 | private function mapPropTagToFtsFields($propTag, $context = null) { |
||
385 | if ($context === 'attachments') { |
||
386 | return ['attachments']; |
||
387 | } |
||
388 | if ($context === 'recipients') { |
||
389 | return ['recipients']; |
||
390 | } |
||
391 | |||
392 | static $map = null; |
||
393 | if ($map === null) { |
||
394 | $map = [ |
||
395 | PR_SUBJECT => ['subject'], |
||
396 | PR_BODY => ['content', 'attachments'], |
||
397 | PR_SENDER_NAME => ['sender'], |
||
398 | PR_SENDER_EMAIL_ADDRESS => ['sender'], |
||
399 | PR_SENT_REPRESENTING_NAME => ['sending'], |
||
400 | PR_SENT_REPRESENTING_EMAIL_ADDRESS => ['sending'], |
||
401 | PR_DISPLAY_TO => ['recipients'], |
||
402 | PR_DISPLAY_CC => ['recipients'], |
||
403 | PR_DISPLAY_BCC => ['recipients'], |
||
404 | PR_EMAIL_ADDRESS => ['recipients'], |
||
405 | PR_SMTP_ADDRESS => ['recipients'], |
||
406 | PR_DISPLAY_NAME => ['others'], |
||
407 | PR_ATTACH_LONG_FILENAME => ['attachments'], |
||
408 | ]; |
||
409 | if (defined('PR_NORMALIZED_SUBJECT')) { |
||
410 | $map[PR_NORMALIZED_SUBJECT] = ['subject']; |
||
411 | } |
||
412 | if (isset($this->properties['categories'])) { |
||
413 | $map[$this->properties['categories']] = ['others']; |
||
414 | } |
||
415 | } |
||
416 | |||
417 | return $map[$propTag] ?? []; |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * Function will set search restrictions on search folder and start search process |
||
422 | * and it will also parse visible columns and sorting data when sending results to client. |
||
423 | * |
||
424 | * @param object $store MAPI Message Store Object |
||
425 | * @param string $entryid entryid of the folder |
||
426 | * @param object $action the action data, sent by the client |
||
427 | * @param string $actionType the action type, sent by the client |
||
428 | */ |
||
429 | #[Override] |
||
430 | public function search($store, $entryid, $action, $actionType) { |
||
431 | $useSearchFolder = $action["use_searchfolder"] ?? false; |
||
432 | $this->logFtsDebug('Search requested', [ |
||
433 | 'store_entryid' => $action['store_entryid'] ?? null, |
||
434 | 'entryid' => $this->formatEntryIdForLog($entryid), |
||
435 | 'subfolders' => $action['subfolders'] ?? null, |
||
436 | 'use_searchfolder' => (bool) $useSearchFolder, |
||
437 | 'restriction_present' => array_key_exists('restriction', $action), |
||
438 | ]); |
||
439 | if (!$useSearchFolder) { |
||
440 | $this->logFtsDebug('Search fallback: store does not support search folders', []); |
||
441 | /* |
||
442 | * store doesn't support search folders so we can't use this |
||
443 | * method instead we will pass restriction to messageList and |
||
444 | * it will give us the restricted results |
||
445 | */ |
||
446 | return parent::messageList($store, $entryid, $action, "list"); |
||
447 | } |
||
448 | $store_props = mapi_getprops($store, [PR_MDB_PROVIDER, PR_DEFAULT_STORE, PR_IPM_SUBTREE_ENTRYID]); |
||
449 | $this->logFtsDebug('Resolved store properties for search', [ |
||
450 | 'provider' => isset($store_props[PR_MDB_PROVIDER]) ? bin2hex((string) $store_props[PR_MDB_PROVIDER]) : null, |
||
451 | 'default_store' => $store_props[PR_DEFAULT_STORE] ?? null, |
||
452 | ]); |
||
453 | if ($store_props[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) { |
||
454 | $this->logFtsDebug('Search fallback: public store does not support search folders', []); |
||
455 | // public store does not support search folders |
||
456 | return parent::messageList($store, $entryid, $action, "search"); |
||
457 | } |
||
458 | if ($GLOBALS['entryid']->compareEntryIds(bin2hex($entryid), bin2hex(TodoList::getEntryId()))) { |
||
459 | $this->logFtsDebug('Search fallback: todo list uses legacy restriction path', []); |
||
460 | // todo list do not need to perform full text index search |
||
461 | return parent::messageList($store, $entryid, $action, "list"); |
||
462 | } |
||
463 | |||
464 | $this->searchFolderList = true; // Set to indicate this is not the normal folder, but a search folder |
||
465 | $this->restriction = false; |
||
466 | |||
467 | // Parse Restriction |
||
468 | $this->parseRestriction($action); |
||
469 | if ($this->restriction == false) { |
||
470 | $this->logFtsDebug('Restriction parsing failed', [ |
||
471 | 'action_type' => $actionType, |
||
472 | ]); |
||
473 | // if error in creating restriction then send error to client |
||
474 | $errorInfo = []; |
||
475 | $errorInfo["error_message"] = _("Error in search, please try again") . "."; |
||
476 | $errorInfo["original_error_message"] = "Error in parsing restrictions."; |
||
477 | |||
478 | return $this->sendSearchErrorToClient($store, $entryid, $action, $errorInfo); |
||
479 | } |
||
480 | $ftsDescriptor = $this->buildFtsDescriptor($this->restriction); |
||
481 | if (empty($ftsDescriptor['ast'])) { |
||
482 | $this->logFtsDebug('Failed to translate restriction to FTS descriptor', [ |
||
483 | 'restriction_sample' => array_keys($this->restriction), |
||
484 | ]); |
||
485 | $errorInfo = []; |
||
486 | $errorInfo["error_message"] = _("Error in search, please try again") . "."; |
||
487 | $errorInfo["original_error_message"] = "Unable to translate search query to full-text expression."; |
||
488 | |||
489 | return $this->sendSearchErrorToClient($store, $entryid, $action, $errorInfo); |
||
490 | } |
||
491 | $serializedRestriction = serialize($this->restriction); |
||
492 | $restrictionSignature = md5($serializedRestriction); |
||
493 | $this->logFtsDebug('Restriction parsed for full-text search', [ |
||
494 | 'restriction_signature' => $restrictionSignature, |
||
495 | 'fts_descriptor' => $ftsDescriptor, |
||
496 | ]); |
||
497 | |||
498 | $isSetSearchFolderEntryId = isset($action['search_folder_entryid']); |
||
499 | if ($isSetSearchFolderEntryId) { |
||
500 | $this->sessionData['searchFolderEntryId'] = $action['search_folder_entryid']; |
||
501 | } |
||
502 | |||
503 | if (isset($action['forceCreateSearchFolder']) && $action['forceCreateSearchFolder']) { |
||
504 | $isSetSearchFolderEntryId = false; |
||
505 | } |
||
506 | |||
507 | // create or open search folder |
||
508 | $searchFolder = $this->createSearchFolder($store, $isSetSearchFolderEntryId); |
||
509 | if ($searchFolder === false) { |
||
510 | if ($store_props[PR_MDB_PROVIDER] == ZARAFA_STORE_DELEGATE_GUID) { |
||
511 | $this->messageList($store, $entryid, $action, "search"); |
||
512 | |||
513 | return true; |
||
514 | } |
||
515 | // if error in creating search folder then send error to client |
||
516 | $errorInfo = []; |
||
517 | |||
518 | $errorInfo["error_message"] = match (mapi_last_hresult()) { |
||
519 | MAPI_E_NO_ACCESS => _("Unable to perform search query, no permissions to create search folder."), |
||
520 | MAPI_E_NOT_FOUND => _("Unable to perform search query, search folder not found."), |
||
521 | default => _("Unable to perform search query, store might not support searching."), |
||
522 | }; |
||
523 | |||
524 | $errorInfo["original_error_message"] = _("Error in creating search folder."); |
||
525 | |||
526 | return $this->sendSearchErrorToClient($store, $entryid, $action, $errorInfo); |
||
527 | } |
||
528 | |||
529 | $subfolder_flag = 0; |
||
530 | $recursive = false; |
||
531 | if (isset($action["subfolders"]) && $action["subfolders"] == "true") { |
||
532 | $recursive = true; |
||
533 | $subfolder_flag = RECURSIVE_SEARCH; |
||
534 | } |
||
535 | |||
536 | if (!is_array($entryid)) { |
||
537 | $entryids = [$entryid]; |
||
538 | } |
||
539 | else { |
||
540 | $entryids = $entryid; |
||
541 | } |
||
542 | |||
543 | $searchFolderEntryId = $this->sessionData['searchFolderEntryId']; |
||
544 | |||
545 | // check if searchcriteria has changed |
||
546 | $restrictionCheck = md5($serializedRestriction . $searchFolderEntryId . $subfolder_flag); |
||
547 | |||
548 | // check if there is need to set searchcriteria again |
||
549 | if (!isset($this->sessionData['searchCriteriaCheck']) || $restrictionCheck != $this->sessionData['searchCriteriaCheck']) { |
||
550 | if (!empty($this->sessionData['searchOriginalEntryids']) && |
||
551 | isset($action['entryid']) && |
||
552 | in_array($action['entryid'], $this->sessionData['searchOriginalEntryids']) |
||
553 | ) { |
||
554 | // get entryids of original folders, and use it to set new search criteria |
||
555 | $entryids = []; |
||
556 | $entryIdsCount = count($this->sessionData['searchOriginalEntryids']); |
||
557 | for ($index = 0; $index < $entryIdsCount; ++$index) { |
||
558 | $entryids[] = hex2bin((string) $this->sessionData['searchOriginalEntryids'][$index]); |
||
559 | } |
||
560 | } |
||
561 | else { |
||
562 | // store entryids of original folders, so that can be used for re-setting the search criteria if needed |
||
563 | $this->sessionData['searchOriginalEntryids'] = []; |
||
564 | for ($index = 0, $len = count($entryids); $index < $len; ++$index) { |
||
565 | $this->sessionData['searchOriginalEntryids'][] = bin2hex($entryids[$index]); |
||
566 | } |
||
567 | } |
||
568 | // we never start the search folder because we will populate the search folder by ourselves |
||
569 | mapi_folder_setsearchcriteria($searchFolder, $this->restriction, $entryids, $subfolder_flag | STOP_SEARCH); |
||
570 | $this->logFtsDebug('Search criteria updated', [ |
||
571 | 'search_folder_entryid' => $searchFolderEntryId, |
||
572 | 'restriction_signature' => $restrictionSignature, |
||
573 | 'recursive' => $recursive, |
||
574 | 'scope_entryids' => $this->formatEntryIdForLog($entryids), |
||
575 | ]); |
||
576 | $this->sessionData['searchCriteriaCheck'] = $restrictionCheck; |
||
577 | } |
||
578 | |||
579 | if (isset($this->sessionData['searchCriteriaCheck']) || $restrictionCheck == $this->sessionData['searchCriteriaCheck']) { |
||
580 | $folderEntryid = bin2hex($entryid); |
||
581 | if ($this->sessionData['searchOriginalEntryids'][0] !== $folderEntryid) { |
||
582 | $this->sessionData['searchOriginalEntryids'][0] = $folderEntryid; |
||
583 | // we never start the search folder because we will populate the search folder by ourselves |
||
584 | mapi_folder_setsearchcriteria($searchFolder, $this->restriction, [$entryid], $subfolder_flag | STOP_SEARCH); |
||
585 | $this->logFtsDebug('Search criteria refreshed for active folder', [ |
||
586 | 'search_folder_entryid' => $searchFolderEntryId, |
||
587 | 'restriction_signature' => $restrictionSignature, |
||
588 | 'target_entryid' => $this->formatEntryIdForLog($entryid), |
||
589 | 'recursive' => $recursive, |
||
590 | ]); |
||
591 | } |
||
592 | } |
||
593 | |||
594 | // Sort |
||
595 | $this->parseSortOrder($action); |
||
596 | // Initialize search patterns with default values |
||
597 | if (is_array($ftsDescriptor['message_classes']) && |
||
598 | count($ftsDescriptor['message_classes']) >= 7) { |
||
599 | $ftsDescriptor['message_classes'] = null; |
||
600 | } |
||
601 | |||
602 | $username = null; |
||
603 | if ($store_props[PR_MDB_PROVIDER] == ZARAFA_STORE_DELEGATE_GUID) { |
||
604 | $eidObj = $GLOBALS["entryid"]->createMsgStoreEntryIdObj(hex2bin((string) $action['store_entryid'])); |
||
605 | $username = $eidObj['ServerShortname']; |
||
606 | $session = $GLOBALS["mapisession"]->getSession(); |
||
607 | |||
608 | if ($username) { |
||
609 | $indexDB = new IndexSqlite($username, $session, $store); |
||
610 | } |
||
611 | } |
||
612 | else { |
||
613 | $indexDB = new IndexSqlite(); |
||
614 | } |
||
615 | $this->logFtsDebug('Dispatching search to index backend', [ |
||
616 | 'search_folder_entryid' => $searchFolderEntryId, |
||
617 | 'restriction_signature' => $restrictionSignature, |
||
618 | 'recursive' => $recursive, |
||
619 | 'delegate_username' => $username, |
||
620 | 'message_classes' => $ftsDescriptor['message_classes'] ?? null, |
||
621 | 'filters' => [ |
||
622 | 'date_start' => $ftsDescriptor['date_start'] ?? null, |
||
623 | 'date_end' => $ftsDescriptor['date_end'] ?? null, |
||
624 | 'unread' => !empty($ftsDescriptor['unread']), |
||
625 | 'has_attachments' => !empty($ftsDescriptor['has_attachments']), |
||
626 | ], |
||
627 | 'ast' => $ftsDescriptor['ast'] ?? null, |
||
628 | ]); |
||
629 | |||
630 | $search_result = $indexDB->search(hex2bin((string) $searchFolderEntryId), $ftsDescriptor, $entryid, $recursive); |
||
631 | if ($search_result == false) { |
||
632 | $this->logFtsDebug('Index search returned no data', [ |
||
633 | 'search_folder_entryid' => $searchFolderEntryId, |
||
634 | 'restriction_signature' => $restrictionSignature, |
||
635 | 'recursive' => $recursive, |
||
636 | ]); |
||
637 | $errorInfo = []; |
||
638 | $errorInfo["error_message"] = _("Unable to perform search query, store might not support searching."); |
||
639 | $errorInfo["original_error_message"] = "Full-text search backend returned no result set."; |
||
640 | |||
641 | return $this->sendSearchErrorToClient($store, $entryid, $action, $errorInfo); |
||
642 | } |
||
643 | |||
644 | unset($action["restriction"]); |
||
645 | |||
646 | // Get the table and merge the arrays |
||
647 | $table = $GLOBALS["operations"]->getTable($store, hex2bin((string) $searchFolderEntryId), $this->properties, $this->sort, $this->start); |
||
648 | $this->logFtsDebug('Search folder table retrieved', [ |
||
649 | 'search_folder_entryid' => $searchFolderEntryId, |
||
650 | 'table_item_count' => isset($table['item']) ? count($table['item']) : null, |
||
651 | 'start' => $this->start, |
||
652 | 'sort' => $this->sort, |
||
653 | ]); |
||
654 | // Create the data array, which will be send back to the client |
||
655 | $data = []; |
||
656 | $data = array_merge($data, $table); |
||
657 | |||
658 | $this->getDelegateFolderInfo($store); |
||
659 | $data = $this->filterPrivateItems($data); |
||
660 | $this->logFtsDebug('Search results filtered for privacy', [ |
||
661 | 'search_folder_entryid' => $searchFolderEntryId, |
||
662 | 'item_count_after_filter' => isset($data['item']) ? count($data['item']) : null, |
||
663 | ]); |
||
664 | |||
665 | // remember which entryid's are send to the client |
||
666 | $searchResults = []; |
||
667 | foreach ($table["item"] as $item) { |
||
668 | // store entryid => last_modification_time mapping |
||
669 | $searchResults[$item["entryid"]] = $item["props"]["last_modification_time"]; |
||
670 | } |
||
671 | |||
672 | // store search results into session data |
||
673 | if (!isset($this->sessionData['searchResults'])) { |
||
674 | $this->sessionData['searchResults'] = []; |
||
675 | } |
||
676 | $this->sessionData['searchResults'][$searchFolderEntryId] = $searchResults; |
||
677 | $this->logFtsDebug('Search results stored in session', [ |
||
678 | 'search_folder_entryid' => $searchFolderEntryId, |
||
679 | 'result_count' => count($searchResults), |
||
680 | ]); |
||
681 | |||
682 | $result = mapi_folder_getsearchcriteria($searchFolder); |
||
683 | $this->logFtsDebug('Search folder state retrieved', [ |
||
684 | 'search_folder_entryid' => $searchFolderEntryId, |
||
685 | 'searchstate' => $result['searchstate'] ?? null, |
||
686 | ]); |
||
687 | |||
688 | $data["search_meta"] = []; |
||
689 | $data["search_meta"]["searchfolder_entryid"] = $searchFolderEntryId; |
||
690 | $data["search_meta"]["search_store_entryid"] = $action["store_entryid"]; |
||
691 | $data["search_meta"]["searchstate"] = $result["searchstate"]; |
||
692 | $data["search_meta"]["results"] = count($searchResults); |
||
693 | |||
694 | // Reopen the search folder, because otherwise the suggestion property will |
||
695 | // not have been updated |
||
696 | $searchFolder = $this->createSearchFolder($store, true); |
||
697 | $storeProps = mapi_getprops($searchFolder, [PR_EC_SUGGESTION]); |
||
698 | if (isset($storeProps[PR_EC_SUGGESTION])) { |
||
699 | $data["search_meta"]["suggestion"] = $storeProps[PR_EC_SUGGESTION]; |
||
700 | $this->logFtsDebug('Search suggestion ready', [ |
||
701 | 'search_folder_entryid' => $searchFolderEntryId, |
||
702 | 'suggestion' => $storeProps[PR_EC_SUGGESTION], |
||
703 | ]); |
||
704 | } |
||
705 | |||
706 | $this->addActionData("search", $data); |
||
707 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
708 | |||
709 | $this->logFtsDebug('Search response dispatched to client', [ |
||
710 | 'search_folder_entryid' => $searchFolderEntryId, |
||
711 | 'items_returned' => isset($data['item']) ? count($data['item']) : null, |
||
712 | 'search_meta' => $data['search_meta'] ?? null, |
||
713 | ]); |
||
714 | return true; |
||
715 | } |
||
716 | |||
717 | private function logFtsDebug(string $message, array $context = []): void { |
||
718 | if (!DEBUG_FULLTEXT_SEARCH) { |
||
719 | return; |
||
720 | } |
||
721 | $prefix = '[fts-debug][module] '; |
||
722 | if (!empty($context)) { |
||
723 | $encoded = json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
||
724 | if ($encoded === false) { |
||
725 | $encoded = 'context_encoding_failed'; |
||
726 | } |
||
727 | error_log($prefix . $message . ' ' . $encoded); |
||
728 | } |
||
729 | else { |
||
730 | error_log($prefix . $message); |
||
731 | } |
||
732 | } |
||
733 | |||
734 | private function formatEntryIdForLog($entryid) { |
||
752 | } |
||
753 | } |
||
754 |