PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.10
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.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 4 months ago auth_controller.php 4 months ago booking_form_settings_controller.php 5 months ago bookings_controller.php 1 year ago calendars_controller.php 9 months ago carts_controller.php 1 year ago controller.php 9 months ago customer_cabinet_controller.php 4 months ago customers_controller.php 4 months ago dashboard_controller.php 9 months ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 9 months ago integrations_controller.php 9 months ago invoices_controller.php 4 months ago manage_booking_by_key_controller.php 4 months ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 4 months ago pro_controller.php 1 year ago process_jobs_controller.php 4 months ago processes_controller.php 4 months ago search_controller.php 1 year ago services_controller.php 9 months ago settings_controller.php 4 months ago steps_controller.php 9 months ago stripe_connect_controller.php 9 months ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 4 months ago wizard_controller.php 4 months ago
process_jobs_controller.php
170 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 $this->check_nonce( 'cancel_job_' . $this->params['id'] );
95 $job = new OsProcessJobModel( $this->params['id'] );
96 if ( $job ) {
97 $job->update_attributes( [ 'status' => LATEPOINT_JOB_STATUS_CANCELLED ] );
98 }
99 if ( $this->get_return_format() == 'json' ) {
100 $this->send_json( [ 'status' => LATEPOINT_STATUS_SUCCESS, 'message' => __( 'Job cancelled', 'latepoint' ) ] );
101 }
102 }
103
104 public function index() {
105 $per_page = OsSettingsHelper::get_number_of_records_per_page();
106 $page_number = isset( $this->params['page_number'] ) ? $this->params['page_number'] : 1;
107
108
109 $query_args = [];
110
111 $jobs = new OsProcessJobModel();
112 $count_jobs = new OsProcessJobModel();
113
114 // TABLE SEARCH FILTERS
115 $filter = isset( $this->params['filter'] ) ? $this->params['filter'] : false;
116 if ( $filter ) {
117 if ( ! empty( $filter['process_id'] ) ) {
118 $query_args['process_id'] = $filter['process_id'];
119 }
120 if ( ! empty( $filter['status'] ) ) {
121 $query_args['status'] = $filter['status'];
122 }
123 if ( ! empty( $filter['object_id'] ) ) {
124 $query_args['object_id'] = $filter['object_id'];
125 }
126
127 if ( ! empty( $filter['to_run_after_utc_from'] ) && ! empty( $filter['to_run_after_utc_to'] ) ) {
128 $query_args['to_run_after_utc >='] = $filter['to_run_after_utc_from'];
129 $query_args['to_run_after_utc <='] = $filter['to_run_after_utc_to'];
130 }
131
132 if ( ! empty( $filter['event_type'] ) ) {
133 $jobs->select( LATEPOINT_TABLE_PROCESS_JOBS . '.*, ' . LATEPOINT_TABLE_PROCESSES . '.event_type' );
134 $jobs->join( LATEPOINT_TABLE_PROCESSES, [ 'id' => LATEPOINT_TABLE_PROCESS_JOBS . '.process_id' ] );
135 $count_jobs->select( LATEPOINT_TABLE_PROCESS_JOBS . '.*, ' . LATEPOINT_TABLE_PROCESSES . '.event_type' );
136 $count_jobs->join( LATEPOINT_TABLE_PROCESSES, [ 'id' => LATEPOINT_TABLE_PROCESS_JOBS . '.process_id' ] );
137 $query_args[ LATEPOINT_TABLE_PROCESSES . '.event_type' ] = $filter['event_type'];
138 }
139 }
140
141 $total_jobs = $count_jobs->where( $query_args )->count();
142
143 $jobs = $jobs->where( $query_args )->order_by( 'created_at desc' )->set_limit( $per_page );
144 if ( $page_number > 1 ) {
145 $jobs = $jobs->set_offset( ( $page_number - 1 ) * $per_page );
146 }
147
148
149 $this->vars['jobs'] = $jobs->get_results_as_models();
150
151 $this->vars['current_page_number'] = $page_number;
152 $this->vars['per_page'] = $per_page;
153 $total_pages = ceil( $total_jobs / $per_page );
154 $this->vars['total_pages'] = $total_pages;
155 $this->vars['total_records'] = $total_jobs;
156
157 $this->vars['showing_from'] = ( ( $page_number - 1 ) * $per_page ) ? ( ( $page_number - 1 ) * $per_page ) : 1;
158 $this->vars['showing_to'] = min( $page_number * $per_page, $total_jobs );
159
160
161 $this->format_render( [ 'json_view_name' => '_table_body', 'html_view_name' => __FUNCTION__ ], [], [ 'total_pages' => $total_pages,
162 'showing_from' => $this->vars['showing_from'],
163 'showing_to' => $this->vars['showing_to'],
164 'total_records' => $total_jobs
165 ] );
166 }
167
168 }
169
170 endif;