Merge from importer status
This commit is contained in:
commit
945cbf661e
|
@ -177,6 +177,7 @@
|
|||
class="actions-cell column-small-width"
|
||||
:label="$i18n.get('label_status')">
|
||||
<div class="actions-container">
|
||||
<span class="label-status">{{ getStatusLabel(bgProcess.status) }}</span>
|
||||
<span
|
||||
v-if="bgProcess.done <= 0"
|
||||
class="icon has-text-success loading-icon">
|
||||
|
@ -188,7 +189,7 @@
|
|||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if="bgProcess.done <= 0"
|
||||
v-if=" bgProcess.status === 'running' "
|
||||
class="icon has-text-gray action-icon"
|
||||
@click="pauseProcess(index)">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-stop"/>
|
||||
|
@ -199,9 +200,42 @@
|
|||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if="bgProcess.done > 0 && !bgProcess.error_log"
|
||||
v-if=" bgProcess.status === 'finished' || bgProcess.status === null"
|
||||
class="icon has-text-success">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-finish"/>
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-approvedcircle"/>
|
||||
</span>
|
||||
<span
|
||||
v-tooltip="{
|
||||
content: $i18n.get('label_process_completed_with_errors'),
|
||||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if=" bgProcess.status === 'finished-errors' "
|
||||
class="icon has-text-success">
|
||||
<i
|
||||
style="margin-right: -5px;"
|
||||
class="tainacan-icon tainacan-icon-20px tainacan-icon-alert"/>
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-approvedcircle"/>
|
||||
</span>
|
||||
<span
|
||||
v-tooltip="{
|
||||
content: $i18n.get('label_process_cancelled'),
|
||||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if=" bgProcess.status === 'cancelled' "
|
||||
class="icon has-text-success">
|
||||
<i class="tainacan-icon has-text-danger tainacan-icon-20px tainacan-icon-repprovedcircle"/>
|
||||
</span>
|
||||
<span
|
||||
v-tooltip="{
|
||||
content: $i18n.get('label_process_paused'),
|
||||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if=" bgProcess.status === 'paused' "
|
||||
class="icon has-text-success">
|
||||
<i class="tainacan-icon has-text-danger tainacan-icon-20px tainacan-icon-pause"/>
|
||||
</span>
|
||||
<span
|
||||
v-tooltip="{
|
||||
|
@ -209,7 +243,7 @@
|
|||
autoHide: false,
|
||||
placement: 'auto-start'
|
||||
}"
|
||||
v-if="bgProcess.done > 0 && bgProcess.error_log"
|
||||
v-if="bgProcess.status === 'errored'"
|
||||
class="icon has-text-danger">
|
||||
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-processerror" />
|
||||
</span>
|
||||
|
@ -358,7 +392,46 @@
|
|||
}
|
||||
},
|
||||
pauseProcess(index) {
|
||||
this.updateProcess({ id: this.processes[index].ID, status: 'closed' });
|
||||
|
||||
this.$modal.open({
|
||||
parent: this,
|
||||
component: CustomDialog,
|
||||
props: {
|
||||
icon: 'alert',
|
||||
title: this.$i18n.get('label_warning'),
|
||||
message: this.$i18n.get('info_warning_process_cancelled'),
|
||||
onConfirm: () => {
|
||||
this.updateProcess({ id: this.processes[index].ID, status: 'closed' });
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
getStatusLabel(status) {
|
||||
|
||||
switch(status) {
|
||||
case 'finished':
|
||||
return this.$i18n.get('info_process_status_finished');
|
||||
|
||||
case 'finished-errors':
|
||||
return this.$i18n.get('info_process_status_finished');
|
||||
|
||||
case 'errored':
|
||||
return this.$i18n.get('info_process_status_errored');
|
||||
|
||||
case 'cancelled':
|
||||
return this.$i18n.get('info_process_status_cancelled');
|
||||
|
||||
case 'paused':
|
||||
return this.$i18n.get('info_process_status_paused');
|
||||
|
||||
case 'running':
|
||||
return this.$i18n.get('info_process_status_running');
|
||||
|
||||
default:
|
||||
return this.$i18n.get('info_process_status_finished');
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -395,6 +468,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
.label-status {
|
||||
font-size: 9pt;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.loading-icon .control.is-loading::after {
|
||||
position: relative !important;
|
||||
right: 0;
|
||||
|
|
|
@ -300,6 +300,9 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'label_last_processed_on' => __( 'Last processed on:', 'tainacan' ),
|
||||
'label_progress' => __( 'Progress', 'tainacan' ),
|
||||
'label_process_completed' => __( 'Process completed', 'tainacan' ),
|
||||
'label_process_completed_with_errors' => __( 'Process completed with errors', 'tainacan' ),
|
||||
'label_process_cancelled' => __( 'Process cancelled by user', 'tainacan' ),
|
||||
'label_process_paused' => __( 'Process paused', 'tainacan' ),
|
||||
'label_stop_process' => __( 'Stop process', 'tainacan' ),
|
||||
'label_process_failed' => __( 'Process failed', 'tainacan' ),
|
||||
'label_max_options_to_show' => __( 'Max options to show', 'tainacan' ),
|
||||
|
@ -512,6 +515,14 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'info_leaving_bulk_edition' => __( 'You are leaving the bulk edition now.', 'tainacan' ),
|
||||
'info_current_view_mode_metadata_not_allowed' => __( 'Current view mode does not allow displayed metadata selection.', 'tainacan' ),
|
||||
'info_cant_select_metadata_without_items' => __( 'Can not select displayed metadata without items on list.', 'tainacan' ),
|
||||
'info_available_exporters_helper' => __( '?', 'tainacan' ),
|
||||
'info_process_status_finished' => __('Finished', 'tainacan'),
|
||||
'info_process_status_finished_errors' => __('Finished with errors', 'tainacan'),
|
||||
'info_process_status_errored' => __('Failed', 'tainacan'),
|
||||
'info_process_status_cancelled' => __('Cancelled', 'tainacan'),
|
||||
'info_process_status_paused' => __('Paused', 'tainacan'),
|
||||
'info_process_status_running' => __('Running', 'tainacan'),
|
||||
'info_warning_process_cancelled' => __( 'Are you sure? This process will be cancelled', 'tainacan' ),
|
||||
'info_empty' => __( 'empty', 'tainacan' ),
|
||||
'info_url_copied' => __( 'URL link copied', 'tainacan' ),
|
||||
'info_other_item_listing_options' => __('Other items listing options: ', 'tainacan'),
|
||||
|
|
|
@ -221,8 +221,37 @@ class REST_Background_Processes_Controller extends REST_Controller {
|
|||
if ( $body['status'] == 'open' ) {
|
||||
$status_q = "done = 0";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'closed' ) {
|
||||
$status_q = "done = 1";
|
||||
$status_q = "done = 1, status = 'cancelled'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'waiting' ) {
|
||||
$status_q = "done = 1, status = 'waiting'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'running' ) {
|
||||
$status_q = "done = 1, status = 'running'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'paused' ) {
|
||||
$status_q = "done = 1, status = 'paused'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'cancelled' ) {
|
||||
$status_q = "done = 1, status = 'cancelled'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'errored' ) {
|
||||
$status_q = "done = 1, status = 'errored'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'finished' ) {
|
||||
$status_q = "done = 1, status = 'finished'";
|
||||
}
|
||||
|
||||
if ( $body['status'] == 'finished-errors' ) {
|
||||
$status_q = "done = 1, status = 'finished-errors'";
|
||||
}
|
||||
|
||||
$id_q = $wpdb->prepare("AND ID = %d", $id);
|
||||
|
|
|
@ -120,7 +120,8 @@ abstract class Background_Process extends \WP_Background_Process {
|
|||
'priority' => $priority,
|
||||
'action' => $this->action,
|
||||
'name' => $this->get_name(),
|
||||
'queued_on' => date('Y-m-d H:i:s')
|
||||
'queued_on' => date('Y-m-d H:i:s'),
|
||||
'status' => 'running'
|
||||
]
|
||||
);
|
||||
$this->ID = $wpdb->insert_id;
|
||||
|
@ -173,7 +174,8 @@ abstract class Background_Process extends \WP_Background_Process {
|
|||
[
|
||||
'done' => 1,
|
||||
'progress_label' => __('Process completed','tainacan'),
|
||||
'progress_value' => 100
|
||||
'progress_value' => 100,
|
||||
'status' => 'finished'
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
|
|
|
@ -39,24 +39,26 @@ class Background_Importer extends Background_Process {
|
|||
$this->write_log($key, $object->get_log());
|
||||
$this->write_error_log($key, $object->get_error_log());
|
||||
|
||||
$batch->progress_label = $object->get_progress_label();
|
||||
$batch->progress_value = $object->get_progress_value();
|
||||
|
||||
$batch->data = $object->_to_Array(true);
|
||||
|
||||
if( count($object->get_error_log()) > 0 ){
|
||||
$this->set_finish_status(2);
|
||||
}
|
||||
|
||||
if (true === $object->get_abort()) {
|
||||
$this->set_finish_status(3);
|
||||
$this->close($key);
|
||||
throw new \Exception('Process aborted by Importer');
|
||||
}
|
||||
|
||||
if (false === $runned) {
|
||||
$this->update($key, $batch);
|
||||
return false;
|
||||
}
|
||||
|
||||
$batch->progress_label = $object->get_progress_label();
|
||||
$batch->progress_value = $object->get_progress_value();
|
||||
|
||||
$batch->data = $object->_to_Array(true);
|
||||
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
@ -78,32 +80,56 @@ class Background_Importer extends Background_Process {
|
|||
|
||||
switch ($this->finish_status){
|
||||
case 1:
|
||||
$label = __('Process completed','tainacan');
|
||||
$wpdb->update(
|
||||
$this->table,
|
||||
[
|
||||
'done' => 1,
|
||||
'progress_label' => __('Process completed','tainacan'),
|
||||
'progress_value' => 100,
|
||||
'status' => 'finished'
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$label = __('Process completed with errors','tainacan');
|
||||
$wpdb->update(
|
||||
$this->table,
|
||||
[
|
||||
'done' => 1,
|
||||
'progress_label' => __('Process completed with errors','tainacan'),
|
||||
'progress_value' => 100,
|
||||
'status' => 'finished'
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$label = __('Process aborted by Importer','tainacan');
|
||||
$wpdb->update(
|
||||
$this->table,
|
||||
[
|
||||
'done' => 1,
|
||||
'progress_label' => __('Process aborted by Importer','tainacan'),
|
||||
'status' => 'errored'
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
$label = __('Process completed','tainacan');
|
||||
$wpdb->update(
|
||||
$this->table,
|
||||
[
|
||||
'done' => 1,
|
||||
'progress_label' => __('Process completed','tainacan'),
|
||||
'status' => 'finished'
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$wpdb->update(
|
||||
$this->table,
|
||||
[
|
||||
'done' => 1,
|
||||
'progress_label' => $label,
|
||||
'progress_value' => 100
|
||||
],
|
||||
['ID' => $key]
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ class Migrations {
|
|||
done boolean not null default 0,
|
||||
progress_label text,
|
||||
progress_value int,
|
||||
status ENUM('waiting','running','paused','cancelled','errored','finished','finished-errors')
|
||||
PRIMARY KEY (ID),
|
||||
KEY user_id (user_id),
|
||||
KEY action (action($max_index_length))
|
||||
|
@ -70,8 +71,6 @@ class Migrations {
|
|||
ADD name text NOT NULL
|
||||
");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static function add_output_column_to_bg_process() {
|
||||
|
@ -87,6 +86,20 @@ class Migrations {
|
|||
}
|
||||
}
|
||||
|
||||
static function create_importer_status_column(){
|
||||
global $wpdb;
|
||||
|
||||
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'status'" );
|
||||
|
||||
if(empty($column_exists)) {
|
||||
$wpdb->query("
|
||||
ALTER TABLE {$wpdb->prefix}tnc_bg_process
|
||||
ADD status ENUM('waiting','running','paused','cancelled','errored','finished','finished-errors')
|
||||
");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static function init_capabilites() {
|
||||
$Tainacan_Capabilities = \Tainacan\Capabilities::get_instance();
|
||||
$Tainacan_Capabilities->init();
|
||||
|
|
Loading…
Reference in New Issue