Commit 6e9321c7 authored by Robert Lyon's avatar Robert Lyon

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

As part of the db upgrade process. This allows us to turn the triggers
off while updating a certain table and turning them on again afterwards.

behatnotneeded

Change-Id: I5d6f2f7fb7075fca5fe8c811820abe87d92790b3
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 1450b0d5
......@@ -4944,13 +4944,15 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2017030200) {
log_debug('Clean institution theme in view table');
if (!get_config('userscanchooseviewthemes')) {
drop_elasticsearch_triggers();
log_debug('Clean institution theme in view table');
execute_sql("
UPDATE {view}
SET theme = NULL
WHERE theme IS NOT NULL
");
create_elasticsearch_triggers();
}
}
......@@ -5036,6 +5038,7 @@ function xmldb_core_upgrade($oldversion=0) {
WHERE g.submittableto = 1
AND bi.configdata NOT LIKE '%showsubmitted%'", array())) {
safe_require('blocktype', 'groupviews');
drop_elasticsearch_triggers();
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
// 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) {
set_time_limit(30);
}
}
create_elasticsearch_triggers();
}
}
......
......@@ -5172,3 +5172,33 @@ function sort_menu_by_weight($a, $b) {
}
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);
}
}
}
Markdown is supported
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