@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | // remember the model relation chain to the JOIN model, because we'll |
66 | 66 | // need it for get_join_statement() |
67 | 67 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); // get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | 69 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
70 | 70 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
71 | 71 | $model_relation_chain, |
72 | 72 | $this->get_this_model()->get_this_model_name() |
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
73 | + ).$this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | 75 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
76 | 76 | $model_relation_chain, |
77 | 77 | $this->get_join_model()->get_this_model_name() |
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
78 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | 80 | // phew! ok, we have all the info we need, now we can create the SQL join string |
81 | 81 | $SQL = $this->_left_join( |
82 | 82 | $join_table, |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $join_table_fk_field_to_this_table->get_table_column(), |
85 | 85 | $this_table_alias, |
86 | 86 | $this_table_pk_field->get_table_column() |
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
87 | + ).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | 89 | return $SQL; |
90 | 90 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
114 | 114 | $this->_model_relation_chain_to_join_model, |
115 | 115 | $this->get_join_model()->get_this_model_name() |
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
116 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | 117 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
118 | 118 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
119 | 119 | $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
120 | 120 | $model_relation_chain, |
121 | 121 | $this->get_other_model()->get_this_model_name() |
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
122 | + ).$other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | 125 | $SQL = $this->_left_join( |
126 | 126 | $other_table, |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $other_table_pk_field->get_table_column(), |
129 | 129 | $join_table_alias, |
130 | 130 | $join_table_fk_field_to_other_table->get_table_column() |
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
131 | + ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | 132 | return $SQL; |
133 | 133 | } |
134 | 134 | |
@@ -161,17 +161,17 @@ discard block |
||
161 | 161 | ); |
162 | 162 | |
163 | 163 | // if $where_query exists lets add them to the query_params. |
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
164 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
165 | 165 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
166 | 166 | // make sure we strip THIS models name from the query param |
167 | 167 | $parsed_query = array(); |
168 | 168 | foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name().".", |
|
171 | 171 | "", |
172 | 172 | $query_param |
173 | 173 | ); |
174 | - $parsed_query[ $query_param ] = $val; |
|
174 | + $parsed_query[$query_param] = $val; |
|
175 | 175 | } |
176 | 176 | $all_fields = array_merge($foreign_keys, $parsed_query); |
177 | 177 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | // new row. |
182 | 182 | // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
183 | 183 | // the other tables) use the joining model directly! |
184 | - if (! $existing_entry_in_join_table) { |
|
184 | + if ( ! $existing_entry_in_join_table) { |
|
185 | 185 | $this->get_join_model()->insert($all_fields); |
186 | 186 | } else { |
187 | 187 | $this->get_join_model()->update( |
@@ -217,17 +217,17 @@ discard block |
||
217 | 217 | ); |
218 | 218 | |
219 | 219 | // if $where_query exists lets add them to the query_params. |
220 | - if (! empty($where_query)) { |
|
220 | + if ( ! empty($where_query)) { |
|
221 | 221 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
222 | 222 | // make sure we strip THIS models name from the query param |
223 | 223 | $parsed_query = array(); |
224 | 224 | foreach ($where_query as $query_param => $val) { |
225 | - $query_param = str_replace( |
|
226 | - $this->get_join_model()->get_this_model_name() . ".", |
|
225 | + $query_param = str_replace( |
|
226 | + $this->get_join_model()->get_this_model_name().".", |
|
227 | 227 | "", |
228 | 228 | $query_param |
229 | 229 | ); |
230 | - $parsed_query[ $query_param ] = $val; |
|
230 | + $parsed_query[$query_param] = $val; |
|
231 | 231 | } |
232 | 232 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
233 | 233 | } |
@@ -9,266 +9,266 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_HABTM_Relation extends EE_Model_Relation_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | - * which joins EE_Event and EE_Question_Group |
|
15 | - * |
|
16 | - * @var EEM_Base |
|
17 | - */ |
|
18 | - protected $_joining_model_name; |
|
12 | + /** |
|
13 | + * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | + * which joins EE_Event and EE_Question_Group |
|
15 | + * |
|
16 | + * @var EEM_Base |
|
17 | + */ |
|
18 | + protected $_joining_model_name; |
|
19 | 19 | |
20 | - protected $_model_relation_chain_to_join_model; |
|
20 | + protected $_model_relation_chain_to_join_model; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | - * (and an ee joining-model.) This knows how to join the models, |
|
26 | - * get related models across the relation, and add-and-remove the relationships. |
|
27 | - * |
|
28 | - * @param bool $joining_model_name |
|
29 | - * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | - * are related models across this relation, block (prevent and add an |
|
31 | - * error) the deletion of this model |
|
32 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | - * default |
|
34 | - */ |
|
35 | - public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | - { |
|
37 | - $this->_joining_model_name = $joining_model_name; |
|
38 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | - } |
|
23 | + /** |
|
24 | + * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | + * (and an ee joining-model.) This knows how to join the models, |
|
26 | + * get related models across the relation, and add-and-remove the relationships. |
|
27 | + * |
|
28 | + * @param bool $joining_model_name |
|
29 | + * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | + * are related models across this relation, block (prevent and add an |
|
31 | + * error) the deletion of this model |
|
32 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | + * default |
|
34 | + */ |
|
35 | + public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | + { |
|
37 | + $this->_joining_model_name = $joining_model_name; |
|
38 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Gets the joining model's object |
|
43 | - * |
|
44 | - * @return EEM_Base |
|
45 | - */ |
|
46 | - public function get_join_model() |
|
47 | - { |
|
48 | - return $this->_get_model($this->_joining_model_name); |
|
49 | - } |
|
41 | + /** |
|
42 | + * Gets the joining model's object |
|
43 | + * |
|
44 | + * @return EEM_Base |
|
45 | + */ |
|
46 | + public function get_join_model() |
|
47 | + { |
|
48 | + return $this->_get_model($this->_joining_model_name); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | - * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | - * |
|
56 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | - * @return string of SQL |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | - { |
|
62 | - // create sql like |
|
63 | - // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | - // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | - // remember the model relation chain to the JOIN model, because we'll |
|
66 | - // need it for get_join_statement() |
|
67 | - $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | - $model_relation_chain, |
|
72 | - $this->get_this_model()->get_this_model_name() |
|
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
52 | + /** |
|
53 | + * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | + * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | + * |
|
56 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | + * @return string of SQL |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | + { |
|
62 | + // create sql like |
|
63 | + // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | + // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | + // remember the model relation chain to the JOIN model, because we'll |
|
66 | + // need it for get_join_statement() |
|
67 | + $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | + $model_relation_chain, |
|
72 | + $this->get_this_model()->get_this_model_name() |
|
73 | + ) . $this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | - $model_relation_chain, |
|
77 | - $this->get_join_model()->get_this_model_name() |
|
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | - // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | - $SQL = $this->_left_join( |
|
82 | - $join_table, |
|
83 | - $join_table_alias, |
|
84 | - $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | - $this_table_alias, |
|
86 | - $this_table_pk_field->get_table_column() |
|
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
75 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | + $model_relation_chain, |
|
77 | + $this->get_join_model()->get_this_model_name() |
|
78 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | + // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | + $SQL = $this->_left_join( |
|
82 | + $join_table, |
|
83 | + $join_table_alias, |
|
84 | + $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | + $this_table_alias, |
|
86 | + $this_table_pk_field->get_table_column() |
|
87 | + ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | - return $SQL; |
|
90 | - } |
|
89 | + return $SQL; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | - * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | - * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | - * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | - * the intermediate join table, and then to the other model's pk's table |
|
99 | - * |
|
100 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | - * @return string of SQL |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public function get_join_statement($model_relation_chain) |
|
105 | - { |
|
106 | - if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | - throw new EE_Error(sprintf(__( |
|
108 | - 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | - 'event_espresso' |
|
110 | - ))); |
|
111 | - } |
|
112 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | - $this->_model_relation_chain_to_join_model, |
|
115 | - $this->get_join_model()->get_this_model_name() |
|
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | - $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | - $model_relation_chain, |
|
121 | - $this->get_other_model()->get_this_model_name() |
|
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
93 | + /** |
|
94 | + * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | + * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | + * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | + * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | + * the intermediate join table, and then to the other model's pk's table |
|
99 | + * |
|
100 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | + * @return string of SQL |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public function get_join_statement($model_relation_chain) |
|
105 | + { |
|
106 | + if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | + throw new EE_Error(sprintf(__( |
|
108 | + 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | + 'event_espresso' |
|
110 | + ))); |
|
111 | + } |
|
112 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | + $this->_model_relation_chain_to_join_model, |
|
115 | + $this->get_join_model()->get_this_model_name() |
|
116 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | + $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | + $model_relation_chain, |
|
121 | + $this->get_other_model()->get_this_model_name() |
|
122 | + ) . $other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | - $SQL = $this->_left_join( |
|
126 | - $other_table, |
|
127 | - $other_table_alias, |
|
128 | - $other_table_pk_field->get_table_column(), |
|
129 | - $join_table_alias, |
|
130 | - $join_table_fk_field_to_other_table->get_table_column() |
|
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | - return $SQL; |
|
133 | - } |
|
125 | + $SQL = $this->_left_join( |
|
126 | + $other_table, |
|
127 | + $other_table_alias, |
|
128 | + $other_table_pk_field->get_table_column(), |
|
129 | + $join_table_alias, |
|
130 | + $join_table_fk_field_to_other_table->get_table_column() |
|
131 | + ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | + return $SQL; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | - * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | - * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | - * columns' values |
|
141 | - * |
|
142 | - * @param EE_Base_Class|int $this_obj_or_id |
|
143 | - * @param EE_Base_Class|int $other_obj_or_id |
|
144 | - * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | - * checking existing values and for setting new rows if |
|
146 | - * no exact matches. |
|
147 | - * @return EE_Base_Class |
|
148 | - * @throws \EE_Error |
|
149 | - */ |
|
150 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | - { |
|
152 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | - // check if such a relationship already exists |
|
155 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
136 | + /** |
|
137 | + * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | + * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | + * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | + * columns' values |
|
141 | + * |
|
142 | + * @param EE_Base_Class|int $this_obj_or_id |
|
143 | + * @param EE_Base_Class|int $other_obj_or_id |
|
144 | + * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | + * checking existing values and for setting new rows if |
|
146 | + * no exact matches. |
|
147 | + * @return EE_Base_Class |
|
148 | + * @throws \EE_Error |
|
149 | + */ |
|
150 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | + { |
|
152 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | + // check if such a relationship already exists |
|
155 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
157 | 157 | |
158 | - $foreign_keys = $all_fields = array( |
|
159 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | - ); |
|
158 | + $foreign_keys = $all_fields = array( |
|
159 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | + ); |
|
162 | 162 | |
163 | - // if $where_query exists lets add them to the query_params. |
|
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
165 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
166 | - // make sure we strip THIS models name from the query param |
|
167 | - $parsed_query = array(); |
|
168 | - foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
171 | - "", |
|
172 | - $query_param |
|
173 | - ); |
|
174 | - $parsed_query[ $query_param ] = $val; |
|
175 | - } |
|
176 | - $all_fields = array_merge($foreign_keys, $parsed_query); |
|
177 | - } |
|
163 | + // if $where_query exists lets add them to the query_params. |
|
164 | + if (! empty($extra_join_model_fields_n_values)) { |
|
165 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
166 | + // make sure we strip THIS models name from the query param |
|
167 | + $parsed_query = array(); |
|
168 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name() . ".", |
|
171 | + "", |
|
172 | + $query_param |
|
173 | + ); |
|
174 | + $parsed_query[ $query_param ] = $val; |
|
175 | + } |
|
176 | + $all_fields = array_merge($foreign_keys, $parsed_query); |
|
177 | + } |
|
178 | 178 | |
179 | - $existing_entry_in_join_table = $this->get_join_model()->get_one(array($foreign_keys)); |
|
180 | - // If there is already an entry in the join table, indicating a relationship, update it instead of adding a |
|
181 | - // new row. |
|
182 | - // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
183 | - // the other tables) use the joining model directly! |
|
184 | - if (! $existing_entry_in_join_table) { |
|
185 | - $this->get_join_model()->insert($all_fields); |
|
186 | - } else { |
|
187 | - $this->get_join_model()->update( |
|
188 | - $all_fields, |
|
189 | - [$foreign_keys] |
|
190 | - ); |
|
191 | - } |
|
192 | - return $other_model_obj; |
|
193 | - } |
|
179 | + $existing_entry_in_join_table = $this->get_join_model()->get_one(array($foreign_keys)); |
|
180 | + // If there is already an entry in the join table, indicating a relationship, update it instead of adding a |
|
181 | + // new row. |
|
182 | + // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
183 | + // the other tables) use the joining model directly! |
|
184 | + if (! $existing_entry_in_join_table) { |
|
185 | + $this->get_join_model()->insert($all_fields); |
|
186 | + } else { |
|
187 | + $this->get_join_model()->update( |
|
188 | + $all_fields, |
|
189 | + [$foreign_keys] |
|
190 | + ); |
|
191 | + } |
|
192 | + return $other_model_obj; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
198 | - * |
|
199 | - * @param EE_Base_Class|int $this_obj_or_id |
|
200 | - * @param EE_Base_Class|int $other_obj_or_id |
|
201 | - * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
202 | - * values and for removing existing rows if exact matches exist. |
|
203 | - * @return EE_Base_Class |
|
204 | - * @throws \EE_Error |
|
205 | - */ |
|
206 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
207 | - { |
|
208 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
209 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
210 | - // check if such a relationship already exists |
|
211 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
212 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
196 | + /** |
|
197 | + * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
198 | + * |
|
199 | + * @param EE_Base_Class|int $this_obj_or_id |
|
200 | + * @param EE_Base_Class|int $other_obj_or_id |
|
201 | + * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
202 | + * values and for removing existing rows if exact matches exist. |
|
203 | + * @return EE_Base_Class |
|
204 | + * @throws \EE_Error |
|
205 | + */ |
|
206 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
207 | + { |
|
208 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
209 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
210 | + // check if such a relationship already exists |
|
211 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
212 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
213 | 213 | |
214 | - $cols_n_values = array( |
|
215 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
216 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
217 | - ); |
|
214 | + $cols_n_values = array( |
|
215 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
216 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
217 | + ); |
|
218 | 218 | |
219 | - // if $where_query exists lets add them to the query_params. |
|
220 | - if (! empty($where_query)) { |
|
221 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
222 | - // make sure we strip THIS models name from the query param |
|
223 | - $parsed_query = array(); |
|
224 | - foreach ($where_query as $query_param => $val) { |
|
225 | - $query_param = str_replace( |
|
226 | - $this->get_join_model()->get_this_model_name() . ".", |
|
227 | - "", |
|
228 | - $query_param |
|
229 | - ); |
|
230 | - $parsed_query[ $query_param ] = $val; |
|
231 | - } |
|
232 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
233 | - } |
|
219 | + // if $where_query exists lets add them to the query_params. |
|
220 | + if (! empty($where_query)) { |
|
221 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
222 | + // make sure we strip THIS models name from the query param |
|
223 | + $parsed_query = array(); |
|
224 | + foreach ($where_query as $query_param => $val) { |
|
225 | + $query_param = str_replace( |
|
226 | + $this->get_join_model()->get_this_model_name() . ".", |
|
227 | + "", |
|
228 | + $query_param |
|
229 | + ); |
|
230 | + $parsed_query[ $query_param ] = $val; |
|
231 | + } |
|
232 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
233 | + } |
|
234 | 234 | |
235 | - $this->get_join_model()->delete(array($cols_n_values)); |
|
236 | - return $other_model_obj; |
|
237 | - } |
|
235 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
236 | + return $other_model_obj; |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * Gets all the non-key fields (ie, not the primary key and not foreign keys) on the join model. |
|
241 | - * @since 4.9.76.p |
|
242 | - * @return EE_Model_Field_Base[] |
|
243 | - * @throws EE_Error |
|
244 | - */ |
|
245 | - public function getNonKeyFields() |
|
246 | - { |
|
247 | - // all fields besides the primary key and two foreign keys should be parameters |
|
248 | - $join_model = $this->get_join_model(); |
|
249 | - $standard_fields = array(); |
|
250 | - if ($join_model->has_primary_key_field()) { |
|
251 | - $standard_fields[] = $join_model->primary_key_name(); |
|
252 | - } |
|
253 | - if ($this->get_this_model()->has_primary_key_field()) { |
|
254 | - $standard_fields[] = $this->get_this_model()->primary_key_name(); |
|
255 | - } |
|
256 | - if ($this->get_other_model()->has_primary_key_field()) { |
|
257 | - $standard_fields[] = $this->get_other_model()->primary_key_name(); |
|
258 | - } |
|
259 | - return array_diff_key( |
|
260 | - $join_model->field_settings(), |
|
261 | - array_flip($standard_fields) |
|
262 | - ); |
|
263 | - } |
|
239 | + /** |
|
240 | + * Gets all the non-key fields (ie, not the primary key and not foreign keys) on the join model. |
|
241 | + * @since 4.9.76.p |
|
242 | + * @return EE_Model_Field_Base[] |
|
243 | + * @throws EE_Error |
|
244 | + */ |
|
245 | + public function getNonKeyFields() |
|
246 | + { |
|
247 | + // all fields besides the primary key and two foreign keys should be parameters |
|
248 | + $join_model = $this->get_join_model(); |
|
249 | + $standard_fields = array(); |
|
250 | + if ($join_model->has_primary_key_field()) { |
|
251 | + $standard_fields[] = $join_model->primary_key_name(); |
|
252 | + } |
|
253 | + if ($this->get_this_model()->has_primary_key_field()) { |
|
254 | + $standard_fields[] = $this->get_this_model()->primary_key_name(); |
|
255 | + } |
|
256 | + if ($this->get_other_model()->has_primary_key_field()) { |
|
257 | + $standard_fields[] = $this->get_other_model()->primary_key_name(); |
|
258 | + } |
|
259 | + return array_diff_key( |
|
260 | + $join_model->field_settings(), |
|
261 | + array_flip($standard_fields) |
|
262 | + ); |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * Returns true if the join model has non-key fields (ie, fields that aren't the primary key or foreign keys.) |
|
267 | - * @since 4.9.76.p |
|
268 | - * @return boolean |
|
269 | - */ |
|
270 | - public function hasNonKeyFields() |
|
271 | - { |
|
272 | - return count($this->get_join_model()->field_settings()) > 3; |
|
273 | - } |
|
265 | + /** |
|
266 | + * Returns true if the join model has non-key fields (ie, fields that aren't the primary key or foreign keys.) |
|
267 | + * @since 4.9.76.p |
|
268 | + * @return boolean |
|
269 | + */ |
|
270 | + public function hasNonKeyFields() |
|
271 | + { |
|
272 | + return count($this->get_join_model()->field_settings()) > 3; |
|
273 | + } |
|
274 | 274 | } |
@@ -3,7 +3,6 @@ |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
5 | 5 | use EventEspresso\core\interfaces\ResettableInterface; |
6 | - |
|
7 | 6 | use EventEspresso\core\services\database\TableManager; |
8 | 7 | use EventEspresso\core\services\database\TableAnalysis; |
9 | 8 | use EventEspresso\core\services\loaders\LoaderFactory; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | public static function instance() |
159 | 159 | { |
160 | 160 | // check if class object is instantiated |
161 | - if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
161 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
162 | 162 | self::$_instance = new self(); |
163 | 163 | } |
164 | 164 | return self::$_instance; |
@@ -234,12 +234,12 @@ discard block |
||
234 | 234 | |
235 | 235 | if (count($parts) == 4) { |
236 | 236 | // it's 4.2-style.eg Core.4.1.0 |
237 | - $plugin_slug = $parts[0];// eg Core |
|
238 | - $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
237 | + $plugin_slug = $parts[0]; // eg Core |
|
238 | + $version_string = $parts[1].".".$parts[2].".".$parts[3]; // eg 4.1.0 |
|
239 | 239 | } else { |
240 | 240 | // it's 4.1-style: eg 4.1.0 |
241 | 241 | $plugin_slug = 'Core'; |
242 | - $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
242 | + $version_string = $plugin_slug_and_version_string; // eg 4.1.0 |
|
243 | 243 | } |
244 | 244 | return array($plugin_slug, $version_string); |
245 | 245 | } |
@@ -291,11 +291,11 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function get_data_migrations_ran() |
293 | 293 | { |
294 | - if (! $this->_data_migrations_ran) { |
|
294 | + if ( ! $this->_data_migrations_ran) { |
|
295 | 295 | // setup autoloaders for each of the scripts in there |
296 | 296 | $this->get_all_data_migration_scripts_available(); |
297 | 297 | $data_migrations_options = $this->get_all_migration_script_options( |
298 | - );// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
298 | + ); // get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
299 | 299 | |
300 | 300 | $data_migrations_ran = array(); |
301 | 301 | // convert into data migration script classes where possible |
@@ -309,23 +309,23 @@ discard block |
||
309 | 309 | $data_migration_option['option_name'], |
310 | 310 | $data_migration_option['option_value'] |
311 | 311 | ); |
312 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
312 | + $data_migrations_ran[$plugin_slug][$version_string] = $class; |
|
313 | 313 | // ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
314 | 314 | $this->_last_ran_script = $class; |
315 | - if (! $class->is_completed()) { |
|
315 | + if ( ! $class->is_completed()) { |
|
316 | 316 | // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
317 | 317 | $this->_last_ran_incomplete_script = $class; |
318 | 318 | } |
319 | 319 | } catch (EE_Error $e) { |
320 | 320 | // ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
321 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
321 | + $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize( |
|
322 | 322 | $data_migration_option['option_value'] |
323 | 323 | ); |
324 | 324 | } |
325 | 325 | } |
326 | 326 | // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
327 | 327 | $this->_data_migrations_ran = $data_migrations_ran; |
328 | - if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
328 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
329 | 329 | $this->_data_migrations_ran = array(); |
330 | 330 | } |
331 | 331 | } |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | { |
359 | 359 | global $wpdb; |
360 | 360 | return $wpdb->get_results( |
361 | - "SELECT * FROM {$wpdb->options} WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id ASC", |
|
361 | + "SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", |
|
362 | 362 | ARRAY_A |
363 | 363 | ); |
364 | 364 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | { |
374 | 374 | return apply_filters( |
375 | 375 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
376 | - array('Core' => EE_CORE . 'data_migration_scripts') |
|
376 | + array('Core' => EE_CORE.'data_migration_scripts') |
|
377 | 377 | ); |
378 | 378 | } |
379 | 379 | |
@@ -389,15 +389,15 @@ discard block |
||
389 | 389 | */ |
390 | 390 | public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
391 | 391 | { |
392 | - if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
393 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
392 | + if (isset($this->script_migration_versions[$migration_script_name])) { |
|
393 | + return $this->script_migration_versions[$migration_script_name]; |
|
394 | 394 | } |
395 | 395 | $dms_info = $this->parse_dms_classname($migration_script_name); |
396 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
396 | + $this->script_migration_versions[$migration_script_name] = array( |
|
397 | 397 | 'slug' => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
398 | - 'version' => $dms_info['major_version'] . "." . $dms_info['minor_version'] . "." . $dms_info['micro_version'], |
|
398 | + 'version' => $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'], |
|
399 | 399 | ); |
400 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
400 | + return $this->script_migration_versions[$migration_script_name]; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | { |
412 | 412 | $matches = array(); |
413 | 413 | preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
414 | - if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
414 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
415 | 415 | throw new EE_Error( |
416 | 416 | sprintf( |
417 | 417 | __( |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | { |
443 | 443 | $espresso_db_core_updates = get_option('espresso_db_update', array()); |
444 | 444 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
445 | - if (! $db_state) { |
|
445 | + if ( ! $db_state) { |
|
446 | 446 | // mark the DB as being in the state as the last version in there. |
447 | 447 | // this is done to trigger maintenance mode and do data migration scripts |
448 | 448 | // if the admin installed this version of EE over 3.1.x or 4.0.x |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | // in 4.1, $db_state would have only been a simple string like '4.1.0', |
462 | 462 | // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
463 | 463 | // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
464 | - if (! is_array($db_state)) { |
|
464 | + if ( ! is_array($db_state)) { |
|
465 | 465 | $db_state = array('Core' => $db_state); |
466 | 466 | update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
467 | 467 | } |
@@ -498,29 +498,29 @@ discard block |
||
498 | 498 | $script_converts_plugin_slug = $migrates_to_version['slug']; |
499 | 499 | $script_converts_to_version = $migrates_to_version['version']; |
500 | 500 | // check if this version script is DONE or not; or if it's never been ran |
501 | - if (! $scripts_ran || |
|
502 | - ! isset($scripts_ran[ $script_converts_plugin_slug ]) || |
|
503 | - ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ])) { |
|
501 | + if ( ! $scripts_ran || |
|
502 | + ! isset($scripts_ran[$script_converts_plugin_slug]) || |
|
503 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
504 | 504 | // we haven't ran this conversion script before |
505 | 505 | // now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
506 | 506 | $script = LoaderFactory::getLoader()->load($classname); |
507 | 507 | /* @var $script EE_Data_Migration_Script_Base */ |
508 | 508 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
509 | 509 | if ($can_migrate) { |
510 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
510 | + $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
|
511 | 511 | $migrates_to_version = $script->migrates_to_version(); |
512 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version']; |
|
513 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
512 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
513 | + unset($script_class_and_filepaths_available[$classname]); |
|
514 | 514 | } |
515 | - } elseif ($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] instanceof EE_Data_Migration_Script_Base) { |
|
515 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
516 | 516 | // this script has been ran, or at least started |
517 | - $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
517 | + $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
|
518 | 518 | if ($script->get_status() != self::status_completed) { |
519 | 519 | // this script is already underway... keep going with it |
520 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
520 | + $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
|
521 | 521 | $migrates_to_version = $script->migrates_to_version(); |
522 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version']; |
|
523 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
522 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
523 | + unset($script_class_and_filepaths_available[$classname]); |
|
524 | 524 | } else { |
525 | 525 | // it must have a status that indicates it has finished, so we don't want to try and run it again |
526 | 526 | } |
@@ -531,14 +531,14 @@ discard block |
||
531 | 531 | } |
532 | 532 | } |
533 | 533 | $iteration++; |
534 | - } while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
534 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
535 | 535 | // ok we have all the scripts that should run, now let's make them into flat array |
536 | 536 | $scripts_that_should_run = array(); |
537 | 537 | foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
538 | 538 | ksort($scripts_at_priority); |
539 | 539 | foreach ($scripts_at_priority as $scripts) { |
540 | 540 | foreach ($scripts as $script) { |
541 | - $scripts_that_should_run[ get_class($script) ] = $script; |
|
541 | + $scripts_that_should_run[get_class($script)] = $script; |
|
542 | 542 | } |
543 | 543 | } |
544 | 544 | } |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | public function get_last_ran_script($include_completed_scripts = false) |
564 | 564 | { |
565 | 565 | // make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
566 | - if (! $this->_data_migrations_ran) { |
|
566 | + if ( ! $this->_data_migrations_ran) { |
|
567 | 567 | $this->get_data_migrations_ran(); |
568 | 568 | } |
569 | 569 | if ($include_completed_scripts) { |
@@ -600,10 +600,10 @@ discard block |
||
600 | 600 | |
601 | 601 | try { |
602 | 602 | $currently_executing_script = $this->get_last_ran_script(); |
603 | - if (! $currently_executing_script) { |
|
603 | + if ( ! $currently_executing_script) { |
|
604 | 604 | // Find the next script that needs to execute |
605 | 605 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
606 | - if (! $scripts) { |
|
606 | + if ( ! $scripts) { |
|
607 | 607 | // huh, no more scripts to run... apparently we're done! |
608 | 608 | // but dont forget to make sure initial data is there |
609 | 609 | // we should be good to allow them to exit maintenance mode now |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
630 | 630 | $plugin_slug = $migrates_to['slug']; |
631 | 631 | $version = $migrates_to['version']; |
632 | - $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
632 | + $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
|
633 | 633 | } |
634 | 634 | $current_script_name = get_class($currently_executing_script); |
635 | 635 | } catch (Exception $e) { |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | |
638 | 638 | $message = sprintf( |
639 | 639 | __("Error Message: %sStack Trace:%s", "event_espresso"), |
640 | - $e->getMessage() . '<br>', |
|
640 | + $e->getMessage().'<br>', |
|
641 | 641 | $e->getTraceAsString() |
642 | 642 | ); |
643 | 643 | // record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | ); |
690 | 690 | // check if there are any more after this one. |
691 | 691 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
692 | - if (! $scripts_remaining) { |
|
692 | + if ( ! $scripts_remaining) { |
|
693 | 693 | // we should be good to allow them to exit maintenance mode now |
694 | 694 | EE_Maintenance_Mode::instance()->set_maintenance_level( |
695 | 695 | intval(EE_Maintenance_Mode::level_0_not_in_maintenance) |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | ), |
790 | 790 | 'script' => 'Unknown', |
791 | 791 | ); |
792 | - $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
792 | + $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
|
793 | 793 | } |
794 | 794 | $warnings_etc = @ob_get_contents(); |
795 | 795 | ob_end_clean(); |
@@ -809,12 +809,12 @@ discard block |
||
809 | 809 | */ |
810 | 810 | public function update_current_database_state_to($slug_and_version = null) |
811 | 811 | { |
812 | - if (! $slug_and_version) { |
|
812 | + if ( ! $slug_and_version) { |
|
813 | 813 | // no version was provided, assume it should be at the current code version |
814 | 814 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
815 | 815 | } |
816 | 816 | $current_database_state = get_option(self::current_database_state); |
817 | - $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
817 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
818 | 818 | update_option(self::current_database_state, $current_database_state); |
819 | 819 | } |
820 | 820 | |
@@ -833,15 +833,15 @@ discard block |
||
833 | 833 | $slug = $slug_and_version['slug']; |
834 | 834 | $version = $slug_and_version['version']; |
835 | 835 | $current_database_state = get_option(self::current_database_state); |
836 | - if (! isset($current_database_state[ $slug ])) { |
|
836 | + if ( ! isset($current_database_state[$slug])) { |
|
837 | 837 | return true; |
838 | 838 | } else { |
839 | 839 | // 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 |
840 | - $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
840 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
841 | 841 | $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
842 | 842 | $needs_updating = false; |
843 | 843 | foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
844 | - if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
844 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
845 | 845 | $needs_updating = true; |
846 | 846 | break; |
847 | 847 | } |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | */ |
864 | 864 | public function get_all_data_migration_scripts_available() |
865 | 865 | { |
866 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
866 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
867 | 867 | $this->_data_migration_class_to_filepath_map = array(); |
868 | 868 | foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
869 | 869 | // strip any placeholders added to classname to make it a unique array key |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | ? $eeAddonClass |
873 | 873 | : ''; |
874 | 874 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
875 | - $files = glob($folder_path . '*.dms.php'); |
|
875 | + $files = glob($folder_path.'*.dms.php'); |
|
876 | 876 | if (empty($files)) { |
877 | 877 | continue; |
878 | 878 | } |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | '4.3.0.alpha.019' |
899 | 899 | ); |
900 | 900 | } |
901 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
901 | + $this->_data_migration_class_to_filepath_map[$classname] = $file; |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 | EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | // get last-ran migration script |
931 | 931 | global $wpdb; |
932 | 932 | $last_migration_script_option = $wpdb->get_row( |
933 | - "SELECT * FROM $wpdb->options WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id DESC LIMIT 1", |
|
933 | + "SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", |
|
934 | 934 | ARRAY_A |
935 | 935 | ); |
936 | 936 | |
@@ -962,10 +962,10 @@ discard block |
||
962 | 962 | $versions_migrated_to = 'Unknown.1.0.0'; |
963 | 963 | // now just to make sure appears as last (in case the were previously a fatal error like this) |
964 | 964 | // delete the old one |
965 | - delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
965 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
966 | 966 | } |
967 | 967 | update_option( |
968 | - self::data_migration_script_option_prefix . $versions_migrated_to, |
|
968 | + self::data_migration_script_option_prefix.$versions_migrated_to, |
|
969 | 969 | $last_ran_migration_script_properties |
970 | 970 | ); |
971 | 971 | } |
@@ -984,8 +984,8 @@ discard block |
||
984 | 984 | $successful_updates = true; |
985 | 985 | foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
986 | 986 | foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
987 | - $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
988 | - $option_name = self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
987 | + $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
|
988 | + $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
|
989 | 989 | $old_option_value = get_option($option_name); |
990 | 990 | if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
991 | 991 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | $successful_updates = update_option($option_name, $array_or_migration_obj); |
998 | 998 | } |
999 | 999 | } |
1000 | - if (! $successful_updates) { |
|
1000 | + if ( ! $successful_updates) { |
|
1001 | 1001 | global $wpdb; |
1002 | 1002 | return $wpdb->last_error; |
1003 | 1003 | } |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | */ |
1032 | 1032 | public function _instantiate_script_from_properties_array($properties_array) |
1033 | 1033 | { |
1034 | - if (! isset($properties_array['class'])) { |
|
1034 | + if ( ! isset($properties_array['class'])) { |
|
1035 | 1035 | throw new EE_Error( |
1036 | 1036 | sprintf( |
1037 | 1037 | __("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
@@ -1040,11 +1040,11 @@ discard block |
||
1040 | 1040 | ); |
1041 | 1041 | } |
1042 | 1042 | $class_name = $properties_array['class']; |
1043 | - if (! class_exists($class_name)) { |
|
1043 | + if ( ! class_exists($class_name)) { |
|
1044 | 1044 | throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
1045 | 1045 | } |
1046 | 1046 | $class = new $class_name; |
1047 | - if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
1047 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
1048 | 1048 | throw new EE_Error( |
1049 | 1049 | sprintf( |
1050 | 1050 | __("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), |
@@ -1111,8 +1111,8 @@ discard block |
||
1111 | 1111 | public function get_migration_ran($version, $plugin_slug = 'Core') |
1112 | 1112 | { |
1113 | 1113 | $migrations_ran = $this->get_data_migrations_ran(); |
1114 | - if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
1115 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
1114 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
1115 | + return $migrations_ran[$plugin_slug][$version]; |
|
1116 | 1116 | } else { |
1117 | 1117 | return null; |
1118 | 1118 | } |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | public function enqueue_db_initialization_for($plugin_slug) |
1174 | 1174 | { |
1175 | 1175 | $queue = $this->get_db_initialization_queue(); |
1176 | - if (! in_array($plugin_slug, $queue)) { |
|
1176 | + if ( ! in_array($plugin_slug, $queue)) { |
|
1177 | 1177 | $queue[] = $plugin_slug; |
1178 | 1178 | } |
1179 | 1179 | update_option(self::db_init_queue_option_name, $queue); |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | $queue = $this->get_db_initialization_queue(); |
1190 | 1190 | foreach ($queue as $plugin_slug) { |
1191 | 1191 | $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
1192 | - if (! $most_up_to_date_dms) { |
|
1192 | + if ( ! $most_up_to_date_dms) { |
|
1193 | 1193 | // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
1194 | 1194 | $verify_db = false; |
1195 | 1195 | } else { |
@@ -33,1238 +33,1238 @@ |
||
33 | 33 | class EE_Data_Migration_Manager implements ResettableInterface |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * |
|
38 | - * @var EE_Registry |
|
39 | - */ |
|
40 | - // protected $EE; |
|
41 | - /** |
|
42 | - * name of the wordpress option which stores an array of data about |
|
43 | - */ |
|
44 | - const data_migrations_option_name = 'ee_data_migration'; |
|
45 | - |
|
46 | - |
|
47 | - const data_migration_script_option_prefix = 'ee_data_migration_script_'; |
|
48 | - |
|
49 | - const data_migration_script_mapping_option_prefix = 'ee_dms_map_'; |
|
50 | - |
|
51 | - /** |
|
52 | - * name of the wordpress option which stores the database' current version. IE, the code may be at version 4.2.0, |
|
53 | - * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc. |
|
54 | - */ |
|
55 | - const current_database_state = 'ee_data_migration_current_db_state'; |
|
56 | - |
|
57 | - /** |
|
58 | - * Special status string returned when we're positive there are no more data migration |
|
59 | - * scripts that can be run. |
|
60 | - */ |
|
61 | - const status_no_more_migration_scripts = 'no_more_migration_scripts'; |
|
62 | - /** |
|
63 | - * string indicating the migration should continue |
|
64 | - */ |
|
65 | - const status_continue = 'status_continue'; |
|
66 | - /** |
|
67 | - * string indicating the migration has completed and should be ended |
|
68 | - */ |
|
69 | - const status_completed = 'status_completed'; |
|
70 | - /** |
|
71 | - * string indicating a fatal error occurred and the data migration should be completely aborted |
|
72 | - */ |
|
73 | - const status_fatal_error = 'status_fatal_error'; |
|
74 | - |
|
75 | - /** |
|
76 | - * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent |
|
77 | - * during migration) |
|
78 | - */ |
|
79 | - const step_size = 50; |
|
80 | - |
|
81 | - /** |
|
82 | - * option name that stores the queue of ee plugins needing to have |
|
83 | - * their data initialized (or re-initialized) once we are done migrations |
|
84 | - */ |
|
85 | - const db_init_queue_option_name = 'ee_db_init_queue'; |
|
86 | - /** |
|
87 | - * Array of information concerning data migrations that have ran in the history |
|
88 | - * of this EE installation. Keys should be the name of the version the script upgraded to |
|
89 | - * |
|
90 | - * @var EE_Data_Migration_Script_Base[] |
|
91 | - */ |
|
92 | - private $_data_migrations_ran = null; |
|
93 | - /** |
|
94 | - * The last ran script. It's nice to store this somewhere accessible, as its easiest |
|
95 | - * to know which was the last run by which is the newest wp option; but in most of the code |
|
96 | - * we just use the local $_data_migration_ran array, which organized the scripts differently |
|
97 | - * |
|
98 | - * @var EE_Data_Migration_Script_Base |
|
99 | - */ |
|
100 | - private $_last_ran_script = null; |
|
101 | - |
|
102 | - /** |
|
103 | - * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script. |
|
104 | - * |
|
105 | - * @var EE_Data_Migration_Script_Base |
|
106 | - */ |
|
107 | - private $_last_ran_incomplete_script = null; |
|
108 | - /** |
|
109 | - * array where keys are classnames, and values are filepaths of all the known migration scripts |
|
110 | - * |
|
111 | - * @var array |
|
112 | - */ |
|
113 | - private $_data_migration_class_to_filepath_map; |
|
114 | - |
|
115 | - /** |
|
116 | - * the following 4 properties are fully set on construction. |
|
117 | - * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished |
|
118 | - * one, we may want to start the next one); whereas the last two indicate whether to continue running a single |
|
119 | - * data migration script |
|
120 | - * |
|
121 | - * @var array |
|
122 | - */ |
|
123 | - public $stati_that_indicate_to_continue_migrations = array(); |
|
124 | - |
|
125 | - public $stati_that_indicate_to_stop_migrations = array(); |
|
126 | - |
|
127 | - public $stati_that_indicate_to_continue_single_migration_script = array(); |
|
128 | - |
|
129 | - public $stati_that_indicate_to_stop_single_migration_script = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
133 | - */ |
|
134 | - protected $_table_manager; |
|
135 | - |
|
136 | - /** |
|
137 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
138 | - */ |
|
139 | - protected $_table_analysis; |
|
140 | - |
|
141 | - /** |
|
142 | - * @var array $script_migration_versions |
|
143 | - */ |
|
144 | - protected $script_migration_versions; |
|
145 | - |
|
146 | - /** |
|
147 | - * @var EE_Data_Migration_Manager $_instance |
|
148 | - * @access private |
|
149 | - */ |
|
150 | - private static $_instance = null; |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @singleton method used to instantiate class object |
|
155 | - * @access public |
|
156 | - * @return EE_Data_Migration_Manager instance |
|
157 | - */ |
|
158 | - public static function instance() |
|
159 | - { |
|
160 | - // check if class object is instantiated |
|
161 | - if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
162 | - self::$_instance = new self(); |
|
163 | - } |
|
164 | - return self::$_instance; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, |
|
169 | - * all new usages of the singleton should be made with Classname::instance()) and returns it |
|
170 | - * |
|
171 | - * @return EE_Data_Migration_Manager |
|
172 | - */ |
|
173 | - public static function reset() |
|
174 | - { |
|
175 | - self::$_instance = null; |
|
176 | - return self::instance(); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * constructor |
|
182 | - */ |
|
183 | - private function __construct() |
|
184 | - { |
|
185 | - $this->stati_that_indicate_to_continue_migrations = array( |
|
186 | - self::status_continue, |
|
187 | - self::status_completed, |
|
188 | - ); |
|
189 | - $this->stati_that_indicate_to_stop_migrations = array( |
|
190 | - self::status_fatal_error, |
|
191 | - self::status_no_more_migration_scripts, |
|
192 | - ); |
|
193 | - $this->stati_that_indicate_to_continue_single_migration_script = array( |
|
194 | - self::status_continue, |
|
195 | - ); |
|
196 | - $this->stati_that_indicate_to_stop_single_migration_script = array( |
|
197 | - self::status_completed, |
|
198 | - self::status_fatal_error |
|
199 | - // note: status_no_more_migration_scripts doesn't apply |
|
200 | - ); |
|
201 | - // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
|
202 | - // to be defined, because right now it doesn't get autoloaded on its own |
|
203 | - EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), true); |
|
204 | - EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), true); |
|
205 | - EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), true); |
|
206 | - EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), true); |
|
207 | - EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), true); |
|
208 | - $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
209 | - $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what |
|
215 | - * the option names are like, but generally they're like |
|
216 | - * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that). |
|
217 | - * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived, |
|
218 | - * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php (eg |
|
219 | - * EE_DMS_Core_4_1_0.dms.php) |
|
220 | - * |
|
221 | - * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
|
222 | - * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of |
|
223 | - * that plugin (eg '4.1.0') |
|
224 | - */ |
|
225 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) |
|
226 | - { |
|
227 | - $plugin_slug_and_version_string = str_replace( |
|
228 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
229 | - "", |
|
230 | - $option_name |
|
231 | - ); |
|
232 | - // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
|
233 | - $parts = explode(".", $plugin_slug_and_version_string); |
|
234 | - |
|
235 | - if (count($parts) == 4) { |
|
236 | - // it's 4.2-style.eg Core.4.1.0 |
|
237 | - $plugin_slug = $parts[0];// eg Core |
|
238 | - $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
239 | - } else { |
|
240 | - // it's 4.1-style: eg 4.1.0 |
|
241 | - $plugin_slug = 'Core'; |
|
242 | - $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
243 | - } |
|
244 | - return array($plugin_slug, $version_string); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Gets the DMS class from the wordpress option, otherwise throws an EE_Error if it's not |
|
249 | - * for a known DMS class. |
|
250 | - * |
|
251 | - * @param string $dms_option_name |
|
252 | - * @param string $dms_option_value (serialized) |
|
253 | - * @return EE_Data_Migration_Script_Base |
|
254 | - * @throws EE_Error |
|
255 | - */ |
|
256 | - private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) |
|
257 | - { |
|
258 | - $data_migration_data = maybe_unserialize($dms_option_value); |
|
259 | - if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
260 | - $class = LoaderFactory::getLoader()->getShared($data_migration_data['class']); |
|
261 | - if ($class instanceof EE_Data_Migration_Script_Base) { |
|
262 | - $class->instantiate_from_array_of_properties($data_migration_data); |
|
263 | - return $class; |
|
264 | - } else { |
|
265 | - // huh, so its an object but not a data migration script?? that shouldn't happen |
|
266 | - // just leave it as an array (which will probably just get ignored) |
|
267 | - throw new EE_Error( |
|
268 | - sprintf( |
|
269 | - __( |
|
270 | - "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", |
|
271 | - 'event_espresso' |
|
272 | - ), |
|
273 | - $data_migration_data['class'] |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - } else { |
|
278 | - // 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 |
|
279 | - throw new EE_Error( |
|
280 | - sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name) |
|
281 | - ); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Gets the array describing what data migrations have run. Also has a side-effect of recording which was the last |
|
287 | - * ran, and which was the last ran which hasn't finished yet |
|
288 | - * |
|
289 | - * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy |
|
290 | - * arrays in there - which should probably be ignored) |
|
291 | - */ |
|
292 | - public function get_data_migrations_ran() |
|
293 | - { |
|
294 | - if (! $this->_data_migrations_ran) { |
|
295 | - // setup autoloaders for each of the scripts in there |
|
296 | - $this->get_all_data_migration_scripts_available(); |
|
297 | - $data_migrations_options = $this->get_all_migration_script_options( |
|
298 | - );// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
299 | - |
|
300 | - $data_migrations_ran = array(); |
|
301 | - // convert into data migration script classes where possible |
|
302 | - foreach ($data_migrations_options as $data_migration_option) { |
|
303 | - list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name( |
|
304 | - $data_migration_option['option_name'] |
|
305 | - ); |
|
306 | - |
|
307 | - try { |
|
308 | - $class = $this->_get_dms_class_from_wp_option( |
|
309 | - $data_migration_option['option_name'], |
|
310 | - $data_migration_option['option_value'] |
|
311 | - ); |
|
312 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
313 | - // ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
|
314 | - $this->_last_ran_script = $class; |
|
315 | - if (! $class->is_completed()) { |
|
316 | - // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
|
317 | - $this->_last_ran_incomplete_script = $class; |
|
318 | - } |
|
319 | - } catch (EE_Error $e) { |
|
320 | - // ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
|
321 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
322 | - $data_migration_option['option_value'] |
|
323 | - ); |
|
324 | - } |
|
325 | - } |
|
326 | - // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
|
327 | - $this->_data_migrations_ran = $data_migrations_ran; |
|
328 | - if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
329 | - $this->_data_migrations_ran = array(); |
|
330 | - } |
|
331 | - } |
|
332 | - return $this->_data_migrations_ran; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * |
|
338 | - * @param string $script_name eg 'DMS_Core_4_1_0' |
|
339 | - * @param string $old_table eg 'wp_events_detail' |
|
340 | - * @param string $old_pk eg 'wp_esp_posts' |
|
341 | - * @param $new_table |
|
342 | - * @return mixed string or int |
|
343 | - */ |
|
344 | - public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
|
345 | - { |
|
346 | - $script = EE_Registry::instance()->load_dms($script_name); |
|
347 | - $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
|
348 | - return $mapping; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that |
|
353 | - * the last option returned in this array is the most-recently ran DMS option |
|
354 | - * |
|
355 | - * @return array |
|
356 | - */ |
|
357 | - public function get_all_migration_script_options() |
|
358 | - { |
|
359 | - global $wpdb; |
|
360 | - return $wpdb->get_results( |
|
361 | - "SELECT * FROM {$wpdb->options} WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id ASC", |
|
362 | - ARRAY_A |
|
363 | - ); |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded |
|
368 | - * |
|
369 | - * @return array where each value is the full folder path of a folder containing data migration scripts, WITH |
|
370 | - * slashes at the end of the folder name. |
|
371 | - */ |
|
372 | - public function get_data_migration_script_folders() |
|
373 | - { |
|
374 | - return apply_filters( |
|
375 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
376 | - array('Core' => EE_CORE . 'data_migration_scripts') |
|
377 | - ); |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Gets the version the migration script upgrades to |
|
382 | - * |
|
383 | - * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0' |
|
384 | - * @return array { |
|
385 | - * @type string $slug like 'Core','Calendar',etc |
|
386 | - * @type string $version like 4.3.0 |
|
387 | - * } |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
|
391 | - { |
|
392 | - if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
393 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
394 | - } |
|
395 | - $dms_info = $this->parse_dms_classname($migration_script_name); |
|
396 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
397 | - 'slug' => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
398 | - 'version' => $dms_info['major_version'] . "." . $dms_info['minor_version'] . "." . $dms_info['micro_version'], |
|
399 | - ); |
|
400 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0' |
|
405 | - * |
|
406 | - * @param string $classname |
|
407 | - * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
|
408 | - * @throws EE_Error |
|
409 | - */ |
|
410 | - public function parse_dms_classname($classname) |
|
411 | - { |
|
412 | - $matches = array(); |
|
413 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
414 | - if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
415 | - throw new EE_Error( |
|
416 | - sprintf( |
|
417 | - __( |
|
418 | - "%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, ", |
|
419 | - "event_espresso" |
|
420 | - ), |
|
421 | - $classname |
|
422 | - ) |
|
423 | - ); |
|
424 | - } |
|
425 | - return array( |
|
426 | - 'slug' => $matches[1], |
|
427 | - 'major_version' => intval($matches[2]), |
|
428 | - 'minor_version' => intval($matches[3]), |
|
429 | - 'micro_version' => intval($matches[4]), |
|
430 | - ); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Ensures that the option indicating the current DB version is set. This should only be |
|
435 | - * a concern when activating EE for the first time, THEORETICALLY. |
|
436 | - * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise |
|
437 | - * to 4.1.x. |
|
438 | - * |
|
439 | - * @return string of current db state |
|
440 | - */ |
|
441 | - public function ensure_current_database_state_is_set() |
|
442 | - { |
|
443 | - $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
444 | - $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
|
445 | - if (! $db_state) { |
|
446 | - // mark the DB as being in the state as the last version in there. |
|
447 | - // this is done to trigger maintenance mode and do data migration scripts |
|
448 | - // if the admin installed this version of EE over 3.1.x or 4.0.x |
|
449 | - // otherwise, the normal maintenance mode code is fine |
|
450 | - $previous_versions_installed = array_keys($espresso_db_core_updates); |
|
451 | - $previous_version_installed = end($previous_versions_installed); |
|
452 | - if (version_compare('4.1.0', $previous_version_installed)) { |
|
453 | - // last installed version was less than 4.1 |
|
454 | - // so we want the data migrations to happen. SO, we're going to say the DB is at that state |
|
455 | - $db_state = array('Core' => $previous_version_installed); |
|
456 | - } else { |
|
457 | - $db_state = array('Core' => EVENT_ESPRESSO_VERSION); |
|
458 | - } |
|
459 | - update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
460 | - } |
|
461 | - // in 4.1, $db_state would have only been a simple string like '4.1.0', |
|
462 | - // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
|
463 | - // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
|
464 | - if (! is_array($db_state)) { |
|
465 | - $db_state = array('Core' => $db_state); |
|
466 | - update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
467 | - } |
|
468 | - return $db_state; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Checks if there are any data migration scripts that ought to be run. If found, |
|
473 | - * returns the instantiated classes. If none are found (ie, they've all already been run |
|
474 | - * or they don't apply), returns an empty array |
|
475 | - * |
|
476 | - * @return EE_Data_Migration_Script_Base[] |
|
477 | - */ |
|
478 | - public function check_for_applicable_data_migration_scripts() |
|
479 | - { |
|
480 | - // get the option describing what options have already run |
|
481 | - $scripts_ran = $this->get_data_migrations_ran(); |
|
482 | - // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
|
483 | - $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available(); |
|
484 | - |
|
485 | - |
|
486 | - $current_database_state = $this->ensure_current_database_state_is_set(); |
|
487 | - // determine which have already been run |
|
488 | - $script_classes_that_should_run_per_iteration = array(); |
|
489 | - $iteration = 0; |
|
490 | - $next_database_state_to_consider = $current_database_state; |
|
491 | - $theoretical_database_state = null; |
|
492 | - do { |
|
493 | - // the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
|
494 | - $theoretical_database_state = $next_database_state_to_consider; |
|
495 | - // 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?) |
|
496 | - foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
497 | - $migrates_to_version = $this->script_migrates_to_version($classname); |
|
498 | - $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
499 | - $script_converts_to_version = $migrates_to_version['version']; |
|
500 | - // check if this version script is DONE or not; or if it's never been ran |
|
501 | - if (! $scripts_ran || |
|
502 | - ! isset($scripts_ran[ $script_converts_plugin_slug ]) || |
|
503 | - ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ])) { |
|
504 | - // we haven't ran this conversion script before |
|
505 | - // now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
|
506 | - $script = LoaderFactory::getLoader()->load($classname); |
|
507 | - /* @var $script EE_Data_Migration_Script_Base */ |
|
508 | - $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
|
509 | - if ($can_migrate) { |
|
510 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
511 | - $migrates_to_version = $script->migrates_to_version(); |
|
512 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version']; |
|
513 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
514 | - } |
|
515 | - } elseif ($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] instanceof EE_Data_Migration_Script_Base) { |
|
516 | - // this script has been ran, or at least started |
|
517 | - $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
518 | - if ($script->get_status() != self::status_completed) { |
|
519 | - // this script is already underway... keep going with it |
|
520 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
521 | - $migrates_to_version = $script->migrates_to_version(); |
|
522 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version']; |
|
523 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
524 | - } else { |
|
525 | - // it must have a status that indicates it has finished, so we don't want to try and run it again |
|
526 | - } |
|
527 | - } else { |
|
528 | - // it exists but it's not a proper data migration script |
|
529 | - // maybe the script got renamed? or was simply removed from EE? |
|
530 | - // either way, its certainly not runnable! |
|
531 | - } |
|
532 | - } |
|
533 | - $iteration++; |
|
534 | - } while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
535 | - // ok we have all the scripts that should run, now let's make them into flat array |
|
536 | - $scripts_that_should_run = array(); |
|
537 | - foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
538 | - ksort($scripts_at_priority); |
|
539 | - foreach ($scripts_at_priority as $scripts) { |
|
540 | - foreach ($scripts as $script) { |
|
541 | - $scripts_that_should_run[ get_class($script) ] = $script; |
|
542 | - } |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - do_action( |
|
547 | - 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', |
|
548 | - $scripts_that_should_run |
|
549 | - ); |
|
550 | - return $scripts_that_should_run; |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * Gets the script which is currently being ran, if there is one. If $include_completed_scripts is set to TRUE |
|
556 | - * it will return the last ran script even if its complete. |
|
557 | - * This means: if you want to find the currently-executing script, leave it as FALSE. |
|
558 | - * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE. |
|
559 | - * |
|
560 | - * @param bool $include_completed_scripts |
|
561 | - * @return EE_Data_Migration_Script_Base |
|
562 | - */ |
|
563 | - public function get_last_ran_script($include_completed_scripts = false) |
|
564 | - { |
|
565 | - // make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
|
566 | - if (! $this->_data_migrations_ran) { |
|
567 | - $this->get_data_migrations_ran(); |
|
568 | - } |
|
569 | - if ($include_completed_scripts) { |
|
570 | - return $this->_last_ran_script; |
|
571 | - } else { |
|
572 | - return $this->_last_ran_incomplete_script; |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Runs the data migration scripts (well, each request to this method calls one of the |
|
579 | - * data migration scripts' migration_step() functions). |
|
580 | - * |
|
581 | - * @param int $step_size |
|
582 | - * @throws EE_Error |
|
583 | - * @return array { |
|
584 | - * // where the first item is one EE_Data_Migration_Script_Base's stati, |
|
585 | - * //and the second item is a string describing what was done |
|
586 | - * @type int $records_to_migrate from the current migration script |
|
587 | - * @type int $records_migrated |
|
588 | - * @type string $status one of EE_Data_Migration_Manager::status_* |
|
589 | - * @type string $script verbose name of the current DMS |
|
590 | - * @type string $message string describing what was done during this step |
|
591 | - * } |
|
592 | - */ |
|
593 | - public function migration_step($step_size = 0) |
|
594 | - { |
|
595 | - |
|
596 | - // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
|
597 | - if (class_exists('EE_CPT_Strategy')) { |
|
598 | - remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
599 | - } |
|
600 | - |
|
601 | - try { |
|
602 | - $currently_executing_script = $this->get_last_ran_script(); |
|
603 | - if (! $currently_executing_script) { |
|
604 | - // Find the next script that needs to execute |
|
605 | - $scripts = $this->check_for_applicable_data_migration_scripts(); |
|
606 | - if (! $scripts) { |
|
607 | - // huh, no more scripts to run... apparently we're done! |
|
608 | - // but dont forget to make sure initial data is there |
|
609 | - // we should be good to allow them to exit maintenance mode now |
|
610 | - EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
611 | - intval(EE_Maintenance_Mode::level_0_not_in_maintenance) |
|
612 | - ); |
|
613 | - // saving migrations ran should actually be unnecessary, but leaving in place just in case |
|
614 | - // remember this migration was finished (even if we timeout initing db for core and plugins) |
|
615 | - $this->_save_migrations_ran(); |
|
616 | - // make sure DB was updated AFTER we've recorded the migration was done |
|
617 | - $this->initialize_db_for_enqueued_ee_plugins(); |
|
618 | - return array( |
|
619 | - 'records_to_migrate' => 1, |
|
620 | - 'records_migrated' => 1, |
|
621 | - 'status' => self::status_no_more_migration_scripts, |
|
622 | - 'script' => __("Data Migration Completed Successfully", "event_espresso"), |
|
623 | - 'message' => __("All done!", "event_espresso"), |
|
624 | - ); |
|
625 | - } |
|
626 | - $currently_executing_script = array_shift($scripts); |
|
627 | - // and add to the array/wp option showing the scripts ran |
|
628 | - |
|
629 | - $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
|
630 | - $plugin_slug = $migrates_to['slug']; |
|
631 | - $version = $migrates_to['version']; |
|
632 | - $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
633 | - } |
|
634 | - $current_script_name = get_class($currently_executing_script); |
|
635 | - } catch (Exception $e) { |
|
636 | - // an exception occurred while trying to get migration scripts |
|
637 | - |
|
638 | - $message = sprintf( |
|
639 | - __("Error Message: %sStack Trace:%s", "event_espresso"), |
|
640 | - $e->getMessage() . '<br>', |
|
641 | - $e->getTraceAsString() |
|
642 | - ); |
|
643 | - // record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
|
644 | - // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
|
645 | - $this->add_error_to_migrations_ran( |
|
646 | - sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message) |
|
647 | - ); |
|
648 | - return array( |
|
649 | - 'records_to_migrate' => 1, |
|
650 | - 'records_migrated' => 0, |
|
651 | - 'status' => self::status_fatal_error, |
|
652 | - 'script' => __("Error loading data migration scripts", "event_espresso"), |
|
653 | - 'message' => $message, |
|
654 | - ); |
|
655 | - } |
|
656 | - // ok so we definitely have a data migration script |
|
657 | - try { |
|
658 | - // how big of a bite do we want to take? Allow users to easily override via their wp-config |
|
659 | - if (absint($step_size) < 1) { |
|
660 | - $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) |
|
661 | - ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
662 | - } |
|
663 | - // do what we came to do! |
|
664 | - $currently_executing_script->migration_step($step_size); |
|
665 | - // can we wrap it up and verify default data? |
|
666 | - $init_dbs = false; |
|
667 | - switch ($currently_executing_script->get_status()) { |
|
668 | - case EE_Data_Migration_Manager::status_continue: |
|
669 | - $response_array = array( |
|
670 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
671 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
672 | - 'status' => EE_Data_Migration_Manager::status_continue, |
|
673 | - 'message' => $currently_executing_script->get_feedback_message(), |
|
674 | - 'script' => $currently_executing_script->pretty_name(), |
|
675 | - ); |
|
676 | - break; |
|
677 | - case EE_Data_Migration_Manager::status_completed: |
|
678 | - // ok so THAT script has completed |
|
679 | - $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
|
680 | - $response_array = array( |
|
681 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
682 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
683 | - 'status' => EE_Data_Migration_Manager::status_completed, |
|
684 | - 'message' => $currently_executing_script->get_feedback_message(), |
|
685 | - 'script' => sprintf( |
|
686 | - __("%s Completed", 'event_espresso'), |
|
687 | - $currently_executing_script->pretty_name() |
|
688 | - ), |
|
689 | - ); |
|
690 | - // check if there are any more after this one. |
|
691 | - $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
|
692 | - if (! $scripts_remaining) { |
|
693 | - // we should be good to allow them to exit maintenance mode now |
|
694 | - EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
695 | - intval(EE_Maintenance_Mode::level_0_not_in_maintenance) |
|
696 | - ); |
|
697 | - // huh, no more scripts to run... apparently we're done! |
|
698 | - // but dont forget to make sure initial data is there |
|
699 | - $init_dbs = true; |
|
700 | - $response_array['status'] = self::status_no_more_migration_scripts; |
|
701 | - } |
|
702 | - break; |
|
703 | - default: |
|
704 | - $response_array = array( |
|
705 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
706 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
707 | - 'status' => $currently_executing_script->get_status(), |
|
708 | - 'message' => sprintf( |
|
709 | - __("Minor errors occurred during %s: %s", "event_espresso"), |
|
710 | - $currently_executing_script->pretty_name(), |
|
711 | - implode(", ", $currently_executing_script->get_errors()) |
|
712 | - ), |
|
713 | - 'script' => $currently_executing_script->pretty_name(), |
|
714 | - ); |
|
715 | - break; |
|
716 | - } |
|
717 | - } catch (Exception $e) { |
|
718 | - // ok so some exception was thrown which killed the data migration script |
|
719 | - // double-check we have a real script |
|
720 | - if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
721 | - $script_name = $currently_executing_script->pretty_name(); |
|
722 | - $currently_executing_script->set_broken(); |
|
723 | - $currently_executing_script->add_error($e->getMessage()); |
|
724 | - } else { |
|
725 | - $script_name = __("Error getting Migration Script", "event_espresso"); |
|
726 | - } |
|
727 | - $response_array = array( |
|
728 | - 'records_to_migrate' => 1, |
|
729 | - 'records_migrated' => 0, |
|
730 | - 'status' => self::status_fatal_error, |
|
731 | - 'message' => sprintf( |
|
732 | - __("A fatal error occurred during the migration: %s", "event_espresso"), |
|
733 | - $e->getMessage() |
|
734 | - ), |
|
735 | - 'script' => $script_name, |
|
736 | - ); |
|
737 | - } |
|
738 | - $successful_save = $this->_save_migrations_ran(); |
|
739 | - if ($successful_save !== true) { |
|
740 | - // ok so the current wp option didn't save. that's tricky, because we'd like to update it |
|
741 | - // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
|
742 | - // however, if we throw an exception, and return that, then the next request |
|
743 | - // won't have as much info in it, and it may be able to save |
|
744 | - throw new EE_Error( |
|
745 | - sprintf( |
|
746 | - __( |
|
747 | - "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.", |
|
748 | - "event_espresso" |
|
749 | - ), |
|
750 | - $successful_save |
|
751 | - ) |
|
752 | - ); |
|
753 | - } |
|
754 | - // if we're all done, initialize EE plugins' default data etc. |
|
755 | - if ($init_dbs) { |
|
756 | - $this->initialize_db_for_enqueued_ee_plugins(); |
|
757 | - } |
|
758 | - return $response_array; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * Echo out JSON response to migration script AJAX requests. Takes precautions |
|
764 | - * to buffer output so that we don't throw junk into our json. |
|
765 | - * |
|
766 | - * @return array with keys: |
|
767 | - * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie, |
|
768 | - * it's NOT the count of hwo many remain) |
|
769 | - * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete = |
|
770 | - * records_migrated/records_to_migrate) |
|
771 | - * 'status'=>a string, one of EE_Data_migration_Manager::status_* |
|
772 | - * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into |
|
773 | - * errors, notifications, and successes |
|
774 | - * 'script'=>a pretty name of the script currently running |
|
775 | - */ |
|
776 | - public function response_to_migration_ajax_request() |
|
777 | - { |
|
778 | - ob_start(); |
|
779 | - try { |
|
780 | - $response = $this->migration_step(); |
|
781 | - } catch (Exception $e) { |
|
782 | - $response = array( |
|
783 | - 'records_to_migrate' => 0, |
|
784 | - 'records_migrated' => 0, |
|
785 | - 'status' => EE_Data_Migration_Manager::status_fatal_error, |
|
786 | - 'message' => sprintf( |
|
787 | - __("Unknown fatal error occurred: %s", "event_espresso"), |
|
788 | - $e->getMessage() |
|
789 | - ), |
|
790 | - 'script' => 'Unknown', |
|
791 | - ); |
|
792 | - $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
793 | - } |
|
794 | - $warnings_etc = @ob_get_contents(); |
|
795 | - ob_end_clean(); |
|
796 | - $response['message'] .= $warnings_etc; |
|
797 | - return $response; |
|
798 | - } |
|
799 | - |
|
800 | - /** |
|
801 | - * Updates the wordpress option that keeps track of which which EE version the database |
|
802 | - * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35) |
|
803 | - * |
|
804 | - * @param array $slug_and_version { |
|
805 | - * @type string $slug like 'Core' or 'Calendar', |
|
806 | - * @type string $version like '4.1.0' |
|
807 | - * } |
|
808 | - * @return void |
|
809 | - */ |
|
810 | - public function update_current_database_state_to($slug_and_version = null) |
|
811 | - { |
|
812 | - if (! $slug_and_version) { |
|
813 | - // no version was provided, assume it should be at the current code version |
|
814 | - $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
|
815 | - } |
|
816 | - $current_database_state = get_option(self::current_database_state); |
|
817 | - $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
818 | - update_option(self::current_database_state, $current_database_state); |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Determines if the database is currently at a state matching what's indicated in $slug and $version. |
|
823 | - * |
|
824 | - * @param array $slug_and_version { |
|
825 | - * @type string $slug like 'Core' or 'Calendar', |
|
826 | - * @type string $version like '4.1.0' |
|
827 | - * } |
|
828 | - * @return boolean |
|
829 | - */ |
|
830 | - public function database_needs_updating_to($slug_and_version) |
|
831 | - { |
|
832 | - |
|
833 | - $slug = $slug_and_version['slug']; |
|
834 | - $version = $slug_and_version['version']; |
|
835 | - $current_database_state = get_option(self::current_database_state); |
|
836 | - if (! isset($current_database_state[ $slug ])) { |
|
837 | - return true; |
|
838 | - } else { |
|
839 | - // 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 |
|
840 | - $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
841 | - $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
842 | - $needs_updating = false; |
|
843 | - foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
844 | - if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
845 | - $needs_updating = true; |
|
846 | - break; |
|
847 | - } |
|
848 | - } |
|
849 | - return $needs_updating; |
|
850 | - } |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * Gets all the data migration scripts available in the core folder and folders |
|
856 | - * in addons. Has the side effect of adding them for autoloading |
|
857 | - * |
|
858 | - * @return array keys are expected classnames, values are their filepaths |
|
859 | - * @throws InvalidInterfaceException |
|
860 | - * @throws InvalidDataTypeException |
|
861 | - * @throws EE_Error |
|
862 | - * @throws InvalidArgumentException |
|
863 | - */ |
|
864 | - public function get_all_data_migration_scripts_available() |
|
865 | - { |
|
866 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
867 | - $this->_data_migration_class_to_filepath_map = array(); |
|
868 | - foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
869 | - // strip any placeholders added to classname to make it a unique array key |
|
870 | - $eeAddonClass = trim($eeAddonClass, '*'); |
|
871 | - $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
872 | - ? $eeAddonClass |
|
873 | - : ''; |
|
874 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
875 | - $files = glob($folder_path . '*.dms.php'); |
|
876 | - if (empty($files)) { |
|
877 | - continue; |
|
878 | - } |
|
879 | - foreach ($files as $file) { |
|
880 | - $pos_of_last_slash = strrpos($file, '/'); |
|
881 | - $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
882 | - $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
883 | - $slug = $migrates_to['slug']; |
|
884 | - // check that the slug as contained in the DMS is associated with |
|
885 | - // the slug of an addon or core |
|
886 | - if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
887 | - EE_Error::doing_it_wrong( |
|
888 | - __FUNCTION__, |
|
889 | - sprintf( |
|
890 | - esc_html__( |
|
891 | - 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
892 | - 'event_espresso' |
|
893 | - ), |
|
894 | - $classname, |
|
895 | - $slug, |
|
896 | - implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
897 | - ), |
|
898 | - '4.3.0.alpha.019' |
|
899 | - ); |
|
900 | - } |
|
901 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
902 | - } |
|
903 | - } |
|
904 | - EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
905 | - } |
|
906 | - return $this->_data_migration_class_to_filepath_map; |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs |
|
912 | - * from each addon, and check if they need updating, |
|
913 | - * |
|
914 | - * @return boolean |
|
915 | - */ |
|
916 | - public function addons_need_updating() |
|
917 | - { |
|
918 | - return false; |
|
919 | - } |
|
920 | - |
|
921 | - /** |
|
922 | - * Adds this error string to the data_migrations_ran array, but we dont necessarily know |
|
923 | - * where to put it, so we just throw it in there... better than nothing... |
|
924 | - * |
|
925 | - * @param string $error_message |
|
926 | - * @throws EE_Error |
|
927 | - */ |
|
928 | - public function add_error_to_migrations_ran($error_message) |
|
929 | - { |
|
930 | - // get last-ran migration script |
|
931 | - global $wpdb; |
|
932 | - $last_migration_script_option = $wpdb->get_row( |
|
933 | - "SELECT * FROM $wpdb->options WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id DESC LIMIT 1", |
|
934 | - ARRAY_A |
|
935 | - ); |
|
936 | - |
|
937 | - $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) |
|
938 | - ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
|
939 | - // now, tread lightly because we're here because a FATAL non-catchable error |
|
940 | - // was thrown last time when we were trying to run a data migration script |
|
941 | - // so the fatal error could have happened while getting the migration script |
|
942 | - // or doing running it... |
|
943 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace( |
|
944 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
945 | - "", |
|
946 | - $last_migration_script_option['option_name'] |
|
947 | - ) : null; |
|
948 | - |
|
949 | - // check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
|
950 | - // because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
|
951 | - if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
952 | - // ok then just add this error to its list of errors |
|
953 | - $last_ran_migration_script_properties['_errors'][] = $error_message; |
|
954 | - $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
|
955 | - } else { |
|
956 | - // so we don't even know which script was last running |
|
957 | - // use the data migration error stub, which is designed specifically for this type of thing |
|
958 | - $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
|
959 | - $general_migration_error->add_error($error_message); |
|
960 | - $general_migration_error->set_broken(); |
|
961 | - $last_ran_migration_script_properties = $general_migration_error->properties_as_array(); |
|
962 | - $versions_migrated_to = 'Unknown.1.0.0'; |
|
963 | - // now just to make sure appears as last (in case the were previously a fatal error like this) |
|
964 | - // delete the old one |
|
965 | - delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
966 | - } |
|
967 | - update_option( |
|
968 | - self::data_migration_script_option_prefix . $versions_migrated_to, |
|
969 | - $last_ran_migration_script_properties |
|
970 | - ); |
|
971 | - } |
|
972 | - |
|
973 | - /** |
|
974 | - * saves what data migrations have ran to the database |
|
975 | - * |
|
976 | - * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
|
977 | - */ |
|
978 | - protected function _save_migrations_ran() |
|
979 | - { |
|
980 | - if ($this->_data_migrations_ran == null) { |
|
981 | - $this->get_data_migrations_ran(); |
|
982 | - } |
|
983 | - // now, we don't want to save actual classes to the DB because that's messy |
|
984 | - $successful_updates = true; |
|
985 | - foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
986 | - foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
987 | - $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
988 | - $option_name = self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
989 | - $old_option_value = get_option($option_name); |
|
990 | - if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
991 | - $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
|
992 | - if ($old_option_value != $script_array_for_saving) { |
|
993 | - $successful_updates = update_option($option_name, $script_array_for_saving); |
|
994 | - } |
|
995 | - } else {// we don't know what this array-thing is. So just save it as-is |
|
996 | - if ($old_option_value != $array_or_migration_obj) { |
|
997 | - $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
998 | - } |
|
999 | - } |
|
1000 | - if (! $successful_updates) { |
|
1001 | - global $wpdb; |
|
1002 | - return $wpdb->last_error; |
|
1003 | - } |
|
1004 | - } |
|
1005 | - } |
|
1006 | - return true; |
|
1007 | - // $updated = update_option(self::data_migrations_option_name, $array_of_migrations); |
|
1008 | - // if ($updated !== true) { |
|
1009 | - // global $wpdb; |
|
1010 | - // return $wpdb->last_error; |
|
1011 | - // } else { |
|
1012 | - // return true; |
|
1013 | - // } |
|
1014 | - // wp_mail( |
|
1015 | - // "[email protected]", |
|
1016 | - // time() . " price debug info", |
|
1017 | - // "updated: $updated, last error: $last_error, byte length of option: " . strlen( |
|
1018 | - // serialize($array_of_migrations) |
|
1019 | - // ) |
|
1020 | - // ); |
|
1021 | - } |
|
1022 | - |
|
1023 | - /** |
|
1024 | - * Takes an array of data migration script properties and re-creates the class from |
|
1025 | - * them. The argument $properties_array is assumed to have been made by |
|
1026 | - * EE_Data_Migration_Script_Base::properties_as_array() |
|
1027 | - * |
|
1028 | - * @param array $properties_array |
|
1029 | - * @return EE_Data_Migration_Script_Base |
|
1030 | - * @throws EE_Error |
|
1031 | - */ |
|
1032 | - public function _instantiate_script_from_properties_array($properties_array) |
|
1033 | - { |
|
1034 | - if (! isset($properties_array['class'])) { |
|
1035 | - throw new EE_Error( |
|
1036 | - sprintf( |
|
1037 | - __("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
|
1038 | - implode(",", $properties_array) |
|
1039 | - ) |
|
1040 | - ); |
|
1041 | - } |
|
1042 | - $class_name = $properties_array['class']; |
|
1043 | - if (! class_exists($class_name)) { |
|
1044 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
1045 | - } |
|
1046 | - $class = new $class_name; |
|
1047 | - if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
1048 | - throw new EE_Error( |
|
1049 | - sprintf( |
|
1050 | - __("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), |
|
1051 | - $class_name, |
|
1052 | - get_class($class) |
|
1053 | - ) |
|
1054 | - ); |
|
1055 | - } |
|
1056 | - $class->instantiate_from_array_of_properties($properties_array); |
|
1057 | - return $class; |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Gets the classname for the most up-to-date DMS (ie, the one that will finally |
|
1062 | - * leave the DB in a state usable by the current plugin code). |
|
1063 | - * |
|
1064 | - * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
|
1065 | - * @return string |
|
1066 | - */ |
|
1067 | - public function get_most_up_to_date_dms($plugin_slug = 'Core') |
|
1068 | - { |
|
1069 | - $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
|
1070 | - $most_up_to_date_dms_classname = null; |
|
1071 | - foreach ($class_to_filepath_map as $classname => $filepath) { |
|
1072 | - if ($most_up_to_date_dms_classname === null) { |
|
1073 | - $migrates_to = $this->script_migrates_to_version($classname); |
|
1074 | - $this_plugin_slug = $migrates_to['slug']; |
|
1075 | - if ($this_plugin_slug == $plugin_slug) { |
|
1076 | - // if it's for core, it wins |
|
1077 | - $most_up_to_date_dms_classname = $classname; |
|
1078 | - } |
|
1079 | - // if it wasn't for core, we must keep searching for one that is! |
|
1080 | - continue; |
|
1081 | - } else { |
|
1082 | - $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
1083 | - $contender_migrates_to = $this->script_migrates_to_version($classname); |
|
1084 | - if ($contender_migrates_to['slug'] == $plugin_slug |
|
1085 | - && version_compare( |
|
1086 | - $champion_migrates_to['version'], |
|
1087 | - $contender_migrates_to['version'], |
|
1088 | - '<' |
|
1089 | - )) { |
|
1090 | - // so the contenders version is higher and its for Core |
|
1091 | - $most_up_to_date_dms_classname = $classname; |
|
1092 | - } |
|
1093 | - } |
|
1094 | - } |
|
1095 | - return $most_up_to_date_dms_classname; |
|
1096 | - } |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * Gets the migration script specified but ONLY if it has already ran. |
|
1100 | - * |
|
1101 | - * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has ran, you would run the following code: |
|
1102 | - * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !== |
|
1103 | - * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or |
|
1104 | - * other addon) DMS has ran, in case the current DMS depends on it. |
|
1105 | - * |
|
1106 | - * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1107 | - * period. Eg '4.1.0' |
|
1108 | - * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1109 | - * @return EE_Data_Migration_Script_Base |
|
1110 | - */ |
|
1111 | - public function get_migration_ran($version, $plugin_slug = 'Core') |
|
1112 | - { |
|
1113 | - $migrations_ran = $this->get_data_migrations_ran(); |
|
1114 | - if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
1115 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
1116 | - } else { |
|
1117 | - return null; |
|
1118 | - } |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * Resets the borked data migration scripts so they're no longer borked |
|
1123 | - * so we can again attempt to migrate |
|
1124 | - * |
|
1125 | - * @return bool |
|
1126 | - * @throws EE_Error |
|
1127 | - */ |
|
1128 | - public function reattempt() |
|
1129 | - { |
|
1130 | - // find if the last-ran script was borked |
|
1131 | - // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
|
1132 | - // add an 'error' saying that we attempted to reset |
|
1133 | - // does it have a stage that was borked too? if so make it no longer borked |
|
1134 | - // add an 'error' saying we attempted to reset |
|
1135 | - $last_ran_script = $this->get_last_ran_script(); |
|
1136 | - if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
1137 | - // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
|
1138 | - $last_ran_script->set_completed(); |
|
1139 | - } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
1140 | - $last_ran_script->reattempt(); |
|
1141 | - } else { |
|
1142 | - throw new EE_Error( |
|
1143 | - sprintf( |
|
1144 | - __( |
|
1145 | - 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', |
|
1146 | - 'event_espresso' |
|
1147 | - ), |
|
1148 | - print_r($last_ran_script, true) |
|
1149 | - ) |
|
1150 | - ); |
|
1151 | - } |
|
1152 | - return $this->_save_migrations_ran(); |
|
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Gets whether or not this particular migration has run or not |
|
1157 | - * |
|
1158 | - * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1159 | - * period. Eg '4.1.0' |
|
1160 | - * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1161 | - * @return boolean |
|
1162 | - */ |
|
1163 | - public function migration_has_ran($version, $plugin_slug = 'Core') |
|
1164 | - { |
|
1165 | - return $this->get_migration_ran($version, $plugin_slug) !== null; |
|
1166 | - } |
|
1167 | - |
|
1168 | - /** |
|
1169 | - * Enqueues this ee plugin to have its data initialized |
|
1170 | - * |
|
1171 | - * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
|
1172 | - */ |
|
1173 | - public function enqueue_db_initialization_for($plugin_slug) |
|
1174 | - { |
|
1175 | - $queue = $this->get_db_initialization_queue(); |
|
1176 | - if (! in_array($plugin_slug, $queue)) { |
|
1177 | - $queue[] = $plugin_slug; |
|
1178 | - } |
|
1179 | - update_option(self::db_init_queue_option_name, $queue); |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
|
1184 | - * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is |
|
1185 | - * in the queue, calls EE_System::initialize_db_if_no_migrations_required(). |
|
1186 | - */ |
|
1187 | - public function initialize_db_for_enqueued_ee_plugins() |
|
1188 | - { |
|
1189 | - $queue = $this->get_db_initialization_queue(); |
|
1190 | - foreach ($queue as $plugin_slug) { |
|
1191 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
1192 | - if (! $most_up_to_date_dms) { |
|
1193 | - // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
|
1194 | - $verify_db = false; |
|
1195 | - } else { |
|
1196 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1197 | - $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1198 | - } |
|
1199 | - if ($plugin_slug == 'Core') { |
|
1200 | - EE_System::instance()->initialize_db_if_no_migrations_required( |
|
1201 | - false, |
|
1202 | - $verify_db |
|
1203 | - ); |
|
1204 | - } else { |
|
1205 | - // just loop through the addons to make sure their database is setup |
|
1206 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
1207 | - if ($addon->name() == $plugin_slug) { |
|
1208 | - $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1209 | - break; |
|
1210 | - } |
|
1211 | - } |
|
1212 | - } |
|
1213 | - } |
|
1214 | - // because we just initialized the DBs for the enqueued ee plugins |
|
1215 | - // we don't need to keep remembering which ones needed to be initialized |
|
1216 | - delete_option(self::db_init_queue_option_name); |
|
1217 | - } |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * Gets a numerically-indexed array of plugin slugs that need to have their databases |
|
1221 | - * (re-)initialized after migrations are complete. ie, each element should be either |
|
1222 | - * 'Core', or the return value of EE_Addon::name() for an addon |
|
1223 | - * |
|
1224 | - * @return array |
|
1225 | - */ |
|
1226 | - public function get_db_initialization_queue() |
|
1227 | - { |
|
1228 | - return get_option(self::db_init_queue_option_name, array()); |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * Gets the injected table analyzer, or throws an exception |
|
1233 | - * |
|
1234 | - * @return TableAnalysis |
|
1235 | - * @throws EE_Error |
|
1236 | - */ |
|
1237 | - protected function _get_table_analysis() |
|
1238 | - { |
|
1239 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
1240 | - return $this->_table_analysis; |
|
1241 | - } else { |
|
1242 | - throw new EE_Error( |
|
1243 | - sprintf( |
|
1244 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1245 | - get_class($this) |
|
1246 | - ) |
|
1247 | - ); |
|
1248 | - } |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Gets the injected table manager, or throws an exception |
|
1253 | - * |
|
1254 | - * @return TableManager |
|
1255 | - * @throws EE_Error |
|
1256 | - */ |
|
1257 | - protected function _get_table_manager() |
|
1258 | - { |
|
1259 | - if ($this->_table_manager instanceof TableManager) { |
|
1260 | - return $this->_table_manager; |
|
1261 | - } else { |
|
1262 | - throw new EE_Error( |
|
1263 | - sprintf( |
|
1264 | - __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1265 | - get_class($this) |
|
1266 | - ) |
|
1267 | - ); |
|
1268 | - } |
|
1269 | - } |
|
36 | + /** |
|
37 | + * |
|
38 | + * @var EE_Registry |
|
39 | + */ |
|
40 | + // protected $EE; |
|
41 | + /** |
|
42 | + * name of the wordpress option which stores an array of data about |
|
43 | + */ |
|
44 | + const data_migrations_option_name = 'ee_data_migration'; |
|
45 | + |
|
46 | + |
|
47 | + const data_migration_script_option_prefix = 'ee_data_migration_script_'; |
|
48 | + |
|
49 | + const data_migration_script_mapping_option_prefix = 'ee_dms_map_'; |
|
50 | + |
|
51 | + /** |
|
52 | + * name of the wordpress option which stores the database' current version. IE, the code may be at version 4.2.0, |
|
53 | + * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc. |
|
54 | + */ |
|
55 | + const current_database_state = 'ee_data_migration_current_db_state'; |
|
56 | + |
|
57 | + /** |
|
58 | + * Special status string returned when we're positive there are no more data migration |
|
59 | + * scripts that can be run. |
|
60 | + */ |
|
61 | + const status_no_more_migration_scripts = 'no_more_migration_scripts'; |
|
62 | + /** |
|
63 | + * string indicating the migration should continue |
|
64 | + */ |
|
65 | + const status_continue = 'status_continue'; |
|
66 | + /** |
|
67 | + * string indicating the migration has completed and should be ended |
|
68 | + */ |
|
69 | + const status_completed = 'status_completed'; |
|
70 | + /** |
|
71 | + * string indicating a fatal error occurred and the data migration should be completely aborted |
|
72 | + */ |
|
73 | + const status_fatal_error = 'status_fatal_error'; |
|
74 | + |
|
75 | + /** |
|
76 | + * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent |
|
77 | + * during migration) |
|
78 | + */ |
|
79 | + const step_size = 50; |
|
80 | + |
|
81 | + /** |
|
82 | + * option name that stores the queue of ee plugins needing to have |
|
83 | + * their data initialized (or re-initialized) once we are done migrations |
|
84 | + */ |
|
85 | + const db_init_queue_option_name = 'ee_db_init_queue'; |
|
86 | + /** |
|
87 | + * Array of information concerning data migrations that have ran in the history |
|
88 | + * of this EE installation. Keys should be the name of the version the script upgraded to |
|
89 | + * |
|
90 | + * @var EE_Data_Migration_Script_Base[] |
|
91 | + */ |
|
92 | + private $_data_migrations_ran = null; |
|
93 | + /** |
|
94 | + * The last ran script. It's nice to store this somewhere accessible, as its easiest |
|
95 | + * to know which was the last run by which is the newest wp option; but in most of the code |
|
96 | + * we just use the local $_data_migration_ran array, which organized the scripts differently |
|
97 | + * |
|
98 | + * @var EE_Data_Migration_Script_Base |
|
99 | + */ |
|
100 | + private $_last_ran_script = null; |
|
101 | + |
|
102 | + /** |
|
103 | + * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script. |
|
104 | + * |
|
105 | + * @var EE_Data_Migration_Script_Base |
|
106 | + */ |
|
107 | + private $_last_ran_incomplete_script = null; |
|
108 | + /** |
|
109 | + * array where keys are classnames, and values are filepaths of all the known migration scripts |
|
110 | + * |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + private $_data_migration_class_to_filepath_map; |
|
114 | + |
|
115 | + /** |
|
116 | + * the following 4 properties are fully set on construction. |
|
117 | + * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished |
|
118 | + * one, we may want to start the next one); whereas the last two indicate whether to continue running a single |
|
119 | + * data migration script |
|
120 | + * |
|
121 | + * @var array |
|
122 | + */ |
|
123 | + public $stati_that_indicate_to_continue_migrations = array(); |
|
124 | + |
|
125 | + public $stati_that_indicate_to_stop_migrations = array(); |
|
126 | + |
|
127 | + public $stati_that_indicate_to_continue_single_migration_script = array(); |
|
128 | + |
|
129 | + public $stati_that_indicate_to_stop_single_migration_script = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
133 | + */ |
|
134 | + protected $_table_manager; |
|
135 | + |
|
136 | + /** |
|
137 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
138 | + */ |
|
139 | + protected $_table_analysis; |
|
140 | + |
|
141 | + /** |
|
142 | + * @var array $script_migration_versions |
|
143 | + */ |
|
144 | + protected $script_migration_versions; |
|
145 | + |
|
146 | + /** |
|
147 | + * @var EE_Data_Migration_Manager $_instance |
|
148 | + * @access private |
|
149 | + */ |
|
150 | + private static $_instance = null; |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @singleton method used to instantiate class object |
|
155 | + * @access public |
|
156 | + * @return EE_Data_Migration_Manager instance |
|
157 | + */ |
|
158 | + public static function instance() |
|
159 | + { |
|
160 | + // check if class object is instantiated |
|
161 | + if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
162 | + self::$_instance = new self(); |
|
163 | + } |
|
164 | + return self::$_instance; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, |
|
169 | + * all new usages of the singleton should be made with Classname::instance()) and returns it |
|
170 | + * |
|
171 | + * @return EE_Data_Migration_Manager |
|
172 | + */ |
|
173 | + public static function reset() |
|
174 | + { |
|
175 | + self::$_instance = null; |
|
176 | + return self::instance(); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * constructor |
|
182 | + */ |
|
183 | + private function __construct() |
|
184 | + { |
|
185 | + $this->stati_that_indicate_to_continue_migrations = array( |
|
186 | + self::status_continue, |
|
187 | + self::status_completed, |
|
188 | + ); |
|
189 | + $this->stati_that_indicate_to_stop_migrations = array( |
|
190 | + self::status_fatal_error, |
|
191 | + self::status_no_more_migration_scripts, |
|
192 | + ); |
|
193 | + $this->stati_that_indicate_to_continue_single_migration_script = array( |
|
194 | + self::status_continue, |
|
195 | + ); |
|
196 | + $this->stati_that_indicate_to_stop_single_migration_script = array( |
|
197 | + self::status_completed, |
|
198 | + self::status_fatal_error |
|
199 | + // note: status_no_more_migration_scripts doesn't apply |
|
200 | + ); |
|
201 | + // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
|
202 | + // to be defined, because right now it doesn't get autoloaded on its own |
|
203 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), true); |
|
204 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), true); |
|
205 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), true); |
|
206 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), true); |
|
207 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), true); |
|
208 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
209 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what |
|
215 | + * the option names are like, but generally they're like |
|
216 | + * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that). |
|
217 | + * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived, |
|
218 | + * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php (eg |
|
219 | + * EE_DMS_Core_4_1_0.dms.php) |
|
220 | + * |
|
221 | + * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
|
222 | + * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of |
|
223 | + * that plugin (eg '4.1.0') |
|
224 | + */ |
|
225 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) |
|
226 | + { |
|
227 | + $plugin_slug_and_version_string = str_replace( |
|
228 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
229 | + "", |
|
230 | + $option_name |
|
231 | + ); |
|
232 | + // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
|
233 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
234 | + |
|
235 | + if (count($parts) == 4) { |
|
236 | + // it's 4.2-style.eg Core.4.1.0 |
|
237 | + $plugin_slug = $parts[0];// eg Core |
|
238 | + $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
239 | + } else { |
|
240 | + // it's 4.1-style: eg 4.1.0 |
|
241 | + $plugin_slug = 'Core'; |
|
242 | + $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
243 | + } |
|
244 | + return array($plugin_slug, $version_string); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Gets the DMS class from the wordpress option, otherwise throws an EE_Error if it's not |
|
249 | + * for a known DMS class. |
|
250 | + * |
|
251 | + * @param string $dms_option_name |
|
252 | + * @param string $dms_option_value (serialized) |
|
253 | + * @return EE_Data_Migration_Script_Base |
|
254 | + * @throws EE_Error |
|
255 | + */ |
|
256 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) |
|
257 | + { |
|
258 | + $data_migration_data = maybe_unserialize($dms_option_value); |
|
259 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
260 | + $class = LoaderFactory::getLoader()->getShared($data_migration_data['class']); |
|
261 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
262 | + $class->instantiate_from_array_of_properties($data_migration_data); |
|
263 | + return $class; |
|
264 | + } else { |
|
265 | + // huh, so its an object but not a data migration script?? that shouldn't happen |
|
266 | + // just leave it as an array (which will probably just get ignored) |
|
267 | + throw new EE_Error( |
|
268 | + sprintf( |
|
269 | + __( |
|
270 | + "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", |
|
271 | + 'event_espresso' |
|
272 | + ), |
|
273 | + $data_migration_data['class'] |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + } else { |
|
278 | + // 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 |
|
279 | + throw new EE_Error( |
|
280 | + sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name) |
|
281 | + ); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Gets the array describing what data migrations have run. Also has a side-effect of recording which was the last |
|
287 | + * ran, and which was the last ran which hasn't finished yet |
|
288 | + * |
|
289 | + * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy |
|
290 | + * arrays in there - which should probably be ignored) |
|
291 | + */ |
|
292 | + public function get_data_migrations_ran() |
|
293 | + { |
|
294 | + if (! $this->_data_migrations_ran) { |
|
295 | + // setup autoloaders for each of the scripts in there |
|
296 | + $this->get_all_data_migration_scripts_available(); |
|
297 | + $data_migrations_options = $this->get_all_migration_script_options( |
|
298 | + );// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
299 | + |
|
300 | + $data_migrations_ran = array(); |
|
301 | + // convert into data migration script classes where possible |
|
302 | + foreach ($data_migrations_options as $data_migration_option) { |
|
303 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name( |
|
304 | + $data_migration_option['option_name'] |
|
305 | + ); |
|
306 | + |
|
307 | + try { |
|
308 | + $class = $this->_get_dms_class_from_wp_option( |
|
309 | + $data_migration_option['option_name'], |
|
310 | + $data_migration_option['option_value'] |
|
311 | + ); |
|
312 | + $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
313 | + // ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
|
314 | + $this->_last_ran_script = $class; |
|
315 | + if (! $class->is_completed()) { |
|
316 | + // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
|
317 | + $this->_last_ran_incomplete_script = $class; |
|
318 | + } |
|
319 | + } catch (EE_Error $e) { |
|
320 | + // ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
|
321 | + $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
322 | + $data_migration_option['option_value'] |
|
323 | + ); |
|
324 | + } |
|
325 | + } |
|
326 | + // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
|
327 | + $this->_data_migrations_ran = $data_migrations_ran; |
|
328 | + if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
329 | + $this->_data_migrations_ran = array(); |
|
330 | + } |
|
331 | + } |
|
332 | + return $this->_data_migrations_ran; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * |
|
338 | + * @param string $script_name eg 'DMS_Core_4_1_0' |
|
339 | + * @param string $old_table eg 'wp_events_detail' |
|
340 | + * @param string $old_pk eg 'wp_esp_posts' |
|
341 | + * @param $new_table |
|
342 | + * @return mixed string or int |
|
343 | + */ |
|
344 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
|
345 | + { |
|
346 | + $script = EE_Registry::instance()->load_dms($script_name); |
|
347 | + $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
|
348 | + return $mapping; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that |
|
353 | + * the last option returned in this array is the most-recently ran DMS option |
|
354 | + * |
|
355 | + * @return array |
|
356 | + */ |
|
357 | + public function get_all_migration_script_options() |
|
358 | + { |
|
359 | + global $wpdb; |
|
360 | + return $wpdb->get_results( |
|
361 | + "SELECT * FROM {$wpdb->options} WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id ASC", |
|
362 | + ARRAY_A |
|
363 | + ); |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded |
|
368 | + * |
|
369 | + * @return array where each value is the full folder path of a folder containing data migration scripts, WITH |
|
370 | + * slashes at the end of the folder name. |
|
371 | + */ |
|
372 | + public function get_data_migration_script_folders() |
|
373 | + { |
|
374 | + return apply_filters( |
|
375 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
376 | + array('Core' => EE_CORE . 'data_migration_scripts') |
|
377 | + ); |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Gets the version the migration script upgrades to |
|
382 | + * |
|
383 | + * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0' |
|
384 | + * @return array { |
|
385 | + * @type string $slug like 'Core','Calendar',etc |
|
386 | + * @type string $version like 4.3.0 |
|
387 | + * } |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
|
391 | + { |
|
392 | + if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
393 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
394 | + } |
|
395 | + $dms_info = $this->parse_dms_classname($migration_script_name); |
|
396 | + $this->script_migration_versions[ $migration_script_name ] = array( |
|
397 | + 'slug' => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
398 | + 'version' => $dms_info['major_version'] . "." . $dms_info['minor_version'] . "." . $dms_info['micro_version'], |
|
399 | + ); |
|
400 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0' |
|
405 | + * |
|
406 | + * @param string $classname |
|
407 | + * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
|
408 | + * @throws EE_Error |
|
409 | + */ |
|
410 | + public function parse_dms_classname($classname) |
|
411 | + { |
|
412 | + $matches = array(); |
|
413 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
414 | + if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
415 | + throw new EE_Error( |
|
416 | + sprintf( |
|
417 | + __( |
|
418 | + "%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, ", |
|
419 | + "event_espresso" |
|
420 | + ), |
|
421 | + $classname |
|
422 | + ) |
|
423 | + ); |
|
424 | + } |
|
425 | + return array( |
|
426 | + 'slug' => $matches[1], |
|
427 | + 'major_version' => intval($matches[2]), |
|
428 | + 'minor_version' => intval($matches[3]), |
|
429 | + 'micro_version' => intval($matches[4]), |
|
430 | + ); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Ensures that the option indicating the current DB version is set. This should only be |
|
435 | + * a concern when activating EE for the first time, THEORETICALLY. |
|
436 | + * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise |
|
437 | + * to 4.1.x. |
|
438 | + * |
|
439 | + * @return string of current db state |
|
440 | + */ |
|
441 | + public function ensure_current_database_state_is_set() |
|
442 | + { |
|
443 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
444 | + $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
|
445 | + if (! $db_state) { |
|
446 | + // mark the DB as being in the state as the last version in there. |
|
447 | + // this is done to trigger maintenance mode and do data migration scripts |
|
448 | + // if the admin installed this version of EE over 3.1.x or 4.0.x |
|
449 | + // otherwise, the normal maintenance mode code is fine |
|
450 | + $previous_versions_installed = array_keys($espresso_db_core_updates); |
|
451 | + $previous_version_installed = end($previous_versions_installed); |
|
452 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
453 | + // last installed version was less than 4.1 |
|
454 | + // so we want the data migrations to happen. SO, we're going to say the DB is at that state |
|
455 | + $db_state = array('Core' => $previous_version_installed); |
|
456 | + } else { |
|
457 | + $db_state = array('Core' => EVENT_ESPRESSO_VERSION); |
|
458 | + } |
|
459 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
460 | + } |
|
461 | + // in 4.1, $db_state would have only been a simple string like '4.1.0', |
|
462 | + // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
|
463 | + // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
|
464 | + if (! is_array($db_state)) { |
|
465 | + $db_state = array('Core' => $db_state); |
|
466 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
467 | + } |
|
468 | + return $db_state; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Checks if there are any data migration scripts that ought to be run. If found, |
|
473 | + * returns the instantiated classes. If none are found (ie, they've all already been run |
|
474 | + * or they don't apply), returns an empty array |
|
475 | + * |
|
476 | + * @return EE_Data_Migration_Script_Base[] |
|
477 | + */ |
|
478 | + public function check_for_applicable_data_migration_scripts() |
|
479 | + { |
|
480 | + // get the option describing what options have already run |
|
481 | + $scripts_ran = $this->get_data_migrations_ran(); |
|
482 | + // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
|
483 | + $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available(); |
|
484 | + |
|
485 | + |
|
486 | + $current_database_state = $this->ensure_current_database_state_is_set(); |
|
487 | + // determine which have already been run |
|
488 | + $script_classes_that_should_run_per_iteration = array(); |
|
489 | + $iteration = 0; |
|
490 | + $next_database_state_to_consider = $current_database_state; |
|
491 | + $theoretical_database_state = null; |
|
492 | + do { |
|
493 | + // the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
|
494 | + $theoretical_database_state = $next_database_state_to_consider; |
|
495 | + // 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?) |
|
496 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
497 | + $migrates_to_version = $this->script_migrates_to_version($classname); |
|
498 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
499 | + $script_converts_to_version = $migrates_to_version['version']; |
|
500 | + // check if this version script is DONE or not; or if it's never been ran |
|
501 | + if (! $scripts_ran || |
|
502 | + ! isset($scripts_ran[ $script_converts_plugin_slug ]) || |
|
503 | + ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ])) { |
|
504 | + // we haven't ran this conversion script before |
|
505 | + // now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
|
506 | + $script = LoaderFactory::getLoader()->load($classname); |
|
507 | + /* @var $script EE_Data_Migration_Script_Base */ |
|
508 | + $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
|
509 | + if ($can_migrate) { |
|
510 | + $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
511 | + $migrates_to_version = $script->migrates_to_version(); |
|
512 | + $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version']; |
|
513 | + unset($script_class_and_filepaths_available[ $classname ]); |
|
514 | + } |
|
515 | + } elseif ($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] instanceof EE_Data_Migration_Script_Base) { |
|
516 | + // this script has been ran, or at least started |
|
517 | + $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
518 | + if ($script->get_status() != self::status_completed) { |
|
519 | + // this script is already underway... keep going with it |
|
520 | + $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
521 | + $migrates_to_version = $script->migrates_to_version(); |
|
522 | + $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version']; |
|
523 | + unset($script_class_and_filepaths_available[ $classname ]); |
|
524 | + } else { |
|
525 | + // it must have a status that indicates it has finished, so we don't want to try and run it again |
|
526 | + } |
|
527 | + } else { |
|
528 | + // it exists but it's not a proper data migration script |
|
529 | + // maybe the script got renamed? or was simply removed from EE? |
|
530 | + // either way, its certainly not runnable! |
|
531 | + } |
|
532 | + } |
|
533 | + $iteration++; |
|
534 | + } while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
535 | + // ok we have all the scripts that should run, now let's make them into flat array |
|
536 | + $scripts_that_should_run = array(); |
|
537 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
538 | + ksort($scripts_at_priority); |
|
539 | + foreach ($scripts_at_priority as $scripts) { |
|
540 | + foreach ($scripts as $script) { |
|
541 | + $scripts_that_should_run[ get_class($script) ] = $script; |
|
542 | + } |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + do_action( |
|
547 | + 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', |
|
548 | + $scripts_that_should_run |
|
549 | + ); |
|
550 | + return $scripts_that_should_run; |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * Gets the script which is currently being ran, if there is one. If $include_completed_scripts is set to TRUE |
|
556 | + * it will return the last ran script even if its complete. |
|
557 | + * This means: if you want to find the currently-executing script, leave it as FALSE. |
|
558 | + * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE. |
|
559 | + * |
|
560 | + * @param bool $include_completed_scripts |
|
561 | + * @return EE_Data_Migration_Script_Base |
|
562 | + */ |
|
563 | + public function get_last_ran_script($include_completed_scripts = false) |
|
564 | + { |
|
565 | + // make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
|
566 | + if (! $this->_data_migrations_ran) { |
|
567 | + $this->get_data_migrations_ran(); |
|
568 | + } |
|
569 | + if ($include_completed_scripts) { |
|
570 | + return $this->_last_ran_script; |
|
571 | + } else { |
|
572 | + return $this->_last_ran_incomplete_script; |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Runs the data migration scripts (well, each request to this method calls one of the |
|
579 | + * data migration scripts' migration_step() functions). |
|
580 | + * |
|
581 | + * @param int $step_size |
|
582 | + * @throws EE_Error |
|
583 | + * @return array { |
|
584 | + * // where the first item is one EE_Data_Migration_Script_Base's stati, |
|
585 | + * //and the second item is a string describing what was done |
|
586 | + * @type int $records_to_migrate from the current migration script |
|
587 | + * @type int $records_migrated |
|
588 | + * @type string $status one of EE_Data_Migration_Manager::status_* |
|
589 | + * @type string $script verbose name of the current DMS |
|
590 | + * @type string $message string describing what was done during this step |
|
591 | + * } |
|
592 | + */ |
|
593 | + public function migration_step($step_size = 0) |
|
594 | + { |
|
595 | + |
|
596 | + // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
|
597 | + if (class_exists('EE_CPT_Strategy')) { |
|
598 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
599 | + } |
|
600 | + |
|
601 | + try { |
|
602 | + $currently_executing_script = $this->get_last_ran_script(); |
|
603 | + if (! $currently_executing_script) { |
|
604 | + // Find the next script that needs to execute |
|
605 | + $scripts = $this->check_for_applicable_data_migration_scripts(); |
|
606 | + if (! $scripts) { |
|
607 | + // huh, no more scripts to run... apparently we're done! |
|
608 | + // but dont forget to make sure initial data is there |
|
609 | + // we should be good to allow them to exit maintenance mode now |
|
610 | + EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
611 | + intval(EE_Maintenance_Mode::level_0_not_in_maintenance) |
|
612 | + ); |
|
613 | + // saving migrations ran should actually be unnecessary, but leaving in place just in case |
|
614 | + // remember this migration was finished (even if we timeout initing db for core and plugins) |
|
615 | + $this->_save_migrations_ran(); |
|
616 | + // make sure DB was updated AFTER we've recorded the migration was done |
|
617 | + $this->initialize_db_for_enqueued_ee_plugins(); |
|
618 | + return array( |
|
619 | + 'records_to_migrate' => 1, |
|
620 | + 'records_migrated' => 1, |
|
621 | + 'status' => self::status_no_more_migration_scripts, |
|
622 | + 'script' => __("Data Migration Completed Successfully", "event_espresso"), |
|
623 | + 'message' => __("All done!", "event_espresso"), |
|
624 | + ); |
|
625 | + } |
|
626 | + $currently_executing_script = array_shift($scripts); |
|
627 | + // and add to the array/wp option showing the scripts ran |
|
628 | + |
|
629 | + $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
|
630 | + $plugin_slug = $migrates_to['slug']; |
|
631 | + $version = $migrates_to['version']; |
|
632 | + $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
633 | + } |
|
634 | + $current_script_name = get_class($currently_executing_script); |
|
635 | + } catch (Exception $e) { |
|
636 | + // an exception occurred while trying to get migration scripts |
|
637 | + |
|
638 | + $message = sprintf( |
|
639 | + __("Error Message: %sStack Trace:%s", "event_espresso"), |
|
640 | + $e->getMessage() . '<br>', |
|
641 | + $e->getTraceAsString() |
|
642 | + ); |
|
643 | + // record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
|
644 | + // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
|
645 | + $this->add_error_to_migrations_ran( |
|
646 | + sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message) |
|
647 | + ); |
|
648 | + return array( |
|
649 | + 'records_to_migrate' => 1, |
|
650 | + 'records_migrated' => 0, |
|
651 | + 'status' => self::status_fatal_error, |
|
652 | + 'script' => __("Error loading data migration scripts", "event_espresso"), |
|
653 | + 'message' => $message, |
|
654 | + ); |
|
655 | + } |
|
656 | + // ok so we definitely have a data migration script |
|
657 | + try { |
|
658 | + // how big of a bite do we want to take? Allow users to easily override via their wp-config |
|
659 | + if (absint($step_size) < 1) { |
|
660 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) |
|
661 | + ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
662 | + } |
|
663 | + // do what we came to do! |
|
664 | + $currently_executing_script->migration_step($step_size); |
|
665 | + // can we wrap it up and verify default data? |
|
666 | + $init_dbs = false; |
|
667 | + switch ($currently_executing_script->get_status()) { |
|
668 | + case EE_Data_Migration_Manager::status_continue: |
|
669 | + $response_array = array( |
|
670 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
671 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
672 | + 'status' => EE_Data_Migration_Manager::status_continue, |
|
673 | + 'message' => $currently_executing_script->get_feedback_message(), |
|
674 | + 'script' => $currently_executing_script->pretty_name(), |
|
675 | + ); |
|
676 | + break; |
|
677 | + case EE_Data_Migration_Manager::status_completed: |
|
678 | + // ok so THAT script has completed |
|
679 | + $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
|
680 | + $response_array = array( |
|
681 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
682 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
683 | + 'status' => EE_Data_Migration_Manager::status_completed, |
|
684 | + 'message' => $currently_executing_script->get_feedback_message(), |
|
685 | + 'script' => sprintf( |
|
686 | + __("%s Completed", 'event_espresso'), |
|
687 | + $currently_executing_script->pretty_name() |
|
688 | + ), |
|
689 | + ); |
|
690 | + // check if there are any more after this one. |
|
691 | + $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
|
692 | + if (! $scripts_remaining) { |
|
693 | + // we should be good to allow them to exit maintenance mode now |
|
694 | + EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
695 | + intval(EE_Maintenance_Mode::level_0_not_in_maintenance) |
|
696 | + ); |
|
697 | + // huh, no more scripts to run... apparently we're done! |
|
698 | + // but dont forget to make sure initial data is there |
|
699 | + $init_dbs = true; |
|
700 | + $response_array['status'] = self::status_no_more_migration_scripts; |
|
701 | + } |
|
702 | + break; |
|
703 | + default: |
|
704 | + $response_array = array( |
|
705 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
706 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
707 | + 'status' => $currently_executing_script->get_status(), |
|
708 | + 'message' => sprintf( |
|
709 | + __("Minor errors occurred during %s: %s", "event_espresso"), |
|
710 | + $currently_executing_script->pretty_name(), |
|
711 | + implode(", ", $currently_executing_script->get_errors()) |
|
712 | + ), |
|
713 | + 'script' => $currently_executing_script->pretty_name(), |
|
714 | + ); |
|
715 | + break; |
|
716 | + } |
|
717 | + } catch (Exception $e) { |
|
718 | + // ok so some exception was thrown which killed the data migration script |
|
719 | + // double-check we have a real script |
|
720 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
721 | + $script_name = $currently_executing_script->pretty_name(); |
|
722 | + $currently_executing_script->set_broken(); |
|
723 | + $currently_executing_script->add_error($e->getMessage()); |
|
724 | + } else { |
|
725 | + $script_name = __("Error getting Migration Script", "event_espresso"); |
|
726 | + } |
|
727 | + $response_array = array( |
|
728 | + 'records_to_migrate' => 1, |
|
729 | + 'records_migrated' => 0, |
|
730 | + 'status' => self::status_fatal_error, |
|
731 | + 'message' => sprintf( |
|
732 | + __("A fatal error occurred during the migration: %s", "event_espresso"), |
|
733 | + $e->getMessage() |
|
734 | + ), |
|
735 | + 'script' => $script_name, |
|
736 | + ); |
|
737 | + } |
|
738 | + $successful_save = $this->_save_migrations_ran(); |
|
739 | + if ($successful_save !== true) { |
|
740 | + // ok so the current wp option didn't save. that's tricky, because we'd like to update it |
|
741 | + // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
|
742 | + // however, if we throw an exception, and return that, then the next request |
|
743 | + // won't have as much info in it, and it may be able to save |
|
744 | + throw new EE_Error( |
|
745 | + sprintf( |
|
746 | + __( |
|
747 | + "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.", |
|
748 | + "event_espresso" |
|
749 | + ), |
|
750 | + $successful_save |
|
751 | + ) |
|
752 | + ); |
|
753 | + } |
|
754 | + // if we're all done, initialize EE plugins' default data etc. |
|
755 | + if ($init_dbs) { |
|
756 | + $this->initialize_db_for_enqueued_ee_plugins(); |
|
757 | + } |
|
758 | + return $response_array; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * Echo out JSON response to migration script AJAX requests. Takes precautions |
|
764 | + * to buffer output so that we don't throw junk into our json. |
|
765 | + * |
|
766 | + * @return array with keys: |
|
767 | + * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie, |
|
768 | + * it's NOT the count of hwo many remain) |
|
769 | + * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete = |
|
770 | + * records_migrated/records_to_migrate) |
|
771 | + * 'status'=>a string, one of EE_Data_migration_Manager::status_* |
|
772 | + * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into |
|
773 | + * errors, notifications, and successes |
|
774 | + * 'script'=>a pretty name of the script currently running |
|
775 | + */ |
|
776 | + public function response_to_migration_ajax_request() |
|
777 | + { |
|
778 | + ob_start(); |
|
779 | + try { |
|
780 | + $response = $this->migration_step(); |
|
781 | + } catch (Exception $e) { |
|
782 | + $response = array( |
|
783 | + 'records_to_migrate' => 0, |
|
784 | + 'records_migrated' => 0, |
|
785 | + 'status' => EE_Data_Migration_Manager::status_fatal_error, |
|
786 | + 'message' => sprintf( |
|
787 | + __("Unknown fatal error occurred: %s", "event_espresso"), |
|
788 | + $e->getMessage() |
|
789 | + ), |
|
790 | + 'script' => 'Unknown', |
|
791 | + ); |
|
792 | + $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
793 | + } |
|
794 | + $warnings_etc = @ob_get_contents(); |
|
795 | + ob_end_clean(); |
|
796 | + $response['message'] .= $warnings_etc; |
|
797 | + return $response; |
|
798 | + } |
|
799 | + |
|
800 | + /** |
|
801 | + * Updates the wordpress option that keeps track of which which EE version the database |
|
802 | + * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35) |
|
803 | + * |
|
804 | + * @param array $slug_and_version { |
|
805 | + * @type string $slug like 'Core' or 'Calendar', |
|
806 | + * @type string $version like '4.1.0' |
|
807 | + * } |
|
808 | + * @return void |
|
809 | + */ |
|
810 | + public function update_current_database_state_to($slug_and_version = null) |
|
811 | + { |
|
812 | + if (! $slug_and_version) { |
|
813 | + // no version was provided, assume it should be at the current code version |
|
814 | + $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
|
815 | + } |
|
816 | + $current_database_state = get_option(self::current_database_state); |
|
817 | + $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
818 | + update_option(self::current_database_state, $current_database_state); |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Determines if the database is currently at a state matching what's indicated in $slug and $version. |
|
823 | + * |
|
824 | + * @param array $slug_and_version { |
|
825 | + * @type string $slug like 'Core' or 'Calendar', |
|
826 | + * @type string $version like '4.1.0' |
|
827 | + * } |
|
828 | + * @return boolean |
|
829 | + */ |
|
830 | + public function database_needs_updating_to($slug_and_version) |
|
831 | + { |
|
832 | + |
|
833 | + $slug = $slug_and_version['slug']; |
|
834 | + $version = $slug_and_version['version']; |
|
835 | + $current_database_state = get_option(self::current_database_state); |
|
836 | + if (! isset($current_database_state[ $slug ])) { |
|
837 | + return true; |
|
838 | + } else { |
|
839 | + // 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 |
|
840 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
841 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
842 | + $needs_updating = false; |
|
843 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
844 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
845 | + $needs_updating = true; |
|
846 | + break; |
|
847 | + } |
|
848 | + } |
|
849 | + return $needs_updating; |
|
850 | + } |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * Gets all the data migration scripts available in the core folder and folders |
|
856 | + * in addons. Has the side effect of adding them for autoloading |
|
857 | + * |
|
858 | + * @return array keys are expected classnames, values are their filepaths |
|
859 | + * @throws InvalidInterfaceException |
|
860 | + * @throws InvalidDataTypeException |
|
861 | + * @throws EE_Error |
|
862 | + * @throws InvalidArgumentException |
|
863 | + */ |
|
864 | + public function get_all_data_migration_scripts_available() |
|
865 | + { |
|
866 | + if (! $this->_data_migration_class_to_filepath_map) { |
|
867 | + $this->_data_migration_class_to_filepath_map = array(); |
|
868 | + foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
869 | + // strip any placeholders added to classname to make it a unique array key |
|
870 | + $eeAddonClass = trim($eeAddonClass, '*'); |
|
871 | + $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
872 | + ? $eeAddonClass |
|
873 | + : ''; |
|
874 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
875 | + $files = glob($folder_path . '*.dms.php'); |
|
876 | + if (empty($files)) { |
|
877 | + continue; |
|
878 | + } |
|
879 | + foreach ($files as $file) { |
|
880 | + $pos_of_last_slash = strrpos($file, '/'); |
|
881 | + $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
882 | + $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
883 | + $slug = $migrates_to['slug']; |
|
884 | + // check that the slug as contained in the DMS is associated with |
|
885 | + // the slug of an addon or core |
|
886 | + if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
887 | + EE_Error::doing_it_wrong( |
|
888 | + __FUNCTION__, |
|
889 | + sprintf( |
|
890 | + esc_html__( |
|
891 | + 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
892 | + 'event_espresso' |
|
893 | + ), |
|
894 | + $classname, |
|
895 | + $slug, |
|
896 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
897 | + ), |
|
898 | + '4.3.0.alpha.019' |
|
899 | + ); |
|
900 | + } |
|
901 | + $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
902 | + } |
|
903 | + } |
|
904 | + EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
905 | + } |
|
906 | + return $this->_data_migration_class_to_filepath_map; |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs |
|
912 | + * from each addon, and check if they need updating, |
|
913 | + * |
|
914 | + * @return boolean |
|
915 | + */ |
|
916 | + public function addons_need_updating() |
|
917 | + { |
|
918 | + return false; |
|
919 | + } |
|
920 | + |
|
921 | + /** |
|
922 | + * Adds this error string to the data_migrations_ran array, but we dont necessarily know |
|
923 | + * where to put it, so we just throw it in there... better than nothing... |
|
924 | + * |
|
925 | + * @param string $error_message |
|
926 | + * @throws EE_Error |
|
927 | + */ |
|
928 | + public function add_error_to_migrations_ran($error_message) |
|
929 | + { |
|
930 | + // get last-ran migration script |
|
931 | + global $wpdb; |
|
932 | + $last_migration_script_option = $wpdb->get_row( |
|
933 | + "SELECT * FROM $wpdb->options WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id DESC LIMIT 1", |
|
934 | + ARRAY_A |
|
935 | + ); |
|
936 | + |
|
937 | + $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) |
|
938 | + ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
|
939 | + // now, tread lightly because we're here because a FATAL non-catchable error |
|
940 | + // was thrown last time when we were trying to run a data migration script |
|
941 | + // so the fatal error could have happened while getting the migration script |
|
942 | + // or doing running it... |
|
943 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace( |
|
944 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
945 | + "", |
|
946 | + $last_migration_script_option['option_name'] |
|
947 | + ) : null; |
|
948 | + |
|
949 | + // check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
|
950 | + // because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
|
951 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
952 | + // ok then just add this error to its list of errors |
|
953 | + $last_ran_migration_script_properties['_errors'][] = $error_message; |
|
954 | + $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
|
955 | + } else { |
|
956 | + // so we don't even know which script was last running |
|
957 | + // use the data migration error stub, which is designed specifically for this type of thing |
|
958 | + $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
|
959 | + $general_migration_error->add_error($error_message); |
|
960 | + $general_migration_error->set_broken(); |
|
961 | + $last_ran_migration_script_properties = $general_migration_error->properties_as_array(); |
|
962 | + $versions_migrated_to = 'Unknown.1.0.0'; |
|
963 | + // now just to make sure appears as last (in case the were previously a fatal error like this) |
|
964 | + // delete the old one |
|
965 | + delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
966 | + } |
|
967 | + update_option( |
|
968 | + self::data_migration_script_option_prefix . $versions_migrated_to, |
|
969 | + $last_ran_migration_script_properties |
|
970 | + ); |
|
971 | + } |
|
972 | + |
|
973 | + /** |
|
974 | + * saves what data migrations have ran to the database |
|
975 | + * |
|
976 | + * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
|
977 | + */ |
|
978 | + protected function _save_migrations_ran() |
|
979 | + { |
|
980 | + if ($this->_data_migrations_ran == null) { |
|
981 | + $this->get_data_migrations_ran(); |
|
982 | + } |
|
983 | + // now, we don't want to save actual classes to the DB because that's messy |
|
984 | + $successful_updates = true; |
|
985 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
986 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
987 | + $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
988 | + $option_name = self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
989 | + $old_option_value = get_option($option_name); |
|
990 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
991 | + $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
|
992 | + if ($old_option_value != $script_array_for_saving) { |
|
993 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
994 | + } |
|
995 | + } else {// we don't know what this array-thing is. So just save it as-is |
|
996 | + if ($old_option_value != $array_or_migration_obj) { |
|
997 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
998 | + } |
|
999 | + } |
|
1000 | + if (! $successful_updates) { |
|
1001 | + global $wpdb; |
|
1002 | + return $wpdb->last_error; |
|
1003 | + } |
|
1004 | + } |
|
1005 | + } |
|
1006 | + return true; |
|
1007 | + // $updated = update_option(self::data_migrations_option_name, $array_of_migrations); |
|
1008 | + // if ($updated !== true) { |
|
1009 | + // global $wpdb; |
|
1010 | + // return $wpdb->last_error; |
|
1011 | + // } else { |
|
1012 | + // return true; |
|
1013 | + // } |
|
1014 | + // wp_mail( |
|
1015 | + // "[email protected]", |
|
1016 | + // time() . " price debug info", |
|
1017 | + // "updated: $updated, last error: $last_error, byte length of option: " . strlen( |
|
1018 | + // serialize($array_of_migrations) |
|
1019 | + // ) |
|
1020 | + // ); |
|
1021 | + } |
|
1022 | + |
|
1023 | + /** |
|
1024 | + * Takes an array of data migration script properties and re-creates the class from |
|
1025 | + * them. The argument $properties_array is assumed to have been made by |
|
1026 | + * EE_Data_Migration_Script_Base::properties_as_array() |
|
1027 | + * |
|
1028 | + * @param array $properties_array |
|
1029 | + * @return EE_Data_Migration_Script_Base |
|
1030 | + * @throws EE_Error |
|
1031 | + */ |
|
1032 | + public function _instantiate_script_from_properties_array($properties_array) |
|
1033 | + { |
|
1034 | + if (! isset($properties_array['class'])) { |
|
1035 | + throw new EE_Error( |
|
1036 | + sprintf( |
|
1037 | + __("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
|
1038 | + implode(",", $properties_array) |
|
1039 | + ) |
|
1040 | + ); |
|
1041 | + } |
|
1042 | + $class_name = $properties_array['class']; |
|
1043 | + if (! class_exists($class_name)) { |
|
1044 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
1045 | + } |
|
1046 | + $class = new $class_name; |
|
1047 | + if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
1048 | + throw new EE_Error( |
|
1049 | + sprintf( |
|
1050 | + __("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), |
|
1051 | + $class_name, |
|
1052 | + get_class($class) |
|
1053 | + ) |
|
1054 | + ); |
|
1055 | + } |
|
1056 | + $class->instantiate_from_array_of_properties($properties_array); |
|
1057 | + return $class; |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Gets the classname for the most up-to-date DMS (ie, the one that will finally |
|
1062 | + * leave the DB in a state usable by the current plugin code). |
|
1063 | + * |
|
1064 | + * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
|
1065 | + * @return string |
|
1066 | + */ |
|
1067 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') |
|
1068 | + { |
|
1069 | + $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
|
1070 | + $most_up_to_date_dms_classname = null; |
|
1071 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
1072 | + if ($most_up_to_date_dms_classname === null) { |
|
1073 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
1074 | + $this_plugin_slug = $migrates_to['slug']; |
|
1075 | + if ($this_plugin_slug == $plugin_slug) { |
|
1076 | + // if it's for core, it wins |
|
1077 | + $most_up_to_date_dms_classname = $classname; |
|
1078 | + } |
|
1079 | + // if it wasn't for core, we must keep searching for one that is! |
|
1080 | + continue; |
|
1081 | + } else { |
|
1082 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
1083 | + $contender_migrates_to = $this->script_migrates_to_version($classname); |
|
1084 | + if ($contender_migrates_to['slug'] == $plugin_slug |
|
1085 | + && version_compare( |
|
1086 | + $champion_migrates_to['version'], |
|
1087 | + $contender_migrates_to['version'], |
|
1088 | + '<' |
|
1089 | + )) { |
|
1090 | + // so the contenders version is higher and its for Core |
|
1091 | + $most_up_to_date_dms_classname = $classname; |
|
1092 | + } |
|
1093 | + } |
|
1094 | + } |
|
1095 | + return $most_up_to_date_dms_classname; |
|
1096 | + } |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * Gets the migration script specified but ONLY if it has already ran. |
|
1100 | + * |
|
1101 | + * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has ran, you would run the following code: |
|
1102 | + * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !== |
|
1103 | + * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or |
|
1104 | + * other addon) DMS has ran, in case the current DMS depends on it. |
|
1105 | + * |
|
1106 | + * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1107 | + * period. Eg '4.1.0' |
|
1108 | + * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1109 | + * @return EE_Data_Migration_Script_Base |
|
1110 | + */ |
|
1111 | + public function get_migration_ran($version, $plugin_slug = 'Core') |
|
1112 | + { |
|
1113 | + $migrations_ran = $this->get_data_migrations_ran(); |
|
1114 | + if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
1115 | + return $migrations_ran[ $plugin_slug ][ $version ]; |
|
1116 | + } else { |
|
1117 | + return null; |
|
1118 | + } |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * Resets the borked data migration scripts so they're no longer borked |
|
1123 | + * so we can again attempt to migrate |
|
1124 | + * |
|
1125 | + * @return bool |
|
1126 | + * @throws EE_Error |
|
1127 | + */ |
|
1128 | + public function reattempt() |
|
1129 | + { |
|
1130 | + // find if the last-ran script was borked |
|
1131 | + // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
|
1132 | + // add an 'error' saying that we attempted to reset |
|
1133 | + // does it have a stage that was borked too? if so make it no longer borked |
|
1134 | + // add an 'error' saying we attempted to reset |
|
1135 | + $last_ran_script = $this->get_last_ran_script(); |
|
1136 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
1137 | + // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
|
1138 | + $last_ran_script->set_completed(); |
|
1139 | + } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
1140 | + $last_ran_script->reattempt(); |
|
1141 | + } else { |
|
1142 | + throw new EE_Error( |
|
1143 | + sprintf( |
|
1144 | + __( |
|
1145 | + 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', |
|
1146 | + 'event_espresso' |
|
1147 | + ), |
|
1148 | + print_r($last_ran_script, true) |
|
1149 | + ) |
|
1150 | + ); |
|
1151 | + } |
|
1152 | + return $this->_save_migrations_ran(); |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Gets whether or not this particular migration has run or not |
|
1157 | + * |
|
1158 | + * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1159 | + * period. Eg '4.1.0' |
|
1160 | + * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1161 | + * @return boolean |
|
1162 | + */ |
|
1163 | + public function migration_has_ran($version, $plugin_slug = 'Core') |
|
1164 | + { |
|
1165 | + return $this->get_migration_ran($version, $plugin_slug) !== null; |
|
1166 | + } |
|
1167 | + |
|
1168 | + /** |
|
1169 | + * Enqueues this ee plugin to have its data initialized |
|
1170 | + * |
|
1171 | + * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
|
1172 | + */ |
|
1173 | + public function enqueue_db_initialization_for($plugin_slug) |
|
1174 | + { |
|
1175 | + $queue = $this->get_db_initialization_queue(); |
|
1176 | + if (! in_array($plugin_slug, $queue)) { |
|
1177 | + $queue[] = $plugin_slug; |
|
1178 | + } |
|
1179 | + update_option(self::db_init_queue_option_name, $queue); |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
|
1184 | + * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is |
|
1185 | + * in the queue, calls EE_System::initialize_db_if_no_migrations_required(). |
|
1186 | + */ |
|
1187 | + public function initialize_db_for_enqueued_ee_plugins() |
|
1188 | + { |
|
1189 | + $queue = $this->get_db_initialization_queue(); |
|
1190 | + foreach ($queue as $plugin_slug) { |
|
1191 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
1192 | + if (! $most_up_to_date_dms) { |
|
1193 | + // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
|
1194 | + $verify_db = false; |
|
1195 | + } else { |
|
1196 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1197 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1198 | + } |
|
1199 | + if ($plugin_slug == 'Core') { |
|
1200 | + EE_System::instance()->initialize_db_if_no_migrations_required( |
|
1201 | + false, |
|
1202 | + $verify_db |
|
1203 | + ); |
|
1204 | + } else { |
|
1205 | + // just loop through the addons to make sure their database is setup |
|
1206 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
1207 | + if ($addon->name() == $plugin_slug) { |
|
1208 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1209 | + break; |
|
1210 | + } |
|
1211 | + } |
|
1212 | + } |
|
1213 | + } |
|
1214 | + // because we just initialized the DBs for the enqueued ee plugins |
|
1215 | + // we don't need to keep remembering which ones needed to be initialized |
|
1216 | + delete_option(self::db_init_queue_option_name); |
|
1217 | + } |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * Gets a numerically-indexed array of plugin slugs that need to have their databases |
|
1221 | + * (re-)initialized after migrations are complete. ie, each element should be either |
|
1222 | + * 'Core', or the return value of EE_Addon::name() for an addon |
|
1223 | + * |
|
1224 | + * @return array |
|
1225 | + */ |
|
1226 | + public function get_db_initialization_queue() |
|
1227 | + { |
|
1228 | + return get_option(self::db_init_queue_option_name, array()); |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * Gets the injected table analyzer, or throws an exception |
|
1233 | + * |
|
1234 | + * @return TableAnalysis |
|
1235 | + * @throws EE_Error |
|
1236 | + */ |
|
1237 | + protected function _get_table_analysis() |
|
1238 | + { |
|
1239 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
1240 | + return $this->_table_analysis; |
|
1241 | + } else { |
|
1242 | + throw new EE_Error( |
|
1243 | + sprintf( |
|
1244 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1245 | + get_class($this) |
|
1246 | + ) |
|
1247 | + ); |
|
1248 | + } |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Gets the injected table manager, or throws an exception |
|
1253 | + * |
|
1254 | + * @return TableManager |
|
1255 | + * @throws EE_Error |
|
1256 | + */ |
|
1257 | + protected function _get_table_manager() |
|
1258 | + { |
|
1259 | + if ($this->_table_manager instanceof TableManager) { |
|
1260 | + return $this->_table_manager; |
|
1261 | + } else { |
|
1262 | + throw new EE_Error( |
|
1263 | + sprintf( |
|
1264 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1265 | + get_class($this) |
|
1266 | + ) |
|
1267 | + ); |
|
1268 | + } |
|
1269 | + } |
|
1270 | 1270 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | public static function instance(ClassInterfaceCache $class_cache = null) |
123 | 123 | { |
124 | 124 | // check if class object is instantiated, and instantiated properly |
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
125 | + if ( ! self::$_instance instanceof EE_Dependency_Map |
|
126 | 126 | && $class_cache instanceof ClassInterfaceCache |
127 | 127 | ) { |
128 | 128 | self::$_instance = new EE_Dependency_Map($class_cache); |
@@ -203,18 +203,18 @@ discard block |
||
203 | 203 | ) { |
204 | 204 | $class = trim($class, '\\'); |
205 | 205 | $registered = false; |
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
206 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
207 | + self::$_instance->_dependency_map[$class] = array(); |
|
208 | 208 | } |
209 | 209 | // we need to make sure that any aliases used when registering a dependency |
210 | 210 | // get resolved to the correct class name |
211 | 211 | foreach ($dependencies as $dependency => $load_source) { |
212 | 212 | $alias = self::$_instance->getFqnForAlias($dependency); |
213 | 213 | if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
214 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
215 | 215 | ) { |
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
216 | + unset($dependencies[$dependency]); |
|
217 | + $dependencies[$alias] = $load_source; |
|
218 | 218 | $registered = true; |
219 | 219 | } |
220 | 220 | } |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
225 | 225 | // Union is way faster than array_merge() but should be used with caution... |
226 | 226 | // especially with numerically indexed arrays |
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
227 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
228 | 228 | // now we need to ensure that the resulting dependencies |
229 | 229 | // array only has the entries that are required for the class |
230 | 230 | // so first count how many dependencies were originally registered for the class |
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
232 | 232 | // if that count is non-zero (meaning dependencies were already registered) |
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
233 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
234 | 234 | // then truncate the final array to match that count |
235 | 235 | ? array_slice($dependencies, 0, $dependency_count) |
236 | 236 | // otherwise just take the incoming array because nothing previously existed |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public static function register_class_loader($class_name, $loader = 'load_core') |
249 | 249 | { |
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
250 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | 251 | throw new DomainException( |
252 | 252 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
253 | 253 | ); |
254 | 254 | } |
255 | 255 | // check that loader is callable or method starts with "load_" and exists in EE_Registry |
256 | - if (! is_callable($loader) |
|
256 | + if ( ! is_callable($loader) |
|
257 | 257 | && ( |
258 | 258 | strpos($loader, 'load_') !== 0 |
259 | 259 | || ! method_exists('EE_Registry', $loader) |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | ); |
271 | 271 | } |
272 | 272 | $class_name = self::$_instance->getFqnForAlias($class_name); |
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
273 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
274 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
275 | 275 | return true; |
276 | 276 | } |
277 | 277 | return false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | if (strpos($class_name, 'EEM_') === 0) { |
300 | 300 | $class_name = 'LEGACY_MODELS'; |
301 | 301 | } |
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
302 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $class_name = 'LEGACY_MODELS'; |
318 | 318 | } |
319 | 319 | $dependency = $this->getFqnForAlias($dependency, $class_name); |
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
320 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
321 | 321 | ? true |
322 | 322 | : false; |
323 | 323 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | $dependency = $this->getFqnForAlias($dependency); |
340 | 340 | return $this->has_dependency_for_class($class_name, $dependency) |
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
341 | + ? $this->_dependency_map[$class_name][$dependency] |
|
342 | 342 | : EE_Dependency_Map::not_registered; |
343 | 343 | } |
344 | 344 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | return 'load_core'; |
362 | 362 | } |
363 | 363 | $class_name = $this->getFqnForAlias($class_name); |
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
364 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | { |
883 | 883 | $this->_class_loaders = array( |
884 | 884 | // load_core |
885 | - 'EE_Dependency_Map' => function () { |
|
885 | + 'EE_Dependency_Map' => function() { |
|
886 | 886 | return $this; |
887 | 887 | }, |
888 | 888 | 'EE_Capabilities' => 'load_core', |
@@ -890,13 +890,13 @@ discard block |
||
890 | 890 | 'EE_Front_Controller' => 'load_core', |
891 | 891 | 'EE_Module_Request_Router' => 'load_core', |
892 | 892 | 'EE_Registry' => 'load_core', |
893 | - 'EE_Request' => function () { |
|
893 | + 'EE_Request' => function() { |
|
894 | 894 | return $this->legacy_request; |
895 | 895 | }, |
896 | - 'EventEspresso\core\services\request\Request' => function () { |
|
896 | + 'EventEspresso\core\services\request\Request' => function() { |
|
897 | 897 | return $this->request; |
898 | 898 | }, |
899 | - 'EventEspresso\core\services\request\Response' => function () { |
|
899 | + 'EventEspresso\core\services\request\Response' => function() { |
|
900 | 900 | return $this->response; |
901 | 901 | }, |
902 | 902 | 'EE_Base' => 'load_core', |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | 'EE_DMS_Core_4_8_0' => 'load_dms', |
930 | 930 | 'EE_DMS_Core_4_9_0' => 'load_dms', |
931 | 931 | 'EE_DMS_Core_4_10_0' => 'load_dms', |
932 | - 'EE_Messages_Generator' => function () { |
|
932 | + 'EE_Messages_Generator' => function() { |
|
933 | 933 | return EE_Registry::instance()->load_lib( |
934 | 934 | 'Messages_Generator', |
935 | 935 | array(), |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | false |
938 | 938 | ); |
939 | 939 | }, |
940 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
940 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
941 | 941 | return EE_Registry::instance()->load_lib( |
942 | 942 | 'Messages_Template_Defaults', |
943 | 943 | $arguments, |
@@ -946,46 +946,46 @@ discard block |
||
946 | 946 | ); |
947 | 947 | }, |
948 | 948 | // load_helper |
949 | - 'EEH_Parse_Shortcodes' => function () { |
|
949 | + 'EEH_Parse_Shortcodes' => function() { |
|
950 | 950 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
951 | 951 | return new EEH_Parse_Shortcodes(); |
952 | 952 | } |
953 | 953 | return null; |
954 | 954 | }, |
955 | - 'EE_Template_Config' => function () { |
|
955 | + 'EE_Template_Config' => function() { |
|
956 | 956 | return EE_Config::instance()->template_settings; |
957 | 957 | }, |
958 | - 'EE_Currency_Config' => function () { |
|
958 | + 'EE_Currency_Config' => function() { |
|
959 | 959 | return EE_Config::instance()->currency; |
960 | 960 | }, |
961 | - 'EE_Registration_Config' => function () { |
|
961 | + 'EE_Registration_Config' => function() { |
|
962 | 962 | return EE_Config::instance()->registration; |
963 | 963 | }, |
964 | - 'EE_Core_Config' => function () { |
|
964 | + 'EE_Core_Config' => function() { |
|
965 | 965 | return EE_Config::instance()->core; |
966 | 966 | }, |
967 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
967 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
968 | 968 | return LoaderFactory::getLoader(); |
969 | 969 | }, |
970 | - 'EE_Network_Config' => function () { |
|
970 | + 'EE_Network_Config' => function() { |
|
971 | 971 | return EE_Network_Config::instance(); |
972 | 972 | }, |
973 | - 'EE_Config' => function () { |
|
973 | + 'EE_Config' => function() { |
|
974 | 974 | return EE_Config::instance(); |
975 | 975 | }, |
976 | - 'EventEspresso\core\domain\Domain' => function () { |
|
976 | + 'EventEspresso\core\domain\Domain' => function() { |
|
977 | 977 | return DomainFactory::getEventEspressoCoreDomain(); |
978 | 978 | }, |
979 | - 'EE_Admin_Config' => function () { |
|
979 | + 'EE_Admin_Config' => function() { |
|
980 | 980 | return EE_Config::instance()->admin; |
981 | 981 | }, |
982 | - 'EE_Organization_Config' => function () { |
|
982 | + 'EE_Organization_Config' => function() { |
|
983 | 983 | return EE_Config::instance()->organization; |
984 | 984 | }, |
985 | - 'EE_Network_Core_Config' => function () { |
|
985 | + 'EE_Network_Core_Config' => function() { |
|
986 | 986 | return EE_Network_Config::instance()->core; |
987 | 987 | }, |
988 | - 'EE_Environment_Config' => function () { |
|
988 | + 'EE_Environment_Config' => function() { |
|
989 | 989 | return EE_Config::instance()->environment; |
990 | 990 | }, |
991 | 991 | ); |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | } |
1047 | 1047 | $this->class_cache->addAlias($fqn, $alias); |
1048 | 1048 | } |
1049 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1049 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1050 | 1050 | $this->class_cache->addAlias( |
1051 | 1051 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
1052 | 1052 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -20,1128 +20,1128 @@ |
||
20 | 20 | class EE_Dependency_Map |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * This means that the requested class dependency is not present in the dependency map |
|
25 | - */ |
|
26 | - const not_registered = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | - */ |
|
31 | - const load_new_object = 1; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | - */ |
|
37 | - const load_from_cache = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * When registering a dependency, |
|
41 | - * this indicates to keep any existing dependencies that already exist, |
|
42 | - * and simply discard any new dependencies declared in the incoming data |
|
43 | - */ |
|
44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * When registering a dependency, |
|
48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | - */ |
|
50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = array(); |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function initialize() |
|
110 | - { |
|
111 | - $this->_register_core_dependencies(); |
|
112 | - $this->_register_core_class_loaders(); |
|
113 | - $this->_register_core_aliases(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param ClassInterfaceCache|null $class_cache |
|
120 | - * @return EE_Dependency_Map |
|
121 | - */ |
|
122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | - { |
|
124 | - // check if class object is instantiated, and instantiated properly |
|
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | - && $class_cache instanceof ClassInterfaceCache |
|
127 | - ) { |
|
128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | - } |
|
130 | - return self::$_instance; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RequestInterface $request |
|
136 | - */ |
|
137 | - public function setRequest(RequestInterface $request) |
|
138 | - { |
|
139 | - $this->request = $request; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param LegacyRequestInterface $legacy_request |
|
145 | - */ |
|
146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | - { |
|
148 | - $this->legacy_request = $legacy_request; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param ResponseInterface $response |
|
154 | - */ |
|
155 | - public function setResponse(ResponseInterface $response) |
|
156 | - { |
|
157 | - $this->response = $response; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param LoaderInterface $loader |
|
163 | - */ |
|
164 | - public function setLoader(LoaderInterface $loader) |
|
165 | - { |
|
166 | - $this->loader = $loader; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $class |
|
172 | - * @param array $dependencies |
|
173 | - * @param int $overwrite |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function register_dependencies( |
|
177 | - $class, |
|
178 | - array $dependencies, |
|
179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | - ) { |
|
181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | - * to the class specified by the first parameter. |
|
188 | - * IMPORTANT !!! |
|
189 | - * The order of elements in the incoming $dependencies array MUST match |
|
190 | - * the order of the constructor parameters for the class in question. |
|
191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | - * |
|
194 | - * @param string $class |
|
195 | - * @param array $dependencies |
|
196 | - * @param int $overwrite |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function registerDependencies( |
|
200 | - $class, |
|
201 | - array $dependencies, |
|
202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | - ) { |
|
204 | - $class = trim($class, '\\'); |
|
205 | - $registered = false; |
|
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | - } |
|
209 | - // we need to make sure that any aliases used when registering a dependency |
|
210 | - // get resolved to the correct class name |
|
211 | - foreach ($dependencies as $dependency => $load_source) { |
|
212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | - ) { |
|
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
218 | - $registered = true; |
|
219 | - } |
|
220 | - } |
|
221 | - // now add our two lists of dependencies together. |
|
222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | - // so $dependencies is NOT overwritten because it is listed first |
|
224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | - // Union is way faster than array_merge() but should be used with caution... |
|
226 | - // especially with numerically indexed arrays |
|
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | - // now we need to ensure that the resulting dependencies |
|
229 | - // array only has the entries that are required for the class |
|
230 | - // so first count how many dependencies were originally registered for the class |
|
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | - // then truncate the final array to match that count |
|
235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
236 | - // otherwise just take the incoming array because nothing previously existed |
|
237 | - : $dependencies; |
|
238 | - return $registered; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $class_name |
|
244 | - * @param string $loader |
|
245 | - * @return bool |
|
246 | - * @throws DomainException |
|
247 | - */ |
|
248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | - { |
|
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | - throw new DomainException( |
|
252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | - if (! is_callable($loader) |
|
257 | - && ( |
|
258 | - strpos($loader, 'load_') !== 0 |
|
259 | - || ! method_exists('EE_Registry', $loader) |
|
260 | - ) |
|
261 | - ) { |
|
262 | - throw new DomainException( |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $loader |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | - return true; |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function dependency_map() |
|
285 | - { |
|
286 | - return $this->_dependency_map; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | - * |
|
293 | - * @param string $class_name |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function has($class_name = '') |
|
297 | - { |
|
298 | - // all legacy models have the same dependencies |
|
299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
300 | - $class_name = 'LEGACY_MODELS'; |
|
301 | - } |
|
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | - ? true |
|
322 | - : false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | - * |
|
329 | - * @param string $class_name |
|
330 | - * @param string $dependency |
|
331 | - * @return int |
|
332 | - */ |
|
333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | - { |
|
335 | - // all legacy models have the same dependencies |
|
336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
337 | - $class_name = 'LEGACY_MODELS'; |
|
338 | - } |
|
339 | - $dependency = $this->getFqnForAlias($dependency); |
|
340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | - : EE_Dependency_Map::not_registered; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $class_name |
|
348 | - * @return string | Closure |
|
349 | - */ |
|
350 | - public function class_loader($class_name) |
|
351 | - { |
|
352 | - // all legacy models use load_model() |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - return 'load_model'; |
|
355 | - } |
|
356 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | - // perform strpos() first to avoid loading regex every time we load a class |
|
358 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | - ) { |
|
361 | - return 'load_core'; |
|
362 | - } |
|
363 | - $class_name = $this->getFqnForAlias($class_name); |
|
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function class_loaders() |
|
372 | - { |
|
373 | - return $this->_class_loaders; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * adds an alias for a classname |
|
379 | - * |
|
380 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | - */ |
|
384 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | - { |
|
386 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | - * WHY? |
|
393 | - * Because if a class is type hinting for a concretion, |
|
394 | - * then why would we need to find another class to supply it? |
|
395 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | - * Don't go looking for some substitute. |
|
398 | - * Whereas if a class is type hinting for an interface... |
|
399 | - * then we need to find an actual class to use. |
|
400 | - * So the interface IS the alias for some other FQN, |
|
401 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | - * represents some other class. |
|
403 | - * |
|
404 | - * @param string $fqn |
|
405 | - * @param string $for_class |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function isAlias($fqn = '', $for_class = '') |
|
409 | - { |
|
410 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | - * for example: |
|
418 | - * if the following two entries were added to the _aliases array: |
|
419 | - * array( |
|
420 | - * 'interface_alias' => 'some\namespace\interface' |
|
421 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | - * ) |
|
423 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | - * to load an instance of 'some\namespace\classname' |
|
425 | - * |
|
426 | - * @param string $alias |
|
427 | - * @param string $for_class |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | - { |
|
432 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | - * This is done by using the following class constants: |
|
440 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | - */ |
|
443 | - protected function _register_core_dependencies() |
|
444 | - { |
|
445 | - $this->_dependency_map = array( |
|
446 | - 'EE_Request_Handler' => array( |
|
447 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_System' => array( |
|
450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_Session' => array( |
|
456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | - ), |
|
462 | - 'EE_Cart' => array( |
|
463 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_Front_Controller' => array( |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messenger_Collection_Loader' => array( |
|
471 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | - ), |
|
473 | - 'EE_Message_Type_Collection_Loader' => array( |
|
474 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Message_Resource_Manager' => array( |
|
477 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_Message_Factory' => array( |
|
482 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_messages' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_Messages_Generator' => array( |
|
488 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EE_Messages_Processor' => array( |
|
494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Messages_Queue' => array( |
|
497 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | - ), |
|
499 | - 'EE_Messages_Template_Defaults' => array( |
|
500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | - ), |
|
503 | - 'EE_Message_To_Generate_From_Request' => array( |
|
504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EE_Data_Migration_Class_Base' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | - ), |
|
567 | - 'EE_DMS_Core_4_1_0' => array( |
|
568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | - ), |
|
571 | - 'EE_DMS_Core_4_2_0' => array( |
|
572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EE_DMS_Core_4_3_0' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | - ), |
|
579 | - 'EE_DMS_Core_4_4_0' => array( |
|
580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EE_DMS_Core_4_5_0' => array( |
|
584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EE_DMS_Core_4_6_0' => array( |
|
588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | - ), |
|
591 | - 'EE_DMS_Core_4_7_0' => array( |
|
592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EE_DMS_Core_4_8_0' => array( |
|
596 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EE_DMS_Core_4_9_0' => array( |
|
600 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | - ), |
|
603 | - 'EE_DMS_Core_4_10_0' => array( |
|
604 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
609 | - array(), |
|
610 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | - ), |
|
612 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
613 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
638 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
641 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
644 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | - ), |
|
647 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
648 | - null, |
|
649 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | - ), |
|
651 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
652 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | - ), |
|
654 | - 'LEGACY_MODELS' => array( |
|
655 | - null, |
|
656 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | - ), |
|
658 | - 'EE_Module_Request_Router' => array( |
|
659 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | - ), |
|
661 | - 'EE_Registration_Processor' => array( |
|
662 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
663 | - ), |
|
664 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
665 | - null, |
|
666 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | - ), |
|
669 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
670 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EE_Admin_Transactions_List_Table' => array( |
|
674 | - null, |
|
675 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | - ), |
|
677 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
678 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | - ), |
|
682 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
683 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | - ), |
|
686 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
687 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | - ), |
|
695 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
696 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | - ), |
|
698 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
699 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | - ), |
|
701 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
702 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | - ), |
|
705 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
706 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | - ), |
|
708 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
709 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | - ), |
|
715 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
716 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | - ), |
|
718 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
719 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | - ), |
|
722 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
723 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | - ), |
|
725 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
726 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | - ), |
|
728 | - 'EE_CPT_Strategy' => array( |
|
729 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | - ), |
|
732 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
733 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | - ), |
|
735 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
736 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | - ), |
|
742 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
743 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
745 | - ), |
|
746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
747 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | - ), |
|
749 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
752 | - ), |
|
753 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
754 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | - ), |
|
756 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
757 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | - ), |
|
759 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
760 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | - ), |
|
762 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
763 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | - ), |
|
765 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
766 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | - ), |
|
769 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
770 | - null, |
|
771 | - null, |
|
772 | - null, |
|
773 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
774 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | - ), |
|
777 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
778 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
780 | - ), |
|
781 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
782 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | - ), |
|
787 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
788 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | - ), |
|
792 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
793 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | - ), |
|
796 | - 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
797 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | - ), |
|
801 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
802 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | - ), |
|
806 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
807 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | - ), |
|
810 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
811 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | - ), |
|
814 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
815 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
816 | - ), |
|
817 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
818 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | - ), |
|
820 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
821 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
822 | - ), |
|
823 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
824 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
826 | - ), |
|
827 | - 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
828 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
830 | - ), |
|
831 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
832 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
833 | - ), |
|
834 | - 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
835 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | - ), |
|
837 | - 'EE_URL_Validation_Strategy' => array( |
|
838 | - null, |
|
839 | - null, |
|
840 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
841 | - ), |
|
842 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
843 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | - 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | - ), |
|
849 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
850 | - 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | - 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
852 | - ), |
|
853 | - 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
854 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | - ), |
|
857 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
858 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | - 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | - ), |
|
861 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
862 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | - ), |
|
864 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | - ], |
|
867 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | - null, |
|
869 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | - ], |
|
872 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | - ], |
|
876 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | - ], |
|
880 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | - ], |
|
884 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | - ], |
|
888 | - ); |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * Registers how core classes are loaded. |
|
894 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
895 | - * 'EE_Request_Handler' => 'load_core' |
|
896 | - * 'EE_Messages_Queue' => 'load_lib' |
|
897 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
898 | - * or, if greater control is required, by providing a custom closure. For example: |
|
899 | - * 'Some_Class' => function () { |
|
900 | - * return new Some_Class(); |
|
901 | - * }, |
|
902 | - * This is required for instantiating dependencies |
|
903 | - * where an interface has been type hinted in a class constructor. For example: |
|
904 | - * 'Required_Interface' => function () { |
|
905 | - * return new A_Class_That_Implements_Required_Interface(); |
|
906 | - * }, |
|
907 | - */ |
|
908 | - protected function _register_core_class_loaders() |
|
909 | - { |
|
910 | - $this->_class_loaders = array( |
|
911 | - // load_core |
|
912 | - 'EE_Dependency_Map' => function () { |
|
913 | - return $this; |
|
914 | - }, |
|
915 | - 'EE_Capabilities' => 'load_core', |
|
916 | - 'EE_Encryption' => 'load_core', |
|
917 | - 'EE_Front_Controller' => 'load_core', |
|
918 | - 'EE_Module_Request_Router' => 'load_core', |
|
919 | - 'EE_Registry' => 'load_core', |
|
920 | - 'EE_Request' => function () { |
|
921 | - return $this->legacy_request; |
|
922 | - }, |
|
923 | - 'EventEspresso\core\services\request\Request' => function () { |
|
924 | - return $this->request; |
|
925 | - }, |
|
926 | - 'EventEspresso\core\services\request\Response' => function () { |
|
927 | - return $this->response; |
|
928 | - }, |
|
929 | - 'EE_Base' => 'load_core', |
|
930 | - 'EE_Request_Handler' => 'load_core', |
|
931 | - 'EE_Session' => 'load_core', |
|
932 | - 'EE_Cron_Tasks' => 'load_core', |
|
933 | - 'EE_System' => 'load_core', |
|
934 | - 'EE_Maintenance_Mode' => 'load_core', |
|
935 | - 'EE_Register_CPTs' => 'load_core', |
|
936 | - 'EE_Admin' => 'load_core', |
|
937 | - 'EE_CPT_Strategy' => 'load_core', |
|
938 | - // load_class |
|
939 | - 'EE_Registration_Processor' => 'load_class', |
|
940 | - // load_lib |
|
941 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
942 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
943 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
944 | - 'EE_Messenger_Collection' => 'load_lib', |
|
945 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
946 | - 'EE_Messages_Processor' => 'load_lib', |
|
947 | - 'EE_Message_Repository' => 'load_lib', |
|
948 | - 'EE_Messages_Queue' => 'load_lib', |
|
949 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
950 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
951 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
952 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
953 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
954 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
955 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
956 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
957 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
958 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
959 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
960 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
961 | - 'EE_Messages_Generator' => function () { |
|
962 | - return EE_Registry::instance()->load_lib( |
|
963 | - 'Messages_Generator', |
|
964 | - array(), |
|
965 | - false, |
|
966 | - false |
|
967 | - ); |
|
968 | - }, |
|
969 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
970 | - return EE_Registry::instance()->load_lib( |
|
971 | - 'Messages_Template_Defaults', |
|
972 | - $arguments, |
|
973 | - false, |
|
974 | - false |
|
975 | - ); |
|
976 | - }, |
|
977 | - // load_helper |
|
978 | - 'EEH_Parse_Shortcodes' => function () { |
|
979 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
980 | - return new EEH_Parse_Shortcodes(); |
|
981 | - } |
|
982 | - return null; |
|
983 | - }, |
|
984 | - 'EE_Template_Config' => function () { |
|
985 | - return EE_Config::instance()->template_settings; |
|
986 | - }, |
|
987 | - 'EE_Currency_Config' => function () { |
|
988 | - return EE_Config::instance()->currency; |
|
989 | - }, |
|
990 | - 'EE_Registration_Config' => function () { |
|
991 | - return EE_Config::instance()->registration; |
|
992 | - }, |
|
993 | - 'EE_Core_Config' => function () { |
|
994 | - return EE_Config::instance()->core; |
|
995 | - }, |
|
996 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
997 | - return LoaderFactory::getLoader(); |
|
998 | - }, |
|
999 | - 'EE_Network_Config' => function () { |
|
1000 | - return EE_Network_Config::instance(); |
|
1001 | - }, |
|
1002 | - 'EE_Config' => function () { |
|
1003 | - return EE_Config::instance(); |
|
1004 | - }, |
|
1005 | - 'EventEspresso\core\domain\Domain' => function () { |
|
1006 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
1007 | - }, |
|
1008 | - 'EE_Admin_Config' => function () { |
|
1009 | - return EE_Config::instance()->admin; |
|
1010 | - }, |
|
1011 | - 'EE_Organization_Config' => function () { |
|
1012 | - return EE_Config::instance()->organization; |
|
1013 | - }, |
|
1014 | - 'EE_Network_Core_Config' => function () { |
|
1015 | - return EE_Network_Config::instance()->core; |
|
1016 | - }, |
|
1017 | - 'EE_Environment_Config' => function () { |
|
1018 | - return EE_Config::instance()->environment; |
|
1019 | - }, |
|
1020 | - ); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * can be used for supplying alternate names for classes, |
|
1026 | - * or for connecting interface names to instantiable classes |
|
1027 | - */ |
|
1028 | - protected function _register_core_aliases() |
|
1029 | - { |
|
1030 | - $aliases = array( |
|
1031 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1032 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1033 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1034 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1035 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1036 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1037 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1038 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1039 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1040 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1041 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1042 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1043 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1044 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1045 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1046 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1047 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1048 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1049 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1050 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1051 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1052 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1053 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1054 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1055 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1056 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1057 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1058 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1059 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1060 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1061 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1062 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1063 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1064 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1065 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1066 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1067 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1068 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
1069 | - ); |
|
1070 | - foreach ($aliases as $alias => $fqn) { |
|
1071 | - if (is_array($fqn)) { |
|
1072 | - foreach ($fqn as $class => $for_class) { |
|
1073 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
1074 | - } |
|
1075 | - continue; |
|
1076 | - } |
|
1077 | - $this->class_cache->addAlias($fqn, $alias); |
|
1078 | - } |
|
1079 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1080 | - $this->class_cache->addAlias( |
|
1081 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1082 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1090 | - * request Primarily used by unit tests. |
|
1091 | - */ |
|
1092 | - public function reset() |
|
1093 | - { |
|
1094 | - $this->_register_core_class_loaders(); |
|
1095 | - $this->_register_core_dependencies(); |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - /** |
|
1100 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
1101 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
1102 | - * WHY? |
|
1103 | - * Because if a class is type hinting for a concretion, |
|
1104 | - * then why would we need to find another class to supply it? |
|
1105 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1106 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1107 | - * Don't go looking for some substitute. |
|
1108 | - * Whereas if a class is type hinting for an interface... |
|
1109 | - * then we need to find an actual class to use. |
|
1110 | - * So the interface IS the alias for some other FQN, |
|
1111 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1112 | - * represents some other class. |
|
1113 | - * |
|
1114 | - * @deprecated 4.9.62.p |
|
1115 | - * @param string $fqn |
|
1116 | - * @param string $for_class |
|
1117 | - * @return bool |
|
1118 | - */ |
|
1119 | - public function has_alias($fqn = '', $for_class = '') |
|
1120 | - { |
|
1121 | - return $this->isAlias($fqn, $for_class); |
|
1122 | - } |
|
1123 | - |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1127 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1128 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1129 | - * for example: |
|
1130 | - * if the following two entries were added to the _aliases array: |
|
1131 | - * array( |
|
1132 | - * 'interface_alias' => 'some\namespace\interface' |
|
1133 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1134 | - * ) |
|
1135 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1136 | - * to load an instance of 'some\namespace\classname' |
|
1137 | - * |
|
1138 | - * @deprecated 4.9.62.p |
|
1139 | - * @param string $alias |
|
1140 | - * @param string $for_class |
|
1141 | - * @return string |
|
1142 | - */ |
|
1143 | - public function get_alias($alias = '', $for_class = '') |
|
1144 | - { |
|
1145 | - return $this->getFqnForAlias($alias, $for_class); |
|
1146 | - } |
|
23 | + /** |
|
24 | + * This means that the requested class dependency is not present in the dependency map |
|
25 | + */ |
|
26 | + const not_registered = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | + */ |
|
31 | + const load_new_object = 1; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | + */ |
|
37 | + const load_from_cache = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * When registering a dependency, |
|
41 | + * this indicates to keep any existing dependencies that already exist, |
|
42 | + * and simply discard any new dependencies declared in the incoming data |
|
43 | + */ |
|
44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * When registering a dependency, |
|
48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | + */ |
|
50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = array(); |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function initialize() |
|
110 | + { |
|
111 | + $this->_register_core_dependencies(); |
|
112 | + $this->_register_core_class_loaders(); |
|
113 | + $this->_register_core_aliases(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param ClassInterfaceCache|null $class_cache |
|
120 | + * @return EE_Dependency_Map |
|
121 | + */ |
|
122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | + { |
|
124 | + // check if class object is instantiated, and instantiated properly |
|
125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | + && $class_cache instanceof ClassInterfaceCache |
|
127 | + ) { |
|
128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | + } |
|
130 | + return self::$_instance; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RequestInterface $request |
|
136 | + */ |
|
137 | + public function setRequest(RequestInterface $request) |
|
138 | + { |
|
139 | + $this->request = $request; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param LegacyRequestInterface $legacy_request |
|
145 | + */ |
|
146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | + { |
|
148 | + $this->legacy_request = $legacy_request; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param ResponseInterface $response |
|
154 | + */ |
|
155 | + public function setResponse(ResponseInterface $response) |
|
156 | + { |
|
157 | + $this->response = $response; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param LoaderInterface $loader |
|
163 | + */ |
|
164 | + public function setLoader(LoaderInterface $loader) |
|
165 | + { |
|
166 | + $this->loader = $loader; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $class |
|
172 | + * @param array $dependencies |
|
173 | + * @param int $overwrite |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function register_dependencies( |
|
177 | + $class, |
|
178 | + array $dependencies, |
|
179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | + ) { |
|
181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | + * to the class specified by the first parameter. |
|
188 | + * IMPORTANT !!! |
|
189 | + * The order of elements in the incoming $dependencies array MUST match |
|
190 | + * the order of the constructor parameters for the class in question. |
|
191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | + * |
|
194 | + * @param string $class |
|
195 | + * @param array $dependencies |
|
196 | + * @param int $overwrite |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function registerDependencies( |
|
200 | + $class, |
|
201 | + array $dependencies, |
|
202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | + ) { |
|
204 | + $class = trim($class, '\\'); |
|
205 | + $registered = false; |
|
206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | + } |
|
209 | + // we need to make sure that any aliases used when registering a dependency |
|
210 | + // get resolved to the correct class name |
|
211 | + foreach ($dependencies as $dependency => $load_source) { |
|
212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | + ) { |
|
216 | + unset($dependencies[ $dependency ]); |
|
217 | + $dependencies[ $alias ] = $load_source; |
|
218 | + $registered = true; |
|
219 | + } |
|
220 | + } |
|
221 | + // now add our two lists of dependencies together. |
|
222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | + // so $dependencies is NOT overwritten because it is listed first |
|
224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | + // Union is way faster than array_merge() but should be used with caution... |
|
226 | + // especially with numerically indexed arrays |
|
227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | + // now we need to ensure that the resulting dependencies |
|
229 | + // array only has the entries that are required for the class |
|
230 | + // so first count how many dependencies were originally registered for the class |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | + // then truncate the final array to match that count |
|
235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
236 | + // otherwise just take the incoming array because nothing previously existed |
|
237 | + : $dependencies; |
|
238 | + return $registered; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $class_name |
|
244 | + * @param string $loader |
|
245 | + * @return bool |
|
246 | + * @throws DomainException |
|
247 | + */ |
|
248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | + { |
|
250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | + throw new DomainException( |
|
252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | + if (! is_callable($loader) |
|
257 | + && ( |
|
258 | + strpos($loader, 'load_') !== 0 |
|
259 | + || ! method_exists('EE_Registry', $loader) |
|
260 | + ) |
|
261 | + ) { |
|
262 | + throw new DomainException( |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $loader |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | + return true; |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function dependency_map() |
|
285 | + { |
|
286 | + return $this->_dependency_map; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | + * |
|
293 | + * @param string $class_name |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function has($class_name = '') |
|
297 | + { |
|
298 | + // all legacy models have the same dependencies |
|
299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
300 | + $class_name = 'LEGACY_MODELS'; |
|
301 | + } |
|
302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | + ? true |
|
322 | + : false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | + * |
|
329 | + * @param string $class_name |
|
330 | + * @param string $dependency |
|
331 | + * @return int |
|
332 | + */ |
|
333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | + { |
|
335 | + // all legacy models have the same dependencies |
|
336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
337 | + $class_name = 'LEGACY_MODELS'; |
|
338 | + } |
|
339 | + $dependency = $this->getFqnForAlias($dependency); |
|
340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | + : EE_Dependency_Map::not_registered; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $class_name |
|
348 | + * @return string | Closure |
|
349 | + */ |
|
350 | + public function class_loader($class_name) |
|
351 | + { |
|
352 | + // all legacy models use load_model() |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + return 'load_model'; |
|
355 | + } |
|
356 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | + // perform strpos() first to avoid loading regex every time we load a class |
|
358 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | + ) { |
|
361 | + return 'load_core'; |
|
362 | + } |
|
363 | + $class_name = $this->getFqnForAlias($class_name); |
|
364 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function class_loaders() |
|
372 | + { |
|
373 | + return $this->_class_loaders; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * adds an alias for a classname |
|
379 | + * |
|
380 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | + */ |
|
384 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | + { |
|
386 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | + * WHY? |
|
393 | + * Because if a class is type hinting for a concretion, |
|
394 | + * then why would we need to find another class to supply it? |
|
395 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | + * Don't go looking for some substitute. |
|
398 | + * Whereas if a class is type hinting for an interface... |
|
399 | + * then we need to find an actual class to use. |
|
400 | + * So the interface IS the alias for some other FQN, |
|
401 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | + * represents some other class. |
|
403 | + * |
|
404 | + * @param string $fqn |
|
405 | + * @param string $for_class |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function isAlias($fqn = '', $for_class = '') |
|
409 | + { |
|
410 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | + * for example: |
|
418 | + * if the following two entries were added to the _aliases array: |
|
419 | + * array( |
|
420 | + * 'interface_alias' => 'some\namespace\interface' |
|
421 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | + * ) |
|
423 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | + * to load an instance of 'some\namespace\classname' |
|
425 | + * |
|
426 | + * @param string $alias |
|
427 | + * @param string $for_class |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | + { |
|
432 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | + * This is done by using the following class constants: |
|
440 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | + */ |
|
443 | + protected function _register_core_dependencies() |
|
444 | + { |
|
445 | + $this->_dependency_map = array( |
|
446 | + 'EE_Request_Handler' => array( |
|
447 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_System' => array( |
|
450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_Session' => array( |
|
456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | + ), |
|
462 | + 'EE_Cart' => array( |
|
463 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_Front_Controller' => array( |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messenger_Collection_Loader' => array( |
|
471 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | + ), |
|
473 | + 'EE_Message_Type_Collection_Loader' => array( |
|
474 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Message_Resource_Manager' => array( |
|
477 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_Message_Factory' => array( |
|
482 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_messages' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_Messages_Generator' => array( |
|
488 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EE_Messages_Processor' => array( |
|
494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Messages_Queue' => array( |
|
497 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | + ), |
|
499 | + 'EE_Messages_Template_Defaults' => array( |
|
500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | + ), |
|
503 | + 'EE_Message_To_Generate_From_Request' => array( |
|
504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EE_Data_Migration_Class_Base' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | + ), |
|
567 | + 'EE_DMS_Core_4_1_0' => array( |
|
568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | + ), |
|
571 | + 'EE_DMS_Core_4_2_0' => array( |
|
572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EE_DMS_Core_4_3_0' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | + ), |
|
579 | + 'EE_DMS_Core_4_4_0' => array( |
|
580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EE_DMS_Core_4_5_0' => array( |
|
584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EE_DMS_Core_4_6_0' => array( |
|
588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | + ), |
|
591 | + 'EE_DMS_Core_4_7_0' => array( |
|
592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EE_DMS_Core_4_8_0' => array( |
|
596 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EE_DMS_Core_4_9_0' => array( |
|
600 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | + ), |
|
603 | + 'EE_DMS_Core_4_10_0' => array( |
|
604 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
609 | + array(), |
|
610 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | + ), |
|
612 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
613 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
638 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
641 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
644 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | + ), |
|
647 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
648 | + null, |
|
649 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | + ), |
|
651 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
652 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | + ), |
|
654 | + 'LEGACY_MODELS' => array( |
|
655 | + null, |
|
656 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | + ), |
|
658 | + 'EE_Module_Request_Router' => array( |
|
659 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | + ), |
|
661 | + 'EE_Registration_Processor' => array( |
|
662 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
663 | + ), |
|
664 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
665 | + null, |
|
666 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | + ), |
|
669 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
670 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EE_Admin_Transactions_List_Table' => array( |
|
674 | + null, |
|
675 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | + ), |
|
677 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
678 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | + ), |
|
682 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
683 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | + ), |
|
686 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
687 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | + ), |
|
695 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
696 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | + ), |
|
698 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
699 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | + ), |
|
701 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
702 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | + ), |
|
705 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
706 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | + ), |
|
708 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
709 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | + ), |
|
715 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
716 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | + ), |
|
718 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
719 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | + ), |
|
722 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
723 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | + ), |
|
725 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
726 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | + ), |
|
728 | + 'EE_CPT_Strategy' => array( |
|
729 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | + ), |
|
732 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
733 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | + ), |
|
735 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
736 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | + ), |
|
742 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
743 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
745 | + ), |
|
746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
747 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | + ), |
|
749 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
752 | + ), |
|
753 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
754 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | + ), |
|
756 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
757 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | + ), |
|
759 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
760 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | + ), |
|
762 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
763 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | + ), |
|
765 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
766 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | + ), |
|
769 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
770 | + null, |
|
771 | + null, |
|
772 | + null, |
|
773 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
774 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | + ), |
|
777 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
778 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
780 | + ), |
|
781 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
782 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | + ), |
|
787 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
788 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | + ), |
|
792 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
793 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | + ), |
|
796 | + 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
797 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | + ), |
|
801 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
802 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | + ), |
|
806 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
807 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | + ), |
|
810 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
811 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | + ), |
|
814 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
815 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
816 | + ), |
|
817 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
818 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | + ), |
|
820 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
821 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
822 | + ), |
|
823 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
824 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
826 | + ), |
|
827 | + 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
828 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
830 | + ), |
|
831 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
832 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
833 | + ), |
|
834 | + 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
835 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | + ), |
|
837 | + 'EE_URL_Validation_Strategy' => array( |
|
838 | + null, |
|
839 | + null, |
|
840 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
841 | + ), |
|
842 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
843 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | + 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | + ), |
|
849 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
850 | + 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | + 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
852 | + ), |
|
853 | + 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
854 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | + ), |
|
857 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
858 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | + 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | + ), |
|
861 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
862 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | + ), |
|
864 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | + ], |
|
867 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | + null, |
|
869 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | + ], |
|
872 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | + ], |
|
876 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | + ], |
|
880 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | + ], |
|
884 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | + ], |
|
888 | + ); |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * Registers how core classes are loaded. |
|
894 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
895 | + * 'EE_Request_Handler' => 'load_core' |
|
896 | + * 'EE_Messages_Queue' => 'load_lib' |
|
897 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
898 | + * or, if greater control is required, by providing a custom closure. For example: |
|
899 | + * 'Some_Class' => function () { |
|
900 | + * return new Some_Class(); |
|
901 | + * }, |
|
902 | + * This is required for instantiating dependencies |
|
903 | + * where an interface has been type hinted in a class constructor. For example: |
|
904 | + * 'Required_Interface' => function () { |
|
905 | + * return new A_Class_That_Implements_Required_Interface(); |
|
906 | + * }, |
|
907 | + */ |
|
908 | + protected function _register_core_class_loaders() |
|
909 | + { |
|
910 | + $this->_class_loaders = array( |
|
911 | + // load_core |
|
912 | + 'EE_Dependency_Map' => function () { |
|
913 | + return $this; |
|
914 | + }, |
|
915 | + 'EE_Capabilities' => 'load_core', |
|
916 | + 'EE_Encryption' => 'load_core', |
|
917 | + 'EE_Front_Controller' => 'load_core', |
|
918 | + 'EE_Module_Request_Router' => 'load_core', |
|
919 | + 'EE_Registry' => 'load_core', |
|
920 | + 'EE_Request' => function () { |
|
921 | + return $this->legacy_request; |
|
922 | + }, |
|
923 | + 'EventEspresso\core\services\request\Request' => function () { |
|
924 | + return $this->request; |
|
925 | + }, |
|
926 | + 'EventEspresso\core\services\request\Response' => function () { |
|
927 | + return $this->response; |
|
928 | + }, |
|
929 | + 'EE_Base' => 'load_core', |
|
930 | + 'EE_Request_Handler' => 'load_core', |
|
931 | + 'EE_Session' => 'load_core', |
|
932 | + 'EE_Cron_Tasks' => 'load_core', |
|
933 | + 'EE_System' => 'load_core', |
|
934 | + 'EE_Maintenance_Mode' => 'load_core', |
|
935 | + 'EE_Register_CPTs' => 'load_core', |
|
936 | + 'EE_Admin' => 'load_core', |
|
937 | + 'EE_CPT_Strategy' => 'load_core', |
|
938 | + // load_class |
|
939 | + 'EE_Registration_Processor' => 'load_class', |
|
940 | + // load_lib |
|
941 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
942 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
943 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
944 | + 'EE_Messenger_Collection' => 'load_lib', |
|
945 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
946 | + 'EE_Messages_Processor' => 'load_lib', |
|
947 | + 'EE_Message_Repository' => 'load_lib', |
|
948 | + 'EE_Messages_Queue' => 'load_lib', |
|
949 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
950 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
951 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
952 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
953 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
954 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
955 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
956 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
957 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
958 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
959 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
960 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
961 | + 'EE_Messages_Generator' => function () { |
|
962 | + return EE_Registry::instance()->load_lib( |
|
963 | + 'Messages_Generator', |
|
964 | + array(), |
|
965 | + false, |
|
966 | + false |
|
967 | + ); |
|
968 | + }, |
|
969 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
970 | + return EE_Registry::instance()->load_lib( |
|
971 | + 'Messages_Template_Defaults', |
|
972 | + $arguments, |
|
973 | + false, |
|
974 | + false |
|
975 | + ); |
|
976 | + }, |
|
977 | + // load_helper |
|
978 | + 'EEH_Parse_Shortcodes' => function () { |
|
979 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
980 | + return new EEH_Parse_Shortcodes(); |
|
981 | + } |
|
982 | + return null; |
|
983 | + }, |
|
984 | + 'EE_Template_Config' => function () { |
|
985 | + return EE_Config::instance()->template_settings; |
|
986 | + }, |
|
987 | + 'EE_Currency_Config' => function () { |
|
988 | + return EE_Config::instance()->currency; |
|
989 | + }, |
|
990 | + 'EE_Registration_Config' => function () { |
|
991 | + return EE_Config::instance()->registration; |
|
992 | + }, |
|
993 | + 'EE_Core_Config' => function () { |
|
994 | + return EE_Config::instance()->core; |
|
995 | + }, |
|
996 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
997 | + return LoaderFactory::getLoader(); |
|
998 | + }, |
|
999 | + 'EE_Network_Config' => function () { |
|
1000 | + return EE_Network_Config::instance(); |
|
1001 | + }, |
|
1002 | + 'EE_Config' => function () { |
|
1003 | + return EE_Config::instance(); |
|
1004 | + }, |
|
1005 | + 'EventEspresso\core\domain\Domain' => function () { |
|
1006 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
1007 | + }, |
|
1008 | + 'EE_Admin_Config' => function () { |
|
1009 | + return EE_Config::instance()->admin; |
|
1010 | + }, |
|
1011 | + 'EE_Organization_Config' => function () { |
|
1012 | + return EE_Config::instance()->organization; |
|
1013 | + }, |
|
1014 | + 'EE_Network_Core_Config' => function () { |
|
1015 | + return EE_Network_Config::instance()->core; |
|
1016 | + }, |
|
1017 | + 'EE_Environment_Config' => function () { |
|
1018 | + return EE_Config::instance()->environment; |
|
1019 | + }, |
|
1020 | + ); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * can be used for supplying alternate names for classes, |
|
1026 | + * or for connecting interface names to instantiable classes |
|
1027 | + */ |
|
1028 | + protected function _register_core_aliases() |
|
1029 | + { |
|
1030 | + $aliases = array( |
|
1031 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1032 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1033 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1034 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1035 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1036 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1037 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1038 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1039 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1040 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1041 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1042 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1043 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1044 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1045 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1046 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1047 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1048 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1049 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1050 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1051 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1052 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1053 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1054 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1055 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1056 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1057 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1058 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1059 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1060 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1061 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1062 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1063 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1064 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1065 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1066 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1067 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1068 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
1069 | + ); |
|
1070 | + foreach ($aliases as $alias => $fqn) { |
|
1071 | + if (is_array($fqn)) { |
|
1072 | + foreach ($fqn as $class => $for_class) { |
|
1073 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
1074 | + } |
|
1075 | + continue; |
|
1076 | + } |
|
1077 | + $this->class_cache->addAlias($fqn, $alias); |
|
1078 | + } |
|
1079 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1080 | + $this->class_cache->addAlias( |
|
1081 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1082 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1090 | + * request Primarily used by unit tests. |
|
1091 | + */ |
|
1092 | + public function reset() |
|
1093 | + { |
|
1094 | + $this->_register_core_class_loaders(); |
|
1095 | + $this->_register_core_dependencies(); |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + /** |
|
1100 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
1101 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
1102 | + * WHY? |
|
1103 | + * Because if a class is type hinting for a concretion, |
|
1104 | + * then why would we need to find another class to supply it? |
|
1105 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1106 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1107 | + * Don't go looking for some substitute. |
|
1108 | + * Whereas if a class is type hinting for an interface... |
|
1109 | + * then we need to find an actual class to use. |
|
1110 | + * So the interface IS the alias for some other FQN, |
|
1111 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1112 | + * represents some other class. |
|
1113 | + * |
|
1114 | + * @deprecated 4.9.62.p |
|
1115 | + * @param string $fqn |
|
1116 | + * @param string $for_class |
|
1117 | + * @return bool |
|
1118 | + */ |
|
1119 | + public function has_alias($fqn = '', $for_class = '') |
|
1120 | + { |
|
1121 | + return $this->isAlias($fqn, $for_class); |
|
1122 | + } |
|
1123 | + |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1127 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1128 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1129 | + * for example: |
|
1130 | + * if the following two entries were added to the _aliases array: |
|
1131 | + * array( |
|
1132 | + * 'interface_alias' => 'some\namespace\interface' |
|
1133 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1134 | + * ) |
|
1135 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1136 | + * to load an instance of 'some\namespace\classname' |
|
1137 | + * |
|
1138 | + * @deprecated 4.9.62.p |
|
1139 | + * @param string $alias |
|
1140 | + * @param string $for_class |
|
1141 | + * @return string |
|
1142 | + */ |
|
1143 | + public function get_alias($alias = '', $for_class = '') |
|
1144 | + { |
|
1145 | + return $this->getFqnForAlias($alias, $for_class); |
|
1146 | + } |
|
1147 | 1147 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
5 | -use EventEspresso\core\services\orm\ModelFieldFactory; |
|
6 | 5 | |
7 | 6 | /** |
8 | 7 | * EEM_Event Model |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | 'WP_User' => new EE_Belongs_To_Relation(), |
279 | 279 | ); |
280 | 280 | // this model is generally available for reading |
281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
281 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
282 | 282 | $this->model_chain_to_password = ''; |
283 | 283 | parent::__construct($timezone); |
284 | 284 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function get_all_event_question_groups($EVT_ID = 0) |
373 | 373 | { |
374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
374 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | 375 | EE_Error::add_error( |
376 | 376 | esc_html__( |
377 | 377 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
407 | 407 | { |
408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
408 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | 409 | EE_Error::add_error( |
410 | 410 | esc_html__( |
411 | 411 | // @codingStandardsIgnoreStart |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
450 | 450 | { |
451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
451 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | 452 | EE_Error::add_error( |
453 | 453 | esc_html__( |
454 | 454 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -861,11 +861,11 @@ discard block |
||
861 | 861 | $questions = array(); |
862 | 862 | // get all question groups for event |
863 | 863 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
864 | - if (! empty($qgs)) { |
|
864 | + if ( ! empty($qgs)) { |
|
865 | 865 | foreach ($qgs as $qg) { |
866 | 866 | $qsts = $qg->questions(); |
867 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
867 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
868 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
869 | 869 | foreach ($qsts as $qst) { |
870 | 870 | if ($qst->is_system_question()) { |
871 | 871 | continue; |
@@ -879,26 +879,26 @@ discard block |
||
879 | 879 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
880 | 880 | $qst_name = $qstn_id = $qst->ID(); |
881 | 881 | $ans_id = $answer->ID(); |
882 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
882 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
883 | 883 | $input_name = ''; |
884 | 884 | $input_id = sanitize_key($qst->display_text()); |
885 | 885 | $input_class = ''; |
886 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
886 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
887 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
888 | 888 | . $input_name |
889 | 889 | . $qst_name; |
890 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
890 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
891 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
892 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
893 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
894 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
895 | 895 | // leave responses as-is, don't convert stuff into html entities please! |
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
896 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
897 | 897 | if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
898 | 898 | $QSOs = $qst->options(true, $answer->value()); |
899 | 899 | if (is_array($QSOs)) { |
900 | 900 | foreach ($QSOs as $QSO_ID => $QSO) { |
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
901 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 | } |
@@ -15,913 +15,913 @@ |
||
15 | 15 | class EEM_Event extends EEM_CPT_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
20 | - * event |
|
21 | - */ |
|
22 | - const sold_out = 'sold_out'; |
|
23 | - |
|
24 | - /** |
|
25 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
26 | - * date) |
|
27 | - */ |
|
28 | - const postponed = 'postponed'; |
|
29 | - |
|
30 | - /** |
|
31 | - * constant used by status(), indicating that the event will no longer occur |
|
32 | - */ |
|
33 | - const cancelled = 'cancelled'; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected static $_default_reg_status; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * This is the default for the additional limit field. |
|
44 | - * @var int |
|
45 | - */ |
|
46 | - protected static $_default_additional_limit = 10; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * private instance of the Event object |
|
51 | - * |
|
52 | - * @var EEM_Event |
|
53 | - */ |
|
54 | - protected static $_instance; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
61 | - * |
|
62 | - * @param string $timezone |
|
63 | - * @throws \EE_Error |
|
64 | - */ |
|
65 | - protected function __construct($timezone = null) |
|
66 | - { |
|
67 | - EE_Registry::instance()->load_model('Registration'); |
|
68 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
69 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
70 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
71 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
72 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
73 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
74 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
75 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
76 | - $this->_custom_stati = apply_filters( |
|
77 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
78 | - array( |
|
79 | - EEM_Event::cancelled => array( |
|
80 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
81 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
82 | - ), |
|
83 | - EEM_Event::postponed => array( |
|
84 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
85 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
86 | - ), |
|
87 | - EEM_Event::sold_out => array( |
|
88 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
89 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
90 | - ), |
|
91 | - ) |
|
92 | - ); |
|
93 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
94 | - : self::$_default_reg_status; |
|
95 | - $this->_tables = array( |
|
96 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
97 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
98 | - ); |
|
99 | - $this->_fields = array( |
|
100 | - 'Event_CPT' => array( |
|
101 | - 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
102 | - 'ID', |
|
103 | - esc_html__('Post ID for Event', 'event_espresso') |
|
104 | - ), |
|
105 | - 'EVT_name' => new EE_Plain_Text_Field( |
|
106 | - 'post_title', |
|
107 | - esc_html__('Event Name', 'event_espresso'), |
|
108 | - false, |
|
109 | - '' |
|
110 | - ), |
|
111 | - 'EVT_desc' => new EE_Post_Content_Field( |
|
112 | - 'post_content', |
|
113 | - esc_html__('Event Description', 'event_espresso'), |
|
114 | - false, |
|
115 | - '' |
|
116 | - ), |
|
117 | - 'EVT_slug' => new EE_Slug_Field( |
|
118 | - 'post_name', |
|
119 | - esc_html__('Event Slug', 'event_espresso'), |
|
120 | - false, |
|
121 | - '' |
|
122 | - ), |
|
123 | - 'EVT_created' => new EE_Datetime_Field( |
|
124 | - 'post_date', |
|
125 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
126 | - false, |
|
127 | - EE_Datetime_Field::now |
|
128 | - ), |
|
129 | - 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
130 | - 'post_excerpt', |
|
131 | - esc_html__('Event Short Description', 'event_espresso'), |
|
132 | - false, |
|
133 | - '' |
|
134 | - ), |
|
135 | - 'EVT_modified' => new EE_Datetime_Field( |
|
136 | - 'post_modified', |
|
137 | - esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
138 | - false, |
|
139 | - EE_Datetime_Field::now |
|
140 | - ), |
|
141 | - 'EVT_wp_user' => new EE_WP_User_Field( |
|
142 | - 'post_author', |
|
143 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
144 | - false |
|
145 | - ), |
|
146 | - 'parent' => new EE_Integer_Field( |
|
147 | - 'post_parent', |
|
148 | - esc_html__('Event Parent ID', 'event_espresso'), |
|
149 | - false, |
|
150 | - 0 |
|
151 | - ), |
|
152 | - 'EVT_order' => new EE_Integer_Field( |
|
153 | - 'menu_order', |
|
154 | - esc_html__('Event Menu Order', 'event_espresso'), |
|
155 | - false, |
|
156 | - 1 |
|
157 | - ), |
|
158 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
159 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
160 | - 'status' => new EE_WP_Post_Status_Field( |
|
161 | - 'post_status', |
|
162 | - esc_html__('Event Status', 'event_espresso'), |
|
163 | - false, |
|
164 | - 'draft', |
|
165 | - $this->_custom_stati |
|
166 | - ), |
|
167 | - 'password' => new EE_Password_Field( |
|
168 | - 'post_password', |
|
169 | - __('Password', 'event_espresso'), |
|
170 | - false, |
|
171 | - '', |
|
172 | - array( |
|
173 | - 'EVT_desc', |
|
174 | - 'EVT_short_desc', |
|
175 | - 'EVT_display_desc', |
|
176 | - 'EVT_display_ticket_selector', |
|
177 | - 'EVT_visible_on', |
|
178 | - 'EVT_additional_limit', |
|
179 | - 'EVT_default_registration_status', |
|
180 | - 'EVT_member_only', |
|
181 | - 'EVT_phone', |
|
182 | - 'EVT_allow_overflow', |
|
183 | - 'EVT_timezone_string', |
|
184 | - 'EVT_external_URL', |
|
185 | - 'EVT_donations' |
|
186 | - ) |
|
187 | - ) |
|
188 | - ), |
|
189 | - 'Event_Meta' => array( |
|
190 | - 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
191 | - 'EVTM_ID', |
|
192 | - esc_html__('Event Meta Row ID', 'event_espresso'), |
|
193 | - false |
|
194 | - ), |
|
195 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
196 | - 'EVT_ID', |
|
197 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
198 | - false |
|
199 | - ), |
|
200 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
201 | - 'EVT_display_desc', |
|
202 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
203 | - false, |
|
204 | - true |
|
205 | - ), |
|
206 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
207 | - 'EVT_display_ticket_selector', |
|
208 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
209 | - false, |
|
210 | - true |
|
211 | - ), |
|
212 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
213 | - 'EVT_visible_on', |
|
214 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
215 | - true, |
|
216 | - EE_Datetime_Field::now |
|
217 | - ), |
|
218 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
219 | - 'EVT_additional_limit', |
|
220 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
221 | - true, |
|
222 | - self::$_default_additional_limit |
|
223 | - ), |
|
224 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
225 | - 'EVT_default_registration_status', |
|
226 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
227 | - false, |
|
228 | - EEM_Event::$_default_reg_status, |
|
229 | - EEM_Registration::reg_status_array() |
|
230 | - ), |
|
231 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
232 | - 'EVT_member_only', |
|
233 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
234 | - false, |
|
235 | - false |
|
236 | - ), |
|
237 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
238 | - 'EVT_phone', |
|
239 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
240 | - false, |
|
241 | - '' |
|
242 | - ), |
|
243 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
244 | - 'EVT_allow_overflow', |
|
245 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
246 | - false, |
|
247 | - false |
|
248 | - ), |
|
249 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
250 | - 'EVT_timezone_string', |
|
251 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
252 | - false, |
|
253 | - '' |
|
254 | - ), |
|
255 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
256 | - 'EVT_external_URL', |
|
257 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
258 | - true |
|
259 | - ), |
|
260 | - 'EVT_donations' => new EE_Boolean_Field( |
|
261 | - 'EVT_donations', |
|
262 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
263 | - false, |
|
264 | - false |
|
265 | - ), |
|
266 | - ), |
|
267 | - ); |
|
268 | - $this->_model_relations = array( |
|
269 | - 'Registration' => new EE_Has_Many_Relation(), |
|
270 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
271 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
272 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
273 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
274 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
275 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
276 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
277 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
278 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
279 | - ); |
|
280 | - // this model is generally available for reading |
|
281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
282 | - $this->model_chain_to_password = ''; |
|
283 | - parent::__construct($timezone); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @param string $default_reg_status |
|
290 | - */ |
|
291 | - public static function set_default_reg_status($default_reg_status) |
|
292 | - { |
|
293 | - self::$_default_reg_status = $default_reg_status; |
|
294 | - // if EEM_Event has already been instantiated, |
|
295 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
296 | - if (self::$_instance instanceof EEM_Event) { |
|
297 | - $default_reg_status = new EE_Enum_Text_Field( |
|
298 | - 'EVT_default_registration_status', |
|
299 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
300 | - false, |
|
301 | - $default_reg_status, |
|
302 | - EEM_Registration::reg_status_array() |
|
303 | - ); |
|
304 | - $default_reg_status->_construct_finalize( |
|
305 | - 'Event_Meta', |
|
306 | - 'EVT_default_registration_status', |
|
307 | - 'EEM_Event' |
|
308 | - ); |
|
309 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Used to override the default for the additional limit field. |
|
316 | - * @param $additional_limit |
|
317 | - */ |
|
318 | - public static function set_default_additional_limit($additional_limit) |
|
319 | - { |
|
320 | - self::$_default_additional_limit = (int) $additional_limit; |
|
321 | - if (self::$_instance instanceof EEM_Event) { |
|
322 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
323 | - 'EVT_additional_limit', |
|
324 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
325 | - true, |
|
326 | - self::$_default_additional_limit |
|
327 | - ); |
|
328 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
329 | - 'Event_Meta', |
|
330 | - 'EVT_additional_limit', |
|
331 | - 'EEM_Event' |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Return what is currently set as the default additional limit for the event. |
|
339 | - * @return int |
|
340 | - */ |
|
341 | - public static function get_default_additional_limit() |
|
342 | - { |
|
343 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * get_question_groups |
|
349 | - * |
|
350 | - * @return array |
|
351 | - * @throws \EE_Error |
|
352 | - */ |
|
353 | - public function get_all_question_groups() |
|
354 | - { |
|
355 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
356 | - array( |
|
357 | - array('QSG_deleted' => false), |
|
358 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
359 | - ) |
|
360 | - ); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * get_question_groups |
|
367 | - * |
|
368 | - * @param int $EVT_ID |
|
369 | - * @return array|bool |
|
370 | - * @throws \EE_Error |
|
371 | - */ |
|
372 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
373 | - { |
|
374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | - EE_Error::add_error( |
|
376 | - esc_html__( |
|
377 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
378 | - 'event_espresso' |
|
379 | - ), |
|
380 | - __FILE__, |
|
381 | - __FUNCTION__, |
|
382 | - __LINE__ |
|
383 | - ); |
|
384 | - return false; |
|
385 | - } |
|
386 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
387 | - array( |
|
388 | - array('EVT_ID' => $EVT_ID), |
|
389 | - ) |
|
390 | - ); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * get_question_groups |
|
396 | - * |
|
397 | - * @param int $EVT_ID |
|
398 | - * @param boolean $for_primary_attendee |
|
399 | - * @return array|bool |
|
400 | - * @throws EE_Error |
|
401 | - * @throws InvalidArgumentException |
|
402 | - * @throws ReflectionException |
|
403 | - * @throws InvalidDataTypeException |
|
404 | - * @throws InvalidInterfaceException |
|
405 | - */ |
|
406 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
407 | - { |
|
408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | - EE_Error::add_error( |
|
410 | - esc_html__( |
|
411 | - // @codingStandardsIgnoreStart |
|
412 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
413 | - // @codingStandardsIgnoreEnd |
|
414 | - 'event_espresso' |
|
415 | - ), |
|
416 | - __FILE__, |
|
417 | - __FUNCTION__, |
|
418 | - __LINE__ |
|
419 | - ); |
|
420 | - return false; |
|
421 | - } |
|
422 | - $query_params = [ |
|
423 | - [ |
|
424 | - 'EVT_ID' => $EVT_ID, |
|
425 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
426 | - ] |
|
427 | - ]; |
|
428 | - if ($for_primary_attendee) { |
|
429 | - $query_params[0]['EQG_primary'] = true; |
|
430 | - } else { |
|
431 | - $query_params[0]['EQG_additional'] = true; |
|
432 | - } |
|
433 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * get_question_groups |
|
439 | - * |
|
440 | - * @param int $EVT_ID |
|
441 | - * @param EE_Registration $registration |
|
442 | - * @return array|bool |
|
443 | - * @throws EE_Error |
|
444 | - * @throws InvalidArgumentException |
|
445 | - * @throws InvalidDataTypeException |
|
446 | - * @throws InvalidInterfaceException |
|
447 | - * @throws ReflectionException |
|
448 | - */ |
|
449 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
450 | - { |
|
451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | - EE_Error::add_error( |
|
453 | - esc_html__( |
|
454 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
455 | - 'event_espresso' |
|
456 | - ), |
|
457 | - __FILE__, |
|
458 | - __FUNCTION__, |
|
459 | - __LINE__ |
|
460 | - ); |
|
461 | - return false; |
|
462 | - } |
|
463 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
464 | - [ |
|
465 | - [ |
|
466 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
467 | - 'Event_Question_Group.' |
|
468 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
469 | - $registration->is_primary_registrant() |
|
470 | - ) => true |
|
471 | - ], |
|
472 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
473 | - ] |
|
474 | - ); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * get_question_target_db_column |
|
481 | - * |
|
482 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
483 | - * @return array|bool |
|
484 | - * @throws \EE_Error |
|
485 | - */ |
|
486 | - public function get_questions_in_groups($QSG_IDs = '') |
|
487 | - { |
|
488 | - if (empty($QSG_IDs)) { |
|
489 | - EE_Error::add_error( |
|
490 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
491 | - __FILE__, |
|
492 | - __FUNCTION__, |
|
493 | - __LINE__ |
|
494 | - ); |
|
495 | - return false; |
|
496 | - } |
|
497 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
498 | - array( |
|
499 | - array( |
|
500 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
501 | - 'QST_deleted' => false, |
|
502 | - 'QST_admin_only' => is_admin(), |
|
503 | - ), |
|
504 | - 'order_by' => 'QST_order', |
|
505 | - ) |
|
506 | - ); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * get_options_for_question |
|
513 | - * |
|
514 | - * @param string $QST_IDs csv list of $QST IDs |
|
515 | - * @return array|bool |
|
516 | - * @throws \EE_Error |
|
517 | - */ |
|
518 | - public function get_options_for_question($QST_IDs) |
|
519 | - { |
|
520 | - if (empty($QST_IDs)) { |
|
521 | - EE_Error::add_error( |
|
522 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
523 | - __FILE__, |
|
524 | - __FUNCTION__, |
|
525 | - __LINE__ |
|
526 | - ); |
|
527 | - return false; |
|
528 | - } |
|
529 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
530 | - array( |
|
531 | - array( |
|
532 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
533 | - 'QSO_deleted' => false, |
|
534 | - ), |
|
535 | - 'order_by' => 'QSO_ID', |
|
536 | - ) |
|
537 | - ); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Gets all events that are published |
|
548 | - * and have event start time earlier than now and an event end time later than now |
|
549 | - * |
|
550 | - * @param array $query_params An array of query params to further filter on |
|
551 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
552 | - * @param bool $count whether to return the count or not (default FALSE) |
|
553 | - * @return EE_Event[]|int |
|
554 | - * @throws \EE_Error |
|
555 | - */ |
|
556 | - public function get_active_events($query_params, $count = false) |
|
557 | - { |
|
558 | - if (array_key_exists(0, $query_params)) { |
|
559 | - $where_params = $query_params[0]; |
|
560 | - unset($query_params[0]); |
|
561 | - } else { |
|
562 | - $where_params = array(); |
|
563 | - } |
|
564 | - // if we have count make sure we don't include group by |
|
565 | - if ($count && isset($query_params['group_by'])) { |
|
566 | - unset($query_params['group_by']); |
|
567 | - } |
|
568 | - // let's add specific query_params for active_events |
|
569 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
570 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
571 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
572 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
573 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
574 | - '<', |
|
575 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
576 | - ); |
|
577 | - } else { |
|
578 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
579 | - '<', |
|
580 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
581 | - ); |
|
582 | - } |
|
583 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
584 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
585 | - '>', |
|
586 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
587 | - ); |
|
588 | - } else { |
|
589 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
590 | - '>', |
|
591 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
592 | - ); |
|
593 | - } |
|
594 | - $query_params[0] = $where_params; |
|
595 | - // don't use $query_params with count() |
|
596 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
597 | - return $count |
|
598 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
599 | - : $this->get_all($query_params); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * get all events that are published and have an event start time later than now |
|
606 | - * |
|
607 | - * @param array $query_params An array of query params to further filter on |
|
608 | - * (Note that status and DTT_EVT_start will be overridden) |
|
609 | - * @param bool $count whether to return the count or not (default FALSE) |
|
610 | - * @return EE_Event[]|int |
|
611 | - * @throws \EE_Error |
|
612 | - */ |
|
613 | - public function get_upcoming_events($query_params, $count = false) |
|
614 | - { |
|
615 | - if (array_key_exists(0, $query_params)) { |
|
616 | - $where_params = $query_params[0]; |
|
617 | - unset($query_params[0]); |
|
618 | - } else { |
|
619 | - $where_params = array(); |
|
620 | - } |
|
621 | - // if we have count make sure we don't include group by |
|
622 | - if ($count && isset($query_params['group_by'])) { |
|
623 | - unset($query_params['group_by']); |
|
624 | - } |
|
625 | - // let's add specific query_params for active_events |
|
626 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
627 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
628 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
629 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
630 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
631 | - '>', |
|
632 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
633 | - ); |
|
634 | - } else { |
|
635 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
636 | - '>', |
|
637 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
638 | - ); |
|
639 | - } |
|
640 | - $query_params[0] = $where_params; |
|
641 | - // don't use $query_params with count() |
|
642 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
643 | - return $count |
|
644 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
645 | - : $this->get_all($query_params); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Gets all events that are published |
|
652 | - * and have an event end time later than now |
|
653 | - * |
|
654 | - * @param array $query_params An array of query params to further filter on |
|
655 | - * (note that status and DTT_EVT_end will be overridden) |
|
656 | - * @param bool $count whether to return the count or not (default FALSE) |
|
657 | - * @return EE_Event[]|int |
|
658 | - * @throws \EE_Error |
|
659 | - */ |
|
660 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
661 | - { |
|
662 | - if (array_key_exists(0, $query_params)) { |
|
663 | - $where_params = $query_params[0]; |
|
664 | - unset($query_params[0]); |
|
665 | - } else { |
|
666 | - $where_params = array(); |
|
667 | - } |
|
668 | - // if we have count make sure we don't include group by |
|
669 | - if ($count && isset($query_params['group_by'])) { |
|
670 | - unset($query_params['group_by']); |
|
671 | - } |
|
672 | - // let's add specific query_params for active_events |
|
673 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
674 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
675 | - // add where params for DTT_EVT_end |
|
676 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
677 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
678 | - '>', |
|
679 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
680 | - ); |
|
681 | - } else { |
|
682 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
683 | - '>', |
|
684 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
685 | - ); |
|
686 | - } |
|
687 | - $query_params[0] = $where_params; |
|
688 | - // don't use $query_params with count() |
|
689 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
690 | - return $count |
|
691 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
692 | - : $this->get_all($query_params); |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * This only returns events that are expired. |
|
699 | - * They may still be published but all their datetimes have expired. |
|
700 | - * |
|
701 | - * @param array $query_params An array of query params to further filter on |
|
702 | - * (note that status and DTT_EVT_end will be overridden) |
|
703 | - * @param bool $count whether to return the count or not (default FALSE) |
|
704 | - * @return EE_Event[]|int |
|
705 | - * @throws \EE_Error |
|
706 | - */ |
|
707 | - public function get_expired_events($query_params, $count = false) |
|
708 | - { |
|
709 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
710 | - // if we have count make sure we don't include group by |
|
711 | - if ($count && isset($query_params['group_by'])) { |
|
712 | - unset($query_params['group_by']); |
|
713 | - } |
|
714 | - // let's add specific query_params for active_events |
|
715 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
716 | - if (isset($where_params['status'])) { |
|
717 | - unset($where_params['status']); |
|
718 | - } |
|
719 | - $exclude_query = $query_params; |
|
720 | - if (isset($exclude_query[0])) { |
|
721 | - unset($exclude_query[0]); |
|
722 | - } |
|
723 | - $exclude_query[0] = array( |
|
724 | - 'Datetime.DTT_EVT_end' => array( |
|
725 | - '>', |
|
726 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
727 | - ), |
|
728 | - ); |
|
729 | - // first get all events that have datetimes where its not expired. |
|
730 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
731 | - $event_ids = array_keys($event_ids); |
|
732 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
733 | - $and_condition = array( |
|
734 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
735 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
736 | - ); |
|
737 | - if (isset($where_params['OR'])) { |
|
738 | - $and_condition['OR'] = $where_params['OR']; |
|
739 | - unset($where_params['OR']); |
|
740 | - } |
|
741 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
742 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
743 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
744 | - } |
|
745 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
746 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
747 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
748 | - } |
|
749 | - // merge remaining $where params with the and conditions. |
|
750 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
751 | - $query_params[0] = $where_params; |
|
752 | - // don't use $query_params with count() |
|
753 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
754 | - return $count |
|
755 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
756 | - : $this->get_all($query_params); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * This basically just returns the events that do not have the publish status. |
|
763 | - * |
|
764 | - * @param array $query_params An array of query params to further filter on |
|
765 | - * (note that status will be overwritten) |
|
766 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
767 | - * @return EE_Event[]|int |
|
768 | - * @throws \EE_Error |
|
769 | - */ |
|
770 | - public function get_inactive_events($query_params, $count = false) |
|
771 | - { |
|
772 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
773 | - // let's add in specific query_params for inactive events. |
|
774 | - if (isset($where_params['status'])) { |
|
775 | - unset($where_params['status']); |
|
776 | - } |
|
777 | - // if we have count make sure we don't include group by |
|
778 | - if ($count && isset($query_params['group_by'])) { |
|
779 | - unset($query_params['group_by']); |
|
780 | - } |
|
781 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
782 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
783 | - if (isset($where_params['OR'])) { |
|
784 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
785 | - unset($where_params['OR']); |
|
786 | - } |
|
787 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
788 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
789 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
790 | - } |
|
791 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
792 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
793 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
794 | - } |
|
795 | - $query_params[0] = $where_params; |
|
796 | - // don't use $query_params with count() |
|
797 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
798 | - return $count |
|
799 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
800 | - : $this->get_all($query_params); |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
807 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
808 | - * attached to the event. See parent for param descriptions |
|
809 | - * |
|
810 | - * @param $id_or_obj |
|
811 | - * @param $other_model_id_or_obj |
|
812 | - * @param string $relationName |
|
813 | - * @param array $where_query |
|
814 | - * @return EE_Base_Class |
|
815 | - * @throws EE_Error |
|
816 | - */ |
|
817 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
818 | - { |
|
819 | - if ($relationName === 'Price') { |
|
820 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
821 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
822 | - // if EVT_ID = 0, then this is a default |
|
823 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
824 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
825 | - $prc_chk->set('PRC_ID', 0); |
|
826 | - } |
|
827 | - // run parent |
|
828 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
829 | - } |
|
830 | - // otherwise carry on as normal |
|
831 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
832 | - } |
|
833 | - |
|
834 | - |
|
835 | - |
|
836 | - /******************** DEPRECATED METHODS ********************/ |
|
837 | - |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * _get_question_target_db_column |
|
842 | - * |
|
843 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
844 | - * EE_Registration_Custom_Questions_Form located in |
|
845 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
846 | - * @access public |
|
847 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
848 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
849 | - * registration). |
|
850 | - * @throws EE_Error |
|
851 | - * @return array |
|
852 | - */ |
|
853 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
854 | - { |
|
855 | - if (empty($EVT_ID)) { |
|
856 | - throw new EE_Error(__( |
|
857 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
858 | - 'event_espresso' |
|
859 | - )); |
|
860 | - } |
|
861 | - $questions = array(); |
|
862 | - // get all question groups for event |
|
863 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
864 | - if (! empty($qgs)) { |
|
865 | - foreach ($qgs as $qg) { |
|
866 | - $qsts = $qg->questions(); |
|
867 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
869 | - foreach ($qsts as $qst) { |
|
870 | - if ($qst->is_system_question()) { |
|
871 | - continue; |
|
872 | - } |
|
873 | - $answer = EEM_Answer::instance()->get_one(array( |
|
874 | - array( |
|
875 | - 'QST_ID' => $qst->ID(), |
|
876 | - 'REG_ID' => $registration->ID(), |
|
877 | - ), |
|
878 | - )); |
|
879 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
880 | - $qst_name = $qstn_id = $qst->ID(); |
|
881 | - $ans_id = $answer->ID(); |
|
882 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
883 | - $input_name = ''; |
|
884 | - $input_id = sanitize_key($qst->display_text()); |
|
885 | - $input_class = ''; |
|
886 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
888 | - . $input_name |
|
889 | - . $qst_name; |
|
890 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
895 | - // leave responses as-is, don't convert stuff into html entities please! |
|
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
897 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
898 | - $QSOs = $qst->options(true, $answer->value()); |
|
899 | - if (is_array($QSOs)) { |
|
900 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
902 | - } |
|
903 | - } |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - } |
|
908 | - return $questions; |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
914 | - * or an stdClass where each property is the name of a column, |
|
915 | - * @return EE_Base_Class |
|
916 | - * @throws \EE_Error |
|
917 | - */ |
|
918 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
919 | - { |
|
920 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
921 | - if ($classInstance instanceof EE_Event) { |
|
922 | - // events have their timezone defined in the DB, so use it immediately |
|
923 | - $this->set_timezone($classInstance->get_timezone()); |
|
924 | - } |
|
925 | - return $classInstance; |
|
926 | - } |
|
18 | + /** |
|
19 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
20 | + * event |
|
21 | + */ |
|
22 | + const sold_out = 'sold_out'; |
|
23 | + |
|
24 | + /** |
|
25 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
26 | + * date) |
|
27 | + */ |
|
28 | + const postponed = 'postponed'; |
|
29 | + |
|
30 | + /** |
|
31 | + * constant used by status(), indicating that the event will no longer occur |
|
32 | + */ |
|
33 | + const cancelled = 'cancelled'; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected static $_default_reg_status; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * This is the default for the additional limit field. |
|
44 | + * @var int |
|
45 | + */ |
|
46 | + protected static $_default_additional_limit = 10; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * private instance of the Event object |
|
51 | + * |
|
52 | + * @var EEM_Event |
|
53 | + */ |
|
54 | + protected static $_instance; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
61 | + * |
|
62 | + * @param string $timezone |
|
63 | + * @throws \EE_Error |
|
64 | + */ |
|
65 | + protected function __construct($timezone = null) |
|
66 | + { |
|
67 | + EE_Registry::instance()->load_model('Registration'); |
|
68 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
69 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
70 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
71 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
72 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
73 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
74 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
75 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
76 | + $this->_custom_stati = apply_filters( |
|
77 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
78 | + array( |
|
79 | + EEM_Event::cancelled => array( |
|
80 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
81 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
82 | + ), |
|
83 | + EEM_Event::postponed => array( |
|
84 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
85 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
86 | + ), |
|
87 | + EEM_Event::sold_out => array( |
|
88 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
89 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
90 | + ), |
|
91 | + ) |
|
92 | + ); |
|
93 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
94 | + : self::$_default_reg_status; |
|
95 | + $this->_tables = array( |
|
96 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
97 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
98 | + ); |
|
99 | + $this->_fields = array( |
|
100 | + 'Event_CPT' => array( |
|
101 | + 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
102 | + 'ID', |
|
103 | + esc_html__('Post ID for Event', 'event_espresso') |
|
104 | + ), |
|
105 | + 'EVT_name' => new EE_Plain_Text_Field( |
|
106 | + 'post_title', |
|
107 | + esc_html__('Event Name', 'event_espresso'), |
|
108 | + false, |
|
109 | + '' |
|
110 | + ), |
|
111 | + 'EVT_desc' => new EE_Post_Content_Field( |
|
112 | + 'post_content', |
|
113 | + esc_html__('Event Description', 'event_espresso'), |
|
114 | + false, |
|
115 | + '' |
|
116 | + ), |
|
117 | + 'EVT_slug' => new EE_Slug_Field( |
|
118 | + 'post_name', |
|
119 | + esc_html__('Event Slug', 'event_espresso'), |
|
120 | + false, |
|
121 | + '' |
|
122 | + ), |
|
123 | + 'EVT_created' => new EE_Datetime_Field( |
|
124 | + 'post_date', |
|
125 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
126 | + false, |
|
127 | + EE_Datetime_Field::now |
|
128 | + ), |
|
129 | + 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
130 | + 'post_excerpt', |
|
131 | + esc_html__('Event Short Description', 'event_espresso'), |
|
132 | + false, |
|
133 | + '' |
|
134 | + ), |
|
135 | + 'EVT_modified' => new EE_Datetime_Field( |
|
136 | + 'post_modified', |
|
137 | + esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
138 | + false, |
|
139 | + EE_Datetime_Field::now |
|
140 | + ), |
|
141 | + 'EVT_wp_user' => new EE_WP_User_Field( |
|
142 | + 'post_author', |
|
143 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
144 | + false |
|
145 | + ), |
|
146 | + 'parent' => new EE_Integer_Field( |
|
147 | + 'post_parent', |
|
148 | + esc_html__('Event Parent ID', 'event_espresso'), |
|
149 | + false, |
|
150 | + 0 |
|
151 | + ), |
|
152 | + 'EVT_order' => new EE_Integer_Field( |
|
153 | + 'menu_order', |
|
154 | + esc_html__('Event Menu Order', 'event_espresso'), |
|
155 | + false, |
|
156 | + 1 |
|
157 | + ), |
|
158 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
159 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
160 | + 'status' => new EE_WP_Post_Status_Field( |
|
161 | + 'post_status', |
|
162 | + esc_html__('Event Status', 'event_espresso'), |
|
163 | + false, |
|
164 | + 'draft', |
|
165 | + $this->_custom_stati |
|
166 | + ), |
|
167 | + 'password' => new EE_Password_Field( |
|
168 | + 'post_password', |
|
169 | + __('Password', 'event_espresso'), |
|
170 | + false, |
|
171 | + '', |
|
172 | + array( |
|
173 | + 'EVT_desc', |
|
174 | + 'EVT_short_desc', |
|
175 | + 'EVT_display_desc', |
|
176 | + 'EVT_display_ticket_selector', |
|
177 | + 'EVT_visible_on', |
|
178 | + 'EVT_additional_limit', |
|
179 | + 'EVT_default_registration_status', |
|
180 | + 'EVT_member_only', |
|
181 | + 'EVT_phone', |
|
182 | + 'EVT_allow_overflow', |
|
183 | + 'EVT_timezone_string', |
|
184 | + 'EVT_external_URL', |
|
185 | + 'EVT_donations' |
|
186 | + ) |
|
187 | + ) |
|
188 | + ), |
|
189 | + 'Event_Meta' => array( |
|
190 | + 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
191 | + 'EVTM_ID', |
|
192 | + esc_html__('Event Meta Row ID', 'event_espresso'), |
|
193 | + false |
|
194 | + ), |
|
195 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
196 | + 'EVT_ID', |
|
197 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
198 | + false |
|
199 | + ), |
|
200 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
201 | + 'EVT_display_desc', |
|
202 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
203 | + false, |
|
204 | + true |
|
205 | + ), |
|
206 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
207 | + 'EVT_display_ticket_selector', |
|
208 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
209 | + false, |
|
210 | + true |
|
211 | + ), |
|
212 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
213 | + 'EVT_visible_on', |
|
214 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
215 | + true, |
|
216 | + EE_Datetime_Field::now |
|
217 | + ), |
|
218 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
219 | + 'EVT_additional_limit', |
|
220 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
221 | + true, |
|
222 | + self::$_default_additional_limit |
|
223 | + ), |
|
224 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
225 | + 'EVT_default_registration_status', |
|
226 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
227 | + false, |
|
228 | + EEM_Event::$_default_reg_status, |
|
229 | + EEM_Registration::reg_status_array() |
|
230 | + ), |
|
231 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
232 | + 'EVT_member_only', |
|
233 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
234 | + false, |
|
235 | + false |
|
236 | + ), |
|
237 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
238 | + 'EVT_phone', |
|
239 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
240 | + false, |
|
241 | + '' |
|
242 | + ), |
|
243 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
244 | + 'EVT_allow_overflow', |
|
245 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
246 | + false, |
|
247 | + false |
|
248 | + ), |
|
249 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
250 | + 'EVT_timezone_string', |
|
251 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
252 | + false, |
|
253 | + '' |
|
254 | + ), |
|
255 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
256 | + 'EVT_external_URL', |
|
257 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
258 | + true |
|
259 | + ), |
|
260 | + 'EVT_donations' => new EE_Boolean_Field( |
|
261 | + 'EVT_donations', |
|
262 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
263 | + false, |
|
264 | + false |
|
265 | + ), |
|
266 | + ), |
|
267 | + ); |
|
268 | + $this->_model_relations = array( |
|
269 | + 'Registration' => new EE_Has_Many_Relation(), |
|
270 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
271 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
272 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
273 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
274 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
275 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
276 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
277 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
278 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
279 | + ); |
|
280 | + // this model is generally available for reading |
|
281 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
282 | + $this->model_chain_to_password = ''; |
|
283 | + parent::__construct($timezone); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @param string $default_reg_status |
|
290 | + */ |
|
291 | + public static function set_default_reg_status($default_reg_status) |
|
292 | + { |
|
293 | + self::$_default_reg_status = $default_reg_status; |
|
294 | + // if EEM_Event has already been instantiated, |
|
295 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
296 | + if (self::$_instance instanceof EEM_Event) { |
|
297 | + $default_reg_status = new EE_Enum_Text_Field( |
|
298 | + 'EVT_default_registration_status', |
|
299 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
300 | + false, |
|
301 | + $default_reg_status, |
|
302 | + EEM_Registration::reg_status_array() |
|
303 | + ); |
|
304 | + $default_reg_status->_construct_finalize( |
|
305 | + 'Event_Meta', |
|
306 | + 'EVT_default_registration_status', |
|
307 | + 'EEM_Event' |
|
308 | + ); |
|
309 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Used to override the default for the additional limit field. |
|
316 | + * @param $additional_limit |
|
317 | + */ |
|
318 | + public static function set_default_additional_limit($additional_limit) |
|
319 | + { |
|
320 | + self::$_default_additional_limit = (int) $additional_limit; |
|
321 | + if (self::$_instance instanceof EEM_Event) { |
|
322 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
323 | + 'EVT_additional_limit', |
|
324 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
325 | + true, |
|
326 | + self::$_default_additional_limit |
|
327 | + ); |
|
328 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
329 | + 'Event_Meta', |
|
330 | + 'EVT_additional_limit', |
|
331 | + 'EEM_Event' |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Return what is currently set as the default additional limit for the event. |
|
339 | + * @return int |
|
340 | + */ |
|
341 | + public static function get_default_additional_limit() |
|
342 | + { |
|
343 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * get_question_groups |
|
349 | + * |
|
350 | + * @return array |
|
351 | + * @throws \EE_Error |
|
352 | + */ |
|
353 | + public function get_all_question_groups() |
|
354 | + { |
|
355 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
356 | + array( |
|
357 | + array('QSG_deleted' => false), |
|
358 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
359 | + ) |
|
360 | + ); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * get_question_groups |
|
367 | + * |
|
368 | + * @param int $EVT_ID |
|
369 | + * @return array|bool |
|
370 | + * @throws \EE_Error |
|
371 | + */ |
|
372 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
373 | + { |
|
374 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | + EE_Error::add_error( |
|
376 | + esc_html__( |
|
377 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
378 | + 'event_espresso' |
|
379 | + ), |
|
380 | + __FILE__, |
|
381 | + __FUNCTION__, |
|
382 | + __LINE__ |
|
383 | + ); |
|
384 | + return false; |
|
385 | + } |
|
386 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
387 | + array( |
|
388 | + array('EVT_ID' => $EVT_ID), |
|
389 | + ) |
|
390 | + ); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * get_question_groups |
|
396 | + * |
|
397 | + * @param int $EVT_ID |
|
398 | + * @param boolean $for_primary_attendee |
|
399 | + * @return array|bool |
|
400 | + * @throws EE_Error |
|
401 | + * @throws InvalidArgumentException |
|
402 | + * @throws ReflectionException |
|
403 | + * @throws InvalidDataTypeException |
|
404 | + * @throws InvalidInterfaceException |
|
405 | + */ |
|
406 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
407 | + { |
|
408 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | + EE_Error::add_error( |
|
410 | + esc_html__( |
|
411 | + // @codingStandardsIgnoreStart |
|
412 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
413 | + // @codingStandardsIgnoreEnd |
|
414 | + 'event_espresso' |
|
415 | + ), |
|
416 | + __FILE__, |
|
417 | + __FUNCTION__, |
|
418 | + __LINE__ |
|
419 | + ); |
|
420 | + return false; |
|
421 | + } |
|
422 | + $query_params = [ |
|
423 | + [ |
|
424 | + 'EVT_ID' => $EVT_ID, |
|
425 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
426 | + ] |
|
427 | + ]; |
|
428 | + if ($for_primary_attendee) { |
|
429 | + $query_params[0]['EQG_primary'] = true; |
|
430 | + } else { |
|
431 | + $query_params[0]['EQG_additional'] = true; |
|
432 | + } |
|
433 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * get_question_groups |
|
439 | + * |
|
440 | + * @param int $EVT_ID |
|
441 | + * @param EE_Registration $registration |
|
442 | + * @return array|bool |
|
443 | + * @throws EE_Error |
|
444 | + * @throws InvalidArgumentException |
|
445 | + * @throws InvalidDataTypeException |
|
446 | + * @throws InvalidInterfaceException |
|
447 | + * @throws ReflectionException |
|
448 | + */ |
|
449 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
450 | + { |
|
451 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | + EE_Error::add_error( |
|
453 | + esc_html__( |
|
454 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
455 | + 'event_espresso' |
|
456 | + ), |
|
457 | + __FILE__, |
|
458 | + __FUNCTION__, |
|
459 | + __LINE__ |
|
460 | + ); |
|
461 | + return false; |
|
462 | + } |
|
463 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
464 | + [ |
|
465 | + [ |
|
466 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
467 | + 'Event_Question_Group.' |
|
468 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
469 | + $registration->is_primary_registrant() |
|
470 | + ) => true |
|
471 | + ], |
|
472 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
473 | + ] |
|
474 | + ); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * get_question_target_db_column |
|
481 | + * |
|
482 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
483 | + * @return array|bool |
|
484 | + * @throws \EE_Error |
|
485 | + */ |
|
486 | + public function get_questions_in_groups($QSG_IDs = '') |
|
487 | + { |
|
488 | + if (empty($QSG_IDs)) { |
|
489 | + EE_Error::add_error( |
|
490 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
491 | + __FILE__, |
|
492 | + __FUNCTION__, |
|
493 | + __LINE__ |
|
494 | + ); |
|
495 | + return false; |
|
496 | + } |
|
497 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
498 | + array( |
|
499 | + array( |
|
500 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
501 | + 'QST_deleted' => false, |
|
502 | + 'QST_admin_only' => is_admin(), |
|
503 | + ), |
|
504 | + 'order_by' => 'QST_order', |
|
505 | + ) |
|
506 | + ); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * get_options_for_question |
|
513 | + * |
|
514 | + * @param string $QST_IDs csv list of $QST IDs |
|
515 | + * @return array|bool |
|
516 | + * @throws \EE_Error |
|
517 | + */ |
|
518 | + public function get_options_for_question($QST_IDs) |
|
519 | + { |
|
520 | + if (empty($QST_IDs)) { |
|
521 | + EE_Error::add_error( |
|
522 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
523 | + __FILE__, |
|
524 | + __FUNCTION__, |
|
525 | + __LINE__ |
|
526 | + ); |
|
527 | + return false; |
|
528 | + } |
|
529 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
530 | + array( |
|
531 | + array( |
|
532 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
533 | + 'QSO_deleted' => false, |
|
534 | + ), |
|
535 | + 'order_by' => 'QSO_ID', |
|
536 | + ) |
|
537 | + ); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Gets all events that are published |
|
548 | + * and have event start time earlier than now and an event end time later than now |
|
549 | + * |
|
550 | + * @param array $query_params An array of query params to further filter on |
|
551 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
552 | + * @param bool $count whether to return the count or not (default FALSE) |
|
553 | + * @return EE_Event[]|int |
|
554 | + * @throws \EE_Error |
|
555 | + */ |
|
556 | + public function get_active_events($query_params, $count = false) |
|
557 | + { |
|
558 | + if (array_key_exists(0, $query_params)) { |
|
559 | + $where_params = $query_params[0]; |
|
560 | + unset($query_params[0]); |
|
561 | + } else { |
|
562 | + $where_params = array(); |
|
563 | + } |
|
564 | + // if we have count make sure we don't include group by |
|
565 | + if ($count && isset($query_params['group_by'])) { |
|
566 | + unset($query_params['group_by']); |
|
567 | + } |
|
568 | + // let's add specific query_params for active_events |
|
569 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
570 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
571 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
572 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
573 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
574 | + '<', |
|
575 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
576 | + ); |
|
577 | + } else { |
|
578 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
579 | + '<', |
|
580 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
581 | + ); |
|
582 | + } |
|
583 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
584 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
585 | + '>', |
|
586 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
587 | + ); |
|
588 | + } else { |
|
589 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
590 | + '>', |
|
591 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
592 | + ); |
|
593 | + } |
|
594 | + $query_params[0] = $where_params; |
|
595 | + // don't use $query_params with count() |
|
596 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
597 | + return $count |
|
598 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
599 | + : $this->get_all($query_params); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * get all events that are published and have an event start time later than now |
|
606 | + * |
|
607 | + * @param array $query_params An array of query params to further filter on |
|
608 | + * (Note that status and DTT_EVT_start will be overridden) |
|
609 | + * @param bool $count whether to return the count or not (default FALSE) |
|
610 | + * @return EE_Event[]|int |
|
611 | + * @throws \EE_Error |
|
612 | + */ |
|
613 | + public function get_upcoming_events($query_params, $count = false) |
|
614 | + { |
|
615 | + if (array_key_exists(0, $query_params)) { |
|
616 | + $where_params = $query_params[0]; |
|
617 | + unset($query_params[0]); |
|
618 | + } else { |
|
619 | + $where_params = array(); |
|
620 | + } |
|
621 | + // if we have count make sure we don't include group by |
|
622 | + if ($count && isset($query_params['group_by'])) { |
|
623 | + unset($query_params['group_by']); |
|
624 | + } |
|
625 | + // let's add specific query_params for active_events |
|
626 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
627 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
628 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
629 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
630 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
631 | + '>', |
|
632 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
633 | + ); |
|
634 | + } else { |
|
635 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
636 | + '>', |
|
637 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
638 | + ); |
|
639 | + } |
|
640 | + $query_params[0] = $where_params; |
|
641 | + // don't use $query_params with count() |
|
642 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
643 | + return $count |
|
644 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
645 | + : $this->get_all($query_params); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Gets all events that are published |
|
652 | + * and have an event end time later than now |
|
653 | + * |
|
654 | + * @param array $query_params An array of query params to further filter on |
|
655 | + * (note that status and DTT_EVT_end will be overridden) |
|
656 | + * @param bool $count whether to return the count or not (default FALSE) |
|
657 | + * @return EE_Event[]|int |
|
658 | + * @throws \EE_Error |
|
659 | + */ |
|
660 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
661 | + { |
|
662 | + if (array_key_exists(0, $query_params)) { |
|
663 | + $where_params = $query_params[0]; |
|
664 | + unset($query_params[0]); |
|
665 | + } else { |
|
666 | + $where_params = array(); |
|
667 | + } |
|
668 | + // if we have count make sure we don't include group by |
|
669 | + if ($count && isset($query_params['group_by'])) { |
|
670 | + unset($query_params['group_by']); |
|
671 | + } |
|
672 | + // let's add specific query_params for active_events |
|
673 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
674 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
675 | + // add where params for DTT_EVT_end |
|
676 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
677 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
678 | + '>', |
|
679 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
680 | + ); |
|
681 | + } else { |
|
682 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
683 | + '>', |
|
684 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
685 | + ); |
|
686 | + } |
|
687 | + $query_params[0] = $where_params; |
|
688 | + // don't use $query_params with count() |
|
689 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
690 | + return $count |
|
691 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
692 | + : $this->get_all($query_params); |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * This only returns events that are expired. |
|
699 | + * They may still be published but all their datetimes have expired. |
|
700 | + * |
|
701 | + * @param array $query_params An array of query params to further filter on |
|
702 | + * (note that status and DTT_EVT_end will be overridden) |
|
703 | + * @param bool $count whether to return the count or not (default FALSE) |
|
704 | + * @return EE_Event[]|int |
|
705 | + * @throws \EE_Error |
|
706 | + */ |
|
707 | + public function get_expired_events($query_params, $count = false) |
|
708 | + { |
|
709 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
710 | + // if we have count make sure we don't include group by |
|
711 | + if ($count && isset($query_params['group_by'])) { |
|
712 | + unset($query_params['group_by']); |
|
713 | + } |
|
714 | + // let's add specific query_params for active_events |
|
715 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
716 | + if (isset($where_params['status'])) { |
|
717 | + unset($where_params['status']); |
|
718 | + } |
|
719 | + $exclude_query = $query_params; |
|
720 | + if (isset($exclude_query[0])) { |
|
721 | + unset($exclude_query[0]); |
|
722 | + } |
|
723 | + $exclude_query[0] = array( |
|
724 | + 'Datetime.DTT_EVT_end' => array( |
|
725 | + '>', |
|
726 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
727 | + ), |
|
728 | + ); |
|
729 | + // first get all events that have datetimes where its not expired. |
|
730 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
731 | + $event_ids = array_keys($event_ids); |
|
732 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
733 | + $and_condition = array( |
|
734 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
735 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
736 | + ); |
|
737 | + if (isset($where_params['OR'])) { |
|
738 | + $and_condition['OR'] = $where_params['OR']; |
|
739 | + unset($where_params['OR']); |
|
740 | + } |
|
741 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
742 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
743 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
744 | + } |
|
745 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
746 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
747 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
748 | + } |
|
749 | + // merge remaining $where params with the and conditions. |
|
750 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
751 | + $query_params[0] = $where_params; |
|
752 | + // don't use $query_params with count() |
|
753 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
754 | + return $count |
|
755 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
756 | + : $this->get_all($query_params); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * This basically just returns the events that do not have the publish status. |
|
763 | + * |
|
764 | + * @param array $query_params An array of query params to further filter on |
|
765 | + * (note that status will be overwritten) |
|
766 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
767 | + * @return EE_Event[]|int |
|
768 | + * @throws \EE_Error |
|
769 | + */ |
|
770 | + public function get_inactive_events($query_params, $count = false) |
|
771 | + { |
|
772 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
773 | + // let's add in specific query_params for inactive events. |
|
774 | + if (isset($where_params['status'])) { |
|
775 | + unset($where_params['status']); |
|
776 | + } |
|
777 | + // if we have count make sure we don't include group by |
|
778 | + if ($count && isset($query_params['group_by'])) { |
|
779 | + unset($query_params['group_by']); |
|
780 | + } |
|
781 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
782 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
783 | + if (isset($where_params['OR'])) { |
|
784 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
785 | + unset($where_params['OR']); |
|
786 | + } |
|
787 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
788 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
789 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
790 | + } |
|
791 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
792 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
793 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
794 | + } |
|
795 | + $query_params[0] = $where_params; |
|
796 | + // don't use $query_params with count() |
|
797 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
798 | + return $count |
|
799 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
800 | + : $this->get_all($query_params); |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
807 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
808 | + * attached to the event. See parent for param descriptions |
|
809 | + * |
|
810 | + * @param $id_or_obj |
|
811 | + * @param $other_model_id_or_obj |
|
812 | + * @param string $relationName |
|
813 | + * @param array $where_query |
|
814 | + * @return EE_Base_Class |
|
815 | + * @throws EE_Error |
|
816 | + */ |
|
817 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
818 | + { |
|
819 | + if ($relationName === 'Price') { |
|
820 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
821 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
822 | + // if EVT_ID = 0, then this is a default |
|
823 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
824 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
825 | + $prc_chk->set('PRC_ID', 0); |
|
826 | + } |
|
827 | + // run parent |
|
828 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
829 | + } |
|
830 | + // otherwise carry on as normal |
|
831 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
832 | + } |
|
833 | + |
|
834 | + |
|
835 | + |
|
836 | + /******************** DEPRECATED METHODS ********************/ |
|
837 | + |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * _get_question_target_db_column |
|
842 | + * |
|
843 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
844 | + * EE_Registration_Custom_Questions_Form located in |
|
845 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
846 | + * @access public |
|
847 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
848 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
849 | + * registration). |
|
850 | + * @throws EE_Error |
|
851 | + * @return array |
|
852 | + */ |
|
853 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
854 | + { |
|
855 | + if (empty($EVT_ID)) { |
|
856 | + throw new EE_Error(__( |
|
857 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
858 | + 'event_espresso' |
|
859 | + )); |
|
860 | + } |
|
861 | + $questions = array(); |
|
862 | + // get all question groups for event |
|
863 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
864 | + if (! empty($qgs)) { |
|
865 | + foreach ($qgs as $qg) { |
|
866 | + $qsts = $qg->questions(); |
|
867 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
869 | + foreach ($qsts as $qst) { |
|
870 | + if ($qst->is_system_question()) { |
|
871 | + continue; |
|
872 | + } |
|
873 | + $answer = EEM_Answer::instance()->get_one(array( |
|
874 | + array( |
|
875 | + 'QST_ID' => $qst->ID(), |
|
876 | + 'REG_ID' => $registration->ID(), |
|
877 | + ), |
|
878 | + )); |
|
879 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
880 | + $qst_name = $qstn_id = $qst->ID(); |
|
881 | + $ans_id = $answer->ID(); |
|
882 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
883 | + $input_name = ''; |
|
884 | + $input_id = sanitize_key($qst->display_text()); |
|
885 | + $input_class = ''; |
|
886 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
888 | + . $input_name |
|
889 | + . $qst_name; |
|
890 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
895 | + // leave responses as-is, don't convert stuff into html entities please! |
|
896 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
897 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
898 | + $QSOs = $qst->options(true, $answer->value()); |
|
899 | + if (is_array($QSOs)) { |
|
900 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
901 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
902 | + } |
|
903 | + } |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + } |
|
908 | + return $questions; |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
914 | + * or an stdClass where each property is the name of a column, |
|
915 | + * @return EE_Base_Class |
|
916 | + * @throws \EE_Error |
|
917 | + */ |
|
918 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
919 | + { |
|
920 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
921 | + if ($classInstance instanceof EE_Event) { |
|
922 | + // events have their timezone defined in the DB, so use it immediately |
|
923 | + $this->set_timezone($classInstance->get_timezone()); |
|
924 | + } |
|
925 | + return $classInstance; |
|
926 | + } |
|
927 | 927 | } |
@@ -16,210 +16,210 @@ |
||
16 | 16 | class espresso_events_Registration_Form_Hooks extends EE_Admin_Hooks |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_Event|null |
|
21 | - */ |
|
22 | - protected $_event; |
|
23 | - |
|
24 | - |
|
25 | - protected function _set_hooks_properties() |
|
26 | - { |
|
27 | - |
|
28 | - $this->_name = 'registration_form'; |
|
29 | - $this->_metaboxes = array( |
|
30 | - 0 => array( |
|
31 | - 'page_route' => array('edit', 'create_new'), |
|
32 | - 'func' => 'primary_questions', |
|
33 | - 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
34 | - 'priority' => 'default', |
|
35 | - 'context' => 'side', |
|
36 | - ), |
|
37 | - ); |
|
38 | - |
|
39 | - // hook into the handler for saving question groups |
|
40 | - add_filter( |
|
41 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
42 | - array($this, 'modify_callbacks'), |
|
43 | - 10 |
|
44 | - ); |
|
45 | - |
|
46 | - // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
47 | - // restricted by page) |
|
48 | - add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
54 | - * |
|
55 | - * @param $callbacks |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function modify_callbacks($callbacks) |
|
59 | - { |
|
60 | - // now let's add the question group callback |
|
61 | - $callbacks[] = array($this, 'primary_question_group_update'); |
|
62 | - return $callbacks; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Hooked into revision restores. |
|
68 | - * |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws ReflectionException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | - $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | - // restore revision for primary questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - ['Question_Group'], |
|
86 | - ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]] |
|
87 | - ); |
|
88 | - return $post_evt; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Content of metabox. |
|
94 | - * |
|
95 | - * @param $post_id |
|
96 | - * @param $post |
|
97 | - * @throws EE_Error |
|
98 | - * @throws InvalidArgumentException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws InvalidInterfaceException |
|
101 | - */ |
|
102 | - public function primary_questions($post_id, $post) |
|
103 | - { |
|
104 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
105 | - $event_id = $this->_event->ID(); |
|
106 | - ?> |
|
19 | + /** |
|
20 | + * @var EE_Event|null |
|
21 | + */ |
|
22 | + protected $_event; |
|
23 | + |
|
24 | + |
|
25 | + protected function _set_hooks_properties() |
|
26 | + { |
|
27 | + |
|
28 | + $this->_name = 'registration_form'; |
|
29 | + $this->_metaboxes = array( |
|
30 | + 0 => array( |
|
31 | + 'page_route' => array('edit', 'create_new'), |
|
32 | + 'func' => 'primary_questions', |
|
33 | + 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
34 | + 'priority' => 'default', |
|
35 | + 'context' => 'side', |
|
36 | + ), |
|
37 | + ); |
|
38 | + |
|
39 | + // hook into the handler for saving question groups |
|
40 | + add_filter( |
|
41 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
42 | + array($this, 'modify_callbacks'), |
|
43 | + 10 |
|
44 | + ); |
|
45 | + |
|
46 | + // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
47 | + // restricted by page) |
|
48 | + add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
54 | + * |
|
55 | + * @param $callbacks |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function modify_callbacks($callbacks) |
|
59 | + { |
|
60 | + // now let's add the question group callback |
|
61 | + $callbacks[] = array($this, 'primary_question_group_update'); |
|
62 | + return $callbacks; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Hooked into revision restores. |
|
68 | + * |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws ReflectionException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | + $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | + // restore revision for primary questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + ['Question_Group'], |
|
86 | + ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]] |
|
87 | + ); |
|
88 | + return $post_evt; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Content of metabox. |
|
94 | + * |
|
95 | + * @param $post_id |
|
96 | + * @param $post |
|
97 | + * @throws EE_Error |
|
98 | + * @throws InvalidArgumentException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws InvalidInterfaceException |
|
101 | + */ |
|
102 | + public function primary_questions($post_id, $post) |
|
103 | + { |
|
104 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
105 | + $event_id = $this->_event->ID(); |
|
106 | + ?> |
|
107 | 107 | <div class="inside"> |
108 | 108 | <p><strong> |
109 | 109 | <?php _e('Question Groups', 'event_espresso'); ?> |
110 | 110 | </strong><br/> |
111 | 111 | <?php |
112 | - printf( |
|
113 | - esc_html__( |
|
114 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
118 | - '</a>' |
|
119 | - ) |
|
120 | - ?> |
|
112 | + printf( |
|
113 | + esc_html__( |
|
114 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
118 | + '</a>' |
|
119 | + ) |
|
120 | + ?> |
|
121 | 121 | </p> |
122 | 122 | <?php |
123 | 123 | |
124 | - $qsg_where['QSG_deleted'] = false; |
|
125 | - $query_params = apply_filters( |
|
126 | - 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
127 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
128 | - ); |
|
129 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
130 | - $EQGs = ! empty($event_id) |
|
131 | - ? $this->_event->get_many_related( |
|
132 | - 'Question_Group', |
|
133 | - [['Event_Question_Group.EQG_primary' => true]] |
|
134 | - ) |
|
135 | - : array(); |
|
136 | - $EQGids = array_keys($EQGs); |
|
137 | - |
|
138 | - if (! empty($QSGs)) { |
|
139 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
140 | - foreach ($QSGs as $QSG) { |
|
141 | - $checked = in_array($QSG->ID(), $EQGids, true) |
|
142 | - || $QSG->get('QSG_system') === 1 |
|
143 | - ? ' checked="checked"' |
|
144 | - : ''; |
|
145 | - $visibility = $QSG->get('QSG_system') === 1 |
|
146 | - ? ' style="visibility:hidden"' |
|
147 | - : ''; |
|
148 | - $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
149 | - 'action' => 'edit_question_group', |
|
150 | - 'QSG_ID' => $QSG->ID(), |
|
151 | - ) : array('action' => 'question_groups'); |
|
152 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
153 | - $edit_query_args, |
|
154 | - EE_FORMS_ADMIN_URL |
|
155 | - ); |
|
156 | - |
|
157 | - $html .= ' |
|
124 | + $qsg_where['QSG_deleted'] = false; |
|
125 | + $query_params = apply_filters( |
|
126 | + 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
127 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
128 | + ); |
|
129 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
130 | + $EQGs = ! empty($event_id) |
|
131 | + ? $this->_event->get_many_related( |
|
132 | + 'Question_Group', |
|
133 | + [['Event_Question_Group.EQG_primary' => true]] |
|
134 | + ) |
|
135 | + : array(); |
|
136 | + $EQGids = array_keys($EQGs); |
|
137 | + |
|
138 | + if (! empty($QSGs)) { |
|
139 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
140 | + foreach ($QSGs as $QSG) { |
|
141 | + $checked = in_array($QSG->ID(), $EQGids, true) |
|
142 | + || $QSG->get('QSG_system') === 1 |
|
143 | + ? ' checked="checked"' |
|
144 | + : ''; |
|
145 | + $visibility = $QSG->get('QSG_system') === 1 |
|
146 | + ? ' style="visibility:hidden"' |
|
147 | + : ''; |
|
148 | + $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
149 | + 'action' => 'edit_question_group', |
|
150 | + 'QSG_ID' => $QSG->ID(), |
|
151 | + ) : array('action' => 'question_groups'); |
|
152 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
153 | + $edit_query_args, |
|
154 | + EE_FORMS_ADMIN_URL |
|
155 | + ); |
|
156 | + |
|
157 | + $html .= ' |
|
158 | 158 | <p id="event-question-group-' . $QSG->ID() . '"> |
159 | 159 | <input value="' . $QSG->ID() . '" type="checkbox"' |
160 | - . $visibility |
|
161 | - . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
160 | + . $visibility |
|
161 | + . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
162 | 162 | <a href="' . $edit_link . '" title="' |
163 | - . sprintf( |
|
164 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
165 | - $QSG->get('QSG_name') |
|
166 | - ) |
|
167 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
163 | + . sprintf( |
|
164 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
165 | + $QSG->get('QSG_name') |
|
166 | + ) |
|
167 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
168 | 168 | </p>'; |
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - } else { |
|
174 | - esc_html_e( |
|
175 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | - 'event_espresso' |
|
177 | - ); |
|
178 | - } |
|
179 | - do_action('AHEE_event_editor_questions_notice'); |
|
180 | - ?> |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + } else { |
|
174 | + esc_html_e( |
|
175 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | + 'event_espresso' |
|
177 | + ); |
|
178 | + } |
|
179 | + do_action('AHEE_event_editor_questions_notice'); |
|
180 | + ?> |
|
181 | 181 | </div> |
182 | 182 | <?php |
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param EE_Event $evtobj |
|
188 | - * @param array $data |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - */ |
|
192 | - public function primary_question_group_update($evtobj, $data) |
|
193 | - { |
|
194 | - $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array(); |
|
195 | - $added_qgs = array_keys($question_groups); |
|
196 | - $success = array(); |
|
197 | - |
|
198 | - // let's get all current question groups associated with this event. |
|
199 | - $current_qgs = $evtobj->get_many_related( |
|
200 | - 'Question_Group', |
|
201 | - [['Event_Question_Group.EQG_primary' => true]] |
|
202 | - ); |
|
203 | - $current_qgs = array_keys($current_qgs); // we just want the ids |
|
204 | - |
|
205 | - // now let's get the groups selected in the editor and update (IF we have data) |
|
206 | - if (! empty($question_groups)) { |
|
207 | - foreach ($question_groups as $id => $val) { |
|
208 | - // add to event |
|
209 | - if ($val) { |
|
210 | - $qg = $evtobj->_add_relation_to($id, 'Question_Group', ['EQG_primary' => true]); |
|
211 | - } |
|
212 | - $success[] = ! empty($qg) ? 1 : 0; |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
217 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
218 | - |
|
219 | - foreach ($removed_qgs as $qgid) { |
|
220 | - $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', ['EQG_primary' => true]); |
|
221 | - $success[] = ! empty($qg) ? 1 : 0; |
|
222 | - } |
|
223 | - return in_array(0, $success, true) ? false : true; |
|
224 | - } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param EE_Event $evtobj |
|
188 | + * @param array $data |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + */ |
|
192 | + public function primary_question_group_update($evtobj, $data) |
|
193 | + { |
|
194 | + $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array(); |
|
195 | + $added_qgs = array_keys($question_groups); |
|
196 | + $success = array(); |
|
197 | + |
|
198 | + // let's get all current question groups associated with this event. |
|
199 | + $current_qgs = $evtobj->get_many_related( |
|
200 | + 'Question_Group', |
|
201 | + [['Event_Question_Group.EQG_primary' => true]] |
|
202 | + ); |
|
203 | + $current_qgs = array_keys($current_qgs); // we just want the ids |
|
204 | + |
|
205 | + // now let's get the groups selected in the editor and update (IF we have data) |
|
206 | + if (! empty($question_groups)) { |
|
207 | + foreach ($question_groups as $id => $val) { |
|
208 | + // add to event |
|
209 | + if ($val) { |
|
210 | + $qg = $evtobj->_add_relation_to($id, 'Question_Group', ['EQG_primary' => true]); |
|
211 | + } |
|
212 | + $success[] = ! empty($qg) ? 1 : 0; |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
217 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
218 | + |
|
219 | + foreach ($removed_qgs as $qgid) { |
|
220 | + $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', ['EQG_primary' => true]); |
|
221 | + $success[] = ! empty($qg) ? 1 : 0; |
|
222 | + } |
|
223 | + return in_array(0, $success, true) ? false : true; |
|
224 | + } |
|
225 | 225 | } |
@@ -32,10 +32,10 @@ |
||
32 | 32 | ); |
33 | 33 | // this model is generally available for reading |
34 | 34 | $path_to_event = 'Event'; |
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
35 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
39 | 39 | parent::__construct($timezone); |
40 | 40 | } |
41 | 41 |
@@ -55,7 +55,7 @@ |
||
55 | 55 | * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
56 | 56 | * EQG_additional. |
57 | 57 | * @since 4.10.0.p |
58 | - * @param string|boolean|int $context |
|
58 | + * @param boolean $context |
|
59 | 59 | * @return string |
60 | 60 | */ |
61 | 61 | public function fieldNameForContext($context) |
@@ -7,72 +7,72 @@ |
||
7 | 7 | */ |
8 | 8 | class EEM_Event_Question_Group extends EEM_Base |
9 | 9 | { |
10 | - /** |
|
11 | - * Name of the field indicating an event should use the question group for the primary attendee |
|
12 | - */ |
|
13 | - const PRIMARY = 'EQG_primary'; |
|
10 | + /** |
|
11 | + * Name of the field indicating an event should use the question group for the primary attendee |
|
12 | + */ |
|
13 | + const PRIMARY = 'EQG_primary'; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Name of hte field indicating an event should use the question group for additional attendees |
|
17 | - */ |
|
18 | - const ADDITIONAL = 'EQG_additional'; |
|
15 | + /** |
|
16 | + * Name of hte field indicating an event should use the question group for additional attendees |
|
17 | + */ |
|
18 | + const ADDITIONAL = 'EQG_additional'; |
|
19 | 19 | |
20 | - // private instance of the Event_Question_Group object |
|
21 | - protected static $_instance = null; |
|
20 | + // private instance of the Event_Question_Group object |
|
21 | + protected static $_instance = null; |
|
22 | 22 | |
23 | - protected function __construct($timezone = null) |
|
24 | - { |
|
25 | - $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
26 | - $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
27 | - $this->_tables = array( |
|
28 | - 'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID') |
|
29 | - ); |
|
30 | - $this->_fields = array( |
|
31 | - 'Event_Question_Group'=>array( |
|
32 | - 'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')), |
|
33 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
34 | - 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'), |
|
35 | - 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false), |
|
36 | - 'EQG_additional'=>new EE_Boolean_Field('EQG_additional', __('Flag indicating question is only for additional attendees', 'event_espresso'), false, false) |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Event'=>new EE_Belongs_To_Relation(), |
|
41 | - 'Question_Group'=>new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - // this model is generally available for reading |
|
44 | - $path_to_event = 'Event'; |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | - parent::__construct($timezone); |
|
50 | - } |
|
23 | + protected function __construct($timezone = null) |
|
24 | + { |
|
25 | + $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
26 | + $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
27 | + $this->_tables = array( |
|
28 | + 'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID') |
|
29 | + ); |
|
30 | + $this->_fields = array( |
|
31 | + 'Event_Question_Group'=>array( |
|
32 | + 'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')), |
|
33 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
34 | + 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'), |
|
35 | + 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false), |
|
36 | + 'EQG_additional'=>new EE_Boolean_Field('EQG_additional', __('Flag indicating question is only for additional attendees', 'event_espresso'), false, false) |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Event'=>new EE_Belongs_To_Relation(), |
|
41 | + 'Question_Group'=>new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + // this model is generally available for reading |
|
44 | + $path_to_event = 'Event'; |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | + parent::__construct($timezone); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether |
|
54 | - * this is concerning primary attendees or additional attendees. |
|
55 | - * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
|
56 | - * EQG_additional. |
|
57 | - * @since 4.10.0.p |
|
58 | - * @param string|boolean|int $context |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function fieldNameForContext($context) |
|
62 | - { |
|
63 | - // Basically do a strict switch statement. |
|
64 | - switch (true) { |
|
65 | - case $context === 'additional': |
|
66 | - case $context === false: |
|
67 | - case $context === 0: |
|
68 | - $field_name = EEM_Event_Question_Group::ADDITIONAL; |
|
69 | - break; |
|
70 | - case $context === 'primary': |
|
71 | - case $context === true: |
|
72 | - case $context === 1: |
|
73 | - default: |
|
74 | - $field_name = EEM_Event_Question_Group::PRIMARY; |
|
75 | - } |
|
76 | - return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context); |
|
77 | - } |
|
52 | + /** |
|
53 | + * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether |
|
54 | + * this is concerning primary attendees or additional attendees. |
|
55 | + * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
|
56 | + * EQG_additional. |
|
57 | + * @since 4.10.0.p |
|
58 | + * @param string|boolean|int $context |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function fieldNameForContext($context) |
|
62 | + { |
|
63 | + // Basically do a strict switch statement. |
|
64 | + switch (true) { |
|
65 | + case $context === 'additional': |
|
66 | + case $context === false: |
|
67 | + case $context === 0: |
|
68 | + $field_name = EEM_Event_Question_Group::ADDITIONAL; |
|
69 | + break; |
|
70 | + case $context === 'primary': |
|
71 | + case $context === true: |
|
72 | + case $context === 1: |
|
73 | + default: |
|
74 | + $field_name = EEM_Event_Question_Group::PRIMARY; |
|
75 | + } |
|
76 | + return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context); |
|
77 | + } |
|
78 | 78 | } |
@@ -16,208 +16,208 @@ |
||
16 | 16 | class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - protected function _extend_properties() |
|
26 | - { |
|
27 | - $this->_metaboxes = array_merge( |
|
28 | - $this->_metaboxes, |
|
29 | - array( |
|
30 | - 1 => array( |
|
31 | - 'page_route' => array('create_new', 'edit'), |
|
32 | - 'func' => 'additional_questions', |
|
33 | - 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
34 | - 'priority' => 'default', |
|
35 | - 'context' => 'side', |
|
36 | - ), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_scripts_styles = array( |
|
40 | - 'registers' => array( |
|
41 | - 'extended-event-editor' => array( |
|
42 | - 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
43 | - . 'registration_form/assets/event-editor-question-groups.js', |
|
44 | - 'depends' => array('jquery'), |
|
45 | - ), |
|
46 | - ), |
|
47 | - 'enqueues' => array( |
|
48 | - 'extended-event-editor' => array('edit', 'create_new'), |
|
49 | - ), |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param Callable[] $callbacks |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function modify_callbacks($callbacks) |
|
59 | - { |
|
60 | - $callbacks = parent::modify_callbacks($callbacks); |
|
61 | - $callbacks[] = array($this, 'additional_question_group_update'); |
|
62 | - return $callbacks; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Call back hooked into revision restores. |
|
68 | - * |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class|void |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $post_evt = parent::restore_revision($post_id, $revision_id); |
|
81 | - |
|
82 | - // restore revision for additional questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - ['Question_Group'], |
|
86 | - [ |
|
87 | - 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
88 | - ] |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function additional_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
19 | + /** |
|
20 | + * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + protected function _extend_properties() |
|
26 | + { |
|
27 | + $this->_metaboxes = array_merge( |
|
28 | + $this->_metaboxes, |
|
29 | + array( |
|
30 | + 1 => array( |
|
31 | + 'page_route' => array('create_new', 'edit'), |
|
32 | + 'func' => 'additional_questions', |
|
33 | + 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
34 | + 'priority' => 'default', |
|
35 | + 'context' => 'side', |
|
36 | + ), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_scripts_styles = array( |
|
40 | + 'registers' => array( |
|
41 | + 'extended-event-editor' => array( |
|
42 | + 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
43 | + . 'registration_form/assets/event-editor-question-groups.js', |
|
44 | + 'depends' => array('jquery'), |
|
45 | + ), |
|
46 | + ), |
|
47 | + 'enqueues' => array( |
|
48 | + 'extended-event-editor' => array('edit', 'create_new'), |
|
49 | + ), |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param Callable[] $callbacks |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function modify_callbacks($callbacks) |
|
59 | + { |
|
60 | + $callbacks = parent::modify_callbacks($callbacks); |
|
61 | + $callbacks[] = array($this, 'additional_question_group_update'); |
|
62 | + return $callbacks; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Call back hooked into revision restores. |
|
68 | + * |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class|void |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $post_evt = parent::restore_revision($post_id, $revision_id); |
|
81 | + |
|
82 | + // restore revision for additional questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + ['Question_Group'], |
|
86 | + [ |
|
87 | + 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
88 | + ] |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function additional_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ); |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ); |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - [['Event_Question_Group.EQG_additional' => true]] |
|
133 | - ) |
|
134 | - : []; |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | - array( |
|
143 | - 'action' => 'edit_question_group', |
|
144 | - 'QSG_ID' => $QSG->ID(), |
|
145 | - ), |
|
146 | - EE_FORMS_ADMIN_URL |
|
147 | - ); |
|
148 | - |
|
149 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + [['Event_Question_Group.EQG_additional' => true]] |
|
133 | + ) |
|
134 | + : []; |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | + array( |
|
143 | + 'action' => 'edit_question_group', |
|
144 | + 'QSG_ID' => $QSG->ID(), |
|
145 | + ), |
|
146 | + EE_FORMS_ADMIN_URL |
|
147 | + ); |
|
148 | + |
|
149 | + $html .= ' |
|
150 | 150 | <p id="event-question-group-' . $QSG->ID() . '"> |
151 | 151 | <input value="' . $QSG->ID() . '"' |
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | 153 | <a href="' . $edit_link . '" title="' |
154 | - . sprintf( |
|
155 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | - $QSG->get('QSG_name') |
|
157 | - ) |
|
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
154 | + . sprintf( |
|
155 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | + $QSG->get('QSG_name') |
|
157 | + ) |
|
158 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
159 | 159 | </p>'; |
160 | - if ($QSG->ID() === 2) { |
|
161 | - $html .= ' |
|
160 | + if ($QSG->ID() === 2) { |
|
161 | + $html .= ' |
|
162 | 162 | <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">' |
163 | - . esc_html__( |
|
164 | - 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | - 'event_espresso' |
|
166 | - ) |
|
167 | - . '</p>'; |
|
168 | - } |
|
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - } else { |
|
174 | - esc_html_e( |
|
175 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | - 'event_espresso' |
|
177 | - ); |
|
178 | - } |
|
179 | - do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
180 | - ?> |
|
163 | + . esc_html__( |
|
164 | + 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | + 'event_espresso' |
|
166 | + ) |
|
167 | + . '</p>'; |
|
168 | + } |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + } else { |
|
174 | + esc_html_e( |
|
175 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | + 'event_espresso' |
|
177 | + ); |
|
178 | + } |
|
179 | + do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
180 | + ?> |
|
181 | 181 | </div> |
182 | 182 | <?php |
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - public function additional_question_group_update($evtobj, $data) |
|
187 | - { |
|
188 | - $question_groups = ! empty($data['add_attendee_question_groups']) |
|
189 | - ? (array) $data['add_attendee_question_groups'] |
|
190 | - : []; |
|
191 | - $added_qgs = array_keys($question_groups); |
|
192 | - $success = []; |
|
193 | - |
|
194 | - // let's get all current question groups associated with this event. |
|
195 | - $current_qgs = $evtobj->get_many_related( |
|
196 | - 'Question_Group', |
|
197 | - [['Event_Question_Group.EQG_additional' => true]] |
|
198 | - ); |
|
199 | - $current_qgs = array_keys($current_qgs); // we just want the ids |
|
200 | - |
|
201 | - // now let's get the groups selected in the editor and update (IF we have data) |
|
202 | - if (! empty($question_groups)) { |
|
203 | - foreach ($question_groups as $qgid) { |
|
204 | - // add to event |
|
205 | - if ($qgid) { |
|
206 | - $qg = $evtobj->add_question_group($qgid, false); |
|
207 | - } |
|
208 | - $success[] = ! empty($qg) ? 1 : 0; |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
213 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
214 | - |
|
215 | - foreach ($removed_qgs as $qgid) { |
|
216 | - $qg = $evtobj->remove_question_group($qgid, false); |
|
217 | - $success[] = ! empty($qg) ? 1 : 0; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - return in_array(0, $success, true) ? false : true; |
|
222 | - } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + public function additional_question_group_update($evtobj, $data) |
|
187 | + { |
|
188 | + $question_groups = ! empty($data['add_attendee_question_groups']) |
|
189 | + ? (array) $data['add_attendee_question_groups'] |
|
190 | + : []; |
|
191 | + $added_qgs = array_keys($question_groups); |
|
192 | + $success = []; |
|
193 | + |
|
194 | + // let's get all current question groups associated with this event. |
|
195 | + $current_qgs = $evtobj->get_many_related( |
|
196 | + 'Question_Group', |
|
197 | + [['Event_Question_Group.EQG_additional' => true]] |
|
198 | + ); |
|
199 | + $current_qgs = array_keys($current_qgs); // we just want the ids |
|
200 | + |
|
201 | + // now let's get the groups selected in the editor and update (IF we have data) |
|
202 | + if (! empty($question_groups)) { |
|
203 | + foreach ($question_groups as $qgid) { |
|
204 | + // add to event |
|
205 | + if ($qgid) { |
|
206 | + $qg = $evtobj->add_question_group($qgid, false); |
|
207 | + } |
|
208 | + $success[] = ! empty($qg) ? 1 : 0; |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
213 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
214 | + |
|
215 | + foreach ($removed_qgs as $qgid) { |
|
216 | + $qg = $evtobj->remove_question_group($qgid, false); |
|
217 | + $success[] = ! empty($qg) ? 1 : 0; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + return in_array(0, $success, true) ? false : true; |
|
222 | + } |
|
223 | 223 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | : []; |
135 | 135 | $EQGids = array_keys($EQGs); |
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | 140 | $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | $html .= ' |
150 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
151 | - <input value="' . $QSG->ID() . '"' |
|
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | - <a href="' . $edit_link . '" title="' |
|
150 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
151 | + <input value="' . $QSG->ID().'"' |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' /> |
|
153 | + <a href="' . $edit_link.'" title="' |
|
154 | 154 | . sprintf( |
155 | 155 | esc_attr__('Edit %s Group', 'event_espresso'), |
156 | 156 | $QSG->get('QSG_name') |
157 | 157 | ) |
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
158 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
159 | 159 | </p>'; |
160 | 160 | if ($QSG->ID() === 2) { |
161 | 161 | $html .= ' |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $current_qgs = array_keys($current_qgs); // we just want the ids |
200 | 200 | |
201 | 201 | // now let's get the groups selected in the editor and update (IF we have data) |
202 | - if (! empty($question_groups)) { |
|
202 | + if ( ! empty($question_groups)) { |
|
203 | 203 | foreach ($question_groups as $qgid) { |
204 | 204 | // add to event |
205 | 205 | if ($qgid) { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getAvailableSpacesCalculator() |
73 | 73 | { |
74 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
74 | + if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
75 | 75 | $this->available_spaces_calculator = new EventSpacesCalculator($this); |
76 | 76 | } |
77 | 77 | return $this->available_spaces_calculator; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | */ |
214 | 214 | public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
215 | 215 | { |
216 | - if (! empty($this->_Primary_Datetime)) { |
|
216 | + if ( ! empty($this->_Primary_Datetime)) { |
|
217 | 217 | return $this->_Primary_Datetime; |
218 | 218 | } |
219 | 219 | $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | { |
237 | 237 | // first get all datetimes |
238 | 238 | $datetimes = $this->datetimes_ordered(); |
239 | - if (! $datetimes) { |
|
239 | + if ( ! $datetimes) { |
|
240 | 240 | return array(); |
241 | 241 | } |
242 | 242 | $datetime_ids = array(); |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
430 | 430 | { |
431 | 431 | $short_desc = $this->get('EVT_short_desc'); |
432 | - if (! empty($short_desc) || $not_full_desc) { |
|
432 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
433 | 433 | return $short_desc; |
434 | 434 | } |
435 | 435 | $full_desc = $this->get('EVT_desc'); |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | ); |
884 | 884 | $all_expired = true; |
885 | 885 | foreach ($tickets as $ticket) { |
886 | - if (! $ticket->is_expired()) { |
|
886 | + if ( ! $ticket->is_expired()) { |
|
887 | 887 | $all_expired = false; |
888 | 888 | break; |
889 | 889 | } |
@@ -972,7 +972,7 @@ discard block |
||
972 | 972 | */ |
973 | 973 | public function is_sold_out($actual = false) |
974 | 974 | { |
975 | - if (! $actual) { |
|
975 | + if ( ! $actual) { |
|
976 | 976 | return $this->status() === EEM_Event::sold_out; |
977 | 977 | } |
978 | 978 | return $this->perform_sold_out_status_check(); |
@@ -1017,11 +1017,11 @@ discard block |
||
1017 | 1017 | public function get_active_status($reset = false) |
1018 | 1018 | { |
1019 | 1019 | // if the active status has already been set, then just use that value (unless we are resetting it) |
1020 | - if (! empty($this->_active_status) && ! $reset) { |
|
1020 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
1021 | 1021 | return $this->_active_status; |
1022 | 1022 | } |
1023 | 1023 | // first check if event id is present on this object |
1024 | - if (! $this->ID()) { |
|
1024 | + if ( ! $this->ID()) { |
|
1025 | 1025 | return false; |
1026 | 1026 | } |
1027 | 1027 | $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | public function get_number_of_tickets_sold() |
1107 | 1107 | { |
1108 | 1108 | $tkt_sold = 0; |
1109 | - if (! $this->ID()) { |
|
1109 | + if ( ! $this->ID()) { |
|
1110 | 1110 | return 0; |
1111 | 1111 | } |
1112 | 1112 | $datetimes = $this->datetimes(); |
@@ -1290,7 +1290,7 @@ discard block |
||
1290 | 1290 | ] |
1291 | 1291 | ); |
1292 | 1292 | $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
1293 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1293 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext( ! $for_primary); |
|
1294 | 1294 | if ($existing_relation->get($other_field) === false) { |
1295 | 1295 | // Delete it. It's now no longer for primary or additional question groups. |
1296 | 1296 | return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
@@ -15,1388 +15,1388 @@ |
||
15 | 15 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * cached value for the the logical active status for the event |
|
20 | - * |
|
21 | - * @see get_active_status() |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_active_status = ''; |
|
25 | - |
|
26 | - /** |
|
27 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
28 | - * |
|
29 | - * @var EE_Datetime |
|
30 | - */ |
|
31 | - protected $_Primary_Datetime; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
35 | - */ |
|
36 | - protected $available_spaces_calculator; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param array $props_n_values incoming values |
|
41 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
42 | - * used.) |
|
43 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
44 | - * date_format and the second value is the time format |
|
45 | - * @return EE_Event |
|
46 | - * @throws EE_Error |
|
47 | - */ |
|
48 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
49 | - { |
|
50 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
51 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array $props_n_values incoming values from the database |
|
57 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
58 | - * the website will be used. |
|
59 | - * @return EE_Event |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
63 | - { |
|
64 | - return new self($props_n_values, true, $timezone); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return EventSpacesCalculator |
|
70 | - * @throws \EE_Error |
|
71 | - */ |
|
72 | - public function getAvailableSpacesCalculator() |
|
73 | - { |
|
74 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
75 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
76 | - } |
|
77 | - return $this->available_spaces_calculator; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
83 | - * |
|
84 | - * @param string $field_name |
|
85 | - * @param mixed $field_value |
|
86 | - * @param bool $use_default |
|
87 | - * @throws EE_Error |
|
88 | - */ |
|
89 | - public function set($field_name, $field_value, $use_default = false) |
|
90 | - { |
|
91 | - switch ($field_name) { |
|
92 | - case 'status': |
|
93 | - $this->set_status($field_value, $use_default); |
|
94 | - break; |
|
95 | - default: |
|
96 | - parent::set($field_name, $field_value, $use_default); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * set_status |
|
103 | - * Checks if event status is being changed to SOLD OUT |
|
104 | - * and updates event meta data with previous event status |
|
105 | - * so that we can revert things if/when the event is no longer sold out |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @param string $new_status |
|
109 | - * @param bool $use_default |
|
110 | - * @return void |
|
111 | - * @throws EE_Error |
|
112 | - */ |
|
113 | - public function set_status($new_status = null, $use_default = false) |
|
114 | - { |
|
115 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
116 | - if (empty($new_status) && ! $use_default) { |
|
117 | - return; |
|
118 | - } |
|
119 | - // get current Event status |
|
120 | - $old_status = $this->status(); |
|
121 | - // if status has changed |
|
122 | - if ($old_status !== $new_status) { |
|
123 | - // TO sold_out |
|
124 | - if ($new_status === EEM_Event::sold_out) { |
|
125 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
126 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
127 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
128 | - // OR FROM sold_out |
|
129 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
130 | - $this->delete_post_meta('_previous_event_status'); |
|
131 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
132 | - } |
|
133 | - // clear out the active status so that it gets reset the next time it is requested |
|
134 | - $this->_active_status = null; |
|
135 | - // update status |
|
136 | - parent::set('status', $new_status, $use_default); |
|
137 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
138 | - return; |
|
139 | - } |
|
140 | - // even though the old value matches the new value, it's still good to |
|
141 | - // allow the parent set method to have a say |
|
142 | - parent::set('status', $new_status, $use_default); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets all the datetimes for this event |
|
148 | - * |
|
149 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
150 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
151 | - * @throws EE_Error |
|
152 | - */ |
|
153 | - public function datetimes($query_params = array()) |
|
154 | - { |
|
155 | - return $this->get_many_related('Datetime', $query_params); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
161 | - * |
|
162 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - public function datetimes_in_chronological_order() |
|
166 | - { |
|
167 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
173 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
174 | - * after running our query, so that this timezone isn't set for EVERY query |
|
175 | - * on EEM_Datetime for the rest of the request, no? |
|
176 | - * |
|
177 | - * @param boolean $show_expired whether or not to include expired events |
|
178 | - * @param boolean $show_deleted whether or not to include deleted events |
|
179 | - * @param null $limit |
|
180 | - * @return EE_Datetime[] |
|
181 | - * @throws EE_Error |
|
182 | - */ |
|
183 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
184 | - { |
|
185 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
186 | - $this->ID(), |
|
187 | - $show_expired, |
|
188 | - $show_deleted, |
|
189 | - $limit |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
196 | - * |
|
197 | - * @return EE_Base_Class|EE_Datetime |
|
198 | - * @throws EE_Error |
|
199 | - */ |
|
200 | - public function first_datetime() |
|
201 | - { |
|
202 | - return $this->get_first_related('Datetime'); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Returns the 'primary' datetime for the event |
|
208 | - * |
|
209 | - * @param bool $try_to_exclude_expired |
|
210 | - * @param bool $try_to_exclude_deleted |
|
211 | - * @return EE_Datetime |
|
212 | - * @throws EE_Error |
|
213 | - */ |
|
214 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
215 | - { |
|
216 | - if (! empty($this->_Primary_Datetime)) { |
|
217 | - return $this->_Primary_Datetime; |
|
218 | - } |
|
219 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
220 | - $this->ID(), |
|
221 | - $try_to_exclude_expired, |
|
222 | - $try_to_exclude_deleted |
|
223 | - ); |
|
224 | - return $this->_Primary_Datetime; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Gets all the tickets available for purchase of this event |
|
230 | - * |
|
231 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
232 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
233 | - * @throws EE_Error |
|
234 | - */ |
|
235 | - public function tickets($query_params = array()) |
|
236 | - { |
|
237 | - // first get all datetimes |
|
238 | - $datetimes = $this->datetimes_ordered(); |
|
239 | - if (! $datetimes) { |
|
240 | - return array(); |
|
241 | - } |
|
242 | - $datetime_ids = array(); |
|
243 | - foreach ($datetimes as $datetime) { |
|
244 | - $datetime_ids[] = $datetime->ID(); |
|
245 | - } |
|
246 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
247 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
248 | - if (is_array($query_params) && isset($query_params[0])) { |
|
249 | - $where_params = array_merge($query_params[0], $where_params); |
|
250 | - unset($query_params[0]); |
|
251 | - } |
|
252 | - // now add $where_params to $query_params |
|
253 | - $query_params[0] = $where_params; |
|
254 | - return EEM_Ticket::instance()->get_all($query_params); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * get all unexpired untrashed tickets |
|
260 | - * |
|
261 | - * @return EE_Ticket[] |
|
262 | - * @throws EE_Error |
|
263 | - */ |
|
264 | - public function active_tickets() |
|
265 | - { |
|
266 | - return $this->tickets( |
|
267 | - array( |
|
268 | - array( |
|
269 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
270 | - 'TKT_deleted' => false, |
|
271 | - ), |
|
272 | - ) |
|
273 | - ); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @return bool |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function additional_limit() |
|
282 | - { |
|
283 | - return $this->get('EVT_additional_limit'); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return bool |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function allow_overflow() |
|
292 | - { |
|
293 | - return $this->get('EVT_allow_overflow'); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @return bool |
|
299 | - * @throws EE_Error |
|
300 | - */ |
|
301 | - public function created() |
|
302 | - { |
|
303 | - return $this->get('EVT_created'); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * @return bool |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - public function description() |
|
312 | - { |
|
313 | - return $this->get('EVT_desc'); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Runs do_shortcode and wpautop on the description |
|
319 | - * |
|
320 | - * @return string of html |
|
321 | - * @throws EE_Error |
|
322 | - */ |
|
323 | - public function description_filtered() |
|
324 | - { |
|
325 | - return $this->get_pretty('EVT_desc'); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @return bool |
|
331 | - * @throws EE_Error |
|
332 | - */ |
|
333 | - public function display_description() |
|
334 | - { |
|
335 | - return $this->get('EVT_display_desc'); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @return bool |
|
341 | - * @throws EE_Error |
|
342 | - */ |
|
343 | - public function display_ticket_selector() |
|
344 | - { |
|
345 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @return bool |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function external_url() |
|
354 | - { |
|
355 | - return $this->get('EVT_external_URL'); |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return bool |
|
361 | - * @throws EE_Error |
|
362 | - */ |
|
363 | - public function member_only() |
|
364 | - { |
|
365 | - return $this->get('EVT_member_only'); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @return bool |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - public function phone() |
|
374 | - { |
|
375 | - return $this->get('EVT_phone'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return bool |
|
381 | - * @throws EE_Error |
|
382 | - */ |
|
383 | - public function modified() |
|
384 | - { |
|
385 | - return $this->get('EVT_modified'); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @return bool |
|
391 | - * @throws EE_Error |
|
392 | - */ |
|
393 | - public function name() |
|
394 | - { |
|
395 | - return $this->get('EVT_name'); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * @return bool |
|
401 | - * @throws EE_Error |
|
402 | - */ |
|
403 | - public function order() |
|
404 | - { |
|
405 | - return $this->get('EVT_order'); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * @return bool|string |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - public function default_registration_status() |
|
414 | - { |
|
415 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
416 | - return ! empty($event_default_registration_status) |
|
417 | - ? $event_default_registration_status |
|
418 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @param int $num_words |
|
424 | - * @param null $more |
|
425 | - * @param bool $not_full_desc |
|
426 | - * @return bool|string |
|
427 | - * @throws EE_Error |
|
428 | - */ |
|
429 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
430 | - { |
|
431 | - $short_desc = $this->get('EVT_short_desc'); |
|
432 | - if (! empty($short_desc) || $not_full_desc) { |
|
433 | - return $short_desc; |
|
434 | - } |
|
435 | - $full_desc = $this->get('EVT_desc'); |
|
436 | - return wp_trim_words($full_desc, $num_words, $more); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * @return bool |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - public function slug() |
|
445 | - { |
|
446 | - return $this->get('EVT_slug'); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @return bool |
|
452 | - * @throws EE_Error |
|
453 | - */ |
|
454 | - public function timezone_string() |
|
455 | - { |
|
456 | - return $this->get('EVT_timezone_string'); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * @return bool |
|
462 | - * @throws EE_Error |
|
463 | - */ |
|
464 | - public function visible_on() |
|
465 | - { |
|
466 | - return $this->get('EVT_visible_on'); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * @return int |
|
472 | - * @throws EE_Error |
|
473 | - */ |
|
474 | - public function wp_user() |
|
475 | - { |
|
476 | - return $this->get('EVT_wp_user'); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * @return bool |
|
482 | - * @throws EE_Error |
|
483 | - */ |
|
484 | - public function donations() |
|
485 | - { |
|
486 | - return $this->get('EVT_donations'); |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * @param $limit |
|
492 | - * @throws EE_Error |
|
493 | - */ |
|
494 | - public function set_additional_limit($limit) |
|
495 | - { |
|
496 | - $this->set('EVT_additional_limit', $limit); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param $created |
|
502 | - * @throws EE_Error |
|
503 | - */ |
|
504 | - public function set_created($created) |
|
505 | - { |
|
506 | - $this->set('EVT_created', $created); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * @param $desc |
|
512 | - * @throws EE_Error |
|
513 | - */ |
|
514 | - public function set_description($desc) |
|
515 | - { |
|
516 | - $this->set('EVT_desc', $desc); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param $display_desc |
|
522 | - * @throws EE_Error |
|
523 | - */ |
|
524 | - public function set_display_description($display_desc) |
|
525 | - { |
|
526 | - $this->set('EVT_display_desc', $display_desc); |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @param $display_ticket_selector |
|
532 | - * @throws EE_Error |
|
533 | - */ |
|
534 | - public function set_display_ticket_selector($display_ticket_selector) |
|
535 | - { |
|
536 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * @param $external_url |
|
542 | - * @throws EE_Error |
|
543 | - */ |
|
544 | - public function set_external_url($external_url) |
|
545 | - { |
|
546 | - $this->set('EVT_external_URL', $external_url); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * @param $member_only |
|
552 | - * @throws EE_Error |
|
553 | - */ |
|
554 | - public function set_member_only($member_only) |
|
555 | - { |
|
556 | - $this->set('EVT_member_only', $member_only); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * @param $event_phone |
|
562 | - * @throws EE_Error |
|
563 | - */ |
|
564 | - public function set_event_phone($event_phone) |
|
565 | - { |
|
566 | - $this->set('EVT_phone', $event_phone); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * @param $modified |
|
572 | - * @throws EE_Error |
|
573 | - */ |
|
574 | - public function set_modified($modified) |
|
575 | - { |
|
576 | - $this->set('EVT_modified', $modified); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * @param $name |
|
582 | - * @throws EE_Error |
|
583 | - */ |
|
584 | - public function set_name($name) |
|
585 | - { |
|
586 | - $this->set('EVT_name', $name); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * @param $order |
|
592 | - * @throws EE_Error |
|
593 | - */ |
|
594 | - public function set_order($order) |
|
595 | - { |
|
596 | - $this->set('EVT_order', $order); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * @param $short_desc |
|
602 | - * @throws EE_Error |
|
603 | - */ |
|
604 | - public function set_short_description($short_desc) |
|
605 | - { |
|
606 | - $this->set('EVT_short_desc', $short_desc); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * @param $slug |
|
612 | - * @throws EE_Error |
|
613 | - */ |
|
614 | - public function set_slug($slug) |
|
615 | - { |
|
616 | - $this->set('EVT_slug', $slug); |
|
617 | - } |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * @param $timezone_string |
|
622 | - * @throws EE_Error |
|
623 | - */ |
|
624 | - public function set_timezone_string($timezone_string) |
|
625 | - { |
|
626 | - $this->set('EVT_timezone_string', $timezone_string); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * @param $visible_on |
|
632 | - * @throws EE_Error |
|
633 | - */ |
|
634 | - public function set_visible_on($visible_on) |
|
635 | - { |
|
636 | - $this->set('EVT_visible_on', $visible_on); |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - /** |
|
641 | - * @param $wp_user |
|
642 | - * @throws EE_Error |
|
643 | - */ |
|
644 | - public function set_wp_user($wp_user) |
|
645 | - { |
|
646 | - $this->set('EVT_wp_user', $wp_user); |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * @param $default_registration_status |
|
652 | - * @throws EE_Error |
|
653 | - */ |
|
654 | - public function set_default_registration_status($default_registration_status) |
|
655 | - { |
|
656 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * @param $donations |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function set_donations($donations) |
|
665 | - { |
|
666 | - $this->set('EVT_donations', $donations); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * Adds a venue to this event |
|
672 | - * |
|
673 | - * @param EE_Venue /int $venue_id_or_obj |
|
674 | - * @return EE_Base_Class|EE_Venue |
|
675 | - * @throws EE_Error |
|
676 | - */ |
|
677 | - public function add_venue($venue_id_or_obj) |
|
678 | - { |
|
679 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * Removes a venue from the event |
|
685 | - * |
|
686 | - * @param EE_Venue /int $venue_id_or_obj |
|
687 | - * @return EE_Base_Class|EE_Venue |
|
688 | - * @throws EE_Error |
|
689 | - */ |
|
690 | - public function remove_venue($venue_id_or_obj) |
|
691 | - { |
|
692 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
698 | - * |
|
699 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
700 | - * @return EE_Base_Class[]|EE_Venue[] |
|
701 | - * @throws EE_Error |
|
702 | - */ |
|
703 | - public function venues($query_params = array()) |
|
704 | - { |
|
705 | - return $this->get_many_related('Venue', $query_params); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * check if event id is present and if event is published |
|
711 | - * |
|
712 | - * @access public |
|
713 | - * @return boolean true yes, false no |
|
714 | - * @throws EE_Error |
|
715 | - */ |
|
716 | - private function _has_ID_and_is_published() |
|
717 | - { |
|
718 | - // first check if event id is present and not NULL, |
|
719 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
720 | - return |
|
721 | - $this->ID() && $this->ID() !== null |
|
722 | - && ( |
|
723 | - $this->status() === 'publish' |
|
724 | - || $this->status() === EEM_Event::sold_out |
|
725 | - || $this->status() === EEM_Event::postponed |
|
726 | - || $this->status() === EEM_Event::cancelled |
|
727 | - ); |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
733 | - * |
|
734 | - * @access public |
|
735 | - * @return boolean true yes, false no |
|
736 | - * @throws EE_Error |
|
737 | - */ |
|
738 | - public function is_upcoming() |
|
739 | - { |
|
740 | - // check if event id is present and if this event is published |
|
741 | - if ($this->is_inactive()) { |
|
742 | - return false; |
|
743 | - } |
|
744 | - // set initial value |
|
745 | - $upcoming = false; |
|
746 | - // next let's get all datetimes and loop through them |
|
747 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
748 | - foreach ($datetimes as $datetime) { |
|
749 | - if ($datetime instanceof EE_Datetime) { |
|
750 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
751 | - if ($datetime->is_expired()) { |
|
752 | - continue; |
|
753 | - } |
|
754 | - // if this dtt is active then we return false. |
|
755 | - if ($datetime->is_active()) { |
|
756 | - return false; |
|
757 | - } |
|
758 | - // otherwise let's check upcoming status |
|
759 | - $upcoming = $datetime->is_upcoming(); |
|
760 | - } |
|
761 | - } |
|
762 | - return $upcoming; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * @return bool |
|
768 | - * @throws EE_Error |
|
769 | - */ |
|
770 | - public function is_active() |
|
771 | - { |
|
772 | - // check if event id is present and if this event is published |
|
773 | - if ($this->is_inactive()) { |
|
774 | - return false; |
|
775 | - } |
|
776 | - // set initial value |
|
777 | - $active = false; |
|
778 | - // next let's get all datetimes and loop through them |
|
779 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
780 | - foreach ($datetimes as $datetime) { |
|
781 | - if ($datetime instanceof EE_Datetime) { |
|
782 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
783 | - if ($datetime->is_expired()) { |
|
784 | - continue; |
|
785 | - } |
|
786 | - // if this dtt is upcoming then we return false. |
|
787 | - if ($datetime->is_upcoming()) { |
|
788 | - return false; |
|
789 | - } |
|
790 | - // otherwise let's check active status |
|
791 | - $active = $datetime->is_active(); |
|
792 | - } |
|
793 | - } |
|
794 | - return $active; |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - /** |
|
799 | - * @return bool |
|
800 | - * @throws EE_Error |
|
801 | - */ |
|
802 | - public function is_expired() |
|
803 | - { |
|
804 | - // check if event id is present and if this event is published |
|
805 | - if ($this->is_inactive()) { |
|
806 | - return false; |
|
807 | - } |
|
808 | - // set initial value |
|
809 | - $expired = false; |
|
810 | - // first let's get all datetimes and loop through them |
|
811 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
812 | - foreach ($datetimes as $datetime) { |
|
813 | - if ($datetime instanceof EE_Datetime) { |
|
814 | - // if this dtt is upcoming or active then we return false. |
|
815 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
816 | - return false; |
|
817 | - } |
|
818 | - // otherwise let's check active status |
|
819 | - $expired = $datetime->is_expired(); |
|
820 | - } |
|
821 | - } |
|
822 | - return $expired; |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * @return bool |
|
828 | - * @throws EE_Error |
|
829 | - */ |
|
830 | - public function is_inactive() |
|
831 | - { |
|
832 | - // check if event id is present and if this event is published |
|
833 | - if ($this->_has_ID_and_is_published()) { |
|
834 | - return false; |
|
835 | - } |
|
836 | - return true; |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * calculate spaces remaining based on "saleable" tickets |
|
842 | - * |
|
843 | - * @param array $tickets |
|
844 | - * @param bool $filtered |
|
845 | - * @return int|float |
|
846 | - * @throws EE_Error |
|
847 | - * @throws DomainException |
|
848 | - * @throws UnexpectedEntityException |
|
849 | - */ |
|
850 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
851 | - { |
|
852 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
853 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
854 | - return $filtered |
|
855 | - ? apply_filters( |
|
856 | - 'FHEE_EE_Event__spaces_remaining', |
|
857 | - $spaces_remaining, |
|
858 | - $this, |
|
859 | - $tickets |
|
860 | - ) |
|
861 | - : $spaces_remaining; |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * perform_sold_out_status_check |
|
867 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
868 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
869 | - * |
|
870 | - * @return bool return the ACTUAL sold out state. |
|
871 | - * @throws EE_Error |
|
872 | - * @throws DomainException |
|
873 | - * @throws UnexpectedEntityException |
|
874 | - */ |
|
875 | - public function perform_sold_out_status_check() |
|
876 | - { |
|
877 | - // get all tickets |
|
878 | - $tickets = $this->tickets( |
|
879 | - array( |
|
880 | - 'default_where_conditions' => 'none', |
|
881 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
882 | - ) |
|
883 | - ); |
|
884 | - $all_expired = true; |
|
885 | - foreach ($tickets as $ticket) { |
|
886 | - if (! $ticket->is_expired()) { |
|
887 | - $all_expired = false; |
|
888 | - break; |
|
889 | - } |
|
890 | - } |
|
891 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
892 | - if ($all_expired) { |
|
893 | - return true; |
|
894 | - } |
|
895 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
896 | - if ($spaces_remaining < 1) { |
|
897 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
898 | - $this->set_status(EEM_Event::sold_out); |
|
899 | - $this->save(); |
|
900 | - } |
|
901 | - $sold_out = true; |
|
902 | - } else { |
|
903 | - $sold_out = false; |
|
904 | - // was event previously marked as sold out ? |
|
905 | - if ($this->status() === EEM_Event::sold_out) { |
|
906 | - // revert status to previous value, if it was set |
|
907 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
908 | - if ($previous_event_status) { |
|
909 | - $this->set_status($previous_event_status); |
|
910 | - $this->save(); |
|
911 | - } |
|
912 | - } |
|
913 | - } |
|
914 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
915 | - return $sold_out; |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * This returns the total remaining spaces for sale on this event. |
|
921 | - * |
|
922 | - * @uses EE_Event::total_available_spaces() |
|
923 | - * @return float|int |
|
924 | - * @throws EE_Error |
|
925 | - * @throws DomainException |
|
926 | - * @throws UnexpectedEntityException |
|
927 | - */ |
|
928 | - public function spaces_remaining_for_sale() |
|
929 | - { |
|
930 | - return $this->total_available_spaces(true); |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * This returns the total spaces available for an event |
|
936 | - * while considering all the qtys on the tickets and the reg limits |
|
937 | - * on the datetimes attached to this event. |
|
938 | - * |
|
939 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
940 | - * If this is false, then we return the most tickets that could ever be sold |
|
941 | - * for this event with the datetime and tickets setup on the event under optimal |
|
942 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
943 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
944 | - * may appear to equal remaining tickets. However, the more tickets are |
|
945 | - * sold out, the more accurate the "live" total is. |
|
946 | - * @return float|int |
|
947 | - * @throws EE_Error |
|
948 | - * @throws DomainException |
|
949 | - * @throws UnexpectedEntityException |
|
950 | - */ |
|
951 | - public function total_available_spaces($consider_sold = false) |
|
952 | - { |
|
953 | - $spaces_available = $consider_sold |
|
954 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
955 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
956 | - return apply_filters( |
|
957 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
958 | - $spaces_available, |
|
959 | - $this, |
|
960 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
961 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
962 | - ); |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * Checks if the event is set to sold out |
|
968 | - * |
|
969 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
970 | - * actual status but also to flip the status if necessary to sold |
|
971 | - * out If false, we just check the existing status of the event |
|
972 | - * @return boolean |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - public function is_sold_out($actual = false) |
|
976 | - { |
|
977 | - if (! $actual) { |
|
978 | - return $this->status() === EEM_Event::sold_out; |
|
979 | - } |
|
980 | - return $this->perform_sold_out_status_check(); |
|
981 | - } |
|
982 | - |
|
983 | - |
|
984 | - /** |
|
985 | - * Checks if the event is marked as postponed |
|
986 | - * |
|
987 | - * @return boolean |
|
988 | - */ |
|
989 | - public function is_postponed() |
|
990 | - { |
|
991 | - return $this->status() === EEM_Event::postponed; |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * Checks if the event is marked as cancelled |
|
997 | - * |
|
998 | - * @return boolean |
|
999 | - */ |
|
1000 | - public function is_cancelled() |
|
1001 | - { |
|
1002 | - return $this->status() === EEM_Event::cancelled; |
|
1003 | - } |
|
1004 | - |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1008 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1009 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1010 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1011 | - * the event is considered expired. |
|
1012 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1013 | - * status set on the EVENT when it is not published and thus is done |
|
1014 | - * |
|
1015 | - * @param bool $reset |
|
1016 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1017 | - * @throws EE_Error |
|
1018 | - */ |
|
1019 | - public function get_active_status($reset = false) |
|
1020 | - { |
|
1021 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1022 | - if (! empty($this->_active_status) && ! $reset) { |
|
1023 | - return $this->_active_status; |
|
1024 | - } |
|
1025 | - // first check if event id is present on this object |
|
1026 | - if (! $this->ID()) { |
|
1027 | - return false; |
|
1028 | - } |
|
1029 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1030 | - // if event is published: |
|
1031 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
1032 | - // active? |
|
1033 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1034 | - EE_Datetime::active, |
|
1035 | - $where_params_for_event |
|
1036 | - ) > 0) { |
|
1037 | - $this->_active_status = EE_Datetime::active; |
|
1038 | - } else { |
|
1039 | - // upcoming? |
|
1040 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1041 | - EE_Datetime::upcoming, |
|
1042 | - $where_params_for_event |
|
1043 | - ) > 0) { |
|
1044 | - $this->_active_status = EE_Datetime::upcoming; |
|
1045 | - } else { |
|
1046 | - // expired? |
|
1047 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1048 | - EE_Datetime::expired, |
|
1049 | - $where_params_for_event |
|
1050 | - ) > 0 |
|
1051 | - ) { |
|
1052 | - $this->_active_status = EE_Datetime::expired; |
|
1053 | - } else { |
|
1054 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
1055 | - // attached to the event. So in this case it will just be considered inactive. |
|
1056 | - $this->_active_status = EE_Datetime::inactive; |
|
1057 | - } |
|
1058 | - } |
|
1059 | - } |
|
1060 | - } else { |
|
1061 | - // the event is not published, so let's just set it's active status according to its' post status |
|
1062 | - switch ($this->status()) { |
|
1063 | - case EEM_Event::sold_out: |
|
1064 | - $this->_active_status = EE_Datetime::sold_out; |
|
1065 | - break; |
|
1066 | - case EEM_Event::cancelled: |
|
1067 | - $this->_active_status = EE_Datetime::cancelled; |
|
1068 | - break; |
|
1069 | - case EEM_Event::postponed: |
|
1070 | - $this->_active_status = EE_Datetime::postponed; |
|
1071 | - break; |
|
1072 | - default: |
|
1073 | - $this->_active_status = EE_Datetime::inactive; |
|
1074 | - } |
|
1075 | - } |
|
1076 | - return $this->_active_status; |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * pretty_active_status |
|
1082 | - * |
|
1083 | - * @access public |
|
1084 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1085 | - * @return mixed void|string |
|
1086 | - * @throws EE_Error |
|
1087 | - */ |
|
1088 | - public function pretty_active_status($echo = true) |
|
1089 | - { |
|
1090 | - $active_status = $this->get_active_status(); |
|
1091 | - $status = '<span class="ee-status event-active-status-' |
|
1092 | - . $active_status |
|
1093 | - . '">' |
|
1094 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1095 | - . '</span>'; |
|
1096 | - if ($echo) { |
|
1097 | - echo $status; |
|
1098 | - return ''; |
|
1099 | - } |
|
1100 | - return $status; |
|
1101 | - } |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * @return bool|int |
|
1106 | - * @throws EE_Error |
|
1107 | - */ |
|
1108 | - public function get_number_of_tickets_sold() |
|
1109 | - { |
|
1110 | - $tkt_sold = 0; |
|
1111 | - if (! $this->ID()) { |
|
1112 | - return 0; |
|
1113 | - } |
|
1114 | - $datetimes = $this->datetimes(); |
|
1115 | - foreach ($datetimes as $datetime) { |
|
1116 | - if ($datetime instanceof EE_Datetime) { |
|
1117 | - $tkt_sold += $datetime->sold(); |
|
1118 | - } |
|
1119 | - } |
|
1120 | - return $tkt_sold; |
|
1121 | - } |
|
1122 | - |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * This just returns a count of all the registrations for this event |
|
1126 | - * |
|
1127 | - * @access public |
|
1128 | - * @return int |
|
1129 | - * @throws EE_Error |
|
1130 | - */ |
|
1131 | - public function get_count_of_all_registrations() |
|
1132 | - { |
|
1133 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * This returns the ticket with the earliest start time that is |
|
1139 | - * available for this event (across all datetimes attached to the event) |
|
1140 | - * |
|
1141 | - * @return EE_Base_Class|EE_Ticket|null |
|
1142 | - * @throws EE_Error |
|
1143 | - */ |
|
1144 | - public function get_ticket_with_earliest_start_time() |
|
1145 | - { |
|
1146 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1147 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1148 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1149 | - } |
|
1150 | - |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * This returns the ticket with the latest end time that is available |
|
1154 | - * for this event (across all datetimes attached to the event) |
|
1155 | - * |
|
1156 | - * @return EE_Base_Class|EE_Ticket|null |
|
1157 | - * @throws EE_Error |
|
1158 | - */ |
|
1159 | - public function get_ticket_with_latest_end_time() |
|
1160 | - { |
|
1161 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1162 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1163 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1164 | - } |
|
1165 | - |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * This returns the number of different ticket types currently on sale for this event. |
|
1169 | - * |
|
1170 | - * @return int |
|
1171 | - * @throws EE_Error |
|
1172 | - */ |
|
1173 | - public function countTicketsOnSale() |
|
1174 | - { |
|
1175 | - $where = array( |
|
1176 | - 'Datetime.EVT_ID' => $this->ID(), |
|
1177 | - 'TKT_start_date' => array('<', time()), |
|
1178 | - 'TKT_end_date' => array('>', time()), |
|
1179 | - ); |
|
1180 | - return EEM_Ticket::instance()->count(array($where)); |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * This returns whether there are any tickets on sale for this event. |
|
1186 | - * |
|
1187 | - * @return bool true = YES tickets on sale. |
|
1188 | - * @throws EE_Error |
|
1189 | - */ |
|
1190 | - public function tickets_on_sale() |
|
1191 | - { |
|
1192 | - return $this->countTicketsOnSale() > 0; |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1198 | - * to check for an external URL first |
|
1199 | - * |
|
1200 | - * @return string |
|
1201 | - * @throws EE_Error |
|
1202 | - */ |
|
1203 | - public function get_permalink() |
|
1204 | - { |
|
1205 | - if ($this->external_url()) { |
|
1206 | - return $this->external_url(); |
|
1207 | - } |
|
1208 | - return parent::get_permalink(); |
|
1209 | - } |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * Gets the first term for 'espresso_event_categories' we can find |
|
1214 | - * |
|
1215 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1216 | - * @return EE_Base_Class|EE_Term|null |
|
1217 | - * @throws EE_Error |
|
1218 | - */ |
|
1219 | - public function first_event_category($query_params = array()) |
|
1220 | - { |
|
1221 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1222 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1223 | - return EEM_Term::instance()->get_one($query_params); |
|
1224 | - } |
|
1225 | - |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Gets all terms for 'espresso_event_categories' we can find |
|
1229 | - * |
|
1230 | - * @param array $query_params |
|
1231 | - * @return EE_Base_Class[]|EE_Term[] |
|
1232 | - * @throws EE_Error |
|
1233 | - */ |
|
1234 | - public function get_all_event_categories($query_params = array()) |
|
1235 | - { |
|
1236 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1237 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1238 | - return EEM_Term::instance()->get_all($query_params); |
|
1239 | - } |
|
1240 | - |
|
1241 | - |
|
1242 | - /** |
|
1243 | - * Adds a question group to this event |
|
1244 | - * |
|
1245 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
1246 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
1247 | - * registrant, if false will be added for others. default: false |
|
1248 | - * @return EE_Base_Class|EE_Question_Group |
|
1249 | - * @throws EE_Error |
|
1250 | - * @throws InvalidArgumentException |
|
1251 | - * @throws InvalidDataTypeException |
|
1252 | - * @throws InvalidInterfaceException |
|
1253 | - * @throws ReflectionException |
|
1254 | - */ |
|
1255 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
1256 | - { |
|
1257 | - // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
1258 | - // That's in EE_HABTM_Relation::add_relation_to(). |
|
1259 | - return $this->_add_relation_to( |
|
1260 | - $question_group_id_or_obj, |
|
1261 | - 'Question_Group', |
|
1262 | - [ |
|
1263 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
1264 | - ] |
|
1265 | - ); |
|
1266 | - } |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Removes a question group from the event |
|
1271 | - * |
|
1272 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
1273 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
1274 | - * registrant, if false will be removed from others. default: false |
|
1275 | - * @return EE_Base_Class|EE_Question_Group |
|
1276 | - * @throws EE_Error |
|
1277 | - * @throws InvalidArgumentException |
|
1278 | - * @throws ReflectionException |
|
1279 | - * @throws InvalidDataTypeException |
|
1280 | - * @throws InvalidInterfaceException |
|
1281 | - */ |
|
1282 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
1283 | - { |
|
1284 | - // If the question group is used for the other type (primary or additional) |
|
1285 | - // then just update it. If not, delete it outright. |
|
1286 | - $existing_relation = $this->get_first_related( |
|
1287 | - 'Event_Question_Group', |
|
1288 | - [ |
|
1289 | - [ |
|
1290 | - 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
1291 | - ] |
|
1292 | - ] |
|
1293 | - ); |
|
1294 | - $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
1295 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1296 | - if ($existing_relation->get($other_field) === false) { |
|
1297 | - // Delete it. It's now no longer for primary or additional question groups. |
|
1298 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
1299 | - } |
|
1300 | - // Just update it. They'll still use this question group for the other category |
|
1301 | - $existing_relation->save( |
|
1302 | - [ |
|
1303 | - $field_to_update => false |
|
1304 | - ] |
|
1305 | - ); |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
1311 | - * |
|
1312 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1313 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
1314 | - * @throws EE_Error |
|
1315 | - */ |
|
1316 | - public function question_groups($query_params = array()) |
|
1317 | - { |
|
1318 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1319 | - return $this->get_many_related('Question_Group', $query_params); |
|
1320 | - } |
|
1321 | - |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * Implementation for EEI_Has_Icon interface method. |
|
1325 | - * |
|
1326 | - * @see EEI_Visual_Representation for comments |
|
1327 | - * @return string |
|
1328 | - */ |
|
1329 | - public function get_icon() |
|
1330 | - { |
|
1331 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
1332 | - } |
|
1333 | - |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * Implementation for EEI_Admin_Links interface method. |
|
1337 | - * |
|
1338 | - * @see EEI_Admin_Links for comments |
|
1339 | - * @return string |
|
1340 | - * @throws EE_Error |
|
1341 | - */ |
|
1342 | - public function get_admin_details_link() |
|
1343 | - { |
|
1344 | - return $this->get_admin_edit_link(); |
|
1345 | - } |
|
1346 | - |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Implementation for EEI_Admin_Links interface method. |
|
1350 | - * |
|
1351 | - * @see EEI_Admin_Links for comments |
|
1352 | - * @return string |
|
1353 | - * @throws EE_Error |
|
1354 | - */ |
|
1355 | - public function get_admin_edit_link() |
|
1356 | - { |
|
1357 | - return EEH_URL::add_query_args_and_nonce( |
|
1358 | - array( |
|
1359 | - 'page' => 'espresso_events', |
|
1360 | - 'action' => 'edit', |
|
1361 | - 'post' => $this->ID(), |
|
1362 | - ), |
|
1363 | - admin_url('admin.php') |
|
1364 | - ); |
|
1365 | - } |
|
1366 | - |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * Implementation for EEI_Admin_Links interface method. |
|
1370 | - * |
|
1371 | - * @see EEI_Admin_Links for comments |
|
1372 | - * @return string |
|
1373 | - */ |
|
1374 | - public function get_admin_settings_link() |
|
1375 | - { |
|
1376 | - return EEH_URL::add_query_args_and_nonce( |
|
1377 | - array( |
|
1378 | - 'page' => 'espresso_events', |
|
1379 | - 'action' => 'default_event_settings', |
|
1380 | - ), |
|
1381 | - admin_url('admin.php') |
|
1382 | - ); |
|
1383 | - } |
|
1384 | - |
|
1385 | - |
|
1386 | - /** |
|
1387 | - * Implementation for EEI_Admin_Links interface method. |
|
1388 | - * |
|
1389 | - * @see EEI_Admin_Links for comments |
|
1390 | - * @return string |
|
1391 | - */ |
|
1392 | - public function get_admin_overview_link() |
|
1393 | - { |
|
1394 | - return EEH_URL::add_query_args_and_nonce( |
|
1395 | - array( |
|
1396 | - 'page' => 'espresso_events', |
|
1397 | - 'action' => 'default', |
|
1398 | - ), |
|
1399 | - admin_url('admin.php') |
|
1400 | - ); |
|
1401 | - } |
|
18 | + /** |
|
19 | + * cached value for the the logical active status for the event |
|
20 | + * |
|
21 | + * @see get_active_status() |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_active_status = ''; |
|
25 | + |
|
26 | + /** |
|
27 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
28 | + * |
|
29 | + * @var EE_Datetime |
|
30 | + */ |
|
31 | + protected $_Primary_Datetime; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
35 | + */ |
|
36 | + protected $available_spaces_calculator; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param array $props_n_values incoming values |
|
41 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
42 | + * used.) |
|
43 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
44 | + * date_format and the second value is the time format |
|
45 | + * @return EE_Event |
|
46 | + * @throws EE_Error |
|
47 | + */ |
|
48 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
49 | + { |
|
50 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
51 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array $props_n_values incoming values from the database |
|
57 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
58 | + * the website will be used. |
|
59 | + * @return EE_Event |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
63 | + { |
|
64 | + return new self($props_n_values, true, $timezone); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return EventSpacesCalculator |
|
70 | + * @throws \EE_Error |
|
71 | + */ |
|
72 | + public function getAvailableSpacesCalculator() |
|
73 | + { |
|
74 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
75 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
76 | + } |
|
77 | + return $this->available_spaces_calculator; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
83 | + * |
|
84 | + * @param string $field_name |
|
85 | + * @param mixed $field_value |
|
86 | + * @param bool $use_default |
|
87 | + * @throws EE_Error |
|
88 | + */ |
|
89 | + public function set($field_name, $field_value, $use_default = false) |
|
90 | + { |
|
91 | + switch ($field_name) { |
|
92 | + case 'status': |
|
93 | + $this->set_status($field_value, $use_default); |
|
94 | + break; |
|
95 | + default: |
|
96 | + parent::set($field_name, $field_value, $use_default); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * set_status |
|
103 | + * Checks if event status is being changed to SOLD OUT |
|
104 | + * and updates event meta data with previous event status |
|
105 | + * so that we can revert things if/when the event is no longer sold out |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @param string $new_status |
|
109 | + * @param bool $use_default |
|
110 | + * @return void |
|
111 | + * @throws EE_Error |
|
112 | + */ |
|
113 | + public function set_status($new_status = null, $use_default = false) |
|
114 | + { |
|
115 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
116 | + if (empty($new_status) && ! $use_default) { |
|
117 | + return; |
|
118 | + } |
|
119 | + // get current Event status |
|
120 | + $old_status = $this->status(); |
|
121 | + // if status has changed |
|
122 | + if ($old_status !== $new_status) { |
|
123 | + // TO sold_out |
|
124 | + if ($new_status === EEM_Event::sold_out) { |
|
125 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
126 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
127 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
128 | + // OR FROM sold_out |
|
129 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
130 | + $this->delete_post_meta('_previous_event_status'); |
|
131 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
132 | + } |
|
133 | + // clear out the active status so that it gets reset the next time it is requested |
|
134 | + $this->_active_status = null; |
|
135 | + // update status |
|
136 | + parent::set('status', $new_status, $use_default); |
|
137 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
138 | + return; |
|
139 | + } |
|
140 | + // even though the old value matches the new value, it's still good to |
|
141 | + // allow the parent set method to have a say |
|
142 | + parent::set('status', $new_status, $use_default); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets all the datetimes for this event |
|
148 | + * |
|
149 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
150 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
151 | + * @throws EE_Error |
|
152 | + */ |
|
153 | + public function datetimes($query_params = array()) |
|
154 | + { |
|
155 | + return $this->get_many_related('Datetime', $query_params); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
161 | + * |
|
162 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + public function datetimes_in_chronological_order() |
|
166 | + { |
|
167 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
173 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
174 | + * after running our query, so that this timezone isn't set for EVERY query |
|
175 | + * on EEM_Datetime for the rest of the request, no? |
|
176 | + * |
|
177 | + * @param boolean $show_expired whether or not to include expired events |
|
178 | + * @param boolean $show_deleted whether or not to include deleted events |
|
179 | + * @param null $limit |
|
180 | + * @return EE_Datetime[] |
|
181 | + * @throws EE_Error |
|
182 | + */ |
|
183 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
184 | + { |
|
185 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
186 | + $this->ID(), |
|
187 | + $show_expired, |
|
188 | + $show_deleted, |
|
189 | + $limit |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
196 | + * |
|
197 | + * @return EE_Base_Class|EE_Datetime |
|
198 | + * @throws EE_Error |
|
199 | + */ |
|
200 | + public function first_datetime() |
|
201 | + { |
|
202 | + return $this->get_first_related('Datetime'); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Returns the 'primary' datetime for the event |
|
208 | + * |
|
209 | + * @param bool $try_to_exclude_expired |
|
210 | + * @param bool $try_to_exclude_deleted |
|
211 | + * @return EE_Datetime |
|
212 | + * @throws EE_Error |
|
213 | + */ |
|
214 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
215 | + { |
|
216 | + if (! empty($this->_Primary_Datetime)) { |
|
217 | + return $this->_Primary_Datetime; |
|
218 | + } |
|
219 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
220 | + $this->ID(), |
|
221 | + $try_to_exclude_expired, |
|
222 | + $try_to_exclude_deleted |
|
223 | + ); |
|
224 | + return $this->_Primary_Datetime; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Gets all the tickets available for purchase of this event |
|
230 | + * |
|
231 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
232 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
233 | + * @throws EE_Error |
|
234 | + */ |
|
235 | + public function tickets($query_params = array()) |
|
236 | + { |
|
237 | + // first get all datetimes |
|
238 | + $datetimes = $this->datetimes_ordered(); |
|
239 | + if (! $datetimes) { |
|
240 | + return array(); |
|
241 | + } |
|
242 | + $datetime_ids = array(); |
|
243 | + foreach ($datetimes as $datetime) { |
|
244 | + $datetime_ids[] = $datetime->ID(); |
|
245 | + } |
|
246 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
247 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
248 | + if (is_array($query_params) && isset($query_params[0])) { |
|
249 | + $where_params = array_merge($query_params[0], $where_params); |
|
250 | + unset($query_params[0]); |
|
251 | + } |
|
252 | + // now add $where_params to $query_params |
|
253 | + $query_params[0] = $where_params; |
|
254 | + return EEM_Ticket::instance()->get_all($query_params); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * get all unexpired untrashed tickets |
|
260 | + * |
|
261 | + * @return EE_Ticket[] |
|
262 | + * @throws EE_Error |
|
263 | + */ |
|
264 | + public function active_tickets() |
|
265 | + { |
|
266 | + return $this->tickets( |
|
267 | + array( |
|
268 | + array( |
|
269 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
270 | + 'TKT_deleted' => false, |
|
271 | + ), |
|
272 | + ) |
|
273 | + ); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @return bool |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function additional_limit() |
|
282 | + { |
|
283 | + return $this->get('EVT_additional_limit'); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return bool |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function allow_overflow() |
|
292 | + { |
|
293 | + return $this->get('EVT_allow_overflow'); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @return bool |
|
299 | + * @throws EE_Error |
|
300 | + */ |
|
301 | + public function created() |
|
302 | + { |
|
303 | + return $this->get('EVT_created'); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * @return bool |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + public function description() |
|
312 | + { |
|
313 | + return $this->get('EVT_desc'); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Runs do_shortcode and wpautop on the description |
|
319 | + * |
|
320 | + * @return string of html |
|
321 | + * @throws EE_Error |
|
322 | + */ |
|
323 | + public function description_filtered() |
|
324 | + { |
|
325 | + return $this->get_pretty('EVT_desc'); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @return bool |
|
331 | + * @throws EE_Error |
|
332 | + */ |
|
333 | + public function display_description() |
|
334 | + { |
|
335 | + return $this->get('EVT_display_desc'); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @return bool |
|
341 | + * @throws EE_Error |
|
342 | + */ |
|
343 | + public function display_ticket_selector() |
|
344 | + { |
|
345 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @return bool |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function external_url() |
|
354 | + { |
|
355 | + return $this->get('EVT_external_URL'); |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return bool |
|
361 | + * @throws EE_Error |
|
362 | + */ |
|
363 | + public function member_only() |
|
364 | + { |
|
365 | + return $this->get('EVT_member_only'); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @return bool |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + public function phone() |
|
374 | + { |
|
375 | + return $this->get('EVT_phone'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return bool |
|
381 | + * @throws EE_Error |
|
382 | + */ |
|
383 | + public function modified() |
|
384 | + { |
|
385 | + return $this->get('EVT_modified'); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @return bool |
|
391 | + * @throws EE_Error |
|
392 | + */ |
|
393 | + public function name() |
|
394 | + { |
|
395 | + return $this->get('EVT_name'); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * @return bool |
|
401 | + * @throws EE_Error |
|
402 | + */ |
|
403 | + public function order() |
|
404 | + { |
|
405 | + return $this->get('EVT_order'); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * @return bool|string |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + public function default_registration_status() |
|
414 | + { |
|
415 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
416 | + return ! empty($event_default_registration_status) |
|
417 | + ? $event_default_registration_status |
|
418 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @param int $num_words |
|
424 | + * @param null $more |
|
425 | + * @param bool $not_full_desc |
|
426 | + * @return bool|string |
|
427 | + * @throws EE_Error |
|
428 | + */ |
|
429 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
430 | + { |
|
431 | + $short_desc = $this->get('EVT_short_desc'); |
|
432 | + if (! empty($short_desc) || $not_full_desc) { |
|
433 | + return $short_desc; |
|
434 | + } |
|
435 | + $full_desc = $this->get('EVT_desc'); |
|
436 | + return wp_trim_words($full_desc, $num_words, $more); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * @return bool |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + public function slug() |
|
445 | + { |
|
446 | + return $this->get('EVT_slug'); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @return bool |
|
452 | + * @throws EE_Error |
|
453 | + */ |
|
454 | + public function timezone_string() |
|
455 | + { |
|
456 | + return $this->get('EVT_timezone_string'); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * @return bool |
|
462 | + * @throws EE_Error |
|
463 | + */ |
|
464 | + public function visible_on() |
|
465 | + { |
|
466 | + return $this->get('EVT_visible_on'); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * @return int |
|
472 | + * @throws EE_Error |
|
473 | + */ |
|
474 | + public function wp_user() |
|
475 | + { |
|
476 | + return $this->get('EVT_wp_user'); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * @return bool |
|
482 | + * @throws EE_Error |
|
483 | + */ |
|
484 | + public function donations() |
|
485 | + { |
|
486 | + return $this->get('EVT_donations'); |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * @param $limit |
|
492 | + * @throws EE_Error |
|
493 | + */ |
|
494 | + public function set_additional_limit($limit) |
|
495 | + { |
|
496 | + $this->set('EVT_additional_limit', $limit); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param $created |
|
502 | + * @throws EE_Error |
|
503 | + */ |
|
504 | + public function set_created($created) |
|
505 | + { |
|
506 | + $this->set('EVT_created', $created); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * @param $desc |
|
512 | + * @throws EE_Error |
|
513 | + */ |
|
514 | + public function set_description($desc) |
|
515 | + { |
|
516 | + $this->set('EVT_desc', $desc); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param $display_desc |
|
522 | + * @throws EE_Error |
|
523 | + */ |
|
524 | + public function set_display_description($display_desc) |
|
525 | + { |
|
526 | + $this->set('EVT_display_desc', $display_desc); |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @param $display_ticket_selector |
|
532 | + * @throws EE_Error |
|
533 | + */ |
|
534 | + public function set_display_ticket_selector($display_ticket_selector) |
|
535 | + { |
|
536 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * @param $external_url |
|
542 | + * @throws EE_Error |
|
543 | + */ |
|
544 | + public function set_external_url($external_url) |
|
545 | + { |
|
546 | + $this->set('EVT_external_URL', $external_url); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * @param $member_only |
|
552 | + * @throws EE_Error |
|
553 | + */ |
|
554 | + public function set_member_only($member_only) |
|
555 | + { |
|
556 | + $this->set('EVT_member_only', $member_only); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * @param $event_phone |
|
562 | + * @throws EE_Error |
|
563 | + */ |
|
564 | + public function set_event_phone($event_phone) |
|
565 | + { |
|
566 | + $this->set('EVT_phone', $event_phone); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * @param $modified |
|
572 | + * @throws EE_Error |
|
573 | + */ |
|
574 | + public function set_modified($modified) |
|
575 | + { |
|
576 | + $this->set('EVT_modified', $modified); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * @param $name |
|
582 | + * @throws EE_Error |
|
583 | + */ |
|
584 | + public function set_name($name) |
|
585 | + { |
|
586 | + $this->set('EVT_name', $name); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * @param $order |
|
592 | + * @throws EE_Error |
|
593 | + */ |
|
594 | + public function set_order($order) |
|
595 | + { |
|
596 | + $this->set('EVT_order', $order); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * @param $short_desc |
|
602 | + * @throws EE_Error |
|
603 | + */ |
|
604 | + public function set_short_description($short_desc) |
|
605 | + { |
|
606 | + $this->set('EVT_short_desc', $short_desc); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * @param $slug |
|
612 | + * @throws EE_Error |
|
613 | + */ |
|
614 | + public function set_slug($slug) |
|
615 | + { |
|
616 | + $this->set('EVT_slug', $slug); |
|
617 | + } |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * @param $timezone_string |
|
622 | + * @throws EE_Error |
|
623 | + */ |
|
624 | + public function set_timezone_string($timezone_string) |
|
625 | + { |
|
626 | + $this->set('EVT_timezone_string', $timezone_string); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * @param $visible_on |
|
632 | + * @throws EE_Error |
|
633 | + */ |
|
634 | + public function set_visible_on($visible_on) |
|
635 | + { |
|
636 | + $this->set('EVT_visible_on', $visible_on); |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + /** |
|
641 | + * @param $wp_user |
|
642 | + * @throws EE_Error |
|
643 | + */ |
|
644 | + public function set_wp_user($wp_user) |
|
645 | + { |
|
646 | + $this->set('EVT_wp_user', $wp_user); |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * @param $default_registration_status |
|
652 | + * @throws EE_Error |
|
653 | + */ |
|
654 | + public function set_default_registration_status($default_registration_status) |
|
655 | + { |
|
656 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * @param $donations |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function set_donations($donations) |
|
665 | + { |
|
666 | + $this->set('EVT_donations', $donations); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * Adds a venue to this event |
|
672 | + * |
|
673 | + * @param EE_Venue /int $venue_id_or_obj |
|
674 | + * @return EE_Base_Class|EE_Venue |
|
675 | + * @throws EE_Error |
|
676 | + */ |
|
677 | + public function add_venue($venue_id_or_obj) |
|
678 | + { |
|
679 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * Removes a venue from the event |
|
685 | + * |
|
686 | + * @param EE_Venue /int $venue_id_or_obj |
|
687 | + * @return EE_Base_Class|EE_Venue |
|
688 | + * @throws EE_Error |
|
689 | + */ |
|
690 | + public function remove_venue($venue_id_or_obj) |
|
691 | + { |
|
692 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
698 | + * |
|
699 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
700 | + * @return EE_Base_Class[]|EE_Venue[] |
|
701 | + * @throws EE_Error |
|
702 | + */ |
|
703 | + public function venues($query_params = array()) |
|
704 | + { |
|
705 | + return $this->get_many_related('Venue', $query_params); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * check if event id is present and if event is published |
|
711 | + * |
|
712 | + * @access public |
|
713 | + * @return boolean true yes, false no |
|
714 | + * @throws EE_Error |
|
715 | + */ |
|
716 | + private function _has_ID_and_is_published() |
|
717 | + { |
|
718 | + // first check if event id is present and not NULL, |
|
719 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
720 | + return |
|
721 | + $this->ID() && $this->ID() !== null |
|
722 | + && ( |
|
723 | + $this->status() === 'publish' |
|
724 | + || $this->status() === EEM_Event::sold_out |
|
725 | + || $this->status() === EEM_Event::postponed |
|
726 | + || $this->status() === EEM_Event::cancelled |
|
727 | + ); |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
733 | + * |
|
734 | + * @access public |
|
735 | + * @return boolean true yes, false no |
|
736 | + * @throws EE_Error |
|
737 | + */ |
|
738 | + public function is_upcoming() |
|
739 | + { |
|
740 | + // check if event id is present and if this event is published |
|
741 | + if ($this->is_inactive()) { |
|
742 | + return false; |
|
743 | + } |
|
744 | + // set initial value |
|
745 | + $upcoming = false; |
|
746 | + // next let's get all datetimes and loop through them |
|
747 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
748 | + foreach ($datetimes as $datetime) { |
|
749 | + if ($datetime instanceof EE_Datetime) { |
|
750 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
751 | + if ($datetime->is_expired()) { |
|
752 | + continue; |
|
753 | + } |
|
754 | + // if this dtt is active then we return false. |
|
755 | + if ($datetime->is_active()) { |
|
756 | + return false; |
|
757 | + } |
|
758 | + // otherwise let's check upcoming status |
|
759 | + $upcoming = $datetime->is_upcoming(); |
|
760 | + } |
|
761 | + } |
|
762 | + return $upcoming; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * @return bool |
|
768 | + * @throws EE_Error |
|
769 | + */ |
|
770 | + public function is_active() |
|
771 | + { |
|
772 | + // check if event id is present and if this event is published |
|
773 | + if ($this->is_inactive()) { |
|
774 | + return false; |
|
775 | + } |
|
776 | + // set initial value |
|
777 | + $active = false; |
|
778 | + // next let's get all datetimes and loop through them |
|
779 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
780 | + foreach ($datetimes as $datetime) { |
|
781 | + if ($datetime instanceof EE_Datetime) { |
|
782 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
783 | + if ($datetime->is_expired()) { |
|
784 | + continue; |
|
785 | + } |
|
786 | + // if this dtt is upcoming then we return false. |
|
787 | + if ($datetime->is_upcoming()) { |
|
788 | + return false; |
|
789 | + } |
|
790 | + // otherwise let's check active status |
|
791 | + $active = $datetime->is_active(); |
|
792 | + } |
|
793 | + } |
|
794 | + return $active; |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + /** |
|
799 | + * @return bool |
|
800 | + * @throws EE_Error |
|
801 | + */ |
|
802 | + public function is_expired() |
|
803 | + { |
|
804 | + // check if event id is present and if this event is published |
|
805 | + if ($this->is_inactive()) { |
|
806 | + return false; |
|
807 | + } |
|
808 | + // set initial value |
|
809 | + $expired = false; |
|
810 | + // first let's get all datetimes and loop through them |
|
811 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
812 | + foreach ($datetimes as $datetime) { |
|
813 | + if ($datetime instanceof EE_Datetime) { |
|
814 | + // if this dtt is upcoming or active then we return false. |
|
815 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
816 | + return false; |
|
817 | + } |
|
818 | + // otherwise let's check active status |
|
819 | + $expired = $datetime->is_expired(); |
|
820 | + } |
|
821 | + } |
|
822 | + return $expired; |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * @return bool |
|
828 | + * @throws EE_Error |
|
829 | + */ |
|
830 | + public function is_inactive() |
|
831 | + { |
|
832 | + // check if event id is present and if this event is published |
|
833 | + if ($this->_has_ID_and_is_published()) { |
|
834 | + return false; |
|
835 | + } |
|
836 | + return true; |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * calculate spaces remaining based on "saleable" tickets |
|
842 | + * |
|
843 | + * @param array $tickets |
|
844 | + * @param bool $filtered |
|
845 | + * @return int|float |
|
846 | + * @throws EE_Error |
|
847 | + * @throws DomainException |
|
848 | + * @throws UnexpectedEntityException |
|
849 | + */ |
|
850 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
851 | + { |
|
852 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
853 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
854 | + return $filtered |
|
855 | + ? apply_filters( |
|
856 | + 'FHEE_EE_Event__spaces_remaining', |
|
857 | + $spaces_remaining, |
|
858 | + $this, |
|
859 | + $tickets |
|
860 | + ) |
|
861 | + : $spaces_remaining; |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * perform_sold_out_status_check |
|
867 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
868 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
869 | + * |
|
870 | + * @return bool return the ACTUAL sold out state. |
|
871 | + * @throws EE_Error |
|
872 | + * @throws DomainException |
|
873 | + * @throws UnexpectedEntityException |
|
874 | + */ |
|
875 | + public function perform_sold_out_status_check() |
|
876 | + { |
|
877 | + // get all tickets |
|
878 | + $tickets = $this->tickets( |
|
879 | + array( |
|
880 | + 'default_where_conditions' => 'none', |
|
881 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
882 | + ) |
|
883 | + ); |
|
884 | + $all_expired = true; |
|
885 | + foreach ($tickets as $ticket) { |
|
886 | + if (! $ticket->is_expired()) { |
|
887 | + $all_expired = false; |
|
888 | + break; |
|
889 | + } |
|
890 | + } |
|
891 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
892 | + if ($all_expired) { |
|
893 | + return true; |
|
894 | + } |
|
895 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
896 | + if ($spaces_remaining < 1) { |
|
897 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
898 | + $this->set_status(EEM_Event::sold_out); |
|
899 | + $this->save(); |
|
900 | + } |
|
901 | + $sold_out = true; |
|
902 | + } else { |
|
903 | + $sold_out = false; |
|
904 | + // was event previously marked as sold out ? |
|
905 | + if ($this->status() === EEM_Event::sold_out) { |
|
906 | + // revert status to previous value, if it was set |
|
907 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
908 | + if ($previous_event_status) { |
|
909 | + $this->set_status($previous_event_status); |
|
910 | + $this->save(); |
|
911 | + } |
|
912 | + } |
|
913 | + } |
|
914 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
915 | + return $sold_out; |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * This returns the total remaining spaces for sale on this event. |
|
921 | + * |
|
922 | + * @uses EE_Event::total_available_spaces() |
|
923 | + * @return float|int |
|
924 | + * @throws EE_Error |
|
925 | + * @throws DomainException |
|
926 | + * @throws UnexpectedEntityException |
|
927 | + */ |
|
928 | + public function spaces_remaining_for_sale() |
|
929 | + { |
|
930 | + return $this->total_available_spaces(true); |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * This returns the total spaces available for an event |
|
936 | + * while considering all the qtys on the tickets and the reg limits |
|
937 | + * on the datetimes attached to this event. |
|
938 | + * |
|
939 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
940 | + * If this is false, then we return the most tickets that could ever be sold |
|
941 | + * for this event with the datetime and tickets setup on the event under optimal |
|
942 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
943 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
944 | + * may appear to equal remaining tickets. However, the more tickets are |
|
945 | + * sold out, the more accurate the "live" total is. |
|
946 | + * @return float|int |
|
947 | + * @throws EE_Error |
|
948 | + * @throws DomainException |
|
949 | + * @throws UnexpectedEntityException |
|
950 | + */ |
|
951 | + public function total_available_spaces($consider_sold = false) |
|
952 | + { |
|
953 | + $spaces_available = $consider_sold |
|
954 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
955 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
956 | + return apply_filters( |
|
957 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
958 | + $spaces_available, |
|
959 | + $this, |
|
960 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
961 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
962 | + ); |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * Checks if the event is set to sold out |
|
968 | + * |
|
969 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
970 | + * actual status but also to flip the status if necessary to sold |
|
971 | + * out If false, we just check the existing status of the event |
|
972 | + * @return boolean |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + public function is_sold_out($actual = false) |
|
976 | + { |
|
977 | + if (! $actual) { |
|
978 | + return $this->status() === EEM_Event::sold_out; |
|
979 | + } |
|
980 | + return $this->perform_sold_out_status_check(); |
|
981 | + } |
|
982 | + |
|
983 | + |
|
984 | + /** |
|
985 | + * Checks if the event is marked as postponed |
|
986 | + * |
|
987 | + * @return boolean |
|
988 | + */ |
|
989 | + public function is_postponed() |
|
990 | + { |
|
991 | + return $this->status() === EEM_Event::postponed; |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * Checks if the event is marked as cancelled |
|
997 | + * |
|
998 | + * @return boolean |
|
999 | + */ |
|
1000 | + public function is_cancelled() |
|
1001 | + { |
|
1002 | + return $this->status() === EEM_Event::cancelled; |
|
1003 | + } |
|
1004 | + |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1008 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1009 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1010 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1011 | + * the event is considered expired. |
|
1012 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1013 | + * status set on the EVENT when it is not published and thus is done |
|
1014 | + * |
|
1015 | + * @param bool $reset |
|
1016 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1017 | + * @throws EE_Error |
|
1018 | + */ |
|
1019 | + public function get_active_status($reset = false) |
|
1020 | + { |
|
1021 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1022 | + if (! empty($this->_active_status) && ! $reset) { |
|
1023 | + return $this->_active_status; |
|
1024 | + } |
|
1025 | + // first check if event id is present on this object |
|
1026 | + if (! $this->ID()) { |
|
1027 | + return false; |
|
1028 | + } |
|
1029 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1030 | + // if event is published: |
|
1031 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
1032 | + // active? |
|
1033 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1034 | + EE_Datetime::active, |
|
1035 | + $where_params_for_event |
|
1036 | + ) > 0) { |
|
1037 | + $this->_active_status = EE_Datetime::active; |
|
1038 | + } else { |
|
1039 | + // upcoming? |
|
1040 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1041 | + EE_Datetime::upcoming, |
|
1042 | + $where_params_for_event |
|
1043 | + ) > 0) { |
|
1044 | + $this->_active_status = EE_Datetime::upcoming; |
|
1045 | + } else { |
|
1046 | + // expired? |
|
1047 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1048 | + EE_Datetime::expired, |
|
1049 | + $where_params_for_event |
|
1050 | + ) > 0 |
|
1051 | + ) { |
|
1052 | + $this->_active_status = EE_Datetime::expired; |
|
1053 | + } else { |
|
1054 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
1055 | + // attached to the event. So in this case it will just be considered inactive. |
|
1056 | + $this->_active_status = EE_Datetime::inactive; |
|
1057 | + } |
|
1058 | + } |
|
1059 | + } |
|
1060 | + } else { |
|
1061 | + // the event is not published, so let's just set it's active status according to its' post status |
|
1062 | + switch ($this->status()) { |
|
1063 | + case EEM_Event::sold_out: |
|
1064 | + $this->_active_status = EE_Datetime::sold_out; |
|
1065 | + break; |
|
1066 | + case EEM_Event::cancelled: |
|
1067 | + $this->_active_status = EE_Datetime::cancelled; |
|
1068 | + break; |
|
1069 | + case EEM_Event::postponed: |
|
1070 | + $this->_active_status = EE_Datetime::postponed; |
|
1071 | + break; |
|
1072 | + default: |
|
1073 | + $this->_active_status = EE_Datetime::inactive; |
|
1074 | + } |
|
1075 | + } |
|
1076 | + return $this->_active_status; |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * pretty_active_status |
|
1082 | + * |
|
1083 | + * @access public |
|
1084 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1085 | + * @return mixed void|string |
|
1086 | + * @throws EE_Error |
|
1087 | + */ |
|
1088 | + public function pretty_active_status($echo = true) |
|
1089 | + { |
|
1090 | + $active_status = $this->get_active_status(); |
|
1091 | + $status = '<span class="ee-status event-active-status-' |
|
1092 | + . $active_status |
|
1093 | + . '">' |
|
1094 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1095 | + . '</span>'; |
|
1096 | + if ($echo) { |
|
1097 | + echo $status; |
|
1098 | + return ''; |
|
1099 | + } |
|
1100 | + return $status; |
|
1101 | + } |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * @return bool|int |
|
1106 | + * @throws EE_Error |
|
1107 | + */ |
|
1108 | + public function get_number_of_tickets_sold() |
|
1109 | + { |
|
1110 | + $tkt_sold = 0; |
|
1111 | + if (! $this->ID()) { |
|
1112 | + return 0; |
|
1113 | + } |
|
1114 | + $datetimes = $this->datetimes(); |
|
1115 | + foreach ($datetimes as $datetime) { |
|
1116 | + if ($datetime instanceof EE_Datetime) { |
|
1117 | + $tkt_sold += $datetime->sold(); |
|
1118 | + } |
|
1119 | + } |
|
1120 | + return $tkt_sold; |
|
1121 | + } |
|
1122 | + |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * This just returns a count of all the registrations for this event |
|
1126 | + * |
|
1127 | + * @access public |
|
1128 | + * @return int |
|
1129 | + * @throws EE_Error |
|
1130 | + */ |
|
1131 | + public function get_count_of_all_registrations() |
|
1132 | + { |
|
1133 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * This returns the ticket with the earliest start time that is |
|
1139 | + * available for this event (across all datetimes attached to the event) |
|
1140 | + * |
|
1141 | + * @return EE_Base_Class|EE_Ticket|null |
|
1142 | + * @throws EE_Error |
|
1143 | + */ |
|
1144 | + public function get_ticket_with_earliest_start_time() |
|
1145 | + { |
|
1146 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1147 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1148 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1149 | + } |
|
1150 | + |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * This returns the ticket with the latest end time that is available |
|
1154 | + * for this event (across all datetimes attached to the event) |
|
1155 | + * |
|
1156 | + * @return EE_Base_Class|EE_Ticket|null |
|
1157 | + * @throws EE_Error |
|
1158 | + */ |
|
1159 | + public function get_ticket_with_latest_end_time() |
|
1160 | + { |
|
1161 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1162 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1163 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1164 | + } |
|
1165 | + |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * This returns the number of different ticket types currently on sale for this event. |
|
1169 | + * |
|
1170 | + * @return int |
|
1171 | + * @throws EE_Error |
|
1172 | + */ |
|
1173 | + public function countTicketsOnSale() |
|
1174 | + { |
|
1175 | + $where = array( |
|
1176 | + 'Datetime.EVT_ID' => $this->ID(), |
|
1177 | + 'TKT_start_date' => array('<', time()), |
|
1178 | + 'TKT_end_date' => array('>', time()), |
|
1179 | + ); |
|
1180 | + return EEM_Ticket::instance()->count(array($where)); |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * This returns whether there are any tickets on sale for this event. |
|
1186 | + * |
|
1187 | + * @return bool true = YES tickets on sale. |
|
1188 | + * @throws EE_Error |
|
1189 | + */ |
|
1190 | + public function tickets_on_sale() |
|
1191 | + { |
|
1192 | + return $this->countTicketsOnSale() > 0; |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1198 | + * to check for an external URL first |
|
1199 | + * |
|
1200 | + * @return string |
|
1201 | + * @throws EE_Error |
|
1202 | + */ |
|
1203 | + public function get_permalink() |
|
1204 | + { |
|
1205 | + if ($this->external_url()) { |
|
1206 | + return $this->external_url(); |
|
1207 | + } |
|
1208 | + return parent::get_permalink(); |
|
1209 | + } |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * Gets the first term for 'espresso_event_categories' we can find |
|
1214 | + * |
|
1215 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1216 | + * @return EE_Base_Class|EE_Term|null |
|
1217 | + * @throws EE_Error |
|
1218 | + */ |
|
1219 | + public function first_event_category($query_params = array()) |
|
1220 | + { |
|
1221 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1222 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1223 | + return EEM_Term::instance()->get_one($query_params); |
|
1224 | + } |
|
1225 | + |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Gets all terms for 'espresso_event_categories' we can find |
|
1229 | + * |
|
1230 | + * @param array $query_params |
|
1231 | + * @return EE_Base_Class[]|EE_Term[] |
|
1232 | + * @throws EE_Error |
|
1233 | + */ |
|
1234 | + public function get_all_event_categories($query_params = array()) |
|
1235 | + { |
|
1236 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1237 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1238 | + return EEM_Term::instance()->get_all($query_params); |
|
1239 | + } |
|
1240 | + |
|
1241 | + |
|
1242 | + /** |
|
1243 | + * Adds a question group to this event |
|
1244 | + * |
|
1245 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
1246 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
1247 | + * registrant, if false will be added for others. default: false |
|
1248 | + * @return EE_Base_Class|EE_Question_Group |
|
1249 | + * @throws EE_Error |
|
1250 | + * @throws InvalidArgumentException |
|
1251 | + * @throws InvalidDataTypeException |
|
1252 | + * @throws InvalidInterfaceException |
|
1253 | + * @throws ReflectionException |
|
1254 | + */ |
|
1255 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
1256 | + { |
|
1257 | + // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
1258 | + // That's in EE_HABTM_Relation::add_relation_to(). |
|
1259 | + return $this->_add_relation_to( |
|
1260 | + $question_group_id_or_obj, |
|
1261 | + 'Question_Group', |
|
1262 | + [ |
|
1263 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
1264 | + ] |
|
1265 | + ); |
|
1266 | + } |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Removes a question group from the event |
|
1271 | + * |
|
1272 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
1273 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
1274 | + * registrant, if false will be removed from others. default: false |
|
1275 | + * @return EE_Base_Class|EE_Question_Group |
|
1276 | + * @throws EE_Error |
|
1277 | + * @throws InvalidArgumentException |
|
1278 | + * @throws ReflectionException |
|
1279 | + * @throws InvalidDataTypeException |
|
1280 | + * @throws InvalidInterfaceException |
|
1281 | + */ |
|
1282 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
1283 | + { |
|
1284 | + // If the question group is used for the other type (primary or additional) |
|
1285 | + // then just update it. If not, delete it outright. |
|
1286 | + $existing_relation = $this->get_first_related( |
|
1287 | + 'Event_Question_Group', |
|
1288 | + [ |
|
1289 | + [ |
|
1290 | + 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
1291 | + ] |
|
1292 | + ] |
|
1293 | + ); |
|
1294 | + $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
1295 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1296 | + if ($existing_relation->get($other_field) === false) { |
|
1297 | + // Delete it. It's now no longer for primary or additional question groups. |
|
1298 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
1299 | + } |
|
1300 | + // Just update it. They'll still use this question group for the other category |
|
1301 | + $existing_relation->save( |
|
1302 | + [ |
|
1303 | + $field_to_update => false |
|
1304 | + ] |
|
1305 | + ); |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
1311 | + * |
|
1312 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1313 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
1314 | + * @throws EE_Error |
|
1315 | + */ |
|
1316 | + public function question_groups($query_params = array()) |
|
1317 | + { |
|
1318 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1319 | + return $this->get_many_related('Question_Group', $query_params); |
|
1320 | + } |
|
1321 | + |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * Implementation for EEI_Has_Icon interface method. |
|
1325 | + * |
|
1326 | + * @see EEI_Visual_Representation for comments |
|
1327 | + * @return string |
|
1328 | + */ |
|
1329 | + public function get_icon() |
|
1330 | + { |
|
1331 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
1332 | + } |
|
1333 | + |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * Implementation for EEI_Admin_Links interface method. |
|
1337 | + * |
|
1338 | + * @see EEI_Admin_Links for comments |
|
1339 | + * @return string |
|
1340 | + * @throws EE_Error |
|
1341 | + */ |
|
1342 | + public function get_admin_details_link() |
|
1343 | + { |
|
1344 | + return $this->get_admin_edit_link(); |
|
1345 | + } |
|
1346 | + |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * Implementation for EEI_Admin_Links interface method. |
|
1350 | + * |
|
1351 | + * @see EEI_Admin_Links for comments |
|
1352 | + * @return string |
|
1353 | + * @throws EE_Error |
|
1354 | + */ |
|
1355 | + public function get_admin_edit_link() |
|
1356 | + { |
|
1357 | + return EEH_URL::add_query_args_and_nonce( |
|
1358 | + array( |
|
1359 | + 'page' => 'espresso_events', |
|
1360 | + 'action' => 'edit', |
|
1361 | + 'post' => $this->ID(), |
|
1362 | + ), |
|
1363 | + admin_url('admin.php') |
|
1364 | + ); |
|
1365 | + } |
|
1366 | + |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * Implementation for EEI_Admin_Links interface method. |
|
1370 | + * |
|
1371 | + * @see EEI_Admin_Links for comments |
|
1372 | + * @return string |
|
1373 | + */ |
|
1374 | + public function get_admin_settings_link() |
|
1375 | + { |
|
1376 | + return EEH_URL::add_query_args_and_nonce( |
|
1377 | + array( |
|
1378 | + 'page' => 'espresso_events', |
|
1379 | + 'action' => 'default_event_settings', |
|
1380 | + ), |
|
1381 | + admin_url('admin.php') |
|
1382 | + ); |
|
1383 | + } |
|
1384 | + |
|
1385 | + |
|
1386 | + /** |
|
1387 | + * Implementation for EEI_Admin_Links interface method. |
|
1388 | + * |
|
1389 | + * @see EEI_Admin_Links for comments |
|
1390 | + * @return string |
|
1391 | + */ |
|
1392 | + public function get_admin_overview_link() |
|
1393 | + { |
|
1394 | + return EEH_URL::add_query_args_and_nonce( |
|
1395 | + array( |
|
1396 | + 'page' => 'espresso_events', |
|
1397 | + 'action' => 'default', |
|
1398 | + ), |
|
1399 | + admin_url('admin.php') |
|
1400 | + ); |
|
1401 | + } |
|
1402 | 1402 | } |
@@ -27,151 +27,151 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param EE_Registration $target_registration |
|
32 | - * @param EE_Registration $registration_to_copy |
|
33 | - * @return bool |
|
34 | - * @throws UnexpectedEntityException |
|
35 | - * @throws EntityNotFoundException |
|
36 | - * @throws RuntimeException |
|
37 | - * @throws EE_Error |
|
38 | - */ |
|
39 | - public function copyRegistrationDetails( |
|
40 | - EE_Registration $target_registration, |
|
41 | - EE_Registration $registration_to_copy |
|
42 | - ) { |
|
43 | - // copy attendee |
|
44 | - $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
45 | - $target_registration->updateStatusBasedOnTotalPaid(false); |
|
46 | - $target_registration->save(); |
|
47 | - // get answers to previous reg questions |
|
48 | - $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
49 | - // get questions to new event reg form |
|
50 | - $new_event = $target_registration->event(); |
|
51 | - $field_name = 'Event_Question_Group.' |
|
52 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
53 | - $registration_to_copy->is_primary_registrant() |
|
54 | - ); |
|
55 | - $question_groups = $new_event->question_groups([ |
|
56 | - [ |
|
57 | - 'Event.EVT_ID' => $new_event->ID(), |
|
58 | - $field_name => true, |
|
59 | - ], |
|
60 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
61 | - ]); |
|
62 | - foreach ($question_groups as $question_group) { |
|
63 | - if ($question_group instanceof \EE_Question_Group) { |
|
64 | - foreach ($question_group->questions() as $question) { |
|
65 | - if ($question instanceof EE_Question) { |
|
66 | - $this->generateNewAnswer( |
|
67 | - $question, |
|
68 | - $target_registration, |
|
69 | - $answers |
|
70 | - ); |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - return true; |
|
76 | - } |
|
30 | + /** |
|
31 | + * @param EE_Registration $target_registration |
|
32 | + * @param EE_Registration $registration_to_copy |
|
33 | + * @return bool |
|
34 | + * @throws UnexpectedEntityException |
|
35 | + * @throws EntityNotFoundException |
|
36 | + * @throws RuntimeException |
|
37 | + * @throws EE_Error |
|
38 | + */ |
|
39 | + public function copyRegistrationDetails( |
|
40 | + EE_Registration $target_registration, |
|
41 | + EE_Registration $registration_to_copy |
|
42 | + ) { |
|
43 | + // copy attendee |
|
44 | + $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
45 | + $target_registration->updateStatusBasedOnTotalPaid(false); |
|
46 | + $target_registration->save(); |
|
47 | + // get answers to previous reg questions |
|
48 | + $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
49 | + // get questions to new event reg form |
|
50 | + $new_event = $target_registration->event(); |
|
51 | + $field_name = 'Event_Question_Group.' |
|
52 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
53 | + $registration_to_copy->is_primary_registrant() |
|
54 | + ); |
|
55 | + $question_groups = $new_event->question_groups([ |
|
56 | + [ |
|
57 | + 'Event.EVT_ID' => $new_event->ID(), |
|
58 | + $field_name => true, |
|
59 | + ], |
|
60 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
61 | + ]); |
|
62 | + foreach ($question_groups as $question_group) { |
|
63 | + if ($question_group instanceof \EE_Question_Group) { |
|
64 | + foreach ($question_group->questions() as $question) { |
|
65 | + if ($question instanceof EE_Question) { |
|
66 | + $this->generateNewAnswer( |
|
67 | + $question, |
|
68 | + $target_registration, |
|
69 | + $answers |
|
70 | + ); |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + return true; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Answer[] $answers |
|
81 | - * @return array |
|
82 | - * @throws EE_Error |
|
83 | - */ |
|
84 | - protected function reindexAnswersByQuestionId(array $answers) |
|
85 | - { |
|
86 | - $reindexed_answers = array(); |
|
87 | - foreach ($answers as $answer) { |
|
88 | - if ($answer instanceof EE_Answer) { |
|
89 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
90 | - } |
|
91 | - } |
|
92 | - return $reindexed_answers; |
|
93 | - } |
|
79 | + /** |
|
80 | + * @param EE_Answer[] $answers |
|
81 | + * @return array |
|
82 | + * @throws EE_Error |
|
83 | + */ |
|
84 | + protected function reindexAnswersByQuestionId(array $answers) |
|
85 | + { |
|
86 | + $reindexed_answers = array(); |
|
87 | + foreach ($answers as $answer) { |
|
88 | + if ($answer instanceof EE_Answer) { |
|
89 | + $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
90 | + } |
|
91 | + } |
|
92 | + return $reindexed_answers; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * @param EE_Question $question |
|
98 | - * @param EE_Registration $registration |
|
99 | - * @param $previous_answers |
|
100 | - * @return EE_Answer |
|
101 | - * @throws UnexpectedEntityException |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - protected function generateNewAnswer( |
|
105 | - EE_Question $question, |
|
106 | - EE_Registration $registration, |
|
107 | - $previous_answers |
|
108 | - ) { |
|
109 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
110 | - ? $previous_answers[ $question->ID() ] |
|
111 | - : ''; |
|
112 | - $new_answer = EE_Answer::new_instance( |
|
113 | - array( |
|
114 | - 'QST_ID' => $question->ID(), |
|
115 | - 'REG_ID' => $registration->ID(), |
|
116 | - 'ANS_value' => $old_answer_value, |
|
117 | - ) |
|
118 | - ); |
|
119 | - if (! $new_answer instanceof EE_Answer) { |
|
120 | - throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
121 | - } |
|
122 | - $new_answer->save(); |
|
123 | - return $new_answer; |
|
124 | - } |
|
96 | + /** |
|
97 | + * @param EE_Question $question |
|
98 | + * @param EE_Registration $registration |
|
99 | + * @param $previous_answers |
|
100 | + * @return EE_Answer |
|
101 | + * @throws UnexpectedEntityException |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + protected function generateNewAnswer( |
|
105 | + EE_Question $question, |
|
106 | + EE_Registration $registration, |
|
107 | + $previous_answers |
|
108 | + ) { |
|
109 | + $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
110 | + ? $previous_answers[ $question->ID() ] |
|
111 | + : ''; |
|
112 | + $new_answer = EE_Answer::new_instance( |
|
113 | + array( |
|
114 | + 'QST_ID' => $question->ID(), |
|
115 | + 'REG_ID' => $registration->ID(), |
|
116 | + 'ANS_value' => $old_answer_value, |
|
117 | + ) |
|
118 | + ); |
|
119 | + if (! $new_answer instanceof EE_Answer) { |
|
120 | + throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
121 | + } |
|
122 | + $new_answer->save(); |
|
123 | + return $new_answer; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - /** |
|
128 | - * @param EE_Registration $target_registration |
|
129 | - * @param EE_Registration $registration_to_copy |
|
130 | - * @return bool |
|
131 | - * @throws RuntimeException |
|
132 | - * @throws UnexpectedEntityException |
|
133 | - * @throws EE_Error |
|
134 | - */ |
|
135 | - public function copyPaymentDetails( |
|
136 | - EE_Registration $target_registration, |
|
137 | - EE_Registration $registration_to_copy |
|
138 | - ) { |
|
139 | - $save = false; |
|
140 | - $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
141 | - $new_registration_payment_total = 0; |
|
142 | - $registration_to_copy_total = $registration_to_copy->paid(); |
|
143 | - foreach ($previous_registration_payments as $previous_registration_payment) { |
|
144 | - if ($previous_registration_payment instanceof EE_Registration_Payment |
|
145 | - && $previous_registration_payment->payment() instanceof EE_Payment |
|
146 | - && $previous_registration_payment->payment()->is_approved() |
|
147 | - ) { |
|
148 | - $payment_amount = $previous_registration_payment->amount(); |
|
149 | - $new_registration_payment = EE_Registration_Payment::new_instance( |
|
150 | - array( |
|
151 | - 'REG_ID' => $target_registration->ID(), |
|
152 | - 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
153 | - 'RPY_amount' => $payment_amount, |
|
154 | - ) |
|
155 | - ); |
|
156 | - if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
157 | - throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
158 | - } |
|
159 | - $new_registration_payment->save(); |
|
160 | - // if new reg payment is good, then set old reg payment amount to zero |
|
161 | - $previous_registration_payment->set_amount(0); |
|
162 | - $previous_registration_payment->save(); |
|
163 | - // now increment/decrement payment amounts |
|
164 | - $new_registration_payment_total += $payment_amount; |
|
165 | - $registration_to_copy_total -= $payment_amount; |
|
166 | - $save = true; |
|
167 | - } |
|
168 | - } |
|
169 | - if ($save) { |
|
170 | - $target_registration->set_paid($new_registration_payment_total); |
|
171 | - $target_registration->save(); |
|
172 | - $registration_to_copy->set_paid($registration_to_copy_total); |
|
173 | - $registration_to_copy->save(); |
|
174 | - } |
|
175 | - return true; |
|
176 | - } |
|
127 | + /** |
|
128 | + * @param EE_Registration $target_registration |
|
129 | + * @param EE_Registration $registration_to_copy |
|
130 | + * @return bool |
|
131 | + * @throws RuntimeException |
|
132 | + * @throws UnexpectedEntityException |
|
133 | + * @throws EE_Error |
|
134 | + */ |
|
135 | + public function copyPaymentDetails( |
|
136 | + EE_Registration $target_registration, |
|
137 | + EE_Registration $registration_to_copy |
|
138 | + ) { |
|
139 | + $save = false; |
|
140 | + $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
141 | + $new_registration_payment_total = 0; |
|
142 | + $registration_to_copy_total = $registration_to_copy->paid(); |
|
143 | + foreach ($previous_registration_payments as $previous_registration_payment) { |
|
144 | + if ($previous_registration_payment instanceof EE_Registration_Payment |
|
145 | + && $previous_registration_payment->payment() instanceof EE_Payment |
|
146 | + && $previous_registration_payment->payment()->is_approved() |
|
147 | + ) { |
|
148 | + $payment_amount = $previous_registration_payment->amount(); |
|
149 | + $new_registration_payment = EE_Registration_Payment::new_instance( |
|
150 | + array( |
|
151 | + 'REG_ID' => $target_registration->ID(), |
|
152 | + 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
153 | + 'RPY_amount' => $payment_amount, |
|
154 | + ) |
|
155 | + ); |
|
156 | + if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
157 | + throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
158 | + } |
|
159 | + $new_registration_payment->save(); |
|
160 | + // if new reg payment is good, then set old reg payment amount to zero |
|
161 | + $previous_registration_payment->set_amount(0); |
|
162 | + $previous_registration_payment->save(); |
|
163 | + // now increment/decrement payment amounts |
|
164 | + $new_registration_payment_total += $payment_amount; |
|
165 | + $registration_to_copy_total -= $payment_amount; |
|
166 | + $save = true; |
|
167 | + } |
|
168 | + } |
|
169 | + if ($save) { |
|
170 | + $target_registration->set_paid($new_registration_payment_total); |
|
171 | + $target_registration->save(); |
|
172 | + $registration_to_copy->set_paid($registration_to_copy_total); |
|
173 | + $registration_to_copy->save(); |
|
174 | + } |
|
175 | + return true; |
|
176 | + } |
|
177 | 177 | } |