Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of using only watchdog, report tripal entities errors to php'… #142

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions includes/Elasticsearch/ESInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ESInstance {
* Establishes a connection to a host.
*
* @param null $host
*
* @throws \Exception
* @return void
*/
public function __construct($host = NULL) {
Expand Down Expand Up @@ -244,14 +244,9 @@ public function setTableSearchParams(
*
* @return $this
*/
public function setIndexParams(
$index_name,
$shards = 5,
$replicas = 0,
$tokenizer = 'standard',
$token_filters = [],
$field_mapping_types = []
) {
public function setIndexParams($index_name, $shards = 5, $replicas = 0,
$tokenizer = 'standard', $token_filters = [],
$field_mapping_types = []) {
$analysis = [
'analyzer' => [
$index_name => [
Expand Down Expand Up @@ -472,13 +467,7 @@ public function bulkUpdate($index, $entries, $type = NULL, $id_key = NULL) {
*
* @return array
*/
public function bulk(
$operation,
$index,
$entries,
$type = NULL,
$id_key = NULL
) {
public function bulk($operation, $index, $entries, $type = NULL, $id_key = NULL) {
if (count($entries) === 0) {
return [];
}
Expand Down Expand Up @@ -520,7 +509,7 @@ public function bulk(
* Paginate search results.
*
* @param $per_page
*
* @throws \Exception
* @return array
*/
public function paginate($per_page) {
Expand Down Expand Up @@ -555,6 +544,7 @@ public function getIndices() {
/**
* Get all available categories.
*
* @throws \Exception
* @return array
*/
public function getAllCategories($version = NULL) {
Expand Down Expand Up @@ -609,9 +599,10 @@ public function getIndexMappings($index) {
/**
* Returns results from all indices.
*
* @param $terms
* @param $size
*
* @param string $terms
* @param int $size
* @param string|null $category
* @throws \Exception
* @return array
*/
public function searchWebIndices($terms, $size, $category = NULL) {
Expand Down Expand Up @@ -684,8 +675,9 @@ public function deleteAllRecords($index_name, $type = NULL) {
/**
* Get a single record.
*
* @param $index
* @param $id
* @param string $index
* @param string $type
* @param int $id
*
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/Elasticsearch/ESQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function run($job) {
$job->handle();
$total = $job->total();
} catch (Exception $exception) {
watchdog('tripal_elasticsearch', $exception->getMessage(), [], WATCHDOG_ERROR);
tripal_report_error('tripal_elasticsearch', TRIPAL_ERROR, $exception->getMessage());
$total = $job->chunk ?: 1;
}

Expand Down
36 changes: 20 additions & 16 deletions includes/Jobs/EntitiesIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,24 @@ public function __construct($bundle, $entity_id = NULL, $round = 1) {
* Bulk index all entries if there are more than one.
*/
public function handle() {
$this->es = new ESInstance();
$records = $this->get();
$records = $this->loadContent($records);

if ($this->total > 1) {
if (!$this->shouldUpdate) {
$this->es->bulkIndex($this->index, $records, $this->index, 'entity_id');
try {
$this->es = new ESInstance();
$records = $this->get();
$records = $this->loadContent($records);

if ($this->total > 1) {
if (!$this->shouldUpdate) {
$this->es->bulkIndex($this->index, $records, $this->index, 'entity_id');
}
else {
$this->es->bulkUpdate($this->index, $records, $this->index, 'entity_id');
}
}
else {
$this->es->bulkUpdate($this->index, $records, $this->index, 'entity_id');
elseif (count($records) > 0) {
$this->es->createEntry($this->index, $this->index, $records[0]->entity_id, $records[0]);
}
}
elseif (count($records) > 0) {
$this->es->createEntry($this->index, $this->index, $records[0]->entity_id, $records[0]);
} catch (Exception $exception) {
tripal_report_error('tripal_elasticsearch', TRIPAL_ERROR, $exception->getMessage());
}
}

Expand Down Expand Up @@ -180,9 +184,9 @@ protected function loadContent($records) {
* @return array
*/
protected function getPriorityList($fields) {
// if ($this->id !== NULL) {
// return $this->getAllFields($fields);
// }
// if ($this->id !== NULL) {
// return $this->getAllFields($fields);
// }

return $this->prioritizeFields($fields);
}
Expand Down Expand Up @@ -241,7 +245,7 @@ protected function prioritizeFields($fields) {
// If we find a match for the priority round add to the should-be-indexed fields list
// Or if this is a single entity add all the fields to the list
if (isset($indexed[$id]) && ($indexed[$id] == $this->priority_round || $this->id !== NULL)) {
if($this->id !== null && $indexed[$id] == 0) {
if ($this->id !== NULL && $indexed[$id] == 0) {
// This field is not supposed to be indexed
continue;
}
Expand Down