Commit 635ff51a authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1720912: Allow easier turning off/on of elasticsearch triggers"

parents f04082e9 6e9321c7
...@@ -4944,13 +4944,15 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -4944,13 +4944,15 @@ function xmldb_core_upgrade($oldversion=0) {
} }
if ($oldversion < 2017030200) { if ($oldversion < 2017030200) {
log_debug('Clean institution theme in view table');
if (!get_config('userscanchooseviewthemes')) { if (!get_config('userscanchooseviewthemes')) {
drop_elasticsearch_triggers();
log_debug('Clean institution theme in view table');
execute_sql(" execute_sql("
UPDATE {view} UPDATE {view}
SET theme = NULL SET theme = NULL
WHERE theme IS NOT NULL WHERE theme IS NOT NULL
"); ");
create_elasticsearch_triggers();
} }
} }
...@@ -5036,6 +5038,7 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -5036,6 +5038,7 @@ function xmldb_core_upgrade($oldversion=0) {
WHERE g.submittableto = 1 WHERE g.submittableto = 1
AND bi.configdata NOT LIKE '%showsubmitted%'", array())) { AND bi.configdata NOT LIKE '%showsubmitted%'", array())) {
safe_require('blocktype', 'groupviews'); safe_require('blocktype', 'groupviews');
drop_elasticsearch_triggers();
log_debug('Update submittable groups to display submissions in block by default'); log_debug('Update submittable groups to display submissions in block by default');
// We can only update those blocks where a decision hasn't yet been made rather than include blocks // We can only update those blocks where a decision hasn't yet been made rather than include blocks
// that have showsubmitted set to false as that may be a valid choice by the group administrator. // that have showsubmitted set to false as that may be a valid choice by the group administrator.
...@@ -5054,6 +5057,7 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -5054,6 +5057,7 @@ function xmldb_core_upgrade($oldversion=0) {
set_time_limit(30); set_time_limit(30);
} }
} }
create_elasticsearch_triggers();
} }
} }
......
...@@ -5172,3 +5172,33 @@ function sort_menu_by_weight($a, $b) { ...@@ -5172,3 +5172,33 @@ function sort_menu_by_weight($a, $b) {
} }
return ($aweight < $bweight) ? -1 : 1; return ($aweight < $bweight) ? -1 : 1;
} }
/**
* Disable elasticsearch triggers for site - useful for upgrades if we don't need to reindex the changes
* This should be paired with create_elasticsearch_triggers(); - an example:
* drop_elasticsearch_triggers();
* execute_sql("UPDATE {view} ... ");
* create_elasticsearch_triggers();
*/
function drop_elasticsearch_triggers() {
if (get_config('searchplugin') == 'elasticsearch') {
log_debug('Dropping elasticsearch triggers');
require_once(get_config('docroot') . 'search/elasticsearch/lib.php');
ElasticsearchIndexing::drop_trigger_functions();
}
}
/**
* Paired with drop_elasticsearch_triggers(); - see it's info for useage
*/
function create_elasticsearch_triggers() {
if (get_config('searchplugin') == 'elasticsearch') {
log_debug('Adding elasticsearch triggers back in');
require_once(get_config('docroot') . 'search/elasticsearch/lib.php');
ElasticsearchIndexing::create_trigger_functions();
$enabledtypes = explode(',', get_config_plugin('search', 'elasticsearch', 'types'));
foreach ($enabledtypes as $type) {
ElasticsearchIndexing::create_triggers($type);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment