PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / trunk
LatePoint – Calendar Booking Plugin for Appointments and Events vtrunk
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 month ago auth_controller.php 3 months ago booking_form_settings_controller.php 3 months ago bookings_controller.php 14 hours ago calendars_controller.php 3 months ago carts_controller.php 14 hours ago controller.php 3 months ago customer_cabinet_controller.php 2 months ago customers_controller.php 14 hours ago dashboard_controller.php 2 months ago default_agent_controller.php 3 months ago events_controller.php 3 months ago form_fields_controller.php 1 week ago integrations_controller.php 3 months ago invoices_controller.php 14 hours ago manage_booking_by_key_controller.php 3 months ago manage_order_by_key_controller.php 3 months ago notifications_controller.php 3 months ago orders_controller.php 14 hours ago pro_controller.php 2 weeks ago process_jobs_controller.php 3 months ago processes_controller.php 1 month ago razorpay_connect_controller.php 1 week ago search_controller.php 3 months ago services_controller.php 3 months ago settings_controller.php 2 months ago steps_controller.php 2 weeks ago stripe_connect_controller.php 1 week ago support_topics_controller.php 3 months ago todos_controller.php 3 months ago transactions_controller.php 14 hours ago wizard_controller.php 1 week ago
process_jobs_controller.php
191 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(
24 'label' => __( 'Process Jobs', 'latepoint' ),
25 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'process_jobs', 'index' ) ),
26 );
27 }
28
29 public function view_job_run_result() {
30 $job = new OsProcessJobModel( $this->params['id'] );
31 $data = json_decode( $job->run_result );
32 $process_info = json_decode( $job->process_info );
33
34 $this->vars['job'] = $job;
35 $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>';
36 $this->vars['content_html'] = '<pre class="format-json">' . $job->run_result . '</pre>';
37 $this->vars['process_name'] = __( 'Job Results', 'latepoint' );
38 $this->vars['status_html'] = '<div class="status-item">' . __( 'Status:', 'latepoint' ) . ' <strong>' . $data->status . '</strong></div>';
39 $this->vars['status_html'] .= '<div class="status-item">' . __( 'Processed on (UTC):', 'latepoint' ) . ' <strong>' . $data->run_datetime_utc . '</strong></div>';
40 $this->vars['status'] = $data->status;
41
42 $this->format_render( __FUNCTION__ );
43 }
44
45 public function preview_job_action() {
46
47 $job = new OsProcessJobModel( $this->params['job_id'] );
48 $action = $job->get_action_by_id_from_settings( $this->params['action_id'] );
49
50 $result_data = ! empty( $job->run_result ) ? json_decode( $job->run_result, true ) : [];
51
52
53 $status_html = '';
54 if ( ! empty( $result_data['ran_actions_info'] ) ) {
55 foreach ( $result_data['ran_actions_info'] as $ran_action_info ) {
56 if ( $ran_action_info['id'] == $action->id ) {
57 $status_html = '<div class="activity-status-wrapper status-' . $ran_action_info['run_status'] . '"><div class="activity-status-content">';
58 $status_html .= '<div class="status-item">' . __( 'Status:', 'latepoint' ) . ' <strong>' . $ran_action_info['run_status'] . '</strong></div>';
59 $status_html .= '<div class="status-item">' . __( 'Processed on:', 'latepoint' ) . ' <strong>' . $ran_action_info['run_datetime_utc'] . '</strong></div>';
60 if ( $ran_action_info['run_status'] == 'error' ) {
61 $status_html .= '<div class="status-item">' . __( 'Error:', 'latepoint' ) . ' <strong>' . $ran_action_info['run_message'] . '</strong></div>';
62 }
63 $status_html .= '</div></div>';
64 }
65 }
66 }
67
68 $this->vars['preview_html'] = $action->generate_preview();
69 $this->vars['action'] = $action;
70 $this->vars['action_status_html'] = $status_html;
71 $this->vars['job'] = $job;
72
73 $this->format_render( __FUNCTION__ );
74 }
75
76 public function run_job() {
77 if ( ! filter_var( $this->params['job_id'], FILTER_VALIDATE_INT ) ) {
78 return false;
79 }
80 $this->check_nonce( 'run_job_' . $this->params['job_id'] );
81 $action_ids = $this->params['action_ids'] ?? [];
82 $job = new OsProcessJobModel( $this->params['job_id'] );
83 if ( $job ) {
84 $job->run( $action_ids );
85 }
86 $result = json_decode( $job->run_result, true );
87
88 if ( $this->get_return_format() == 'json' ) {
89 $this->send_json(
90 [
91 'status' => $result['status'],
92 'message' => $result['message'],
93 ]
94 );
95 }
96 }
97
98 public function cancel() {
99 if ( ! filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
100 return false;
101 }
102 $this->check_nonce( 'cancel_job_' . $this->params['id'] );
103 $job = new OsProcessJobModel( $this->params['id'] );
104 if ( $job ) {
105 $job->update_attributes( [ 'status' => LATEPOINT_JOB_STATUS_CANCELLED ] );
106 }
107 if ( $this->get_return_format() == 'json' ) {
108 $this->send_json(
109 [
110 'status' => LATEPOINT_STATUS_SUCCESS,
111 'message' => __( 'Job cancelled', 'latepoint' ),
112 ]
113 );
114 }
115 }
116
117 public function index() {
118 $per_page = OsSettingsHelper::get_number_of_records_per_page();
119 $page_number = isset( $this->params['page_number'] ) ? $this->params['page_number'] : 1;
120
121
122 $query_args = [];
123
124 $jobs = new OsProcessJobModel();
125 $count_jobs = new OsProcessJobModel();
126
127 // TABLE SEARCH FILTERS
128 $filter = isset( $this->params['filter'] ) ? $this->params['filter'] : false;
129 if ( $filter ) {
130 if ( ! empty( $filter['process_id'] ) ) {
131 $query_args['process_id'] = $filter['process_id'];
132 }
133 if ( ! empty( $filter['status'] ) ) {
134 $query_args['status'] = $filter['status'];
135 }
136 if ( ! empty( $filter['object_id'] ) ) {
137 $query_args['object_id'] = $filter['object_id'];
138 }
139
140 if ( ! empty( $filter['to_run_after_utc_from'] ) && ! empty( $filter['to_run_after_utc_to'] ) ) {
141 $query_args['to_run_after_utc >='] = $filter['to_run_after_utc_from'];
142 $query_args['to_run_after_utc <='] = $filter['to_run_after_utc_to'];
143 }
144
145 if ( ! empty( $filter['event_type'] ) ) {
146 $jobs->select( LATEPOINT_TABLE_PROCESS_JOBS . '.*, ' . LATEPOINT_TABLE_PROCESSES . '.event_type' );
147 $jobs->join( LATEPOINT_TABLE_PROCESSES, [ 'id' => LATEPOINT_TABLE_PROCESS_JOBS . '.process_id' ] );
148 $count_jobs->select( LATEPOINT_TABLE_PROCESS_JOBS . '.*, ' . LATEPOINT_TABLE_PROCESSES . '.event_type' );
149 $count_jobs->join( LATEPOINT_TABLE_PROCESSES, [ 'id' => LATEPOINT_TABLE_PROCESS_JOBS . '.process_id' ] );
150 $query_args[ LATEPOINT_TABLE_PROCESSES . '.event_type' ] = $filter['event_type'];
151 }
152 }
153
154 $total_jobs = $count_jobs->where( $query_args )->count();
155
156 $jobs = $jobs->where( $query_args )->order_by( 'created_at desc' )->set_limit( $per_page );
157 if ( $page_number > 1 ) {
158 $jobs = $jobs->set_offset( ( $page_number - 1 ) * $per_page );
159 }
160
161
162 $this->vars['jobs'] = $jobs->get_results_as_models();
163
164 $this->vars['current_page_number'] = $page_number;
165 $this->vars['per_page'] = $per_page;
166 $total_pages = ceil( $total_jobs / $per_page );
167 $this->vars['total_pages'] = $total_pages;
168 $this->vars['total_records'] = $total_jobs;
169
170 $this->vars['showing_from'] = ( ( $page_number - 1 ) * $per_page ) ? ( ( $page_number - 1 ) * $per_page ) : 1;
171 $this->vars['showing_to'] = min( $page_number * $per_page, $total_jobs );
172
173
174 $this->format_render(
175 [
176 'json_view_name' => '_table_body',
177 'html_view_name' => __FUNCTION__,
178 ],
179 [],
180 [
181 'total_pages' => $total_pages,
182 'showing_from' => $this->vars['showing_from'],
183 'showing_to' => $this->vars['showing_to'],
184 'total_records' => $total_jobs,
185 ]
186 );
187 }
188 }
189
190 endif;
191