Skip to content

Commit

Permalink
Fix #10207 #10209 #8899 - Multiple Elasticsearch indexing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSiero authored and jack7anderson7 committed Jan 18, 2024
1 parent 1848830 commit b39d961
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion data/SugarBean.php
Original file line number Diff line number Diff line change
Expand Up @@ -4347,7 +4347,7 @@ public function process_list_query($query, $row_offset, $limit = -1, $max_per_pa
$next_offset--;
$previous_offset++;
}
} elseif (!isset($rows_found)) {
} elseif ($rows_found == 0) {
$rows_found = $row_offset + count($list);
}

Expand Down
6 changes: 4 additions & 2 deletions include/Smarty/plugins/function.diff_for_humans.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
*/
function smarty_function_diff_for_humans(array $params)
{
return \Carbon\Carbon::createFromTimeString($params['datetime'])->diffForHumans();
}
global $timedate;

return \Carbon\Carbon::createFromTimeString($timedate->to_db($params['datetime']))->diffForHumans();
}
2 changes: 1 addition & 1 deletion lib/Search/ElasticSearch/ElasticSearchIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function getMeta(string $module): ?array
return null;
}

return $results[$lowercaseModule]['mappings']['_meta'];
return $results[$lowercaseModule]['mappings']['_meta'] ?? array();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions lib/Search/Index/IndexingSchedulerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public static function schedulerJob($options = [])
$indexer = new self();
$indexer->getLogger()->debug('Starting scheduled job');

$checkPartialIndexing = json_decode(html_entity_decode($options['fetched_row']['data']), true);

$indexer->setDifferentialIndexing($checkPartialIndexing['partial'] ?? true);
$indexer->setDifferentialIndexing($options['partial'] ?? true);

try {
$indexer->index();
Expand Down
4 changes: 4 additions & 0 deletions lib/Search/UI/SearchThrowableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
}

use Elasticsearch\Common\Exceptions\NoNodesAvailableException;
use Elasticsearch\Common\Exceptions\Missing404Exception;
use Exception;
use SuiteCRM\Search\Exceptions\SearchEngineNotFoundException;
use SuiteCRM\Search\Exceptions\SearchException;
Expand Down Expand Up @@ -131,6 +132,9 @@ private function getFriendlyMessage(): string
case SearchException::class:
$message = $mod_strings['LBL_ELASTIC_SEARCH_EXCEPTION_SEARCH'];
break;
case Missing404Exception::class:
$message = $mod_strings['LBL_ELASTIC_SEARCH_EXCEPTION_MISSING_INDEX'];
break;
default:
$message = $mod_strings['LBL_ELASTIC_SEARCH_EXCEPTION_DEFAULT'];
}
Expand Down
5 changes: 5 additions & 0 deletions modules/Administration/Search/ElasticSearch/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public function getSchedulers()
/** @var Scheduler[]|null $schedulers */
$schedulers = BeanFactory::getBean('Schedulers')->get_full_list(null, $where);

foreach ($schedulers as &$scheduler) {
$scheduler->check_date_relationships_load();
}
unset($scheduler);

return $schedulers;
}

Expand Down
18 changes: 14 additions & 4 deletions modules/Administration/Search/ElasticSearch/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ $("#es-test-connection").click(function () {
$("#es-full-index").click(function () {
var url = "index.php?module=Administration&action=ElasticSearchSettings&do=FullIndex";

$.ajax(url).done(function () {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_SUCCESS"));
$.ajax(url).done(function (data) {
if (data.status === "success") {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_SUCCESS"));
}
else {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_FAIL_NO_SUCCESS"));
}
}).error(function () {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_FAIL"));
});
Expand All @@ -82,8 +87,13 @@ $("#es-full-index").click(function () {
$("#es-partial-index").click(function () {
var url = "index.php?module=Administration&action=ElasticSearchSettings&do=PartialIndex";

$.ajax(url).done(function () {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_SUCCESS"));
$.ajax(url).done(function (data) {
if (data.status === "success") {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_SUCCESS"));
}
else {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_FAIL_NO_SUCCESS"));
}
}).error(function () {
alert(SUGAR.language.get("Administration", "LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_FAIL"));
});
Expand Down
3 changes: 1 addition & 2 deletions modules/Administration/Search/ElasticSearch/view.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,4 @@
{$JAVASCRIPT}

</form>
<script src="modules/Administration/Search/ElasticSearch/scripts.js"></script>
<script src="modules/Administration/Search/ajaxSubmit.js"></script>
<script src="modules/Administration/Search/ElasticSearch/scripts.js"></script>
12 changes: 7 additions & 5 deletions modules/Administration/language/en_us.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@
'LBL_QUICK_REPAIR_TITLE' => 'Please select Module(s) to repair:',
'LBL_QUICK_REPAIR_AND_REBUILD_DESC' => 'Repairs and rebuilds DB, Extensions, Vardefs, SuiteCRM Dashlets etc.',
'LBL_ALL_MODULES' => 'All Modules',
'LBL_REPAIR_ELASTICSEARCH_INDEX' => 'Repair ElasticSearch Index',
'LBL_REPAIR_ELASTICSEARCH_INDEX_DONE' => 'ElasticSearch Indexing has been repaired',
'LBL_REPAIR_ELASTICSEARCH_INDEX' => 'Repair Elasticsearch Index',
'LBL_REPAIR_ELASTICSEARCH_INDEX_DONE' => 'Elasticsearch Indexing has been repaired',
'LBL_CAMPAIGN_CONFIG_TITLE' => 'Campaign Email Settings',
'LBL_CAMPAIGN_CONFIG_DESC' => 'Configure email settings for campaigns',
'LBL_REPAIR_ORACLE_FULLTEXT' => 'Rebuild fulltext indices',
Expand Down Expand Up @@ -951,26 +951,28 @@
'LBL_ELASTIC_SEARCH_TEST_CONNECTION' => 'Test connection',
'LBL_ELASTIC_SEARCH_TEST_CONNECTION_SUCCESS' => 'Connection successful.',
'LBL_ELASTIC_SEARCH_TEST_CONNECTION_FAIL' => 'Connection failed.',
'LBL_SETUP_ELASTICSEARCH' => 'Please enable ElasticSearch before repairing Indexes',
'LBL_SETUP_ELASTICSEARCH' => 'Please enable Elasticsearch before repairing Indexes',
'LBL_ELASTIC_SEARCH_TEST_CONNECTION_ERROR' => 'Failed perform ping request.',
'LBL_ELASTIC_SEARCH_SERVER' => 'Server',
'LBL_ELASTIC_SEARCH_HOST' => 'Host',
'LBL_ELASTIC_SEARCH_USER' => 'Username',
'LBL_ELASTIC_SEARCH_PASS' => 'Password',
'LBL_ELASTIC_SEARCH_SCHEDULERS' => 'Schedulers',
'LBL_ELASTIC_SEARCH_SCHEDULERS_HELP' => 'The following ElasticSearch schedulers were detected:',
'LBL_ELASTIC_SEARCH_SCHEDULERS_HELP' => 'The following Elasticsearch schedulers were detected:',
'LBL_ELASTIC_SEARCH_SCHEDULERS_LAST_RUN' => 'last run:',
'LBL_ELASTIC_SEARCH_SCHEDULERS_NEVER_RUN' => 'This job has never run',
'LBL_ELASTIC_SEARCH_SCHEDULERS_NOT_FOUND' => 'No schedulers found. Consider creating one.',
'LBL_ELASTIC_SEARCH_SCHEDULERS_DESC' => 'The ElasticSearch module uses schedulers to keep the database and the indexing engine synchronised.',
'LBL_ELASTIC_SEARCH_SCHEDULERS_DESC' => 'The Elasticsearch module uses schedulers to keep the database and the indexing engine synchronised.',
'LBL_ELASTIC_SEARCH_INDEX' => 'Index',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_HELP' => 'Schedule an indexing',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL' => 'Schedule full indexing',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART' => 'Schedule partial indexing',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_SUCCESS' => 'A full indexing has been scheduled and will start in the next 60 seconds. Search results might be inconsistent until the process is complete.',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_FAIL' => 'Failed to start full index.',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_FULL_FAIL_NO_SUCCESS' => 'Full indexing was not scheduled. Are you still logged in?',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_SUCCESS' => 'A partial indexing has been scheduled and will start in the next 60 seconds.',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_FAIL' => 'Failed to start partial index.',
'LBL_ELASTIC_SEARCH_INDEX_SCHEDULE_PART_FAIL_NO_SUCCESS' => 'Partial indexing was not scheduled. Are you still logged in?',

// SearchWrapper Settings
'LBL_SEARCH_INTERFACE' => 'Search Interface',
Expand Down
1 change: 1 addition & 0 deletions modules/Home/language/en_us.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
'LBL_ELASTIC_SEARCH_EXCEPTION_SEARCH' => 'An error internal to the Search has occurred.',
'LBL_ELASTIC_SEARCH_EXCEPTION_DEFAULT' => 'An unknown error has occurred while performing the search.',
'LBL_ELASTIC_SEARCH_EXCEPTION_END_MESSAGE' => 'Contact an administrator if the problem persists. More information available in the logs.',
'LBL_ELASTIC_SEARCH_EXCEPTION_MISSING_INDEX' => 'The search index for one or more modules could not be found. Please make sure that crontab is configured and running, open the Elasticsearch configuration and click "Schedule full indexing" and consider creating a Scheduler job "Elasticsearch Indexer" when not existent.',

'LBL_ELASTIC_SEARCH_DEFAULT' => 'No results matching your search criteria. Try broadening your search.',

Expand Down
12 changes: 12 additions & 0 deletions modules/Schedulers/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,18 @@ public function rebuildDefaultSchedulers()
$sched16->modified_user_id = '1';
$sched16->catch_up = '0';
$sched16->save();

$sched17 = new Scheduler;
$sched17->name = $mod_strings['LBL_OOTB_ELASTIC_INDEX'];
$sched17->job = 'function::runElasticSearchIndexerScheduler';
$sched17->date_time_start = create_date(2015, 1, 1) . ' ' . create_time(0, 0, 1);
$sched17->date_time_end = null;
$sched17->job_interval = '30::4::*::*::*';
$sched17->status = 'Active';
$sched17->created_by = '1';
$sched17->modified_user_id = '1';
$sched17->catch_up = '0';
$sched17->save();
}

//// END SCHEDULER HELPER FUNCTIONS
Expand Down
4 changes: 2 additions & 2 deletions modules/Schedulers/_AddJobsHere.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,9 @@ public function run($data)
}
}

function runElasticSearchIndexerScheduler($data)
function runElasticSearchIndexerScheduler($job, $data = '{}')
{
return \SuiteCRM\Search\ElasticSearch\ElasticSearchIndexer::schedulerJob((array) $data);
return \SuiteCRM\Search\ElasticSearch\ElasticSearchIndexer::schedulerJob(json_decode(html_entity_decode($data), true));
}

if (file_exists('custom/modules/Schedulers/_AddJobsHere.php')) {
Expand Down
1 change: 1 addition & 0 deletions modules/Schedulers/language/en_us.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'LBL_OOTB_CLEANUP_QUEUE' => 'Clean Jobs Queue',
'LBL_OOTB_REMOVE_DOCUMENTS_FROM_FS' => 'Removal of documents from filesystem',
'LBL_OOTB_GOOGLE_CAL_SYNC' => 'Google Calendar Sync',
'LBL_OOTB_ELASTIC_INDEX' => 'Perform Elasticsearch Index',

// List Labels
'LBL_LIST_JOB_INTERVAL' => 'Interval:',
Expand Down

0 comments on commit b39d961

Please sign in to comment.