Skip to content

Commit

Permalink
Merge pull request #113 from tripal/uninstall-script
Browse files Browse the repository at this point in the history
Uninstall db tables when running pm-uninstall
  • Loading branch information
almasaeed2010 authored Dec 8, 2017
2 parents 42ad2cf + c12c714 commit 8a50e04
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
12 changes: 6 additions & 6 deletions includes/Elasticsearch/ESQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function progress() {
MIN(started_at) AS started_at
FROM {' . self::QUEUE_TABLE . '}
GROUP BY index_name, priority
ORDER BY index_name ASC';
ORDER BY index_name ASC, priority ASC';
$queues = db_query($query)->fetchAll();

$progress = [];
Expand All @@ -72,9 +72,9 @@ public static function progress() {
$progress_started_at = time();

foreach ($queues as $queue) {
if ($queue->total === $queue->completed) {
continue;
}
// if ($queue->total === $queue->completed) {
// continue;
// }

$last_run = new DateTime();
$last_run->setTimestamp($queue->last_run_at);
Expand All @@ -87,7 +87,7 @@ public static function progress() {

$total += $queue->total;
$completed += $queue->completed;
$round_name = ' Round: ' . ($queue->priority === 1 ? 'High' : 'Low');
$round_name = ' Round: ' . (intval($queue->priority) === 1 ? 'High' : 'Low');
$progress[$queue->index_name . $round_name] = (object) [
'total' => $queue->total,
'completed' => $queue->completed,
Expand All @@ -96,6 +96,7 @@ public static function progress() {
'last_run_at' => $last_run,
'started_at' => $started_at,
'time' => $queue->last_run_at - $queue->started_at,
'priority' => $queue->priority
];
}

Expand Down Expand Up @@ -180,7 +181,6 @@ public static function initProgress(
if ($queue) {
return db_query('UPDATE {' . $counter_table . '} SET total=:total, last_run_at=:time, completed=:completed, started_at=:started_at WHERE type=:type', [
':type' => $type,
':index_name' => $index_name,
':total' => $total,
':completed' => 0,
':time' => time(),
Expand Down
6 changes: 5 additions & 1 deletion includes/indices_management.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ function tripal_elasticsearch_progress_page($callback = FALSE) {

$data = ESQueue::progress();

if(!$callback) {
dpm($data);
}

$content .= '<h3>Overall Progress</h3>';

if ($data->remaining === 0) {
Expand Down Expand Up @@ -954,7 +958,7 @@ function tripal_elasticsearch_update_index_table(&$values) {
$index_name = $values['index_name'];
$index_table = $values['table_name'];
$exposed = $values['exposed'] ? 1 : 0;
$url = $values['url'];
$url = isset($values['url']) ? $values['url'] : '';

try {
db_update('tripal_elasticsearch_indices')->fields([
Expand Down
20 changes: 20 additions & 0 deletions tripal_elasticsearch.install
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,26 @@ function tripal_elasticsearch_schema() {
return $schema;
}

/**
* Uninstall
*/
function tripal_elasticsearch_uninstall() {
// Get the schema
$schema = tripal_elasticsearch_schema();

// Auto drop anything in the schema
foreach ($schema as $table => $fields) {
if(db_table_exists($table)) {
db_drop_table($table);
}
}

// Drop tables that are created in the update functions
if(db_table_exists('tripal_elasticsearch_indices')) {
db_drop_table('tripal_elasticsearch_indices');
}
}

/**
* Run updates on install
*/
Expand Down
1 change: 1 addition & 0 deletions tripal_elasticsearch.module
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ function tripal_elasticsearch_web_search_results_page_callback($node_type = ''
$results = $es->setWebsiteSearchParams($keyword, $node_type, implode(',', $index_name), '')
->paginate($per_page);
} catch (\Exception $e) {
tripal_report_error('tripal_elasticsearch', TRIPAL_ERROR, $e->getMessage());
return 'Searching is not available. Please try later.';
}

Expand Down

0 comments on commit 8a50e04

Please sign in to comment.