Commit 4485d540 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1656731: Fixing issues for elasticsearch



behatnotneeded

Change-Id: I6dac5a09617dd61ca84a9e47dbc37e0c3ee60b20
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 9cf83e93
......@@ -1273,7 +1273,7 @@ abstract class ElasticsearchType
/**
* get the info from the DB for indexing
*/
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$record = get_record($type, 'id', $id);
if ($record) {
// we need to set block_instance creation time later (using view ctime)
......
......@@ -169,7 +169,7 @@ class ElasticsearchType_artefact extends ElasticsearchType
}
}
public static function getRecordById($type, $id, $artefacttypesmap_array){
public static function getRecordById($type, $id, $map = null) {
$record = parent::getRecordById($type, $id);
if (!$record) {
return false;
......@@ -200,39 +200,40 @@ class ElasticsearchType_artefact extends ElasticsearchType
$record->access = $accessObj;
// set 'mainfacetterm' & 'artefactgroup'
$terms = explode("|", $artefacttypesmap_array[$record->artefacttype]);
$record->mainfacetterm = $terms[2];
$record->secfacetterm = $terms[1];
require_once(get_config('docroot') . 'artefact/resume/lib.php');
if (PluginArtefactResume::is_active()) {
// If the artefacttype is one of the résumé ones we need to get the description
// from this artefact's related résumé table. There is a one -> many relationship between
// the artefact and the items but seen as all resume items are added
// to a page when choosing One résumé field, rather than selecting them individually,
// we can just blob together all the info for this résumé artefact into $record->description.
$resumetypes = ArtefactTypeResumeComposite::get_composite_artefact_types();
if (in_array($terms[0], $resumetypes)) {
try {
$query = "SELECT * FROM {artefact_resume_" . $terms[0] . "} WHERE artefact = ?";
$results = get_records_sql_assoc($query, array($record->id));
}
catch (SQLException $e) {
// Table doesn't exist
$results = array();
}
foreach ($results as $result) {
$items = get_object_vars($result);
foreach ($items as $key => $item) {
if (!in_array($key, array('id', 'artefact','displayorder'))) {
$record->description .= $item . ' ';
if (!empty($map) && isset($map[$record->artefacttype])) {
$terms = explode("|", $map[$record->artefacttype]);
$record->mainfacetterm = $terms[2];
$record->secfacetterm = $terms[1];
require_once(get_config('docroot') . 'artefact/resume/lib.php');
if (PluginArtefactResume::is_active()) {
// If the artefacttype is one of the résumé ones we need to get the description
// from this artefact's related résumé table. There is a one -> many relationship between
// the artefact and the items but seen as all resume items are added
// to a page when choosing One résumé field, rather than selecting them individually,
// we can just blob together all the info for this résumé artefact into $record->description.
$resumetypes = ArtefactTypeResumeComposite::get_composite_artefact_types();
if (in_array($terms[0], $resumetypes)) {
try {
$query = "SELECT * FROM {artefact_resume_" . $terms[0] . "} WHERE artefact = ?";
$results = get_records_sql_assoc($query, array($record->id));
}
catch (SQLException $e) {
// Table doesn't exist
$results = array();
}
foreach ($results as $result) {
$items = get_object_vars($result);
foreach ($items as $key => $item) {
if (!in_array($key, array('id', 'artefact','displayorder'))) {
$record->description .= $item . ' ';
}
}
}
}
}
}
// AS the field "sort" is not analyzed, we need to clean it (remove html tags & lowercase)
$record->sort = strtolower(strip_tags($record->title));
......
......@@ -137,7 +137,7 @@ class ElasticsearchType_block_instance extends ElasticsearchType
}
public static function getRecordById($type, $id) {
public static function getRecordById($type, $id, $map = null) {
$record = parent::getRecordById($type, $id);
if (!$record) {
return false;
......
......@@ -136,7 +136,7 @@ class ElasticsearchType_collection extends ElasticsearchType
}
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$record = parent::getRecordById($type, $id);
if (!$record) {
return false;
......
......@@ -88,7 +88,7 @@ class ElasticsearchType_group extends ElasticsearchType
}
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$record = parent::getRecordById($type, $id);
if (!$record || $record->deleted) {
return false;
......
......@@ -76,7 +76,7 @@ class ElasticsearchType_interaction_forum_post extends ElasticsearchType
}
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$sql = 'SELECT p.id, p.subject, p.body, i.group, p.deleted, p.ctime
FROM {interaction_forum_post} p
......
......@@ -81,7 +81,7 @@ class ElasticsearchType_interaction_instance extends ElasticsearchType
}
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$record = parent::getRecordById($type, $id);
if (!$record || $record->deleted) {
return false;
......
......@@ -90,7 +90,7 @@ class ElasticsearchType_usr extends ElasticsearchType
}
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$sql = 'SELECT u.id, u.username, u.preferredname, ap.value AS hidenamepref,
CASE ap.value WHEN \'1\' THEN NULL ELSE u.firstname END AS firstname,
CASE ap.value WHEN \'1\' THEN NULL ELSE u.lastname END AS lastname,
......
......@@ -142,7 +142,7 @@ class ElasticsearchType_view extends ElasticsearchType
}
public static function getRecordById($type, $id){
public static function getRecordById($type, $id, $map = null) {
$record = parent::getRecordById($type, $id);
if (!$record) {
return false;
......
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