@@ -15,80 +15,80 @@ |
||
15 | 15 | class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Arguments that will be passed into the select2 javascript constructor |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $_select2_js_args = array(); |
|
18 | + /** |
|
19 | + * Arguments that will be passed into the select2 javascript constructor |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $_select2_js_args = array(); |
|
23 | 23 | |
24 | - /** |
|
25 | - * |
|
26 | - * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
|
27 | - * to pass into the select2 js/html input. See https://select2.github.io |
|
28 | - */ |
|
29 | - public function __construct($select2_js_args = array()) |
|
30 | - { |
|
31 | - $this->_select2_js_args = $select2_js_args; |
|
32 | - parent::__construct(); |
|
33 | - } |
|
24 | + /** |
|
25 | + * |
|
26 | + * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
|
27 | + * to pass into the select2 js/html input. See https://select2.github.io |
|
28 | + */ |
|
29 | + public function __construct($select2_js_args = array()) |
|
30 | + { |
|
31 | + $this->_select2_js_args = $select2_js_args; |
|
32 | + parent::__construct(); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * enqueues the select2 initializing js (which depends on the select2 js) and |
|
37 | - * the select2 css |
|
38 | - */ |
|
39 | - public function enqueue_js() |
|
40 | - { |
|
41 | - // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
|
42 | - // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
|
43 | - wp_deregister_script('select2'); |
|
44 | - wp_deregister_style('select2'); |
|
45 | - wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | - wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | - wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
48 | - wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
49 | - } |
|
35 | + /** |
|
36 | + * enqueues the select2 initializing js (which depends on the select2 js) and |
|
37 | + * the select2 css |
|
38 | + */ |
|
39 | + public function enqueue_js() |
|
40 | + { |
|
41 | + // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
|
42 | + // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
|
43 | + wp_deregister_script('select2'); |
|
44 | + wp_deregister_style('select2'); |
|
45 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
48 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Gets the javascript args which will be localized and passed into the select2 js/html input |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function get_js_args() |
|
56 | - { |
|
57 | - return $this->_select2_js_args; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Gets the javascript args which will be localized and passed into the select2 js/html input |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function get_js_args() |
|
56 | + { |
|
57 | + return $this->_select2_js_args; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Sets the exact js args which will be passed into the select2 js/html input |
|
62 | - * @param array $js_args |
|
63 | - */ |
|
64 | - public function set_js_args($js_args) |
|
65 | - { |
|
66 | - $this->_select2_js_args = $js_args; |
|
67 | - } |
|
60 | + /** |
|
61 | + * Sets the exact js args which will be passed into the select2 js/html input |
|
62 | + * @param array $js_args |
|
63 | + */ |
|
64 | + public function set_js_args($js_args) |
|
65 | + { |
|
66 | + $this->_select2_js_args = $js_args; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Adds select2 data for localization |
|
71 | - * @param array $other_js_data |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function get_other_js_data($other_js_data = array()) |
|
75 | - { |
|
76 | - $other_js_data = parent::get_other_js_data($other_js_data); |
|
77 | - if (! isset($other_js_data['select2s'])) { |
|
78 | - $other_js_data['select2s'] = array(); |
|
79 | - } |
|
80 | - $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
81 | - return $other_js_data; |
|
82 | - } |
|
69 | + /** |
|
70 | + * Adds select2 data for localization |
|
71 | + * @param array $other_js_data |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function get_other_js_data($other_js_data = array()) |
|
75 | + { |
|
76 | + $other_js_data = parent::get_other_js_data($other_js_data); |
|
77 | + if (! isset($other_js_data['select2s'])) { |
|
78 | + $other_js_data['select2s'] = array(); |
|
79 | + } |
|
80 | + $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
81 | + return $other_js_data; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Overrides standard attributes array to add the CSS class "ee-select2" |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - protected function _standard_attributes_array() |
|
89 | - { |
|
90 | - $standard_attributes = parent::_standard_attributes_array(); |
|
91 | - $standard_attributes['class'] .= ' ee-select2'; |
|
92 | - return $standard_attributes; |
|
93 | - } |
|
84 | + /** |
|
85 | + * Overrides standard attributes array to add the CSS class "ee-select2" |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + protected function _standard_attributes_array() |
|
89 | + { |
|
90 | + $standard_attributes = parent::_standard_attributes_array(); |
|
91 | + $standard_attributes['class'] .= ' ee-select2'; |
|
92 | + return $standard_attributes; |
|
93 | + } |
|
94 | 94 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
43 | 43 | wp_deregister_script('select2'); |
44 | 44 | wp_deregister_style('select2'); |
45 | - wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | - wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | - wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
48 | - wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
45 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL.'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL.'scripts/form_section_select2_init.js', array('select2'), '1.0.0', true); |
|
48 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | public function get_other_js_data($other_js_data = array()) |
75 | 75 | { |
76 | 76 | $other_js_data = parent::get_other_js_data($other_js_data); |
77 | - if (! isset($other_js_data['select2s'])) { |
|
77 | + if ( ! isset($other_js_data['select2s'])) { |
|
78 | 78 | $other_js_data['select2s'] = array(); |
79 | 79 | } |
80 | - $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
80 | + $other_js_data['select2s'][$this->_input->html_id()] = $this->get_js_args(); |
|
81 | 81 | return $other_js_data; |
82 | 82 | } |
83 | 83 |
@@ -25,215 +25,215 @@ |
||
25 | 25 | */ |
26 | 26 | class BatchRequestProcessor |
27 | 27 | { |
28 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
29 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
30 | - /** |
|
31 | - * Current job's ID (if assigned) |
|
32 | - * |
|
33 | - * @var string|null |
|
34 | - */ |
|
35 | - protected $_job_id; |
|
28 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
29 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
30 | + /** |
|
31 | + * Current job's ID (if assigned) |
|
32 | + * |
|
33 | + * @var string|null |
|
34 | + */ |
|
35 | + protected $_job_id; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Current job's parameters |
|
39 | - * |
|
40 | - * @var JobParameters|null |
|
41 | - */ |
|
42 | - protected $_job_parameters; |
|
43 | - /** |
|
44 | - * @var LoaderInterface |
|
45 | - */ |
|
46 | - private $loader; |
|
37 | + /** |
|
38 | + * Current job's parameters |
|
39 | + * |
|
40 | + * @var JobParameters|null |
|
41 | + */ |
|
42 | + protected $_job_parameters; |
|
43 | + /** |
|
44 | + * @var LoaderInterface |
|
45 | + */ |
|
46 | + private $loader; |
|
47 | 47 | |
48 | - /** |
|
49 | - * BatchRequestProcessor constructor. |
|
50 | - * @param LoaderInterface $loader |
|
51 | - */ |
|
52 | - public function __construct(LoaderInterface $loader) |
|
53 | - { |
|
54 | - $this->loader = $loader; |
|
55 | - } |
|
56 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | - /** |
|
58 | - * Creates a job for the specified batch handler class (which should be autoloaded) |
|
59 | - * and the specified request data |
|
60 | - * |
|
61 | - * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
62 | - * @param array $request_data to be used by the batch job handler |
|
63 | - * @return JobStepResponse |
|
64 | - */ |
|
65 | - public function create_job($batch_job_handler_class, $request_data) |
|
66 | - { |
|
67 | - try { |
|
68 | - $this->_job_id = wp_generate_password(15, false); |
|
69 | - $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
70 | - $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
71 | - $response = $obj->create_job($this->_job_parameters); |
|
72 | - if (! $response instanceof JobStepResponse) { |
|
73 | - throw new BatchRequestException( |
|
74 | - sprintf( |
|
75 | - __( |
|
76 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - wp_json_encode($request_data) |
|
80 | - ) |
|
81 | - ); |
|
82 | - } |
|
83 | - $success = $this->_job_parameters->save(true); |
|
84 | - if (! $success) { |
|
85 | - throw new BatchRequestException( |
|
86 | - sprintf( |
|
87 | - __( |
|
88 | - 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - $this->_job_id, |
|
92 | - wp_json_encode($request_data) |
|
93 | - ) |
|
94 | - ); |
|
95 | - } |
|
96 | - } catch (\Exception $e) { |
|
97 | - $response = $this->_get_error_response($e, 'create_job'); |
|
98 | - } |
|
99 | - return $response; |
|
100 | - } |
|
48 | + /** |
|
49 | + * BatchRequestProcessor constructor. |
|
50 | + * @param LoaderInterface $loader |
|
51 | + */ |
|
52 | + public function __construct(LoaderInterface $loader) |
|
53 | + { |
|
54 | + $this->loader = $loader; |
|
55 | + } |
|
56 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | + /** |
|
58 | + * Creates a job for the specified batch handler class (which should be autoloaded) |
|
59 | + * and the specified request data |
|
60 | + * |
|
61 | + * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
62 | + * @param array $request_data to be used by the batch job handler |
|
63 | + * @return JobStepResponse |
|
64 | + */ |
|
65 | + public function create_job($batch_job_handler_class, $request_data) |
|
66 | + { |
|
67 | + try { |
|
68 | + $this->_job_id = wp_generate_password(15, false); |
|
69 | + $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
70 | + $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
71 | + $response = $obj->create_job($this->_job_parameters); |
|
72 | + if (! $response instanceof JobStepResponse) { |
|
73 | + throw new BatchRequestException( |
|
74 | + sprintf( |
|
75 | + __( |
|
76 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + wp_json_encode($request_data) |
|
80 | + ) |
|
81 | + ); |
|
82 | + } |
|
83 | + $success = $this->_job_parameters->save(true); |
|
84 | + if (! $success) { |
|
85 | + throw new BatchRequestException( |
|
86 | + sprintf( |
|
87 | + __( |
|
88 | + 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + $this->_job_id, |
|
92 | + wp_json_encode($request_data) |
|
93 | + ) |
|
94 | + ); |
|
95 | + } |
|
96 | + } catch (\Exception $e) { |
|
97 | + $response = $this->_get_error_response($e, 'create_job'); |
|
98 | + } |
|
99 | + return $response; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Retrieves the job's arguments |
|
105 | - * |
|
106 | - * @param string $job_id |
|
107 | - * @param int $batch_size |
|
108 | - * @return JobStepResponse |
|
109 | - */ |
|
110 | - public function continue_job($job_id, $batch_size = 50) |
|
111 | - { |
|
112 | - try { |
|
113 | - $this->_job_id = $job_id; |
|
114 | - $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
115 | - // get the corresponding WordPress option for the job |
|
116 | - $this->_job_parameters = JobParameters::load($this->_job_id); |
|
117 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
118 | - // continue it |
|
119 | - $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
120 | - if (! $response instanceof JobStepResponse) { |
|
121 | - throw new BatchRequestException( |
|
122 | - sprintf( |
|
123 | - __( |
|
124 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - $this->_job_id |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - $this->_job_parameters->save(); |
|
132 | - } catch (\Exception $e) { |
|
133 | - $response = $this->_get_error_response($e, 'continue_job'); |
|
134 | - } |
|
135 | - return $response; |
|
136 | - } |
|
103 | + /** |
|
104 | + * Retrieves the job's arguments |
|
105 | + * |
|
106 | + * @param string $job_id |
|
107 | + * @param int $batch_size |
|
108 | + * @return JobStepResponse |
|
109 | + */ |
|
110 | + public function continue_job($job_id, $batch_size = 50) |
|
111 | + { |
|
112 | + try { |
|
113 | + $this->_job_id = $job_id; |
|
114 | + $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
115 | + // get the corresponding WordPress option for the job |
|
116 | + $this->_job_parameters = JobParameters::load($this->_job_id); |
|
117 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
118 | + // continue it |
|
119 | + $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
120 | + if (! $response instanceof JobStepResponse) { |
|
121 | + throw new BatchRequestException( |
|
122 | + sprintf( |
|
123 | + __( |
|
124 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + $this->_job_id |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + $this->_job_parameters->save(); |
|
132 | + } catch (\Exception $e) { |
|
133 | + $response = $this->_get_error_response($e, 'continue_job'); |
|
134 | + } |
|
135 | + return $response; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Instantiates an object of type $classname, which implements |
|
141 | - * JobHandlerInterface |
|
142 | - * |
|
143 | - * @param string $classname |
|
144 | - * @return JobHandlerInterface |
|
145 | - * @throws BatchRequestException |
|
146 | - */ |
|
147 | - public function instantiate_batch_job_handler_from_classname($classname) |
|
148 | - { |
|
149 | - if (! class_exists($classname)) { |
|
150 | - throw new BatchRequestException( |
|
151 | - sprintf( |
|
152 | - __( |
|
153 | - 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - $classname |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - $obj = $this->loader->getNew($classname); |
|
161 | - if (! $obj instanceof JobHandlerInterface) { |
|
162 | - throw new BatchRequestException( |
|
163 | - sprintf( |
|
164 | - __( |
|
165 | - 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
166 | - 'event_espresso' |
|
167 | - ), |
|
168 | - $classname |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - return $obj; |
|
173 | - } |
|
139 | + /** |
|
140 | + * Instantiates an object of type $classname, which implements |
|
141 | + * JobHandlerInterface |
|
142 | + * |
|
143 | + * @param string $classname |
|
144 | + * @return JobHandlerInterface |
|
145 | + * @throws BatchRequestException |
|
146 | + */ |
|
147 | + public function instantiate_batch_job_handler_from_classname($classname) |
|
148 | + { |
|
149 | + if (! class_exists($classname)) { |
|
150 | + throw new BatchRequestException( |
|
151 | + sprintf( |
|
152 | + __( |
|
153 | + 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + $classname |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + $obj = $this->loader->getNew($classname); |
|
161 | + if (! $obj instanceof JobHandlerInterface) { |
|
162 | + throw new BatchRequestException( |
|
163 | + sprintf( |
|
164 | + __( |
|
165 | + 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
166 | + 'event_espresso' |
|
167 | + ), |
|
168 | + $classname |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + return $obj; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | - /** |
|
177 | - * Forces a job to be cleaned up |
|
178 | - * |
|
179 | - * @param string $job_id |
|
180 | - * @return JobStepResponse |
|
181 | - * @throws BatchRequestException |
|
182 | - */ |
|
183 | - public function cleanup_job($job_id) |
|
184 | - { |
|
185 | - try { |
|
186 | - $this->_job_id = $job_id; |
|
187 | - $job_parameters = JobParameters::load($this->_job_id); |
|
188 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
189 | - // continue it |
|
190 | - $response = $handler_obj->cleanup_job($job_parameters); |
|
191 | - if (! $response instanceof JobStepResponse) { |
|
192 | - throw new BatchRequestException( |
|
193 | - sprintf( |
|
194 | - __( |
|
195 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - $this->_job_id |
|
199 | - ) |
|
200 | - ); |
|
201 | - } |
|
202 | - $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
203 | - $job_parameters->delete(); |
|
204 | - return $response; |
|
205 | - } catch (\Exception $e) { |
|
206 | - $response = $this->_get_error_response($e, 'cleanup_job'); |
|
207 | - } |
|
208 | - return $response; |
|
209 | - } |
|
176 | + /** |
|
177 | + * Forces a job to be cleaned up |
|
178 | + * |
|
179 | + * @param string $job_id |
|
180 | + * @return JobStepResponse |
|
181 | + * @throws BatchRequestException |
|
182 | + */ |
|
183 | + public function cleanup_job($job_id) |
|
184 | + { |
|
185 | + try { |
|
186 | + $this->_job_id = $job_id; |
|
187 | + $job_parameters = JobParameters::load($this->_job_id); |
|
188 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
189 | + // continue it |
|
190 | + $response = $handler_obj->cleanup_job($job_parameters); |
|
191 | + if (! $response instanceof JobStepResponse) { |
|
192 | + throw new BatchRequestException( |
|
193 | + sprintf( |
|
194 | + __( |
|
195 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + $this->_job_id |
|
199 | + ) |
|
200 | + ); |
|
201 | + } |
|
202 | + $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
203 | + $job_parameters->delete(); |
|
204 | + return $response; |
|
205 | + } catch (\Exception $e) { |
|
206 | + $response = $this->_get_error_response($e, 'cleanup_job'); |
|
207 | + } |
|
208 | + return $response; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * Creates a valid JobStepResponse object from an exception and method name. |
|
214 | - * |
|
215 | - * @param \Exception $exception |
|
216 | - * @param string $method_name |
|
217 | - * @return JobStepResponse |
|
218 | - */ |
|
219 | - protected function _get_error_response(\Exception $exception, $method_name) |
|
220 | - { |
|
221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
222 | - $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
|
223 | - } |
|
224 | - $this->_job_parameters->set_status(JobParameters::status_error); |
|
225 | - return new JobStepResponse( |
|
226 | - $this->_job_parameters, |
|
227 | - sprintf( |
|
228 | - __( |
|
229 | - 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
230 | - 'event_espresso' |
|
231 | - ), |
|
232 | - get_class($exception), |
|
233 | - 'BatchRunner::' . $method_name . '()', |
|
234 | - $exception->getMessage(), |
|
235 | - $exception->getTraceAsString() |
|
236 | - ) |
|
237 | - ); |
|
238 | - } |
|
212 | + /** |
|
213 | + * Creates a valid JobStepResponse object from an exception and method name. |
|
214 | + * |
|
215 | + * @param \Exception $exception |
|
216 | + * @param string $method_name |
|
217 | + * @return JobStepResponse |
|
218 | + */ |
|
219 | + protected function _get_error_response(\Exception $exception, $method_name) |
|
220 | + { |
|
221 | + if (! $this->_job_parameters instanceof JobParameters) { |
|
222 | + $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
|
223 | + } |
|
224 | + $this->_job_parameters->set_status(JobParameters::status_error); |
|
225 | + return new JobStepResponse( |
|
226 | + $this->_job_parameters, |
|
227 | + sprintf( |
|
228 | + __( |
|
229 | + 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
230 | + 'event_espresso' |
|
231 | + ), |
|
232 | + get_class($exception), |
|
233 | + 'BatchRunner::' . $method_name . '()', |
|
234 | + $exception->getMessage(), |
|
235 | + $exception->getTraceAsString() |
|
236 | + ) |
|
237 | + ); |
|
238 | + } |
|
239 | 239 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
70 | 70 | $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
71 | 71 | $response = $obj->create_job($this->_job_parameters); |
72 | - if (! $response instanceof JobStepResponse) { |
|
72 | + if ( ! $response instanceof JobStepResponse) { |
|
73 | 73 | throw new BatchRequestException( |
74 | 74 | sprintf( |
75 | 75 | __( |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | ); |
82 | 82 | } |
83 | 83 | $success = $this->_job_parameters->save(true); |
84 | - if (! $success) { |
|
84 | + if ( ! $success) { |
|
85 | 85 | throw new BatchRequestException( |
86 | 86 | sprintf( |
87 | 87 | __( |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
118 | 118 | // continue it |
119 | 119 | $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
120 | - if (! $response instanceof JobStepResponse) { |
|
120 | + if ( ! $response instanceof JobStepResponse) { |
|
121 | 121 | throw new BatchRequestException( |
122 | 122 | sprintf( |
123 | 123 | __( |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function instantiate_batch_job_handler_from_classname($classname) |
148 | 148 | { |
149 | - if (! class_exists($classname)) { |
|
149 | + if ( ! class_exists($classname)) { |
|
150 | 150 | throw new BatchRequestException( |
151 | 151 | sprintf( |
152 | 152 | __( |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | ); |
159 | 159 | } |
160 | 160 | $obj = $this->loader->getNew($classname); |
161 | - if (! $obj instanceof JobHandlerInterface) { |
|
161 | + if ( ! $obj instanceof JobHandlerInterface) { |
|
162 | 162 | throw new BatchRequestException( |
163 | 163 | sprintf( |
164 | 164 | __( |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
189 | 189 | // continue it |
190 | 190 | $response = $handler_obj->cleanup_job($job_parameters); |
191 | - if (! $response instanceof JobStepResponse) { |
|
191 | + if ( ! $response instanceof JobStepResponse) { |
|
192 | 192 | throw new BatchRequestException( |
193 | 193 | sprintf( |
194 | 194 | __( |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | protected function _get_error_response(\Exception $exception, $method_name) |
220 | 220 | { |
221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
221 | + if ( ! $this->_job_parameters instanceof JobParameters) { |
|
222 | 222 | $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
223 | 223 | } |
224 | 224 | $this->_job_parameters->set_status(JobParameters::status_error); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | 'event_espresso' |
231 | 231 | ), |
232 | 232 | get_class($exception), |
233 | - 'BatchRunner::' . $method_name . '()', |
|
233 | + 'BatchRunner::'.$method_name.'()', |
|
234 | 234 | $exception->getMessage(), |
235 | 235 | $exception->getTraceAsString() |
236 | 236 | ) |
@@ -10,11 +10,11 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_File_Input_Display_Strategy extends EE_Text_Input_Display_Strategy |
12 | 12 | { |
13 | - /** |
|
14 | - * Override's parent to just set the type. May someday support other arguments. |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - parent::__construct('file'); |
|
19 | - } |
|
13 | + /** |
|
14 | + * Override's parent to just set the type. May someday support other arguments. |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + parent::__construct('file'); |
|
19 | + } |
|
20 | 20 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
56 | 56 | implode(', ', $this->allowed_file_extensions) |
57 | 57 | ), |
58 | - '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
58 | + '~.*\.('.implode('|', $this->allowed_file_extensions).')$~' |
|
59 | 59 | ) |
60 | 60 | ); |
61 | 61 | parent::__construct($options); |
@@ -19,86 +19,86 @@ |
||
19 | 19 | */ |
20 | 20 | class EE_File_Input extends EE_Form_Input_Base |
21 | 21 | { |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $allowed_file_extensions; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $allowed_file_extensions; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $allowed_mime_types; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $allowed_mime_types; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param array $options |
|
34 | - * @throws InvalidArgumentException |
|
35 | - */ |
|
36 | - public function __construct($options = array()) |
|
37 | - { |
|
38 | - if (isset($options['allowed_file_extensions'])) { |
|
39 | - $this->allowed_file_extensions = (array) $options['allowed_file_extensions']; |
|
40 | - } else { |
|
41 | - $this->allowed_file_extensions = ['csv']; |
|
42 | - } |
|
43 | - if (isset($options['allowed_mime_types'])) { |
|
44 | - $this->allowed_mime_types = (array) $options['allowed_file_extensions']; |
|
45 | - } else { |
|
46 | - $this->allowed_mime_types = ['text/csv']; |
|
47 | - } |
|
32 | + /** |
|
33 | + * @param array $options |
|
34 | + * @throws InvalidArgumentException |
|
35 | + */ |
|
36 | + public function __construct($options = array()) |
|
37 | + { |
|
38 | + if (isset($options['allowed_file_extensions'])) { |
|
39 | + $this->allowed_file_extensions = (array) $options['allowed_file_extensions']; |
|
40 | + } else { |
|
41 | + $this->allowed_file_extensions = ['csv']; |
|
42 | + } |
|
43 | + if (isset($options['allowed_mime_types'])) { |
|
44 | + $this->allowed_mime_types = (array) $options['allowed_file_extensions']; |
|
45 | + } else { |
|
46 | + $this->allowed_mime_types = ['text/csv']; |
|
47 | + } |
|
48 | 48 | |
49 | - $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
|
50 | - $this->_set_normalization_strategy(new EE_File_Normalization()); |
|
51 | - $this->add_validation_strategy( |
|
52 | - new EE_Text_Validation_Strategy( |
|
53 | - sprintf( |
|
54 | - // translators: %1$s is a list of allowed file extensions. |
|
55 | - esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
|
56 | - implode(', ', $this->allowed_file_extensions) |
|
57 | - ), |
|
58 | - '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
59 | - ) |
|
60 | - ); |
|
61 | - parent::__construct($options); |
|
49 | + $this->_set_display_strategy(new EE_File_Input_Display_Strategy()); |
|
50 | + $this->_set_normalization_strategy(new EE_File_Normalization()); |
|
51 | + $this->add_validation_strategy( |
|
52 | + new EE_Text_Validation_Strategy( |
|
53 | + sprintf( |
|
54 | + // translators: %1$s is a list of allowed file extensions. |
|
55 | + esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'), |
|
56 | + implode(', ', $this->allowed_file_extensions) |
|
57 | + ), |
|
58 | + '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~' |
|
59 | + ) |
|
60 | + ); |
|
61 | + parent::__construct($options); |
|
62 | 62 | |
63 | 63 | // It would be great to add this HTML attribute, but jQuery validate chokes on it. |
64 | - $this->set_other_html_attributes( |
|
65 | - $this->other_html_attributes() |
|
66 | - . ' extension="' |
|
67 | - . implode( |
|
68 | - ',', |
|
69 | - $this->allowed_file_extensions |
|
70 | - ) |
|
71 | - . '"' |
|
72 | - ); |
|
73 | - } |
|
64 | + $this->set_other_html_attributes( |
|
65 | + $this->other_html_attributes() |
|
66 | + . ' extension="' |
|
67 | + . implode( |
|
68 | + ',', |
|
69 | + $this->allowed_file_extensions |
|
70 | + ) |
|
71 | + . '"' |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * $_FILES has a really weird structure. So we let `FilesDataHandler` take care of finding the file info for |
|
77 | - * this input. |
|
78 | - * @since 4.9.80.p |
|
79 | - * @param array $req_data |
|
80 | - * @return FileSubmissionInterface |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws InvalidDataTypeException |
|
83 | - * @throws InvalidInterfaceException |
|
84 | - */ |
|
85 | - public function find_form_data_for_this_section($req_data) |
|
86 | - { |
|
87 | - // ignore $req_data. Files are in the files data handler. |
|
88 | - $fileDataHandler = LoaderFactory::getLoader()->getShared( |
|
89 | - 'EventEspresso\core\services\request\files\FilesDataHandler' |
|
90 | - ); |
|
91 | - return $fileDataHandler->getFileObject($this->html_name()); |
|
92 | - } |
|
75 | + /** |
|
76 | + * $_FILES has a really weird structure. So we let `FilesDataHandler` take care of finding the file info for |
|
77 | + * this input. |
|
78 | + * @since 4.9.80.p |
|
79 | + * @param array $req_data |
|
80 | + * @return FileSubmissionInterface |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws InvalidDataTypeException |
|
83 | + * @throws InvalidInterfaceException |
|
84 | + */ |
|
85 | + public function find_form_data_for_this_section($req_data) |
|
86 | + { |
|
87 | + // ignore $req_data. Files are in the files data handler. |
|
88 | + $fileDataHandler = LoaderFactory::getLoader()->getShared( |
|
89 | + 'EventEspresso\core\services\request\files\FilesDataHandler' |
|
90 | + ); |
|
91 | + return $fileDataHandler->getFileObject($this->html_name()); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Don't transform the file submission object into a string, thanks. |
|
96 | - * |
|
97 | - * @param string $value |
|
98 | - * @return null|string |
|
99 | - */ |
|
100 | - protected function _sanitize($value) |
|
101 | - { |
|
102 | - return $value; |
|
103 | - } |
|
94 | + /** |
|
95 | + * Don't transform the file submission object into a string, thanks. |
|
96 | + * |
|
97 | + * @param string $value |
|
98 | + * @return null|string |
|
99 | + */ |
|
100 | + protected function _sanitize($value) |
|
101 | + { |
|
102 | + return $value; |
|
103 | + } |
|
104 | 104 | } |
@@ -13,40 +13,40 @@ |
||
13 | 13 | class EE_File_Normalization extends EE_Normalization_Strategy_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Keep in mind $value_to_normalize should be a FileSubmissionInterface or null, so this shouldn't really do |
|
18 | - * much (other than NOT convert it to a string or something). |
|
19 | - * @param string $value_to_normalize |
|
20 | - * @return FileSubmissionInterface |
|
21 | - */ |
|
22 | - public function normalize($value_to_normalize) |
|
23 | - { |
|
24 | - if ($value_to_normalize instanceof FileSubmissionInterface || is_null($value_to_normalize)) { |
|
25 | - return $value_to_normalize; |
|
26 | - } else { |
|
27 | - throw new EE_Validation_Error( |
|
28 | - esc_html__('The file input has an invalid format.', 'event_espresso') |
|
29 | - ); |
|
30 | - } |
|
31 | - } |
|
16 | + /** |
|
17 | + * Keep in mind $value_to_normalize should be a FileSubmissionInterface or null, so this shouldn't really do |
|
18 | + * much (other than NOT convert it to a string or something). |
|
19 | + * @param string $value_to_normalize |
|
20 | + * @return FileSubmissionInterface |
|
21 | + */ |
|
22 | + public function normalize($value_to_normalize) |
|
23 | + { |
|
24 | + if ($value_to_normalize instanceof FileSubmissionInterface || is_null($value_to_normalize)) { |
|
25 | + return $value_to_normalize; |
|
26 | + } else { |
|
27 | + throw new EE_Validation_Error( |
|
28 | + esc_html__('The file input has an invalid format.', 'event_espresso') |
|
29 | + ); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * This may be called prematurely on submitted data, so we actually don't want to convert it into a string because |
|
36 | - * we'll lose all the FileSubmissionInterface data. So prefer to leave it alone. FileSubmissionInterface |
|
37 | - * can be cast to a string just fine so it's good as-is. |
|
38 | - * |
|
39 | - * @param string $normalized_value |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function unnormalize($normalized_value) |
|
43 | - { |
|
44 | - if ($normalized_value instanceof FileSubmissionInterface || is_null($normalized_value)) { |
|
45 | - // Leave it as the object, it can be treated like a string because it |
|
46 | - // overrides __toString() |
|
47 | - return $normalized_value; |
|
48 | - } else { |
|
49 | - return (string) $normalized_value; |
|
50 | - } |
|
51 | - } |
|
34 | + /** |
|
35 | + * This may be called prematurely on submitted data, so we actually don't want to convert it into a string because |
|
36 | + * we'll lose all the FileSubmissionInterface data. So prefer to leave it alone. FileSubmissionInterface |
|
37 | + * can be cast to a string just fine so it's good as-is. |
|
38 | + * |
|
39 | + * @param string $normalized_value |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function unnormalize($normalized_value) |
|
43 | + { |
|
44 | + if ($normalized_value instanceof FileSubmissionInterface || is_null($normalized_value)) { |
|
45 | + // Leave it as the object, it can be treated like a string because it |
|
46 | + // overrides __toString() |
|
47 | + return $normalized_value; |
|
48 | + } else { |
|
49 | + return (string) $normalized_value; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -16,89 +16,89 @@ |
||
16 | 16 | abstract class EE_Data_Migration_Script_Stage_Table extends EE_Data_Migration_Script_Stage |
17 | 17 | { |
18 | 18 | |
19 | - protected $_old_table; |
|
19 | + protected $_old_table; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string The columns to select. May be overridden for children. |
|
23 | - */ |
|
24 | - protected $select_expression = '*'; |
|
21 | + /** |
|
22 | + * @var string The columns to select. May be overridden for children. |
|
23 | + */ |
|
24 | + protected $select_expression = '*'; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Set in the constructor to add this sql to both the counting query in |
|
28 | - * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and |
|
29 | - * EE_Data_Migration_Script_Stage_Table::_get_rows(). |
|
30 | - * Eg "where column_name like '%some_value%'" |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $_extra_where_sql; |
|
26 | + /** |
|
27 | + * Set in the constructor to add this sql to both the counting query in |
|
28 | + * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and |
|
29 | + * EE_Data_Migration_Script_Stage_Table::_get_rows(). |
|
30 | + * Eg "where column_name like '%some_value%'" |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $_extra_where_sql; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property |
|
39 | - * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that |
|
40 | - * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the |
|
41 | - * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees |
|
42 | - * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at |
|
43 | - * very least we MUST report/return 50 items migrated) |
|
44 | - * |
|
45 | - * @param int $num_items |
|
46 | - * @return int number of items ACTUALLY migrated |
|
47 | - */ |
|
48 | - public function _migration_step($num_items = 50) |
|
49 | - { |
|
50 | - $rows = $this->_get_rows($num_items); |
|
51 | - $items_actually_migrated = 0; |
|
52 | - foreach ($rows as $old_row) { |
|
53 | - $this->_migrate_old_row($old_row); |
|
54 | - $items_actually_migrated++; |
|
55 | - } |
|
56 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
57 | - $this->set_completed(); |
|
58 | - } |
|
59 | - return $items_actually_migrated; |
|
60 | - } |
|
37 | + /** |
|
38 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property |
|
39 | + * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that |
|
40 | + * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the |
|
41 | + * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees |
|
42 | + * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at |
|
43 | + * very least we MUST report/return 50 items migrated) |
|
44 | + * |
|
45 | + * @param int $num_items |
|
46 | + * @return int number of items ACTUALLY migrated |
|
47 | + */ |
|
48 | + public function _migration_step($num_items = 50) |
|
49 | + { |
|
50 | + $rows = $this->_get_rows($num_items); |
|
51 | + $items_actually_migrated = 0; |
|
52 | + foreach ($rows as $old_row) { |
|
53 | + $this->_migrate_old_row($old_row); |
|
54 | + $items_actually_migrated++; |
|
55 | + } |
|
56 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
57 | + $this->set_completed(); |
|
58 | + } |
|
59 | + return $items_actually_migrated; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Gets the rows for each migration stage from the old table |
|
64 | - * |
|
65 | - * @global wpdb $wpdb |
|
66 | - * @param int $limit |
|
67 | - * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
68 | - */ |
|
69 | - protected function _get_rows($limit) |
|
70 | - { |
|
71 | - global $wpdb; |
|
72 | - $start_at_record = $this->count_records_migrated(); |
|
73 | - $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
74 | - "LIMIT %d, %d", |
|
75 | - $start_at_record, |
|
76 | - $limit |
|
77 | - ); |
|
78 | - return $wpdb->get_results($query, ARRAY_A); |
|
79 | - } |
|
62 | + /** |
|
63 | + * Gets the rows for each migration stage from the old table |
|
64 | + * |
|
65 | + * @global wpdb $wpdb |
|
66 | + * @param int $limit |
|
67 | + * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
68 | + */ |
|
69 | + protected function _get_rows($limit) |
|
70 | + { |
|
71 | + global $wpdb; |
|
72 | + $start_at_record = $this->count_records_migrated(); |
|
73 | + $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
74 | + "LIMIT %d, %d", |
|
75 | + $start_at_record, |
|
76 | + $limit |
|
77 | + ); |
|
78 | + return $wpdb->get_results($query, ARRAY_A); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * Counts the records to migrate; the public version may cache it |
|
84 | - * |
|
85 | - * @return int |
|
86 | - */ |
|
87 | - public function _count_records_to_migrate() |
|
88 | - { |
|
89 | - global $wpdb; |
|
90 | - $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}"; |
|
91 | - $count = $wpdb->get_var($query); |
|
92 | - return $count; |
|
93 | - } |
|
82 | + /** |
|
83 | + * Counts the records to migrate; the public version may cache it |
|
84 | + * |
|
85 | + * @return int |
|
86 | + */ |
|
87 | + public function _count_records_to_migrate() |
|
88 | + { |
|
89 | + global $wpdb; |
|
90 | + $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}"; |
|
91 | + $count = $wpdb->get_var($query); |
|
92 | + return $count; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * takes care of migrating this particular row from the OLD table to whatever its |
|
97 | - * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a |
|
98 | - * fatal error which prevents all future migrations, throw an exception describing it |
|
99 | - * |
|
100 | - * @param array $old_row an associative array where keys are column names and values are their values. |
|
101 | - * @return null |
|
102 | - */ |
|
103 | - abstract protected function _migrate_old_row($old_row); |
|
95 | + /** |
|
96 | + * takes care of migrating this particular row from the OLD table to whatever its |
|
97 | + * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a |
|
98 | + * fatal error which prevents all future migrations, throw an exception describing it |
|
99 | + * |
|
100 | + * @param array $old_row an associative array where keys are column names and values are their values. |
|
101 | + * @return null |
|
102 | + */ |
|
103 | + abstract protected function _migrate_old_row($old_row); |
|
104 | 104 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | { |
71 | 71 | global $wpdb; |
72 | 72 | $start_at_record = $this->count_records_migrated(); |
73 | - $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare( |
|
73 | + $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} ".$wpdb->prepare( |
|
74 | 74 | "LIMIT %d, %d", |
75 | 75 | $start_at_record, |
76 | 76 | $limit |
@@ -12,288 +12,288 @@ |
||
12 | 12 | abstract class EE_Form_Section_Layout_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Form form section to lay out |
|
17 | - * |
|
18 | - * @var EE_Form_Section_Proper |
|
19 | - */ |
|
20 | - protected $_form_section; |
|
21 | - |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * __construct |
|
26 | - */ |
|
27 | - public function __construct() |
|
28 | - { |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * The form section on which this strategy is to perform |
|
35 | - * |
|
36 | - * @param EE_Form_Section_Proper $form |
|
37 | - */ |
|
38 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
39 | - { |
|
40 | - $this->_form_section = $form; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return EE_Form_Section_Proper |
|
47 | - */ |
|
48 | - public function form_section() |
|
49 | - { |
|
50 | - return $this->_form_section; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
57 | - * this form. |
|
58 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
59 | - * proper subsections. |
|
60 | - * Returns the HTML |
|
61 | - * |
|
62 | - * @return string HTML for displaying |
|
63 | - * @throws EE_Error |
|
64 | - */ |
|
65 | - public function layout_form() |
|
66 | - { |
|
67 | - $html = ''; |
|
68 | - // layout_form_begin |
|
69 | - $html .= apply_filters( |
|
70 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
71 | - $this->layout_form_begin(), |
|
72 | - $this->_form_section |
|
73 | - ); |
|
74 | - // layout_form_loop |
|
75 | - $html .= apply_filters( |
|
76 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
77 | - $this->layout_form_loop(), |
|
78 | - $this->_form_section |
|
79 | - ); |
|
80 | - // layout_form_end |
|
81 | - $html .= apply_filters( |
|
82 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
83 | - $this->layout_form_end(), |
|
84 | - $this->_form_section |
|
85 | - ); |
|
86 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
87 | - return $html; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public function layout_form_loop() |
|
97 | - { |
|
98 | - $html = ''; |
|
99 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
100 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
101 | - $html .= apply_filters( |
|
102 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
103 | - . $name . '__in_' . $this->_form_section->name(), |
|
104 | - $this->layout_input($subsection), |
|
105 | - $this->_form_section, |
|
106 | - $subsection |
|
107 | - ); |
|
108 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
109 | - $html .= apply_filters( |
|
110 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
111 | - . $name . '__in_' . $this->_form_section->name(), |
|
112 | - $this->layout_subsection($subsection), |
|
113 | - $this->_form_section, |
|
114 | - $subsection |
|
115 | - ); |
|
116 | - } |
|
117 | - } |
|
118 | - return $html; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - abstract public function layout_form_begin(); |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - abstract public function layout_form_end(); |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
143 | - * is putting each input in a row of its own, this should probably be called by a |
|
144 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
145 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
146 | - * customize the form's layout, but would like to make use of it for laying out |
|
147 | - * 'easy-to-layout' inputs |
|
148 | - * |
|
149 | - * @param EE_Form_Input_Base $input |
|
150 | - * @return string html |
|
151 | - */ |
|
152 | - abstract public function layout_input($input); |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
158 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
159 | - * that the proper subsection will layout its container, label, etc on its own. |
|
160 | - * |
|
161 | - * @param EE_Form_Section_Base $subsection |
|
162 | - * @return string html |
|
163 | - */ |
|
164 | - abstract public function layout_subsection($subsection); |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Gets the HTML for the label tag and its contents for the input |
|
170 | - * |
|
171 | - * @param EE_Form_Input_Base $input |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function display_label($input) |
|
175 | - { |
|
176 | - if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
177 | - return ''; |
|
178 | - } |
|
179 | - $class = $input->required() |
|
180 | - ? 'ee-required-label ' . $input->html_label_class() |
|
181 | - : $input->html_label_class(); |
|
182 | - $label_text = $input->required() |
|
183 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
184 | - : $input->html_label_text(); |
|
185 | - return '<label id="' |
|
186 | - . $input->html_label_id() |
|
187 | - . '" class="' |
|
188 | - . $class |
|
189 | - . '" style="' |
|
190 | - . $input->html_label_style() |
|
191 | - . '" for="' . $input->html_id() |
|
192 | - . '">' |
|
193 | - . $label_text |
|
194 | - . '</label>'; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
201 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
202 | - * those errors would probably be on the form section, not one of its inputs) |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function display_form_wide_errors() |
|
206 | - { |
|
207 | - $html = ''; |
|
208 | - if ($this->_form_section->get_validation_errors()) { |
|
209 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
210 | - // get all the errors on THIS form section (errors which aren't |
|
211 | - // for specific inputs, but instead for the entire form section) |
|
212 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
213 | - $html .= $error->getMessage() . '<br>'; |
|
214 | - } |
|
215 | - $html .= '</div>'; |
|
216 | - } |
|
217 | - return apply_filters( |
|
218 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
219 | - $html, |
|
220 | - $this |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * returns the HTML for the server-side validation errors for the specified input |
|
228 | - * Note that if JS is enabled, it should remove these and instead |
|
229 | - * populate the form's errors in the jquery validate fashion |
|
230 | - * using the localized data provided to the JS |
|
231 | - * |
|
232 | - * @param EE_Form_Input_Base $input |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - public function display_errors($input) |
|
236 | - { |
|
237 | - if ($input->get_validation_errors()) { |
|
238 | - return "<label id='" |
|
239 | - . $input->html_id() |
|
240 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
241 | - . $input->get_validation_error_string() |
|
242 | - . '</label>'; |
|
243 | - } |
|
244 | - return ''; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Displays the help span for the specified input |
|
251 | - * |
|
252 | - * @param EE_Form_Input_Base $input |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function display_help_text($input) |
|
256 | - { |
|
257 | - $help_text = $input->html_help_text(); |
|
258 | - if ($help_text !== '' && $help_text !== null) { |
|
259 | - $tag = is_admin() ? 'p' : 'span'; |
|
260 | - return '<' |
|
261 | - . $tag |
|
262 | - . ' id="' |
|
263 | - . $input->html_id() |
|
264 | - . '-help" class="' |
|
265 | - . $input->html_help_class() |
|
266 | - . '" style="' |
|
267 | - . $input->html_help_style() |
|
268 | - . '">' |
|
269 | - . $help_text |
|
270 | - . '</' |
|
271 | - . $tag |
|
272 | - . '>'; |
|
273 | - } |
|
274 | - return ''; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Does an action and hook onto the end of teh form |
|
281 | - * |
|
282 | - * @param string $html |
|
283 | - * @return string |
|
284 | - */ |
|
285 | - public function add_form_section_hooks_and_filters($html) |
|
286 | - { |
|
287 | - // replace dashes and spaces with underscores |
|
288 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
289 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
290 | - $html = (string) apply_filters( |
|
291 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
292 | - $html, |
|
293 | - $this->_form_section |
|
294 | - ); |
|
295 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
296 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
297 | - return $html; |
|
298 | - } |
|
15 | + /** |
|
16 | + * Form form section to lay out |
|
17 | + * |
|
18 | + * @var EE_Form_Section_Proper |
|
19 | + */ |
|
20 | + protected $_form_section; |
|
21 | + |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * __construct |
|
26 | + */ |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * The form section on which this strategy is to perform |
|
35 | + * |
|
36 | + * @param EE_Form_Section_Proper $form |
|
37 | + */ |
|
38 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
39 | + { |
|
40 | + $this->_form_section = $form; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return EE_Form_Section_Proper |
|
47 | + */ |
|
48 | + public function form_section() |
|
49 | + { |
|
50 | + return $this->_form_section; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
57 | + * this form. |
|
58 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
59 | + * proper subsections. |
|
60 | + * Returns the HTML |
|
61 | + * |
|
62 | + * @return string HTML for displaying |
|
63 | + * @throws EE_Error |
|
64 | + */ |
|
65 | + public function layout_form() |
|
66 | + { |
|
67 | + $html = ''; |
|
68 | + // layout_form_begin |
|
69 | + $html .= apply_filters( |
|
70 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
71 | + $this->layout_form_begin(), |
|
72 | + $this->_form_section |
|
73 | + ); |
|
74 | + // layout_form_loop |
|
75 | + $html .= apply_filters( |
|
76 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
77 | + $this->layout_form_loop(), |
|
78 | + $this->_form_section |
|
79 | + ); |
|
80 | + // layout_form_end |
|
81 | + $html .= apply_filters( |
|
82 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
83 | + $this->layout_form_end(), |
|
84 | + $this->_form_section |
|
85 | + ); |
|
86 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
87 | + return $html; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public function layout_form_loop() |
|
97 | + { |
|
98 | + $html = ''; |
|
99 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
100 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
101 | + $html .= apply_filters( |
|
102 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
103 | + . $name . '__in_' . $this->_form_section->name(), |
|
104 | + $this->layout_input($subsection), |
|
105 | + $this->_form_section, |
|
106 | + $subsection |
|
107 | + ); |
|
108 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
109 | + $html .= apply_filters( |
|
110 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
111 | + . $name . '__in_' . $this->_form_section->name(), |
|
112 | + $this->layout_subsection($subsection), |
|
113 | + $this->_form_section, |
|
114 | + $subsection |
|
115 | + ); |
|
116 | + } |
|
117 | + } |
|
118 | + return $html; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + abstract public function layout_form_begin(); |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + abstract public function layout_form_end(); |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
143 | + * is putting each input in a row of its own, this should probably be called by a |
|
144 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
145 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
146 | + * customize the form's layout, but would like to make use of it for laying out |
|
147 | + * 'easy-to-layout' inputs |
|
148 | + * |
|
149 | + * @param EE_Form_Input_Base $input |
|
150 | + * @return string html |
|
151 | + */ |
|
152 | + abstract public function layout_input($input); |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
158 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
159 | + * that the proper subsection will layout its container, label, etc on its own. |
|
160 | + * |
|
161 | + * @param EE_Form_Section_Base $subsection |
|
162 | + * @return string html |
|
163 | + */ |
|
164 | + abstract public function layout_subsection($subsection); |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Gets the HTML for the label tag and its contents for the input |
|
170 | + * |
|
171 | + * @param EE_Form_Input_Base $input |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function display_label($input) |
|
175 | + { |
|
176 | + if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
177 | + return ''; |
|
178 | + } |
|
179 | + $class = $input->required() |
|
180 | + ? 'ee-required-label ' . $input->html_label_class() |
|
181 | + : $input->html_label_class(); |
|
182 | + $label_text = $input->required() |
|
183 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
184 | + : $input->html_label_text(); |
|
185 | + return '<label id="' |
|
186 | + . $input->html_label_id() |
|
187 | + . '" class="' |
|
188 | + . $class |
|
189 | + . '" style="' |
|
190 | + . $input->html_label_style() |
|
191 | + . '" for="' . $input->html_id() |
|
192 | + . '">' |
|
193 | + . $label_text |
|
194 | + . '</label>'; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
201 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
202 | + * those errors would probably be on the form section, not one of its inputs) |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function display_form_wide_errors() |
|
206 | + { |
|
207 | + $html = ''; |
|
208 | + if ($this->_form_section->get_validation_errors()) { |
|
209 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
210 | + // get all the errors on THIS form section (errors which aren't |
|
211 | + // for specific inputs, but instead for the entire form section) |
|
212 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
213 | + $html .= $error->getMessage() . '<br>'; |
|
214 | + } |
|
215 | + $html .= '</div>'; |
|
216 | + } |
|
217 | + return apply_filters( |
|
218 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
219 | + $html, |
|
220 | + $this |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * returns the HTML for the server-side validation errors for the specified input |
|
228 | + * Note that if JS is enabled, it should remove these and instead |
|
229 | + * populate the form's errors in the jquery validate fashion |
|
230 | + * using the localized data provided to the JS |
|
231 | + * |
|
232 | + * @param EE_Form_Input_Base $input |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + public function display_errors($input) |
|
236 | + { |
|
237 | + if ($input->get_validation_errors()) { |
|
238 | + return "<label id='" |
|
239 | + . $input->html_id() |
|
240 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
241 | + . $input->get_validation_error_string() |
|
242 | + . '</label>'; |
|
243 | + } |
|
244 | + return ''; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Displays the help span for the specified input |
|
251 | + * |
|
252 | + * @param EE_Form_Input_Base $input |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function display_help_text($input) |
|
256 | + { |
|
257 | + $help_text = $input->html_help_text(); |
|
258 | + if ($help_text !== '' && $help_text !== null) { |
|
259 | + $tag = is_admin() ? 'p' : 'span'; |
|
260 | + return '<' |
|
261 | + . $tag |
|
262 | + . ' id="' |
|
263 | + . $input->html_id() |
|
264 | + . '-help" class="' |
|
265 | + . $input->html_help_class() |
|
266 | + . '" style="' |
|
267 | + . $input->html_help_style() |
|
268 | + . '">' |
|
269 | + . $help_text |
|
270 | + . '</' |
|
271 | + . $tag |
|
272 | + . '>'; |
|
273 | + } |
|
274 | + return ''; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Does an action and hook onto the end of teh form |
|
281 | + * |
|
282 | + * @param string $html |
|
283 | + * @return string |
|
284 | + */ |
|
285 | + public function add_form_section_hooks_and_filters($html) |
|
286 | + { |
|
287 | + // replace dashes and spaces with underscores |
|
288 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
289 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
290 | + $html = (string) apply_filters( |
|
291 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
292 | + $html, |
|
293 | + $this->_form_section |
|
294 | + ); |
|
295 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
296 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
297 | + return $html; |
|
298 | + } |
|
299 | 299 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | $html = ''; |
68 | 68 | // layout_form_begin |
69 | 69 | $html .= apply_filters( |
70 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
70 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
71 | 71 | $this->layout_form_begin(), |
72 | 72 | $this->_form_section |
73 | 73 | ); |
74 | 74 | // layout_form_loop |
75 | 75 | $html .= apply_filters( |
76 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
76 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
77 | 77 | $this->layout_form_loop(), |
78 | 78 | $this->_form_section |
79 | 79 | ); |
80 | 80 | // layout_form_end |
81 | 81 | $html .= apply_filters( |
82 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
82 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
83 | 83 | $this->layout_form_end(), |
84 | 84 | $this->_form_section |
85 | 85 | ); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | if ($subsection instanceof EE_Form_Input_Base) { |
101 | 101 | $html .= apply_filters( |
102 | 102 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
103 | - . $name . '__in_' . $this->_form_section->name(), |
|
103 | + . $name.'__in_'.$this->_form_section->name(), |
|
104 | 104 | $this->layout_input($subsection), |
105 | 105 | $this->_form_section, |
106 | 106 | $subsection |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
109 | 109 | $html .= apply_filters( |
110 | 110 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
111 | - . $name . '__in_' . $this->_form_section->name(), |
|
111 | + . $name.'__in_'.$this->_form_section->name(), |
|
112 | 112 | $this->layout_subsection($subsection), |
113 | 113 | $this->_form_section, |
114 | 114 | $subsection |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | return ''; |
178 | 178 | } |
179 | 179 | $class = $input->required() |
180 | - ? 'ee-required-label ' . $input->html_label_class() |
|
180 | + ? 'ee-required-label '.$input->html_label_class() |
|
181 | 181 | : $input->html_label_class(); |
182 | 182 | $label_text = $input->required() |
183 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
183 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
184 | 184 | : $input->html_label_text(); |
185 | 185 | return '<label id="' |
186 | 186 | . $input->html_label_id() |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | . $class |
189 | 189 | . '" style="' |
190 | 190 | . $input->html_label_style() |
191 | - . '" for="' . $input->html_id() |
|
191 | + . '" for="'.$input->html_id() |
|
192 | 192 | . '">' |
193 | 193 | . $label_text |
194 | 194 | . '</label>'; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // get all the errors on THIS form section (errors which aren't |
211 | 211 | // for specific inputs, but instead for the entire form section) |
212 | 212 | foreach ($this->_form_section->get_validation_errors() as $error) { |
213 | - $html .= $error->getMessage() . '<br>'; |
|
213 | + $html .= $error->getMessage().'<br>'; |
|
214 | 214 | } |
215 | 215 | $html .= '</div>'; |
216 | 216 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function display_help_text($input) |
256 | 256 | { |
257 | - $help_text = $input->html_help_text(); |
|
257 | + $help_text = $input->html_help_text(); |
|
258 | 258 | if ($help_text !== '' && $help_text !== null) { |
259 | 259 | $tag = is_admin() ? 'p' : 'span'; |
260 | 260 | return '<' |
@@ -286,14 +286,14 @@ discard block |
||
286 | 286 | { |
287 | 287 | // replace dashes and spaces with underscores |
288 | 288 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
289 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
289 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
290 | 290 | $html = (string) apply_filters( |
291 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
291 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
292 | 292 | $html, |
293 | 293 | $this->_form_section |
294 | 294 | ); |
295 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
296 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
295 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
296 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
297 | 297 | return $html; |
298 | 298 | } |
299 | 299 | } |
@@ -16,33 +16,33 @@ |
||
16 | 16 | class InvalidEntityException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidEntityException constructor. |
|
21 | - * |
|
22 | - * @param mixed $actual the actual object (or thing) we got |
|
23 | - * @param string $expected classname of the entity we wanted |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - ob_start(); |
|
32 | - var_dump($actual); |
|
33 | - $object = ob_get_clean(); |
|
34 | - $message = sprintf( |
|
35 | - __( |
|
36 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
37 | - 'event_espresso' |
|
38 | - ), |
|
39 | - is_object($actual) |
|
40 | - ? get_class($actual) |
|
41 | - : gettype($actual), |
|
42 | - $expected, |
|
43 | - $object |
|
44 | - ); |
|
45 | - } |
|
46 | - parent::__construct($message, $code, $previous); |
|
47 | - } |
|
19 | + /** |
|
20 | + * InvalidEntityException constructor. |
|
21 | + * |
|
22 | + * @param mixed $actual the actual object (or thing) we got |
|
23 | + * @param string $expected classname of the entity we wanted |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + ob_start(); |
|
32 | + var_dump($actual); |
|
33 | + $object = ob_get_clean(); |
|
34 | + $message = sprintf( |
|
35 | + __( |
|
36 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
37 | + 'event_espresso' |
|
38 | + ), |
|
39 | + is_object($actual) |
|
40 | + ? get_class($actual) |
|
41 | + : gettype($actual), |
|
42 | + $expected, |
|
43 | + $object |
|
44 | + ); |
|
45 | + } |
|
46 | + parent::__construct($message, $code, $previous); |
|
47 | + } |
|
48 | 48 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public function verify(CommandInterface $command) |
32 | 32 | { |
33 | 33 | $expected = str_replace('CommandHandler', 'Command', get_class($this)); |
34 | - if (! $command instanceof $expected) { |
|
34 | + if ( ! $command instanceof $expected) { |
|
35 | 35 | throw new InvalidEntityException($command, $expected); |
36 | 36 | } |
37 | 37 | return $this; |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class CommandHandler implements CommandHandlerInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * Verifies the Command class matches the Handler class |
|
19 | - * by simply removing "Handler" from the Command class and then comparing. |
|
20 | - * IF the Command Handler has been changed via CommandHandlerManager::addCommandHandler, |
|
21 | - * or via the filter in CommandHandlerManager::getCommandHandler(), |
|
22 | - * then this method MUST be overridden in the new Command Handler class. |
|
23 | - * PLZ NOTE: that it also needs to return itself ($this) |
|
24 | - * because the CommandBus utilizes method chaining. |
|
25 | - * |
|
26 | - * @param CommandInterface $command |
|
27 | - * @return CommandHandler |
|
28 | - * @throws InvalidEntityException |
|
29 | - * @since 4.9.80.p |
|
30 | - */ |
|
31 | - public function verify(CommandInterface $command) |
|
32 | - { |
|
33 | - $expected = str_replace('CommandHandler', 'Command', get_class($this)); |
|
34 | - if (! $command instanceof $expected) { |
|
35 | - throw new InvalidEntityException($command, $expected); |
|
36 | - } |
|
37 | - return $this; |
|
38 | - } |
|
17 | + /** |
|
18 | + * Verifies the Command class matches the Handler class |
|
19 | + * by simply removing "Handler" from the Command class and then comparing. |
|
20 | + * IF the Command Handler has been changed via CommandHandlerManager::addCommandHandler, |
|
21 | + * or via the filter in CommandHandlerManager::getCommandHandler(), |
|
22 | + * then this method MUST be overridden in the new Command Handler class. |
|
23 | + * PLZ NOTE: that it also needs to return itself ($this) |
|
24 | + * because the CommandBus utilizes method chaining. |
|
25 | + * |
|
26 | + * @param CommandInterface $command |
|
27 | + * @return CommandHandler |
|
28 | + * @throws InvalidEntityException |
|
29 | + * @since 4.9.80.p |
|
30 | + */ |
|
31 | + public function verify(CommandInterface $command) |
|
32 | + { |
|
33 | + $expected = str_replace('CommandHandler', 'Command', get_class($this)); |
|
34 | + if (! $command instanceof $expected) { |
|
35 | + throw new InvalidEntityException($command, $expected); |
|
36 | + } |
|
37 | + return $this; |
|
38 | + } |
|
39 | 39 | } |