@@ -24,15 +24,15 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct() { |
| 26 | 26 | static $initialized = false; |
| 27 | - if ( ! $initialized ) { |
|
| 27 | + if ( ! $initialized) { |
|
| 28 | 28 | // instantiate PSR4 autoloader |
| 29 | - espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' ); |
|
| 29 | + espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php'); |
|
| 30 | 30 | EE_Psr4AutoloaderInit::$psr4_loader = new \EventEspresso\Core\Psr4Autoloader(); |
| 31 | 31 | // register the autoloader |
| 32 | 32 | EE_Psr4AutoloaderInit::$psr4_loader->register(); |
| 33 | 33 | // register the base directories for the namespace prefix |
| 34 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspresso', EE_PLUGIN_DIR_PATH ); |
|
| 35 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspressoBatchRequest', EE_LIBRARIES . 'batch' ); |
|
| 34 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
| 35 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch'); |
|
| 36 | 36 | $initialized = true; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -1,17 +1,17 @@ discard block |
||
| 1 | 1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
| 2 | 2 | /** |
| 3 | - * CSV Import Export class |
|
| 4 | - * |
|
| 5 | - * For dealing with CSV files directly. For exports/reports, it would generally |
|
| 6 | - * be preferred to use EventEspressoBatchRequest\BatchRequestProcessor and |
|
| 7 | - * EEH_Export to create csv files on the server and then direct the user to download them |
|
| 8 | - * |
|
| 9 | - * @package Event Espresso |
|
| 10 | - * @subpackage includes/functions |
|
| 11 | - * @author Brent Christensen |
|
| 12 | - * |
|
| 13 | - * ------------------------------------------------------------------------ |
|
| 14 | - */ |
|
| 3 | + * CSV Import Export class |
|
| 4 | + * |
|
| 5 | + * For dealing with CSV files directly. For exports/reports, it would generally |
|
| 6 | + * be preferred to use EventEspressoBatchRequest\BatchRequestProcessor and |
|
| 7 | + * EEH_Export to create csv files on the server and then direct the user to download them |
|
| 8 | + * |
|
| 9 | + * @package Event Espresso |
|
| 10 | + * @subpackage includes/functions |
|
| 11 | + * @author Brent Christensen |
|
| 12 | + * |
|
| 13 | + * ------------------------------------------------------------------------ |
|
| 14 | + */ |
|
| 15 | 15 | class EE_CSV { |
| 16 | 16 | |
| 17 | 17 | // instance of the EE_CSV object |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | // header("Content-Type: application/download"); |
| 320 | 320 | header('Content-disposition: attachment; filename='.$filename); |
| 321 | 321 | header("Content-Type: text/csv; charset=utf-8"); |
| 322 | - do_action( 'AHEE__EE_CSV__begin_sending_csv__headers' ); |
|
| 322 | + do_action( 'AHEE__EE_CSV__begin_sending_csv__headers' ); |
|
| 323 | 323 | echo apply_filters('FHEE__EE_CSV__begin_sending_csv__start_writing', "\xEF\xBB\xBF" ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
| 324 | 324 | $fh = fopen('php://output', 'w'); |
| 325 | 325 | return $fh; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3 | 3 | /** |
| 4 | 4 | * EE_Export class |
| 5 | 5 | * |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | * @access private |
| 40 | 40 | * @param array $request_data |
| 41 | 41 | */ |
| 42 | - private function __construct( $request_data = array() ) { |
|
| 42 | + private function __construct($request_data = array()) { |
|
| 43 | 43 | $this->_req_data = $request_data; |
| 44 | - $this->today = date("Y-m-d",time()); |
|
| 45 | - require_once( EE_CLASSES . 'EE_CSV.class.php' ); |
|
| 46 | - $this->EE_CSV= EE_CSV::instance(); |
|
| 44 | + $this->today = date("Y-m-d", time()); |
|
| 45 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
| 46 | + $this->EE_CSV = EE_CSV::instance(); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | * @param array $request_data |
| 56 | 56 | * @return \EE_Export |
| 57 | 57 | */ |
| 58 | - public static function instance( $request_data = array() ) { |
|
| 58 | + public static function instance($request_data = array()) { |
|
| 59 | 59 | // check if class object is instantiated |
| 60 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Export )) { |
|
| 61 | - self::$_instance = new self( $request_data ); |
|
| 60 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
| 61 | + self::$_instance = new self($request_data); |
|
| 62 | 62 | } |
| 63 | 63 | return self::$_instance; |
| 64 | 64 | } |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | public function export() { |
| 73 | 73 | |
| 74 | 74 | // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
| 75 | - if ( isset( $this->_req_data['action'] ) && strpos( $this->_req_data['action'], 'export' ) === FALSE ) { |
|
| 75 | + if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === FALSE) { |
|
| 76 | 76 | // check if action2 has export action |
| 77 | - if ( isset( $this->_req_data['action2'] ) && strpos( $this->_req_data['action2'], 'export' ) !== FALSE ) { |
|
| 77 | + if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== FALSE) { |
|
| 78 | 78 | // whoop! there it is! |
| 79 | 79 | $this->_req_data['action'] = $this->_req_data['action2']; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $this->_req_data['export'] = isset( $this->_req_data['export'] ) ? $this->_req_data['export'] : ''; |
|
| 83 | + $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
| 84 | 84 | |
| 85 | 85 | switch ($this->_req_data['export']) { |
| 86 | 86 | case 'report': |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | break; |
| 95 | 95 | |
| 96 | 96 | case 'registrations_report_for_event': |
| 97 | - $this->report_registrations_for_event( $this->_req_data['EVT_ID'] ); |
|
| 97 | + $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
| 98 | 98 | break; |
| 99 | 99 | |
| 100 | 100 | case 'attendees': |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | break; |
| 107 | 107 | |
| 108 | 108 | default: |
| 109 | - EE_Error::add_error(__('An error occurred! The requested export report could not be found.','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ) ; |
|
| 109 | + EE_Error::add_error(__('An error occurred! The requested export report could not be found.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 110 | 110 | return FALSE; |
| 111 | 111 | break; |
| 112 | 112 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * Downloads a CSV file with all the columns, but no data. This should be used for importing |
| 125 | 125 | * @return null kills execution |
| 126 | 126 | */ |
| 127 | - function export_sample(){ |
|
| 127 | + function export_sample() { |
|
| 128 | 128 | $event = EEM_Event::instance()->get_one(); |
| 129 | 129 | $this->_req_data['EVT_ID'] = $event->ID(); |
| 130 | 130 | $this->export_all_event_data(); |
@@ -150,23 +150,23 @@ discard block |
||
| 150 | 150 | $state_country_query_params = array(); |
| 151 | 151 | $question_group_query_params = array(); |
| 152 | 152 | $question_query_params = array(); |
| 153 | - if ( isset( $this->_req_data['EVT_ID'] )) { |
|
| 153 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 154 | 154 | // do we have an array of IDs ? |
| 155 | 155 | |
| 156 | - if ( is_array( $this->_req_data['EVT_ID'] )) { |
|
| 157 | - $EVT_IDs = array_map( 'sanitize_text_field', $this->_req_data['EVT_ID'] ); |
|
| 158 | - $value_to_equal = array('IN',$EVT_IDs); |
|
| 156 | + if (is_array($this->_req_data['EVT_ID'])) { |
|
| 157 | + $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
| 158 | + $value_to_equal = array('IN', $EVT_IDs); |
|
| 159 | 159 | $filename = 'events'; |
| 160 | 160 | } else { |
| 161 | 161 | // generate regular where = clause |
| 162 | - $EVT_ID = absint( $this->_req_data['EVT_ID'] ); |
|
| 162 | + $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
| 163 | 163 | $value_to_equal = $EVT_ID; |
| 164 | 164 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
| 165 | 165 | |
| 166 | - $filename = 'event-' . ( $event instanceof EE_Event ? $event->slug() : __( 'unknown', 'event_espresso' ) ); |
|
| 166 | + $filename = 'event-'.($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
| 167 | 167 | |
| 168 | 168 | } |
| 169 | - $event_query_params[0]['EVT_ID'] =$value_to_equal; |
|
| 169 | + $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
| 170 | 170 | $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
| 171 | 171 | $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
| 172 | 172 | $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
@@ -210,37 +210,37 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | ); |
| 212 | 212 | |
| 213 | - $model_data = $this->_get_export_data_for_models( $models_to_export ); |
|
| 213 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
| 214 | 214 | |
| 215 | - $filename = $this->generate_filename ( $filename ); |
|
| 215 | + $filename = $this->generate_filename($filename); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename, $model_data )) { |
|
| 218 | - EE_Error::add_error(__("'An error occurred and the Event details could not be exported from the database.'", "event_espresso"), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 217 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 218 | + EE_Error::add_error(__("'An error occurred and the Event details could not be exported from the database.'", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - function report_attendees(){ |
|
| 223 | - $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( array( 'force_join' => array( 'State', 'Country' ) ) ); |
|
| 222 | + function report_attendees() { |
|
| 223 | + $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results(array('force_join' => array('State', 'Country'))); |
|
| 224 | 224 | $csv_data = array(); |
| 225 | - foreach( $attendee_rows as $attendee_row ){ |
|
| 225 | + foreach ($attendee_rows as $attendee_row) { |
|
| 226 | 226 | $csv_row = array(); |
| 227 | - foreach( EEM_Attendee::instance()->field_settings() as $field_name => $field_obj ){ |
|
| 228 | - if( $field_name == 'STA_ID' ){ |
|
| 229 | - $state_name_field = EEM_State::instance()->field_settings_for( 'STA_name' ); |
|
| 230 | - $csv_row[ __( 'State', 'event_espresso' ) ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
| 231 | - }elseif( $field_name == 'CNT_ISO' ){ |
|
| 232 | - $country_name_field = EEM_Country::instance()->field_settings_for( 'CNT_name' ); |
|
| 233 | - $csv_row[ __( 'Country', 'event_espresso' ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
| 234 | - }else{ |
|
| 235 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
| 227 | + foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
| 228 | + if ($field_name == 'STA_ID') { |
|
| 229 | + $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
| 230 | + $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()]; |
|
| 231 | + }elseif ($field_name == 'CNT_ISO') { |
|
| 232 | + $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
| 233 | + $csv_row[__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
| 234 | + } else { |
|
| 235 | + $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; |
|
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | $csv_data[] = $csv_row; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $filename = $this->generate_filename ( 'contact-list-report' ); |
|
| 241 | + $filename = $this->generate_filename('contact-list-report'); |
|
| 242 | 242 | |
| 243 | - $handle = $this->EE_CSV->begin_sending_csv( $filename); |
|
| 243 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
| 244 | 244 | $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
| 245 | 245 | $this->EE_CSV->end_sending_csv($handle); |
| 246 | 246 | } |
@@ -257,18 +257,18 @@ discard block |
||
| 257 | 257 | $countries_that_have_an_attendee = EEM_Country::instance()->get_all(array(0=>array('Attendee.ATT_ID'=>array('IS NOT NULL')))); |
| 258 | 258 | // $states_to_export_query_params |
| 259 | 259 | $models_to_export = array( |
| 260 | - 'Country'=>array(array('CNT_ISO'=>array('IN',array_keys($countries_that_have_an_attendee)))), |
|
| 261 | - 'State'=>array(array('STA_ID'=>array('IN',array_keys($states_that_have_an_attendee)))), |
|
| 260 | + 'Country'=>array(array('CNT_ISO'=>array('IN', array_keys($countries_that_have_an_attendee)))), |
|
| 261 | + 'State'=>array(array('STA_ID'=>array('IN', array_keys($states_that_have_an_attendee)))), |
|
| 262 | 262 | 'Attendee'=>array(), |
| 263 | 263 | ); |
| 264 | 264 | |
| 265 | 265 | |
| 266 | 266 | |
| 267 | - $model_data = $this->_get_export_data_for_models( $models_to_export ); |
|
| 268 | - $filename = $this->generate_filename ( 'all-attendees' ); |
|
| 267 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
| 268 | + $filename = $this->generate_filename('all-attendees'); |
|
| 269 | 269 | |
| 270 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename, $model_data )) { |
|
| 271 | - EE_Error::add_error(__('An error occurred and the Attendee data could not be exported from the database.','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 270 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
| 271 | + EE_Error::add_error(__('An error occurred and the Attendee data could not be exported from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
@@ -280,19 +280,19 @@ discard block |
||
| 280 | 280 | * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | - protected function _prepare_value_from_db_for_display( $model, $field_name, $raw_db_value, $pretty_schema = true ) { |
|
| 284 | - $field_obj = $model->field_settings_for( $field_name ); |
|
| 285 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db( $raw_db_value ); |
|
| 286 | - if( $field_obj instanceof EE_Datetime_Field ) { |
|
| 287 | - $field_obj->set_date_format( EE_CSV::instance()->get_date_format_for_csv( $field_obj->get_date_format( $pretty_schema ) ), $pretty_schema ); |
|
| 288 | - $field_obj->set_time_format( EE_CSV::instance()->get_time_format_for_csv( $field_obj->get_time_format( $pretty_schema ) ), $pretty_schema ); |
|
| 283 | + protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) { |
|
| 284 | + $field_obj = $model->field_settings_for($field_name); |
|
| 285 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
| 286 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 287 | + $field_obj->set_date_format(EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
| 288 | + $field_obj->set_time_format(EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
| 289 | 289 | } |
| 290 | - if( $pretty_schema === true){ |
|
| 291 | - return $field_obj->prepare_for_pretty_echoing( $value_on_model_obj ); |
|
| 292 | - }elseif( is_string( $pretty_schema ) ) { |
|
| 293 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema ); |
|
| 294 | - }else{ |
|
| 295 | - return $field_obj->prepare_for_get( $value_on_model_obj ); |
|
| 290 | + if ($pretty_schema === true) { |
|
| 291 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
| 292 | + }elseif (is_string($pretty_schema)) { |
|
| 293 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
| 294 | + } else { |
|
| 295 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * and the questions associated with the registrations |
| 302 | 302 | * @param int $event_id |
| 303 | 303 | */ |
| 304 | - function report_registrations_for_event( $event_id = NULL ){ |
|
| 304 | + function report_registrations_for_event($event_id = NULL) { |
|
| 305 | 305 | $reg_fields_to_include = array( |
| 306 | 306 | 'TXN_ID', |
| 307 | 307 | 'ATT_ID', |
@@ -333,125 +333,125 @@ discard block |
||
| 333 | 333 | array( |
| 334 | 334 | 'OR' => array( |
| 335 | 335 | //don't include registrations from failed or abandoned transactions... |
| 336 | - 'Transaction.STS_ID' => array( 'NOT IN', array( EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code ) ), |
|
| 336 | + 'Transaction.STS_ID' => array('NOT IN', array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code)), |
|
| 337 | 337 | //unless the registration is approved, in which case include it regardless of transaction status |
| 338 | 338 | 'STS_ID' => EEM_Registration::status_id_approved |
| 339 | 339 | ), |
| 340 | - 'Ticket.TKT_deleted' => array( 'IN', array( true, false ) ) |
|
| 340 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)) |
|
| 341 | 341 | ), |
| 342 | - 'order_by' => array('Transaction.TXN_ID'=>'asc','REG_count'=>'asc'), |
|
| 343 | - 'force_join' => array( 'Transaction', 'Ticket', 'Attendee' ) |
|
| 342 | + 'order_by' => array('Transaction.TXN_ID'=>'asc', 'REG_count'=>'asc'), |
|
| 343 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee') |
|
| 344 | 344 | ), |
| 345 | 345 | $event_id |
| 346 | 346 | ); |
| 347 | - if( $event_id ){ |
|
| 348 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 349 | - }else{ |
|
| 350 | - $query_params[ 'force_join' ][] = 'Event'; |
|
| 347 | + if ($event_id) { |
|
| 348 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 349 | + } else { |
|
| 350 | + $query_params['force_join'][] = 'Event'; |
|
| 351 | 351 | } |
| 352 | - $registration_rows = $reg_model->get_all_wpdb_results( $query_params ); |
|
| 352 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 353 | 353 | //get all questions which relate to someone in this group |
| 354 | 354 | $registration_ids = array(); |
| 355 | - foreach( $registration_rows as $reg_row ) { |
|
| 356 | - $registration_ids[] = intval( $reg_row[ 'Registration.REG_ID'] ); |
|
| 355 | + foreach ($registration_rows as $reg_row) { |
|
| 356 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 357 | 357 | } |
| 358 | 358 | // EEM_Question::instance()->show_next_x_db_queries(); |
| 359 | - $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(array(array('Answer.REG_ID'=>array('IN',$registration_ids)))); |
|
| 360 | - foreach($registration_rows as $reg_row){ |
|
| 361 | - if ( is_array( $reg_row ) ) { |
|
| 359 | + $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(array(array('Answer.REG_ID'=>array('IN', $registration_ids)))); |
|
| 360 | + foreach ($registration_rows as $reg_row) { |
|
| 361 | + if (is_array($reg_row)) { |
|
| 362 | 362 | $reg_csv_array = array(); |
| 363 | - if( ! $event_id ){ |
|
| 363 | + if ( ! $event_id) { |
|
| 364 | 364 | //get the event's name and Id |
| 365 | - $reg_csv_array[ __( 'Event', 'event_espresso' ) ] = sprintf( __( '%1$s (%2$s)', 'event_espresso' ), $this->_prepare_value_from_db_for_display( EEM_Event::instance(), 'EVT_name', $reg_row[ 'Event_CPT.post_title'] ), $reg_row[ 'Event_CPT.ID' ] ); |
|
| 365 | + $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), $this->_prepare_value_from_db_for_display(EEM_Event::instance(), 'EVT_name', $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); |
|
| 366 | 366 | } |
| 367 | - $is_primary_reg = $reg_row[ 'Registration.REG_count' ] == '1' ? true : false; |
|
| 367 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 368 | 368 | /*@var $reg_row EE_Registration */ |
| 369 | - foreach($reg_fields_to_include as $field_name){ |
|
| 369 | + foreach ($reg_fields_to_include as $field_name) { |
|
| 370 | 370 | $field = $reg_model->field_settings_for($field_name); |
| 371 | - if($field_name == 'REG_final_price'){ |
|
| 372 | - $value = $this->_prepare_value_from_db_for_display( $reg_model, $field_name, $reg_row[ 'Registration.REG_final_price'], 'localized_float' ); |
|
| 373 | - }elseif( $field_name == 'REG_count' ){ |
|
| 374 | - $value = sprintf( __( '%s of %s', 'event_espresso' ), $this->_prepare_value_from_db_for_display( $reg_model, 'REG_count', $reg_row['Registration.REG_count'] ), $this->_prepare_value_from_db_for_display( $reg_model, 'REG_group_size', $reg_row['Registration.REG_group_size' ] ) ); |
|
| 375 | - }elseif( $field_name == 'REG_date' ) { |
|
| 376 | - $value = $this->_prepare_value_from_db_for_display( $reg_model, $field_name, $reg_row[ 'Registration.REG_date'], 'no_html' ); |
|
| 377 | - }else{ |
|
| 378 | - $value = $this->_prepare_value_from_db_for_display( $reg_model, $field_name, $reg_row[ $field->get_qualified_column() ] ); |
|
| 371 | + if ($field_name == 'REG_final_price') { |
|
| 372 | + $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row['Registration.REG_final_price'], 'localized_float'); |
|
| 373 | + }elseif ($field_name == 'REG_count') { |
|
| 374 | + $value = sprintf(__('%s of %s', 'event_espresso'), $this->_prepare_value_from_db_for_display($reg_model, 'REG_count', $reg_row['Registration.REG_count']), $this->_prepare_value_from_db_for_display($reg_model, 'REG_group_size', $reg_row['Registration.REG_group_size'])); |
|
| 375 | + }elseif ($field_name == 'REG_date') { |
|
| 376 | + $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row['Registration.REG_date'], 'no_html'); |
|
| 377 | + } else { |
|
| 378 | + $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row[$field->get_qualified_column()]); |
|
| 379 | 379 | } |
| 380 | 380 | $reg_csv_array[$this->_get_column_name_for_field($field)] = $value; |
| 381 | - if($field_name == 'REG_final_price'){ |
|
| 381 | + if ($field_name == 'REG_final_price') { |
|
| 382 | 382 | //add a column named Currency after the final price |
| 383 | 383 | $reg_csv_array[__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | //get pretty status |
| 387 | - $stati = EEM_Status::instance()->localized_status( array( |
|
| 388 | - $reg_row[ 'Registration.STS_ID' ] => __( 'unknown', 'event_espresso' ), |
|
| 389 | - $reg_row[ 'Transaction.STS_ID' ] => __( 'unknown', 'event_espresso' ) ), |
|
| 387 | + $stati = EEM_Status::instance()->localized_status(array( |
|
| 388 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 389 | + $reg_row['Transaction.STS_ID'] => __('unknown', 'event_espresso') ), |
|
| 390 | 390 | FALSE, |
| 391 | - 'sentence' ); |
|
| 392 | - $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[ $reg_row[ 'Registration.STS_ID' ] ]; |
|
| 391 | + 'sentence'); |
|
| 392 | + $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
| 393 | 393 | //get pretty trnasaction status |
| 394 | - $reg_csv_array[__("Transaction Status", 'event_espresso')] = $stati[ $reg_row[ 'Transaction.STS_ID' ] ]; |
|
| 395 | - $reg_csv_array[ __( 'Transaction Amount Due', 'event_espresso' ) ] = $is_primary_reg ? $this->_prepare_value_from_db_for_display( EEM_Transaction::instance(), 'TXN_total', $reg_row[ 'Transaction.TXN_total' ], 'localized_float' ) : '0.00'; |
|
| 396 | - $reg_csv_array[ __( 'Amount Paid', 'event_espresso' )] = $is_primary_reg ? $this->_prepare_value_from_db_for_display( EEM_Transaction::instance(), 'TXN_paid', $reg_row[ 'Transaction.TXN_paid' ], 'localized_float' ) : '0.00'; |
|
| 394 | + $reg_csv_array[__("Transaction Status", 'event_espresso')] = $stati[$reg_row['Transaction.STS_ID']]; |
|
| 395 | + $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg ? $this->_prepare_value_from_db_for_display(EEM_Transaction::instance(), 'TXN_total', $reg_row['Transaction.TXN_total'], 'localized_float') : '0.00'; |
|
| 396 | + $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg ? $this->_prepare_value_from_db_for_display(EEM_Transaction::instance(), 'TXN_paid', $reg_row['Transaction.TXN_paid'], 'localized_float') : '0.00'; |
|
| 397 | 397 | $payment_methods = array(); |
| 398 | 398 | $gateway_txn_ids_etc = array(); |
| 399 | 399 | $payment_times = array(); |
| 400 | - if( $is_primary_reg && $reg_row[ 'Transaction.TXN_ID' ] ){ |
|
| 400 | + if ($is_primary_reg && $reg_row['Transaction.TXN_ID']) { |
|
| 401 | 401 | $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
| 402 | 402 | array( |
| 403 | 403 | array( |
| 404 | - 'TXN_ID' => $reg_row[ 'Transaction.TXN_ID' ], |
|
| 404 | + 'TXN_ID' => $reg_row['Transaction.TXN_ID'], |
|
| 405 | 405 | 'STS_ID' => EEM_Payment::status_id_approved |
| 406 | 406 | ), |
| 407 | - 'force_join' => array( 'Payment_Method' ), |
|
| 407 | + 'force_join' => array('Payment_Method'), |
|
| 408 | 408 | |
| 409 | 409 | ), |
| 410 | 410 | ARRAY_A, |
| 411 | 411 | 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' ); |
| 412 | 412 | |
| 413 | - foreach( $payments_info as $payment_method_and_gateway_txn_id ){ |
|
| 414 | - $payment_methods[] = isset( $payment_method_and_gateway_txn_id[ 'name' ] ) ? $payment_method_and_gateway_txn_id[ 'name' ] : __( 'Unknown', 'event_espresso' ); |
|
| 415 | - $gateway_txn_ids_etc[] = isset( $payment_method_and_gateway_txn_id[ 'gateway_txn_id' ] ) ? $payment_method_and_gateway_txn_id[ 'gateway_txn_id' ] : ''; |
|
| 416 | - $payment_times[] = isset( $payment_method_and_gateway_txn_id[ 'payment_time' ] ) ? $payment_method_and_gateway_txn_id[ 'payment_time' ] : ''; |
|
| 413 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 414 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 415 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 416 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | } |
| 420 | - $reg_csv_array[ __( 'Payment Date(s)', 'event_espresso' ) ] = implode( ',', $payment_times ); |
|
| 421 | - $reg_csv_array[ __( 'Payment Method(s)', 'event_espresso' ) ] = implode( ",", $payment_methods ); |
|
| 422 | - $reg_csv_array[ __( 'Gateway Transaction ID(s)', 'event_espresso' )] = implode( ',', $gateway_txn_ids_etc ); |
|
| 420 | + $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
| 421 | + $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
| 422 | + $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); |
|
| 423 | 423 | |
| 424 | 424 | //get whether or not the user has checked in |
| 425 | - $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related( $reg_row[ 'Registration.REG_ID'] , 'Checkin' ); |
|
| 425 | + $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); |
|
| 426 | 426 | //get ticket of registration and its price |
| 427 | 427 | $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
| 428 | - if( $reg_row[ 'Ticket.TKT_ID'] ) { |
|
| 429 | - $ticket_name = $this->_prepare_value_from_db_for_display( $ticket_model, 'TKT_name', $reg_row[ 'Ticket.TKT_name' ] ); |
|
| 428 | + if ($reg_row['Ticket.TKT_ID']) { |
|
| 429 | + $ticket_name = $this->_prepare_value_from_db_for_display($ticket_model, 'TKT_name', $reg_row['Ticket.TKT_name']); |
|
| 430 | 430 | $datetimes_strings = array(); |
| 431 | - foreach( EEM_Datetime::instance()->get_all_wpdb_results( array( array( 'Ticket.TKT_ID' => $reg_row[ 'Ticket.TKT_ID' ] ), 'order_by' => array( 'DTT_EVT_start' => 'ASC' ), 'default_where_conditions' => 'none' ) ) as $datetime){ |
|
| 432 | - $datetimes_strings[] = $this->_prepare_value_from_db_for_display( EEM_Datetime::instance(), 'DTT_EVT_start', $datetime[ 'Datetime.DTT_EVT_start'] ); |
|
| 431 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results(array(array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), 'order_by' => array('DTT_EVT_start' => 'ASC'), 'default_where_conditions' => 'none')) as $datetime) { |
|
| 432 | + $datetimes_strings[] = $this->_prepare_value_from_db_for_display(EEM_Datetime::instance(), 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | } else { |
| 436 | - $ticket_name = __( 'Unknown', 'event_espresso' ); |
|
| 437 | - $datetimes_strings = array( __( 'Unknown', 'event_espresso' ) ); |
|
| 436 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
| 437 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 438 | 438 | } |
| 439 | 439 | $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
| 440 | 440 | $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
| 441 | 441 | //get datetime(s) of registration |
| 442 | 442 | |
| 443 | 443 | //add attendee columns |
| 444 | - foreach($att_fields_to_include as $att_field_name){ |
|
| 444 | + foreach ($att_fields_to_include as $att_field_name) { |
|
| 445 | 445 | $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
| 446 | - if( $reg_row[ 'Attendee_CPT.ID' ]){ |
|
| 447 | - if($att_field_name == 'STA_ID'){ |
|
| 448 | - $value = EEM_State::instance()->get_var( array( array( 'STA_ID' => $reg_row[ 'Attendee_Meta.STA_ID' ] ) ), 'STA_name' ); |
|
| 449 | - }elseif($att_field_name == 'CNT_ISO'){ |
|
| 450 | - $value = EEM_Country::instance()->get_var( array( array( 'CNT_ISO' => $reg_row[ 'Attendee_Meta.CNT_ISO' ] ) ), 'CNT_name' ); |
|
| 451 | - }else{ |
|
| 452 | - $value = $this->_prepare_value_from_db_for_display( EEM_Attendee::instance(), $att_field_name, $reg_row[ $field_obj->get_qualified_column() ] ); |
|
| 446 | + if ($reg_row['Attendee_CPT.ID']) { |
|
| 447 | + if ($att_field_name == 'STA_ID') { |
|
| 448 | + $value = EEM_State::instance()->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), 'STA_name'); |
|
| 449 | + }elseif ($att_field_name == 'CNT_ISO') { |
|
| 450 | + $value = EEM_Country::instance()->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), 'CNT_name'); |
|
| 451 | + } else { |
|
| 452 | + $value = $this->_prepare_value_from_db_for_display(EEM_Attendee::instance(), $att_field_name, $reg_row[$field_obj->get_qualified_column()]); |
|
| 453 | 453 | } |
| 454 | - }else{ |
|
| 454 | + } else { |
|
| 455 | 455 | $value = ''; |
| 456 | 456 | } |
| 457 | 457 | |
@@ -459,56 +459,56 @@ discard block |
||
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | //make sure each registration has the same questions in the same order |
| 462 | - foreach($questions_for_these_regs_rows as $question_row){ |
|
| 463 | - if( ! isset($reg_csv_array[$question_row[ 'Question.QST_admin_label']])){ |
|
| 464 | - $reg_csv_array[$question_row[ 'Question.QST_admin_label' ] ] = null; |
|
| 462 | + foreach ($questions_for_these_regs_rows as $question_row) { |
|
| 463 | + if ( ! isset($reg_csv_array[$question_row['Question.QST_admin_label']])) { |
|
| 464 | + $reg_csv_array[$question_row['Question.QST_admin_label']] = null; |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | //now fill out the questions THEY answered |
| 468 | - foreach( EEM_Answer::instance()->get_all_wpdb_results( array( array( 'REG_ID' => $reg_row[ 'Registration.REG_ID' ] ), 'force_join' => array( 'Question' ) ) ) as $answer_row){ |
|
| 468 | + foreach (EEM_Answer::instance()->get_all_wpdb_results(array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question'))) as $answer_row) { |
|
| 469 | 469 | /* @var $answer EE_Answer */ |
| 470 | - if( $answer_row[ 'Question.QST_ID' ] ){ |
|
| 471 | - $question_label = $this->_prepare_value_from_db_for_display( EEM_Question::instance(), 'QST_admin_label', $answer_row[ 'Question.QST_admin_label' ] ); |
|
| 472 | - }else{ |
|
| 473 | - $question_label = sprintf( __( 'Question $s', 'event_espresso' ), $answer_row[ 'Answer.QST_ID' ] ); |
|
| 470 | + if ($answer_row['Question.QST_ID']) { |
|
| 471 | + $question_label = $this->_prepare_value_from_db_for_display(EEM_Question::instance(), 'QST_admin_label', $answer_row['Question.QST_admin_label']); |
|
| 472 | + } else { |
|
| 473 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 474 | 474 | } |
| 475 | - if( isset( $answer_row[ 'Question.QST_type'] ) && $answer_row[ 'Question.QST_type' ] == EEM_Question::QST_type_state ) { |
|
| 476 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( $answer_row[ 'Answer.ANS_value' ] ); |
|
| 475 | + if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
| 476 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID($answer_row['Answer.ANS_value']); |
|
| 477 | 477 | } else { |
| 478 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( EEM_Answer::instance(), 'ANS_value', $answer_row[ 'Answer.ANS_value' ] ); |
|
| 478 | + $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display(EEM_Answer::instance(), 'ANS_value', $answer_row['Answer.ANS_value']); |
|
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | - $registrations_csv_ready_array[] = apply_filters( 'FHEE__EE_Export__report_registrations__reg_csv_array', $reg_csv_array, $reg_row ); |
|
| 481 | + $registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array', $reg_csv_array, $reg_row); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | //if we couldn't export anything, we want to at least show the column headers |
| 486 | - if(empty($registrations_csv_ready_array)){ |
|
| 486 | + if (empty($registrations_csv_ready_array)) { |
|
| 487 | 487 | $reg_csv_array = array(); |
| 488 | 488 | $model_and_fields_to_include = array( |
| 489 | 489 | 'Registration' => $reg_fields_to_include, |
| 490 | 490 | 'Attendee' => $att_fields_to_include |
| 491 | 491 | ); |
| 492 | - foreach($model_and_fields_to_include as $model_name => $field_list){ |
|
| 492 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 493 | 493 | $model = EE_Registry::instance()->load_model($model_name); |
| 494 | - foreach($field_list as $field_name){ |
|
| 494 | + foreach ($field_list as $field_name) { |
|
| 495 | 495 | $field = $model->field_settings_for($field_name); |
| 496 | - $reg_csv_array[$this->_get_column_name_for_field($field)] = null;//$registration->get($field->get_name()); |
|
| 496 | + $reg_csv_array[$this->_get_column_name_for_field($field)] = null; //$registration->get($field->get_name()); |
|
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | $registrations_csv_ready_array [] = $reg_csv_array; |
| 500 | 500 | } |
| 501 | - if( $event_id ){ |
|
| 502 | - $event_slug = EEM_Event::instance()->get_var( array( array( 'EVT_ID' => $event_id ) ), 'EVT_slug' ); |
|
| 503 | - if( ! $event_slug ) { |
|
| 504 | - $event_slug = __( 'unknown', 'event_espresso' ); |
|
| 501 | + if ($event_id) { |
|
| 502 | + $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
| 503 | + if ( ! $event_slug) { |
|
| 504 | + $event_slug = __('unknown', 'event_espresso'); |
|
| 505 | 505 | } |
| 506 | - }else{ |
|
| 507 | - $event_slug = __( 'all', 'event_espresso' ); |
|
| 506 | + } else { |
|
| 507 | + $event_slug = __('all', 'event_espresso'); |
|
| 508 | 508 | } |
| 509 | - $filename = sprintf( "registrations-for-%s", $event_slug ); |
|
| 509 | + $filename = sprintf("registrations-for-%s", $event_slug); |
|
| 510 | 510 | |
| 511 | - $handle = $this->EE_CSV->begin_sending_csv( $filename); |
|
| 511 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
| 512 | 512 | $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
| 513 | 513 | $this->EE_CSV->end_sending_csv($handle); |
| 514 | 514 | } |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * @param EE_Model_Field_Base $field |
| 519 | 519 | * @return string |
| 520 | 520 | */ |
| 521 | - protected function _get_column_name_for_field(EE_Model_Field_Base $field){ |
|
| 521 | + protected function _get_column_name_for_field(EE_Model_Field_Base $field) { |
|
| 522 | 522 | return $field->get_nicename()."[".$field->get_name()."]"; |
| 523 | 523 | } |
| 524 | 524 | |
@@ -531,17 +531,17 @@ discard block |
||
| 531 | 531 | function export_categories() { |
| 532 | 532 | // are any Event IDs set? |
| 533 | 533 | $query_params = array(); |
| 534 | - if ( isset( $this->_req_data['EVT_CAT_ID'] )) { |
|
| 534 | + if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 535 | 535 | // do we have an array of IDs ? |
| 536 | - if ( is_array( $this->_req_data['EVT_CAT_ID'] )) { |
|
| 536 | + if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
| 537 | 537 | // generate an "IN (CSV)" where clause |
| 538 | - $EVT_CAT_IDs = array_map( 'sanitize_text_field', $this->_req_data['EVT_CAT_ID'] ); |
|
| 538 | + $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
| 539 | 539 | $filename = 'event-categories'; |
| 540 | - $query_params[0]['term_taxonomy_id'] = array('IN',$EVT_CAT_IDs); |
|
| 540 | + $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
| 541 | 541 | } else { |
| 542 | 542 | // generate regular where = clause |
| 543 | - $EVT_CAT_ID = absint( $this->_req_data['EVT_CAT_ID'] ); |
|
| 544 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
| 543 | + $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
| 544 | + $filename = 'event-category#'.$EVT_CAT_ID; |
|
| 545 | 545 | $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
| 546 | 546 | } |
| 547 | 547 | } else { |
@@ -553,11 +553,11 @@ discard block |
||
| 553 | 553 | 'Term_Taxonomy' => $query_params |
| 554 | 554 | ); |
| 555 | 555 | |
| 556 | - $table_data = $this->_get_export_data_for_models( $tables_to_export ); |
|
| 557 | - $filename = $this->generate_filename ( $filename ); |
|
| 556 | + $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
| 557 | + $filename = $this->generate_filename($filename); |
|
| 558 | 558 | |
| 559 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename, $table_data )) { |
|
| 560 | - EE_Error::add_error(__('An error occurred and the Category details could not be exported from the database.','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 559 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
| 560 | + EE_Error::add_error(__('An error occurred and the Category details could not be exported from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | |
@@ -568,13 +568,13 @@ discard block |
||
| 568 | 568 | * @param string - export_name |
| 569 | 569 | * @return string on success, FALSE on fail |
| 570 | 570 | */ |
| 571 | - private function generate_filename ( $export_name = '' ) { |
|
| 572 | - if ( $export_name != '' ) { |
|
| 573 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
| 574 | - $filename = sanitize_key( $filename ) . '-' . $this->today; |
|
| 571 | + private function generate_filename($export_name = '') { |
|
| 572 | + if ($export_name != '') { |
|
| 573 | + $filename = get_bloginfo('name').'-'.$export_name; |
|
| 574 | + $filename = sanitize_key($filename).'-'.$this->today; |
|
| 575 | 575 | return $filename; |
| 576 | - } else { |
|
| 577 | - EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 576 | + } else { |
|
| 577 | + EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
| 578 | 578 | } |
| 579 | 579 | return false; |
| 580 | 580 | } |
@@ -587,12 +587,12 @@ discard block |
||
| 587 | 587 | * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of query params like on EEM_Base::get_all |
| 588 | 588 | * @return array on success, FALSE on fail |
| 589 | 589 | */ |
| 590 | - private function _get_export_data_for_models( $models_to_export = array() ) { |
|
| 590 | + private function _get_export_data_for_models($models_to_export = array()) { |
|
| 591 | 591 | $table_data = FALSE; |
| 592 | - if ( is_array( $models_to_export ) ) { |
|
| 593 | - foreach ( $models_to_export as $model_name => $query_params ) { |
|
| 592 | + if (is_array($models_to_export)) { |
|
| 593 | + foreach ($models_to_export as $model_name => $query_params) { |
|
| 594 | 594 | //check for a numerically-indexed array. in that case, $model_name is the value!! |
| 595 | - if(is_int($model_name)){ |
|
| 595 | + if (is_int($model_name)) { |
|
| 596 | 596 | $model_name = $query_params; |
| 597 | 597 | $query_params = array(); |
| 598 | 598 | } |
@@ -600,17 +600,17 @@ discard block |
||
| 600 | 600 | $model_objects = $model->get_all($query_params); |
| 601 | 601 | |
| 602 | 602 | $table_data[$model_name] = array(); |
| 603 | - foreach($model_objects as $model_object){ |
|
| 603 | + foreach ($model_objects as $model_object) { |
|
| 604 | 604 | $model_data_array = array(); |
| 605 | 605 | $fields = $model->field_settings(); |
| 606 | - foreach($fields as $field){ |
|
| 606 | + foreach ($fields as $field) { |
|
| 607 | 607 | $column_name = $field->get_nicename()."[".$field->get_name()."]"; |
| 608 | - if($field instanceof EE_Datetime_Field){ |
|
| 608 | + if ($field instanceof EE_Datetime_Field) { |
|
| 609 | 609 | // $field->set_date_format('Y-m-d'); |
| 610 | 610 | // $field->set_time_format('H:i:s'); |
| 611 | - $model_data_array[$column_name] = $model_object->get_datetime($field->get_name(),'Y-m-d','H:i:s'); |
|
| 611 | + $model_data_array[$column_name] = $model_object->get_datetime($field->get_name(), 'Y-m-d', 'H:i:s'); |
|
| 612 | 612 | } |
| 613 | - else{ |
|
| 613 | + else { |
|
| 614 | 614 | $model_data_array[$column_name] = $model_object->get($field->get_name()); |
| 615 | 615 | } |
| 616 | 616 | } |
@@ -1,17 +1,17 @@ discard block |
||
| 1 | 1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
| 2 | 2 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
| 3 | 3 | /** |
| 4 | - * EE_Export class |
|
| 5 | - * |
|
| 6 | - * For creating csv file exports/reports in a single request. |
|
| 7 | - * Note that if you're creating a large csv file this is likely to timeout, |
|
| 8 | - * and so it would be better to use EventEspressoBatchRequest\BatchRequestProcessor |
|
| 9 | - * @package Event Espresso |
|
| 10 | - * @subpackage includes/functions |
|
| 11 | - * @author Brent Christensen |
|
| 12 | - * |
|
| 13 | - * ------------------------------------------------------------------------ |
|
| 14 | - */ |
|
| 4 | + * EE_Export class |
|
| 5 | + * |
|
| 6 | + * For creating csv file exports/reports in a single request. |
|
| 7 | + * Note that if you're creating a large csv file this is likely to timeout, |
|
| 8 | + * and so it would be better to use EventEspressoBatchRequest\BatchRequestProcessor |
|
| 9 | + * @package Event Espresso |
|
| 10 | + * @subpackage includes/functions |
|
| 11 | + * @author Brent Christensen |
|
| 12 | + * |
|
| 13 | + * ------------------------------------------------------------------------ |
|
| 14 | + */ |
|
| 15 | 15 | class EE_Export { |
| 16 | 16 | |
| 17 | 17 | const option_prefix = 'ee_report_job_'; |
@@ -472,11 +472,11 @@ discard block |
||
| 472 | 472 | }else{ |
| 473 | 473 | $question_label = sprintf( __( 'Question $s', 'event_espresso' ), $answer_row[ 'Answer.QST_ID' ] ); |
| 474 | 474 | } |
| 475 | - if( isset( $answer_row[ 'Question.QST_type'] ) && $answer_row[ 'Question.QST_type' ] == EEM_Question::QST_type_state ) { |
|
| 476 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( $answer_row[ 'Answer.ANS_value' ] ); |
|
| 477 | - } else { |
|
| 478 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( EEM_Answer::instance(), 'ANS_value', $answer_row[ 'Answer.ANS_value' ] ); |
|
| 479 | - } |
|
| 475 | + if( isset( $answer_row[ 'Question.QST_type'] ) && $answer_row[ 'Question.QST_type' ] == EEM_Question::QST_type_state ) { |
|
| 476 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( $answer_row[ 'Answer.ANS_value' ] ); |
|
| 477 | + } else { |
|
| 478 | + $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( EEM_Answer::instance(), 'ANS_value', $answer_row[ 'Answer.ANS_value' ] ); |
|
| 479 | + } |
|
| 480 | 480 | } |
| 481 | 481 | $registrations_csv_ready_array[] = apply_filters( 'FHEE__EE_Export__report_registrations__reg_csv_array', $reg_csv_array, $reg_row ); |
| 482 | 482 | } |
@@ -87,13 +87,13 @@ |
||
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * |
| 90 | - * Writes a row to the csv file |
|
| 91 | - * @param array $row - individual row of csv data |
|
| 92 | - * @param string $delimiter - csv delimiter |
|
| 93 | - * @param string $enclosure - csv enclosure |
|
| 94 | - * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
| 95 | - * @return string of text for teh csv file |
|
| 96 | - */ |
|
| 90 | + * Writes a row to the csv file |
|
| 91 | + * @param array $row - individual row of csv data |
|
| 92 | + * @param string $delimiter - csv delimiter |
|
| 93 | + * @param string $enclosure - csv enclosure |
|
| 94 | + * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
| 95 | + * @return string of text for teh csv file |
|
| 96 | + */ |
|
| 97 | 97 | public static function get_csv_row ( array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false ) { |
| 98 | 98 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards |
| 99 | 99 | $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param EE_Model_Field_Base $field |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public static function get_column_name_for_field(EE_Model_Field_Base $field){ |
|
| 33 | + public static function get_column_name_for_field(EE_Model_Field_Base $field) { |
|
| 34 | 34 | return $field->get_nicename()."[".$field->get_name()."]"; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -52,32 +52,32 @@ discard block |
||
| 52 | 52 | * we consider that a success (because we wrote everything there was...nothing) |
| 53 | 53 | * @throws EE_Error |
| 54 | 54 | */ |
| 55 | - public static function write_data_array_to_csv( $filepath, $data, $write_column_headers = true ){ |
|
| 55 | + public static function write_data_array_to_csv($filepath, $data, $write_column_headers = true) { |
|
| 56 | 56 | EE_Registry::instance()->load_helper('Array'); |
| 57 | 57 | |
| 58 | 58 | $new_file_contents = ''; |
| 59 | 59 | //determine if $data is actually a 2d array |
| 60 | - if ( $data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))){ |
|
| 60 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
| 61 | 61 | //make sure top level is numerically indexed, |
| 62 | 62 | |
| 63 | - if( EEH_Array::is_associative_array($data)){ |
|
| 64 | - throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s","event_espresso"),implode(",",array_keys($data)))); |
|
| 63 | + if (EEH_Array::is_associative_array($data)) { |
|
| 64 | + throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
| 65 | 65 | } |
| 66 | 66 | $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
| 67 | 67 | //now, is the last item in the top-level array of $data an associative or numeric array? |
| 68 | - if( $write_column_headers && |
|
| 69 | - EEH_Array::is_associative_array($item_in_top_level_array)){ |
|
| 68 | + if ($write_column_headers && |
|
| 69 | + EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
| 70 | 70 | //its associative, so we want to output its keys as column headers |
| 71 | 71 | $keys = array_keys($item_in_top_level_array); |
| 72 | - $new_file_contents .= EEH_Export::get_csv_row( $keys ); |
|
| 72 | + $new_file_contents .= EEH_Export::get_csv_row($keys); |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | //start writing data |
| 76 | - foreach($data as $data_row){ |
|
| 77 | - $new_file_contents .= EEH_Export::get_csv_row( $data_row); |
|
| 76 | + foreach ($data as $data_row) { |
|
| 77 | + $new_file_contents .= EEH_Export::get_csv_row($data_row); |
|
| 78 | 78 | } |
| 79 | - return EEH_File::write_to_file( $filepath, EEH_File::get_file_contents( $filepath ) . $new_file_contents ); |
|
| 80 | - }else{ |
|
| 79 | + return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath).$new_file_contents); |
|
| 80 | + } else { |
|
| 81 | 81 | //no data TO write... so we can assume that's a success |
| 82 | 82 | return true; |
| 83 | 83 | } |
@@ -94,29 +94,29 @@ discard block |
||
| 94 | 94 | * @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
| 95 | 95 | * @return string of text for teh csv file |
| 96 | 96 | */ |
| 97 | - public static function get_csv_row ( array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false ) { |
|
| 97 | + public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) { |
|
| 98 | 98 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards |
| 99 | - $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); |
|
| 100 | - $enclosure = apply_filters( 'FHEE__EE_CSV__fputcsv2__enclosure', $enclosure ); |
|
| 99 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
| 100 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
| 101 | 101 | |
| 102 | 102 | $delimiter_esc = preg_quote($delimiter, '/'); |
| 103 | 103 | $enclosure_esc = preg_quote($enclosure, '/'); |
| 104 | 104 | |
| 105 | 105 | $output = array(); |
| 106 | 106 | foreach ($row as $field_value) { |
| 107 | - if(is_object($field_value) || is_array($field_value)){ |
|
| 107 | + if (is_object($field_value) || is_array($field_value)) { |
|
| 108 | 108 | $field_value = serialize($field_value); |
| 109 | 109 | } |
| 110 | - if ($field_value === null && $mysql_null ) { |
|
| 110 | + if ($field_value === null && $mysql_null) { |
|
| 111 | 111 | $output[] = 'NULL'; |
| 112 | 112 | continue; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
| 116 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
| 116 | + ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) : $field_value; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return implode($delimiter, $output) . PHP_EOL; |
|
| 119 | + return implode($delimiter, $output).PHP_EOL; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | - public static function prepare_value_from_db_for_display( $model, $field_name, $raw_db_value, $pretty_schema = true ) { |
|
| 133 | - $field_obj = $model->field_settings_for( $field_name ); |
|
| 134 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db( $raw_db_value ); |
|
| 135 | - if( $field_obj instanceof EE_Datetime_Field ) { |
|
| 136 | - $field_obj->set_date_format( EEH_Export::get_date_format_for_export( $field_obj->get_date_format( $pretty_schema ) ), $pretty_schema ); |
|
| 137 | - $field_obj->set_time_format( EEH_Export::get_time_format_for_export( $field_obj->get_time_format( $pretty_schema ) ), $pretty_schema ); |
|
| 132 | + public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) { |
|
| 133 | + $field_obj = $model->field_settings_for($field_name); |
|
| 134 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
| 135 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 136 | + $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
| 137 | + $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
| 138 | 138 | } |
| 139 | - if( $pretty_schema === true){ |
|
| 140 | - return $field_obj->prepare_for_pretty_echoing( $value_on_model_obj ); |
|
| 141 | - }elseif( is_string( $pretty_schema ) ) { |
|
| 142 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema ); |
|
| 143 | - }else{ |
|
| 144 | - return $field_obj->prepare_for_get( $value_on_model_obj ); |
|
| 139 | + if ($pretty_schema === true) { |
|
| 140 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
| 141 | + }elseif (is_string($pretty_schema)) { |
|
| 142 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
| 143 | + } else { |
|
| 144 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * @param string $current_format |
| 153 | 153 | * @return string |
| 154 | 154 | */ |
| 155 | - public static function get_date_format_for_export( $current_format = null ) { |
|
| 156 | - return apply_filters( 'FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format ); |
|
| 155 | + public static function get_date_format_for_export($current_format = null) { |
|
| 156 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | * @param string $current_format |
| 164 | 164 | * @return string |
| 165 | 165 | */ |
| 166 | - public static function get_time_format_for_export( $current_format = null ) { |
|
| 167 | - return apply_filters( 'FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format ); |
|
| 166 | + public static function get_time_format_for_export($current_format = null) { |
|
| 167 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Event Espresso |
| 4 | 6 | * |
@@ -77,7 +79,7 @@ discard block |
||
| 77 | 79 | $new_file_contents .= EEH_Export::get_csv_row( $data_row); |
| 78 | 80 | } |
| 79 | 81 | return EEH_File::write_to_file( $filepath, EEH_File::get_file_contents( $filepath ) . $new_file_contents ); |
| 80 | - }else{ |
|
| 82 | + } else{ |
|
| 81 | 83 | //no data TO write... so we can assume that's a success |
| 82 | 84 | return true; |
| 83 | 85 | } |
@@ -138,9 +140,9 @@ discard block |
||
| 138 | 140 | } |
| 139 | 141 | if( $pretty_schema === true){ |
| 140 | 142 | return $field_obj->prepare_for_pretty_echoing( $value_on_model_obj ); |
| 141 | - }elseif( is_string( $pretty_schema ) ) { |
|
| 143 | + } elseif( is_string( $pretty_schema ) ) { |
|
| 142 | 144 | return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema ); |
| 143 | - }else{ |
|
| 145 | + } else{ |
|
| 144 | 146 | return $field_obj->prepare_for_get( $value_on_model_obj ); |
| 145 | 147 | } |
| 146 | 148 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | use EventEspressoBatchRequest\Helpers\JobParameters; |
| 24 | 24 | use EventEspressoBatchRequest\Helpers\JobStepResponse; |
| 25 | 25 | |
| 26 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 27 | - exit( 'No direct script access allowed' ); |
|
| 26 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 27 | + exit('No direct script access allowed'); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | |
@@ -50,32 +50,32 @@ discard block |
||
| 50 | 50 | * @param array $request_data to be used by the batch job handler |
| 51 | 51 | * @return JobStepResponse |
| 52 | 52 | */ |
| 53 | - public function create_job( $batch_job_handler_class, $request_data ) { |
|
| 53 | + public function create_job($batch_job_handler_class, $request_data) { |
|
| 54 | 54 | try { |
| 55 | - $this->_job_id = wp_generate_password( 15, false ); |
|
| 56 | - $obj = $this->instantiate_batch_job_handler_from_classname( $batch_job_handler_class ); |
|
| 57 | - $this->_job_parameters = new JobParameters( $this->_job_id, $batch_job_handler_class, $request_data ); |
|
| 58 | - $response = $obj->create_job( $this->_job_parameters ); |
|
| 59 | - if( ! $response instanceof JobStepResponse ) { |
|
| 55 | + $this->_job_id = wp_generate_password(15, false); |
|
| 56 | + $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
| 57 | + $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
| 58 | + $response = $obj->create_job($this->_job_parameters); |
|
| 59 | + if ( ! $response instanceof JobStepResponse) { |
|
| 60 | 60 | throw new BatchRequestException( |
| 61 | 61 | sprintf( |
| 62 | - __( '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', 'event_espresso' ), |
|
| 63 | - wp_json_encode( $request_data ) |
|
| 62 | + __('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', 'event_espresso'), |
|
| 63 | + wp_json_encode($request_data) |
|
| 64 | 64 | ) |
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | - $success = $this->_job_parameters->save( true ); |
|
| 68 | - if( ! $success ) { |
|
| 67 | + $success = $this->_job_parameters->save(true); |
|
| 68 | + if ( ! $success) { |
|
| 69 | 69 | throw new BatchRequestException( |
| 70 | 70 | sprintf( |
| 71 | 71 | __('Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', 'event_espresso'), |
| 72 | 72 | $this->_job_id, |
| 73 | - wp_json_encode( $request_data ) |
|
| 73 | + wp_json_encode($request_data) |
|
| 74 | 74 | ) |
| 75 | 75 | ); |
| 76 | 76 | } |
| 77 | - } catch( \Exception $e ) { |
|
| 78 | - $response = $this->_get_error_response( $e, 'create_job' ); |
|
| 77 | + } catch (\Exception $e) { |
|
| 78 | + $response = $this->_get_error_response($e, 'create_job'); |
|
| 79 | 79 | } |
| 80 | 80 | return $response; |
| 81 | 81 | } |
@@ -88,26 +88,26 @@ discard block |
||
| 88 | 88 | * @param int $batch_size |
| 89 | 89 | * @return JobStepResponse |
| 90 | 90 | */ |
| 91 | - public function continue_job( $job_id, $batch_size = 50 ) { |
|
| 91 | + public function continue_job($job_id, $batch_size = 50) { |
|
| 92 | 92 | try { |
| 93 | 93 | $this->_job_id = $job_id; |
| 94 | - $batch_size = defined( 'EE_BATCHRUNNER_BATCH_SIZE' ) ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
| 94 | + $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
| 95 | 95 | //get the corresponding WordPress option for the job |
| 96 | - $this->_job_parameters = JobParameters::load( $this->_job_id ); |
|
| 97 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname( $this->_job_parameters->classname() ); |
|
| 96 | + $this->_job_parameters = JobParameters::load($this->_job_id); |
|
| 97 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
| 98 | 98 | //continue it |
| 99 | - $response = $handler_obj->continue_job( $this->_job_parameters, $batch_size ); |
|
| 100 | - if( ! $response instanceof JobStepResponse ) { |
|
| 99 | + $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
| 100 | + if ( ! $response instanceof JobStepResponse) { |
|
| 101 | 101 | throw new BatchRequestException( |
| 102 | 102 | sprintf( |
| 103 | - __( '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', 'event_espresso' ), |
|
| 103 | + __('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', 'event_espresso'), |
|
| 104 | 104 | $this->_job_id |
| 105 | 105 | ) |
| 106 | 106 | ); |
| 107 | 107 | } |
| 108 | 108 | $this->_job_parameters->save(); |
| 109 | - } catch( \Exception $e ) { |
|
| 110 | - $response = $this->_get_error_response( $e, 'continue_job' ); |
|
| 109 | + } catch (\Exception $e) { |
|
| 110 | + $response = $this->_get_error_response($e, 'continue_job'); |
|
| 111 | 111 | } |
| 112 | 112 | return $response; |
| 113 | 113 | } |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * @return JobHandlerInterface |
| 123 | 123 | * @throws BatchRequestException |
| 124 | 124 | */ |
| 125 | - public function instantiate_batch_job_handler_from_classname( $classname ) { |
|
| 126 | - if( ! class_exists( $classname ) ) { |
|
| 125 | + public function instantiate_batch_job_handler_from_classname($classname) { |
|
| 126 | + if ( ! class_exists($classname)) { |
|
| 127 | 127 | throw new BatchRequestException( |
| 128 | 128 | sprintf( |
| 129 | 129 | __('The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', 'event_espresso'), |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | 134 | $obj = new $classname; |
| 135 | - if( ! $obj instanceof JobHandlerInterface ) { |
|
| 135 | + if ( ! $obj instanceof JobHandlerInterface) { |
|
| 136 | 136 | throw new BatchRequestException( |
| 137 | 137 | sprintf( |
| 138 | 138 | __('The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', 'event_espresso'), |
@@ -152,26 +152,26 @@ discard block |
||
| 152 | 152 | * @return JobStepResponse |
| 153 | 153 | * @throws BatchRequestException |
| 154 | 154 | */ |
| 155 | - public function cleanup_job( $job_id ) { |
|
| 156 | - try{ |
|
| 155 | + public function cleanup_job($job_id) { |
|
| 156 | + try { |
|
| 157 | 157 | $this->_job_id = $job_id; |
| 158 | - $job_parameters = JobParameters::load( $this->_job_id ); |
|
| 159 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname( $job_parameters->classname() ); |
|
| 158 | + $job_parameters = JobParameters::load($this->_job_id); |
|
| 159 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
| 160 | 160 | //continue it |
| 161 | - $response = $handler_obj->cleanup_job( $job_parameters ); |
|
| 162 | - if( ! $response instanceof JobStepResponse ) { |
|
| 161 | + $response = $handler_obj->cleanup_job($job_parameters); |
|
| 162 | + if ( ! $response instanceof JobStepResponse) { |
|
| 163 | 163 | throw new BatchRequestException( |
| 164 | 164 | sprintf( |
| 165 | - __( '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', 'event_espresso' ), |
|
| 165 | + __('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', 'event_espresso'), |
|
| 166 | 166 | $this->_job_id |
| 167 | 167 | ) |
| 168 | 168 | ); |
| 169 | 169 | } |
| 170 | - $job_parameters->set_status( JobParameters::status_cleaned_up ); |
|
| 170 | + $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
| 171 | 171 | $job_parameters->delete(); |
| 172 | 172 | return $response; |
| 173 | - } catch( \Exception $e ) { |
|
| 174 | - $response = $this->_get_error_response( $e, 'cleanup_job' ); |
|
| 173 | + } catch (\Exception $e) { |
|
| 174 | + $response = $this->_get_error_response($e, 'cleanup_job'); |
|
| 175 | 175 | } |
| 176 | 176 | return $response; |
| 177 | 177 | } |
@@ -184,17 +184,17 @@ discard block |
||
| 184 | 184 | * @param string $method_name |
| 185 | 185 | * @return JobStepResponse |
| 186 | 186 | */ |
| 187 | - protected function _get_error_response( \Exception $exception, $method_name ) { |
|
| 188 | - if( ! $this->_job_parameters instanceof JobParameters ) { |
|
| 189 | - $this->_job_parameters = new JobParameters( $this->_job_id, __( '__Unknown__', 'event_espresso' ), array() ); |
|
| 187 | + protected function _get_error_response(\Exception $exception, $method_name) { |
|
| 188 | + if ( ! $this->_job_parameters instanceof JobParameters) { |
|
| 189 | + $this->_job_parameters = new JobParameters($this->_job_id, __('__Unknown__', 'event_espresso'), array()); |
|
| 190 | 190 | } |
| 191 | - $this->_job_parameters->set_status( JobParameters::status_error ); |
|
| 191 | + $this->_job_parameters->set_status(JobParameters::status_error); |
|
| 192 | 192 | return new JobStepResponse( |
| 193 | 193 | $this->_job_parameters, |
| 194 | 194 | sprintf( |
| 195 | 195 | __('An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', 'event_espresso'), |
| 196 | - get_class( $exception ), |
|
| 197 | - 'BatchRunner::' . $method_name . '()', |
|
| 196 | + get_class($exception), |
|
| 197 | + 'BatchRunner::'.$method_name.'()', |
|
| 198 | 198 | $exception->getMessage(), |
| 199 | 199 | $exception->getTraceAsString() |
| 200 | 200 | ) |
@@ -1,21 +1,21 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class BatchRequetProcessor |
|
| 3 | + * |
|
| 4 | + * Class BatchRequetProcessor |
|
| 5 | 5 | * |
| 6 | - * Responsible for receiving a request to start a job and assign it a job Id. |
|
| 7 | - * Then when subsequent requests come in to continue that job, dispatches |
|
| 8 | - * the request to the appropriate JobHandler, which processes a step of the batch, |
|
| 9 | - * and then returns the job's new status. |
|
| 10 | - * This class is used by controller code, and the controller code is sent HTTP |
|
| 11 | - * requests from the batch_runner.js library |
|
| 12 | - * |
|
| 13 | - * @package Event Espresso |
|
| 14 | - * @subpackage batch |
|
| 15 | - * @author Mike Nelson |
|
| 16 | - * @since 4.8.26 |
|
| 17 | - * |
|
| 18 | - */ |
|
| 6 | + * Responsible for receiving a request to start a job and assign it a job Id. |
|
| 7 | + * Then when subsequent requests come in to continue that job, dispatches |
|
| 8 | + * the request to the appropriate JobHandler, which processes a step of the batch, |
|
| 9 | + * and then returns the job's new status. |
|
| 10 | + * This class is used by controller code, and the controller code is sent HTTP |
|
| 11 | + * requests from the batch_runner.js library |
|
| 12 | + * |
|
| 13 | + * @package Event Espresso |
|
| 14 | + * @subpackage batch |
|
| 15 | + * @author Mike Nelson |
|
| 16 | + * @since 4.8.26 |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | 19 | namespace EventEspressoBatchRequest; |
| 20 | 20 | |
| 21 | 21 | use EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerInterface; |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | namespace EventEspressoBatchRequest\Helpers; |
| 16 | 16 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
| 17 | 17 | |
| 18 | -class BatchRequestException extends \Exception{ |
|
| 18 | +class BatchRequestException extends \Exception { |
|
| 19 | 19 | //so far the same as exception |
| 20 | 20 | } |
| 21 | 21 | |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class BatchRequestException |
|
| 5 | - * |
|
| 6 | - * Exception class for whenever we have trouble running start, continuing, or finishing |
|
| 7 | - * a batch job. |
|
| 8 | - * |
|
| 9 | - * @package Event Espresso |
|
| 10 | - * @subpackage batch |
|
| 11 | - * @author Mike Nelson |
|
| 12 | - * @since 4.8.26 |
|
| 13 | - * |
|
| 14 | - */ |
|
| 3 | + * |
|
| 4 | + * Class BatchRequestException |
|
| 5 | + * |
|
| 6 | + * Exception class for whenever we have trouble running start, continuing, or finishing |
|
| 7 | + * a batch job. |
|
| 8 | + * |
|
| 9 | + * @package Event Espresso |
|
| 10 | + * @subpackage batch |
|
| 11 | + * @author Mike Nelson |
|
| 12 | + * @since 4.8.26 |
|
| 13 | + * |
|
| 14 | + */ |
|
| 15 | 15 | namespace EventEspressoBatchRequest\Helpers; |
| 16 | 16 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
| 17 | 17 | |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | * @param array $request_data |
| 97 | 97 | * @param array $extra_data |
| 98 | 98 | */ |
| 99 | - function __construct( $job_id, $classname, $request_data, $extra_data = array() ) { |
|
| 100 | - $this->set_job_id( $job_id ); |
|
| 101 | - $this->set_classname( $classname ); |
|
| 102 | - $this->set_request_data( $request_data ); |
|
| 103 | - $this->set_extra_data( $extra_data ); |
|
| 104 | - $this->set_status( JobParameters::status_continue ); |
|
| 99 | + function __construct($job_id, $classname, $request_data, $extra_data = array()) { |
|
| 100 | + $this->set_job_id($job_id); |
|
| 101 | + $this->set_classname($classname); |
|
| 102 | + $this->set_request_data($request_data); |
|
| 103 | + $this->set_extra_data($extra_data); |
|
| 104 | + $this->set_status(JobParameters::status_continue); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * @param boolean $first |
| 127 | 127 | * @return boolean success |
| 128 | 128 | */ |
| 129 | - function save( $first = false ) { |
|
| 130 | - $object_vars = wp_json_encode( get_object_vars( $this ) ); |
|
| 131 | - if( $first ) { |
|
| 132 | - return add_option( $this->option_name(), $object_vars, null, 'no' ); |
|
| 133 | - } else{ |
|
| 134 | - return update_option( $this->option_name(), $object_vars ); |
|
| 129 | + function save($first = false) { |
|
| 130 | + $object_vars = wp_json_encode(get_object_vars($this)); |
|
| 131 | + if ($first) { |
|
| 132 | + return add_option($this->option_name(), $object_vars, null, 'no'); |
|
| 133 | + } else { |
|
| 134 | + return update_option($this->option_name(), $object_vars); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return boolean |
| 144 | 144 | */ |
| 145 | 145 | function delete() { |
| 146 | - return delete_option( $this->option_name() ); |
|
| 146 | + return delete_option($this->option_name()); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -154,26 +154,26 @@ discard block |
||
| 154 | 154 | * @return JobParameters |
| 155 | 155 | * @throws BatchRequestException |
| 156 | 156 | */ |
| 157 | - static function load( $job_id ) { |
|
| 158 | - $job_parameter_vars = json_decode( get_option( JobParameters::wp_option_prefix . $job_id ), true ); |
|
| 159 | - if( |
|
| 160 | - ! is_array( $job_parameter_vars ) || |
|
| 161 | - ! isset( $job_parameter_vars[ '_classname' ] ) || |
|
| 162 | - ! isset( $job_parameter_vars[ '_request_data' ] ) |
|
| 157 | + static function load($job_id) { |
|
| 158 | + $job_parameter_vars = json_decode(get_option(JobParameters::wp_option_prefix.$job_id), true); |
|
| 159 | + if ( |
|
| 160 | + ! is_array($job_parameter_vars) || |
|
| 161 | + ! isset($job_parameter_vars['_classname']) || |
|
| 162 | + ! isset($job_parameter_vars['_request_data']) |
|
| 163 | 163 | ) { |
| 164 | 164 | throw new BatchRequestException( |
| 165 | 165 | sprintf( |
| 166 | 166 | __('Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s', 'event_espresso'), |
| 167 | 167 | $job_id, |
| 168 | - get_option( JobParameters::wp_option_prefix . $job_id ) |
|
| 168 | + get_option(JobParameters::wp_option_prefix.$job_id) |
|
| 169 | 169 | ) |
| 170 | 170 | ); |
| 171 | 171 | } |
| 172 | 172 | $job_parameters = new JobParameters( |
| 173 | 173 | $job_id, |
| 174 | - $job_parameter_vars[ '_classname' ], |
|
| 175 | - $job_parameter_vars[ '_request_data'] ); |
|
| 176 | - foreach( $job_parameter_vars as $key => $value ) { |
|
| 174 | + $job_parameter_vars['_classname'], |
|
| 175 | + $job_parameter_vars['_request_data'] ); |
|
| 176 | + foreach ($job_parameter_vars as $key => $value) { |
|
| 177 | 177 | $job_parameters->$key = $value; |
| 178 | 178 | } |
| 179 | 179 | return $job_parameters; |
@@ -217,9 +217,9 @@ discard block |
||
| 217 | 217 | * @param string|array $default |
| 218 | 218 | * @return string|array |
| 219 | 219 | */ |
| 220 | - function request_datum( $key, $default = '' ) { |
|
| 221 | - if( isset( $this->_request_data[ $key ] ) ) { |
|
| 222 | - return $this->_request_data[ $key ]; |
|
| 220 | + function request_datum($key, $default = '') { |
|
| 221 | + if (isset($this->_request_data[$key])) { |
|
| 222 | + return $this->_request_data[$key]; |
|
| 223 | 223 | } else { |
| 224 | 224 | return $default; |
| 225 | 225 | } |
@@ -233,9 +233,9 @@ discard block |
||
| 233 | 233 | * @param string|array $default |
| 234 | 234 | * @return string|array |
| 235 | 235 | */ |
| 236 | - function extra_datum( $key, $default = '' ) { |
|
| 237 | - if( isset( $this->_extra_data[ $key ] ) ) { |
|
| 238 | - return $this->_extra_data[ $key ]; |
|
| 236 | + function extra_datum($key, $default = '') { |
|
| 237 | + if (isset($this->_extra_data[$key])) { |
|
| 238 | + return $this->_extra_data[$key]; |
|
| 239 | 239 | } else { |
| 240 | 240 | return $default; |
| 241 | 241 | } |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | * @param string $key |
| 249 | 249 | * @param string|int|array|null $value almost any extra data you want to store |
| 250 | 250 | */ |
| 251 | - function add_extra_data( $key, $value ) { |
|
| 252 | - $this->_extra_data[ $key ] = $value; |
|
| 251 | + function add_extra_data($key, $value) { |
|
| 252 | + $this->_extra_data[$key] = $value; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * Sets the job size. You decide what units to use |
| 279 | 279 | * @param int $size |
| 280 | 280 | */ |
| 281 | - function set_job_size( $size ) { |
|
| 281 | + function set_job_size($size) { |
|
| 282 | 282 | $this->_job_size = $size; |
| 283 | 283 | } |
| 284 | 284 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param int $newly_processed |
| 300 | 300 | * @return int updated units processed |
| 301 | 301 | */ |
| 302 | - function mark_processed( $newly_processed ) { |
|
| 302 | + function mark_processed($newly_processed) { |
|
| 303 | 303 | $this->_units_processed += $newly_processed; |
| 304 | 304 | return $this->_units_processed; |
| 305 | 305 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * Sets the total count of units processed. You might prefer to use mark_processed |
| 311 | 311 | * @param int $total_units_processed |
| 312 | 312 | */ |
| 313 | - function set_units_processed( $total_units_processed ) { |
|
| 313 | + function set_units_processed($total_units_processed) { |
|
| 314 | 314 | $this->_units_processed = $total_units_processed; |
| 315 | 315 | } |
| 316 | 316 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * Sets the job's ID |
| 321 | 321 | * @param string $job_id |
| 322 | 322 | */ |
| 323 | - function set_job_id( $job_id ) { |
|
| 323 | + function set_job_id($job_id) { |
|
| 324 | 324 | $this->_job_id = $job_id; |
| 325 | 325 | } |
| 326 | 326 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * sets the classname |
| 331 | 331 | * @param string $classname |
| 332 | 332 | */ |
| 333 | - function set_classname( $classname ) { |
|
| 333 | + function set_classname($classname) { |
|
| 334 | 334 | $this->_classname = $classname; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * Sets the request data |
| 341 | 341 | * @param array $request_data |
| 342 | 342 | */ |
| 343 | - function set_request_data( $request_data ) { |
|
| 343 | + function set_request_data($request_data) { |
|
| 344 | 344 | $this->_request_data = $request_data; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | * Sets the array of extra data we want to store on this request |
| 351 | 351 | * @param array $extra_data |
| 352 | 352 | */ |
| 353 | - function set_extra_data( $extra_data ) { |
|
| 353 | + function set_extra_data($extra_data) { |
|
| 354 | 354 | $this->_extra_data = $extra_data; |
| 355 | 355 | } |
| 356 | 356 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @return string |
| 362 | 362 | */ |
| 363 | 363 | function option_name() { |
| 364 | - return JobParameters::wp_option_prefix . $this->job_id(); |
|
| 364 | + return JobParameters::wp_option_prefix.$this->job_id(); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * |
| 381 | 381 | * @param string $status on eof JobParameters::valid_stati() |
| 382 | 382 | */ |
| 383 | - public function set_status( $status ) { |
|
| 383 | + public function set_status($status) { |
|
| 384 | 384 | $this->_status = $status; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class JobParameters |
|
| 5 | - * |
|
| 6 | - * Class for storing information about a job. Takes care of serializing the |
|
| 7 | - * data for storing in a wordpress option |
|
| 8 | - * |
|
| 9 | - * @package Event Espresso |
|
| 10 | - * @subpackage batch |
|
| 11 | - * @author Mike Nelson |
|
| 12 | - * @since 4.8.26 |
|
| 13 | - * |
|
| 14 | - */ |
|
| 3 | + * |
|
| 4 | + * Class JobParameters |
|
| 5 | + * |
|
| 6 | + * Class for storing information about a job. Takes care of serializing the |
|
| 7 | + * data for storing in a wordpress option |
|
| 8 | + * |
|
| 9 | + * @package Event Espresso |
|
| 10 | + * @subpackage batch |
|
| 11 | + * @author Mike Nelson |
|
| 12 | + * @since 4.8.26 |
|
| 13 | + * |
|
| 14 | + */ |
|
| 15 | 15 | namespace EventEspressoBatchRequest\Helpers; |
| 16 | 16 | |
| 17 | 17 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
@@ -214,7 +214,7 @@ |
||
| 214 | 214 | /** |
| 215 | 215 | * Gets a single item from the request data |
| 216 | 216 | * @param string $key |
| 217 | - * @param string|array $default |
|
| 217 | + * @param string $default |
|
| 218 | 218 | * @return string|array |
| 219 | 219 | */ |
| 220 | 220 | function request_datum( $key, $default = '' ) { |
@@ -43,10 +43,10 @@ |
||
| 43 | 43 | * @param string $update_text |
| 44 | 44 | * @param array $extra_data |
| 45 | 45 | */ |
| 46 | - public function __construct(JobParameters $job_parameters, $update_text, $extra_data = array() ) { |
|
| 47 | - $this->_job_parameters = $job_parameters; |
|
| 46 | + public function __construct(JobParameters $job_parameters, $update_text, $extra_data = array()) { |
|
| 47 | + $this->_job_parameters = $job_parameters; |
|
| 48 | 48 | $this->_update_text = $update_text; |
| 49 | - $this->_extra_data = (array)$extra_data; |
|
| 49 | + $this->_extra_data = (array) $extra_data; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | use EventEspressoBatchRequest\Helpers\BatchRequestException; |
| 18 | 18 | |
| 19 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 20 | - exit( 'No direct script access allowed' ); |
|
| 19 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 20 | + exit('No direct script access allowed'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | protected $_file_helper = null; |
| 31 | 31 | const temp_folder_name = 'batch_temp_folder'; |
| 32 | - public function __construct( EEHI_File $file_helper = null ) { |
|
| 33 | - if( ! $file_helper ) { |
|
| 32 | + public function __construct(EEHI_File $file_helper = null) { |
|
| 33 | + if ( ! $file_helper) { |
|
| 34 | 34 | $this->_file_helper = new \EEH_File(); |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -45,30 +45,30 @@ discard block |
||
| 45 | 45 | * @return string |
| 46 | 46 | * @throws BatchRequestException |
| 47 | 47 | */ |
| 48 | - public function create_file_from_job_with_name( $job_id, $filename ) { |
|
| 48 | + public function create_file_from_job_with_name($job_id, $filename) { |
|
| 49 | 49 | $filepath = ''; |
| 50 | - try{ |
|
| 50 | + try { |
|
| 51 | 51 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
| 52 | - EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name |
|
| 52 | + EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name |
|
| 53 | 53 | ); |
| 54 | - if ( $success ) { |
|
| 54 | + if ($success) { |
|
| 55 | 55 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
| 56 | - EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name . DS . $job_id |
|
| 56 | + EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name.DS.$job_id |
|
| 57 | 57 | ); |
| 58 | 58 | } |
| 59 | - if( $success ) { |
|
| 60 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name . DS . $job_id . DS. $filename; |
|
| 61 | - $success = $this->_file_helper->ensure_file_exists_and_is_writable( $filepath ); |
|
| 59 | + if ($success) { |
|
| 60 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name.DS.$job_id.DS.$filename; |
|
| 61 | + $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
| 62 | 62 | } |
| 63 | 63 | //those methods normally fail with an exception, but if not, let's do it |
| 64 | - if( ! $success ) { |
|
| 65 | - throw new \EE_Error( 'could_not_create_temp_file', |
|
| 66 | - __( 'An unknown error occurred', 'event_espresso' )); |
|
| 64 | + if ( ! $success) { |
|
| 65 | + throw new \EE_Error('could_not_create_temp_file', |
|
| 66 | + __('An unknown error occurred', 'event_espresso')); |
|
| 67 | 67 | } |
| 68 | - } catch( \EE_Error $e ) { |
|
| 68 | + } catch (\EE_Error $e) { |
|
| 69 | 69 | throw new BatchRequestException( |
| 70 | 70 | sprintf( |
| 71 | - __( 'Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso' ), |
|
| 71 | + __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
| 72 | 72 | $job_id, |
| 73 | 73 | $e->getMessage() |
| 74 | 74 | ), |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @param string $filepath |
| 85 | 85 | * @return string url to file |
| 86 | 86 | */ |
| 87 | - public function get_url_to_file( $filepath ) { |
|
| 88 | - return str_replace( EVENT_ESPRESSO_UPLOAD_DIR, EVENT_ESPRESSO_UPLOAD_URL, $filepath ); |
|
| 87 | + public function get_url_to_file($filepath) { |
|
| 88 | + return str_replace(EVENT_ESPRESSO_UPLOAD_DIR, EVENT_ESPRESSO_UPLOAD_URL, $filepath); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class JobHandlerFile |
|
| 5 | - * |
|
| 6 | - * Base class for common implementations of JobHandlerInterface, but ones |
|
| 7 | - * which write to a temporary file |
|
| 8 | - * |
|
| 9 | - * @package Event Espresso |
|
| 10 | - * @subpackage batch |
|
| 11 | - * @author Mike Nelson |
|
| 12 | - * @since 4.8.26 |
|
| 13 | - * |
|
| 14 | - */ |
|
| 3 | + * |
|
| 4 | + * Class JobHandlerFile |
|
| 5 | + * |
|
| 6 | + * Base class for common implementations of JobHandlerInterface, but ones |
|
| 7 | + * which write to a temporary file |
|
| 8 | + * |
|
| 9 | + * @package Event Espresso |
|
| 10 | + * @subpackage batch |
|
| 11 | + * @author Mike Nelson |
|
| 12 | + * @since 4.8.26 |
|
| 13 | + * |
|
| 14 | + */ |
|
| 15 | 15 | namespace EventEspressoBatchRequest\JobHandlerBaseClasses; |
| 16 | 16 | |
| 17 | 17 | use EventEspressoBatchRequest\Helpers\BatchRequestException; |