@@ -1,7 +1,7 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | -require_once( EE_MODELS . 'EEM_Base.model.php' ); |
|
| 4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | |
@@ -25,65 +25,65 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @param string $timezone |
| 27 | 27 | */ |
| 28 | - protected function __construct( $timezone = null ) { |
|
| 29 | - $this->singular_item = __( 'Term', 'event_espresso' ); |
|
| 30 | - $this->plural_item = __( 'Terms', 'event_espresso' ); |
|
| 28 | + protected function __construct($timezone = null) { |
|
| 29 | + $this->singular_item = __('Term', 'event_espresso'); |
|
| 30 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
| 31 | 31 | $this->_tables = array( |
| 32 | - 'Term' => new EE_Primary_Table( 'terms', 'term_id' ), |
|
| 32 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
| 33 | 33 | ); |
| 34 | 34 | $this->_fields = array( |
| 35 | 35 | 'Term' => array( |
| 36 | - 'term_id' => new EE_Primary_Key_Int_Field( 'term_id', __( 'Term ID', 'event_espresso' ) ), |
|
| 37 | - 'name' => new EE_Plain_Text_Field( 'name', __( 'Term Name', 'event_espresso' ), false, '' ), |
|
| 38 | - 'slug' => new EE_Slug_Field( 'slug', __( 'Term Slug', 'event_espresso' ), false ), |
|
| 39 | - 'term_group' => new EE_Integer_Field( 'term_group', __( "Term Group", "event_espresso" ), false, 0 ), |
|
| 36 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
| 37 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
| 38 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
| 39 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
| 40 | 40 | ), |
| 41 | 41 | ); |
| 42 | 42 | $this->_model_relations = array( |
| 43 | 43 | 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
| 44 | 44 | ); |
| 45 | 45 | $path_to_tax_model = 'Term_Taxonomy'; |
| 46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 46 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
| 48 | 48 | $path_to_tax_model |
| 49 | 49 | ); |
| 50 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
| 51 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
| 52 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
| 50 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
| 51 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
| 52 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
| 53 | 53 | //add cap restrictions for editing relating to the "ee_edit_*" |
| 54 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 54 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
| 55 | 55 | array( |
| 56 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array( '!=', 'espresso_event_categories' ), |
|
| 56 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
| 57 | 57 | ) |
| 58 | 58 | ); |
| 59 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 59 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
| 60 | 60 | array( |
| 61 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array( '!=', 'espresso_venue_categories' ), |
|
| 61 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 62 | 62 | ) |
| 63 | 63 | ); |
| 64 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 64 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
| 65 | 65 | array( |
| 66 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array( '!=', 'espresso_event_type' ), |
|
| 66 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
| 67 | 67 | ) |
| 68 | 68 | ); |
| 69 | 69 | //add cap restrictions for deleting relating to the "ee_deleting_*" |
| 70 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 70 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
| 71 | 71 | array( |
| 72 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array( '!=', 'espresso_event_categories' ), |
|
| 72 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
| 73 | 73 | ) |
| 74 | 74 | ); |
| 75 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 75 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
| 76 | 76 | array( |
| 77 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array( '!=', 'espresso_venue_categories' ), |
|
| 77 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
| 78 | 78 | ) |
| 79 | 79 | ); |
| 80 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 80 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
| 81 | 81 | array( |
| 82 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array( '!=', 'espresso_event_type' ), |
|
| 82 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
| 83 | 83 | ) |
| 84 | 84 | ); |
| 85 | - parent::__construct( $timezone ); |
|
| 86 | - add_filter( 'FHEE__Read__create_model_query_params', array( 'EEM_Term', 'rest_api_query_params' ), 10, 3 ); |
|
| 85 | + parent::__construct($timezone); |
|
| 86 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | * @param bool $show_uncategorized |
| 96 | 96 | * @return \EE_Base_Class[] |
| 97 | 97 | */ |
| 98 | - public function get_all_ee_categories( $show_uncategorized = false ) { |
|
| 98 | + public function get_all_ee_categories($show_uncategorized = false) { |
|
| 99 | 99 | $where_params = array( |
| 100 | 100 | 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
| 101 | - 'NOT' => array( 'name' => __( 'Uncategorized', 'event_espresso' ) ), |
|
| 101 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
| 102 | 102 | ); |
| 103 | - if ( $show_uncategorized ) { |
|
| 104 | - unset( $where_params['NOT'] ); |
|
| 103 | + if ($show_uncategorized) { |
|
| 104 | + unset($where_params['NOT']); |
|
| 105 | 105 | } |
| 106 | 106 | return EEM_Term::instance()->get_all( |
| 107 | 107 | array( |
| 108 | 108 | $where_params, |
| 109 | - 'order_by' => array( 'name' => 'ASC' ), |
|
| 109 | + 'order_by' => array('name' => 'ASC'), |
|
| 110 | 110 | ) |
| 111 | 111 | ); |
| 112 | 112 | } |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | * @param string $post_type |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - public function get_all_CPT_post_tags( $post_type = '' ) { |
|
| 124 | - switch ( $post_type ) { |
|
| 123 | + public function get_all_CPT_post_tags($post_type = '') { |
|
| 124 | + switch ($post_type) { |
|
| 125 | 125 | case 'espresso_events' : |
| 126 | 126 | return $this->get_all_event_post_tags(); |
| 127 | 127 | break; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | default : |
| 132 | 132 | $event_tags = $this->get_all_event_post_tags(); |
| 133 | 133 | $venue_tags = $this->get_all_venue_post_tags(); |
| 134 | - return array_merge( $event_tags, $venue_tags ); |
|
| 134 | + return array_merge($event_tags, $venue_tags); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -149,15 +149,15 @@ discard block |
||
| 149 | 149 | 'Term_Taxonomy.taxonomy' => 'post_tag', |
| 150 | 150 | 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
| 151 | 151 | ), |
| 152 | - 'order_by' => array( 'name' => 'ASC' ), |
|
| 153 | - 'force_join' => array( 'Term_Taxonomy.Event' ), |
|
| 152 | + 'order_by' => array('name' => 'ASC'), |
|
| 153 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
| 154 | 154 | ) |
| 155 | 155 | ); |
| 156 | - foreach ( $post_tags as $key => $post_tag ) { |
|
| 157 | - if ( ! isset( $post_tags[ $key ]->post_type ) ) { |
|
| 158 | - $post_tags[ $key ]->post_type = array(); |
|
| 156 | + foreach ($post_tags as $key => $post_tag) { |
|
| 157 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
| 158 | + $post_tags[$key]->post_type = array(); |
|
| 159 | 159 | } |
| 160 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
| 160 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
| 161 | 161 | } |
| 162 | 162 | return $post_tags; |
| 163 | 163 | } |
@@ -176,15 +176,15 @@ discard block |
||
| 176 | 176 | 'Term_Taxonomy.taxonomy' => 'post_tag', |
| 177 | 177 | 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
| 178 | 178 | ), |
| 179 | - 'order_by' => array( 'name' => 'ASC' ), |
|
| 180 | - 'force_join' => array( 'Term_Taxonomy' ), |
|
| 179 | + 'order_by' => array('name' => 'ASC'), |
|
| 180 | + 'force_join' => array('Term_Taxonomy'), |
|
| 181 | 181 | ) |
| 182 | 182 | ); |
| 183 | - foreach ( $post_tags as $key => $post_tag ) { |
|
| 184 | - if ( ! isset( $post_tags[ $key ]->post_type ) ) { |
|
| 185 | - $post_tags[ $key ]->post_type = array(); |
|
| 183 | + foreach ($post_tags as $key => $post_tag) { |
|
| 184 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
| 185 | + $post_tags[$key]->post_type = array(); |
|
| 186 | 186 | } |
| 187 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
| 187 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
| 188 | 188 | } |
| 189 | 189 | return $post_tags; |
| 190 | 190 | } |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @param EEM_Base $model |
| 201 | 201 | * @return array |
| 202 | 202 | */ |
| 203 | - public static function rest_api_query_params( $model_query_params, $querystring_query_params, $model ) { |
|
| 204 | - if ( $model === EEM_Term::instance() ) { |
|
| 205 | - $taxonomies = get_taxonomies( array( 'show_in_rest' => true ) ); |
|
| 206 | - if ( ! empty( $taxonomies ) ) { |
|
| 207 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array( 'IN', $taxonomies ); |
|
| 203 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) { |
|
| 204 | + if ($model === EEM_Term::instance()) { |
|
| 205 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
| 206 | + if ( ! empty($taxonomies)) { |
|
| 207 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | return $model_query_params; |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
| 7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
| 8 | 8 | |
| 9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 10 | - exit( 'No direct script access allowed' ); |
|
| 9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -46,22 +46,22 @@ discard block |
||
| 46 | 46 | * @param \WP_REST_Request $request |
| 47 | 47 | * @return \WP_REST_Response|\WP_Error |
| 48 | 48 | */ |
| 49 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
| 49 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
| 50 | 50 | $controller = new Read(); |
| 51 | - try{ |
|
| 51 | + try { |
|
| 52 | 52 | $matches = $controller->parse_route( |
| 53 | 53 | $request->get_route(), |
| 54 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
| 55 | - array( 'version', 'model' ) |
|
| 54 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
| 55 | + array('version', 'model') |
|
| 56 | 56 | ); |
| 57 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 58 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 59 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
| 57 | + $controller->set_requested_version($matches['version']); |
|
| 58 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 59 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 60 | 60 | return $controller->send_response( |
| 61 | 61 | new \WP_Error( |
| 62 | 62 | 'endpoint_parsing_error', |
| 63 | 63 | sprintf( |
| 64 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 64 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 65 | 65 | $model_name_singular |
| 66 | 66 | ) |
| 67 | 67 | ) |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | return $controller->send_response( |
| 71 | 71 | $controller->get_entities_from_model( |
| 72 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
| 72 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 73 | 73 | $request |
| 74 | 74 | ) |
| 75 | 75 | ); |
| 76 | - } catch( \Exception $e ) { |
|
| 77 | - return $controller->send_response( $e ); |
|
| 76 | + } catch (\Exception $e) { |
|
| 77 | + return $controller->send_response($e); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,21 +84,21 @@ discard block |
||
| 84 | 84 | * @param \WP_REST_Request $request |
| 85 | 85 | * @return \WP_REST_Response|\WP_Error |
| 86 | 86 | */ |
| 87 | - public static function handle_request_get_one( \WP_REST_Request $request ) { |
|
| 87 | + public static function handle_request_get_one(\WP_REST_Request $request) { |
|
| 88 | 88 | $controller = new Read(); |
| 89 | - try{ |
|
| 89 | + try { |
|
| 90 | 90 | $matches = $controller->parse_route( |
| 91 | 91 | $request->get_route(), |
| 92 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
| 93 | - array( 'version', 'model', 'id' ) ); |
|
| 94 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 95 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 96 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
| 92 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
| 93 | + array('version', 'model', 'id') ); |
|
| 94 | + $controller->set_requested_version($matches['version']); |
|
| 95 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 96 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 97 | 97 | return $controller->send_response( |
| 98 | 98 | new \WP_Error( |
| 99 | 99 | 'endpoint_parsing_error', |
| 100 | 100 | sprintf( |
| 101 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 101 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 102 | 102 | $model_name_singular |
| 103 | 103 | ) |
| 104 | 104 | ) |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | return $controller->send_response( |
| 108 | 108 | $controller->get_entity_from_model( |
| 109 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
| 109 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 110 | 110 | $request |
| 111 | 111 | ) |
| 112 | 112 | ); |
| 113 | - } catch( \Exception $e ) { |
|
| 114 | - return $controller->send_response( $e ); |
|
| 113 | + } catch (\Exception $e) { |
|
| 114 | + return $controller->send_response($e); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -123,40 +123,40 @@ discard block |
||
| 123 | 123 | * @param \WP_REST_Request $request |
| 124 | 124 | * @return \WP_REST_Response|\WP_Error |
| 125 | 125 | */ |
| 126 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
| 126 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
| 127 | 127 | $controller = new Read(); |
| 128 | - try{ |
|
| 128 | + try { |
|
| 129 | 129 | $matches = $controller->parse_route( |
| 130 | 130 | $request->get_route(), |
| 131 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
| 132 | - array( 'version', 'model', 'id', 'related_model' ) |
|
| 131 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
| 132 | + array('version', 'model', 'id', 'related_model') |
|
| 133 | 133 | ); |
| 134 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 135 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 136 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
| 134 | + $controller->set_requested_version($matches['version']); |
|
| 135 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 136 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 137 | 137 | return $controller->send_response( |
| 138 | 138 | new \WP_Error( |
| 139 | 139 | 'endpoint_parsing_error', |
| 140 | 140 | sprintf( |
| 141 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 141 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 142 | 142 | $main_model_name_singular |
| 143 | 143 | ) |
| 144 | 144 | ) |
| 145 | 145 | ); |
| 146 | 146 | } |
| 147 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
| 147 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
| 148 | 148 | //assume the related model name is plural and try to find the model's name |
| 149 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
| 150 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
| 149 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
| 150 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 151 | 151 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
| 152 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
| 152 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
| 153 | 153 | } |
| 154 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
| 154 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 155 | 155 | return $controller->send_response( |
| 156 | 156 | new \WP_Error( |
| 157 | 157 | 'endpoint_parsing_error', |
| 158 | 158 | sprintf( |
| 159 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 159 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 160 | 160 | $related_model_name_singular |
| 161 | 161 | ) |
| 162 | 162 | ) |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | return $controller->send_response( |
| 167 | 167 | $controller->get_entities_from_relation( |
| 168 | - $request->get_param( 'id' ), |
|
| 169 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
| 168 | + $request->get_param('id'), |
|
| 169 | + $main_model->related_settings_for($related_model_name_singular), |
|
| 170 | 170 | $request |
| 171 | 171 | ) |
| 172 | 172 | ); |
| 173 | - } catch( \Exception $e ) { |
|
| 174 | - return $controller->send_response( $e ); |
|
| 173 | + } catch (\Exception $e) { |
|
| 174 | + return $controller->send_response($e); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -184,28 +184,28 @@ discard block |
||
| 184 | 184 | * @param \WP_REST_Request $request |
| 185 | 185 | * @return array|\WP_Error |
| 186 | 186 | */ |
| 187 | - public function get_entities_from_model( $model, $request) { |
|
| 188 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
| 189 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
| 190 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
| 187 | + public function get_entities_from_model($model, $request) { |
|
| 188 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
| 189 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 190 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 191 | 191 | return new \WP_Error( |
| 192 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
| 192 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
| 193 | 193 | sprintf( |
| 194 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
| 194 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
| 195 | 195 | $model_name_plural, |
| 196 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
| 196 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
| 197 | 197 | ), |
| 198 | - array( 'status' => 403 ) |
|
| 198 | + array('status' => 403) |
|
| 199 | 199 | ); |
| 200 | 200 | } |
| 201 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
| 202 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
| 201 | + if ( ! $request->get_header('no_rest_headers')) { |
|
| 202 | + $this->_set_headers_from_query_params($model, $query_params); |
|
| 203 | 203 | } |
| 204 | 204 | /** @type array $results */ |
| 205 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
| 205 | + $results = $model->get_all_wpdb_results($query_params); |
|
| 206 | 206 | $nice_results = array( ); |
| 207 | - foreach ( $results as $result ) { |
|
| 208 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
| 207 | + foreach ($results as $result) { |
|
| 208 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
| 209 | 209 | $model, |
| 210 | 210 | $result, |
| 211 | 211 | $request |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @param \WP_REST_Request $request |
| 222 | 222 | * @return \WP_Error|array |
| 223 | 223 | */ |
| 224 | - protected function _get_entities_from_relation( $primary_model_query_params, $relation, $request ) { |
|
| 225 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
| 224 | + protected function _get_entities_from_relation($primary_model_query_params, $relation, $request) { |
|
| 225 | + $context = $this->validate_context($request->get_param('caps')); |
|
| 226 | 226 | $model = $relation->get_this_model(); |
| 227 | 227 | $related_model = $relation->get_other_model(); |
| 228 | - if( ! isset( $primary_model_query_params[0]) ) { |
|
| 228 | + if ( ! isset($primary_model_query_params[0])) { |
|
| 229 | 229 | $primary_model_query_params[0] = array(); |
| 230 | 230 | } |
| 231 | 231 | //check if they can access the 1st model object |
@@ -233,60 +233,60 @@ discard block |
||
| 233 | 233 | 0 => $primary_model_query_params[0], |
| 234 | 234 | 'limit' => 1 |
| 235 | 235 | ); |
| 236 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
| 237 | - $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included( $primary_model_query_params ); |
|
| 236 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 237 | + $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params); |
|
| 238 | 238 | } |
| 239 | 239 | $restricted_query_params = $primary_model_query_params; |
| 240 | - $restricted_query_params[ 'caps' ] = $context; |
|
| 241 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
| 242 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
| 240 | + $restricted_query_params['caps'] = $context; |
|
| 241 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
| 242 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
| 243 | 243 | |
| 244 | - if( |
|
| 244 | + if ( |
|
| 245 | 245 | ! ( |
| 246 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
| 247 | - && $model->exists( $restricted_query_params ) |
|
| 246 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
| 247 | + && $model->exists($restricted_query_params) |
|
| 248 | 248 | ) |
| 249 | - ){ |
|
| 250 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
| 251 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
| 252 | - }else{ |
|
| 253 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
| 249 | + ) { |
|
| 250 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 251 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
| 252 | + } else { |
|
| 253 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
| 254 | 254 | } |
| 255 | 255 | return new \WP_Error( |
| 256 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
| 256 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
| 257 | 257 | sprintf( |
| 258 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
| 258 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
| 259 | 259 | $related_model_name_maybe_plural, |
| 260 | 260 | $relation->get_this_model()->get_this_model_name(), |
| 261 | 261 | implode( |
| 262 | 262 | ',', |
| 263 | 263 | array_keys( |
| 264 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
| 264 | + Capabilities::get_missing_permissions($related_model, $context) |
|
| 265 | 265 | ) |
| 266 | 266 | ) |
| 267 | 267 | ), |
| 268 | - array( 'status' => 403 ) |
|
| 268 | + array('status' => 403) |
|
| 269 | 269 | ); |
| 270 | 270 | } |
| 271 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
| 272 | - foreach( $primary_model_query_params[0] as $where_condition_key => $where_condition_value ) { |
|
| 273 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $where_condition_key ] = $where_condition_value; |
|
| 271 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
| 272 | + foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) { |
|
| 273 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$where_condition_key] = $where_condition_value; |
|
| 274 | 274 | } |
| 275 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
| 276 | - $query_params[ 'caps' ] = $context; |
|
| 277 | - if( ! $request->get_header( 'no_rest_headers' ) ) { |
|
| 278 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
| 275 | + $query_params['default_where_conditions'] = 'none'; |
|
| 276 | + $query_params['caps'] = $context; |
|
| 277 | + if ( ! $request->get_header('no_rest_headers')) { |
|
| 278 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
| 279 | 279 | } |
| 280 | 280 | /** @type array $results */ |
| 281 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
| 281 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
| 282 | 282 | $nice_results = array(); |
| 283 | - foreach( $results as $result ) { |
|
| 283 | + foreach ($results as $result) { |
|
| 284 | 284 | $nice_result = $this->create_entity_from_wpdb_result( |
| 285 | 285 | $relation->get_other_model(), |
| 286 | 286 | $result, |
| 287 | 287 | $request |
| 288 | 288 | ); |
| 289 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
| 289 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
| 290 | 290 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
| 291 | 291 | //if there are conflicts we prefer the properties from the main model |
| 292 | 292 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -294,18 +294,18 @@ discard block |
||
| 294 | 294 | $result, |
| 295 | 295 | $request |
| 296 | 296 | ); |
| 297 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
| 297 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
| 298 | 298 | //but keep the meta stuff from the main model |
| 299 | - if( isset( $nice_result['meta'] ) ){ |
|
| 299 | + if (isset($nice_result['meta'])) { |
|
| 300 | 300 | $joined_result['meta'] = $nice_result['meta']; |
| 301 | 301 | } |
| 302 | 302 | $nice_result = $joined_result; |
| 303 | 303 | } |
| 304 | 304 | $nice_results[] = $nice_result; |
| 305 | 305 | } |
| 306 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
| 307 | - return array_shift( $nice_results ); |
|
| 308 | - }else{ |
|
| 306 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 307 | + return array_shift($nice_results); |
|
| 308 | + } else { |
|
| 309 | 309 | return $nice_results; |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | * @return array|\WP_Error |
| 325 | 325 | * @throws \EE_Error |
| 326 | 326 | */ |
| 327 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
| 328 | - if( ! $relation->get_this_model()->has_primary_key_field() ) { |
|
| 327 | + public function get_entities_from_relation($id, $relation, $request) { |
|
| 328 | + if ( ! $relation->get_this_model()->has_primary_key_field()) { |
|
| 329 | 329 | throw new \EE_Error( |
| 330 | 330 | sprintf( |
| 331 | - __( 'Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', 'event_espresso'), |
|
| 331 | + __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', 'event_espresso'), |
|
| 332 | 332 | $relation->get_this_model()->get_this_model_name() |
| 333 | 333 | ) |
| 334 | 334 | ); |
@@ -352,30 +352,30 @@ discard block |
||
| 352 | 352 | * @param array $query_params |
| 353 | 353 | * @return void |
| 354 | 354 | */ |
| 355 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
| 356 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
| 357 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
| 355 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
| 356 | + $this->_set_debug_info('model query params', $query_params); |
|
| 357 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
| 358 | 358 | //normally the limit to a 2-part array, where the 2nd item is the limit |
| 359 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
| 360 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 359 | + if ( ! isset($query_params['limit'])) { |
|
| 360 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 361 | 361 | } |
| 362 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
| 363 | - $limit_parts = $query_params[ 'limit' ]; |
|
| 362 | + if (is_array($query_params['limit'])) { |
|
| 363 | + $limit_parts = $query_params['limit']; |
|
| 364 | 364 | } else { |
| 365 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
| 366 | - if( count( $limit_parts ) == 1 ){ |
|
| 367 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
| 365 | + $limit_parts = explode(',', $query_params['limit']); |
|
| 366 | + if (count($limit_parts) == 1) { |
|
| 367 | + $limit_parts = array(0, $limit_parts[0]); |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | //remove the group by and having parts of the query, as those will |
| 371 | 371 | //make the sql query return an array of values, instead of just a single value |
| 372 | - unset( $query_params[ 'group_by' ], $query_params[ 'having' ], $query_params[ 'limit' ] ); |
|
| 373 | - $count = $model->count( $query_params, null, true ); |
|
| 372 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
| 373 | + $count = $model->count($query_params, null, true); |
|
| 374 | 374 | |
| 375 | - $pages = $count / $limit_parts[ 1 ]; |
|
| 376 | - $this->_set_response_header( 'Total', $count, false ); |
|
| 377 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
| 378 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
| 375 | + $pages = $count / $limit_parts[1]; |
|
| 376 | + $this->_set_response_header('Total', $count, false); |
|
| 377 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
| 378 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -388,50 +388,50 @@ discard block |
||
| 388 | 388 | * @param string $deprecated no longer used |
| 389 | 389 | * @return array ready for being converted into json for sending to client |
| 390 | 390 | */ |
| 391 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
| 392 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
| 391 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
| 392 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
| 393 | 393 | //ok so this was called in the old style, where the 3rd arg was |
| 394 | 394 | //$include, and the 4th arg was $context |
| 395 | 395 | //now setup the request just to avoid fatal errors, although we won't be able |
| 396 | 396 | //to truly make use of it because it's kinda devoid of info |
| 397 | 397 | $rest_request = new \WP_REST_Request(); |
| 398 | - $rest_request->set_param( 'include', $rest_request ); |
|
| 399 | - $rest_request->set_param( 'caps', $deprecated ); |
|
| 398 | + $rest_request->set_param('include', $rest_request); |
|
| 399 | + $rest_request->set_param('caps', $deprecated); |
|
| 400 | 400 | } |
| 401 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
| 402 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
| 401 | + if ($rest_request->get_param('caps') == null) { |
|
| 402 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
| 403 | 403 | } |
| 404 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
| 405 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
| 406 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
| 407 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
| 408 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array, $db_row ); |
|
| 404 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
| 405 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
| 406 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
| 407 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
| 408 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row); |
|
| 409 | 409 | $entity_array = apply_filters( |
| 410 | 410 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
| 411 | 411 | $entity_array, |
| 412 | 412 | $model, |
| 413 | - $rest_request->get_param( 'caps' ), |
|
| 413 | + $rest_request->get_param('caps'), |
|
| 414 | 414 | $rest_request, |
| 415 | 415 | $this |
| 416 | 416 | ); |
| 417 | 417 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
| 418 | 418 | $entity_array, |
| 419 | 419 | $model, |
| 420 | - $rest_request->get_param( 'caps' ), |
|
| 420 | + $rest_request->get_param('caps'), |
|
| 421 | 421 | $this->get_model_version_info(), |
| 422 | 422 | $model->get_index_primary_key_string( |
| 423 | - $model->deduce_fields_n_values_from_cols_n_values($db_row ) |
|
| 423 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
| 424 | 424 | ) |
| 425 | 425 | ); |
| 426 | 426 | $this->_set_debug_info( |
| 427 | 427 | 'inaccessible fields', |
| 428 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
| 428 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
| 429 | 429 | ); |
| 430 | 430 | return apply_filters( |
| 431 | 431 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
| 432 | 432 | $result_without_inaccessible_fields, |
| 433 | 433 | $model, |
| 434 | - $rest_request->get_param( 'caps' ) |
|
| 434 | + $rest_request->get_param('caps') |
|
| 435 | 435 | ); |
| 436 | 436 | } |
| 437 | 437 | |
@@ -443,39 +443,39 @@ discard block |
||
| 443 | 443 | * @param array $db_row |
| 444 | 444 | * @return array entity mostly ready for converting to JSON and sending in the response |
| 445 | 445 | */ |
| 446 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
| 447 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
| 448 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
| 449 | - foreach( $result as $field_name => $raw_field_value ) { |
|
| 446 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
| 447 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
| 448 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
| 449 | + foreach ($result as $field_name => $raw_field_value) { |
|
| 450 | 450 | $field_obj = $model->field_settings_for($field_name); |
| 451 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
| 452 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
| 453 | - unset( $result[ $field_name ] ); |
|
| 454 | - }elseif( |
|
| 455 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
| 456 | - ){ |
|
| 457 | - $result[ $field_name ] = array( |
|
| 458 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
| 459 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
| 451 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
| 452 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
| 453 | + unset($result[$field_name]); |
|
| 454 | + }elseif ( |
|
| 455 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
| 456 | + ) { |
|
| 457 | + $result[$field_name] = array( |
|
| 458 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 459 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
| 460 | 460 | ); |
| 461 | - }elseif( |
|
| 462 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
| 463 | - ){ |
|
| 464 | - $result[ $field_name ] = array( |
|
| 465 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
| 466 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
| 461 | + }elseif ( |
|
| 462 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
| 463 | + ) { |
|
| 464 | + $result[$field_name] = array( |
|
| 465 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 466 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
| 467 | 467 | ); |
| 468 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
| 469 | - if( $field_value instanceof \DateTime ) { |
|
| 468 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 469 | + if ($field_value instanceof \DateTime) { |
|
| 470 | 470 | $timezone = $field_value->getTimezone(); |
| 471 | - $field_value->setTimezone( new \DateTimeZone( 'UTC' ) ); |
|
| 472 | - $result[ $field_name . '_gmt' ] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 471 | + $field_value->setTimezone(new \DateTimeZone('UTC')); |
|
| 472 | + $result[$field_name.'_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 473 | 473 | $field_obj, |
| 474 | 474 | $field_value, |
| 475 | 475 | $this->get_model_version_info()->requested_version() |
| 476 | 476 | ); |
| 477 | - $field_value->setTimezone( $timezone ); |
|
| 478 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 477 | + $field_value->setTimezone($timezone); |
|
| 478 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 479 | 479 | $field_obj, |
| 480 | 480 | $field_value, |
| 481 | 481 | $this->get_model_version_info()->requested_version() |
@@ -483,9 +483,9 @@ discard block |
||
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | } else { |
| 486 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 486 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
| 487 | 487 | $field_obj, |
| 488 | - $field_obj->prepare_for_get( $field_value ), |
|
| 488 | + $field_obj->prepare_for_get($field_value), |
|
| 489 | 489 | $this->get_model_version_info()->requested_version() |
| 490 | 490 | ); |
| 491 | 491 | } |
@@ -500,9 +500,9 @@ discard block |
||
| 500 | 500 | * @param array $entity_array |
| 501 | 501 | * @return array modified entity |
| 502 | 502 | */ |
| 503 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
| 504 | - if( $model instanceof \EEM_CPT_Base ) { |
|
| 505 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
| 503 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
| 504 | + if ($model instanceof \EEM_CPT_Base) { |
|
| 505 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
| 506 | 506 | } |
| 507 | 507 | return $entity_array; |
| 508 | 508 | } |
@@ -516,14 +516,14 @@ discard block |
||
| 516 | 516 | * @param array $entity_array |
| 517 | 517 | * @return array the _links item in the entity |
| 518 | 518 | */ |
| 519 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
| 519 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
| 520 | 520 | //add basic links |
| 521 | 521 | $links = array(); |
| 522 | - if( $model->has_primary_key_field() ) { |
|
| 522 | + if ($model->has_primary_key_field()) { |
|
| 523 | 523 | $links['self'] = array( |
| 524 | 524 | array( |
| 525 | 525 | 'href' => $this->get_versioned_link_to( |
| 526 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
| 526 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
| 527 | 527 | ) |
| 528 | 528 | ) |
| 529 | 529 | ); |
@@ -531,33 +531,33 @@ discard block |
||
| 531 | 531 | $links['collection'] = array( |
| 532 | 532 | array( |
| 533 | 533 | 'href' => $this->get_versioned_link_to( |
| 534 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
| 534 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 535 | 535 | ) |
| 536 | 536 | ) |
| 537 | 537 | ); |
| 538 | 538 | |
| 539 | 539 | //add link to the wp core endpoint, if wp api is active |
| 540 | 540 | global $wp_rest_server; |
| 541 | - if( $model instanceof \EEM_CPT_Base && |
|
| 541 | + if ($model instanceof \EEM_CPT_Base && |
|
| 542 | 542 | $wp_rest_server instanceof \WP_REST_Server && |
| 543 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) && |
|
| 544 | - $model->has_primary_key_field() ) { |
|
| 545 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
| 543 | + $wp_rest_server->get_route_options('/wp/v2/posts') && |
|
| 544 | + $model->has_primary_key_field()) { |
|
| 545 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
| 546 | 546 | array( |
| 547 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
| 547 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
| 548 | 548 | 'single' => true |
| 549 | 549 | ) |
| 550 | 550 | ); |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | //add links to related models |
| 554 | - if( $model->has_primary_key_field() ) { |
|
| 555 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
| 556 | - $related_model_part = Read::get_related_entity_name( $relation_name, $relation_obj ); |
|
| 557 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
| 554 | + if ($model->has_primary_key_field()) { |
|
| 555 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
| 556 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
| 557 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
| 558 | 558 | array( |
| 559 | 559 | 'href' => $this->get_versioned_link_to( |
| 560 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
| 560 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
| 561 | 561 | ), |
| 562 | 562 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
| 563 | 563 | ) |
@@ -575,52 +575,52 @@ discard block |
||
| 575 | 575 | * @param array $db_row |
| 576 | 576 | * @return array the modified entity |
| 577 | 577 | */ |
| 578 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array, $db_row = array() ) { |
|
| 578 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array, $db_row = array()) { |
|
| 579 | 579 | //if $db_row not included, hope the entity array has what we need |
| 580 | - if( ! $db_row ) { |
|
| 580 | + if ( ! $db_row) { |
|
| 581 | 581 | $db_row = $entity_array; |
| 582 | 582 | } |
| 583 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
| 584 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
| 583 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
| 584 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
| 585 | 585 | //if they passed in * or didn't specify any includes, return everything |
| 586 | - if( ! in_array( '*', $includes_for_this_model ) |
|
| 587 | - && ! empty( $includes_for_this_model ) ) { |
|
| 588 | - if( $model->has_primary_key_field() ) { |
|
| 586 | + if ( ! in_array('*', $includes_for_this_model) |
|
| 587 | + && ! empty($includes_for_this_model)) { |
|
| 588 | + if ($model->has_primary_key_field()) { |
|
| 589 | 589 | //always include the primary key. ya just gotta know that at least |
| 590 | 590 | $includes_for_this_model[] = $model->primary_key_name(); |
| 591 | 591 | } |
| 592 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
| 592 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
| 593 | 593 | $includes_for_this_model[] = '_calculated_fields'; |
| 594 | 594 | } |
| 595 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
| 595 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
| 596 | 596 | } |
| 597 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
| 598 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
| 597 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
| 598 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
| 599 | 599 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
| 600 | - $rest_request->get_param( 'include' ), |
|
| 600 | + $rest_request->get_param('include'), |
|
| 601 | 601 | $relation_name |
| 602 | 602 | ); |
| 603 | 603 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
| 604 | - $rest_request->get_param( 'calculate' ), |
|
| 604 | + $rest_request->get_param('calculate'), |
|
| 605 | 605 | $relation_name |
| 606 | 606 | ); |
| 607 | 607 | //did they specify they wanted to include a related model, or |
| 608 | 608 | //specific fields from a related model? |
| 609 | 609 | //or did they specify to calculate a field from a related model? |
| 610 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
| 610 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
| 611 | 611 | //if so, we should include at least some part of the related model |
| 612 | 612 | $pretend_related_request = new \WP_REST_Request(); |
| 613 | 613 | $pretend_related_request->set_query_params( |
| 614 | 614 | array( |
| 615 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
| 615 | + 'caps' => $rest_request->get_param('caps'), |
|
| 616 | 616 | 'include' => $related_fields_to_include, |
| 617 | 617 | 'calculate' => $related_fields_to_calculate, |
| 618 | 618 | ) |
| 619 | 619 | ); |
| 620 | - $pretend_related_request->add_header( 'no_rest_headers', true ); |
|
| 620 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
| 621 | 621 | $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID( |
| 622 | 622 | $model->get_index_primary_key_string( |
| 623 | - $model->deduce_fields_n_values_from_cols_n_values( $db_row ) |
|
| 623 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
| 624 | 624 | ) |
| 625 | 625 | ); |
| 626 | 626 | $related_results = $this->_get_entities_from_relation( |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | $relation_obj, |
| 629 | 629 | $pretend_related_request |
| 630 | 630 | ); |
| 631 | - $entity_array[ Read::get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error |
|
| 631 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error |
|
| 632 | 632 | ? null |
| 633 | 633 | : $related_results; |
| 634 | 634 | } |
@@ -642,8 +642,8 @@ discard block |
||
| 642 | 642 | * @param array $arr |
| 643 | 643 | * @return array |
| 644 | 644 | */ |
| 645 | - private function _remove_model_names_from_array( $arr ) { |
|
| 646 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
| 645 | + private function _remove_model_names_from_array($arr) { |
|
| 646 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
| 647 | 647 | } |
| 648 | 648 | /** |
| 649 | 649 | * Gets the calculated fields for the response |
@@ -653,15 +653,15 @@ discard block |
||
| 653 | 653 | * @param \WP_REST_Request $rest_request |
| 654 | 654 | * @return \stdClass the _calculations item in the entity |
| 655 | 655 | */ |
| 656 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
| 656 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
| 657 | 657 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
| 658 | - $rest_request->get_param( 'calculate' ), |
|
| 658 | + $rest_request->get_param('calculate'), |
|
| 659 | 659 | '' |
| 660 | 660 | ); |
| 661 | 661 | //note: setting calculate=* doesn't do anything |
| 662 | 662 | $calculated_fields_to_return = new \stdClass(); |
| 663 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
| 664 | - try{ |
|
| 663 | + foreach ($calculated_fields as $field_to_calculate) { |
|
| 664 | + try { |
|
| 665 | 665 | $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
| 666 | 666 | null, |
| 667 | 667 | $this->_fields_calculator->retrieve_calculated_field_value( |
@@ -673,10 +673,10 @@ discard block |
||
| 673 | 673 | ), |
| 674 | 674 | $this->get_model_version_info()->requested_version() |
| 675 | 675 | ); |
| 676 | - } catch( Rest_Exception $e ) { |
|
| 676 | + } catch (Rest_Exception $e) { |
|
| 677 | 677 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
| 678 | 678 | $this->_set_response_header( |
| 679 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
| 679 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
| 680 | 680 | $e->getMessage(), |
| 681 | 681 | true |
| 682 | 682 | ); |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
| 691 | 691 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
| 692 | 692 | */ |
| 693 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
| 693 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
| 694 | 694 | return rest_url( |
| 695 | 695 | \EED_Core_Rest_Api::ee_api_namespace |
| 696 | 696 | . $this->get_model_version_info()->requested_version() |
@@ -706,11 +706,11 @@ discard block |
||
| 706 | 706 | * @param \EE_Model_Relation_Base $relation_obj |
| 707 | 707 | * @return string |
| 708 | 708 | */ |
| 709 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
| 710 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
| 711 | - return strtolower( $relation_name ); |
|
| 712 | - }else{ |
|
| 713 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
| 709 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
| 710 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
| 711 | + return strtolower($relation_name); |
|
| 712 | + } else { |
|
| 713 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
| 714 | 714 | } |
| 715 | 715 | } |
| 716 | 716 | |
@@ -723,43 +723,43 @@ discard block |
||
| 723 | 723 | * @param \WP_REST_Request $request |
| 724 | 724 | * @return array|\WP_Error |
| 725 | 725 | */ |
| 726 | - public function get_entity_from_model( $model, $request ) { |
|
| 727 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
| 728 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
| 726 | + public function get_entity_from_model($model, $request) { |
|
| 727 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
| 728 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 729 | 729 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
| 730 | 730 | } |
| 731 | 731 | $restricted_query_params = $query_params; |
| 732 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
| 733 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
| 734 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
| 735 | - if ( ! empty ( $model_rows ) ) { |
|
| 732 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
| 733 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
| 734 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
| 735 | + if ( ! empty ($model_rows)) { |
|
| 736 | 736 | return $this->create_entity_from_wpdb_result( |
| 737 | 737 | $model, |
| 738 | - array_shift( $model_rows ), |
|
| 738 | + array_shift($model_rows), |
|
| 739 | 739 | $request ); |
| 740 | 740 | } else { |
| 741 | 741 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
| 742 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
| 743 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
| 744 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
| 742 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
| 743 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
| 744 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
| 745 | 745 | //you got shafted- it existed but we didn't want to tell you! |
| 746 | 746 | return new \WP_Error( |
| 747 | 747 | 'rest_user_cannot_read', |
| 748 | 748 | sprintf( |
| 749 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
| 750 | - strtolower( $model->get_this_model_name() ), |
|
| 749 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
| 750 | + strtolower($model->get_this_model_name()), |
|
| 751 | 751 | Capabilities::get_missing_permissions_string( |
| 752 | 752 | $model, |
| 753 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
| 753 | + $this->validate_context($request->get_param('caps')) ) |
|
| 754 | 754 | ), |
| 755 | - array( 'status' => 403 ) |
|
| 755 | + array('status' => 403) |
|
| 756 | 756 | ); |
| 757 | 757 | } else { |
| 758 | 758 | //it's not you. It just doesn't exist |
| 759 | 759 | return new \WP_Error( |
| 760 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
| 761 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
| 762 | - array( 'status' => 404 ) |
|
| 760 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
| 761 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
| 762 | + array('status' => 404) |
|
| 763 | 763 | ); |
| 764 | 764 | } |
| 765 | 765 | } |
@@ -772,14 +772,14 @@ discard block |
||
| 772 | 772 | * @param string $context |
| 773 | 773 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
| 774 | 774 | */ |
| 775 | - public function validate_context( $context ) { |
|
| 776 | - if( ! $context ) { |
|
| 775 | + public function validate_context($context) { |
|
| 776 | + if ( ! $context) { |
|
| 777 | 777 | $context = \EEM_Base::caps_read; |
| 778 | 778 | } |
| 779 | 779 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
| 780 | - if( in_array( $context, $valid_contexts ) ){ |
|
| 780 | + if (in_array($context, $valid_contexts)) { |
|
| 781 | 781 | return $context; |
| 782 | - }else{ |
|
| 782 | + } else { |
|
| 783 | 783 | return \EEM_Base::caps_read; |
| 784 | 784 | } |
| 785 | 785 | } |
@@ -798,87 +798,87 @@ discard block |
||
| 798 | 798 | * that absolutely no results should be returned |
| 799 | 799 | * @throws \EE_Error |
| 800 | 800 | */ |
| 801 | - public function create_model_query_params( $model, $query_parameters ) { |
|
| 801 | + public function create_model_query_params($model, $query_parameters) { |
|
| 802 | 802 | $model_query_params = array( ); |
| 803 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
| 804 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 805 | - $query_parameters[ 'where' ], |
|
| 803 | + if (isset($query_parameters['where'])) { |
|
| 804 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 805 | + $query_parameters['where'], |
|
| 806 | 806 | $model, |
| 807 | 807 | $this->get_model_version_info()->requested_version() |
| 808 | 808 | ); |
| 809 | 809 | } |
| 810 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
| 811 | - $order_by = $query_parameters[ 'order_by' ]; |
|
| 812 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
| 813 | - $order_by = $query_parameters[ 'orderby' ]; |
|
| 814 | - }else{ |
|
| 810 | + if (isset($query_parameters['order_by'])) { |
|
| 811 | + $order_by = $query_parameters['order_by']; |
|
| 812 | + } elseif (isset($query_parameters['orderby'])) { |
|
| 813 | + $order_by = $query_parameters['orderby']; |
|
| 814 | + } else { |
|
| 815 | 815 | $order_by = null; |
| 816 | 816 | } |
| 817 | - if( $order_by !== null ){ |
|
| 818 | - if( is_array( $order_by ) ) { |
|
| 819 | - $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json( $order_by ); |
|
| 817 | + if ($order_by !== null) { |
|
| 818 | + if (is_array($order_by)) { |
|
| 819 | + $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by); |
|
| 820 | 820 | } else { |
| 821 | 821 | //it's a single item |
| 822 | - $order_by = Model_Data_Translator::prepare_field_name_from_json( $order_by ); |
|
| 822 | + $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by); |
|
| 823 | 823 | } |
| 824 | - $model_query_params[ 'order_by' ] = $order_by; |
|
| 824 | + $model_query_params['order_by'] = $order_by; |
|
| 825 | 825 | } |
| 826 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
| 827 | - $group_by = $query_parameters[ 'group_by' ]; |
|
| 828 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
| 829 | - $group_by = $query_parameters[ 'groupby' ]; |
|
| 830 | - }else{ |
|
| 831 | - $group_by = array_keys( $model->get_combined_primary_key_fields() ); |
|
| 826 | + if (isset($query_parameters['group_by'])) { |
|
| 827 | + $group_by = $query_parameters['group_by']; |
|
| 828 | + } elseif (isset($query_parameters['groupby'])) { |
|
| 829 | + $group_by = $query_parameters['groupby']; |
|
| 830 | + } else { |
|
| 831 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
| 832 | 832 | } |
| 833 | 833 | //make sure they're all real names |
| 834 | - if( is_array( $group_by ) ) { |
|
| 835 | - $group_by = Model_Data_Translator::prepare_field_names_from_json( $group_by ); |
|
| 834 | + if (is_array($group_by)) { |
|
| 835 | + $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by); |
|
| 836 | 836 | } |
| 837 | - if( $group_by !== null ){ |
|
| 838 | - $model_query_params[ 'group_by' ] = $group_by; |
|
| 837 | + if ($group_by !== null) { |
|
| 838 | + $model_query_params['group_by'] = $group_by; |
|
| 839 | 839 | } |
| 840 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
| 841 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 842 | - $query_parameters[ 'having' ], |
|
| 840 | + if (isset($query_parameters['having'])) { |
|
| 841 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
| 842 | + $query_parameters['having'], |
|
| 843 | 843 | $model, |
| 844 | 844 | $this->get_model_version_info()->requested_version() |
| 845 | 845 | ); |
| 846 | 846 | } |
| 847 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
| 848 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
| 847 | + if (isset($query_parameters['order'])) { |
|
| 848 | + $model_query_params['order'] = $query_parameters['order']; |
|
| 849 | 849 | } |
| 850 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
| 851 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
| 850 | + if (isset($query_parameters['mine'])) { |
|
| 851 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
| 852 | 852 | } |
| 853 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
| 853 | + if (isset($query_parameters['limit'])) { |
|
| 854 | 854 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
| 855 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
| 856 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
| 857 | - }else { |
|
| 858 | - $limit_array = $query_parameters[ 'limit' ]; |
|
| 855 | + if ( ! is_array($query_parameters['limit'])) { |
|
| 856 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
| 857 | + } else { |
|
| 858 | + $limit_array = $query_parameters['limit']; |
|
| 859 | 859 | } |
| 860 | 860 | $sanitized_limit = array(); |
| 861 | - foreach( $limit_array as $key => $limit_part ) { |
|
| 862 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
| 861 | + foreach ($limit_array as $key => $limit_part) { |
|
| 862 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 863 | 863 | throw new \EE_Error( |
| 864 | 864 | sprintf( |
| 865 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
| 866 | - json_encode( $query_parameters[ 'limit' ] ) |
|
| 865 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
| 866 | + json_encode($query_parameters['limit']) |
|
| 867 | 867 | ) |
| 868 | 868 | ); |
| 869 | 869 | } |
| 870 | - $sanitized_limit[] = (int)$limit_part; |
|
| 870 | + $sanitized_limit[] = (int) $limit_part; |
|
| 871 | 871 | } |
| 872 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
| 873 | - }else{ |
|
| 874 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 872 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
| 873 | + } else { |
|
| 874 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
| 875 | 875 | } |
| 876 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
| 877 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
| 878 | - }else{ |
|
| 879 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
| 876 | + if (isset($query_parameters['caps'])) { |
|
| 877 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
| 878 | + } else { |
|
| 879 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
| 880 | 880 | } |
| 881 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
| 881 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | |
@@ -890,13 +890,13 @@ discard block |
||
| 890 | 890 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
| 891 | 891 | * @return array |
| 892 | 892 | */ |
| 893 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
| 893 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
| 894 | 894 | $model_ready_query_params = array(); |
| 895 | - foreach( $query_params as $key => $value ) { |
|
| 896 | - if( is_array( $value ) ) { |
|
| 897 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
| 898 | - }else{ |
|
| 899 | - $model_ready_query_params[ $key ] = $value; |
|
| 895 | + foreach ($query_params as $key => $value) { |
|
| 896 | + if (is_array($value)) { |
|
| 897 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
| 898 | + } else { |
|
| 899 | + $model_ready_query_params[$key] = $value; |
|
| 900 | 900 | } |
| 901 | 901 | } |
| 902 | 902 | return $model_ready_query_params; |
@@ -910,13 +910,13 @@ discard block |
||
| 910 | 910 | * @param $query_params |
| 911 | 911 | * @return array |
| 912 | 912 | */ |
| 913 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
| 913 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
| 914 | 914 | $model_ready_query_params = array(); |
| 915 | - foreach( $query_params as $key => $value ) { |
|
| 916 | - if( is_array( $value ) ) { |
|
| 917 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
| 915 | + foreach ($query_params as $key => $value) { |
|
| 916 | + if (is_array($value)) { |
|
| 917 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
| 918 | 918 | } else { |
| 919 | - $model_ready_query_params[ $key ] = $value; |
|
| 919 | + $model_ready_query_params[$key] = $value; |
|
| 920 | 920 | } |
| 921 | 921 | } |
| 922 | 922 | return $model_ready_query_params; |
@@ -931,33 +931,33 @@ discard block |
||
| 931 | 931 | * we only return strings starting with that and a period; if no prefix was specified |
| 932 | 932 | * we return all items containing NO periods |
| 933 | 933 | */ |
| 934 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
| 935 | - if( is_string( $string_to_explode ) ) { |
|
| 936 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
| 937 | - } else if( is_array( $string_to_explode ) ) { |
|
| 934 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
| 935 | + if (is_string($string_to_explode)) { |
|
| 936 | + $exploded_contents = explode(',', $string_to_explode); |
|
| 937 | + } else if (is_array($string_to_explode)) { |
|
| 938 | 938 | $exploded_contents = $string_to_explode; |
| 939 | 939 | } else { |
| 940 | 940 | $exploded_contents = array(); |
| 941 | 941 | } |
| 942 | 942 | //if the string was empty, we want an empty array |
| 943 | - $exploded_contents = array_filter( $exploded_contents ); |
|
| 943 | + $exploded_contents = array_filter($exploded_contents); |
|
| 944 | 944 | $contents_with_prefix = array(); |
| 945 | - foreach( $exploded_contents as $item ) { |
|
| 946 | - $item = trim( $item ); |
|
| 945 | + foreach ($exploded_contents as $item) { |
|
| 946 | + $item = trim($item); |
|
| 947 | 947 | //if no prefix was provided, so we look for items with no "." in them |
| 948 | - if( ! $prefix ) { |
|
| 948 | + if ( ! $prefix) { |
|
| 949 | 949 | //does this item have a period? |
| 950 | - if( strpos( $item, '.' ) === false ) { |
|
| 950 | + if (strpos($item, '.') === false) { |
|
| 951 | 951 | //if not, then its what we're looking for |
| 952 | 952 | $contents_with_prefix[] = $item; |
| 953 | 953 | } |
| 954 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
| 954 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
| 955 | 955 | //this item has the prefix and a period, grab it |
| 956 | 956 | $contents_with_prefix[] = substr( |
| 957 | 957 | $item, |
| 958 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
| 958 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
| 959 | 959 | ); |
| 960 | - } else if( $item === $prefix ) { |
|
| 960 | + } else if ($item === $prefix) { |
|
| 961 | 961 | //this item is JUST the prefix |
| 962 | 962 | //so let's grab everything after, which is a blank string |
| 963 | 963 | $contents_with_prefix[] = ''; |
@@ -980,33 +980,33 @@ discard block |
||
| 980 | 980 | * the fields for that model, with the model's name removed from each. |
| 981 | 981 | * If $include_string was blank or '*' returns an empty array |
| 982 | 982 | */ |
| 983 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
| 984 | - if( is_array( $include_string ) ) { |
|
| 985 | - $include_string = implode( ',', $include_string ); |
|
| 983 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
| 984 | + if (is_array($include_string)) { |
|
| 985 | + $include_string = implode(',', $include_string); |
|
| 986 | 986 | } |
| 987 | - if( $include_string === '*' || $include_string === '' ) { |
|
| 987 | + if ($include_string === '*' || $include_string === '') { |
|
| 988 | 988 | return array(); |
| 989 | 989 | } |
| 990 | - $includes = explode( ',', $include_string ); |
|
| 990 | + $includes = explode(',', $include_string); |
|
| 991 | 991 | $extracted_fields_to_include = array(); |
| 992 | - if( $model_name ){ |
|
| 993 | - foreach( $includes as $field_to_include ) { |
|
| 994 | - $field_to_include = trim( $field_to_include ); |
|
| 995 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
| 992 | + if ($model_name) { |
|
| 993 | + foreach ($includes as $field_to_include) { |
|
| 994 | + $field_to_include = trim($field_to_include); |
|
| 995 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
| 996 | 996 | //found the model name at the exact start |
| 997 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
| 997 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
| 998 | 998 | $extracted_fields_to_include[] = $field_sans_model_name; |
| 999 | - }elseif( $field_to_include == $model_name ){ |
|
| 999 | + }elseif ($field_to_include == $model_name) { |
|
| 1000 | 1000 | $extracted_fields_to_include[] = '*'; |
| 1001 | 1001 | } |
| 1002 | 1002 | } |
| 1003 | - }else{ |
|
| 1003 | + } else { |
|
| 1004 | 1004 | //look for ones with no period |
| 1005 | - foreach( $includes as $field_to_include ) { |
|
| 1006 | - $field_to_include = trim( $field_to_include ); |
|
| 1005 | + foreach ($includes as $field_to_include) { |
|
| 1006 | + $field_to_include = trim($field_to_include); |
|
| 1007 | 1007 | if ( |
| 1008 | - strpos( $field_to_include, '.' ) === false |
|
| 1009 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
| 1008 | + strpos($field_to_include, '.') === false |
|
| 1009 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
| 1010 | 1010 | ) { |
| 1011 | 1011 | $extracted_fields_to_include[] = $field_to_include; |
| 1012 | 1012 | } |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | //we only care to do this for frontend reads and when the user can't edit the item |
| 112 | 112 | if ( |
| 113 | 113 | $request_type !== \EEM_Base::caps_read |
| 114 | - || $model->exists( |
|
| 114 | + || $model->exists( |
|
| 115 | 115 | $model->alter_query_params_to_restrict_by_ID( |
| 116 | 116 | $primary_key_string, |
| 117 | 117 | array( |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
| 24 | 24 | * @return boolean |
| 25 | 25 | */ |
| 26 | - public static function current_user_has_partial_access_to( $model, $model_context = \EEM_Base::caps_read ) { |
|
| 26 | + public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) { |
|
| 27 | 27 | if ( |
| 28 | 28 | apply_filters( |
| 29 | 29 | 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | ) { |
| 35 | 35 | return true; |
| 36 | 36 | } |
| 37 | - foreach ( $model->caps_missing( $model_context ) as $capability_name => $restriction_obj ) { |
|
| 38 | - if ( $restriction_obj instanceof \EE_Return_None_Where_Conditions ) { |
|
| 37 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
| 38 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
| 39 | 39 | return false; |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @param string $request_type one of the constants on WP_JSON_Server |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public static function get_missing_permissions( $model, $request_type = \EEM_Base::caps_read ) { |
|
| 66 | - return $model->caps_missing( $request_type ); |
|
| 65 | + public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) { |
|
| 66 | + return $model->caps_missing($request_type); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | - public static function get_missing_permissions_string( $model, $model_context = \EEM_Base::caps_read ) { |
|
| 80 | - return implode( ',', array_keys( self::get_missing_permissions( $model, $model_context ) ) ); |
|
| 79 | + public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) { |
|
| 80 | + return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | //if they didn't provide the primary key string, we'll just hope we can figure it out |
| 104 | 104 | //from the entity (although it's preferred client code does it, because the entity might be missing |
| 105 | 105 | //necessary fields for creating the primary key string, or they could be named differently) |
| 106 | - if ( $primary_key_string === null ) { |
|
| 106 | + if ($primary_key_string === null) { |
|
| 107 | 107 | $primary_key_string = $model->get_index_primary_key_string( |
| 108 | - $model->deduce_fields_n_values_from_cols_n_values( $entity ) |
|
| 108 | + $model->deduce_fields_n_values_from_cols_n_values($entity) |
|
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | //we only care to do this for frontend reads and when the user can't edit the item |
@@ -123,14 +123,14 @@ discard block |
||
| 123 | 123 | ) { |
| 124 | 124 | return $entity; |
| 125 | 125 | } |
| 126 | - foreach ( $model->field_settings() as $field_name => $field_obj ) { |
|
| 126 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
| 127 | 127 | if ( |
| 128 | - $model_version_info->field_has_rendered_format( $field_obj ) |
|
| 129 | - && isset( $entity[ $field_name ] ) |
|
| 130 | - && is_array( $entity[ $field_name ] ) |
|
| 131 | - && isset( $entity[ $field_name ]['raw'] ) |
|
| 128 | + $model_version_info->field_has_rendered_format($field_obj) |
|
| 129 | + && isset($entity[$field_name]) |
|
| 130 | + && is_array($entity[$field_name]) |
|
| 131 | + && isset($entity[$field_name]['raw']) |
|
| 132 | 132 | ) { |
| 133 | - unset( $entity[ $field_name ]['raw'] ); |
|
| 133 | + unset($entity[$field_name]['raw']); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | //theoretically we may want to filter out specific fields for specific models |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @since 4.6.0 |
| 601 | 601 | * @global WPDB $wpdb |
| 602 | 602 | * |
| 603 | - * @return mixed null|int WP_user ID or NULL |
|
| 603 | + * @return integer|null null|int WP_user ID or NULL |
|
| 604 | 604 | */ |
| 605 | 605 | public static function get_default_creator_id() { |
| 606 | 606 | global $wpdb; |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * @static |
| 760 | 760 | * @deprecated instead use TableManager::dropTable() |
| 761 | 761 | * @param string $table_name |
| 762 | - * @return bool | int |
|
| 762 | + * @return integer | int |
|
| 763 | 763 | */ |
| 764 | 764 | public static function delete_unused_db_table( $table_name ) { |
| 765 | 765 | return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | * @deprecated instead use TableManager::dropIndex() |
| 776 | 776 | * @param string $table_name |
| 777 | 777 | * @param string $index_name |
| 778 | - * @return bool | int |
|
| 778 | + * @return integer | int |
|
| 779 | 779 | */ |
| 780 | 780 | public static function drop_index( $table_name, $index_name ) { |
| 781 | 781 | return \EEH_Activation::getTableManager()->dropIndex( $table_name, $index_name ); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | if ( is_array( $hooks_to_fire_at_time ) ) { |
| 252 | 252 | foreach ( $hooks_to_fire_at_time as $hook_name => $hook_actions ) { |
| 253 | 253 | if ( isset( $ee_cron_tasks_to_remove[ $hook_name ] ) |
| 254 | - && is_array( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
| 254 | + && is_array( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
| 255 | 255 | ) { |
| 256 | 256 | unset( $crons[ $timestamp ][ $hook_name ] ); |
| 257 | 257 | } |
@@ -736,13 +736,13 @@ discard block |
||
| 736 | 736 | |
| 737 | 737 | |
| 738 | 738 | /** |
| 739 | - * delete_db_table_if_empty |
|
| 740 | - * |
|
| 741 | - * @access public |
|
| 742 | - * @static |
|
| 743 | - * @param string $table_name |
|
| 744 | - * @return bool | int |
|
| 745 | - */ |
|
| 739 | + * delete_db_table_if_empty |
|
| 740 | + * |
|
| 741 | + * @access public |
|
| 742 | + * @static |
|
| 743 | + * @param string $table_name |
|
| 744 | + * @return bool | int |
|
| 745 | + */ |
|
| 746 | 746 | public static function delete_db_table_if_empty( $table_name ) { |
| 747 | 747 | if ( \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ) ) { |
| 748 | 748 | return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
@@ -1103,14 +1103,14 @@ discard block |
||
| 1103 | 1103 | $QSG_ID = reset( $id_col ); |
| 1104 | 1104 | } else { |
| 1105 | 1105 | //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
| 1106 | - EE_Log::instance()->log( |
|
| 1107 | - __FILE__, |
|
| 1108 | - __FUNCTION__, |
|
| 1109 | - sprintf( |
|
| 1110 | - __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
| 1111 | - $QST_ID ), |
|
| 1112 | - 'error' ); |
|
| 1113 | - continue; |
|
| 1106 | + EE_Log::instance()->log( |
|
| 1107 | + __FILE__, |
|
| 1108 | + __FUNCTION__, |
|
| 1109 | + sprintf( |
|
| 1110 | + __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
| 1111 | + $QST_ID ), |
|
| 1112 | + 'error' ); |
|
| 1113 | + continue; |
|
| 1114 | 1114 | } |
| 1115 | 1115 | } |
| 1116 | 1116 | |
@@ -1118,8 +1118,8 @@ discard block |
||
| 1118 | 1118 | $wpdb->insert( |
| 1119 | 1119 | \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question_group_question' ), |
| 1120 | 1120 | array( 'QSG_ID' => $QSG_ID, |
| 1121 | - 'QST_ID' => $QST_ID, |
|
| 1122 | - 'QGQ_order' => ( $QSG_ID === 1 ) ? $order_for_group_1++ : $order_for_group_2++ |
|
| 1121 | + 'QST_ID' => $QST_ID, |
|
| 1122 | + 'QGQ_order' => ( $QSG_ID === 1 ) ? $order_for_group_1++ : $order_for_group_2++ |
|
| 1123 | 1123 | ), |
| 1124 | 1124 | array( '%d', '%d', '%d' ) |
| 1125 | 1125 | ); |
@@ -1663,8 +1663,8 @@ discard block |
||
| 1663 | 1663 | } |
| 1664 | 1664 | } |
| 1665 | 1665 | } |
| 1666 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1667 | - remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
| 1666 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1667 | + remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
| 1668 | 1668 | |
| 1669 | 1669 | if ( $remove_all && $espresso_db_update = get_option( 'espresso_db_update' )) { |
| 1670 | 1670 | $db_update_sans_ee4 = array(); |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
| 2 | 2 | /** |
| 3 | 3 | * EEH_Activation Helper |
| 4 | 4 | * |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @return \EventEspresso\core\services\database\TableAnalysis |
| 55 | 55 | */ |
| 56 | 56 | public static function getTableAnalysis() { |
| 57 | - if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis ) { |
|
| 58 | - self::$table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
| 57 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 58 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 59 | 59 | } |
| 60 | 60 | return self::$table_analysis; |
| 61 | 61 | } |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @return \EventEspresso\core\services\database\TableManager |
| 67 | 67 | */ |
| 68 | 68 | public static function getTableManager() { |
| 69 | - if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager ) { |
|
| 70 | - self::$table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
| 69 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 70 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 71 | 71 | } |
| 72 | 72 | return self::$table_manager; |
| 73 | 73 | } |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param $table_name |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - public static function ensure_table_name_has_prefix( $table_name ) { |
|
| 86 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( $table_name ); |
|
| 85 | + public static function ensure_table_name_has_prefix($table_name) { |
|
| 86 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return boolean success, whether the database and folders are setup properly |
| 112 | 112 | * @throws \EE_Error |
| 113 | 113 | */ |
| 114 | - public static function initialize_db_and_folders(){ |
|
| 114 | + public static function initialize_db_and_folders() { |
|
| 115 | 115 | $good_filesystem = EEH_Activation::create_upload_directories(); |
| 116 | 116 | $good_db = EEH_Activation::create_database_tables(); |
| 117 | 117 | return $good_filesystem && $good_db; |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @throws \EE_Error |
| 129 | 129 | */ |
| 130 | - public static function initialize_db_content(){ |
|
| 130 | + public static function initialize_db_content() { |
|
| 131 | 131 | //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
| 132 | - if( EEH_Activation::$_initialized_db_content_already_in_this_request ) { |
|
| 132 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | EEH_Activation::remove_cron_tasks(); |
| 147 | 147 | EEH_Activation::create_cron_tasks(); |
| 148 | 148 | // remove all TXN locks since that is being done via extra meta now |
| 149 | - delete_option( 'ee_locked_transactions' ); |
|
| 149 | + delete_option('ee_locked_transactions'); |
|
| 150 | 150 | //also, check for CAF default db content |
| 151 | - do_action( 'AHEE__EEH_Activation__initialize_db_content' ); |
|
| 151 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 152 | 152 | //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
| 153 | 153 | //which users really won't care about on initial activation |
| 154 | 154 | EE_Error::overwrite_success(); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @return array |
| 169 | 169 | * @throws \EE_Error |
| 170 | 170 | */ |
| 171 | - public static function get_cron_tasks( $which_to_include ) { |
|
| 171 | + public static function get_cron_tasks($which_to_include) { |
|
| 172 | 172 | $cron_tasks = apply_filters( |
| 173 | 173 | 'FHEE__EEH_Activation__get_cron_tasks', |
| 174 | 174 | array( |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
| 178 | 178 | ) |
| 179 | 179 | ); |
| 180 | - if ( $which_to_include === 'old' ) { |
|
| 180 | + if ($which_to_include === 'old') { |
|
| 181 | 181 | $cron_tasks = array_filter( |
| 182 | 182 | $cron_tasks, |
| 183 | - function ( $value ) { |
|
| 183 | + function($value) { |
|
| 184 | 184 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
| 185 | 185 | } |
| 186 | 186 | ); |
| 187 | - } elseif ( $which_to_include === 'current' ) { |
|
| 188 | - $cron_tasks = array_filter( $cron_tasks ); |
|
| 189 | - } elseif ( WP_DEBUG && $which_to_include !== 'all' ) { |
|
| 187 | + } elseif ($which_to_include === 'current') { |
|
| 188 | + $cron_tasks = array_filter($cron_tasks); |
|
| 189 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 190 | 190 | throw new EE_Error( |
| 191 | 191 | sprintf( |
| 192 | 192 | __( |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public static function create_cron_tasks() { |
| 211 | 211 | |
| 212 | - foreach( EEH_Activation::get_cron_tasks( 'current' ) as $hook_name => $frequency ) { |
|
| 213 | - if( ! wp_next_scheduled( $hook_name ) ) { |
|
| 214 | - wp_schedule_event( time(), $frequency, $hook_name ); |
|
| 212 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 213 | + if ( ! wp_next_scheduled($hook_name)) { |
|
| 214 | + wp_schedule_event(time(), $frequency, $hook_name); |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
@@ -225,10 +225,10 @@ discard block |
||
| 225 | 225 | * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
| 226 | 226 | * @throws \EE_Error |
| 227 | 227 | */ |
| 228 | - public static function remove_cron_tasks( $remove_all = true ) { |
|
| 228 | + public static function remove_cron_tasks($remove_all = true) { |
|
| 229 | 229 | $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
| 230 | 230 | $crons = _get_cron_array(); |
| 231 | - $crons = is_array( $crons ) ? $crons : array(); |
|
| 231 | + $crons = is_array($crons) ? $crons : array(); |
|
| 232 | 232 | /* reminder of what $crons look like: |
| 233 | 233 | * Top-level keys are timestamps, and their values are arrays. |
| 234 | 234 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
@@ -246,23 +246,23 @@ discard block |
||
| 246 | 246 | * ... |
| 247 | 247 | * ... |
| 248 | 248 | */ |
| 249 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks( $cron_tasks_to_remove ); |
|
| 250 | - foreach ( $crons as $timestamp => $hooks_to_fire_at_time ) { |
|
| 251 | - if ( is_array( $hooks_to_fire_at_time ) ) { |
|
| 252 | - foreach ( $hooks_to_fire_at_time as $hook_name => $hook_actions ) { |
|
| 253 | - if ( isset( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
| 254 | - && is_array( $ee_cron_tasks_to_remove[ $hook_name ] ) |
|
| 249 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 250 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 251 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 252 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 253 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 254 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 255 | 255 | ) { |
| 256 | - unset( $crons[ $timestamp ][ $hook_name ] ); |
|
| 256 | + unset($crons[$timestamp][$hook_name]); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | //also take care of any empty cron timestamps. |
| 260 | - if ( empty( $hooks_to_fire_at_time ) ) { |
|
| 261 | - unset( $crons[ $timestamp ] ); |
|
| 260 | + if (empty($hooks_to_fire_at_time)) { |
|
| 261 | + unset($crons[$timestamp]); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | - _set_cron_array( $crons ); |
|
| 265 | + _set_cron_array($crons); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | public static function CPT_initialization() { |
| 279 | 279 | // register Custom Post Types |
| 280 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
| 280 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 281 | 281 | flush_rewrite_rules(); |
| 282 | 282 | } |
| 283 | 283 | |
@@ -295,11 +295,11 @@ discard block |
||
| 295 | 295 | * @return void |
| 296 | 296 | */ |
| 297 | 297 | public static function reset_and_update_config() { |
| 298 | - do_action( 'AHEE__EE_Config___load_core_config__start', array( 'EEH_Activation', 'load_calendar_config' ) ); |
|
| 299 | - add_filter( 'FHEE__EE_Config___load_core_config__config_settings', array( 'EEH_Activation', 'migrate_old_config_data' ), 10, 3 ); |
|
| 298 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 299 | + add_filter('FHEE__EE_Config___load_core_config__config_settings', array('EEH_Activation', 'migrate_old_config_data'), 10, 3); |
|
| 300 | 300 | //EE_Config::reset(); |
| 301 | - if ( ! EE_Config::logging_enabled() ) { |
|
| 302 | - delete_option( EE_Config::LOG_NAME ); |
|
| 301 | + if ( ! EE_Config::logging_enabled()) { |
|
| 302 | + delete_option(EE_Config::LOG_NAME); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -312,28 +312,28 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | public static function load_calendar_config() { |
| 314 | 314 | // grab array of all plugin folders and loop thru it |
| 315 | - $plugins = glob( WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR ); |
|
| 316 | - if ( empty( $plugins ) ) { |
|
| 315 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
| 316 | + if (empty($plugins)) { |
|
| 317 | 317 | return; |
| 318 | 318 | } |
| 319 | - foreach ( $plugins as $plugin_path ) { |
|
| 319 | + foreach ($plugins as $plugin_path) { |
|
| 320 | 320 | // grab plugin folder name from path |
| 321 | - $plugin = basename( $plugin_path ); |
|
| 321 | + $plugin = basename($plugin_path); |
|
| 322 | 322 | // drill down to Espresso plugins |
| 323 | 323 | // then to calendar related plugins |
| 324 | 324 | if ( |
| 325 | - strpos( $plugin, 'espresso' ) !== FALSE |
|
| 326 | - || strpos( $plugin, 'Espresso' ) !== FALSE |
|
| 327 | - || strpos( $plugin, 'ee4' ) !== FALSE |
|
| 328 | - || strpos( $plugin, 'EE4' ) !== FALSE |
|
| 329 | - || strpos( $plugin, 'calendar' ) !== false |
|
| 325 | + strpos($plugin, 'espresso') !== FALSE |
|
| 326 | + || strpos($plugin, 'Espresso') !== FALSE |
|
| 327 | + || strpos($plugin, 'ee4') !== FALSE |
|
| 328 | + || strpos($plugin, 'EE4') !== FALSE |
|
| 329 | + || strpos($plugin, 'calendar') !== false |
|
| 330 | 330 | ) { |
| 331 | 331 | // this is what we are looking for |
| 332 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 332 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
| 333 | 333 | // does it exist in this folder ? |
| 334 | - if ( is_readable( $calendar_config )) { |
|
| 334 | + if (is_readable($calendar_config)) { |
|
| 335 | 335 | // YEAH! let's load it |
| 336 | - require_once( $calendar_config ); |
|
| 336 | + require_once($calendar_config); |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | } |
@@ -349,21 +349,21 @@ discard block |
||
| 349 | 349 | * @param \EE_Config $EE_Config |
| 350 | 350 | * @return \stdClass |
| 351 | 351 | */ |
| 352 | - public static function migrate_old_config_data( $settings = array(), $config = '', EE_Config $EE_Config ) { |
|
| 353 | - $convert_from_array = array( 'addons' ); |
|
| 352 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) { |
|
| 353 | + $convert_from_array = array('addons'); |
|
| 354 | 354 | // in case old settings were saved as an array |
| 355 | - if ( is_array( $settings ) && in_array( $config, $convert_from_array )) { |
|
| 355 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 356 | 356 | // convert existing settings to an object |
| 357 | 357 | $config_array = $settings; |
| 358 | 358 | $settings = new stdClass(); |
| 359 | - foreach ( $config_array as $key => $value ){ |
|
| 360 | - if ( $key === 'calendar' && class_exists( 'EE_Calendar_Config' )) { |
|
| 361 | - $EE_Config->set_config( 'addons', 'EE_Calendar', 'EE_Calendar_Config', $value ); |
|
| 359 | + foreach ($config_array as $key => $value) { |
|
| 360 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 361 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 362 | 362 | } else { |
| 363 | 363 | $settings->{$key} = $value; |
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | - add_filter( 'FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true' ); |
|
| 366 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 367 | 367 | } |
| 368 | 368 | return $settings; |
| 369 | 369 | } |
@@ -379,8 +379,8 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public static function deactivate_event_espresso() { |
| 381 | 381 | // check permissions |
| 382 | - if ( current_user_can( 'activate_plugins' )) { |
|
| 383 | - deactivate_plugins( EE_PLUGIN_BASENAME, TRUE ); |
|
| 382 | + if (current_user_can('activate_plugins')) { |
|
| 383 | + deactivate_plugins(EE_PLUGIN_BASENAME, TRUE); |
|
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | |
@@ -402,25 +402,25 @@ discard block |
||
| 402 | 402 | $critical_pages = array( |
| 403 | 403 | array( |
| 404 | 404 | 'id' =>'reg_page_id', |
| 405 | - 'name' => __( 'Registration Checkout', 'event_espresso' ), |
|
| 405 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 406 | 406 | 'post' => NULL, |
| 407 | 407 | 'code' => 'ESPRESSO_CHECKOUT' |
| 408 | 408 | ), |
| 409 | 409 | array( |
| 410 | 410 | 'id' => 'txn_page_id', |
| 411 | - 'name' => __( 'Transactions', 'event_espresso' ), |
|
| 411 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 412 | 412 | 'post' => NULL, |
| 413 | 413 | 'code' => 'ESPRESSO_TXN_PAGE' |
| 414 | 414 | ), |
| 415 | 415 | array( |
| 416 | 416 | 'id' => 'thank_you_page_id', |
| 417 | - 'name' => __( 'Thank You', 'event_espresso' ), |
|
| 417 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 418 | 418 | 'post' => NULL, |
| 419 | 419 | 'code' => 'ESPRESSO_THANK_YOU' |
| 420 | 420 | ), |
| 421 | 421 | array( |
| 422 | 422 | 'id' => 'cancel_page_id', |
| 423 | - 'name' => __( 'Registration Cancelled', 'event_espresso' ), |
|
| 423 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 424 | 424 | 'post' => NULL, |
| 425 | 425 | 'code' => 'ESPRESSO_CANCELLED' |
| 426 | 426 | ), |
@@ -428,62 +428,62 @@ discard block |
||
| 428 | 428 | |
| 429 | 429 | $EE_Core_Config = EE_Registry::instance()->CFG->core; |
| 430 | 430 | |
| 431 | - foreach ( $critical_pages as $critical_page ) { |
|
| 431 | + foreach ($critical_pages as $critical_page) { |
|
| 432 | 432 | // is critical page ID set in config ? |
| 433 | - if ( $EE_Core_Config->{$critical_page[ 'id' ]} !== FALSE ) { |
|
| 433 | + if ($EE_Core_Config->{$critical_page['id']} !== FALSE) { |
|
| 434 | 434 | // attempt to find post by ID |
| 435 | - $critical_page['post'] = get_post( $EE_Core_Config->{$critical_page[ 'id' ]} ); |
|
| 435 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']} ); |
|
| 436 | 436 | } |
| 437 | 437 | // no dice? |
| 438 | - if ( $critical_page['post'] === null ) { |
|
| 438 | + if ($critical_page['post'] === null) { |
|
| 439 | 439 | // attempt to find post by title |
| 440 | - $critical_page['post'] = self::get_page_by_ee_shortcode( $critical_page['code'] ); |
|
| 440 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 441 | 441 | // still nothing? |
| 442 | - if ( $critical_page['post'] === null ) { |
|
| 443 | - $critical_page = EEH_Activation::create_critical_page( $critical_page ); |
|
| 442 | + if ($critical_page['post'] === null) { |
|
| 443 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 444 | 444 | // REALLY? Still nothing ??!?!? |
| 445 | - if ( $critical_page['post'] === null ) { |
|
| 446 | - $msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' ); |
|
| 447 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 445 | + if ($critical_page['post'] === null) { |
|
| 446 | + $msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso'); |
|
| 447 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 448 | 448 | break; |
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | // track post_shortcodes |
| 453 | - if ( $critical_page['post'] ) { |
|
| 454 | - EEH_Activation::_track_critical_page_post_shortcodes( $critical_page ); |
|
| 453 | + if ($critical_page['post']) { |
|
| 454 | + EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 455 | 455 | } |
| 456 | 456 | // check that Post ID matches critical page ID in config |
| 457 | 457 | if ( |
| 458 | - isset( $critical_page['post']->ID ) |
|
| 459 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page[ 'id' ]} |
|
| 458 | + isset($critical_page['post']->ID) |
|
| 459 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 460 | 460 | ) { |
| 461 | 461 | //update Config with post ID |
| 462 | - $EE_Core_Config->{$critical_page[ 'id' ]} = $critical_page['post']->ID; |
|
| 463 | - if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE ) ) { |
|
| 464 | - $msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' ); |
|
| 465 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 462 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 463 | + if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) { |
|
| 464 | + $msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso'); |
|
| 465 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | $critical_page_problem = |
| 470 | - ! isset( $critical_page['post']->post_status ) |
|
| 470 | + ! isset($critical_page['post']->post_status) |
|
| 471 | 471 | || $critical_page['post']->post_status !== 'publish' |
| 472 | - || strpos( $critical_page['post']->post_content, $critical_page['code'] ) === FALSE |
|
| 472 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === FALSE |
|
| 473 | 473 | ? TRUE |
| 474 | 474 | : $critical_page_problem; |
| 475 | 475 | |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if ( $critical_page_problem ) { |
|
| 478 | + if ($critical_page_problem) { |
|
| 479 | 479 | $msg = sprintf( |
| 480 | - __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso' ), |
|
| 481 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' . __('Event Espresso Critical Pages Settings', 'event_espresso') . '</a>' |
|
| 480 | + __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso'), |
|
| 481 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'.__('Event Espresso Critical Pages Settings', 'event_espresso').'</a>' |
|
| 482 | 482 | ); |
| 483 | - EE_Error::add_persistent_admin_notice( 'critical_page_problem', $msg ); |
|
| 483 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 484 | 484 | } |
| 485 | - if ( EE_Error::has_notices() ) { |
|
| 486 | - EE_Error::get_notices( FALSE, TRUE, TRUE ); |
|
| 485 | + if (EE_Error::has_notices()) { |
|
| 486 | + EE_Error::get_notices(FALSE, TRUE, TRUE); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | |
@@ -495,13 +495,13 @@ discard block |
||
| 495 | 495 | * parameter to the shortcode |
| 496 | 496 | * @return WP_Post or NULl |
| 497 | 497 | */ |
| 498 | - public static function get_page_by_ee_shortcode($ee_shortcode){ |
|
| 498 | + public static function get_page_by_ee_shortcode($ee_shortcode) { |
|
| 499 | 499 | global $wpdb; |
| 500 | 500 | $shortcode_and_opening_bracket = '['.$ee_shortcode; |
| 501 | 501 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
| 502 | - if($post_id){ |
|
| 502 | + if ($post_id) { |
|
| 503 | 503 | return get_post($post_id); |
| 504 | - }else{ |
|
| 504 | + } else { |
|
| 505 | 505 | return NULL; |
| 506 | 506 | } |
| 507 | 507 | |
@@ -518,32 +518,32 @@ discard block |
||
| 518 | 518 | * @param array $critical_page |
| 519 | 519 | * @return array |
| 520 | 520 | */ |
| 521 | - public static function create_critical_page( $critical_page ) { |
|
| 521 | + public static function create_critical_page($critical_page) { |
|
| 522 | 522 | |
| 523 | 523 | $post_args = array( |
| 524 | 524 | 'post_title' => $critical_page['name'], |
| 525 | 525 | 'post_status' => 'publish', |
| 526 | 526 | 'post_type' => 'page', |
| 527 | 527 | 'comment_status' => 'closed', |
| 528 | - 'post_content' => '[' . $critical_page['code'] . ']' |
|
| 528 | + 'post_content' => '['.$critical_page['code'].']' |
|
| 529 | 529 | ); |
| 530 | 530 | |
| 531 | - $post_id = wp_insert_post( $post_args ); |
|
| 532 | - if ( ! $post_id ) { |
|
| 531 | + $post_id = wp_insert_post($post_args); |
|
| 532 | + if ( ! $post_id) { |
|
| 533 | 533 | $msg = sprintf( |
| 534 | - __( 'The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso' ), |
|
| 534 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 535 | 535 | $critical_page['name'] |
| 536 | 536 | ); |
| 537 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 537 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 538 | 538 | return $critical_page; |
| 539 | 539 | } |
| 540 | 540 | // get newly created post's details |
| 541 | - if ( ! $critical_page['post'] = get_post( $post_id )) { |
|
| 541 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
| 542 | 542 | $msg = sprintf( |
| 543 | - __( 'The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso' ), |
|
| 543 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 544 | 544 | $critical_page['name'] |
| 545 | 545 | ); |
| 546 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 546 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | return $critical_page; |
@@ -562,35 +562,35 @@ discard block |
||
| 562 | 562 | * @param array $critical_page |
| 563 | 563 | * @return void |
| 564 | 564 | */ |
| 565 | - private static function _track_critical_page_post_shortcodes( $critical_page = array() ) { |
|
| 565 | + private static function _track_critical_page_post_shortcodes($critical_page = array()) { |
|
| 566 | 566 | // check the goods |
| 567 | - if ( ! $critical_page['post'] instanceof WP_Post ) { |
|
| 567 | + if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 568 | 568 | $msg = sprintf( |
| 569 | - __( 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso' ), |
|
| 569 | + __('The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso'), |
|
| 570 | 570 | $critical_page['name'] |
| 571 | 571 | ); |
| 572 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 572 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 573 | 573 | return; |
| 574 | 574 | } |
| 575 | 575 | $EE_Core_Config = EE_Registry::instance()->CFG->core; |
| 576 | 576 | // map shortcode to post |
| 577 | - $EE_Core_Config->post_shortcodes[ $critical_page['post']->post_name ][ $critical_page['code'] ] = $critical_page['post']->ID; |
|
| 577 | + $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 578 | 578 | // and make sure it's NOT added to the WP "Posts Page" |
| 579 | 579 | // name of the WP Posts Page |
| 580 | 580 | $posts_page = EE_Config::get_page_for_posts(); |
| 581 | - if ( isset( $EE_Core_Config->post_shortcodes[ $posts_page ] )) { |
|
| 582 | - unset( $EE_Core_Config->post_shortcodes[ $posts_page ][ $critical_page['code'] ] ); |
|
| 581 | + if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 582 | + unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 583 | 583 | } |
| 584 | - if ( $posts_page !== 'posts' && isset( $EE_Core_Config->post_shortcodes['posts'] )) { |
|
| 585 | - unset( $EE_Core_Config->post_shortcodes['posts'][ $critical_page['code'] ] ); |
|
| 584 | + if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 585 | + unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 586 | 586 | } |
| 587 | 587 | // update post_shortcode CFG |
| 588 | - if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE )) { |
|
| 588 | + if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) { |
|
| 589 | 589 | $msg = sprintf( |
| 590 | - __( 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso' ), |
|
| 590 | + __('The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso'), |
|
| 591 | 591 | $critical_page['name'] |
| 592 | 592 | ); |
| 593 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 593 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | |
@@ -608,24 +608,24 @@ discard block |
||
| 608 | 608 | public static function get_default_creator_id() { |
| 609 | 609 | global $wpdb; |
| 610 | 610 | |
| 611 | - if ( ! empty( self::$_default_creator_id ) ) { |
|
| 611 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 612 | 612 | return self::$_default_creator_id; |
| 613 | 613 | }/**/ |
| 614 | 614 | |
| 615 | - $role_to_check = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator' ); |
|
| 615 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 616 | 616 | |
| 617 | 617 | //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
| 618 | - $pre_filtered_id = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check ); |
|
| 619 | - if ( $pre_filtered_id !== false ) { |
|
| 618 | + $pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check); |
|
| 619 | + if ($pre_filtered_id !== false) { |
|
| 620 | 620 | return (int) $pre_filtered_id; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'capabilities' ); |
|
| 624 | - $query = $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%' . $role_to_check . '%' ); |
|
| 625 | - $user_id = $wpdb->get_var( $query ); |
|
| 626 | - $user_id = apply_filters( 'FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id ); |
|
| 627 | - if ( $user_id && (int)$user_id ) { |
|
| 628 | - self::$_default_creator_id = (int)$user_id; |
|
| 623 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 624 | + $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%'.$role_to_check.'%'); |
|
| 625 | + $user_id = $wpdb->get_var($query); |
|
| 626 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 627 | + if ($user_id && (int) $user_id) { |
|
| 628 | + self::$_default_creator_id = (int) $user_id; |
|
| 629 | 629 | return self::$_default_creator_id; |
| 630 | 630 | } else { |
| 631 | 631 | return NULL; |
@@ -654,28 +654,28 @@ discard block |
||
| 654 | 654 | * @return void |
| 655 | 655 | * @throws EE_Error if there are database errors |
| 656 | 656 | */ |
| 657 | - public static function create_table( $table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false ) { |
|
| 658 | - if( apply_filters( 'FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql ) ){ |
|
| 657 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) { |
|
| 658 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql)) { |
|
| 659 | 659 | return; |
| 660 | 660 | } |
| 661 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 662 | - if ( ! function_exists( 'dbDelta' )) { |
|
| 663 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 661 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 662 | + if ( ! function_exists('dbDelta')) { |
|
| 663 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 664 | 664 | } |
| 665 | 665 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
| 666 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix( $table_name ); |
|
| 666 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 667 | 667 | // do we need to first delete an existing version of this table ? |
| 668 | - if ( $drop_pre_existing_table && $tableAnalysis->tableExists( $wp_table_name ) ){ |
|
| 668 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 669 | 669 | // ok, delete the table... but ONLY if it's empty |
| 670 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty( $wp_table_name ); |
|
| 670 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 671 | 671 | // table is NOT empty, are you SURE you want to delete this table ??? |
| 672 | - if ( ! $deleted_safely && defined( 'EE_DROP_BAD_TABLES' ) && EE_DROP_BAD_TABLES ){ |
|
| 673 | - \EEH_Activation::getTableManager()->dropTable( $wp_table_name ); |
|
| 674 | - } else if ( ! $deleted_safely ) { |
|
| 672 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 673 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 674 | + } else if ( ! $deleted_safely) { |
|
| 675 | 675 | // so we should be more cautious rather than just dropping tables so easily |
| 676 | 676 | EE_Error::add_persistent_admin_notice( |
| 677 | - 'bad_table_' . $wp_table_name . '_detected', |
|
| 678 | - sprintf( __( 'Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso' ), |
|
| 677 | + 'bad_table_'.$wp_table_name.'_detected', |
|
| 678 | + sprintf(__('Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso'), |
|
| 679 | 679 | $wp_table_name, |
| 680 | 680 | "<pre>define( 'EE_DROP_BAD_TABLES', TRUE );</pre>", |
| 681 | 681 | '<b>wp-config.php</b>', |
@@ -683,8 +683,8 @@ discard block |
||
| 683 | 683 | TRUE ); |
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | - $engine = str_replace( 'ENGINE=', '', $engine ); |
|
| 687 | - \EEH_Activation::getTableManager()->createTable( $table_name, $sql, $engine ); |
|
| 686 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 687 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | * 'VARCHAR(10)' |
| 703 | 703 | * @return bool|int |
| 704 | 704 | */ |
| 705 | - public static function add_column_if_it_doesnt_exist($table_name,$column_name,$column_info='INT UNSIGNED NOT NULL'){ |
|
| 706 | - return \EEH_Activation::getTableManager()->addColumn( $table_name, $column_name, $column_info ); |
|
| 705 | + public static function add_column_if_it_doesnt_exist($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') { |
|
| 706 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | |
@@ -719,8 +719,8 @@ discard block |
||
| 719 | 719 | * @param string $table_name, without prefixed $wpdb->prefix |
| 720 | 720 | * @return array of database column names |
| 721 | 721 | */ |
| 722 | - public static function get_fields_on_table( $table_name = NULL ) { |
|
| 723 | - return \EEH_Activation::getTableManager()->getTableColumns( $table_name ); |
|
| 722 | + public static function get_fields_on_table($table_name = NULL) { |
|
| 723 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | |
@@ -734,8 +734,8 @@ discard block |
||
| 734 | 734 | * @param string $table_name |
| 735 | 735 | * @return bool |
| 736 | 736 | */ |
| 737 | - public static function db_table_is_empty( $table_name ) { |
|
| 738 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ); |
|
| 737 | + public static function db_table_is_empty($table_name) { |
|
| 738 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | |
@@ -748,9 +748,9 @@ discard block |
||
| 748 | 748 | * @param string $table_name |
| 749 | 749 | * @return bool | int |
| 750 | 750 | */ |
| 751 | - public static function delete_db_table_if_empty( $table_name ) { |
|
| 752 | - if ( \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ) ) { |
|
| 753 | - return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
|
| 751 | + public static function delete_db_table_if_empty($table_name) { |
|
| 752 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 753 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 754 | 754 | } |
| 755 | 755 | return false; |
| 756 | 756 | } |
@@ -766,8 +766,8 @@ discard block |
||
| 766 | 766 | * @param string $table_name |
| 767 | 767 | * @return bool | int |
| 768 | 768 | */ |
| 769 | - public static function delete_unused_db_table( $table_name ) { |
|
| 770 | - return \EEH_Activation::getTableManager()->dropTable( $table_name ); |
|
| 769 | + public static function delete_unused_db_table($table_name) { |
|
| 770 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | |
@@ -782,8 +782,8 @@ discard block |
||
| 782 | 782 | * @param string $index_name |
| 783 | 783 | * @return bool | int |
| 784 | 784 | */ |
| 785 | - public static function drop_index( $table_name, $index_name ) { |
|
| 786 | - return \EEH_Activation::getTableManager()->dropIndex( $table_name, $index_name ); |
|
| 785 | + public static function drop_index($table_name, $index_name) { |
|
| 786 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | |
@@ -797,27 +797,27 @@ discard block |
||
| 797 | 797 | * @return boolean success (whether database is setup properly or not) |
| 798 | 798 | */ |
| 799 | 799 | public static function create_database_tables() { |
| 800 | - EE_Registry::instance()->load_core( 'Data_Migration_Manager' ); |
|
| 800 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 801 | 801 | //find the migration script that sets the database to be compatible with the code |
| 802 | 802 | $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
| 803 | - if( $dms_name ){ |
|
| 804 | - $current_data_migration_script = EE_Registry::instance()->load_dms( $dms_name ); |
|
| 805 | - $current_data_migration_script->set_migrating( false ); |
|
| 803 | + if ($dms_name) { |
|
| 804 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 805 | + $current_data_migration_script->set_migrating(false); |
|
| 806 | 806 | $current_data_migration_script->schema_changes_before_migration(); |
| 807 | 807 | $current_data_migration_script->schema_changes_after_migration(); |
| 808 | - if( $current_data_migration_script->get_errors() ){ |
|
| 809 | - if( WP_DEBUG ){ |
|
| 810 | - foreach( $current_data_migration_script->get_errors() as $error ){ |
|
| 811 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 808 | + if ($current_data_migration_script->get_errors()) { |
|
| 809 | + if (WP_DEBUG) { |
|
| 810 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 811 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 812 | 812 | } |
| 813 | - }else{ |
|
| 814 | - EE_Error::add_error( __( 'There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso' ) ); |
|
| 813 | + } else { |
|
| 814 | + EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso')); |
|
| 815 | 815 | } |
| 816 | 816 | return false; |
| 817 | 817 | } |
| 818 | 818 | EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
| 819 | - }else{ |
|
| 820 | - EE_Error::add_error( __( 'Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 819 | + } else { |
|
| 820 | + EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 821 | 821 | return false; |
| 822 | 822 | } |
| 823 | 823 | return true; |
@@ -837,27 +837,27 @@ discard block |
||
| 837 | 837 | public static function initialize_system_questions() { |
| 838 | 838 | // QUESTION GROUPS |
| 839 | 839 | global $wpdb; |
| 840 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question_group' ); |
|
| 840 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 841 | 841 | $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
| 842 | 842 | // what we have |
| 843 | - $question_groups = $wpdb->get_col( $SQL ); |
|
| 843 | + $question_groups = $wpdb->get_col($SQL); |
|
| 844 | 844 | // check the response |
| 845 | - $question_groups = is_array( $question_groups ) ? $question_groups : array(); |
|
| 845 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 846 | 846 | // what we should have |
| 847 | - $QSG_systems = array( 1, 2 ); |
|
| 847 | + $QSG_systems = array(1, 2); |
|
| 848 | 848 | // loop thru what we should have and compare to what we have |
| 849 | - foreach ( $QSG_systems as $QSG_system ) { |
|
| 849 | + foreach ($QSG_systems as $QSG_system) { |
|
| 850 | 850 | // reset values array |
| 851 | 851 | $QSG_values = array(); |
| 852 | 852 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
| 853 | - if ( ! in_array( "$QSG_system", $question_groups )) { |
|
| 853 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
| 854 | 854 | // add it |
| 855 | - switch ( $QSG_system ) { |
|
| 855 | + switch ($QSG_system) { |
|
| 856 | 856 | |
| 857 | 857 | case 1: |
| 858 | 858 | $QSG_values = array( |
| 859 | - 'QSG_name' => __( 'Personal Information', 'event_espresso' ), |
|
| 860 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 859 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 860 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
| 861 | 861 | 'QSG_desc' => '', |
| 862 | 862 | 'QSG_order' => 1, |
| 863 | 863 | 'QSG_show_group_name' => 1, |
@@ -869,8 +869,8 @@ discard block |
||
| 869 | 869 | |
| 870 | 870 | case 2: |
| 871 | 871 | $QSG_values = array( |
| 872 | - 'QSG_name' => __( 'Address Information','event_espresso' ), |
|
| 873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 872 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 873 | + 'QSG_identifier' => 'address-information-'.time(), |
|
| 874 | 874 | 'QSG_desc' => '', |
| 875 | 875 | 'QSG_order' => 2, |
| 876 | 876 | 'QSG_show_group_name' => 1, |
@@ -882,14 +882,14 @@ discard block |
||
| 882 | 882 | |
| 883 | 883 | } |
| 884 | 884 | // make sure we have some values before inserting them |
| 885 | - if ( ! empty( $QSG_values )) { |
|
| 885 | + if ( ! empty($QSG_values)) { |
|
| 886 | 886 | // insert system question |
| 887 | 887 | $wpdb->insert( |
| 888 | 888 | $table_name, |
| 889 | 889 | $QSG_values, |
| 890 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d' ) |
|
| 890 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 891 | 891 | ); |
| 892 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
| 892 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | 895 | } |
@@ -898,10 +898,10 @@ discard block |
||
| 898 | 898 | |
| 899 | 899 | // QUESTIONS |
| 900 | 900 | global $wpdb; |
| 901 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question' ); |
|
| 901 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 902 | 902 | $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
| 903 | 903 | // what we have |
| 904 | - $questions = $wpdb->get_col( $SQL ); |
|
| 904 | + $questions = $wpdb->get_col($SQL); |
|
| 905 | 905 | // what we should have |
| 906 | 906 | $QST_systems = array( |
| 907 | 907 | 'fname', |
@@ -918,25 +918,25 @@ discard block |
||
| 918 | 918 | $order_for_group_1 = 1; |
| 919 | 919 | $order_for_group_2 = 1; |
| 920 | 920 | // loop thru what we should have and compare to what we have |
| 921 | - foreach ( $QST_systems as $QST_system ) { |
|
| 921 | + foreach ($QST_systems as $QST_system) { |
|
| 922 | 922 | // reset values array |
| 923 | 923 | $QST_values = array(); |
| 924 | 924 | // if we don't have what we should have |
| 925 | - if ( ! in_array( $QST_system, $questions )) { |
|
| 925 | + if ( ! in_array($QST_system, $questions)) { |
|
| 926 | 926 | // add it |
| 927 | - switch ( $QST_system ) { |
|
| 927 | + switch ($QST_system) { |
|
| 928 | 928 | |
| 929 | 929 | case 'fname': |
| 930 | 930 | $QST_values = array( |
| 931 | - 'QST_display_text' => __( 'First Name', 'event_espresso' ), |
|
| 932 | - 'QST_admin_label' => __( 'First Name - System Question', 'event_espresso' ), |
|
| 931 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 932 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 933 | 933 | 'QST_system' => 'fname', |
| 934 | 934 | 'QST_type' => 'TEXT', |
| 935 | 935 | 'QST_required' => 1, |
| 936 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 936 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 937 | 937 | 'QST_order' => 1, |
| 938 | 938 | 'QST_admin_only' => 0, |
| 939 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 939 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 940 | 940 | 'QST_wp_user' => self::get_default_creator_id(), |
| 941 | 941 | 'QST_deleted' => 0 |
| 942 | 942 | ); |
@@ -944,15 +944,15 @@ discard block |
||
| 944 | 944 | |
| 945 | 945 | case 'lname': |
| 946 | 946 | $QST_values = array( |
| 947 | - 'QST_display_text' => __( 'Last Name', 'event_espresso' ), |
|
| 948 | - 'QST_admin_label' => __( 'Last Name - System Question', 'event_espresso' ), |
|
| 947 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 948 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 949 | 949 | 'QST_system' => 'lname', |
| 950 | 950 | 'QST_type' => 'TEXT', |
| 951 | 951 | 'QST_required' => 1, |
| 952 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 952 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 953 | 953 | 'QST_order' => 2, |
| 954 | 954 | 'QST_admin_only' => 0, |
| 955 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 955 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 956 | 956 | 'QST_wp_user' => self::get_default_creator_id(), |
| 957 | 957 | 'QST_deleted' => 0 |
| 958 | 958 | ); |
@@ -960,15 +960,15 @@ discard block |
||
| 960 | 960 | |
| 961 | 961 | case 'email': |
| 962 | 962 | $QST_values = array( |
| 963 | - 'QST_display_text' => __( 'Email Address', 'event_espresso' ), |
|
| 964 | - 'QST_admin_label' => __( 'Email Address - System Question', 'event_espresso' ), |
|
| 963 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 964 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 965 | 965 | 'QST_system' => 'email', |
| 966 | 966 | 'QST_type' => 'EMAIL', |
| 967 | 967 | 'QST_required' => 1, |
| 968 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 968 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 969 | 969 | 'QST_order' => 3, |
| 970 | 970 | 'QST_admin_only' => 0, |
| 971 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 971 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 972 | 972 | 'QST_wp_user' => self::get_default_creator_id(), |
| 973 | 973 | 'QST_deleted' => 0 |
| 974 | 974 | ); |
@@ -976,15 +976,15 @@ discard block |
||
| 976 | 976 | |
| 977 | 977 | case 'address': |
| 978 | 978 | $QST_values = array( |
| 979 | - 'QST_display_text' => __( 'Address', 'event_espresso' ), |
|
| 980 | - 'QST_admin_label' => __( 'Address - System Question', 'event_espresso' ), |
|
| 979 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 980 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 981 | 981 | 'QST_system' => 'address', |
| 982 | 982 | 'QST_type' => 'TEXT', |
| 983 | 983 | 'QST_required' => 0, |
| 984 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 984 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 985 | 985 | 'QST_order' => 4, |
| 986 | 986 | 'QST_admin_only' => 0, |
| 987 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 987 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 988 | 988 | 'QST_wp_user' => self::get_default_creator_id(), |
| 989 | 989 | 'QST_deleted' => 0 |
| 990 | 990 | ); |
@@ -992,15 +992,15 @@ discard block |
||
| 992 | 992 | |
| 993 | 993 | case 'address2': |
| 994 | 994 | $QST_values = array( |
| 995 | - 'QST_display_text' => __( 'Address2', 'event_espresso' ), |
|
| 996 | - 'QST_admin_label' => __( 'Address2 - System Question', 'event_espresso' ), |
|
| 995 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 996 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 997 | 997 | 'QST_system' => 'address2', |
| 998 | 998 | 'QST_type' => 'TEXT', |
| 999 | 999 | 'QST_required' => 0, |
| 1000 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 1000 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1001 | 1001 | 'QST_order' => 5, |
| 1002 | 1002 | 'QST_admin_only' => 0, |
| 1003 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 1003 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1004 | 1004 | 'QST_wp_user' => self::get_default_creator_id(), |
| 1005 | 1005 | 'QST_deleted' => 0 |
| 1006 | 1006 | ); |
@@ -1008,27 +1008,27 @@ discard block |
||
| 1008 | 1008 | |
| 1009 | 1009 | case 'city': |
| 1010 | 1010 | $QST_values = array( |
| 1011 | - 'QST_display_text' => __( 'City', 'event_espresso' ), |
|
| 1012 | - 'QST_admin_label' => __( 'City - System Question', 'event_espresso' ), |
|
| 1011 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1012 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1013 | 1013 | 'QST_system' => 'city', |
| 1014 | 1014 | 'QST_type' => 'TEXT', |
| 1015 | 1015 | 'QST_required' => 0, |
| 1016 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 1016 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1017 | 1017 | 'QST_order' => 6, |
| 1018 | 1018 | 'QST_admin_only' => 0, |
| 1019 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 1019 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1020 | 1020 | 'QST_wp_user' => self::get_default_creator_id(), |
| 1021 | 1021 | 'QST_deleted' => 0 |
| 1022 | 1022 | ); |
| 1023 | 1023 | break; |
| 1024 | 1024 | case 'country' : |
| 1025 | 1025 | $QST_values = array( |
| 1026 | - 'QST_display_text' => __( 'Country', 'event_espresso' ), |
|
| 1027 | - 'QST_admin_label' => __( 'Country - System Question', 'event_espresso' ), |
|
| 1026 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1027 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1028 | 1028 | 'QST_system' => 'country', |
| 1029 | 1029 | 'QST_type' => 'COUNTRY', |
| 1030 | 1030 | 'QST_required' => 0, |
| 1031 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 1031 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1032 | 1032 | 'QST_order' => 7, |
| 1033 | 1033 | 'QST_admin_only' => 0, |
| 1034 | 1034 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1038,12 +1038,12 @@ discard block |
||
| 1038 | 1038 | |
| 1039 | 1039 | case 'state': |
| 1040 | 1040 | $QST_values = array( |
| 1041 | - 'QST_display_text' => __( 'State/Province', 'event_espresso' ), |
|
| 1042 | - 'QST_admin_label' => __( 'State/Province - System Question', 'event_espresso' ), |
|
| 1041 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1042 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1043 | 1043 | 'QST_system' => 'state', |
| 1044 | 1044 | 'QST_type' => 'STATE', |
| 1045 | 1045 | 'QST_required' => 0, |
| 1046 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 1046 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1047 | 1047 | 'QST_order' => 8, |
| 1048 | 1048 | 'QST_admin_only' => 0, |
| 1049 | 1049 | 'QST_wp_user' => self::get_default_creator_id(), |
@@ -1053,15 +1053,15 @@ discard block |
||
| 1053 | 1053 | |
| 1054 | 1054 | case 'zip': |
| 1055 | 1055 | $QST_values = array( |
| 1056 | - 'QST_display_text' => __( 'Zip/Postal Code', 'event_espresso' ), |
|
| 1057 | - 'QST_admin_label' => __( 'Zip/Postal Code - System Question', 'event_espresso' ), |
|
| 1056 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1057 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1058 | 1058 | 'QST_system' => 'zip', |
| 1059 | 1059 | 'QST_type' => 'TEXT', |
| 1060 | 1060 | 'QST_required' => 0, |
| 1061 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 1061 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1062 | 1062 | 'QST_order' => 9, |
| 1063 | 1063 | 'QST_admin_only' => 0, |
| 1064 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 1064 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1065 | 1065 | 'QST_wp_user' => self::get_default_creator_id(), |
| 1066 | 1066 | 'QST_deleted' => 0 |
| 1067 | 1067 | ); |
@@ -1069,49 +1069,49 @@ discard block |
||
| 1069 | 1069 | |
| 1070 | 1070 | case 'phone': |
| 1071 | 1071 | $QST_values = array( |
| 1072 | - 'QST_display_text' => __( 'Phone Number', 'event_espresso' ), |
|
| 1073 | - 'QST_admin_label' => __( 'Phone Number - System Question', 'event_espresso' ), |
|
| 1072 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1073 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1074 | 1074 | 'QST_system' => 'phone', |
| 1075 | 1075 | 'QST_type' => 'TEXT', |
| 1076 | 1076 | 'QST_required' => 0, |
| 1077 | - 'QST_required_text' => __( 'This field is required', 'event_espresso' ), |
|
| 1077 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1078 | 1078 | 'QST_order' => 10, |
| 1079 | 1079 | 'QST_admin_only' => 0, |
| 1080 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ), |
|
| 1080 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1081 | 1081 | 'QST_wp_user' => self::get_default_creator_id(), |
| 1082 | 1082 | 'QST_deleted' => 0 |
| 1083 | 1083 | ); |
| 1084 | 1084 | break; |
| 1085 | 1085 | |
| 1086 | 1086 | } |
| 1087 | - if ( ! empty( $QST_values )) { |
|
| 1087 | + if ( ! empty($QST_values)) { |
|
| 1088 | 1088 | // insert system question |
| 1089 | 1089 | $wpdb->insert( |
| 1090 | 1090 | $table_name, |
| 1091 | 1091 | $QST_values, |
| 1092 | - array( '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d' ) |
|
| 1092 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1093 | 1093 | ); |
| 1094 | 1094 | $QST_ID = $wpdb->insert_id; |
| 1095 | 1095 | |
| 1096 | 1096 | // QUESTION GROUP QUESTIONS |
| 1097 | - if( in_array( $QST_system, array( 'fname', 'lname', 'email' ) ) ) { |
|
| 1097 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1098 | 1098 | $system_question_we_want = EEM_Question_Group::system_personal; |
| 1099 | 1099 | } else { |
| 1100 | 1100 | $system_question_we_want = EEM_Question_Group::system_address; |
| 1101 | 1101 | } |
| 1102 | - if( isset( $QSG_IDs[ $system_question_we_want ] ) ) { |
|
| 1103 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
| 1102 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1103 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1104 | 1104 | } else { |
| 1105 | - $id_col = EEM_Question_Group::instance()->get_col( array( array( 'QSG_system' => $system_question_we_want ) ) ); |
|
| 1106 | - if( is_array( $id_col ) ) { |
|
| 1107 | - $QSG_ID = reset( $id_col ); |
|
| 1105 | + $id_col = EEM_Question_Group::instance()->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1106 | + if (is_array($id_col)) { |
|
| 1107 | + $QSG_ID = reset($id_col); |
|
| 1108 | 1108 | } else { |
| 1109 | 1109 | //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
| 1110 | 1110 | EE_Log::instance()->log( |
| 1111 | 1111 | __FILE__, |
| 1112 | 1112 | __FUNCTION__, |
| 1113 | 1113 | sprintf( |
| 1114 | - __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
| 1114 | + __('Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), |
|
| 1115 | 1115 | $QST_ID ), |
| 1116 | 1116 | 'error' ); |
| 1117 | 1117 | continue; |
@@ -1120,12 +1120,12 @@ discard block |
||
| 1120 | 1120 | |
| 1121 | 1121 | // add system questions to groups |
| 1122 | 1122 | $wpdb->insert( |
| 1123 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( 'esp_question_group_question' ), |
|
| 1124 | - array( 'QSG_ID' => $QSG_ID, |
|
| 1123 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1124 | + array('QSG_ID' => $QSG_ID, |
|
| 1125 | 1125 | 'QST_ID' => $QST_ID, |
| 1126 | - 'QGQ_order' => ( $QSG_ID === 1 ) ? $order_for_group_1++ : $order_for_group_2++ |
|
| 1126 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++ |
|
| 1127 | 1127 | ), |
| 1128 | - array( '%d', '%d', '%d' ) |
|
| 1128 | + array('%d', '%d', '%d') |
|
| 1129 | 1129 | ); |
| 1130 | 1130 | } |
| 1131 | 1131 | } |
@@ -1141,11 +1141,11 @@ discard block |
||
| 1141 | 1141 | * |
| 1142 | 1142 | * @throws \EE_Error |
| 1143 | 1143 | */ |
| 1144 | - public static function insert_default_payment_methods(){ |
|
| 1145 | - if( ! EEM_Payment_Method::instance()->count_active( EEM_Payment_Method::scope_cart ) ){ |
|
| 1146 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
| 1147 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( 'Invoice' ); |
|
| 1148 | - }else{ |
|
| 1144 | + public static function insert_default_payment_methods() { |
|
| 1145 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1146 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1147 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1148 | + } else { |
|
| 1149 | 1149 | EEM_Payment_Method::instance()->verify_button_urls(); |
| 1150 | 1150 | } |
| 1151 | 1151 | } |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | |
| 1162 | 1162 | global $wpdb; |
| 1163 | 1163 | |
| 1164 | - if ( \EEH_Activation::getTableAnalysis()->tableExists( EEM_Status::instance()->table() ) ) { |
|
| 1164 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1165 | 1165 | |
| 1166 | 1166 | $table_name = EEM_Status::instance()->table(); |
| 1167 | 1167 | |
@@ -1237,33 +1237,33 @@ discard block |
||
| 1237 | 1237 | $folders = array( |
| 1238 | 1238 | EVENT_ESPRESSO_TEMPLATE_DIR, |
| 1239 | 1239 | EVENT_ESPRESSO_GATEWAY_DIR, |
| 1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1242 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/' |
|
| 1240 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
| 1241 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
| 1242 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/' |
|
| 1243 | 1243 | ); |
| 1244 | - foreach ( $folders as $folder ) { |
|
| 1244 | + foreach ($folders as $folder) { |
|
| 1245 | 1245 | try { |
| 1246 | - EEH_File::ensure_folder_exists_and_is_writable( $folder ); |
|
| 1247 | - @ chmod( $folder, 0755 ); |
|
| 1248 | - } catch( EE_Error $e ){ |
|
| 1246 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1247 | + @ chmod($folder, 0755); |
|
| 1248 | + } catch (EE_Error $e) { |
|
| 1249 | 1249 | EE_Error::add_error( |
| 1250 | 1250 | sprintf( |
| 1251 | - __( 'Could not create the folder at "%1$s" because: %2$s', 'event_espresso' ), |
|
| 1251 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1252 | 1252 | $folder, |
| 1253 | - '<br />' . $e->getMessage() |
|
| 1253 | + '<br />'.$e->getMessage() |
|
| 1254 | 1254 | ), |
| 1255 | 1255 | __FILE__, __FUNCTION__, __LINE__ |
| 1256 | 1256 | ); |
| 1257 | 1257 | //indicate we'll need to fix this later |
| 1258 | - update_option( EEH_Activation::upload_directories_incomplete_option_name, true ); |
|
| 1258 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1259 | 1259 | return FALSE; |
| 1260 | 1260 | } |
| 1261 | 1261 | } |
| 1262 | 1262 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
| 1263 | 1263 | //is disabled, there might be activation errors recorded in there |
| 1264 | - EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs/' ); |
|
| 1264 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
| 1265 | 1265 | //remember EE's folders are all good |
| 1266 | - delete_option( EEH_Activation::upload_directories_incomplete_option_name ); |
|
| 1266 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1267 | 1267 | return TRUE; |
| 1268 | 1268 | } |
| 1269 | 1269 | |
@@ -1276,7 +1276,7 @@ discard block |
||
| 1276 | 1276 | * @return boolean |
| 1277 | 1277 | */ |
| 1278 | 1278 | public static function upload_directories_incomplete() { |
| 1279 | - return get_option( EEH_Activation::upload_directories_incomplete_option_name, false ); |
|
| 1279 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | |
@@ -1293,7 +1293,7 @@ discard block |
||
| 1293 | 1293 | */ |
| 1294 | 1294 | public static function generate_default_message_templates() { |
| 1295 | 1295 | /** @type EE_Message_Resource_Manager $message_resource_manager */ |
| 1296 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 1296 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1297 | 1297 | /* |
| 1298 | 1298 | * This first method is taking care of ensuring any default messengers |
| 1299 | 1299 | * that should be made active and have templates generated are done. |
@@ -1329,22 +1329,22 @@ discard block |
||
| 1329 | 1329 | $active_messengers = $message_resource_manager->active_messengers(); |
| 1330 | 1330 | $installed_message_types = $message_resource_manager->installed_message_types(); |
| 1331 | 1331 | $templates_created = false; |
| 1332 | - foreach ( $active_messengers as $active_messenger ) { |
|
| 1332 | + foreach ($active_messengers as $active_messenger) { |
|
| 1333 | 1333 | $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
| 1334 | 1334 | $default_message_type_names_to_activate = array(); |
| 1335 | 1335 | // looping through each default message type reported by the messenger |
| 1336 | 1336 | // and setup the actual message types to activate. |
| 1337 | - foreach ( $default_message_type_names_for_messenger as $default_message_type_name_for_messenger ) { |
|
| 1337 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1338 | 1338 | // if already active or has already been activated before we skip |
| 1339 | 1339 | // (otherwise we might reactivate something user's intentionally deactivated.) |
| 1340 | 1340 | // we also skip if the message type is not installed. |
| 1341 | 1341 | if ( |
| 1342 | - $message_resource_manager->has_message_type_been_activated_for_messenger( $default_message_type_name_for_messenger, $active_messenger->name ) |
|
| 1342 | + $message_resource_manager->has_message_type_been_activated_for_messenger($default_message_type_name_for_messenger, $active_messenger->name) |
|
| 1343 | 1343 | || $message_resource_manager->is_message_type_active_for_messenger( |
| 1344 | 1344 | $active_messenger->name, |
| 1345 | 1345 | $default_message_type_name_for_messenger |
| 1346 | 1346 | ) |
| 1347 | - || ! isset( $installed_message_types[ $default_message_type_name_for_messenger ] ) |
|
| 1347 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1348 | 1348 | ) { |
| 1349 | 1349 | continue; |
| 1350 | 1350 | } |
@@ -1357,7 +1357,7 @@ discard block |
||
| 1357 | 1357 | false |
| 1358 | 1358 | ); |
| 1359 | 1359 | //activate the templates for these message types |
| 1360 | - if ( ! empty( $default_message_type_names_to_activate ) ) { |
|
| 1360 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1361 | 1361 | $templates_created = EEH_MSG_Template::generate_new_templates( |
| 1362 | 1362 | $active_messenger->name, |
| 1363 | 1363 | $default_message_type_names_for_messenger, |
@@ -1384,18 +1384,18 @@ discard block |
||
| 1384 | 1384 | EE_Message_Resource_Manager $message_resource_manager |
| 1385 | 1385 | ) { |
| 1386 | 1386 | /** @type EE_messenger[] $messengers_to_generate */ |
| 1387 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation( $message_resource_manager ); |
|
| 1387 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1388 | 1388 | $installed_message_types = $message_resource_manager->installed_message_types(); |
| 1389 | 1389 | $templates_generated = false; |
| 1390 | - foreach ( $messengers_to_generate as $messenger_to_generate ) { |
|
| 1390 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1391 | 1391 | $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
| 1392 | 1392 | //verify the default message types match an installed message type. |
| 1393 | - foreach ( $default_message_type_names_for_messenger as $key => $name ) { |
|
| 1393 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1394 | 1394 | if ( |
| 1395 | - ! isset( $installed_message_types[ $name ] ) |
|
| 1396 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( $name, $messenger_to_generate->name ) |
|
| 1395 | + ! isset($installed_message_types[$name]) |
|
| 1396 | + || $message_resource_manager->has_message_type_been_activated_for_messenger($name, $messenger_to_generate->name) |
|
| 1397 | 1397 | ) { |
| 1398 | - unset( $default_message_type_names_for_messenger[ $key ] ); |
|
| 1398 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1399 | 1399 | } |
| 1400 | 1400 | } |
| 1401 | 1401 | // in previous iterations, the active_messengers option in the db |
@@ -1409,7 +1409,7 @@ discard block |
||
| 1409 | 1409 | false |
| 1410 | 1410 | ); |
| 1411 | 1411 | //create any templates needing created (or will reactivate templates already generated as necessary). |
| 1412 | - if ( ! empty( $default_message_type_names_for_messenger ) ) { |
|
| 1412 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1413 | 1413 | $templates_generated = EEH_MSG_Template::generate_new_templates( |
| 1414 | 1414 | $messenger_to_generate->name, |
| 1415 | 1415 | $default_message_type_names_for_messenger, |
@@ -1441,18 +1441,18 @@ discard block |
||
| 1441 | 1441 | $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
| 1442 | 1442 | |
| 1443 | 1443 | $messengers_to_generate = array(); |
| 1444 | - foreach ( $installed_messengers as $installed_messenger ) { |
|
| 1444 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1445 | 1445 | //if installed messenger is a messenger that should be activated on install |
| 1446 | 1446 | //and is not already active |
| 1447 | 1447 | //and has never been activated |
| 1448 | 1448 | if ( |
| 1449 | 1449 | ! $installed_messenger->activate_on_install |
| 1450 | - || isset( $active_messengers[ $installed_messenger->name ] ) |
|
| 1451 | - || isset( $has_activated[ $installed_messenger->name ] ) |
|
| 1450 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1451 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1452 | 1452 | ) { |
| 1453 | 1453 | continue; |
| 1454 | 1454 | } |
| 1455 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
| 1455 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1456 | 1456 | } |
| 1457 | 1457 | return $messengers_to_generate; |
| 1458 | 1458 | } |
@@ -1477,9 +1477,9 @@ discard block |
||
| 1477 | 1477 | */ |
| 1478 | 1478 | public static function validate_messages_system() { |
| 1479 | 1479 | /** @type EE_Message_Resource_Manager $message_resource_manager */ |
| 1480 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 1480 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1481 | 1481 | $message_resource_manager->validate_active_message_types_are_installed(); |
| 1482 | - do_action( 'AHEE__EEH_Activation__validate_messages_system' ); |
|
| 1482 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | |
@@ -1492,12 +1492,12 @@ discard block |
||
| 1492 | 1492 | * @static |
| 1493 | 1493 | * @return void |
| 1494 | 1494 | */ |
| 1495 | - public static function create_no_ticket_prices_array(){ |
|
| 1495 | + public static function create_no_ticket_prices_array() { |
|
| 1496 | 1496 | // this creates an array for tracking events that have no active ticket prices created |
| 1497 | 1497 | // this allows us to warn admins of the situation so that it can be corrected |
| 1498 | - $espresso_no_ticket_prices = get_option( 'ee_no_ticket_prices', FALSE ); |
|
| 1499 | - if ( ! $espresso_no_ticket_prices ) { |
|
| 1500 | - add_option( 'ee_no_ticket_prices', array(), '', FALSE ); |
|
| 1498 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', FALSE); |
|
| 1499 | + if ( ! $espresso_no_ticket_prices) { |
|
| 1500 | + add_option('ee_no_ticket_prices', array(), '', FALSE); |
|
| 1501 | 1501 | } |
| 1502 | 1502 | } |
| 1503 | 1503 | |
@@ -1522,24 +1522,24 @@ discard block |
||
| 1522 | 1522 | * @global wpdb $wpdb |
| 1523 | 1523 | * @throws \EE_Error |
| 1524 | 1524 | */ |
| 1525 | - public static function delete_all_espresso_cpt_data(){ |
|
| 1525 | + public static function delete_all_espresso_cpt_data() { |
|
| 1526 | 1526 | global $wpdb; |
| 1527 | 1527 | //get all the CPT post_types |
| 1528 | 1528 | $ee_post_types = array(); |
| 1529 | - foreach(EE_Registry::instance()->non_abstract_db_models as $model_name){ |
|
| 1530 | - if ( method_exists( $model_name, 'instance' )) { |
|
| 1531 | - $model_obj = call_user_func( array( $model_name, 'instance' )); |
|
| 1532 | - if ( $model_obj instanceof EEM_CPT_Base ) { |
|
| 1533 | - $ee_post_types[] = $wpdb->prepare("%s",$model_obj->post_type()); |
|
| 1529 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1530 | + if (method_exists($model_name, 'instance')) { |
|
| 1531 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1532 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1533 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | } |
| 1536 | 1536 | } |
| 1537 | 1537 | //get all our CPTs |
| 1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",",$ee_post_types).")"; |
|
| 1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
| 1539 | 1539 | $cpt_ids = $wpdb->get_col($query); |
| 1540 | 1540 | //delete each post meta and term relations too |
| 1541 | - foreach($cpt_ids as $post_id){ |
|
| 1542 | - wp_delete_post($post_id,true); |
|
| 1541 | + foreach ($cpt_ids as $post_id) { |
|
| 1542 | + wp_delete_post($post_id, true); |
|
| 1543 | 1543 | } |
| 1544 | 1544 | } |
| 1545 | 1545 | |
@@ -1551,12 +1551,12 @@ discard block |
||
| 1551 | 1551 | public static function drop_espresso_tables() { |
| 1552 | 1552 | $tables = array(); |
| 1553 | 1553 | // load registry |
| 1554 | - foreach( EE_Registry::instance()->non_abstract_db_models as $model_name ){ |
|
| 1555 | - if ( method_exists( $model_name, 'instance' )) { |
|
| 1556 | - $model_obj = call_user_func( array( $model_name, 'instance' )); |
|
| 1557 | - if ( $model_obj instanceof EEM_Base ) { |
|
| 1558 | - foreach ( $model_obj->get_tables() as $table ) { |
|
| 1559 | - if ( strpos( $table->get_table_name(), 'esp_' ) |
|
| 1554 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1555 | + if (method_exists($model_name, 'instance')) { |
|
| 1556 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1557 | + if ($model_obj instanceof EEM_Base) { |
|
| 1558 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1559 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1560 | 1560 | && |
| 1561 | 1561 | ( |
| 1562 | 1562 | is_main_site()//main site? nuke them all |
@@ -1579,10 +1579,10 @@ discard block |
||
| 1579 | 1579 | 'esp_promotion_rule', |
| 1580 | 1580 | 'esp_rule' |
| 1581 | 1581 | ); |
| 1582 | - foreach( $tables_without_models as $table ){ |
|
| 1582 | + foreach ($tables_without_models as $table) { |
|
| 1583 | 1583 | $tables[] = $table; |
| 1584 | 1584 | } |
| 1585 | - return \EEH_Activation::getTableManager()->dropTables( $tables ); |
|
| 1585 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1586 | 1586 | } |
| 1587 | 1587 | |
| 1588 | 1588 | /** |
@@ -1594,8 +1594,8 @@ discard block |
||
| 1594 | 1594 | * @param array $table_names |
| 1595 | 1595 | * @return array of table names which we deleted |
| 1596 | 1596 | */ |
| 1597 | - public static function drop_tables( $table_names ) { |
|
| 1598 | - return \EEH_Activation::getTableManager()->dropTables( $table_names ); |
|
| 1597 | + public static function drop_tables($table_names) { |
|
| 1598 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1599 | 1599 | } |
| 1600 | 1600 | /** |
| 1601 | 1601 | * plugin_uninstall |
@@ -1605,7 +1605,7 @@ discard block |
||
| 1605 | 1605 | * @param bool $remove_all |
| 1606 | 1606 | * @return void |
| 1607 | 1607 | */ |
| 1608 | - public static function delete_all_espresso_tables_and_data( $remove_all = true ) { |
|
| 1608 | + public static function delete_all_espresso_tables_and_data($remove_all = true) { |
|
| 1609 | 1609 | global $wpdb; |
| 1610 | 1610 | self::drop_espresso_tables(); |
| 1611 | 1611 | |
@@ -1643,50 +1643,50 @@ discard block |
||
| 1643 | 1643 | 'ee_job_parameters_' => false, |
| 1644 | 1644 | 'ee_upload_directories_incomplete' => true, |
| 1645 | 1645 | ); |
| 1646 | - if( is_main_site() ) { |
|
| 1647 | - $wp_options_to_delete[ 'ee_network_config' ] = true; |
|
| 1646 | + if (is_main_site()) { |
|
| 1647 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1648 | 1648 | } |
| 1649 | 1649 | |
| 1650 | 1650 | $undeleted_options = array(); |
| 1651 | - foreach ( $wp_options_to_delete as $option_name => $no_wildcard ) { |
|
| 1651 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1652 | 1652 | |
| 1653 | - if( $no_wildcard ){ |
|
| 1654 | - if( ! delete_option( $option_name ) ){ |
|
| 1653 | + if ($no_wildcard) { |
|
| 1654 | + if ( ! delete_option($option_name)) { |
|
| 1655 | 1655 | $undeleted_options[] = $option_name; |
| 1656 | 1656 | } |
| 1657 | - }else{ |
|
| 1658 | - $option_names_to_delete_from_wildcard = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'" ); |
|
| 1659 | - foreach($option_names_to_delete_from_wildcard as $option_name_from_wildcard ){ |
|
| 1660 | - if( ! delete_option( $option_name_from_wildcard ) ){ |
|
| 1657 | + } else { |
|
| 1658 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1659 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1660 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1661 | 1661 | $undeleted_options[] = $option_name_from_wildcard; |
| 1662 | 1662 | } |
| 1663 | 1663 | } |
| 1664 | 1664 | } |
| 1665 | 1665 | } |
| 1666 | 1666 | //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
| 1667 | - remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 ); |
|
| 1667 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1668 | 1668 | |
| 1669 | - if ( $remove_all && $espresso_db_update = get_option( 'espresso_db_update' )) { |
|
| 1669 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1670 | 1670 | $db_update_sans_ee4 = array(); |
| 1671 | - foreach($espresso_db_update as $version => $times_activated){ |
|
| 1672 | - if( (string)$version[0] === '3'){//if its NON EE4 |
|
| 1671 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1672 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
| 1673 | 1673 | $db_update_sans_ee4[$version] = $times_activated; |
| 1674 | 1674 | } |
| 1675 | 1675 | } |
| 1676 | - update_option( 'espresso_db_update', $db_update_sans_ee4 ); |
|
| 1676 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | 1679 | $errors = ''; |
| 1680 | - if ( ! empty( $undeleted_options )) { |
|
| 1680 | + if ( ! empty($undeleted_options)) { |
|
| 1681 | 1681 | $errors .= sprintf( |
| 1682 | - __( 'The following wp-options could not be deleted: %s%s', 'event_espresso' ), |
|
| 1682 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1683 | 1683 | '<br/>', |
| 1684 | - implode( ',<br/>', $undeleted_options ) |
|
| 1684 | + implode(',<br/>', $undeleted_options) |
|
| 1685 | 1685 | ); |
| 1686 | 1686 | |
| 1687 | 1687 | } |
| 1688 | - if ( ! empty( $errors ) ) { |
|
| 1689 | - EE_Error::add_attention( $errors, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1688 | + if ( ! empty($errors)) { |
|
| 1689 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | } |
| 1692 | 1692 | |
@@ -1696,10 +1696,10 @@ discard block |
||
| 1696 | 1696 | */ |
| 1697 | 1697 | public static function last_wpdb_error_code() { |
| 1698 | 1698 | global $wpdb; |
| 1699 | - if( $wpdb->use_mysqli ) { |
|
| 1700 | - return mysqli_errno( $wpdb->dbh ); |
|
| 1699 | + if ($wpdb->use_mysqli) { |
|
| 1700 | + return mysqli_errno($wpdb->dbh); |
|
| 1701 | 1701 | } else { |
| 1702 | - return mysql_errno( $wpdb->dbh ); |
|
| 1702 | + return mysql_errno($wpdb->dbh); |
|
| 1703 | 1703 | } |
| 1704 | 1704 | } |
| 1705 | 1705 | |
@@ -1710,14 +1710,14 @@ discard block |
||
| 1710 | 1710 | * @param string $table_name with or without $wpdb->prefix |
| 1711 | 1711 | * @return boolean |
| 1712 | 1712 | */ |
| 1713 | - public static function table_exists( $table_name ){ |
|
| 1714 | - return \EEH_Activation::getTableAnalysis()->tableExists( $table_name ); |
|
| 1713 | + public static function table_exists($table_name) { |
|
| 1714 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | /** |
| 1718 | 1718 | * Resets the cache on EEH_Activation |
| 1719 | 1719 | */ |
| 1720 | - public static function reset(){ |
|
| 1720 | + public static function reset() { |
|
| 1721 | 1721 | self::$_default_creator_id = NULL; |
| 1722 | 1722 | self::$_initialized_db_content_already_in_this_request = false; |
| 1723 | 1723 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | * @param string $table_name |
| 25 | 25 | * @return string $tableName, having ensured it has the wpdb prefix on the front |
| 26 | 26 | */ |
| 27 | - public function ensureTableNameHasPrefix( $table_name ) |
|
| 27 | + public function ensureTableNameHasPrefix($table_name) |
|
| 28 | 28 | { |
| 29 | 29 | global $wpdb; |
| 30 | - return strpos( $table_name, $wpdb->base_prefix ) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
| 30 | + return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix.$table_name; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | * @param $table_name |
| 37 | 37 | * @return bool |
| 38 | 38 | */ |
| 39 | - public function tableIsEmpty( $table_name ) |
|
| 39 | + public function tableIsEmpty($table_name) |
|
| 40 | 40 | { |
| 41 | 41 | global $wpdb; |
| 42 | - $table_name = $this->ensureTableNameHasPrefix( $table_name ); |
|
| 43 | - if ( $this->tableExists( $table_name ) ) { |
|
| 44 | - $count = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); |
|
| 45 | - return absint( $count ) === 0 ? true : false; |
|
| 42 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
| 43 | + if ($this->tableExists($table_name)) { |
|
| 44 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
| 45 | + return absint($count) === 0 ? true : false; |
|
| 46 | 46 | } |
| 47 | 47 | return false; |
| 48 | 48 | } |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * @param $table_name |
| 54 | 54 | * @return bool |
| 55 | 55 | */ |
| 56 | - public function tableExists( $table_name ) |
|
| 56 | + public function tableExists($table_name) |
|
| 57 | 57 | { |
| 58 | 58 | global $wpdb, $EZSQL_ERROR; |
| 59 | - $table_name = $this->ensureTableNameHasPrefix( $table_name ); |
|
| 59 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
| 60 | 60 | //ignore if this causes an sql error |
| 61 | 61 | $old_error = $wpdb->last_error; |
| 62 | 62 | $old_suppress_errors = $wpdb->suppress_errors(); |
| 63 | - $old_show_errors_value = $wpdb->show_errors( FALSE ); |
|
| 63 | + $old_show_errors_value = $wpdb->show_errors(FALSE); |
|
| 64 | 64 | $ezsql_error_cache = $EZSQL_ERROR; |
| 65 | - $wpdb->get_results( "SELECT * from $table_name LIMIT 1"); |
|
| 66 | - $wpdb->show_errors( $old_show_errors_value ); |
|
| 67 | - $wpdb->suppress_errors( $old_suppress_errors ); |
|
| 65 | + $wpdb->get_results("SELECT * from $table_name LIMIT 1"); |
|
| 66 | + $wpdb->show_errors($old_show_errors_value); |
|
| 67 | + $wpdb->suppress_errors($old_suppress_errors); |
|
| 68 | 68 | $new_error = $wpdb->last_error; |
| 69 | 69 | $wpdb->last_error = $old_error; |
| 70 | 70 | $EZSQL_ERROR = $ezsql_error_cache; |
| 71 | 71 | //if there was a table doesn't exist error |
| 72 | - if( ! empty( $new_error ) ) { |
|
| 73 | - if( |
|
| 72 | + if ( ! empty($new_error)) { |
|
| 73 | + if ( |
|
| 74 | 74 | in_array( |
| 75 | 75 | \EEH_Activation::last_wpdb_error_code(), |
| 76 | 76 | array( |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | ) |
| 81 | 81 | ) |
| 82 | 82 | || |
| 83 | - preg_match( '~^Table .* doesn\'t exist~', $new_error ) //in case not using mysql and error codes aren't reliable, just check for this error string |
|
| 83 | + preg_match('~^Table .* doesn\'t exist~', $new_error) //in case not using mysql and error codes aren't reliable, just check for this error string |
|
| 84 | 84 | ) { |
| 85 | 85 | return false; |
| 86 | 86 | } else { |
| 87 | 87 | //log this because that's weird. Just use the normal PHP error log |
| 88 | 88 | error_log( |
| 89 | 89 | sprintf( |
| 90 | - __( 'Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', 'event_espresso' ), |
|
| 90 | + __('Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', 'event_espresso'), |
|
| 91 | 91 | $new_error |
| 92 | 92 | ) |
| 93 | 93 | ); |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | * @param $class_file |
| 9 | 9 | * @return array |
| 10 | 10 | */ |
| 11 | -function espresso_invoice_template_files( $class_file) { |
|
| 11 | +function espresso_invoice_template_files($class_file) { |
|
| 12 | 12 | // read our template dir and build an array of files |
| 13 | - $dhandle = opendir(dirname($class_file) . '/lib/templates/css/'); //If the template files have been moved to the uploads folder |
|
| 13 | + $dhandle = opendir(dirname($class_file).'/lib/templates/css/'); //If the template files have been moved to the uploads folder |
|
| 14 | 14 | //} else return FALSE; |
| 15 | 15 | |
| 16 | 16 | $files = array(); |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | * @param string $selected |
| 51 | 51 | * @return string |
| 52 | 52 | */ |
| 53 | -function espresso_invoice_is_selected( $input_item, $selected='') { |
|
| 54 | - if ( $input_item === $selected ) { |
|
| 53 | +function espresso_invoice_is_selected($input_item, $selected = '') { |
|
| 54 | + if ($input_item === $selected) { |
|
| 55 | 55 | return 'selected="selected"'; |
| 56 | 56 | } else { |
| 57 | 57 | return ''; |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\services\database\TableAnalysis; |
| 3 | 3 | use EventEspresso\core\services\database\TableManager; |
| 4 | 4 | |
| 5 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { |
|
| 5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | 6 | exit('No direct script access allowed'); |
| 7 | 7 | } |
| 8 | 8 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | /** |
| 22 | 22 | */ |
| 23 | -class EE_DMS_Unknown_1_0_0 extends EE_Data_Migration_Script_Base{ |
|
| 23 | +class EE_DMS_Unknown_1_0_0 extends EE_Data_Migration_Script_Base { |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Returns whether or not this data migration script can operate on the given version of the database. |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | * @param TableManager $table_manager |
| 48 | 48 | * @param TableAnalysis $table_analysis |
| 49 | 49 | */ |
| 50 | - public function __construct( TableManager $table_manager = null, TableAnalysis $table_analysis = null ) { |
|
| 50 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) { |
|
| 51 | 51 | $this->_migration_stages = array(); |
| 52 | 52 | $this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso"); |
| 53 | 53 | // dd($this); |
| 54 | - parent::__construct( $table_manager, $table_analysis ); |
|
| 54 | + parent::__construct($table_manager, $table_analysis); |
|
| 55 | 55 | } |
| 56 | 56 | public function migration_page_hooks() { |
| 57 | 57 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * to indicate it successfully migrate some data, and has nothing left to do; or EE_Data_Migration_Manager::status_fatal_error to indicate |
| 25 | 25 | * an error occurred which means the ajax script should probably stop executing. |
| 26 | 26 | */ |
| 27 | -class EE_Data_Migration_Manager{ |
|
| 27 | +class EE_Data_Migration_Manager { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * of this EE installation. Keys should be the name of the version the script upgraded to |
| 82 | 82 | * @var EE_Data_Migration_Script_Base[] |
| 83 | 83 | */ |
| 84 | - private $_data_migrations_ran =null; |
|
| 84 | + private $_data_migrations_ran = null; |
|
| 85 | 85 | /** |
| 86 | 86 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
| 87 | 87 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public static function instance() { |
| 143 | 143 | // check if class object is instantiated |
| 144 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
| 144 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 145 | 145 | self::$_instance = new self(); |
| 146 | 146 | } |
| 147 | 147 | return self::$_instance; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
| 152 | 152 | * @return EE_Data_Migration_Manager |
| 153 | 153 | */ |
| 154 | - public static function reset(){ |
|
| 154 | + public static function reset() { |
|
| 155 | 155 | self::$_instance = NULL; |
| 156 | 156 | return self::instance(); |
| 157 | 157 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | /** |
| 162 | 162 | * constructor |
| 163 | 163 | */ |
| 164 | - private function __construct(){ |
|
| 164 | + private function __construct() { |
|
| 165 | 165 | $this->stati_that_indicate_to_continue_migrations = array( |
| 166 | 166 | self::status_continue, |
| 167 | 167 | self::status_completed |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | ); |
| 181 | 181 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
| 182 | 182 | //to be defined, because right now it doesn't get autoloaded on its own |
| 183 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
| 184 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
| 185 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
| 186 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
| 187 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
| 188 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
| 189 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
| 183 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
| 184 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
| 185 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
| 186 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
| 187 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
| 188 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 189 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | |
@@ -199,21 +199,21 @@ discard block |
||
| 199 | 199 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
| 200 | 200 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
| 201 | 201 | */ |
| 202 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
| 202 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
| 203 | 203 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
| 204 | 204 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
| 205 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
| 205 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
| 206 | 206 | |
| 207 | - if(count($parts) == 4){ |
|
| 207 | + if (count($parts) == 4) { |
|
| 208 | 208 | //it's 4.2-style.eg Core.4.1.0 |
| 209 | - $plugin_slug = $parts[0];//eg Core |
|
| 209 | + $plugin_slug = $parts[0]; //eg Core |
|
| 210 | 210 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
| 211 | - }else{ |
|
| 211 | + } else { |
|
| 212 | 212 | //it's 4.1-style: eg 4.1.0 |
| 213 | 213 | $plugin_slug = 'Core'; |
| 214 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
| 214 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
| 215 | 215 | } |
| 216 | - return array($plugin_slug,$version_string); |
|
| 216 | + return array($plugin_slug, $version_string); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -224,21 +224,21 @@ discard block |
||
| 224 | 224 | * @return EE_Data_Migration_Script_Base |
| 225 | 225 | * @throws EE_Error |
| 226 | 226 | */ |
| 227 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
| 227 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
| 228 | 228 | $data_migration_data = maybe_unserialize($dms_option_value); |
| 229 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
| 229 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
| 230 | 230 | $class = new $data_migration_data['class']; |
| 231 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
| 231 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
| 232 | 232 | $class->instantiate_from_array_of_properties($data_migration_data); |
| 233 | 233 | return $class; |
| 234 | - }else{ |
|
| 234 | + } else { |
|
| 235 | 235 | //huh, so its an object but not a data migration script?? that shouldn't happen |
| 236 | 236 | //just leave it as an array (which will probably just get ignored) |
| 237 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
| 237 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
| 238 | 238 | } |
| 239 | - }else{ |
|
| 239 | + } else { |
|
| 240 | 240 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
| 241 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
| 241 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | /** |
@@ -246,34 +246,34 @@ discard block |
||
| 246 | 246 | * the last ran which hasn't finished yet |
| 247 | 247 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
| 248 | 248 | */ |
| 249 | - public function get_data_migrations_ran(){ |
|
| 250 | - if( ! $this->_data_migrations_ran ){ |
|
| 249 | + public function get_data_migrations_ran() { |
|
| 250 | + if ( ! $this->_data_migrations_ran) { |
|
| 251 | 251 | //setup autoloaders for each of the scripts in there |
| 252 | 252 | $this->get_all_data_migration_scripts_available(); |
| 253 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 253 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 254 | 254 | |
| 255 | 255 | $data_migrations_ran = array(); |
| 256 | 256 | //convert into data migration script classes where possible |
| 257 | - foreach($data_migrations_options as $data_migration_option){ |
|
| 258 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 257 | + foreach ($data_migrations_options as $data_migration_option) { |
|
| 258 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 259 | 259 | |
| 260 | - try{ |
|
| 261 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
| 260 | + try { |
|
| 261 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
| 262 | 262 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
| 263 | 263 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
| 264 | 264 | $this->_last_ran_script = $class; |
| 265 | - if( ! $class->is_completed()){ |
|
| 265 | + if ( ! $class->is_completed()) { |
|
| 266 | 266 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
| 267 | 267 | $this->_last_ran_incomplete_script = $class; |
| 268 | 268 | } |
| 269 | - }catch(EE_Error $e){ |
|
| 269 | + } catch (EE_Error $e) { |
|
| 270 | 270 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
| 271 | 271 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
| 275 | 275 | $this->_data_migrations_ran = $data_migrations_ran; |
| 276 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
| 276 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 277 | 277 | $this->_data_migrations_ran = array(); |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param $new_table |
| 291 | 291 | * @return mixed string or int |
| 292 | 292 | */ |
| 293 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
| 293 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
| 294 | 294 | $script = EE_Registry::instance()->load_dms($script_name); |
| 295 | 295 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
| 296 | 296 | return $mapping; |
@@ -301,9 +301,9 @@ discard block |
||
| 301 | 301 | * option returned in this array is the most-recently ran DMS option |
| 302 | 302 | * @return array |
| 303 | 303 | */ |
| 304 | - public function get_all_migration_script_options(){ |
|
| 304 | + public function get_all_migration_script_options() { |
|
| 305 | 305 | global $wpdb; |
| 306 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
| 306 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
| 312 | 312 | * folder name. |
| 313 | 313 | */ |
| 314 | - public function get_data_migration_script_folders(){ |
|
| 315 | - return apply_filters( 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',array(EE_CORE.'data_migration_scripts') ); |
|
| 314 | + public function get_data_migration_script_folders() { |
|
| 315 | + return apply_filters('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', array(EE_CORE.'data_migration_scripts')); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | * } |
| 325 | 325 | * @throws EE_Error |
| 326 | 326 | */ |
| 327 | - public function script_migrates_to_version($migration_script_name){ |
|
| 327 | + public function script_migrates_to_version($migration_script_name) { |
|
| 328 | 328 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 329 | 329 | return array( |
| 330 | - 'slug'=> $dms_info[ 'slug' ], |
|
| 331 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] ); |
|
| 330 | + 'slug'=> $dms_info['slug'], |
|
| 331 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -337,13 +337,13 @@ discard block |
||
| 337 | 337 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
| 338 | 338 | * @throws EE_Error |
| 339 | 339 | */ |
| 340 | - public function parse_dms_classname($classname){ |
|
| 340 | + public function parse_dms_classname($classname) { |
|
| 341 | 341 | $matches = array(); |
| 342 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
| 343 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
| 344 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
| 342 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
| 343 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 344 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
| 345 | 345 | } |
| 346 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
| 346 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
| 347 | 347 | } |
| 348 | 348 | /** |
| 349 | 349 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -352,33 +352,33 @@ discard block |
||
| 352 | 352 | * to 4.1.x. |
| 353 | 353 | * @return string of current db state |
| 354 | 354 | */ |
| 355 | - public function ensure_current_database_state_is_set(){ |
|
| 356 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
| 355 | + public function ensure_current_database_state_is_set() { |
|
| 356 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
| 357 | 357 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
| 358 | - if( ! $db_state ){ |
|
| 358 | + if ( ! $db_state) { |
|
| 359 | 359 | //mark the DB as being in the state as the last version in there. |
| 360 | 360 | //this is done to trigger maintenance mode and do data migration scripts |
| 361 | 361 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
| 362 | 362 | //otherwise, the normal maintenance mode code is fine |
| 363 | 363 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
| 364 | 364 | $previous_version_installed = end($previous_versions_installed); |
| 365 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
| 365 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
| 366 | 366 | //last installed version was less than 4.1 |
| 367 | 367 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
| 368 | 368 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
| 369 | 369 | $db_state = array('Core'=>$previous_version_installed); |
| 370 | - }else{ |
|
| 370 | + } else { |
|
| 371 | 371 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
| 372 | 372 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
| 373 | 373 | } |
| 374 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 374 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 375 | 375 | } |
| 376 | 376 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
| 377 | 377 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
| 378 | 378 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
| 379 | - if( ! is_array($db_state)){ |
|
| 379 | + if ( ! is_array($db_state)) { |
|
| 380 | 380 | $db_state = array('Core'=>$db_state); |
| 381 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 381 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 382 | 382 | } |
| 383 | 383 | return $db_state; |
| 384 | 384 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * or they don't apply), returns an empty array |
| 390 | 390 | * @return EE_Data_Migration_Script_Base[] |
| 391 | 391 | */ |
| 392 | - public function check_for_applicable_data_migration_scripts(){ |
|
| 392 | + public function check_for_applicable_data_migration_scripts() { |
|
| 393 | 393 | //get the option describing what options have already run |
| 394 | 394 | $scripts_ran = $this->get_data_migrations_ran(); |
| 395 | 395 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -402,62 +402,62 @@ discard block |
||
| 402 | 402 | $iteration = 0; |
| 403 | 403 | $next_database_state_to_consider = $current_database_state; |
| 404 | 404 | $theoretical_database_state = NULL; |
| 405 | - do{ |
|
| 405 | + do { |
|
| 406 | 406 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
| 407 | 407 | $theoretical_database_state = $next_database_state_to_consider; |
| 408 | 408 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
| 409 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
| 409 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
| 410 | 410 | |
| 411 | 411 | $migrates_to_version = $this->script_migrates_to_version($classname); |
| 412 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
| 413 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
| 412 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
| 413 | + $script_converts_to_version = $migrates_to_version['version']; |
|
| 414 | 414 | //check if this version script is DONE or not; or if it's never been ran |
| 415 | - if( ! $scripts_ran || |
|
| 415 | + if ( ! $scripts_ran || |
|
| 416 | 416 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
| 417 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
| 417 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
| 418 | 418 | //we haven't ran this conversion script before |
| 419 | 419 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
| 420 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
| 420 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
| 421 | 421 | /* @var $script EE_Data_Migration_Script_Base */ |
| 422 | 422 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
| 423 | - if($can_migrate){ |
|
| 423 | + if ($can_migrate) { |
|
| 424 | 424 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 425 | 425 | $migrates_to_version = $script->migrates_to_version(); |
| 426 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 426 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 427 | 427 | unset($script_class_and_filepaths_available[$classname]); |
| 428 | 428 | } |
| 429 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
| 429 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
| 430 | 430 | //this script has been ran, or at least started |
| 431 | 431 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
| 432 | - if( $script->get_status() != self::status_completed){ |
|
| 432 | + if ($script->get_status() != self::status_completed) { |
|
| 433 | 433 | //this script is already underway... keep going with it |
| 434 | 434 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 435 | 435 | $migrates_to_version = $script->migrates_to_version(); |
| 436 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 436 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 437 | 437 | unset($script_class_and_filepaths_available[$classname]); |
| 438 | - }else{ |
|
| 438 | + } else { |
|
| 439 | 439 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
| 440 | 440 | } |
| 441 | - }else{ |
|
| 441 | + } else { |
|
| 442 | 442 | //it exists but it's not a proper data migration script |
| 443 | 443 | //maybe the script got renamed? or was simply removed from EE? |
| 444 | 444 | //either way, its certainly not runnable! |
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | $iteration++; |
| 448 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
| 448 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
| 449 | 449 | //ok we have all the scripts that should run, now let's make them into flat array |
| 450 | 450 | $scripts_that_should_run = array(); |
| 451 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
| 451 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
| 452 | 452 | ksort($scripts_at_priority); |
| 453 | - foreach($scripts_at_priority as $scripts){ |
|
| 454 | - foreach($scripts as $script){ |
|
| 453 | + foreach ($scripts_at_priority as $scripts) { |
|
| 454 | + foreach ($scripts as $script) { |
|
| 455 | 455 | $scripts_that_should_run[get_class($script)] = $script; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
| 460 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
| 461 | 461 | return $scripts_that_should_run; |
| 462 | 462 | } |
| 463 | 463 | |
@@ -471,14 +471,14 @@ discard block |
||
| 471 | 471 | * @param bool $include_completed_scripts |
| 472 | 472 | * @return EE_Data_Migration_Script_Base |
| 473 | 473 | */ |
| 474 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
| 474 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
| 475 | 475 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
| 476 | - if( ! $this->_data_migrations_ran){ |
|
| 476 | + if ( ! $this->_data_migrations_ran) { |
|
| 477 | 477 | $this->get_data_migrations_ran(); |
| 478 | 478 | } |
| 479 | - if($include_completed_scripts){ |
|
| 479 | + if ($include_completed_scripts) { |
|
| 480 | 480 | return $this->_last_ran_script; |
| 481 | - }else{ |
|
| 481 | + } else { |
|
| 482 | 482 | return $this->_last_ran_incomplete_script; |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -501,19 +501,19 @@ discard block |
||
| 501 | 501 | * @type string $message string describing what was done during this step |
| 502 | 502 | * } |
| 503 | 503 | */ |
| 504 | - public function migration_step( $step_size = 0 ){ |
|
| 504 | + public function migration_step($step_size = 0) { |
|
| 505 | 505 | |
| 506 | 506 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
| 507 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
| 508 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
| 507 | + if (class_exists('EE_CPT_Strategy')) { |
|
| 508 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - try{ |
|
| 511 | + try { |
|
| 512 | 512 | $currently_executing_script = $this->get_last_ran_script(); |
| 513 | - if( ! $currently_executing_script){ |
|
| 513 | + if ( ! $currently_executing_script) { |
|
| 514 | 514 | //Find the next script that needs to execute |
| 515 | 515 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
| 516 | - if( ! $scripts ){ |
|
| 516 | + if ( ! $scripts) { |
|
| 517 | 517 | //huh, no more scripts to run... apparently we're done! |
| 518 | 518 | //but dont forget to make sure initial data is there |
| 519 | 519 | //we should be good to allow them to exit maintenance mode now |
@@ -534,18 +534,18 @@ discard block |
||
| 534 | 534 | //and add to the array/wp option showing the scripts ran |
| 535 | 535 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
| 536 | 536 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
| 537 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
| 538 | - $version = $migrates_to[ 'version' ]; |
|
| 537 | + $plugin_slug = $migrates_to['slug']; |
|
| 538 | + $version = $migrates_to['version']; |
|
| 539 | 539 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
| 540 | 540 | } |
| 541 | 541 | $current_script_name = get_class($currently_executing_script); |
| 542 | - }catch(Exception $e){ |
|
| 542 | + } catch (Exception $e) { |
|
| 543 | 543 | //an exception occurred while trying to get migration scripts |
| 544 | 544 | |
| 545 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
| 545 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
| 546 | 546 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
| 547 | 547 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
| 548 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
| 548 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
| 549 | 549 | return array( |
| 550 | 550 | 'records_to_migrate'=>1, |
| 551 | 551 | 'records_migrated'=>0, |
@@ -555,16 +555,16 @@ discard block |
||
| 555 | 555 | ); |
| 556 | 556 | } |
| 557 | 557 | //ok so we definitely have a data migration script |
| 558 | - try{ |
|
| 558 | + try { |
|
| 559 | 559 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
| 560 | - if( ! absint( $step_size ) > 0 ){ |
|
| 561 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 560 | + if ( ! absint($step_size) > 0) { |
|
| 561 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 562 | 562 | } |
| 563 | 563 | //do what we came to do! |
| 564 | 564 | $currently_executing_script->migration_step($step_size); |
| 565 | 565 | //can we wrap it up and verify default data? |
| 566 | 566 | $init_dbs = false; |
| 567 | - switch($currently_executing_script->get_status()){ |
|
| 567 | + switch ($currently_executing_script->get_status()) { |
|
| 568 | 568 | case EE_Data_Migration_Manager::status_continue: |
| 569 | 569 | $response_array = array( |
| 570 | 570 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -576,16 +576,16 @@ discard block |
||
| 576 | 576 | case EE_Data_Migration_Manager::status_completed: |
| 577 | 577 | //ok so THAT script has completed |
| 578 | 578 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
| 579 | - $response_array = array( |
|
| 579 | + $response_array = array( |
|
| 580 | 580 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 581 | 581 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 582 | 582 | 'status'=> EE_Data_Migration_Manager::status_completed, |
| 583 | 583 | 'message'=>$currently_executing_script->get_feedback_message(), |
| 584 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
| 584 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
| 585 | 585 | ); |
| 586 | 586 | //check if there are any more after this one. |
| 587 | 587 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
| 588 | - if( ! $scripts_remaining ){ |
|
| 588 | + if ( ! $scripts_remaining) { |
|
| 589 | 589 | //we should be good to allow them to exit maintenance mode now |
| 590 | 590 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
| 591 | 591 | ////huh, no more scripts to run... apparently we're done! |
@@ -599,39 +599,39 @@ discard block |
||
| 599 | 599 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 600 | 600 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 601 | 601 | 'status'=> $currently_executing_script->get_status(), |
| 602 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
| 602 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
| 603 | 603 | 'script'=>$currently_executing_script->pretty_name() |
| 604 | 604 | ); |
| 605 | 605 | break; |
| 606 | 606 | } |
| 607 | - }catch(Exception $e){ |
|
| 607 | + } catch (Exception $e) { |
|
| 608 | 608 | //ok so some exception was thrown which killed the data migration script |
| 609 | 609 | //double-check we have a real script |
| 610 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
| 610 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
| 611 | 611 | $script_name = $currently_executing_script->pretty_name(); |
| 612 | 612 | $currently_executing_script->set_broken(); |
| 613 | 613 | $currently_executing_script->add_error($e->getMessage()); |
| 614 | - }else{ |
|
| 614 | + } else { |
|
| 615 | 615 | $script_name = __("Error getting Migration Script", "event_espresso"); |
| 616 | 616 | } |
| 617 | 617 | $response_array = array( |
| 618 | 618 | 'records_to_migrate'=>1, |
| 619 | 619 | 'records_migrated'=>0, |
| 620 | 620 | 'status'=>self::status_fatal_error, |
| 621 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
| 621 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
| 622 | 622 | 'script'=>$script_name |
| 623 | 623 | ); |
| 624 | 624 | } |
| 625 | 625 | $successful_save = $this->_save_migrations_ran(); |
| 626 | - if($successful_save !== TRUE){ |
|
| 626 | + if ($successful_save !== TRUE) { |
|
| 627 | 627 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
| 628 | 628 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
| 629 | 629 | //however, if we throw an exception, and return that, then the next request |
| 630 | 630 | //won't have as much info in it, and it may be able to save |
| 631 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
| 631 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
| 632 | 632 | } |
| 633 | 633 | //if we're all done, initialize EE plugins' default data etc. |
| 634 | - if( $init_dbs ) { |
|
| 634 | + if ($init_dbs) { |
|
| 635 | 635 | $this->initialize_db_for_enqueued_ee_plugins(); |
| 636 | 636 | } |
| 637 | 637 | return $response_array; |
@@ -649,23 +649,23 @@ discard block |
||
| 649 | 649 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
| 650 | 650 | * 'script'=>a pretty name of the script currently running |
| 651 | 651 | */ |
| 652 | - public function response_to_migration_ajax_request(){ |
|
| 652 | + public function response_to_migration_ajax_request() { |
|
| 653 | 653 | // //start output buffer just to make sure we don't mess up the json |
| 654 | 654 | ob_start(); |
| 655 | - try{ |
|
| 655 | + try { |
|
| 656 | 656 | $response = $this->migration_step(); |
| 657 | - }catch(Exception $e){ |
|
| 657 | + } catch (Exception $e) { |
|
| 658 | 658 | $response = array( |
| 659 | 659 | 'records_to_migrate'=>0, |
| 660 | 660 | 'records_migrated'=>0, |
| 661 | 661 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
| 662 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
| 662 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
| 663 | 663 | 'script'=>'Unknown'); |
| 664 | 664 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
| 665 | 665 | } |
| 666 | 666 | $warnings_etc = @ob_get_contents(); |
| 667 | 667 | ob_end_clean(); |
| 668 | - $response['message'] .=$warnings_etc; |
|
| 668 | + $response['message'] .= $warnings_etc; |
|
| 669 | 669 | return $response; |
| 670 | 670 | } |
| 671 | 671 | |
@@ -678,14 +678,14 @@ discard block |
||
| 678 | 678 | * } |
| 679 | 679 | * @return void |
| 680 | 680 | */ |
| 681 | - public function update_current_database_state_to($slug_and_version = null){ |
|
| 682 | - if( ! $slug_and_version ){ |
|
| 681 | + public function update_current_database_state_to($slug_and_version = null) { |
|
| 682 | + if ( ! $slug_and_version) { |
|
| 683 | 683 | //no version was provided, assume it should be at the current code version |
| 684 | 684 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
| 685 | 685 | } |
| 686 | 686 | $current_database_state = get_option(self::current_database_state); |
| 687 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
| 688 | - update_option(self::current_database_state,$current_database_state); |
|
| 687 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
| 688 | + update_option(self::current_database_state, $current_database_state); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -696,20 +696,20 @@ discard block |
||
| 696 | 696 | * } |
| 697 | 697 | * @return boolean |
| 698 | 698 | */ |
| 699 | - public function database_needs_updating_to( $slug_and_version ) { |
|
| 699 | + public function database_needs_updating_to($slug_and_version) { |
|
| 700 | 700 | |
| 701 | - $slug = $slug_and_version[ 'slug' ]; |
|
| 702 | - $version = $slug_and_version[ 'version' ]; |
|
| 701 | + $slug = $slug_and_version['slug']; |
|
| 702 | + $version = $slug_and_version['version']; |
|
| 703 | 703 | $current_database_state = get_option(self::current_database_state); |
| 704 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
| 704 | + if ( ! isset($current_database_state[$slug])) { |
|
| 705 | 705 | return true; |
| 706 | - }else{ |
|
| 706 | + } else { |
|
| 707 | 707 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
| 708 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
| 709 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
| 708 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
| 709 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
| 710 | 710 | $needs_updating = false; |
| 711 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
| 712 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
| 711 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
| 712 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
| 713 | 713 | $needs_updating = true; |
| 714 | 714 | break; |
| 715 | 715 | } |
@@ -723,29 +723,29 @@ discard block |
||
| 723 | 723 | * in addons. Has the side effect of adding them for autoloading |
| 724 | 724 | * @return array keys are expected classnames, values are their filepaths |
| 725 | 725 | */ |
| 726 | - public function get_all_data_migration_scripts_available(){ |
|
| 727 | - if( ! $this->_data_migration_class_to_filepath_map){ |
|
| 726 | + public function get_all_data_migration_scripts_available() { |
|
| 727 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
| 728 | 728 | $this->_data_migration_class_to_filepath_map = array(); |
| 729 | - foreach($this->get_data_migration_script_folders() as $folder_path){ |
|
| 730 | - if($folder_path[count($folder_path-1)] != DS ){ |
|
| 731 | - $folder_path.= DS; |
|
| 729 | + foreach ($this->get_data_migration_script_folders() as $folder_path) { |
|
| 730 | + if ($folder_path[count($folder_path - 1)] != DS) { |
|
| 731 | + $folder_path .= DS; |
|
| 732 | 732 | } |
| 733 | - $files = glob( $folder_path. '*.dms.php' ); |
|
| 733 | + $files = glob($folder_path.'*.dms.php'); |
|
| 734 | 734 | |
| 735 | - if ( empty( $files ) ) { |
|
| 735 | + if (empty($files)) { |
|
| 736 | 736 | continue; |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - foreach($files as $file){ |
|
| 740 | - $pos_of_last_slash = strrpos($file,DS); |
|
| 741 | - $classname = str_replace(".dms.php","", substr($file, $pos_of_last_slash+1)); |
|
| 742 | - $migrates_to = $this->script_migrates_to_version( $classname ); |
|
| 743 | - $slug = $migrates_to[ 'slug' ]; |
|
| 739 | + foreach ($files as $file) { |
|
| 740 | + $pos_of_last_slash = strrpos($file, DS); |
|
| 741 | + $classname = str_replace(".dms.php", "", substr($file, $pos_of_last_slash + 1)); |
|
| 742 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
| 743 | + $slug = $migrates_to['slug']; |
|
| 744 | 744 | //check that the slug as contained in the DMS is associated with |
| 745 | 745 | //the slug of an addon or core |
| 746 | - if( $slug != 'Core' ){ |
|
| 747 | - if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) { |
|
| 748 | - EE_Error::doing_it_wrong(__FUNCTION__, sprintf( __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ),$classname,$slug,implode(",", array_keys( EE_Registry::instance()->get_addons_by_name() ) ) ), '4.3.0.alpha.019' ); |
|
| 746 | + if ($slug != 'Core') { |
|
| 747 | + if ( ! EE_Registry::instance()->get_addon_by_name($slug)) { |
|
| 748 | + EE_Error::doing_it_wrong(__FUNCTION__, sprintf(__('The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso'), $classname, $slug, implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))), '4.3.0.alpha.019'); |
|
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | $this->_data_migration_class_to_filepath_map[$classname] = $file; |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | * from each addon, and check if they need updating, |
| 766 | 766 | * @return boolean |
| 767 | 767 | */ |
| 768 | - public function addons_need_updating(){ |
|
| 768 | + public function addons_need_updating() { |
|
| 769 | 769 | return false; |
| 770 | 770 | } |
| 771 | 771 | /** |
@@ -774,25 +774,25 @@ discard block |
||
| 774 | 774 | * @param string $error_message |
| 775 | 775 | * @throws EE_Error |
| 776 | 776 | */ |
| 777 | - public function add_error_to_migrations_ran($error_message){ |
|
| 777 | + public function add_error_to_migrations_ran($error_message) { |
|
| 778 | 778 | //get last-ran migration script |
| 779 | 779 | global $wpdb; |
| 780 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
| 780 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
| 781 | 781 | |
| 782 | 782 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
| 783 | 783 | //now, tread lightly because we're here because a FATAL non-catchable error |
| 784 | 784 | //was thrown last time when we were trying to run a data migration script |
| 785 | 785 | //so the fatal error could have happened while getting the migration script |
| 786 | 786 | //or doing running it... |
| 787 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
| 787 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
| 788 | 788 | |
| 789 | 789 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
| 790 | 790 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
| 791 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
| 791 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
| 792 | 792 | //ok then just add this error to its list of errors |
| 793 | 793 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
| 794 | 794 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
| 795 | - }else{ |
|
| 795 | + } else { |
|
| 796 | 796 | //so we don't even know which script was last running |
| 797 | 797 | //use the data migration error stub, which is designed specifically for this type of thing |
| 798 | 798 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -802,39 +802,39 @@ discard block |
||
| 802 | 802 | $versions_migrated_to = 'Unknown.1.0.0'; |
| 803 | 803 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
| 804 | 804 | //delete the old one |
| 805 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
| 805 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
| 806 | 806 | } |
| 807 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
| 807 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
| 808 | 808 | |
| 809 | 809 | } |
| 810 | 810 | /** |
| 811 | 811 | * saves what data migrations have ran to the database |
| 812 | 812 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
| 813 | 813 | */ |
| 814 | - protected function _save_migrations_ran(){ |
|
| 815 | - if($this->_data_migrations_ran == null){ |
|
| 814 | + protected function _save_migrations_ran() { |
|
| 815 | + if ($this->_data_migrations_ran == null) { |
|
| 816 | 816 | $this->get_data_migrations_ran(); |
| 817 | 817 | } |
| 818 | 818 | //now, we don't want to save actual classes to the DB because that's messy |
| 819 | 819 | $successful_updates = true; |
| 820 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
| 821 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
| 820 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
| 821 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
| 822 | 822 | // echo "saving migration script to $version_string<br>"; |
| 823 | 823 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
| 824 | 824 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
| 825 | 825 | $old_option_value = get_option($option_name); |
| 826 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
| 826 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
| 827 | 827 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
| 828 | - if( $old_option_value != $script_array_for_saving){ |
|
| 829 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
| 828 | + if ($old_option_value != $script_array_for_saving) { |
|
| 829 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
| 830 | 830 | } |
| 831 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
| 831 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
| 832 | 832 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
| 833 | - if($old_option_value != $array_or_migration_obj){ |
|
| 834 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
| 833 | + if ($old_option_value != $array_or_migration_obj) { |
|
| 834 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
| 835 | 835 | } |
| 836 | 836 | } |
| 837 | - if( ! $successful_updates ){ |
|
| 837 | + if ( ! $successful_updates) { |
|
| 838 | 838 | global $wpdb; |
| 839 | 839 | return $wpdb->last_error; |
| 840 | 840 | } |
@@ -858,17 +858,17 @@ discard block |
||
| 858 | 858 | * @return EE_Data_Migration_Script_Base |
| 859 | 859 | * @throws EE_Error |
| 860 | 860 | */ |
| 861 | - function _instantiate_script_from_properties_array($properties_array){ |
|
| 862 | - if( ! isset($properties_array['class'])){ |
|
| 863 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
| 861 | + function _instantiate_script_from_properties_array($properties_array) { |
|
| 862 | + if ( ! isset($properties_array['class'])) { |
|
| 863 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
| 864 | 864 | } |
| 865 | 865 | $class_name = $properties_array['class']; |
| 866 | - if( ! class_exists($class_name)){ |
|
| 867 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
| 866 | + if ( ! class_exists($class_name)) { |
|
| 867 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
| 868 | 868 | } |
| 869 | 869 | $class = new $class_name; |
| 870 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
| 871 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
| 870 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 871 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
| 872 | 872 | } |
| 873 | 873 | $class->instantiate_from_array_of_properties($properties_array); |
| 874 | 874 | return $class; |
@@ -880,25 +880,25 @@ discard block |
||
| 880 | 880 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
| 881 | 881 | * @return string |
| 882 | 882 | */ |
| 883 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
| 883 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
| 884 | 884 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
| 885 | 885 | $most_up_to_date_dms_classname = NULL; |
| 886 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
| 887 | - if($most_up_to_date_dms_classname === NULL){ |
|
| 886 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
| 887 | + if ($most_up_to_date_dms_classname === NULL) { |
|
| 888 | 888 | $migrates_to = $this->script_migrates_to_version($classname); |
| 889 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
| 889 | + $this_plugin_slug = $migrates_to['slug']; |
|
| 890 | 890 | // $version_string = $migrates_to[ 'version' ]; |
| 891 | 891 | // $details = $this->parse_dms_classname($classname); |
| 892 | - if($this_plugin_slug == $plugin_slug){ |
|
| 892 | + if ($this_plugin_slug == $plugin_slug) { |
|
| 893 | 893 | //if it's for core, it wins |
| 894 | 894 | $most_up_to_date_dms_classname = $classname; |
| 895 | 895 | } |
| 896 | 896 | //if it wasn't for core, we must keep searching for one that is! |
| 897 | 897 | continue; |
| 898 | - }else{ |
|
| 899 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 898 | + } else { |
|
| 899 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 900 | 900 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
| 901 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
| 901 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
| 902 | 902 | //so the contenders version is higher and its for Core |
| 903 | 903 | $most_up_to_date_dms_classname = $classname; |
| 904 | 904 | } |
@@ -918,11 +918,11 @@ discard block |
||
| 918 | 918 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 919 | 919 | * @return EE_Data_Migration_Script_Base |
| 920 | 920 | */ |
| 921 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
| 921 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
| 922 | 922 | $migrations_ran = $this->get_data_migrations_ran(); |
| 923 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
| 924 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 925 | - }else{ |
|
| 923 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
| 924 | + return $migrations_ran[$plugin_slug][$version]; |
|
| 925 | + } else { |
|
| 926 | 926 | return NULL; |
| 927 | 927 | } |
| 928 | 928 | } |
@@ -934,20 +934,20 @@ discard block |
||
| 934 | 934 | * @return bool |
| 935 | 935 | * @throws \EE_Error |
| 936 | 936 | */ |
| 937 | - public function reattempt(){ |
|
| 937 | + public function reattempt() { |
|
| 938 | 938 | //find if the last-ran script was borked |
| 939 | 939 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
| 940 | 940 | //add an 'error' saying that we attempted to reset |
| 941 | 941 | //does it have a stage that was borked too? if so make it no longer borked |
| 942 | 942 | //add an 'error' saying we attempted to reset |
| 943 | 943 | $last_ran_script = $this->get_last_ran_script(); |
| 944 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
| 944 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
| 945 | 945 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
| 946 | 946 | $last_ran_script->set_completed(); |
| 947 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
| 947 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
| 948 | 948 | $last_ran_script->reattempt(); |
| 949 | - }else{ |
|
| 950 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
| 949 | + } else { |
|
| 950 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
| 951 | 951 | } |
| 952 | 952 | return $this->_save_migrations_ran(); |
| 953 | 953 | } |
@@ -957,19 +957,19 @@ discard block |
||
| 957 | 957 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 958 | 958 | * @return boolean |
| 959 | 959 | */ |
| 960 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
| 961 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
| 960 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
| 961 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
| 962 | 962 | } |
| 963 | 963 | /** |
| 964 | 964 | * Enqueues this ee plugin to have its data initialized |
| 965 | 965 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
| 966 | 966 | */ |
| 967 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
| 967 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
| 968 | 968 | $queue = $this->get_db_initialization_queue(); |
| 969 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
| 969 | + if ( ! in_array($plugin_slug, $queue)) { |
|
| 970 | 970 | $queue[] = $plugin_slug; |
| 971 | 971 | } |
| 972 | - update_option( self::db_init_queue_option_name, $queue ); |
|
| 972 | + update_option(self::db_init_queue_option_name, $queue); |
|
| 973 | 973 | } |
| 974 | 974 | /** |
| 975 | 975 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -979,26 +979,26 @@ discard block |
||
| 979 | 979 | public function initialize_db_for_enqueued_ee_plugins() { |
| 980 | 980 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
| 981 | 981 | $queue = $this->get_db_initialization_queue(); |
| 982 | - foreach( $queue as $plugin_slug ) { |
|
| 983 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
| 984 | - if( ! $most_up_to_date_dms ) { |
|
| 982 | + foreach ($queue as $plugin_slug) { |
|
| 983 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
| 984 | + if ( ! $most_up_to_date_dms) { |
|
| 985 | 985 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
| 986 | 986 | $verify_db = false; |
| 987 | - }else{ |
|
| 988 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
| 989 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
| 987 | + } else { |
|
| 988 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
| 989 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
| 990 | 990 | } |
| 991 | - if( $plugin_slug == 'Core' ){ |
|
| 991 | + if ($plugin_slug == 'Core') { |
|
| 992 | 992 | EE_System::instance()->initialize_db_if_no_migrations_required( |
| 993 | 993 | false, |
| 994 | 994 | $verify_db |
| 995 | 995 | ); |
| 996 | - }else{ |
|
| 996 | + } else { |
|
| 997 | 997 | //just loop through the addons to make sure their database is setup |
| 998 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
| 999 | - if( $addon->name() == $plugin_slug ) { |
|
| 998 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 999 | + if ($addon->name() == $plugin_slug) { |
|
| 1000 | 1000 | |
| 1001 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
| 1001 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
| 1002 | 1002 | break; |
| 1003 | 1003 | } |
| 1004 | 1004 | } |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | // EEH_Debug_Tools::instance()->show_times(); |
| 1009 | 1009 | //because we just initialized the DBs for the enqueued ee plugins |
| 1010 | 1010 | //we don't need to keep remembering which ones needed to be initialized |
| 1011 | - delete_option( self::db_init_queue_option_name ); |
|
| 1011 | + delete_option(self::db_init_queue_option_name); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | /** |
@@ -1017,8 +1017,8 @@ discard block |
||
| 1017 | 1017 | * 'Core', or the return value of EE_Addon::name() for an addon |
| 1018 | 1018 | * @return array |
| 1019 | 1019 | */ |
| 1020 | - public function get_db_initialization_queue(){ |
|
| 1021 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
| 1020 | + public function get_db_initialization_queue() { |
|
| 1021 | + return get_option(self::db_init_queue_option_name, array()); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | /** |
@@ -1027,13 +1027,13 @@ discard block |
||
| 1027 | 1027 | * @throws \EE_Error |
| 1028 | 1028 | */ |
| 1029 | 1029 | protected function _get_table_analysis() { |
| 1030 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
| 1030 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 1031 | 1031 | return $this->_table_analysis; |
| 1032 | 1032 | } else { |
| 1033 | 1033 | throw new \EE_Error( |
| 1034 | 1034 | sprintf( |
| 1035 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1036 | - get_class( $this ) |
|
| 1035 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1036 | + get_class($this) |
|
| 1037 | 1037 | ) |
| 1038 | 1038 | ); |
| 1039 | 1039 | } |
@@ -1045,13 +1045,13 @@ discard block |
||
| 1045 | 1045 | * @throws \EE_Error |
| 1046 | 1046 | */ |
| 1047 | 1047 | protected function _get_table_manager() { |
| 1048 | - if( $this->_table_manager instanceof TableManager ) { |
|
| 1048 | + if ($this->_table_manager instanceof TableManager) { |
|
| 1049 | 1049 | return $this->_table_manager; |
| 1050 | 1050 | } else { |
| 1051 | 1051 | throw new \EE_Error( |
| 1052 | 1052 | sprintf( |
| 1053 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1054 | - get_class( $this ) |
|
| 1053 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1054 | + get_class($this) |
|
| 1055 | 1055 | ) |
| 1056 | 1056 | ); |
| 1057 | 1057 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | |
| 23 | -abstract class EE_Data_Migration_Class_Base{ |
|
| 23 | +abstract class EE_Data_Migration_Class_Base { |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var $records_to_migrate int count of all that have been migrated |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param TableManager $table_manager |
| 73 | 73 | * @param TableAnalysis $table_analysis |
| 74 | 74 | */ |
| 75 | - public function __construct( TableManager $table_manager = null, TableAnalysis $table_analysis = null ){ |
|
| 75 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) { |
|
| 76 | 76 | $this->_table_manager = $table_manager; |
| 77 | 77 | $this->_table_analysis = $table_analysis; |
| 78 | 78 | $this->set_status(EE_Data_Migration_Manager::status_continue); |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | * @throws EE_Error |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function pretty_name(){ |
|
| 89 | - if($this->_pretty_name === null){ |
|
| 90 | - throw new EE_Error(sprintf(__("Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", "event_espresso"),get_class($this))); |
|
| 88 | + public function pretty_name() { |
|
| 89 | + if ($this->_pretty_name === null) { |
|
| 90 | + throw new EE_Error(sprintf(__("Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", "event_espresso"), get_class($this))); |
|
| 91 | 91 | } |
| 92 | 92 | return $this->_pretty_name; |
| 93 | 93 | } |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return int |
| 97 | 97 | */ |
| 98 | - public function count_records_to_migrate(){ |
|
| 99 | - if( $this->_records_to_migrate == null){ |
|
| 98 | + public function count_records_to_migrate() { |
|
| 99 | + if ($this->_records_to_migrate == null) { |
|
| 100 | 100 | $this->_records_to_migrate = $this->_count_records_to_migrate(); |
| 101 | 101 | } |
| 102 | 102 | return $this->_records_to_migrate; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @return string one of EE_Data_Migration_Manager::status_* constants |
| 117 | 117 | * @throws EE_Error |
| 118 | 118 | */ |
| 119 | - public function get_status(){ |
|
| 120 | - if($this->_status === null){ |
|
| 121 | - throw new EE_Error(sprintf(__("Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", "event_espresso"),get_class($this))); |
|
| 119 | + public function get_status() { |
|
| 120 | + if ($this->_status === null) { |
|
| 121 | + throw new EE_Error(sprintf(__("Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", "event_espresso"), get_class($this))); |
|
| 122 | 122 | } |
| 123 | 123 | return $this->_status; |
| 124 | 124 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param string $status |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | - protected function set_status($status){ |
|
| 130 | + protected function set_status($status) { |
|
| 131 | 131 | $this->_status = $status; |
| 132 | 132 | } |
| 133 | 133 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Returns the last error that occurred. If none occurred, returns null |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - public function get_last_error(){ |
|
| 142 | + public function get_last_error() { |
|
| 143 | 143 | $errors = $this->get_errors(); |
| 144 | - if($errors){ |
|
| 144 | + if ($errors) { |
|
| 145 | 145 | return end($errors); |
| 146 | - }else{ |
|
| 146 | + } else { |
|
| 147 | 147 | return null; |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -152,26 +152,26 @@ discard block |
||
| 152 | 152 | * @param string $error a string describing the error that will be useful for debugging. Consider including all the data that led to the error, and a stack trace etc. |
| 153 | 153 | * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are already at their limit, we will purposefully forget the first half |
| 154 | 154 | */ |
| 155 | - public function add_error($error, $force = FALSE ){ |
|
| 156 | - if( ! defined( 'EE_DMS_ERROR_LIMIT' ) ){ |
|
| 155 | + public function add_error($error, $force = FALSE) { |
|
| 156 | + if ( ! defined('EE_DMS_ERROR_LIMIT')) { |
|
| 157 | 157 | $limit = 50; |
| 158 | - }else{ |
|
| 158 | + } else { |
|
| 159 | 159 | $limit = EE_DMS_ERROR_LIMIT; |
| 160 | 160 | } |
| 161 | 161 | //make sure errors is an array, see ticket #8261 |
| 162 | - if( is_string( $this->_errors ) ){ |
|
| 163 | - $this->_errors = array( $this->_errors ); |
|
| 162 | + if (is_string($this->_errors)) { |
|
| 163 | + $this->_errors = array($this->_errors); |
|
| 164 | 164 | } |
| 165 | - if(count($this->_errors) >= $limit ){ |
|
| 166 | - if( $force ){ |
|
| 165 | + if (count($this->_errors) >= $limit) { |
|
| 166 | + if ($force) { |
|
| 167 | 167 | //get rid of the first half of the errors and any above the limit |
| 168 | - $this->_errors = array_slice( $this->_errors, $limit / 2, $limit / 2 ); |
|
| 168 | + $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
| 169 | 169 | $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
| 170 | 170 | $this->_errors[] = $error; |
| 171 | - }else{ |
|
| 172 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
| 171 | + } else { |
|
| 172 | + $this->_errors[$limit] = 'More, but limit reached...'; |
|
| 173 | 173 | } |
| 174 | - }else{ |
|
| 174 | + } else { |
|
| 175 | 175 | $this->_errors[] = $error; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -180,57 +180,57 @@ discard block |
||
| 180 | 180 | * Indicates there was a fatal error and the migration cannot possibly continue |
| 181 | 181 | * @return boolean |
| 182 | 182 | */ |
| 183 | - public function is_broken(){ |
|
| 183 | + public function is_broken() { |
|
| 184 | 184 | return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
| 185 | 185 | } |
| 186 | 186 | /** |
| 187 | 187 | * @deprecated since 4.6.12 |
| 188 | 188 | */ |
| 189 | - public function is_borked(){ |
|
| 190 | - EE_Error::doing_it_wrong('is_borked', __( 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso' ), '4.6.12'); |
|
| 189 | + public function is_borked() { |
|
| 190 | + EE_Error::doing_it_wrong('is_borked', __('The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso'), '4.6.12'); |
|
| 191 | 191 | return $this->is_broken(); |
| 192 | 192 | } |
| 193 | 193 | /** |
| 194 | 194 | * Sets the status to as having a fatal error |
| 195 | 195 | */ |
| 196 | - public function set_broken(){ |
|
| 196 | + public function set_broken() { |
|
| 197 | 197 | $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
| 198 | 198 | } |
| 199 | 199 | /** |
| 200 | 200 | * |
| 201 | 201 | * @deprecated since 4.6.12 |
| 202 | 202 | */ |
| 203 | - public function set_borked(){ |
|
| 204 | - EE_Error::doing_it_wrong('is_borked', __( 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso' ), '4.6.12'); |
|
| 203 | + public function set_borked() { |
|
| 204 | + EE_Error::doing_it_wrong('is_borked', __('The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso'), '4.6.12'); |
|
| 205 | 205 | return $this->set_broken(); |
| 206 | 206 | } |
| 207 | 207 | /** |
| 208 | 208 | * Checks if this thing believes it is completed |
| 209 | 209 | * @return boolean |
| 210 | 210 | */ |
| 211 | - public function is_completed(){ |
|
| 211 | + public function is_completed() { |
|
| 212 | 212 | return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
| 213 | 213 | } |
| 214 | 214 | /** |
| 215 | 215 | * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
| 216 | 216 | * @return boolean |
| 217 | 217 | */ |
| 218 | - public function has_more_to_do(){ |
|
| 218 | + public function has_more_to_do() { |
|
| 219 | 219 | return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
| 220 | 220 | } |
| 221 | 221 | /** |
| 222 | 222 | * Marks that we believe this migration thing is completed |
| 223 | 223 | */ |
| 224 | - public function set_completed(){ |
|
| 224 | + public function set_completed() { |
|
| 225 | 225 | $this->_status = EE_Data_Migration_Manager::status_completed; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Marks that we think this migration class can continue to migrate |
| 230 | 230 | */ |
| 231 | - public function reattempt(){ |
|
| 231 | + public function reattempt() { |
|
| 232 | 232 | $this->_status = EE_Data_Migration_Manager::status_continue; |
| 233 | - $this->add_error( __( 'Reattempt migration', 'event_espresso' ), TRUE ); |
|
| 233 | + $this->add_error(__('Reattempt migration', 'event_espresso'), TRUE); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * possible that this class is defined when it goes to sleep, but NOT available when it |
| 240 | 240 | * awakes (eg, this class is part of an addon that is deactivated at some point). |
| 241 | 241 | */ |
| 242 | - public function properties_as_array(){ |
|
| 243 | - $properties = get_object_vars($this); |
|
| 242 | + public function properties_as_array() { |
|
| 243 | + $properties = get_object_vars($this); |
|
| 244 | 244 | $properties['class'] = get_class($this); |
| 245 | 245 | unset($properties['_migration_script']); |
| 246 | 246 | return $properties; |
@@ -261,22 +261,22 @@ discard block |
||
| 261 | 261 | * @param array $data_types numerically indexed |
| 262 | 262 | * @return string |
| 263 | 263 | */ |
| 264 | - protected function _create_error_message_for_db_insertion($old_table, $old_row_as_array, $new_table, $new_row_as_array, $data_types){ |
|
| 264 | + protected function _create_error_message_for_db_insertion($old_table, $old_row_as_array, $new_table, $new_row_as_array, $data_types) { |
|
| 265 | 265 | global $wpdb; |
| 266 | 266 | $old_columns_and_values_for_string = array(); |
| 267 | - foreach($old_row_as_array as $column => $value){ |
|
| 267 | + foreach ($old_row_as_array as $column => $value) { |
|
| 268 | 268 | $old_columns_and_values_for_string[] = "$column => $value"; |
| 269 | 269 | } |
| 270 | 270 | $new_columns_and_values_for_string = array(); |
| 271 | 271 | $count = 0; |
| 272 | - foreach($new_row_as_array as $column => $value){ |
|
| 272 | + foreach ($new_row_as_array as $column => $value) { |
|
| 273 | 273 | $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")"; |
| 274 | 274 | } |
| 275 | 275 | return sprintf( |
| 276 | 276 | __('Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4%s.', "event_espresso"), |
| 277 | - implode(", ",$new_columns_and_values_for_string), |
|
| 277 | + implode(", ", $new_columns_and_values_for_string), |
|
| 278 | 278 | $new_table, |
| 279 | - implode(", ",$old_columns_and_values_for_string), |
|
| 279 | + implode(", ", $old_columns_and_values_for_string), |
|
| 280 | 280 | $old_table, |
| 281 | 281 | '<br/>', |
| 282 | 282 | $wpdb->last_error |
@@ -291,12 +291,12 @@ discard block |
||
| 291 | 291 | * @param array $array_of_data |
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | - protected function _json_encode($array_of_data){ |
|
| 294 | + protected function _json_encode($array_of_data) { |
|
| 295 | 295 | //we'd rather NOT serialize the transaction details |
| 296 | 296 | $fields_to_include = array(); |
| 297 | - foreach($array_of_data as $name => $value){ |
|
| 297 | + foreach ($array_of_data as $name => $value) { |
|
| 298 | 298 | $unserialized_data = @unserialize($value); |
| 299 | - if($unserialized_data === FALSE){ |
|
| 299 | + if ($unserialized_data === FALSE) { |
|
| 300 | 300 | $fields_to_include[$name] = $value; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | * @throws EE_Error |
| 310 | 310 | */ |
| 311 | 311 | protected function _get_table_manager() { |
| 312 | - if( $this->_table_manager instanceof TableManager ) { |
|
| 312 | + if ($this->_table_manager instanceof TableManager) { |
|
| 313 | 313 | return $this->_table_manager; |
| 314 | 314 | } else { |
| 315 | 315 | throw new EE_Error( |
| 316 | 316 | sprintf( |
| 317 | - __( 'Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 318 | - get_class( $this ) |
|
| 317 | + __('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 318 | + get_class($this) |
|
| 319 | 319 | ) |
| 320 | 320 | ); |
| 321 | 321 | } |
@@ -327,13 +327,13 @@ discard block |
||
| 327 | 327 | * @throws EE_Error |
| 328 | 328 | */ |
| 329 | 329 | protected function _get_table_analysis() { |
| 330 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
| 330 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 331 | 331 | return $this->_table_analysis; |
| 332 | 332 | } else { |
| 333 | 333 | throw new EE_Error( |
| 334 | 334 | sprintf( |
| 335 | - __( 'Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 336 | - get_class( $this ) |
|
| 335 | + __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 336 | + get_class($this) |
|
| 337 | 337 | ) |
| 338 | 338 | ); |
| 339 | 339 | } |