Commit acaaeabe authored by Robert Lyon's avatar Robert Lyon

Bug 1738898: Elasticsearch not indexing access changes correctly

There is an add_to_queue_access() function that is meant to check what
pages have had their access changed since they were indexed. It was
designed to catch the pages which have a start/stop date.

But that is not quite sufficient.

See bug report for more info

behatnotneeded

Change-Id: I160d074fc709c7e94c9c4cacab8f2c5e6c7e9a86
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 731866e4
......@@ -1277,7 +1277,13 @@ class View {
$beforeusers = activity_get_viewaccess_users($this->get('id'));
$select = 'view = ? AND visible = 1 AND token IS NULL';
$beforerules = get_records_select_array('view_access', $select, array($this->id));
if (get_config('searchplugin') == 'elasticsearch' && !empty($beforerules) && empty($accessdata) && $viewids != null) {
// We are removing access rules and none are left so we need to let elasticsearch know
// as it won't be picked up by the add_to_queue_access() function
safe_require('search', 'elasticsearch');
ElasticsearchIndexing::add_to_queue_access(null, null, $viewids);
}
db_begin();
delete_records_select('view_access', $select, array($this->id));
......
......@@ -1714,32 +1714,52 @@ class ElasticsearchIndexing {
/**
* Check if access changed between the last time the function was called (view_access table) and
* add items to the queue
* add items to the queue. Or pass in an array of views to work wih (useful when all view_access rules
* deleted for view)
*/
public static function add_to_queue_access($last_run, $timestamp) {
public static function add_to_queue_access($last_run, $timestamp, $views = array()) {
$artefacttypes_str = self::artefacttypes_filter_string();
if (!empty($views)) {
$joinstr = '';
$wherestr = " v.id IN (" . implode(',', array_values($views)) . ")";
}
else {
$joinstr = " INNER JOIN {view_access} vac ON vac.view = v.id ";
$wherestr = " vac.startdate BETWEEN '{$last_run}' AND '{$timestamp}'
OR vac.stopdate BETWEEN '{$last_run}' AND '{$timestamp}'
OR vac.ctime BETWEEN '{$last_run}' AND '{$timestamp}'";
}
execute_sql("
INSERT INTO {search_elasticsearch_queue} (itemid, type)
SELECT view, 'view'
FROM {view_access} WHERE startdate BETWEEN '{$last_run}' AND '{$timestamp}'
OR stopdate BETWEEN '{$last_run}' AND '{$timestamp}'
;"
SELECT v.id, 'view'
FROM {view} v
" . $joinstr . "
WHERE " . $wherestr . ";"
);
execute_sql("
INSERT INTO {search_elasticsearch_queue} (itemid, type, artefacttype)
SELECT var.artefact, 'artefact', a.artefacttype
FROM {view_access} vac
INNER JOIN {view_artefact} var ON var.view = vac.view
FROM {view} v
" . $joinstr . "
INNER JOIN {view_artefact} var ON var.view = v.id
INNER JOIN {artefact} a ON var.artefact = a.id
WHERE
(
vac.startdate BETWEEN '{$last_run}' AND '{$timestamp}'
OR vac.stopdate BETWEEN '{$last_run}' AND '{$timestamp}'
)
AND a.artefacttype IN {$artefacttypes_str}
WHERE (" . $wherestr . ")
AND a.artefacttype IN {$artefacttypes_str}
;"
);
// Deal with text blocks
execute_sql("
INSERT INTO {search_elasticsearch_queue} (itemid, type)
SELECT b.id, 'block_instance'
FROM {view} v
" . $joinstr . "
INNER JOIN {block_instance} b ON v.id = b.view
WHERE (" . $wherestr . ")
AND b.blocktype IN ('text')
;"
);
}
......
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