PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.5
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.5
5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / process_jobs_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 year ago auth_controller.php 10 months ago booking_form_settings_controller.php 1 year ago bookings_controller.php 1 year ago calendars_controller.php 11 months ago carts_controller.php 1 year ago controller.php 11 months ago customer_cabinet_controller.php 11 months ago customers_controller.php 10 months ago dashboard_controller.php 11 months ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 11 months ago integrations_controller.php 11 months ago invoices_controller.php 1 year ago manage_booking_by_key_controller.php 1 year ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 1 year ago pro_controller.php 1 year ago process_jobs_controller.php 11 months ago processes_controller.php 1 year ago search_controller.php 1 year ago services_controller.php 11 months ago settings_controller.php 1 year ago steps_controller.php 11 months ago stripe_connect_controller.php 10 months ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 1 year ago wizard_controller.php 1 year ago
process_jobs_controller.php
169 lines
1 <?php
2 /*
3 * Copyright (c) 2022 LatePoint LLC. All rights reserved.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10
11 if ( ! class_exists( 'OsProcessJobsController' ) ) :
12
13
14 class OsProcessJobsController extends OsController {
15
16 function __construct() {
17 parent::__construct();
18
19
20 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'process_jobs/';
21 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'processes' );
22 $this->vars['pre_page_header'] = OsMenuHelper::get_label_by_id( 'processes' );
23 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Process Jobs', 'latepoint' ), 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'process_jobs', 'index' ) ) );
24 }
25
26 public function view_job_run_result() {
27 $job = new OsProcessJobModel( $this->params['id'] );
28 $data = json_decode( $job->run_result );
29 $process_info = json_decode( $job->process_info );
30
31 $this->vars['job'] = $job;
32 $this->vars['meta_html'] = '<div class="activity-preview-to"><span class="os-label">' . __( 'Process:', 'latepoint' ) . '</span><span class="os-value">' . $process_info->name . '</span><span class="os-label">' . __( 'Trigger:', 'latepoint' ) . '</span><span class="os-value">' . \LatePoint\Misc\ProcessEvent::get_event_name_for_type( $process_info->event_type ) . '</span></div>';
33 $this->vars['content_html'] = '<pre class="format-json">' . $job->run_result . '</pre>';
34 $this->vars['process_name'] = __( 'Job Results', 'latepoint' );
35 $this->vars['status_html'] = '<div class="status-item">' . __( 'Status:', 'latepoint' ) . ' <strong>' . $data->status . '</strong></div>';
36 $this->vars['status_html'] .= '<div class="status-item">' . __( 'Processed on (UTC):', 'latepoint' ) . ' <strong>' . $data->run_datetime_utc . '</strong></div>';
37 $this->vars['status'] = $data->status;
38
39 $this->format_render( __FUNCTION__ );
40 }
41
42 public function preview_job_action() {
43
44 $job = new OsProcessJobModel( $this->params['job_id'] );
45 $action = $job->get_action_by_id_from_settings( $this->params['action_id'] );
46
47 $result_data = ! empty( $job->run_result ) ? json_decode( $job->run_result, true ) : [];
48
49
50 $status_html = '';
51 if ( ! empty( $result_data['ran_actions_info'] ) ) {
52 foreach ( $result_data['ran_actions_info'] as $ran_action_info ) {
53 if ( $ran_action_info['id'] == $action->id ) {
54 $status_html = '<div class="activity-status-wrapper status-' . $ran_action_info['run_status'] . '"><div class="activity-status-content">';
55 $status_html .= '<div class="status-item">' . __( 'Status:', 'latepoint' ) . ' <strong>' . $ran_action_info['run_status'] . '</strong></div>';
56 $status_html .= '<div class="status-item">' . __( 'Processed on:', 'latepoint' ) . ' <strong>' . $ran_action_info['run_datetime_utc'] . '</strong></div>';
57 if ( $ran_action_info['run_status'] == 'error' ) {
58 $status_html .= '<div class="status-item">' . __( 'Error:', 'latepoint' ) . ' <strong>' . $ran_action_info['run_message'] . '</strong></div>';
59 }
60 $status_html .= '</div></div>';
61 }
62 }
63 }
64
65 $this->vars['preview_html'] = $action->generate_preview();
66 $this->vars['action'] = $action;
67 $this->vars['action_status_html'] = $status_html;
68 $this->vars['job'] = $job;
69
70 $this->format_render( __FUNCTION__ );
71 }
72
73 public function run_job() {
74 if ( ! filter_var( $this->params['job_id'], FILTER_VALIDATE_INT ) ) {
75 return false;
76 }
77 $this->check_nonce( 'run_job_' . $this->params['job_id'] );
78 $action_ids = $this->params['action_ids'] ?? [];
79 $job = new OsProcessJobModel( $this->params['job_id'] );
80 if ( $job ) {
81 $job->run( $action_ids );
82 }
83 $result = json_decode( $job->run_result, true );
84
85 if ( $this->get_return_format() == 'json' ) {
86 $this->send_json( [ 'status' => $result['status'], 'message' => $result['message'] ] );
87 }
88 }
89
90 public function cancel() {
91 if ( ! filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
92 return false;
93 }
94 $job = new OsProcessJobModel( $this->params['id'] );
95 if ( $job ) {
96 $job->update_attributes( [ 'status' => LATEPOINT_JOB_STATUS_CANCELLED ] );
97 }
98 if ( $this->get_return_format() == 'json' ) {
99 $this->send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => __( 'Job cancelled', 'latepoint' ) ] );
100 }
101 }
102
103 public function index() {
104 $per_page = OsSettingsHelper::get_number_of_records_per_page();
105 $page_number = isset( $this->params['page_number'] ) ? $this->params['page_number'] : 1;
106
107
108 $query_args = [];
109
110 $jobs = new OsProcessJobModel();
111 $count_jobs = new OsProcessJobModel();
112
113 // TABLE SEARCH FILTERS
114 $filter = isset( $this->params['filter'] ) ? $this->params['filter'] : false;
115 if ( $filter ) {
116 if ( ! empty( $filter['process_id'] ) ) {
117 $query_args['process_id'] = $filter['process_id'];
118 }
119 if ( ! empty( $filter['status'] ) ) {
120 $query_args['status'] = $filter['status'];
121 }
122 if ( ! empty( $filter['object_id'] ) ) {
123 $query_args['object_id'] = $filter['object_id'];
124 }
125
126 if ( ! empty( $filter['to_run_after_utc_from'] ) && ! empty( $filter['to_run_after_utc_to'] ) ) {
127 $query_args['to_run_after_utc >='] = $filter['to_run_after_utc_from'];
128 $query_args['to_run_after_utc <='] = $filter['to_run_after_utc_to'];
129 }
130
131 if ( ! empty( $filter['event_type'] ) ) {
132 $jobs->select( LATEPOINT_TABLE_PROCESS_JOBS . '.*, ' . LATEPOINT_TABLE_PROCESSES . '.event_type' );
133 $jobs->join( LATEPOINT_TABLE_PROCESSES, [ 'id' => LATEPOINT_TABLE_PROCESS_JOBS . '.process_id' ] );
134 $count_jobs->select( LATEPOINT_TABLE_PROCESS_JOBS . '.*, ' . LATEPOINT_TABLE_PROCESSES . '.event_type' );
135 $count_jobs->join( LATEPOINT_TABLE_PROCESSES, [ 'id' => LATEPOINT_TABLE_PROCESS_JOBS . '.process_id' ] );
136 $query_args[ LATEPOINT_TABLE_PROCESSES . '.event_type' ] = $filter['event_type'];
137 }
138 }
139
140 $total_jobs = $count_jobs->where( $query_args )->count();
141
142 $jobs = $jobs->where( $query_args )->order_by( 'created_at desc' )->set_limit( $per_page );
143 if ( $page_number > 1 ) {
144 $jobs = $jobs->set_offset( ( $page_number - 1 ) * $per_page );
145 }
146
147
148 $this->vars['jobs'] = $jobs->get_results_as_models();
149
150 $this->vars['current_page_number'] = $page_number;
151 $this->vars['per_page'] = $per_page;
152 $total_pages = ceil( $total_jobs / $per_page );
153 $this->vars['total_pages'] = $total_pages;
154 $this->vars['total_records'] = $total_jobs;
155
156 $this->vars['showing_from'] = ( ( $page_number - 1 ) * $per_page ) ? ( ( $page_number - 1 ) * $per_page ) : 1;
157 $this->vars['showing_to'] = min( $page_number * $per_page, $total_jobs );
158
159
160 $this->format_render( [ 'json_view_name' => '_table_body', 'html_view_name' => __FUNCTION__ ], [], [ 'total_pages' => $total_pages,
161 'showing_from' => $this->vars['showing_from'],
162 'showing_to' => $this->vars['showing_to'],
163 'total_records' => $total_jobs
164 ] );
165 }
166
167 }
168
169 endif;