Completed
Branch FET/add-with-latest-checkin-ho... (2cd866)
by
unknown
09:12 queued 23s
created
core/libraries/batch/JobHandlers/RegistrationsReport.php 1 patch
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -31,530 +31,530 @@
 block discarded – undo
31 31
  */
32 32
 class RegistrationsReport extends JobHandlerFile
33 33
 {
34
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
-    /**
37
-     * Performs any necessary setup for starting the job. This is also a good
38
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
-     * when continue_job will be called
40
-     *
41
-     * @param JobParameters $job_parameters
42
-     * @throws BatchRequestException
43
-     * @return JobStepResponse
44
-     */
45
-    public function create_job(JobParameters $job_parameters)
46
-    {
47
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
-        }
51
-        $filepath = $this->create_file_from_job_with_name(
52
-            $job_parameters->job_id(),
53
-            $this->get_filename($event_id)
54
-        );
55
-        $job_parameters->add_extra_data('filepath', $filepath);
56
-        if ($job_parameters->request_datum('use_filters', false)) {
57
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
-        } else {
59
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
-                array(
61
-                    'OR'                 => array(
62
-                        // don't include registrations from failed or abandoned transactions...
63
-                        'Transaction.STS_ID' => array(
64
-                            'NOT IN',
65
-                            array(
66
-                                EEM_Transaction::failed_status_code,
67
-                                EEM_Transaction::abandoned_status_code,
68
-                            ),
69
-                        ),
70
-                        // unless the registration is approved, in which case include it regardless of transaction status
71
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
72
-                    ),
73
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
-                ),
75
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
-                'caps'       => \EEM_Base::caps_read_admin,
78
-            ), $event_id);
79
-            if ($event_id) {
80
-                $query_params[0]['EVT_ID'] = $event_id;
81
-            } else {
82
-                $query_params['force_join'][] = 'Event';
83
-            }
84
-        }
85
-        if (! isset($query_params['force_join'])) {
86
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
-        }
88
-        $job_parameters->add_extra_data('query_params', $query_params);
89
-        $question_labels = $this->_get_question_labels($query_params);
90
-        $job_parameters->add_extra_data('question_labels', $question_labels);
91
-        $job_parameters->set_job_size(
92
-            \EEM_Registration::instance()->count(
93
-                array_diff_key(
94
-                    $query_params,
95
-                    array_flip(
96
-                        array('limit')
97
-                    )
98
-                )
99
-            )
100
-        );
101
-        // we should also set the header columns
102
-        $csv_data_for_row = $this->get_csv_data_for(
103
-            $event_id,
104
-            0,
105
-            1,
106
-            $job_parameters->extra_datum('question_labels'),
107
-            $job_parameters->extra_datum('query_params')
108
-        );
109
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
-        // if we actually processed a row there, record it
111
-        if ($job_parameters->job_size()) {
112
-            $job_parameters->mark_processed(1);
113
-        }
114
-        return new JobStepResponse(
115
-            $job_parameters,
116
-            __('Registrations report started successfully...', 'event_espresso')
117
-        );
118
-    }
34
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
+	/**
37
+	 * Performs any necessary setup for starting the job. This is also a good
38
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
+	 * when continue_job will be called
40
+	 *
41
+	 * @param JobParameters $job_parameters
42
+	 * @throws BatchRequestException
43
+	 * @return JobStepResponse
44
+	 */
45
+	public function create_job(JobParameters $job_parameters)
46
+	{
47
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
+		}
51
+		$filepath = $this->create_file_from_job_with_name(
52
+			$job_parameters->job_id(),
53
+			$this->get_filename($event_id)
54
+		);
55
+		$job_parameters->add_extra_data('filepath', $filepath);
56
+		if ($job_parameters->request_datum('use_filters', false)) {
57
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
+		} else {
59
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
+				array(
61
+					'OR'                 => array(
62
+						// don't include registrations from failed or abandoned transactions...
63
+						'Transaction.STS_ID' => array(
64
+							'NOT IN',
65
+							array(
66
+								EEM_Transaction::failed_status_code,
67
+								EEM_Transaction::abandoned_status_code,
68
+							),
69
+						),
70
+						// unless the registration is approved, in which case include it regardless of transaction status
71
+						'STS_ID'             => \EEM_Registration::status_id_approved,
72
+					),
73
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
+				),
75
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
+				'caps'       => \EEM_Base::caps_read_admin,
78
+			), $event_id);
79
+			if ($event_id) {
80
+				$query_params[0]['EVT_ID'] = $event_id;
81
+			} else {
82
+				$query_params['force_join'][] = 'Event';
83
+			}
84
+		}
85
+		if (! isset($query_params['force_join'])) {
86
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
+		}
88
+		$job_parameters->add_extra_data('query_params', $query_params);
89
+		$question_labels = $this->_get_question_labels($query_params);
90
+		$job_parameters->add_extra_data('question_labels', $question_labels);
91
+		$job_parameters->set_job_size(
92
+			\EEM_Registration::instance()->count(
93
+				array_diff_key(
94
+					$query_params,
95
+					array_flip(
96
+						array('limit')
97
+					)
98
+				)
99
+			)
100
+		);
101
+		// we should also set the header columns
102
+		$csv_data_for_row = $this->get_csv_data_for(
103
+			$event_id,
104
+			0,
105
+			1,
106
+			$job_parameters->extra_datum('question_labels'),
107
+			$job_parameters->extra_datum('query_params')
108
+		);
109
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
+		// if we actually processed a row there, record it
111
+		if ($job_parameters->job_size()) {
112
+			$job_parameters->mark_processed(1);
113
+		}
114
+		return new JobStepResponse(
115
+			$job_parameters,
116
+			__('Registrations report started successfully...', 'event_espresso')
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Gets the filename
123
-     *
124
-     * @return string
125
-     */
126
-    protected function get_filename()
127
-    {
128
-        return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
129
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * Gets the questions which are to be used for this report, so they
134
-     * can be remembered for later
135
-     *
136
-     * @param array $registration_query_params
137
-     * @return array question admin labels to be used for this report
138
-     */
139
-    protected function _get_question_labels($registration_query_params)
140
-    {
141
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
142
-        $question_query_params = array();
143
-        if ($where !== null) {
144
-            $question_query_params = array(
145
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
146
-            );
147
-        }
148
-        // Make sure it's not a system question
149
-        $question_query_params[0]['OR*not-system-questions'] = [
150
-            'QST_system' => '',
151
-            'QST_system*null' => ['IS_NULL']
152
-        ];
153
-        if (apply_filters(
154
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
155
-            false,
156
-            $registration_query_params
157
-        )) {
158
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
159
-        }
160
-        $question_query_params['group_by'] = array('QST_ID');
161
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
162
-    }
132
+	/**
133
+	 * Gets the questions which are to be used for this report, so they
134
+	 * can be remembered for later
135
+	 *
136
+	 * @param array $registration_query_params
137
+	 * @return array question admin labels to be used for this report
138
+	 */
139
+	protected function _get_question_labels($registration_query_params)
140
+	{
141
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
142
+		$question_query_params = array();
143
+		if ($where !== null) {
144
+			$question_query_params = array(
145
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
146
+			);
147
+		}
148
+		// Make sure it's not a system question
149
+		$question_query_params[0]['OR*not-system-questions'] = [
150
+			'QST_system' => '',
151
+			'QST_system*null' => ['IS_NULL']
152
+		];
153
+		if (apply_filters(
154
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
155
+			false,
156
+			$registration_query_params
157
+		)) {
158
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
159
+		}
160
+		$question_query_params['group_by'] = array('QST_ID');
161
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
162
+	}
163 163
 
164 164
 
165
-    /**
166
-     * Takes where params meant for registrations and changes them to work for questions
167
-     *
168
-     * @param array $reg_where_params
169
-     * @return array
170
-     */
171
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
172
-    {
173
-        $question_where_params = array();
174
-        foreach ($reg_where_params as $key => $val) {
175
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
176
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
177
-            } else {
178
-                // it's a normal where condition
179
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
180
-            }
181
-        }
182
-        return $question_where_params;
183
-    }
165
+	/**
166
+	 * Takes where params meant for registrations and changes them to work for questions
167
+	 *
168
+	 * @param array $reg_where_params
169
+	 * @return array
170
+	 */
171
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
172
+	{
173
+		$question_where_params = array();
174
+		foreach ($reg_where_params as $key => $val) {
175
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
176
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
177
+			} else {
178
+				// it's a normal where condition
179
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
180
+			}
181
+		}
182
+		return $question_where_params;
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * Performs another step of the job
188
-     *
189
-     * @param JobParameters $job_parameters
190
-     * @param int           $batch_size
191
-     * @return JobStepResponse
192
-     * @throws \EE_Error
193
-     */
194
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
195
-    {
196
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
197
-            $csv_data = $this->get_csv_data_for(
198
-                $job_parameters->request_datum('EVT_ID', '0'),
199
-                $job_parameters->units_processed(),
200
-                $batch_size,
201
-                $job_parameters->extra_datum('question_labels'),
202
-                $job_parameters->extra_datum('query_params')
203
-            );
204
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
205
-            $units_processed = count($csv_data);
206
-        } else {
207
-            $csv_data = array();
208
-            $units_processed = 0;
209
-        }
210
-        $job_parameters->mark_processed($units_processed);
211
-        $extra_response_data = array(
212
-            'file_url' => '',
213
-        );
214
-        if ($units_processed < $batch_size) {
215
-            $job_parameters->set_status(JobParameters::status_complete);
216
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
217
-        }
186
+	/**
187
+	 * Performs another step of the job
188
+	 *
189
+	 * @param JobParameters $job_parameters
190
+	 * @param int           $batch_size
191
+	 * @return JobStepResponse
192
+	 * @throws \EE_Error
193
+	 */
194
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
195
+	{
196
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
197
+			$csv_data = $this->get_csv_data_for(
198
+				$job_parameters->request_datum('EVT_ID', '0'),
199
+				$job_parameters->units_processed(),
200
+				$batch_size,
201
+				$job_parameters->extra_datum('question_labels'),
202
+				$job_parameters->extra_datum('query_params')
203
+			);
204
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
205
+			$units_processed = count($csv_data);
206
+		} else {
207
+			$csv_data = array();
208
+			$units_processed = 0;
209
+		}
210
+		$job_parameters->mark_processed($units_processed);
211
+		$extra_response_data = array(
212
+			'file_url' => '',
213
+		);
214
+		if ($units_processed < $batch_size) {
215
+			$job_parameters->set_status(JobParameters::status_complete);
216
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
217
+		}
218 218
 
219
-        return new JobStepResponse(
220
-            $job_parameters,
221
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
222
-            $extra_response_data
223
-        );
224
-    }
219
+		return new JobStepResponse(
220
+			$job_parameters,
221
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
222
+			$extra_response_data
223
+		);
224
+	}
225 225
 
226 226
 
227
-    /**
228
-     * Gets the csv data for a batch of registrations
229
-     *
230
-     * @param int|null $event_id
231
-     * @param int $offset
232
-     * @param int $limit
233
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
234
-     * @param array $query_params for using where querying the model
235
-     * @return array top-level keys are numeric, next-level keys are column headers
236
-     * @throws \EE_Error
237
-     */
238
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
239
-    {
240
-        $reg_fields_to_include = array(
241
-            'TXN_ID',
242
-            'ATT_ID',
243
-            'REG_ID',
244
-            'REG_date',
245
-            'REG_code',
246
-            'REG_count',
247
-            'REG_final_price',
248
-        );
249
-        $att_fields_to_include = array(
250
-            'ATT_fname',
251
-            'ATT_lname',
252
-            'ATT_email',
253
-            'ATT_address',
254
-            'ATT_address2',
255
-            'ATT_city',
256
-            'STA_ID',
257
-            'CNT_ISO',
258
-            'ATT_zip',
259
-            'ATT_phone',
260
-        );
261
-        $registrations_csv_ready_array = array();
262
-        $reg_model = EE_Registry::instance()->load_model('Registration');
263
-        $query_params['limit'] = array($offset, $limit);
264
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
265
-        $registration_ids = array();
266
-        foreach ($registration_rows as $reg_row) {
267
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
268
-        }
269
-        foreach ($registration_rows as $reg_row) {
270
-            if (is_array($reg_row)) {
271
-                $reg_csv_array = array();
272
-                if (! $event_id) {
273
-                    // get the event's name and Id
274
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
275
-                        /* translators: 1: event name, 2: event ID */
276
-                        __('%1$s (%2$s)', 'event_espresso'),
277
-                        EEH_Export::prepare_value_from_db_for_display(
278
-                            EEM_Event::instance(),
279
-                            'EVT_name',
280
-                            $reg_row['Event_CPT.post_title']
281
-                        ),
282
-                        $reg_row['Event_CPT.ID']
283
-                    );
284
-                }
285
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
286
-                /*@var $reg_row EE_Registration */
287
-                foreach ($reg_fields_to_include as $field_name) {
288
-                    $field = $reg_model->field_settings_for($field_name);
289
-                    if ($field_name == 'REG_final_price') {
290
-                        $value = EEH_Export::prepare_value_from_db_for_display(
291
-                            $reg_model,
292
-                            $field_name,
293
-                            $reg_row['Registration.REG_final_price'],
294
-                            'localized_float'
295
-                        );
296
-                    } elseif ($field_name == 'REG_count') {
297
-                        $value = sprintf(
298
-                            /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
299
-                            __('%1$s of %2$s', 'event_espresso'),
300
-                            EEH_Export::prepare_value_from_db_for_display(
301
-                                $reg_model,
302
-                                'REG_count',
303
-                                $reg_row['Registration.REG_count']
304
-                            ),
305
-                            EEH_Export::prepare_value_from_db_for_display(
306
-                                $reg_model,
307
-                                'REG_group_size',
308
-                                $reg_row['Registration.REG_group_size']
309
-                            )
310
-                        );
311
-                    } elseif ($field_name == 'REG_date') {
312
-                        $value = EEH_Export::prepare_value_from_db_for_display(
313
-                            $reg_model,
314
-                            $field_name,
315
-                            $reg_row['Registration.REG_date'],
316
-                            'no_html'
317
-                        );
318
-                    } else {
319
-                        $value = EEH_Export::prepare_value_from_db_for_display(
320
-                            $reg_model,
321
-                            $field_name,
322
-                            $reg_row[ $field->get_qualified_column() ]
323
-                        );
324
-                    }
325
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
326
-                    if ($field_name == 'REG_final_price') {
327
-                        // add a column named Currency after the final price
328
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
329
-                    }
330
-                }
331
-                // get pretty status
332
-                $stati = EEM_Status::instance()->localized_status(
333
-                    array(
334
-                        $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
335
-                        $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
336
-                    ),
337
-                    false,
338
-                    'sentence'
339
-                );
340
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
341
-                // get pretty transaction status
342
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
343
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
344
-                    ? EEH_Export::prepare_value_from_db_for_display(
345
-                        EEM_Transaction::instance(),
346
-                        'TXN_total',
347
-                        $reg_row['TransactionTable.TXN_total'],
348
-                        'localized_float'
349
-                    ) : '0.00';
350
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
351
-                    ? EEH_Export::prepare_value_from_db_for_display(
352
-                        EEM_Transaction::instance(),
353
-                        'TXN_paid',
354
-                        $reg_row['TransactionTable.TXN_paid'],
355
-                        'localized_float'
356
-                    ) : '0.00';
357
-                $payment_methods = array();
358
-                $gateway_txn_ids_etc = array();
359
-                $payment_times = array();
360
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
361
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
362
-                        array(
363
-                            array(
364
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
365
-                                'STS_ID' => EEM_Payment::status_id_approved,
366
-                            ),
367
-                            'force_join' => array('Payment_Method'),
368
-                        ),
369
-                        ARRAY_A,
370
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
371
-                    );
372
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
373
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
374
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
375
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
376
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
377
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
378
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
379
-                    }
380
-                }
381
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
382
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
383
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
384
-                    ',',
385
-                    $gateway_txn_ids_etc
386
-                );
387
-                // get whether or not the user has checked in
388
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
389
-                    $reg_row['Registration.REG_ID'],
390
-                    'Checkin'
391
-                );
392
-                // get ticket of registration and its price
393
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
394
-                if ($reg_row['Ticket.TKT_ID']) {
395
-                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
396
-                        $ticket_model,
397
-                        'TKT_name',
398
-                        $reg_row['Ticket.TKT_name']
399
-                    );
400
-                    $datetimes_strings = array();
401
-                    foreach (EEM_Datetime::instance()->get_all_wpdb_results(
402
-                        array(
403
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
404
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
405
-                            'default_where_conditions' => 'none',
406
-                        )
407
-                    ) as $datetime) {
408
-                        $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
409
-                            EEM_Datetime::instance(),
410
-                            'DTT_EVT_start',
411
-                            $datetime['Datetime.DTT_EVT_start']
412
-                        );
413
-                    }
414
-                } else {
415
-                    $ticket_name = __('Unknown', 'event_espresso');
416
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
417
-                }
418
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
419
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
420
-                // get datetime(s) of registration
421
-                // add attendee columns
422
-                foreach ($att_fields_to_include as $att_field_name) {
423
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
424
-                    if ($reg_row['Attendee_CPT.ID']) {
425
-                        if ($att_field_name == 'STA_ID') {
426
-                            $value = EEM_State::instance()->get_var(
427
-                                array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
428
-                                'STA_name'
429
-                            );
430
-                        } elseif ($att_field_name == 'CNT_ISO') {
431
-                            $value = EEM_Country::instance()->get_var(
432
-                                array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
433
-                                'CNT_name'
434
-                            );
435
-                        } else {
436
-                            $value = EEH_Export::prepare_value_from_db_for_display(
437
-                                EEM_Attendee::instance(),
438
-                                $att_field_name,
439
-                                $reg_row[ $field_obj->get_qualified_column() ]
440
-                            );
441
-                        }
442
-                    } else {
443
-                        $value = '';
444
-                    }
445
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
446
-                }
447
-                // make sure each registration has the same questions in the same order
448
-                foreach ($question_labels as $question_label) {
449
-                    if (! isset($reg_csv_array[ $question_label ])) {
450
-                        $reg_csv_array[ $question_label ] = null;
451
-                    }
452
-                }
453
-                $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
454
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
455
-                    'force_join' => array('Question'),
456
-                ));
457
-                // now fill out the questions THEY answered
458
-                foreach ($answers as $answer_row) {
459
-                    if ($answer_row['Question.QST_system']) {
460
-                        // it's an answer to a system question. That was already displayed as part of the attendee
461
-                        // fields, so don't write it out again thanks.
462
-                        continue;
463
-                    }
464
-                    if ($answer_row['Question.QST_ID']) {
465
-                        $question_label = EEH_Export::prepare_value_from_db_for_display(
466
-                            EEM_Question::instance(),
467
-                            'QST_admin_label',
468
-                            $answer_row['Question.QST_admin_label']
469
-                        );
470
-                    } else {
471
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
472
-                    }
473
-                    if (isset($answer_row['Question.QST_type'])
474
-                        && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
475
-                    ) {
476
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
477
-                            $answer_row['Answer.ANS_value']
478
-                        );
479
-                    } else {
480
-                        // this isn't for html, so don't show html entities
481
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
482
-                            EEH_Export::prepare_value_from_db_for_display(
483
-                                EEM_Answer::instance(),
484
-                                'ANS_value',
485
-                                $answer_row['Answer.ANS_value']
486
-                            )
487
-                        );
488
-                    }
489
-                }
227
+	/**
228
+	 * Gets the csv data for a batch of registrations
229
+	 *
230
+	 * @param int|null $event_id
231
+	 * @param int $offset
232
+	 * @param int $limit
233
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
234
+	 * @param array $query_params for using where querying the model
235
+	 * @return array top-level keys are numeric, next-level keys are column headers
236
+	 * @throws \EE_Error
237
+	 */
238
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
239
+	{
240
+		$reg_fields_to_include = array(
241
+			'TXN_ID',
242
+			'ATT_ID',
243
+			'REG_ID',
244
+			'REG_date',
245
+			'REG_code',
246
+			'REG_count',
247
+			'REG_final_price',
248
+		);
249
+		$att_fields_to_include = array(
250
+			'ATT_fname',
251
+			'ATT_lname',
252
+			'ATT_email',
253
+			'ATT_address',
254
+			'ATT_address2',
255
+			'ATT_city',
256
+			'STA_ID',
257
+			'CNT_ISO',
258
+			'ATT_zip',
259
+			'ATT_phone',
260
+		);
261
+		$registrations_csv_ready_array = array();
262
+		$reg_model = EE_Registry::instance()->load_model('Registration');
263
+		$query_params['limit'] = array($offset, $limit);
264
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
265
+		$registration_ids = array();
266
+		foreach ($registration_rows as $reg_row) {
267
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
268
+		}
269
+		foreach ($registration_rows as $reg_row) {
270
+			if (is_array($reg_row)) {
271
+				$reg_csv_array = array();
272
+				if (! $event_id) {
273
+					// get the event's name and Id
274
+					$reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
275
+						/* translators: 1: event name, 2: event ID */
276
+						__('%1$s (%2$s)', 'event_espresso'),
277
+						EEH_Export::prepare_value_from_db_for_display(
278
+							EEM_Event::instance(),
279
+							'EVT_name',
280
+							$reg_row['Event_CPT.post_title']
281
+						),
282
+						$reg_row['Event_CPT.ID']
283
+					);
284
+				}
285
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
286
+				/*@var $reg_row EE_Registration */
287
+				foreach ($reg_fields_to_include as $field_name) {
288
+					$field = $reg_model->field_settings_for($field_name);
289
+					if ($field_name == 'REG_final_price') {
290
+						$value = EEH_Export::prepare_value_from_db_for_display(
291
+							$reg_model,
292
+							$field_name,
293
+							$reg_row['Registration.REG_final_price'],
294
+							'localized_float'
295
+						);
296
+					} elseif ($field_name == 'REG_count') {
297
+						$value = sprintf(
298
+							/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
299
+							__('%1$s of %2$s', 'event_espresso'),
300
+							EEH_Export::prepare_value_from_db_for_display(
301
+								$reg_model,
302
+								'REG_count',
303
+								$reg_row['Registration.REG_count']
304
+							),
305
+							EEH_Export::prepare_value_from_db_for_display(
306
+								$reg_model,
307
+								'REG_group_size',
308
+								$reg_row['Registration.REG_group_size']
309
+							)
310
+						);
311
+					} elseif ($field_name == 'REG_date') {
312
+						$value = EEH_Export::prepare_value_from_db_for_display(
313
+							$reg_model,
314
+							$field_name,
315
+							$reg_row['Registration.REG_date'],
316
+							'no_html'
317
+						);
318
+					} else {
319
+						$value = EEH_Export::prepare_value_from_db_for_display(
320
+							$reg_model,
321
+							$field_name,
322
+							$reg_row[ $field->get_qualified_column() ]
323
+						);
324
+					}
325
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
326
+					if ($field_name == 'REG_final_price') {
327
+						// add a column named Currency after the final price
328
+						$reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
329
+					}
330
+				}
331
+				// get pretty status
332
+				$stati = EEM_Status::instance()->localized_status(
333
+					array(
334
+						$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
335
+						$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
336
+					),
337
+					false,
338
+					'sentence'
339
+				);
340
+				$reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
341
+				// get pretty transaction status
342
+				$reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
343
+				$reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
344
+					? EEH_Export::prepare_value_from_db_for_display(
345
+						EEM_Transaction::instance(),
346
+						'TXN_total',
347
+						$reg_row['TransactionTable.TXN_total'],
348
+						'localized_float'
349
+					) : '0.00';
350
+				$reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
351
+					? EEH_Export::prepare_value_from_db_for_display(
352
+						EEM_Transaction::instance(),
353
+						'TXN_paid',
354
+						$reg_row['TransactionTable.TXN_paid'],
355
+						'localized_float'
356
+					) : '0.00';
357
+				$payment_methods = array();
358
+				$gateway_txn_ids_etc = array();
359
+				$payment_times = array();
360
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
361
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
362
+						array(
363
+							array(
364
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
365
+								'STS_ID' => EEM_Payment::status_id_approved,
366
+							),
367
+							'force_join' => array('Payment_Method'),
368
+						),
369
+						ARRAY_A,
370
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
371
+					);
372
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
373
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
374
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
375
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
376
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
377
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
378
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
379
+					}
380
+				}
381
+				$reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
382
+				$reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
383
+				$reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
384
+					',',
385
+					$gateway_txn_ids_etc
386
+				);
387
+				// get whether or not the user has checked in
388
+				$reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
389
+					$reg_row['Registration.REG_ID'],
390
+					'Checkin'
391
+				);
392
+				// get ticket of registration and its price
393
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
394
+				if ($reg_row['Ticket.TKT_ID']) {
395
+					$ticket_name = EEH_Export::prepare_value_from_db_for_display(
396
+						$ticket_model,
397
+						'TKT_name',
398
+						$reg_row['Ticket.TKT_name']
399
+					);
400
+					$datetimes_strings = array();
401
+					foreach (EEM_Datetime::instance()->get_all_wpdb_results(
402
+						array(
403
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
404
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
405
+							'default_where_conditions' => 'none',
406
+						)
407
+					) as $datetime) {
408
+						$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
409
+							EEM_Datetime::instance(),
410
+							'DTT_EVT_start',
411
+							$datetime['Datetime.DTT_EVT_start']
412
+						);
413
+					}
414
+				} else {
415
+					$ticket_name = __('Unknown', 'event_espresso');
416
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
417
+				}
418
+				$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
419
+				$reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
420
+				// get datetime(s) of registration
421
+				// add attendee columns
422
+				foreach ($att_fields_to_include as $att_field_name) {
423
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
424
+					if ($reg_row['Attendee_CPT.ID']) {
425
+						if ($att_field_name == 'STA_ID') {
426
+							$value = EEM_State::instance()->get_var(
427
+								array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
428
+								'STA_name'
429
+							);
430
+						} elseif ($att_field_name == 'CNT_ISO') {
431
+							$value = EEM_Country::instance()->get_var(
432
+								array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
433
+								'CNT_name'
434
+							);
435
+						} else {
436
+							$value = EEH_Export::prepare_value_from_db_for_display(
437
+								EEM_Attendee::instance(),
438
+								$att_field_name,
439
+								$reg_row[ $field_obj->get_qualified_column() ]
440
+							);
441
+						}
442
+					} else {
443
+						$value = '';
444
+					}
445
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
446
+				}
447
+				// make sure each registration has the same questions in the same order
448
+				foreach ($question_labels as $question_label) {
449
+					if (! isset($reg_csv_array[ $question_label ])) {
450
+						$reg_csv_array[ $question_label ] = null;
451
+					}
452
+				}
453
+				$answers = EEM_Answer::instance()->get_all_wpdb_results(array(
454
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
455
+					'force_join' => array('Question'),
456
+				));
457
+				// now fill out the questions THEY answered
458
+				foreach ($answers as $answer_row) {
459
+					if ($answer_row['Question.QST_system']) {
460
+						// it's an answer to a system question. That was already displayed as part of the attendee
461
+						// fields, so don't write it out again thanks.
462
+						continue;
463
+					}
464
+					if ($answer_row['Question.QST_ID']) {
465
+						$question_label = EEH_Export::prepare_value_from_db_for_display(
466
+							EEM_Question::instance(),
467
+							'QST_admin_label',
468
+							$answer_row['Question.QST_admin_label']
469
+						);
470
+					} else {
471
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
472
+					}
473
+					if (isset($answer_row['Question.QST_type'])
474
+						&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
475
+					) {
476
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
477
+							$answer_row['Answer.ANS_value']
478
+						);
479
+					} else {
480
+						// this isn't for html, so don't show html entities
481
+						$reg_csv_array[ $question_label ] = html_entity_decode(
482
+							EEH_Export::prepare_value_from_db_for_display(
483
+								EEM_Answer::instance(),
484
+								'ANS_value',
485
+								$answer_row['Answer.ANS_value']
486
+							)
487
+						);
488
+					}
489
+				}
490 490
 
491
-                /**
492
-                 * Filter to change the contents of each row of the registrations report CSV file.
493
-                 * This can be used to add or remote columns from the CSV file, or change their values.
494
-                 * Note when using: all rows in the CSV should have the same columns.
495
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
496
-                 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
497
-                 */
498
-                $registrations_csv_ready_array[] = apply_filters(
499
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
500
-                    $reg_csv_array,
501
-                    $reg_row
502
-                );
503
-            }
504
-        }
505
-        // if we couldn't export anything, we want to at least show the column headers
506
-        if (empty($registrations_csv_ready_array)) {
507
-            $reg_csv_array = array();
508
-            $model_and_fields_to_include = array(
509
-                'Registration' => $reg_fields_to_include,
510
-                'Attendee'     => $att_fields_to_include,
511
-            );
512
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
513
-                $model = EE_Registry::instance()->load_model($model_name);
514
-                foreach ($field_list as $field_name) {
515
-                    $field = $model->field_settings_for($field_name);
516
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
517
-                }
518
-            }
519
-            $registrations_csv_ready_array[] = $reg_csv_array;
520
-        }
521
-        return $registrations_csv_ready_array;
522
-    }
491
+				/**
492
+				 * Filter to change the contents of each row of the registrations report CSV file.
493
+				 * This can be used to add or remote columns from the CSV file, or change their values.
494
+				 * Note when using: all rows in the CSV should have the same columns.
495
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
496
+				 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
497
+				 */
498
+				$registrations_csv_ready_array[] = apply_filters(
499
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
500
+					$reg_csv_array,
501
+					$reg_row
502
+				);
503
+			}
504
+		}
505
+		// if we couldn't export anything, we want to at least show the column headers
506
+		if (empty($registrations_csv_ready_array)) {
507
+			$reg_csv_array = array();
508
+			$model_and_fields_to_include = array(
509
+				'Registration' => $reg_fields_to_include,
510
+				'Attendee'     => $att_fields_to_include,
511
+			);
512
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
513
+				$model = EE_Registry::instance()->load_model($model_name);
514
+				foreach ($field_list as $field_name) {
515
+					$field = $model->field_settings_for($field_name);
516
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
517
+				}
518
+			}
519
+			$registrations_csv_ready_array[] = $reg_csv_array;
520
+		}
521
+		return $registrations_csv_ready_array;
522
+	}
523 523
 
524 524
 
525
-    /**
526
-     * Counts total unit to process
527
-     *
528
-     * @deprecated since 4.9.19
529
-     * @param int|array $event_id
530
-     * @return int
531
-     */
532
-    public function count_units_to_process($event_id)
533
-    {
534
-        // use the legacy filter
535
-        if ($event_id) {
536
-            $query_params[0]['EVT_ID'] = $event_id;
537
-        } else {
538
-            $query_params['force_join'][] = 'Event';
539
-        }
540
-        return \EEM_Registration::instance()->count($query_params);
541
-    }
525
+	/**
526
+	 * Counts total unit to process
527
+	 *
528
+	 * @deprecated since 4.9.19
529
+	 * @param int|array $event_id
530
+	 * @return int
531
+	 */
532
+	public function count_units_to_process($event_id)
533
+	{
534
+		// use the legacy filter
535
+		if ($event_id) {
536
+			$query_params[0]['EVT_ID'] = $event_id;
537
+		} else {
538
+			$query_params['force_join'][] = 'Event';
539
+		}
540
+		return \EEM_Registration::instance()->count($query_params);
541
+	}
542 542
 
543 543
 
544
-    /**
545
-     * Performs any clean-up logic when we know the job is completed.
546
-     * In this case, we delete the temporary file
547
-     *
548
-     * @param JobParameters $job_parameters
549
-     * @return boolean
550
-     */
551
-    public function cleanup_job(JobParameters $job_parameters)
552
-    {
553
-        $this->_file_helper->delete(
554
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
555
-            true,
556
-            'd'
557
-        );
558
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
559
-    }
544
+	/**
545
+	 * Performs any clean-up logic when we know the job is completed.
546
+	 * In this case, we delete the temporary file
547
+	 *
548
+	 * @param JobParameters $job_parameters
549
+	 * @return boolean
550
+	 */
551
+	public function cleanup_job(JobParameters $job_parameters)
552
+	{
553
+		$this->_file_helper->delete(
554
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
555
+			true,
556
+			'd'
557
+		);
558
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
559
+	}
560 560
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_answers.dmsstage.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -32,102 +32,102 @@
 block discarded – undo
32 32
 
33 33
 class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table
34 34
 {
35
-    private $_new_answer_table;
36
-    private $_new_question_table;
37
-    public function __construct()
38
-    {
39
-        global $wpdb;
40
-        $this->_pretty_name = __("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix."events_answer";
42
-        // join to attendee and then join to events table
43
-        $this->select_expression = 'ans.*, e.event_status';
44
-        $this->_extra_where_sql = ' AS ans 
35
+	private $_new_answer_table;
36
+	private $_new_question_table;
37
+	public function __construct()
38
+	{
39
+		global $wpdb;
40
+		$this->_pretty_name = __("Answers", "event_espresso");
41
+		$this->_old_table = $wpdb->prefix."events_answer";
42
+		// join to attendee and then join to events table
43
+		$this->select_expression = 'ans.*, e.event_status';
44
+		$this->_extra_where_sql = ' AS ans 
45 45
             INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
46 46
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
47 47
             WHERE e.event_status !="D"';
48
-        $this->_new_answer_table = $wpdb->prefix."esp_answer";
49
-        $this->_new_question_table = $wpdb->prefix."esp_question";
50
-        parent::__construct();
51
-    }
52
-    protected function _migrate_old_row($old_row)
53
-    {
54
-        // get the new REGs for the old answer
55
-        global $wpdb;
56
-        $old_attendee_table = $wpdb->prefix."events_attendee";
57
-        $new_reg_table = $wpdb->prefix."esp_registration";
58
-        $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
-        if (! $regs) {
60
-            $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61
-            return false;
62
-        }
63
-        // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
64
-        foreach ($regs as $new_reg_id) {
65
-            $this->_insert_new_answer($old_row, $new_reg_id);
66
-        }
67
-    }
68
-    /**
69
-     * Creates a 4.1 price base type
70
-     * @global type $wpdb
71
-     * @param array $old_price
72
-     * @param int $new_reg_id
73
-     * @return int
74
-     */
75
-    private function _insert_new_answer($old_answer, $new_reg_id)
76
-    {
77
-        global $wpdb;
78
-        $old_question_table = $wpdb->prefix."events_question";
79
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
48
+		$this->_new_answer_table = $wpdb->prefix."esp_answer";
49
+		$this->_new_question_table = $wpdb->prefix."esp_question";
50
+		parent::__construct();
51
+	}
52
+	protected function _migrate_old_row($old_row)
53
+	{
54
+		// get the new REGs for the old answer
55
+		global $wpdb;
56
+		$old_attendee_table = $wpdb->prefix."events_attendee";
57
+		$new_reg_table = $wpdb->prefix."esp_registration";
58
+		$regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
+		if (! $regs) {
60
+			$this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61
+			return false;
62
+		}
63
+		// as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
64
+		foreach ($regs as $new_reg_id) {
65
+			$this->_insert_new_answer($old_row, $new_reg_id);
66
+		}
67
+	}
68
+	/**
69
+	 * Creates a 4.1 price base type
70
+	 * @global type $wpdb
71
+	 * @param array $old_price
72
+	 * @param int $new_reg_id
73
+	 * @return int
74
+	 */
75
+	private function _insert_new_answer($old_answer, $new_reg_id)
76
+	{
77
+		global $wpdb;
78
+		$old_question_table = $wpdb->prefix."events_question";
79
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
80 80
 
81
-        $question_row = $this->_get_question_type_and_system($new_question_id);
82
-        if ($question_row['QST_system']) {
83
-            // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column,
84
-            // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom
85
-            // questions.
86
-            return 0;
87
-        }
88
-        if (in_array($question_row['QST_type'], array('MULTIPLE'))) {
89
-            $ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
90
-        } else {
91
-            $ans_value = stripslashes($old_answer['answer']);
92
-        }
93
-        $cols_n_values = array(
94
-            'REG_ID'=>$new_reg_id,
95
-            'QST_ID'=>$new_question_id,
96
-            'ANS_value'=>$ans_value
97
-        );
98
-        $datatypes = array(
99
-            '%d',// REG_ID
100
-            '%d',// QST_ID
101
-            '%s',// ANS_value
102
-        );
103
-        $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
-        if (! $success) {
105
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106
-            return 0;
107
-        }
108
-        $new_id = $wpdb->insert_id;
109
-        return $new_id;
110
-    }
81
+		$question_row = $this->_get_question_type_and_system($new_question_id);
82
+		if ($question_row['QST_system']) {
83
+			// It's an answer to a system question? EE3 used to store that on both the attendee and the answers column,
84
+			// but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom
85
+			// questions.
86
+			return 0;
87
+		}
88
+		if (in_array($question_row['QST_type'], array('MULTIPLE'))) {
89
+			$ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
90
+		} else {
91
+			$ans_value = stripslashes($old_answer['answer']);
92
+		}
93
+		$cols_n_values = array(
94
+			'REG_ID'=>$new_reg_id,
95
+			'QST_ID'=>$new_question_id,
96
+			'ANS_value'=>$ans_value
97
+		);
98
+		$datatypes = array(
99
+			'%d',// REG_ID
100
+			'%d',// QST_ID
101
+			'%s',// ANS_value
102
+		);
103
+		$success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
+		if (! $success) {
105
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106
+			return 0;
107
+		}
108
+		$new_id = $wpdb->insert_id;
109
+		return $new_id;
110
+	}
111 111
 
112
-    /**
113
-     * Gets the question's type
114
-     * @global type $wpdb
115
-     * @param type $question_id
116
-     * @return array {
117
-     *  @type string $QST_type
118
-     *  @type string $QST_system
119
-     * }
120
-     */
121
-    private function _get_question_type_and_system($question_id)
122
-    {
123
-        global $wpdb;
124
-        $row = $wpdb->get_row(
125
-            $wpdb->prepare(
126
-                "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1",
127
-                $question_id
128
-            ),
129
-            ARRAY_A
130
-        );
131
-        return $row;
132
-    }
112
+	/**
113
+	 * Gets the question's type
114
+	 * @global type $wpdb
115
+	 * @param type $question_id
116
+	 * @return array {
117
+	 *  @type string $QST_type
118
+	 *  @type string $QST_system
119
+	 * }
120
+	 */
121
+	private function _get_question_type_and_system($question_id)
122
+	{
123
+		global $wpdb;
124
+		$row = $wpdb->get_row(
125
+			$wpdb->prepare(
126
+				"SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1",
127
+				$question_id
128
+			),
129
+			ARRAY_A
130
+		);
131
+		return $row;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_questions.dmsstage.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -57,119 +57,119 @@
 block discarded – undo
57 57
  */
58 58
 class EE_DMS_4_1_0_questions extends EE_Data_Migration_Script_Stage
59 59
 {
60
-    private $_old_table;
61
-    private $_new_table;
62
-    private $_option_table;
63
-    public function _migration_step($num_items = 50)
64
-    {
65
-        global $wpdb;
66
-        $start_at_record = $this->count_records_migrated();
67
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
68
-        $items_actually_migrated = 0;
69
-        foreach ($rows as $question_row) {
70
-            $new_id = $this->_insert_new_question($question_row);
71
-            $this->get_migration_script()->set_mapping($this->_old_table, $question_row['id'], $this->_new_table, $new_id);
72
-            $items_actually_migrated++;
73
-        }
74
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
75
-            $this->set_completed();
76
-        }
77
-        return $items_actually_migrated;
78
-    }
79
-    public function _count_records_to_migrate()
80
-    {
81
-        global $wpdb;
82
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
83
-        return $count;
84
-    }
85
-    public function __construct()
86
-    {
87
-        global $wpdb;
88
-        $this->_pretty_name = __("Questions", "event_espresso");
89
-        $this->_old_table = $wpdb->prefix."events_question";
90
-        $this->_new_table = $wpdb->prefix."esp_question";
91
-        $this->_option_table = $wpdb->prefix."esp_question_option";
92
-        parent::__construct();
93
-    }
94
-    private function _insert_new_question($old_question)
95
-    {
96
-        global $wpdb;
97
-        // if this pretends to be a 'system' question, check if we already have a
98
-        // system question for that string. If so, pretend THAT new question
99
-        // is what we just isnerted
100
-        if ($old_question['system_name']) {
101
-            $id_of_new_system_question = intval($wpdb->get_var($wpdb->prepare("SELECT QST_ID FROM {$this->_new_table} WHERE QST_system = %s", $old_question['system_name'])));
102
-            if ($id_of_new_system_question) {
103
-                return $id_of_new_system_question;
104
-            }
105
-            // ok so this must be the first one. Carry on.
106
-        }
60
+	private $_old_table;
61
+	private $_new_table;
62
+	private $_option_table;
63
+	public function _migration_step($num_items = 50)
64
+	{
65
+		global $wpdb;
66
+		$start_at_record = $this->count_records_migrated();
67
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
68
+		$items_actually_migrated = 0;
69
+		foreach ($rows as $question_row) {
70
+			$new_id = $this->_insert_new_question($question_row);
71
+			$this->get_migration_script()->set_mapping($this->_old_table, $question_row['id'], $this->_new_table, $new_id);
72
+			$items_actually_migrated++;
73
+		}
74
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
75
+			$this->set_completed();
76
+		}
77
+		return $items_actually_migrated;
78
+	}
79
+	public function _count_records_to_migrate()
80
+	{
81
+		global $wpdb;
82
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
83
+		return $count;
84
+	}
85
+	public function __construct()
86
+	{
87
+		global $wpdb;
88
+		$this->_pretty_name = __("Questions", "event_espresso");
89
+		$this->_old_table = $wpdb->prefix."events_question";
90
+		$this->_new_table = $wpdb->prefix."esp_question";
91
+		$this->_option_table = $wpdb->prefix."esp_question_option";
92
+		parent::__construct();
93
+	}
94
+	private function _insert_new_question($old_question)
95
+	{
96
+		global $wpdb;
97
+		// if this pretends to be a 'system' question, check if we already have a
98
+		// system question for that string. If so, pretend THAT new question
99
+		// is what we just isnerted
100
+		if ($old_question['system_name']) {
101
+			$id_of_new_system_question = intval($wpdb->get_var($wpdb->prepare("SELECT QST_ID FROM {$this->_new_table} WHERE QST_system = %s", $old_question['system_name'])));
102
+			if ($id_of_new_system_question) {
103
+				return $id_of_new_system_question;
104
+			}
105
+			// ok so this must be the first one. Carry on.
106
+		}
107 107
 
108
-        $cols_n_values = array(
109
-            'QST_display_text' => stripslashes($old_question['question']),
110
-            'QST_admin_label' => $old_question['system_name'] ? $old_question['system_name'] : sanitize_title($old_question['question']),
111
-            'QST_system' => (string) $old_question['system_name'],
112
-            'QST_type' => $old_question['question_type'],
113
-            'QST_required' => 'Y' == $old_question['required'],
114
-            'QST_required_text' => stripslashes($old_question['required_text']),
115
-            'QST_order' => $old_question['sequence'],
116
-            'QST_admin_only' => 'Y' == $old_question['admin_only'],
117
-            'QST_wp_user' => $old_question['wp_user'],
118
-            'QST_deleted' => false
119
-        );
120
-        $datatypes = array(
121
-            '%s',// QST_display_text
122
-            '%s',// QST-admin_label
123
-            '%s',// QST_system
124
-            '%s',// QST_type
125
-            '%d',// QST_required
126
-            '%s',// QST_required_text
127
-            '%d',// QST_order
128
-            '%d',// QST_admin_only
129
-            '%d',// QST_wp_user
130
-            '%d',// QST_deleted
131
-        );
132
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
133
-        if (! $success) {
134
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question, $this->_new_table, $cols_n_values, $datatypes));
135
-            return 0;
136
-        }
137
-        $new_id = $wpdb->insert_id;
138
-        // now take care of posisbly adding question options
139
-        if (in_array($old_question['question_type'], array('DROPDOWN','SINGLE','MULTIPLE'))) {
140
-            $options = explode(",", $old_question['response']);
141
-            foreach ($options as $option) {
142
-                $this->_insert_question_option($option, $new_id);
143
-            }
144
-        }
145
-        return $new_id;
146
-    }
147
-    /**
148
-     * Adds a question option to the db
149
-     * @global type $wpdb
150
-     * @param string $option
151
-     * @param int $question_id
152
-     * @return int
153
-     */
154
-    private function _insert_question_option($option, $question_id)
155
-    {
156
-        $option = trim($option);
157
-        global $wpdb;
158
-        $cols_n_values = array(
159
-            'QST_ID'=>$question_id,
160
-            'QSO_value'=>$option,
161
-            'QSO_deleted'=>false
162
-        );
163
-        $datatypes= array(
164
-            '%d',// QST_ID
165
-            '%s',// QSO_value
166
-            '%d',// QSO_deleted
167
-        );
168
-        $success = $wpdb->insert($this->_option_table, $cols_n_values, $datatypes);
169
-        if (! $success) {
170
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option,'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
171
-            return 0;
172
-        }
173
-        return $wpdb->insert_id;
174
-    }
108
+		$cols_n_values = array(
109
+			'QST_display_text' => stripslashes($old_question['question']),
110
+			'QST_admin_label' => $old_question['system_name'] ? $old_question['system_name'] : sanitize_title($old_question['question']),
111
+			'QST_system' => (string) $old_question['system_name'],
112
+			'QST_type' => $old_question['question_type'],
113
+			'QST_required' => 'Y' == $old_question['required'],
114
+			'QST_required_text' => stripslashes($old_question['required_text']),
115
+			'QST_order' => $old_question['sequence'],
116
+			'QST_admin_only' => 'Y' == $old_question['admin_only'],
117
+			'QST_wp_user' => $old_question['wp_user'],
118
+			'QST_deleted' => false
119
+		);
120
+		$datatypes = array(
121
+			'%s',// QST_display_text
122
+			'%s',// QST-admin_label
123
+			'%s',// QST_system
124
+			'%s',// QST_type
125
+			'%d',// QST_required
126
+			'%s',// QST_required_text
127
+			'%d',// QST_order
128
+			'%d',// QST_admin_only
129
+			'%d',// QST_wp_user
130
+			'%d',// QST_deleted
131
+		);
132
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
133
+		if (! $success) {
134
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question, $this->_new_table, $cols_n_values, $datatypes));
135
+			return 0;
136
+		}
137
+		$new_id = $wpdb->insert_id;
138
+		// now take care of posisbly adding question options
139
+		if (in_array($old_question['question_type'], array('DROPDOWN','SINGLE','MULTIPLE'))) {
140
+			$options = explode(",", $old_question['response']);
141
+			foreach ($options as $option) {
142
+				$this->_insert_question_option($option, $new_id);
143
+			}
144
+		}
145
+		return $new_id;
146
+	}
147
+	/**
148
+	 * Adds a question option to the db
149
+	 * @global type $wpdb
150
+	 * @param string $option
151
+	 * @param int $question_id
152
+	 * @return int
153
+	 */
154
+	private function _insert_question_option($option, $question_id)
155
+	{
156
+		$option = trim($option);
157
+		global $wpdb;
158
+		$cols_n_values = array(
159
+			'QST_ID'=>$question_id,
160
+			'QSO_value'=>$option,
161
+			'QSO_deleted'=>false
162
+		);
163
+		$datatypes= array(
164
+			'%d',// QST_ID
165
+			'%s',// QSO_value
166
+			'%d',// QSO_deleted
167
+		);
168
+		$success = $wpdb->insert($this->_option_table, $cols_n_values, $datatypes);
169
+		if (! $success) {
170
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option,'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
171
+			return 0;
172
+		}
173
+		return $wpdb->insert_id;
174
+	}
175 175
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -118,25 +118,25 @@  discard block
 block discarded – undo
118 118
             'QST_deleted' => false
119 119
         );
120 120
         $datatypes = array(
121
-            '%s',// QST_display_text
122
-            '%s',// QST-admin_label
123
-            '%s',// QST_system
124
-            '%s',// QST_type
125
-            '%d',// QST_required
126
-            '%s',// QST_required_text
127
-            '%d',// QST_order
128
-            '%d',// QST_admin_only
129
-            '%d',// QST_wp_user
130
-            '%d',// QST_deleted
121
+            '%s', // QST_display_text
122
+            '%s', // QST-admin_label
123
+            '%s', // QST_system
124
+            '%s', // QST_type
125
+            '%d', // QST_required
126
+            '%s', // QST_required_text
127
+            '%d', // QST_order
128
+            '%d', // QST_admin_only
129
+            '%d', // QST_wp_user
130
+            '%d', // QST_deleted
131 131
         );
132 132
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
133
-        if (! $success) {
133
+        if ( ! $success) {
134 134
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question, $this->_new_table, $cols_n_values, $datatypes));
135 135
             return 0;
136 136
         }
137 137
         $new_id = $wpdb->insert_id;
138 138
         // now take care of posisbly adding question options
139
-        if (in_array($old_question['question_type'], array('DROPDOWN','SINGLE','MULTIPLE'))) {
139
+        if (in_array($old_question['question_type'], array('DROPDOWN', 'SINGLE', 'MULTIPLE'))) {
140 140
             $options = explode(",", $old_question['response']);
141 141
             foreach ($options as $option) {
142 142
                 $this->_insert_question_option($option, $new_id);
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
             'QSO_value'=>$option,
161 161
             'QSO_deleted'=>false
162 162
         );
163
-        $datatypes= array(
164
-            '%d',// QST_ID
165
-            '%s',// QSO_value
166
-            '%d',// QSO_deleted
163
+        $datatypes = array(
164
+            '%d', // QST_ID
165
+            '%s', // QSO_value
166
+            '%d', // QSO_deleted
167 167
         );
168 168
         $success = $wpdb->insert($this->_option_table, $cols_n_values, $datatypes);
169
-        if (! $success) {
170
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option,'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
169
+        if ( ! $success) {
170
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option, 'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
171 171
             return 0;
172 172
         }
173 173
         return $wpdb->insert_id;
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.81.rc.006');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.81.rc.006');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.