Completed
Branch BUG/fix-table-exists-query (b2f8d0)
by
unknown
08:37 queued 43s
created
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_prices.dmsstage.php 3 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
     /**
350 350
      * Adds a join between a ticket and a price
351 351
      * @global type $wpdb
352
-     * @param type $new_ticket_id
353
-     * @param type $new_price_id
352
+     * @param integer $new_ticket_id
353
+     * @param integer $new_price_id
354 354
      * @return int
355 355
      */
356 356
     private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
@@ -376,8 +376,7 @@  discard block
 block discarded – undo
376 376
     /**
377 377
      * Adds a join between a ticket and a datetime
378 378
      * @global type $wpdb
379
-     * @param type $new_ticket_id
380
-     * @param type $new_price_id
379
+     * @param integer $new_ticket_id
381 380
      * @return int
382 381
      */
383 382
     private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -87,57 +87,57 @@  discard block
 block discarded – undo
87 87
  */
88 88
 class EE_DMS_4_1_0_prices extends EE_Data_Migration_Script_Stage_Table
89 89
 {
90
-    private $_new_price_table;
91
-    private $_new_ticket_table;
92
-    private $_new_ticket_price_table;
93
-    private $_new_datetime_ticket_table;
94
-    /**
95
-     * A count of all the different tickets created, used for setting the new ones' TKT_Order
96
-     * @var int
97
-     */
98
-    private $_ticket_count = 0;
99
-    const price_type_base = 1;
100
-    const price_type_member_discount = 3;
101
-    const price_type_percent_surcharge = 4;
102
-    const price_type_flat_surcharge = 5;
90
+	private $_new_price_table;
91
+	private $_new_ticket_table;
92
+	private $_new_ticket_price_table;
93
+	private $_new_datetime_ticket_table;
94
+	/**
95
+	 * A count of all the different tickets created, used for setting the new ones' TKT_Order
96
+	 * @var int
97
+	 */
98
+	private $_ticket_count = 0;
99
+	const price_type_base = 1;
100
+	const price_type_member_discount = 3;
101
+	const price_type_percent_surcharge = 4;
102
+	const price_type_flat_surcharge = 5;
103 103
 
104
-    public function __construct()
105
-    {
106
-        global $wpdb;
107
-        $this->_pretty_name = __("Prices", "event_espresso");
108
-        $this->_old_table = $wpdb->prefix."events_prices";
109
-        $this->select_expression = 'p.*, e.event_status';
110
-        $this->_extra_where_sql = ' AS p 
104
+	public function __construct()
105
+	{
106
+		global $wpdb;
107
+		$this->_pretty_name = __("Prices", "event_espresso");
108
+		$this->_old_table = $wpdb->prefix."events_prices";
109
+		$this->select_expression = 'p.*, e.event_status';
110
+		$this->_extra_where_sql = ' AS p 
111 111
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id
112 112
             WHERE e.event_status!="D"';
113
-        $this->_new_price_table = $wpdb->prefix."esp_price";
114
-        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
115
-        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
116
-        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
117
-        parent::__construct();
118
-    }
119
-    protected function _migrate_old_row($old_row)
120
-    {
121
-        // create the base price
122
-        $new_price_id = $this->_insert_new_price($old_row);
123
-        // create the member discount if there is any
124
-        // commented-out because we may actually NOT be supporting this in 4.1
113
+		$this->_new_price_table = $wpdb->prefix."esp_price";
114
+		$this->_new_ticket_table = $wpdb->prefix."esp_ticket";
115
+		$this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
116
+		$this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
117
+		parent::__construct();
118
+	}
119
+	protected function _migrate_old_row($old_row)
120
+	{
121
+		// create the base price
122
+		$new_price_id = $this->_insert_new_price($old_row);
123
+		// create the member discount if there is any
124
+		// commented-out because we may actually NOT be supporting this in 4.1
125 125
 //      if($old_row['event_cost'] != $old_row['member_price']){
126 126
 //          $member_price_discount_id = $this->_insert_new_member_price($old_row);
127 127
 //      }else{
128 128
 //          $member_price_discount_id = 0;
129 129
 //      }
130
-        // create the surcharge if there is any
131
-        if (floatval($old_row['surcharge']) >= 0.01) {
132
-            $surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
134
-        } else {
135
-            $surcharge_price_id = 0;
136
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
137
-        }
138
-        // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice.
139
-        // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one)
140
-        // create ticket
130
+		// create the surcharge if there is any
131
+		if (floatval($old_row['surcharge']) >= 0.01) {
132
+			$surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
134
+		} else {
135
+			$surcharge_price_id = 0;
136
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
137
+		}
138
+		// associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice.
139
+		// if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one)
140
+		// create ticket
141 141
 //      $ticket_id = $this->_insert_new_ticket($old_row);
142 142
 //      if($ticket_id){
143 143
 //          $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id);
@@ -149,62 +149,62 @@  discard block
 block discarded – undo
149 149
 //              $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
150 150
 //          }
151 151
 //      }
152
-        // create a ticket for each old price -old datetime combo
153
-        $tickets_for_old_price = array();
154
-        foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) {
155
-            $ticket_id = $this->_insert_new_ticket($old_row);
156
-            $tickets_for_old_price[] = $ticket_id;
157
-            // associate to old prices
158
-            $this->_insert_ticket_price_relation($ticket_id, $new_price_id);
159
-            $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id);
160
-            $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
161
-        }
162
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price);
163
-    }
164
-    /**
165
-     * Creates a 4.1 price base type
166
-     * @global type $wpdb
167
-     * @param type $old_price
168
-     * @return int
169
-     */
170
-    private function _insert_new_price($old_price)
171
-    {
172
-        global $wpdb;
173
-        $cols_n_values = array(
174
-            'PRT_ID'=>self::price_type_base,
175
-            'PRC_amount'=>floatval($old_price['event_cost']),
176
-            'PRC_name'=>$old_price['price_type'],
177
-            'PRC_is_default'=>false,
178
-            'PRC_overrides'=>false,
179
-            'PRC_order'=>0,
180
-            'PRC_deleted'=>false,
181
-            'PRC_parent'=>null
152
+		// create a ticket for each old price -old datetime combo
153
+		$tickets_for_old_price = array();
154
+		foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) {
155
+			$ticket_id = $this->_insert_new_ticket($old_row);
156
+			$tickets_for_old_price[] = $ticket_id;
157
+			// associate to old prices
158
+			$this->_insert_ticket_price_relation($ticket_id, $new_price_id);
159
+			$this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id);
160
+			$this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
161
+		}
162
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price);
163
+	}
164
+	/**
165
+	 * Creates a 4.1 price base type
166
+	 * @global type $wpdb
167
+	 * @param type $old_price
168
+	 * @return int
169
+	 */
170
+	private function _insert_new_price($old_price)
171
+	{
172
+		global $wpdb;
173
+		$cols_n_values = array(
174
+			'PRT_ID'=>self::price_type_base,
175
+			'PRC_amount'=>floatval($old_price['event_cost']),
176
+			'PRC_name'=>$old_price['price_type'],
177
+			'PRC_is_default'=>false,
178
+			'PRC_overrides'=>false,
179
+			'PRC_order'=>0,
180
+			'PRC_deleted'=>false,
181
+			'PRC_parent'=>null
182 182
 
183
-        );
184
-        $datatypes = array(
185
-            '%d',// PRT_ID
186
-            '%f',// PRT_amount
187
-            '%s',// PRC_name
188
-            '%d',// PRC_is_default
189
-            '%d',// PRC_overrides
190
-            '%d',// PRC_order
191
-            '%d',// PRC_deleted
192
-            '%d',// PRC_parent
193
-        );
194
-        $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
-        if (! $success) {
196
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197
-            return 0;
198
-        }
199
-        $new_id = $wpdb->insert_id;
200
-        return $new_id;
201
-    }
202
-    /**
203
-     * Creates a 4.1 member price discount
204
-     * @global type $wpdb
205
-     * @param type $old_price
206
-     * @return int
207
-     */
183
+		);
184
+		$datatypes = array(
185
+			'%d',// PRT_ID
186
+			'%f',// PRT_amount
187
+			'%s',// PRC_name
188
+			'%d',// PRC_is_default
189
+			'%d',// PRC_overrides
190
+			'%d',// PRC_order
191
+			'%d',// PRC_deleted
192
+			'%d',// PRC_parent
193
+		);
194
+		$success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
+		if (! $success) {
196
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197
+			return 0;
198
+		}
199
+		$new_id = $wpdb->insert_id;
200
+		return $new_id;
201
+	}
202
+	/**
203
+	 * Creates a 4.1 member price discount
204
+	 * @global type $wpdb
205
+	 * @param type $old_price
206
+	 * @return int
207
+	 */
208 208
 //  private function _insert_new_member_price($old_price){
209 209
 //      $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']);
210 210
 //      global $wpdb;
@@ -237,207 +237,207 @@  discard block
 block discarded – undo
237 237
 //      $new_id = $wpdb->insert_id;
238 238
 //      return $new_id;
239 239
 //  }
240
-    /**
241
-     * Creates a 4.1 member price discount
242
-     * @global type $wpdb
243
-     * @param type $old_price
244
-     * @return int
245
-     */
246
-    private function _insert_new_surcharge_price($old_price)
247
-    {
240
+	/**
241
+	 * Creates a 4.1 member price discount
242
+	 * @global type $wpdb
243
+	 * @param type $old_price
244
+	 * @return int
245
+	 */
246
+	private function _insert_new_surcharge_price($old_price)
247
+	{
248 248
 
249
-        if ($old_price['surcharge_type'] == 'flat_rate') {
250
-            $price_type = self::price_type_flat_surcharge;
251
-        } else {
252
-            $price_type = self::price_type_percent_surcharge;
253
-        }
254
-        global $wpdb;
255
-        $cols_n_values = array(
256
-            'PRT_ID'=>$price_type,
257
-            'PRC_amount'=>floatval($old_price['surcharge']),
258
-            'PRC_name'=>  __("Surcharge", "event_espresso"),
259
-            'PRC_is_default'=>false,
260
-            'PRC_overrides'=>false,
261
-            'PRC_order'=>20,
262
-            'PRC_deleted'=>false,
263
-            'PRC_parent'=>null
249
+		if ($old_price['surcharge_type'] == 'flat_rate') {
250
+			$price_type = self::price_type_flat_surcharge;
251
+		} else {
252
+			$price_type = self::price_type_percent_surcharge;
253
+		}
254
+		global $wpdb;
255
+		$cols_n_values = array(
256
+			'PRT_ID'=>$price_type,
257
+			'PRC_amount'=>floatval($old_price['surcharge']),
258
+			'PRC_name'=>  __("Surcharge", "event_espresso"),
259
+			'PRC_is_default'=>false,
260
+			'PRC_overrides'=>false,
261
+			'PRC_order'=>20,
262
+			'PRC_deleted'=>false,
263
+			'PRC_parent'=>null
264 264
 
265
-        );
266
-        $datatypes = array(
267
-            '%d',// PRT_ID
268
-            '%f',// PRT_amount
269
-            '%s',// PRC_name
270
-            '%d',// PRC_is_default
271
-            '%d',// PRC_overrides
272
-            '%d',// PRC_order
273
-            '%d',// PRC_deleted
274
-            '%d',// PRC_parent
275
-        );
276
-        $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
-        if (! $success) {
278
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279
-            return 0;
280
-        }
281
-        $new_id = $wpdb->insert_id;
282
-        return $new_id;
283
-    }
284
-    /**
285
-     * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price
286
-     * @param $old_price_row array where keys are columns
287
-     * @param $new_base_price_id int
288
-     * @param $new_member_discount_id int
289
-     * @param $new_surcharge_id int
290
-     * @return int new ticket id
291
-     */
292
-    private function _insert_new_ticket($old_price_row)
293
-    {
294
-        global $wpdb;
295
-        $event_row = $this->_get_event_row($old_price_row['event_id']);
296
-        if ($old_price_row['surcharge_type'] == 'flat_rate') {
297
-            $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298
-        } else {// percent surcharge
299
-            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
300
-        }
301
-        $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302
-        $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
303
-        $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304
-        $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305
-        $cols_n_values = array(
306
-            'TTM_ID'=>0,
307
-            'TKT_name'=>$old_price_row['price_type'],
308
-            'TKT_description'=>'',
309
-            'TKT_start_date'=>$start_date_utc,
310
-            'TKT_end_date'=>$end_date_utc,
311
-            'TKT_min'=>0,
312
-            'TKT_max'=>-1,
313
-            'TKT_price'=>$final_ticket_price,
314
-            'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
315
-            'TKT_qty'=> -1,
316
-            'TKT_uses'=> 1,
317
-            'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318
-            'TKT_is_default'=>false,
319
-            'TKT_order'=>$this->_get_ticket_count(),
320
-            'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
321
-            'TKT_deleted'=>false,
322
-            'TKT_parent'=>0
265
+		);
266
+		$datatypes = array(
267
+			'%d',// PRT_ID
268
+			'%f',// PRT_amount
269
+			'%s',// PRC_name
270
+			'%d',// PRC_is_default
271
+			'%d',// PRC_overrides
272
+			'%d',// PRC_order
273
+			'%d',// PRC_deleted
274
+			'%d',// PRC_parent
275
+		);
276
+		$success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
+		if (! $success) {
278
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279
+			return 0;
280
+		}
281
+		$new_id = $wpdb->insert_id;
282
+		return $new_id;
283
+	}
284
+	/**
285
+	 * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price
286
+	 * @param $old_price_row array where keys are columns
287
+	 * @param $new_base_price_id int
288
+	 * @param $new_member_discount_id int
289
+	 * @param $new_surcharge_id int
290
+	 * @return int new ticket id
291
+	 */
292
+	private function _insert_new_ticket($old_price_row)
293
+	{
294
+		global $wpdb;
295
+		$event_row = $this->_get_event_row($old_price_row['event_id']);
296
+		if ($old_price_row['surcharge_type'] == 'flat_rate') {
297
+			$final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298
+		} else {// percent surcharge
299
+			$final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
300
+		}
301
+		$start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302
+		$start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
303
+		$end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304
+		$end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305
+		$cols_n_values = array(
306
+			'TTM_ID'=>0,
307
+			'TKT_name'=>$old_price_row['price_type'],
308
+			'TKT_description'=>'',
309
+			'TKT_start_date'=>$start_date_utc,
310
+			'TKT_end_date'=>$end_date_utc,
311
+			'TKT_min'=>0,
312
+			'TKT_max'=>-1,
313
+			'TKT_price'=>$final_ticket_price,
314
+			'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
315
+			'TKT_qty'=> -1,
316
+			'TKT_uses'=> 1,
317
+			'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318
+			'TKT_is_default'=>false,
319
+			'TKT_order'=>$this->_get_ticket_count(),
320
+			'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
321
+			'TKT_deleted'=>false,
322
+			'TKT_parent'=>0
323 323
 
324
-        );
325
-        $datatypes = array(
326
-            '%d',// TTM_ID
327
-            '%s',// TKT_name
328
-            '%s',// TKT_description
329
-            '%s',// TKT_start_date
330
-            '%s',// TKT_end_date
331
-            '%d',// TKT_min
332
-            '%d',// TKT_max
333
-            '%f',// TKT_price
334
-            '%d',// TKT_sold
335
-            '%d',// TKT_qty
336
-            '%d',// TKT_uses
337
-            '%d',// TKT_taxable
338
-            '%d',// TKT_is_default
339
-            '%d',// TKT_order
340
-            '%d',// TKT_row
341
-            '%d',// TKT_deleted
342
-            '%d',// TKT_parent
343
-        );
344
-        $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
-        if (! $success) {
346
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347
-            return 0;
348
-        }
349
-        $new_id = $wpdb->insert_id;
350
-        return $new_id;
351
-    }
324
+		);
325
+		$datatypes = array(
326
+			'%d',// TTM_ID
327
+			'%s',// TKT_name
328
+			'%s',// TKT_description
329
+			'%s',// TKT_start_date
330
+			'%s',// TKT_end_date
331
+			'%d',// TKT_min
332
+			'%d',// TKT_max
333
+			'%f',// TKT_price
334
+			'%d',// TKT_sold
335
+			'%d',// TKT_qty
336
+			'%d',// TKT_uses
337
+			'%d',// TKT_taxable
338
+			'%d',// TKT_is_default
339
+			'%d',// TKT_order
340
+			'%d',// TKT_row
341
+			'%d',// TKT_deleted
342
+			'%d',// TKT_parent
343
+		);
344
+		$success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
+		if (! $success) {
346
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347
+			return 0;
348
+		}
349
+		$new_id = $wpdb->insert_id;
350
+		return $new_id;
351
+	}
352 352
 
353
-    /**
354
-     * Adds a join between a ticket and a price
355
-     * @global type $wpdb
356
-     * @param type $new_ticket_id
357
-     * @param type $new_price_id
358
-     * @return int
359
-     */
360
-    private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
361
-    {
362
-        global $wpdb;
363
-        $cols_n_values = array(
364
-            'TKT_ID'=>$new_ticket_id,
365
-            'PRC_ID'=>$new_price_id,
366
-        );
367
-        $datatypes = array(
368
-            '%d',// TKT_ID
369
-            '%d',// PRC_ID
370
-        );
371
-        $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
-        if (! $success) {
373
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374
-            return 0;
375
-        }
376
-        $new_id = $wpdb->insert_id;
377
-        return $new_id;
378
-    }
353
+	/**
354
+	 * Adds a join between a ticket and a price
355
+	 * @global type $wpdb
356
+	 * @param type $new_ticket_id
357
+	 * @param type $new_price_id
358
+	 * @return int
359
+	 */
360
+	private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
361
+	{
362
+		global $wpdb;
363
+		$cols_n_values = array(
364
+			'TKT_ID'=>$new_ticket_id,
365
+			'PRC_ID'=>$new_price_id,
366
+		);
367
+		$datatypes = array(
368
+			'%d',// TKT_ID
369
+			'%d',// PRC_ID
370
+		);
371
+		$success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
+		if (! $success) {
373
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374
+			return 0;
375
+		}
376
+		$new_id = $wpdb->insert_id;
377
+		return $new_id;
378
+	}
379 379
 
380
-    /**
381
-     * Adds a join between a ticket and a datetime
382
-     * @global type $wpdb
383
-     * @param type $new_ticket_id
384
-     * @param type $new_price_id
385
-     * @return int
386
-     */
387
-    private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
388
-    {
389
-        global $wpdb;
390
-        $cols_n_values = array(
391
-            'TKT_ID'=>$new_ticket_id,
392
-            'DTT_ID'=>$new_datetime_id,
393
-        );
394
-        $datatypes = array(
395
-            '%d',// TKT_ID
396
-            '%d',// DTT_ID
397
-        );
398
-        $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
-        if (! $success) {
400
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401
-            return 0;
402
-        }
403
-        $new_id = $wpdb->insert_id;
404
-        return $new_id;
405
-    }
380
+	/**
381
+	 * Adds a join between a ticket and a datetime
382
+	 * @global type $wpdb
383
+	 * @param type $new_ticket_id
384
+	 * @param type $new_price_id
385
+	 * @return int
386
+	 */
387
+	private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
388
+	{
389
+		global $wpdb;
390
+		$cols_n_values = array(
391
+			'TKT_ID'=>$new_ticket_id,
392
+			'DTT_ID'=>$new_datetime_id,
393
+		);
394
+		$datatypes = array(
395
+			'%d',// TKT_ID
396
+			'%d',// DTT_ID
397
+		);
398
+		$success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
+		if (! $success) {
400
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401
+			return 0;
402
+		}
403
+		$new_id = $wpdb->insert_id;
404
+		return $new_id;
405
+	}
406 406
 
407
-    /**
408
-     * Simply gets the 3.1 event row data
409
-     * @global type $wpdb
410
-     * @param type $event_id
411
-     * @return array
412
-     */
413
-    private function _get_event_row($event_id)
414
-    {
415
-        global $wpdb;
416
-        $old_event_table = $wpdb->prefix."events_detail";
417
-        return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418
-    }
419
-    /**
420
-     * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests).
421
-     * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too
422
-     * @return int
423
-     */
424
-    private function _get_ticket_count()
425
-    {
426
-        return $this->_ticket_count++;
427
-    }
407
+	/**
408
+	 * Simply gets the 3.1 event row data
409
+	 * @global type $wpdb
410
+	 * @param type $event_id
411
+	 * @return array
412
+	 */
413
+	private function _get_event_row($event_id)
414
+	{
415
+		global $wpdb;
416
+		$old_event_table = $wpdb->prefix."events_detail";
417
+		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418
+	}
419
+	/**
420
+	 * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests).
421
+	 * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too
422
+	 * @return int
423
+	 */
424
+	private function _get_ticket_count()
425
+	{
426
+		return $this->_ticket_count++;
427
+	}
428 428
 
429
-    /**
430
-     * Using the 3.1 event id, gets the 4.1 datetimes for it
431
-     * @param int $old_event_id
432
-     * @return array where values are datetime ids
433
-     */
434
-    private function _get_datetime_ids_for_old_event_id($old_event_id)
435
-    {
436
-        global $wpdb;
437
-        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438
-        $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439
-        return $datetime_ids;
440
-    }
429
+	/**
430
+	 * Using the 3.1 event id, gets the 4.1 datetimes for it
431
+	 * @param int $old_event_id
432
+	 * @return array where values are datetime ids
433
+	 */
434
+	private function _get_datetime_ids_for_old_event_id($old_event_id)
435
+	{
436
+		global $wpdb;
437
+		$new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438
+		$datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439
+		return $datetime_ids;
440
+	}
441 441
 }
442 442
 // @todo: tell users that in 3.1 the limit was on registration PER event,in 4.1 it's limit PER TICKET... SO, if they sell 2 different types of tickets
443 443
 //
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         $this->_old_table = $wpdb->prefix."events_prices";
109 109
         $this->select_expression = 'p.*, e.event_status';
110 110
         $this->_extra_where_sql = ' AS p 
111
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id
111
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id
112 112
             WHERE e.event_status!="D"';
113 113
         $this->_new_price_table = $wpdb->prefix."esp_price";
114 114
         $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         // create the surcharge if there is any
131 131
         if (floatval($old_row['surcharge']) >= 0.01) {
132 132
             $surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
133
+            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id));
134 134
         } else {
135 135
             $surcharge_price_id = 0;
136 136
             $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 
183 183
         );
184 184
         $datatypes = array(
185
-            '%d',// PRT_ID
186
-            '%f',// PRT_amount
187
-            '%s',// PRC_name
188
-            '%d',// PRC_is_default
189
-            '%d',// PRC_overrides
190
-            '%d',// PRC_order
191
-            '%d',// PRC_deleted
192
-            '%d',// PRC_parent
185
+            '%d', // PRT_ID
186
+            '%f', // PRT_amount
187
+            '%s', // PRC_name
188
+            '%d', // PRC_is_default
189
+            '%d', // PRC_overrides
190
+            '%d', // PRC_order
191
+            '%d', // PRC_deleted
192
+            '%d', // PRC_parent
193 193
         );
194 194
         $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
-        if (! $success) {
195
+        if ( ! $success) {
196 196
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197 197
             return 0;
198 198
         }
@@ -264,17 +264,17 @@  discard block
 block discarded – undo
264 264
 
265 265
         );
266 266
         $datatypes = array(
267
-            '%d',// PRT_ID
268
-            '%f',// PRT_amount
269
-            '%s',// PRC_name
270
-            '%d',// PRC_is_default
271
-            '%d',// PRC_overrides
272
-            '%d',// PRC_order
273
-            '%d',// PRC_deleted
274
-            '%d',// PRC_parent
267
+            '%d', // PRT_ID
268
+            '%f', // PRT_amount
269
+            '%s', // PRC_name
270
+            '%d', // PRC_is_default
271
+            '%d', // PRC_overrides
272
+            '%d', // PRC_order
273
+            '%d', // PRC_deleted
274
+            '%d', // PRC_parent
275 275
         );
276 276
         $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
-        if (! $success) {
277
+        if ( ! $success) {
278 278
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279 279
             return 0;
280 280
         }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
         if ($old_price_row['surcharge_type'] == 'flat_rate') {
297 297
             $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298 298
         } else {// percent surcharge
299
-            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
299
+            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100);
300 300
         }
301 301
         $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302 302
         $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
@@ -311,38 +311,38 @@  discard block
 block discarded – undo
311 311
             'TKT_min'=>0,
312 312
             'TKT_max'=>-1,
313 313
             'TKT_price'=>$final_ticket_price,
314
-            'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
314
+            'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration
315 315
             'TKT_qty'=> -1,
316 316
             'TKT_uses'=> 1,
317
-            'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
317
+            'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318 318
             'TKT_is_default'=>false,
319 319
             'TKT_order'=>$this->_get_ticket_count(),
320
-            'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
320
+            'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways
321 321
             'TKT_deleted'=>false,
322 322
             'TKT_parent'=>0
323 323
 
324 324
         );
325 325
         $datatypes = array(
326
-            '%d',// TTM_ID
327
-            '%s',// TKT_name
328
-            '%s',// TKT_description
329
-            '%s',// TKT_start_date
330
-            '%s',// TKT_end_date
331
-            '%d',// TKT_min
332
-            '%d',// TKT_max
333
-            '%f',// TKT_price
334
-            '%d',// TKT_sold
335
-            '%d',// TKT_qty
336
-            '%d',// TKT_uses
337
-            '%d',// TKT_taxable
338
-            '%d',// TKT_is_default
339
-            '%d',// TKT_order
340
-            '%d',// TKT_row
341
-            '%d',// TKT_deleted
342
-            '%d',// TKT_parent
326
+            '%d', // TTM_ID
327
+            '%s', // TKT_name
328
+            '%s', // TKT_description
329
+            '%s', // TKT_start_date
330
+            '%s', // TKT_end_date
331
+            '%d', // TKT_min
332
+            '%d', // TKT_max
333
+            '%f', // TKT_price
334
+            '%d', // TKT_sold
335
+            '%d', // TKT_qty
336
+            '%d', // TKT_uses
337
+            '%d', // TKT_taxable
338
+            '%d', // TKT_is_default
339
+            '%d', // TKT_order
340
+            '%d', // TKT_row
341
+            '%d', // TKT_deleted
342
+            '%d', // TKT_parent
343 343
         );
344 344
         $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
-        if (! $success) {
345
+        if ( ! $success) {
346 346
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347 347
             return 0;
348 348
         }
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
             'PRC_ID'=>$new_price_id,
366 366
         );
367 367
         $datatypes = array(
368
-            '%d',// TKT_ID
369
-            '%d',// PRC_ID
368
+            '%d', // TKT_ID
369
+            '%d', // PRC_ID
370 370
         );
371 371
         $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
-        if (! $success) {
373
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
372
+        if ( ! $success) {
373
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374 374
             return 0;
375 375
         }
376 376
         $new_id = $wpdb->insert_id;
@@ -392,12 +392,12 @@  discard block
 block discarded – undo
392 392
             'DTT_ID'=>$new_datetime_id,
393 393
         );
394 394
         $datatypes = array(
395
-            '%d',// TKT_ID
396
-            '%d',// DTT_ID
395
+            '%d', // TKT_ID
396
+            '%d', // DTT_ID
397 397
         );
398 398
         $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
-        if (! $success) {
400
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
399
+        if ( ! $success) {
400
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401 401
             return 0;
402 402
         }
403 403
         $new_id = $wpdb->insert_id;
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_question_group_question.dmsstage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@
 block discarded – undo
130 130
      * being address info, and 0 being neither)
131 131
      * @global type $wpdb
132 132
      * @param type $new_question_group_id
133
-     * @return boolean
133
+     * @return integer
134 134
      */
135 135
     private function _is_system_question_group($new_question_group_id)
136 136
     {
Please login to merge, or discard this patch.
Indentation   +105 added lines, -107 removed lines patch added patch discarded remove patch
@@ -12,8 +12,6 @@  discard block
 block discarded – undo
12 12
   KEY `group_id` (`group_id`),
13 13
   KEY `question_id` (`question_id`)
14 14
 ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8$$
15
-
16
-
17 15
  * 4.1 question group question model's tables and fields:
18 16
  $this->_tables = array(
19 17
             'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question','QGQ_ID')
@@ -29,113 +27,113 @@  discard block
 block discarded – undo
29 27
  */
30 28
 class EE_DMS_4_1_0_question_group_question extends EE_Data_Migration_Script_Stage
31 29
 {
32
-    private $_old_table;
33
-    private $_new_table;
34
-    public function _migration_step($num_items = 50)
35
-    {
30
+	private $_old_table;
31
+	private $_new_table;
32
+	public function _migration_step($num_items = 50)
33
+	{
36 34
         
37
-        global $wpdb;
38
-        $start_at_record = $this->count_records_migrated();
39
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
40
-        $items_actually_migrated = 0;
41
-        foreach ($rows as $question_group_question) {
42
-            $this->_insert_new_question_group_question($question_group_question);
43
-            $items_actually_migrated++;
44
-        }
45
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
46
-            $this->set_completed();
47
-        }
48
-        return $items_actually_migrated;
49
-    }
50
-    public function _count_records_to_migrate()
51
-    {
52
-        global $wpdb;
53
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
54
-        return $count;
55
-    }
56
-    public function __construct()
57
-    {
58
-        global $wpdb;
59
-        $this->_old_table = $wpdb->prefix."events_qst_group_rel";
60
-        $this->_new_table = $wpdb->prefix."esp_question_group_question";
61
-        $this->_pretty_name = __("Question Group to Question Relations", "event_espresso");
62
-        parent::__construct();
63
-    }
35
+		global $wpdb;
36
+		$start_at_record = $this->count_records_migrated();
37
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
+		$items_actually_migrated = 0;
39
+		foreach ($rows as $question_group_question) {
40
+			$this->_insert_new_question_group_question($question_group_question);
41
+			$items_actually_migrated++;
42
+		}
43
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
44
+			$this->set_completed();
45
+		}
46
+		return $items_actually_migrated;
47
+	}
48
+	public function _count_records_to_migrate()
49
+	{
50
+		global $wpdb;
51
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
52
+		return $count;
53
+	}
54
+	public function __construct()
55
+	{
56
+		global $wpdb;
57
+		$this->_old_table = $wpdb->prefix."events_qst_group_rel";
58
+		$this->_new_table = $wpdb->prefix."esp_question_group_question";
59
+		$this->_pretty_name = __("Question Group to Question Relations", "event_espresso");
60
+		parent::__construct();
61
+	}
64 62
     
65
-    /**
66
-     * Attempts to insert a new question group inthe new format given an old one
67
-     * @global type $wpdb
68
-     * @param array $old_question_group_question
69
-     * @return int
70
-     */
71
-    private function _insert_new_question_group_question($old_question_group_question)
72
-    {
73
-        global $wpdb;
74
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question");
75
-        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group");
76
-        if (! $new_question_id) {
77
-            $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
78
-            return 0;
79
-        }
80
-        if (! $new_question_group_id) {
81
-            $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
82
-            return 0;
83
-        }
84
-        // if it's a system question, it needs to be in the right system group. otherwise no dice!
85
-        if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
86
-                ||
87
-                ! $this->_is_system_question_for_question_group($new_question_id)
88
-            ) {
89
-            $cols_n_values = array(
90
-                'QSG_ID'=>$new_question_group_id,
91
-                'QST_ID'=>$new_question_id
92
-            );
93
-            $datatypes = array(
94
-                '%d',// QSG_ID
95
-                '%d',// QST_ID
96
-            );
97
-            $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
98
-            if (! $success) {
99
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
100
-                return 0;
101
-            }
102
-            return $wpdb->insert_id;
103
-        } else {
104
-            return false;
105
-        }
106
-    }
63
+	/**
64
+	 * Attempts to insert a new question group inthe new format given an old one
65
+	 * @global type $wpdb
66
+	 * @param array $old_question_group_question
67
+	 * @return int
68
+	 */
69
+	private function _insert_new_question_group_question($old_question_group_question)
70
+	{
71
+		global $wpdb;
72
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question");
73
+		$new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group");
74
+		if (! $new_question_id) {
75
+			$this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
76
+			return 0;
77
+		}
78
+		if (! $new_question_group_id) {
79
+			$this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
80
+			return 0;
81
+		}
82
+		// if it's a system question, it needs to be in the right system group. otherwise no dice!
83
+		if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
84
+				||
85
+				! $this->_is_system_question_for_question_group($new_question_id)
86
+			) {
87
+			$cols_n_values = array(
88
+				'QSG_ID'=>$new_question_group_id,
89
+				'QST_ID'=>$new_question_id
90
+			);
91
+			$datatypes = array(
92
+				'%d',// QSG_ID
93
+				'%d',// QST_ID
94
+			);
95
+			$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
96
+			if (! $success) {
97
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
98
+				return 0;
99
+			}
100
+			return $wpdb->insert_id;
101
+		} else {
102
+			return false;
103
+		}
104
+	}
107 105
     
108
-    /**
109
-     * If this question is a system question, returns the QSG_system number that
110
-     * indicates the question group its permitted in.
111
-     * @global type $wpdb
112
-     * @param type $new_question_id
113
-     * @return int
114
-     */
115
-    private function _is_system_question_for_question_group($new_question_id)
116
-    {
117
-        global $wpdb;
118
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id));
119
-        if (in_array($system_id, array('fname','lname','email'))) {
120
-            return 1;
121
-        } elseif ($system_id!='' && $system_id) {
122
-            return 2;
123
-        } else {
124
-            return 0;
125
-        }
126
-    }
106
+	/**
107
+	 * If this question is a system question, returns the QSG_system number that
108
+	 * indicates the question group its permitted in.
109
+	 * @global type $wpdb
110
+	 * @param type $new_question_id
111
+	 * @return int
112
+	 */
113
+	private function _is_system_question_for_question_group($new_question_id)
114
+	{
115
+		global $wpdb;
116
+		$system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id));
117
+		if (in_array($system_id, array('fname','lname','email'))) {
118
+			return 1;
119
+		} elseif ($system_id!='' && $system_id) {
120
+			return 2;
121
+		} else {
122
+			return 0;
123
+		}
124
+	}
127 125
     
128
-    /**
129
-     * Returns the questino group's QSG_system value (1 meaning personal info, 2
130
-     * being address info, and 0 being neither)
131
-     * @global type $wpdb
132
-     * @param type $new_question_group_id
133
-     * @return boolean
134
-     */
135
-    private function _is_system_question_group($new_question_group_id)
136
-    {
137
-        global $wpdb;
138
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
139
-        return intval($system_id);
140
-    }
126
+	/**
127
+	 * Returns the questino group's QSG_system value (1 meaning personal info, 2
128
+	 * being address info, and 0 being neither)
129
+	 * @global type $wpdb
130
+	 * @param type $new_question_group_id
131
+	 * @return boolean
132
+	 */
133
+	private function _is_system_question_group($new_question_group_id)
134
+	{
135
+		global $wpdb;
136
+		$system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
137
+		return intval($system_id);
138
+	}
141 139
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
         global $wpdb;
74 74
         $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question");
75 75
         $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group");
76
-        if (! $new_question_id) {
76
+        if ( ! $new_question_id) {
77 77
             $this->add_error(sprintf(__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
78 78
             return 0;
79 79
         }
80
-        if (! $new_question_group_id) {
80
+        if ( ! $new_question_group_id) {
81 81
             $this->add_error(sprintf(__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
82 82
             return 0;
83 83
         }
84 84
         // if it's a system question, it needs to be in the right system group. otherwise no dice!
85
-        if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
85
+        if (($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id))
86 86
                 ||
87 87
                 ! $this->_is_system_question_for_question_group($new_question_id)
88 88
             ) {
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 'QST_ID'=>$new_question_id
92 92
             );
93 93
             $datatypes = array(
94
-                '%d',// QSG_ID
95
-                '%d',// QST_ID
94
+                '%d', // QSG_ID
95
+                '%d', // QST_ID
96 96
             );
97 97
             $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
98
-            if (! $success) {
98
+            if ( ! $success) {
99 99
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
100 100
                 return 0;
101 101
             }
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
     {
117 117
         global $wpdb;
118 118
         $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id));
119
-        if (in_array($system_id, array('fname','lname','email'))) {
119
+        if (in_array($system_id, array('fname', 'lname', 'email'))) {
120 120
             return 1;
121
-        } elseif ($system_id!='' && $system_id) {
121
+        } elseif ($system_id != '' && $system_id) {
122 122
             return 2;
123 123
         } else {
124 124
             return 0;
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_venues.dmsstage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -205,7 +205,7 @@
 block discarded – undo
205 205
 
206 206
     /**
207 207
      * Inserts into the venue_meta table
208
-     * @param type $cpt_id
208
+     * @param integer $cpt_id
209 209
      * @param type $old_venue
210 210
      * @return int
211 211
      */
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -63,210 +63,210 @@
 block discarded – undo
63 63
  */
64 64
 class EE_DMS_4_1_0_venues extends EE_Data_Migration_Script_Stage
65 65
 {
66
-    private $_old_table;
67
-    private $_new_table;
68
-    private $_new_meta_table;
69
-    public function _migration_step($num_items = 50)
70
-    {
71
-        global $wpdb;
72
-        $start_at_record = $this->count_records_migrated();
73
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74
-        $items_actually_migrated = 0;
75
-        foreach ($rows as $old_venue) {
76
-            if (! $new_id = $this->_insert_into_posts($old_venue)) {
77
-                $items_actually_migrated++;
78
-                continue;
79
-            }
80
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
-            if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82
-                $items_actually_migrated++;
83
-                continue;
84
-            }
85
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id);
86
-            // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it
87
-            $venue_meta = maybe_unserialize($old_venue['meta']);
88
-            if (isset($venue_meta['contact']) && $venue_meta['contact']) {
89
-                add_post_meta($new_id, 'contact', $venue_meta['contact']);
90
-            }
91
-            // is there an image on this venue?
92
-            $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null;
93
-            if ($guid) {
94
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
95
-            }
96
-            $items_actually_migrated++;
97
-            if ($guid) {
98
-                // if there was an image, we may have had to download it etc and it may have taken
99
-                // longer, then let's not bother migrating anymore on this step
100
-                break;
101
-            }
102
-        }
103
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
104
-            $this->set_completed();
105
-        }
106
-        return $items_actually_migrated;
107
-    }
108
-    public function _count_records_to_migrate()
109
-    {
110
-        global $wpdb;
111
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
112
-        return $count;
113
-    }
114
-    public function __construct()
115
-    {
116
-        $this->_pretty_name = __("Venues", "event_espresso");
117
-        global $wpdb;
118
-        $this->_old_table = $wpdb->prefix."events_venue";
119
-        $this->_new_table = $wpdb->posts;
120
-        $this->_new_meta_table = $wpdb->prefix."esp_venue_meta";
121
-        parent::__construct();
122
-    }
66
+	private $_old_table;
67
+	private $_new_table;
68
+	private $_new_meta_table;
69
+	public function _migration_step($num_items = 50)
70
+	{
71
+		global $wpdb;
72
+		$start_at_record = $this->count_records_migrated();
73
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74
+		$items_actually_migrated = 0;
75
+		foreach ($rows as $old_venue) {
76
+			if (! $new_id = $this->_insert_into_posts($old_venue)) {
77
+				$items_actually_migrated++;
78
+				continue;
79
+			}
80
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
+			if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82
+				$items_actually_migrated++;
83
+				continue;
84
+			}
85
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id);
86
+			// lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it
87
+			$venue_meta = maybe_unserialize($old_venue['meta']);
88
+			if (isset($venue_meta['contact']) && $venue_meta['contact']) {
89
+				add_post_meta($new_id, 'contact', $venue_meta['contact']);
90
+			}
91
+			// is there an image on this venue?
92
+			$guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null;
93
+			if ($guid) {
94
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
95
+			}
96
+			$items_actually_migrated++;
97
+			if ($guid) {
98
+				// if there was an image, we may have had to download it etc and it may have taken
99
+				// longer, then let's not bother migrating anymore on this step
100
+				break;
101
+			}
102
+		}
103
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
104
+			$this->set_completed();
105
+		}
106
+		return $items_actually_migrated;
107
+	}
108
+	public function _count_records_to_migrate()
109
+	{
110
+		global $wpdb;
111
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
112
+		return $count;
113
+	}
114
+	public function __construct()
115
+	{
116
+		$this->_pretty_name = __("Venues", "event_espresso");
117
+		global $wpdb;
118
+		$this->_old_table = $wpdb->prefix."events_venue";
119
+		$this->_new_table = $wpdb->posts;
120
+		$this->_new_meta_table = $wpdb->prefix."esp_venue_meta";
121
+		parent::__construct();
122
+	}
123 123
 
124
-    /**
125
-     * Inserts the CPT
126
-     * @param array $old_venue keys are cols, values are col values
127
-     * @return int
128
-     */
129
-    private function _insert_into_posts($old_venue)
130
-    {
131
-        global $wpdb;
132
-        $meta = maybe_unserialize($old_venue['meta']);
133
-        $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134
-        $insertion_array = array(
135
-                    'post_title'=>stripslashes($old_venue['name']),// VNU_name
136
-                    'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
-                    'post_name'=> $slug,// VNU_identifier
138
-                    'post_date'=>current_time('mysql'),// VNU_created
139
-                    'post_date_gmt'=>  current_time('mysql', true),
140
-                    'post_excerpt'=>'',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
-                    'post_modified'=>current_time('mysql'),// VNU_modified
142
-                    'post_modified_gmt'=>current_time('mysql', true),
143
-                    'post_author'=>$old_venue['wp_user'],// VNU_wp_user
144
-                    'post_parent'=>0,// parent
145
-                    'menu_order'=>0,// VNU_order
146
-                    'post_type'=>'espresso_venues'// post_type
147
-                );
148
-        $datatypes_array = array(
149
-                    '%s',// VNU_name
150
-                    '%s',// VNU_desc
151
-                    '%s',// VNU_identifier
152
-                    '%s',// VNU_created
153
-                    '%s',
154
-                    '%s',// VNU_short_desc
155
-                    '%s',// VNU_modified
156
-                    '%s',
157
-                    '%d',// VNU_wp_user
158
-                    '%d',// parent
159
-                    '%d',// VNU_order
160
-                    '%s',// post_type
161
-                );
162
-        $success = $wpdb->insert(
163
-            $this->_new_table,
164
-            $insertion_array,
165
-            $datatypes_array
166
-        );
167
-        if (! $success) {
168
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169
-            return 0;
170
-        }
171
-        return $wpdb->insert_id;
172
-    }
124
+	/**
125
+	 * Inserts the CPT
126
+	 * @param array $old_venue keys are cols, values are col values
127
+	 * @return int
128
+	 */
129
+	private function _insert_into_posts($old_venue)
130
+	{
131
+		global $wpdb;
132
+		$meta = maybe_unserialize($old_venue['meta']);
133
+		$slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134
+		$insertion_array = array(
135
+					'post_title'=>stripslashes($old_venue['name']),// VNU_name
136
+					'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
+					'post_name'=> $slug,// VNU_identifier
138
+					'post_date'=>current_time('mysql'),// VNU_created
139
+					'post_date_gmt'=>  current_time('mysql', true),
140
+					'post_excerpt'=>'',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
+					'post_modified'=>current_time('mysql'),// VNU_modified
142
+					'post_modified_gmt'=>current_time('mysql', true),
143
+					'post_author'=>$old_venue['wp_user'],// VNU_wp_user
144
+					'post_parent'=>0,// parent
145
+					'menu_order'=>0,// VNU_order
146
+					'post_type'=>'espresso_venues'// post_type
147
+				);
148
+		$datatypes_array = array(
149
+					'%s',// VNU_name
150
+					'%s',// VNU_desc
151
+					'%s',// VNU_identifier
152
+					'%s',// VNU_created
153
+					'%s',
154
+					'%s',// VNU_short_desc
155
+					'%s',// VNU_modified
156
+					'%s',
157
+					'%d',// VNU_wp_user
158
+					'%d',// parent
159
+					'%d',// VNU_order
160
+					'%s',// post_type
161
+				);
162
+		$success = $wpdb->insert(
163
+			$this->_new_table,
164
+			$insertion_array,
165
+			$datatypes_array
166
+		);
167
+		if (! $success) {
168
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169
+			return 0;
170
+		}
171
+		return $wpdb->insert_id;
172
+	}
173 173
 
174
-    /**
175
-     * Finds a unique slug for this venue, given its name (we could have simply used
176
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
177
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
178
-     * @param string $post_name
179
-     * @return string
180
-     */
181
-    private function _find_unique_slug($post_name, $old_identifier = '')
182
-    {
183
-        $count = 0;
184
-        $original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185
-        $event_slug = $original_name;
186
-        while ($this->_other_post_exists_with_that_slug($event_slug) && $count<50) {
187
-            $event_slug = sanitize_title($original_name."-".++$count);
188
-        }
189
-        return $event_slug;
190
-    }
174
+	/**
175
+	 * Finds a unique slug for this venue, given its name (we could have simply used
176
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
177
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
178
+	 * @param string $post_name
179
+	 * @return string
180
+	 */
181
+	private function _find_unique_slug($post_name, $old_identifier = '')
182
+	{
183
+		$count = 0;
184
+		$original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185
+		$event_slug = $original_name;
186
+		while ($this->_other_post_exists_with_that_slug($event_slug) && $count<50) {
187
+			$event_slug = sanitize_title($original_name."-".++$count);
188
+		}
189
+		return $event_slug;
190
+	}
191 191
 
192
-    /**
193
-     * returns whether or not there is a post that has this same slug (post_title)
194
-     * @global type $wpdb
195
-     * @param type $slug
196
-     * @return boolean
197
-     */
198
-    private function _other_post_exists_with_that_slug($slug)
199
-    {
200
-        global $wpdb;
201
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", $slug);
202
-        $count = $wpdb->get_var($query);
203
-        return (boolean) intval($count);
204
-    }
192
+	/**
193
+	 * returns whether or not there is a post that has this same slug (post_title)
194
+	 * @global type $wpdb
195
+	 * @param type $slug
196
+	 * @return boolean
197
+	 */
198
+	private function _other_post_exists_with_that_slug($slug)
199
+	{
200
+		global $wpdb;
201
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", $slug);
202
+		$count = $wpdb->get_var($query);
203
+		return (boolean) intval($count);
204
+	}
205 205
 
206
-    /**
207
-     * Inserts into the venue_meta table
208
-     * @param type $cpt_id
209
-     * @param type $old_venue
210
-     * @return int
211
-     */
212
-    private function _insert_into_meta_table($cpt_id, $old_venue)
213
-    {
214
-        global $wpdb;
215
-        // get a country with the same name, or insert one
216
-        try {
217
-            $country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country']));
218
-            $country_iso = $country['CNT_ISO'];
219
-        } catch (EE_Error $e) {
220
-            $this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
221
-            $country_iso = null;
222
-        }
223
-        // get a state with the same name, if possible
224
-        try {
225
-            $state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags($old_venue['country']));
226
-            $state_id = $state['STA_ID'];
227
-        } catch (EE_Error $e) {
228
-            $this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
229
-            $state_id = 0;
230
-        }
231
-        $meta = maybe_unserialize($old_venue['meta']);
232
-        // now insert into meta table
233
-        $insertion_array = array(
234
-            'VNU_ID'=>$cpt_id,// VNU_ID_fk
235
-            'VNU_address'=>stripslashes($old_venue['address']),// VNU_address
236
-            'VNU_address2'=>stripslashes($old_venue['address2']),// VNU_address2
237
-            'VNU_city'=>stripslashes($old_venue['city']),// VNU_city
238
-            'STA_ID'=>$state_id,// STA_ID
239
-            'CNT_ISO'=>$country_iso,// CNT_ISO
240
-            'VNU_zip'=>stripslashes($old_venue['zip']),// VNU_zip
241
-            'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
-            'VNU_capacity'=>-1,// VNU_capacity
243
-            'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
-            'VNU_virtual_phone'=>'',// VNU_virtual_phone
245
-            'VNU_virtual_url'=>'',// VNU_virtual_url
246
-            'VNU_google_map_link'=>'',// VNU_google_map_link
247
-            'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
248
-        );
249
-        $datatypes = array(
250
-            '%d',// VNU_ID_fk
251
-            '%s',// VNU_address
252
-            '%s',// VNU_address2
253
-            '%s',// VNU_city
254
-            '%d',// STA_ID
255
-            '%s',// CNT_ISO
256
-            '%s',// VNU_zip
257
-            '%s',// VNU_phone
258
-            '%d',// VNU_capacity
259
-            '%s',// VNU_url
260
-            '%s',// VNU_virtual_phone
261
-            '%s',// VNU_virtual_url
262
-            '%s',// VNU_google_map_link
263
-            '%d',// VNU_enable_for_gmap
264
-        );
265
-        $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
-        if (! $success) {
267
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268
-            return 0;
269
-        }
270
-        return $wpdb->insert_id;
271
-    }
206
+	/**
207
+	 * Inserts into the venue_meta table
208
+	 * @param type $cpt_id
209
+	 * @param type $old_venue
210
+	 * @return int
211
+	 */
212
+	private function _insert_into_meta_table($cpt_id, $old_venue)
213
+	{
214
+		global $wpdb;
215
+		// get a country with the same name, or insert one
216
+		try {
217
+			$country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country']));
218
+			$country_iso = $country['CNT_ISO'];
219
+		} catch (EE_Error $e) {
220
+			$this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
221
+			$country_iso = null;
222
+		}
223
+		// get a state with the same name, if possible
224
+		try {
225
+			$state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags($old_venue['country']));
226
+			$state_id = $state['STA_ID'];
227
+		} catch (EE_Error $e) {
228
+			$this->add_error(sprintf(__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
229
+			$state_id = 0;
230
+		}
231
+		$meta = maybe_unserialize($old_venue['meta']);
232
+		// now insert into meta table
233
+		$insertion_array = array(
234
+			'VNU_ID'=>$cpt_id,// VNU_ID_fk
235
+			'VNU_address'=>stripslashes($old_venue['address']),// VNU_address
236
+			'VNU_address2'=>stripslashes($old_venue['address2']),// VNU_address2
237
+			'VNU_city'=>stripslashes($old_venue['city']),// VNU_city
238
+			'STA_ID'=>$state_id,// STA_ID
239
+			'CNT_ISO'=>$country_iso,// CNT_ISO
240
+			'VNU_zip'=>stripslashes($old_venue['zip']),// VNU_zip
241
+			'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
+			'VNU_capacity'=>-1,// VNU_capacity
243
+			'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
+			'VNU_virtual_phone'=>'',// VNU_virtual_phone
245
+			'VNU_virtual_url'=>'',// VNU_virtual_url
246
+			'VNU_google_map_link'=>'',// VNU_google_map_link
247
+			'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
248
+		);
249
+		$datatypes = array(
250
+			'%d',// VNU_ID_fk
251
+			'%s',// VNU_address
252
+			'%s',// VNU_address2
253
+			'%s',// VNU_city
254
+			'%d',// STA_ID
255
+			'%s',// CNT_ISO
256
+			'%s',// VNU_zip
257
+			'%s',// VNU_phone
258
+			'%d',// VNU_capacity
259
+			'%s',// VNU_url
260
+			'%s',// VNU_virtual_phone
261
+			'%s',// VNU_virtual_url
262
+			'%s',// VNU_google_map_link
263
+			'%d',// VNU_enable_for_gmap
264
+		);
265
+		$success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
+		if (! $success) {
267
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268
+			return 0;
269
+		}
270
+		return $wpdb->insert_id;
271
+	}
272 272
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
         $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74 74
         $items_actually_migrated = 0;
75 75
         foreach ($rows as $old_venue) {
76
-            if (! $new_id = $this->_insert_into_posts($old_venue)) {
76
+            if ( ! $new_id = $this->_insert_into_posts($old_venue)) {
77 77
                 $items_actually_migrated++;
78 78
                 continue;
79 79
             }
80 80
             $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
-            if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
81
+            if ( ! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82 82
                 $items_actually_migrated++;
83 83
                 continue;
84 84
             }
@@ -132,39 +132,39 @@  discard block
 block discarded – undo
132 132
         $meta = maybe_unserialize($old_venue['meta']);
133 133
         $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134 134
         $insertion_array = array(
135
-                    'post_title'=>stripslashes($old_venue['name']),// VNU_name
136
-                    'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
-                    'post_name'=> $slug,// VNU_identifier
138
-                    'post_date'=>current_time('mysql'),// VNU_created
135
+                    'post_title'=>stripslashes($old_venue['name']), // VNU_name
136
+                    'post_content'=>isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '', // VNU_desc
137
+                    'post_name'=> $slug, // VNU_identifier
138
+                    'post_date'=>current_time('mysql'), // VNU_created
139 139
                     'post_date_gmt'=>  current_time('mysql', true),
140
-                    'post_excerpt'=>'',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
-                    'post_modified'=>current_time('mysql'),// VNU_modified
140
+                    'post_excerpt'=>'', // wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
+                    'post_modified'=>current_time('mysql'), // VNU_modified
142 142
                     'post_modified_gmt'=>current_time('mysql', true),
143
-                    'post_author'=>$old_venue['wp_user'],// VNU_wp_user
144
-                    'post_parent'=>0,// parent
145
-                    'menu_order'=>0,// VNU_order
143
+                    'post_author'=>$old_venue['wp_user'], // VNU_wp_user
144
+                    'post_parent'=>0, // parent
145
+                    'menu_order'=>0, // VNU_order
146 146
                     'post_type'=>'espresso_venues'// post_type
147 147
                 );
148 148
         $datatypes_array = array(
149
-                    '%s',// VNU_name
150
-                    '%s',// VNU_desc
151
-                    '%s',// VNU_identifier
152
-                    '%s',// VNU_created
149
+                    '%s', // VNU_name
150
+                    '%s', // VNU_desc
151
+                    '%s', // VNU_identifier
152
+                    '%s', // VNU_created
153 153
                     '%s',
154
-                    '%s',// VNU_short_desc
155
-                    '%s',// VNU_modified
154
+                    '%s', // VNU_short_desc
155
+                    '%s', // VNU_modified
156 156
                     '%s',
157
-                    '%d',// VNU_wp_user
158
-                    '%d',// parent
159
-                    '%d',// VNU_order
160
-                    '%s',// post_type
157
+                    '%d', // VNU_wp_user
158
+                    '%d', // parent
159
+                    '%d', // VNU_order
160
+                    '%s', // post_type
161 161
                 );
162 162
         $success = $wpdb->insert(
163 163
             $this->_new_table,
164 164
             $insertion_array,
165 165
             $datatypes_array
166 166
         );
167
-        if (! $success) {
167
+        if ( ! $success) {
168 168
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169 169
             return 0;
170 170
         }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         $count = 0;
184 184
         $original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185 185
         $event_slug = $original_name;
186
-        while ($this->_other_post_exists_with_that_slug($event_slug) && $count<50) {
186
+        while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187 187
             $event_slug = sanitize_title($original_name."-".++$count);
188 188
         }
189 189
         return $event_slug;
@@ -231,39 +231,39 @@  discard block
 block discarded – undo
231 231
         $meta = maybe_unserialize($old_venue['meta']);
232 232
         // now insert into meta table
233 233
         $insertion_array = array(
234
-            'VNU_ID'=>$cpt_id,// VNU_ID_fk
235
-            'VNU_address'=>stripslashes($old_venue['address']),// VNU_address
236
-            'VNU_address2'=>stripslashes($old_venue['address2']),// VNU_address2
237
-            'VNU_city'=>stripslashes($old_venue['city']),// VNU_city
238
-            'STA_ID'=>$state_id,// STA_ID
239
-            'CNT_ISO'=>$country_iso,// CNT_ISO
240
-            'VNU_zip'=>stripslashes($old_venue['zip']),// VNU_zip
241
-            'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
-            'VNU_capacity'=>-1,// VNU_capacity
243
-            'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
-            'VNU_virtual_phone'=>'',// VNU_virtual_phone
245
-            'VNU_virtual_url'=>'',// VNU_virtual_url
246
-            'VNU_google_map_link'=>'',// VNU_google_map_link
234
+            'VNU_ID'=>$cpt_id, // VNU_ID_fk
235
+            'VNU_address'=>stripslashes($old_venue['address']), // VNU_address
236
+            'VNU_address2'=>stripslashes($old_venue['address2']), // VNU_address2
237
+            'VNU_city'=>stripslashes($old_venue['city']), // VNU_city
238
+            'STA_ID'=>$state_id, // STA_ID
239
+            'CNT_ISO'=>$country_iso, // CNT_ISO
240
+            'VNU_zip'=>stripslashes($old_venue['zip']), // VNU_zip
241
+            'VNU_phone'=>isset($meta['phone']) ? stripslashes($meta['phone']) : '', // VNU_phone
242
+            'VNU_capacity'=>-1, // VNU_capacity
243
+            'VNU_url'=>isset($meta['website']) ? stripslashes($meta['website']) : '', // VNU_url
244
+            'VNU_virtual_phone'=>'', // VNU_virtual_phone
245
+            'VNU_virtual_url'=>'', // VNU_virtual_url
246
+            'VNU_google_map_link'=>'', // VNU_google_map_link
247 247
             'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
248 248
         );
249 249
         $datatypes = array(
250
-            '%d',// VNU_ID_fk
251
-            '%s',// VNU_address
252
-            '%s',// VNU_address2
253
-            '%s',// VNU_city
254
-            '%d',// STA_ID
255
-            '%s',// CNT_ISO
256
-            '%s',// VNU_zip
257
-            '%s',// VNU_phone
258
-            '%d',// VNU_capacity
259
-            '%s',// VNU_url
260
-            '%s',// VNU_virtual_phone
261
-            '%s',// VNU_virtual_url
262
-            '%s',// VNU_google_map_link
263
-            '%d',// VNU_enable_for_gmap
250
+            '%d', // VNU_ID_fk
251
+            '%s', // VNU_address
252
+            '%s', // VNU_address2
253
+            '%s', // VNU_city
254
+            '%d', // STA_ID
255
+            '%s', // CNT_ISO
256
+            '%s', // VNU_zip
257
+            '%s', // VNU_phone
258
+            '%d', // VNU_capacity
259
+            '%s', // VNU_url
260
+            '%s', // VNU_virtual_phone
261
+            '%s', // VNU_virtual_url
262
+            '%s', // VNU_google_map_link
263
+            '%d', // VNU_enable_for_gmap
264 264
         );
265 265
         $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
-        if (! $success) {
266
+        if ( ! $success) {
267 267
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268 268
             return 0;
269 269
         }
Please login to merge, or discard this patch.
4_6_0_stages/EE_DMS_4_6_0_payment_method_currencies.dmsstage.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -128,6 +128,9 @@  discard block
 block discarded – undo
128 128
         return $items_actually_migrated;
129 129
     }
130 130
 
131
+    /**
132
+     * @param integer $num_items_to_migrate
133
+     */
131 134
     private function _gather_relations_to_add($num_items_to_migrate)
132 135
     {
133 136
         $relations_to_add_this_step = array();
@@ -160,8 +163,6 @@  discard block
 block discarded – undo
160 163
 
161 164
     /**
162 165
      * Adds teh relation between the payment method and the currencies it can be used for
163
-     * @param int $id
164
-     * @param string $gateway_slug
165 166
      */
166 167
     private function _add_currency_relations($pm_id, $currency_code)
167 168
     {
Please login to merge, or discard this patch.
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -12,174 +12,174 @@
 block discarded – undo
12 12
  */
13 13
 class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage
14 14
 {
15
-    protected $_currency_table_name;
16
-    protected $_currency_payment_method_table_name;
17
-    protected $_payment_method_table_name;
18
-    /**
19
-     * each key is the name of a 4.1-style gateway we know how to migrate to 4.6
20
-     * @var array
21
-     */
22
-    protected $_gateway_currencies = array(
23
-        'Aim' => array(
24
-            'AUD',
25
-            'USD',
26
-            'CAD',
27
-            'EUR',
28
-            'GBP',
29
-            'NZD',
30
-        ),
31
-        'Bank' => 'all',
32
-        'Check' => 'all',
33
-        'Invoice' => 'all',
34
-        'Mijireh' => 'all',
35
-        'Paypal_Pro' => array(
36
-            'USD',
37
-            'GBP',
38
-            'CAD',
39
-            'AUD',
40
-            'BRL',
41
-            'CHF',
42
-            'CZK',
43
-            'DKK',
44
-            'EUR',
45
-            'HKD',
46
-            'HUF',
47
-            'ILS',
48
-            'JPY',
49
-            'MXN',
50
-            'MYR',
51
-            'NOK',
52
-            'NZD',
53
-            'PHP',
54
-            'PLN',
55
-            'SEK',
56
-            'SGD',
57
-            'THB',
58
-            'TRY',
59
-            'TWD',
60
-        ),
61
-        'Paypal_Standard' => array(
62
-            'USD',
63
-            'GBP',
64
-            'CAD',
65
-            'AUD',
66
-            'BRL',
67
-            'CHF',
68
-            'CZK',
69
-            'DKK',
70
-            'EUR',
71
-            'HKD',
72
-            'HUF',
73
-            'ILS',
74
-            'JPY',
75
-            'MXN',
76
-            'MYR',
77
-            'NOK',
78
-            'NZD',
79
-            'PHP',
80
-            'PLN',
81
-            'SEK',
82
-            'SGD',
83
-            'THB',
84
-            'TRY',
85
-            'TWD'
86
-        )
87
-    );
88
-    public function __construct()
89
-    {
90
-        global $wpdb;
91
-        $this->_pretty_name = __('Payment Method Currencies', 'event_espresso');
92
-        $this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method';
93
-        $this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method';
94
-        $this->_currency_table_name = $wpdb->prefix.'esp_currency';
95
-        parent::__construct();
96
-    }
15
+	protected $_currency_table_name;
16
+	protected $_currency_payment_method_table_name;
17
+	protected $_payment_method_table_name;
18
+	/**
19
+	 * each key is the name of a 4.1-style gateway we know how to migrate to 4.6
20
+	 * @var array
21
+	 */
22
+	protected $_gateway_currencies = array(
23
+		'Aim' => array(
24
+			'AUD',
25
+			'USD',
26
+			'CAD',
27
+			'EUR',
28
+			'GBP',
29
+			'NZD',
30
+		),
31
+		'Bank' => 'all',
32
+		'Check' => 'all',
33
+		'Invoice' => 'all',
34
+		'Mijireh' => 'all',
35
+		'Paypal_Pro' => array(
36
+			'USD',
37
+			'GBP',
38
+			'CAD',
39
+			'AUD',
40
+			'BRL',
41
+			'CHF',
42
+			'CZK',
43
+			'DKK',
44
+			'EUR',
45
+			'HKD',
46
+			'HUF',
47
+			'ILS',
48
+			'JPY',
49
+			'MXN',
50
+			'MYR',
51
+			'NOK',
52
+			'NZD',
53
+			'PHP',
54
+			'PLN',
55
+			'SEK',
56
+			'SGD',
57
+			'THB',
58
+			'TRY',
59
+			'TWD',
60
+		),
61
+		'Paypal_Standard' => array(
62
+			'USD',
63
+			'GBP',
64
+			'CAD',
65
+			'AUD',
66
+			'BRL',
67
+			'CHF',
68
+			'CZK',
69
+			'DKK',
70
+			'EUR',
71
+			'HKD',
72
+			'HUF',
73
+			'ILS',
74
+			'JPY',
75
+			'MXN',
76
+			'MYR',
77
+			'NOK',
78
+			'NZD',
79
+			'PHP',
80
+			'PLN',
81
+			'SEK',
82
+			'SGD',
83
+			'THB',
84
+			'TRY',
85
+			'TWD'
86
+		)
87
+	);
88
+	public function __construct()
89
+	{
90
+		global $wpdb;
91
+		$this->_pretty_name = __('Payment Method Currencies', 'event_espresso');
92
+		$this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method';
93
+		$this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method';
94
+		$this->_currency_table_name = $wpdb->prefix.'esp_currency';
95
+		parent::__construct();
96
+	}
97 97
 
98
-    protected function _count_records_to_migrate()
99
-    {
100
-        $count = 0;
101
-        foreach ($this->_gateway_currencies as $currencies) {
102
-            if ($currencies == 'all') {
103
-                $currencies = $this->_get_all_currencies();
104
-            }
105
-            $count += count($currencies);
106
-        }
107
-        return $count;
108
-    }
98
+	protected function _count_records_to_migrate()
99
+	{
100
+		$count = 0;
101
+		foreach ($this->_gateway_currencies as $currencies) {
102
+			if ($currencies == 'all') {
103
+				$currencies = $this->_get_all_currencies();
104
+			}
105
+			$count += count($currencies);
106
+		}
107
+		return $count;
108
+	}
109 109
 
110 110
 
111 111
 
112
-    protected function _migration_step($num_items_to_migrate = 50)
113
-    {
114
-        $items_actually_migrated = 0;
115
-        $relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate);
116
-        foreach ($relations_to_add_this_step as $pm_slug => $currencies) {
117
-            $id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name);
118
-            foreach ($currencies as $currency) {
119
-                if ($id) {
120
-                    $this->_add_currency_relations($id, $currency);
121
-                }
122
-                $items_actually_migrated++;
123
-            }
124
-        }
125
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
126
-            $this->set_completed();
127
-        }
128
-        return $items_actually_migrated;
129
-    }
112
+	protected function _migration_step($num_items_to_migrate = 50)
113
+	{
114
+		$items_actually_migrated = 0;
115
+		$relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate);
116
+		foreach ($relations_to_add_this_step as $pm_slug => $currencies) {
117
+			$id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name);
118
+			foreach ($currencies as $currency) {
119
+				if ($id) {
120
+					$this->_add_currency_relations($id, $currency);
121
+				}
122
+				$items_actually_migrated++;
123
+			}
124
+		}
125
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
126
+			$this->set_completed();
127
+		}
128
+		return $items_actually_migrated;
129
+	}
130 130
 
131
-    private function _gather_relations_to_add($num_items_to_migrate)
132
-    {
133
-        $relations_to_add_this_step = array();
134
-        $migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate;
135
-        $iterator = 0;
136
-        foreach ($this->_gateway_currencies as $pm_slug => $currencies) {
137
-            if ($currencies == 'all') {
138
-                $currencies = $this->_get_all_currencies();
139
-            }
140
-            foreach ($currencies as $currency_code) {
141
-                if ($this->count_records_migrated() <= $iterator &&
142
-                        $iterator < $migrate_up_to_count ) {
143
-                    $relations_to_add_this_step[ $pm_slug ] [] = $currency_code;
144
-                }
145
-                $iterator++;
146
-            }
147
-        }
148
-        return $relations_to_add_this_step;
149
-    }
150
-    /**
151
-     * Gets all the currency codes in the database
152
-     * @return array
153
-     */
154
-    private function _get_all_currencies()
155
-    {
156
-        global $wpdb;
157
-        $currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}");
158
-        return $currencies;
159
-    }
131
+	private function _gather_relations_to_add($num_items_to_migrate)
132
+	{
133
+		$relations_to_add_this_step = array();
134
+		$migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate;
135
+		$iterator = 0;
136
+		foreach ($this->_gateway_currencies as $pm_slug => $currencies) {
137
+			if ($currencies == 'all') {
138
+				$currencies = $this->_get_all_currencies();
139
+			}
140
+			foreach ($currencies as $currency_code) {
141
+				if ($this->count_records_migrated() <= $iterator &&
142
+						$iterator < $migrate_up_to_count ) {
143
+					$relations_to_add_this_step[ $pm_slug ] [] = $currency_code;
144
+				}
145
+				$iterator++;
146
+			}
147
+		}
148
+		return $relations_to_add_this_step;
149
+	}
150
+	/**
151
+	 * Gets all the currency codes in the database
152
+	 * @return array
153
+	 */
154
+	private function _get_all_currencies()
155
+	{
156
+		global $wpdb;
157
+		$currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}");
158
+		return $currencies;
159
+	}
160 160
 
161
-    /**
162
-     * Adds teh relation between the payment method and the currencies it can be used for
163
-     * @param int $id
164
-     * @param string $gateway_slug
165
-     */
166
-    private function _add_currency_relations($pm_id, $currency_code)
167
-    {
168
-        global $wpdb;
169
-        $cur_pm_relation = array(
170
-                    'CUR_code'=>$currency_code,
171
-                    'PMD_ID'=>$pm_id,
172
-                );
173
-        $success = $wpdb->insert(
174
-            $this->_currency_payment_method_table_name,
175
-            $cur_pm_relation,
176
-            array(
177
-                    '%s',// CUR_code
178
-                    '%d',// PMD_ID
179
-                )
180
-        );
181
-        if (! $success) {
182
-            $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error));
183
-        }
184
-    }
161
+	/**
162
+	 * Adds teh relation between the payment method and the currencies it can be used for
163
+	 * @param int $id
164
+	 * @param string $gateway_slug
165
+	 */
166
+	private function _add_currency_relations($pm_id, $currency_code)
167
+	{
168
+		global $wpdb;
169
+		$cur_pm_relation = array(
170
+					'CUR_code'=>$currency_code,
171
+					'PMD_ID'=>$pm_id,
172
+				);
173
+		$success = $wpdb->insert(
174
+			$this->_currency_payment_method_table_name,
175
+			$cur_pm_relation,
176
+			array(
177
+					'%s',// CUR_code
178
+					'%d',// PMD_ID
179
+				)
180
+		);
181
+		if (! $success) {
182
+			$this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error));
183
+		}
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
             }
140 140
             foreach ($currencies as $currency_code) {
141 141
                 if ($this->count_records_migrated() <= $iterator &&
142
-                        $iterator < $migrate_up_to_count ) {
143
-                    $relations_to_add_this_step[ $pm_slug ] [] = $currency_code;
142
+                        $iterator < $migrate_up_to_count) {
143
+                    $relations_to_add_this_step[$pm_slug] [] = $currency_code;
144 144
                 }
145 145
                 $iterator++;
146 146
             }
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
             $this->_currency_payment_method_table_name,
175 175
             $cur_pm_relation,
176 176
             array(
177
-                    '%s',// CUR_code
178
-                    '%d',// PMD_ID
177
+                    '%s', // CUR_code
178
+                    '%d', // PMD_ID
179 179
                 )
180 180
         );
181
-        if (! $success) {
181
+        if ( ! $success) {
182 182
             $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error));
183 183
         }
184 184
     }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_6_0_stages/EE_DMS_4_6_0_payments.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,6 @@
 block discarded – undo
58 58
             'IV'=>  __("Invoice", 'event_espresso'),
59 59
             'MO'=>  __("Money Order", 'event_espresso'),
60 60
      * @global type $wpdb
61
-     * @param int $id
62 61
      * @return string
63 62
      */
64 63
     protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column)
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -11,44 +11,44 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class EE_DMS_4_6_0_payments extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14
-    protected $_payment_method_table;
15
-    public function __construct()
16
-    {
17
-        global $wpdb;
18
-        $this->_old_table = $wpdb->prefix . 'esp_payment';
19
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
20
-        $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso');
21
-        parent::__construct();
22
-    }
23
-    protected function _migrate_old_row($payment_row)
24
-    {
25
-        global $wpdb;
26
-        // get the payment method's ID
27
-        $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method']));
28
-        if (! $PMD_ID) {
29
-            $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row)));
30
-            $PMD_ID = 0;
31
-        }
32
-        $new_values = array(
33
-            'PMD_ID' => $PMD_ID,
34
-            'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) );
35
-        $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] );
36
-        $new_value_datatypes = array( '%d', '%s' );
37
-        $where_datatypes = array( '%d' );
38
-        $success = $wpdb->update(
39
-            $this->_old_table,
40
-            $new_values,
41
-            $wheres,
42
-            $new_value_datatypes,
43
-            $where_datatypes
44
-        );
45
-        if (! $success) {
46
-            $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres)));
47
-        }
48
-    }
49
-    /**
50
-     *
51
-     *  array(
14
+	protected $_payment_method_table;
15
+	public function __construct()
16
+	{
17
+		global $wpdb;
18
+		$this->_old_table = $wpdb->prefix . 'esp_payment';
19
+		$this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
20
+		$this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso');
21
+		parent::__construct();
22
+	}
23
+	protected function _migrate_old_row($payment_row)
24
+	{
25
+		global $wpdb;
26
+		// get the payment method's ID
27
+		$PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method']));
28
+		if (! $PMD_ID) {
29
+			$this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row)));
30
+			$PMD_ID = 0;
31
+		}
32
+		$new_values = array(
33
+			'PMD_ID' => $PMD_ID,
34
+			'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) );
35
+		$wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] );
36
+		$new_value_datatypes = array( '%d', '%s' );
37
+		$where_datatypes = array( '%d' );
38
+		$success = $wpdb->update(
39
+			$this->_old_table,
40
+			$new_values,
41
+			$wheres,
42
+			$new_value_datatypes,
43
+			$where_datatypes
44
+		);
45
+		if (! $success) {
46
+			$this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres)));
47
+		}
48
+	}
49
+	/**
50
+	 *
51
+	 *  array(
52 52
             'PP' => __( 'PayPal', 'event_espresso' ),
53 53
             'CC' => __( 'Credit Card', 'event_espresso' ),
54 54
             'DB'=>  __("Debit Card", 'event_espresso'),
@@ -57,44 +57,44 @@  discard block
 block discarded – undo
57 57
             'BK'=>  __("Bank", 'event_espresso'),
58 58
             'IV'=>  __("Invoice", 'event_espresso'),
59 59
             'MO'=>  __("Money Order", 'event_espresso'),
60
-     * @global type $wpdb
61
-     * @param int $id
62
-     * @return string
63
-     */
64
-    protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column)
65
-    {
66
-        global $wpdb;
67
-        // convert from old known PAY_method values to their corresponding
68
-        // PMD_type or default PMD_name
69
-        switch ($old_pay_method_column) {
70
-            case 'PP':
71
-                $pmd_type = 'Paypal_Standard';
72
-                break;
73
-            case 'CC':
74
-                $pmd_type = 'Credit_Card';
75
-                break;
76
-            case 'DB':
77
-                $pmd_type = 'Debit_Card';
78
-                break;
79
-            case 'CHQ':
80
-                $pmd_type = 'Check';
81
-                break;
82
-            case 'CSH':
83
-                $pmd_type = 'Cash';
84
-                break;
85
-            case 'BK':
86
-                $pmd_type = 'Bank';
87
-                break;
88
-            case 'IV':
89
-                $pmd_type = 'Invoice';
90
-                break;
91
-            case 'MO':
92
-                $pmd_type = 'Money_Order';
93
-                break;
94
-            default:
95
-                $pmd_type = $gateway_name;
96
-        }
97
-        $pmd_name = str_replace("_", " ", $pmd_type);
98
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
99
-    }
60
+	 * @global type $wpdb
61
+	 * @param int $id
62
+	 * @return string
63
+	 */
64
+	protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column)
65
+	{
66
+		global $wpdb;
67
+		// convert from old known PAY_method values to their corresponding
68
+		// PMD_type or default PMD_name
69
+		switch ($old_pay_method_column) {
70
+			case 'PP':
71
+				$pmd_type = 'Paypal_Standard';
72
+				break;
73
+			case 'CC':
74
+				$pmd_type = 'Credit_Card';
75
+				break;
76
+			case 'DB':
77
+				$pmd_type = 'Debit_Card';
78
+				break;
79
+			case 'CHQ':
80
+				$pmd_type = 'Check';
81
+				break;
82
+			case 'CSH':
83
+				$pmd_type = 'Cash';
84
+				break;
85
+			case 'BK':
86
+				$pmd_type = 'Bank';
87
+				break;
88
+			case 'IV':
89
+				$pmd_type = 'Invoice';
90
+				break;
91
+			case 'MO':
92
+				$pmd_type = 'Money_Order';
93
+				break;
94
+			default:
95
+				$pmd_type = $gateway_name;
96
+		}
97
+		$pmd_name = str_replace("_", " ", $pmd_type);
98
+		return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
99
+	}
100 100
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
     public function __construct()
16 16
     {
17 17
         global $wpdb;
18
-        $this->_old_table = $wpdb->prefix . 'esp_payment';
19
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
18
+        $this->_old_table = $wpdb->prefix.'esp_payment';
19
+        $this->_payment_method_table = $wpdb->prefix.'esp_payment_method';
20 20
         $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso');
21 21
         parent::__construct();
22 22
     }
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
         global $wpdb;
26 26
         // get the payment method's ID
27 27
         $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method']));
28
-        if (! $PMD_ID) {
28
+        if ( ! $PMD_ID) {
29 29
             $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row)));
30 30
             $PMD_ID = 0;
31 31
         }
32 32
         $new_values = array(
33 33
             'PMD_ID' => $PMD_ID,
34
-            'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) );
35
-        $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] );
36
-        $new_value_datatypes = array( '%d', '%s' );
37
-        $where_datatypes = array( '%d' );
34
+            'PAY_source' => ($payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART') );
35
+        $wheres = array('PAY_ID' => $payment_row['PAY_ID']);
36
+        $new_value_datatypes = array('%d', '%s');
37
+        $where_datatypes = array('%d');
38 38
         $success = $wpdb->update(
39 39
             $this->_old_table,
40 40
             $new_values,
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             $new_value_datatypes,
43 43
             $where_datatypes
44 44
         );
45
-        if (! $success) {
45
+        if ( ! $success) {
46 46
             $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres)));
47 47
         }
48 48
     }
@@ -95,6 +95,6 @@  discard block
 block discarded – undo
95 95
                 $pmd_type = $gateway_name;
96 96
         }
97 97
         $pmd_name = str_replace("_", " ", $pmd_type);
98
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
98
+        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name));
99 99
     }
100 100
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_6_0_stages/EE_DMS_4_6_0_transactions.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,6 @@
 block discarded – undo
50 50
     /**
51 51
      *
52 52
      * @global type $wpdb
53
-     * @param int $id
54 53
      * @return string
55 54
      */
56 55
     protected function _get_payment_method_id_by_gateway_name($gateway_name)
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -11,51 +11,51 @@
 block discarded – undo
11 11
  */
12 12
 class EE_DMS_4_6_0_transactions extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14
-    protected $_transaction_table;
15
-    protected $_payment_method_table;
16
-    public function __construct()
17
-    {
18
-        global $wpdb;
19
-        $this->_old_table = $wpdb->prefix . 'esp_extra_meta';
20
-        $this->_transaction_table = $wpdb->prefix . 'esp_transaction';
21
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
22
-        $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso');
23
-        $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'";
24
-        parent::__construct();
25
-    }
26
-    protected function _migrate_old_row($extra_meta_row)
27
-    {
28
-        global $wpdb;
29
-        // get the payment method's ID
30
-        $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']);
31
-        if (! $PMD_ID) {
32
-            $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row)));
33
-            return;
34
-        }
35
-        $new_values = array( 'PMD_ID' => $PMD_ID );
36
-        $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] );
37
-        $new_value_datatypes = array( '%d' );
38
-        $where_datatypes = array( '%d' );
39
-        $success = $wpdb->update(
40
-            $this->_transaction_table,
41
-            $new_values,
42
-            $wheres,
43
-            $new_value_datatypes,
44
-            $where_datatypes
45
-        );
46
-        if (! $success) {
47
-            $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres)));
48
-        }
49
-    }
50
-    /**
51
-     *
52
-     * @global type $wpdb
53
-     * @param int $id
54
-     * @return string
55
-     */
56
-    protected function _get_payment_method_id_by_gateway_name($gateway_name)
57
-    {
58
-        global $wpdb;
59
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name));
60
-    }
14
+	protected $_transaction_table;
15
+	protected $_payment_method_table;
16
+	public function __construct()
17
+	{
18
+		global $wpdb;
19
+		$this->_old_table = $wpdb->prefix . 'esp_extra_meta';
20
+		$this->_transaction_table = $wpdb->prefix . 'esp_transaction';
21
+		$this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
22
+		$this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso');
23
+		$this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'";
24
+		parent::__construct();
25
+	}
26
+	protected function _migrate_old_row($extra_meta_row)
27
+	{
28
+		global $wpdb;
29
+		// get the payment method's ID
30
+		$PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']);
31
+		if (! $PMD_ID) {
32
+			$this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row)));
33
+			return;
34
+		}
35
+		$new_values = array( 'PMD_ID' => $PMD_ID );
36
+		$wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] );
37
+		$new_value_datatypes = array( '%d' );
38
+		$where_datatypes = array( '%d' );
39
+		$success = $wpdb->update(
40
+			$this->_transaction_table,
41
+			$new_values,
42
+			$wheres,
43
+			$new_value_datatypes,
44
+			$where_datatypes
45
+		);
46
+		if (! $success) {
47
+			$this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres)));
48
+		}
49
+	}
50
+	/**
51
+	 *
52
+	 * @global type $wpdb
53
+	 * @param int $id
54
+	 * @return string
55
+	 */
56
+	protected function _get_payment_method_id_by_gateway_name($gateway_name)
57
+	{
58
+		global $wpdb;
59
+		return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name));
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
     public function __construct()
17 17
     {
18 18
         global $wpdb;
19
-        $this->_old_table = $wpdb->prefix . 'esp_extra_meta';
20
-        $this->_transaction_table = $wpdb->prefix . 'esp_transaction';
21
-        $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method';
19
+        $this->_old_table = $wpdb->prefix.'esp_extra_meta';
20
+        $this->_transaction_table = $wpdb->prefix.'esp_transaction';
21
+        $this->_payment_method_table = $wpdb->prefix.'esp_payment_method';
22 22
         $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso');
23 23
         $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'";
24 24
         parent::__construct();
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
         global $wpdb;
29 29
         // get the payment method's ID
30 30
         $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']);
31
-        if (! $PMD_ID) {
31
+        if ( ! $PMD_ID) {
32 32
             $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row)));
33 33
             return;
34 34
         }
35
-        $new_values = array( 'PMD_ID' => $PMD_ID );
36
-        $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] );
37
-        $new_value_datatypes = array( '%d' );
38
-        $where_datatypes = array( '%d' );
35
+        $new_values = array('PMD_ID' => $PMD_ID);
36
+        $wheres = array('TXN_ID' => $extra_meta_row['OBJ_ID']);
37
+        $new_value_datatypes = array('%d');
38
+        $where_datatypes = array('%d');
39 39
         $success = $wpdb->update(
40 40
             $this->_transaction_table,
41 41
             $new_values,
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
             $new_value_datatypes,
44 44
             $where_datatypes
45 45
         );
46
-        if (! $success) {
46
+        if ( ! $success) {
47 47
             $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres)));
48 48
         }
49 49
     }
@@ -56,6 +56,6 @@  discard block
 block discarded – undo
56 56
     protected function _get_payment_method_id_by_gateway_name($gateway_name)
57 57
     {
58 58
         global $wpdb;
59
-        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name));
59
+        return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s", $gateway_name));
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Class_Base.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
      * @param array  $old_row_as_array
326 326
      * @param string $new_table
327 327
      * @param array  $new_row_as_array columns=>values like used in wpdb->insert
328
-     * @param array  $data_types       numerically indexed
328
+     * @param string[]  $data_types       numerically indexed
329 329
      * @return string
330 330
      */
331 331
     protected function _create_error_message_for_db_insertion(
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function add_error($error, $force = false)
187 187
     {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
188
+        if ( ! defined('EE_DMS_ERROR_LIMIT')) {
189 189
             $limit = 50;
190 190
         } else {
191 191
             $limit = EE_DMS_ERROR_LIMIT;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                 $this->_errors[] = "Limit reached; removed first half of errors to save space";
202 202
                 $this->_errors[] = $error;
203 203
             } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
204
+                $this->_errors[$limit] = 'More, but limit reached...';
205 205
             }
206 206
         } else {
207 207
             $this->_errors[] = $error;
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
         $new_columns_and_values_for_string = array();
344 344
         $count = 0;
345 345
         foreach ($new_row_as_array as $column => $value) {
346
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
346
+            $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")";
347 347
         }
348 348
         return sprintf(
349 349
             __(
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
         foreach ($array_of_data as $name => $value) {
375 375
             $unserialized_data = @unserialize($value);
376 376
             if ($unserialized_data === false) {
377
-                $fields_to_include[ $name ] = $value;
377
+                $fields_to_include[$name] = $value;
378 378
             }
379 379
         }
380 380
         return wp_json_encode($fields_to_include);
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -17,408 +17,408 @@
 block discarded – undo
17 17
 abstract class EE_Data_Migration_Class_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var $records_to_migrate int count of all that have been migrated
22
-     */
23
-    protected $_records_to_migrate = 0;
24
-
25
-    /**
26
-     *
27
-     * @var $records_migrated int
28
-     */
29
-    protected $_records_migrated = 0;
30
-
31
-    /**
32
-     * Whether this migration script is done or not. This COULD be deduced by
33
-     * _records_to_migrate and _records_migrated, but that might nto be accurate
34
-     *
35
-     * @var string one of EE_Data_migration_Manager::status_* constants
36
-     */
37
-    protected $_status = null;
38
-
39
-    /**
40
-     * internationalized name of this class. Convention is to NOT restate that
41
-     * this class if a migration script or a migration script stage
42
-     *
43
-     * @var string (i18ned)
44
-     */
45
-    protected $_pretty_name = null;
46
-
47
-    /**
48
-     * @var array
49
-     */
50
-    protected $_errors = array();
51
-
52
-    /**
53
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
54
-     */
55
-    protected $_table_manager;
56
-
57
-    /**
58
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
-     */
60
-    protected $_table_analysis;
61
-
62
-
63
-    /**
64
-     * Just initializes the status of the migration
65
-     *
66
-     * @param TableManager  $table_manager
67
-     * @param TableAnalysis $table_analysis
68
-     */
69
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
-    {
71
-        $this->_table_manager = $table_manager;
72
-        $this->_table_analysis = $table_analysis;
73
-        $this->set_status(EE_Data_Migration_Manager::status_continue);
74
-    }
75
-
76
-
77
-    /**
78
-     * Just gets the pretty name for this migration script or stage
79
-     *
80
-     * @throws EE_Error
81
-     * @return string
82
-     */
83
-    public function pretty_name()
84
-    {
85
-        if ($this->_pretty_name === null) {
86
-            throw new EE_Error(
87
-                sprintf(
88
-                    __(
89
-                        "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
-                        "event_espresso"
91
-                    ),
92
-                    get_class($this)
93
-                )
94
-            );
95
-        }
96
-        return $this->_pretty_name;
97
-    }
98
-
99
-    /**
100
-     *
101
-     * @return int
102
-     */
103
-    public function count_records_to_migrate()
104
-    {
105
-        if ($this->_records_to_migrate == null) {
106
-            $this->_records_to_migrate = $this->_count_records_to_migrate();
107
-        }
108
-        return $this->_records_to_migrate;
109
-    }
110
-
111
-    /**
112
-     * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
-     * EE_Data_migration_Script_Stage
114
-     *
115
-     * @return int
116
-     */
117
-    abstract public function count_records_migrated();
118
-
119
-    /**
120
-     * Counts the records to migrate; the public version may cache it
121
-     *
122
-     * @return int
123
-     */
124
-    abstract protected function _count_records_to_migrate();
125
-
126
-    /**
127
-     * Returns a string indicating the migration script's status.
128
-     *
129
-     * @return string one of EE_Data_Migration_Manager::status_* constants
130
-     * @throws EE_Error
131
-     */
132
-    public function get_status()
133
-    {
134
-        if ($this->_status === null) {
135
-            throw new EE_Error(
136
-                sprintf(
137
-                    __(
138
-                        "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
-                        "event_espresso"
140
-                    ),
141
-                    get_class($this)
142
-                )
143
-            );
144
-        }
145
-        return $this->_status;
146
-    }
147
-
148
-    /**
149
-     *
150
-     * @param string $status
151
-     * @return void
152
-     */
153
-    protected function set_status($status)
154
-    {
155
-        $this->_status = $status;
156
-    }
157
-
158
-    /**
159
-     * @return array of strings
160
-     */
161
-    abstract public function get_errors();
162
-
163
-    /**
164
-     * Returns the last error that occurred. If none occurred, returns null
165
-     *
166
-     * @return string
167
-     */
168
-    public function get_last_error()
169
-    {
170
-        $errors = $this->get_errors();
171
-        if ($errors) {
172
-            return end($errors);
173
-        } else {
174
-            return null;
175
-        }
176
-    }
177
-
178
-    /**
179
-     * Adds an error to the array of errors on this class.
180
-     *
181
-     * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
-     *                       the data that led to the error, and a stack trace etc.
183
-     * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
-     *                       already at their limit, we will purposefully forget the first half
185
-     */
186
-    public function add_error($error, $force = false)
187
-    {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
189
-            $limit = 50;
190
-        } else {
191
-            $limit = EE_DMS_ERROR_LIMIT;
192
-        }
193
-        // make sure errors is an array, see ticket #8261
194
-        if (is_string($this->_errors)) {
195
-            $this->_errors = array($this->_errors);
196
-        }
197
-        if (count($this->_errors) >= $limit) {
198
-            if ($force) {
199
-                // get rid of the first half of the errors and any above the limit
200
-                $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
-                $this->_errors[] = "Limit reached; removed first half of errors to save space";
202
-                $this->_errors[] = $error;
203
-            } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
205
-            }
206
-        } else {
207
-            $this->_errors[] = $error;
208
-        }
209
-    }
210
-
211
-    /**
212
-     * Indicates there was a fatal error and the migration cannot possibly continue
213
-     *
214
-     * @return boolean
215
-     */
216
-    public function is_broken()
217
-    {
218
-        return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
-    }
220
-
221
-    /**
222
-     * @deprecated since 4.6.12
223
-     */
224
-    public function is_borked()
225
-    {
226
-        EE_Error::doing_it_wrong(
227
-            'is_borked',
228
-            __(
229
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
-                'event_espresso'
231
-            ),
232
-            '4.6.12'
233
-        );
234
-        return $this->is_broken();
235
-    }
236
-
237
-    /**
238
-     * Sets the status to as having a fatal error
239
-     */
240
-    public function set_broken()
241
-    {
242
-        $this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
-    }
244
-
245
-    /**
246
-     *
247
-     * @deprecated since 4.6.12
248
-     */
249
-    public function set_borked()
250
-    {
251
-        EE_Error::doing_it_wrong(
252
-            'is_borked',
253
-            __(
254
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
-                'event_espresso'
256
-            ),
257
-            '4.6.12'
258
-        );
259
-        return $this->set_broken();
260
-    }
261
-
262
-    /**
263
-     * Checks if this thing believes it is completed
264
-     *
265
-     * @return boolean
266
-     */
267
-    public function is_completed()
268
-    {
269
-        return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
-    }
271
-
272
-    /**
273
-     * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
-     *
275
-     * @return boolean
276
-     */
277
-    public function has_more_to_do()
278
-    {
279
-        return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
-    }
281
-
282
-    /**
283
-     * Marks that we believe this migration thing is completed
284
-     */
285
-    public function set_completed()
286
-    {
287
-        $this->_status = EE_Data_Migration_Manager::status_completed;
288
-    }
289
-
290
-    /**
291
-     * Marks that we think this migration class can continue to migrate
292
-     */
293
-    public function reattempt()
294
-    {
295
-        $this->_status = EE_Data_Migration_Manager::status_continue;
296
-        $this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
-    }
298
-
299
-    /**
300
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
-     * properties to the DB. However, we don't want to use __sleep() because its quite
302
-     * possible that this class is defined when it goes to sleep, but NOT available when it
303
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
304
-     */
305
-    public function properties_as_array()
306
-    {
307
-        $properties = get_object_vars($this);
308
-        $properties['class'] = get_class($this);
309
-        unset($properties['_migration_script']);
310
-        unset($properties['_table_manager']);
311
-        unset($properties['_table_analysis']);
312
-        return $properties;
313
-    }
314
-
315
-    /**
316
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
-     * to have been made from the properties_as_array() function.
318
-     *
319
-     * @param array $array_of_properties like what's produced from properties_as_array() method
320
-     */
321
-    abstract public function instantiate_from_array_of_properties($array_of_properties);
322
-
323
-    /**
324
-     * Convenience method for showing a database insertion error
325
-     *
326
-     * @param string $old_table
327
-     * @param array  $old_row_as_array
328
-     * @param string $new_table
329
-     * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
-     * @param array  $data_types       numerically indexed
331
-     * @return string
332
-     */
333
-    protected function _create_error_message_for_db_insertion(
334
-        $old_table,
335
-        $old_row_as_array,
336
-        $new_table,
337
-        $new_row_as_array,
338
-        $data_types
339
-    ) {
340
-        global $wpdb;
341
-        $old_columns_and_values_for_string = array();
342
-        foreach ($old_row_as_array as $column => $value) {
343
-            $old_columns_and_values_for_string[] = "$column => $value";
344
-        }
345
-        $new_columns_and_values_for_string = array();
346
-        $count = 0;
347
-        foreach ($new_row_as_array as $column => $value) {
348
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
-        }
350
-        return sprintf(
351
-            __(
352
-                'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
-                'event_espresso'
354
-            ),
355
-            implode(", ", $new_columns_and_values_for_string),
356
-            $new_table,
357
-            implode(", ", $old_columns_and_values_for_string),
358
-            $old_table,
359
-            '<br/>',
360
-            $wpdb->last_error
361
-        );
362
-    }
363
-
364
-
365
-    /**
366
-     * Same as json_encode, just avoids putting
367
-     * serialized arrays into the http build query, as that would
368
-     *
369
-     * @param array $array_of_data
370
-     * @return string
371
-     */
372
-    protected function _json_encode($array_of_data)
373
-    {
374
-        // we'd rather NOT serialize the transaction details
375
-        $fields_to_include = array();
376
-        foreach ($array_of_data as $name => $value) {
377
-            $unserialized_data = @unserialize($value);
378
-            if ($unserialized_data === false) {
379
-                $fields_to_include[ $name ] = $value;
380
-            }
381
-        }
382
-        return wp_json_encode($fields_to_include);
383
-    }
384
-
385
-    /**
386
-     * Gets the table manager (or throws an exception if it cannot be retrieved)
387
-     *
388
-     * @return TableManager
389
-     * @throws EE_Error
390
-     */
391
-    protected function _get_table_manager()
392
-    {
393
-        if ($this->_table_manager instanceof TableManager) {
394
-            return $this->_table_manager;
395
-        } else {
396
-            throw new EE_Error(
397
-                sprintf(
398
-                    __('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
-                    get_class($this)
400
-                )
401
-            );
402
-        }
403
-    }
404
-
405
-    /**
406
-     * Gets the injected table analyzer, or throws an exception
407
-     *
408
-     * @return TableAnalysis
409
-     * @throws EE_Error
410
-     */
411
-    protected function _get_table_analysis()
412
-    {
413
-        if ($this->_table_analysis instanceof TableAnalysis) {
414
-            return $this->_table_analysis;
415
-        } else {
416
-            throw new EE_Error(
417
-                sprintf(
418
-                    __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
-                    get_class($this)
420
-                )
421
-            );
422
-        }
423
-    }
20
+	/**
21
+	 * @var $records_to_migrate int count of all that have been migrated
22
+	 */
23
+	protected $_records_to_migrate = 0;
24
+
25
+	/**
26
+	 *
27
+	 * @var $records_migrated int
28
+	 */
29
+	protected $_records_migrated = 0;
30
+
31
+	/**
32
+	 * Whether this migration script is done or not. This COULD be deduced by
33
+	 * _records_to_migrate and _records_migrated, but that might nto be accurate
34
+	 *
35
+	 * @var string one of EE_Data_migration_Manager::status_* constants
36
+	 */
37
+	protected $_status = null;
38
+
39
+	/**
40
+	 * internationalized name of this class. Convention is to NOT restate that
41
+	 * this class if a migration script or a migration script stage
42
+	 *
43
+	 * @var string (i18ned)
44
+	 */
45
+	protected $_pretty_name = null;
46
+
47
+	/**
48
+	 * @var array
49
+	 */
50
+	protected $_errors = array();
51
+
52
+	/**
53
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
54
+	 */
55
+	protected $_table_manager;
56
+
57
+	/**
58
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
+	 */
60
+	protected $_table_analysis;
61
+
62
+
63
+	/**
64
+	 * Just initializes the status of the migration
65
+	 *
66
+	 * @param TableManager  $table_manager
67
+	 * @param TableAnalysis $table_analysis
68
+	 */
69
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
+	{
71
+		$this->_table_manager = $table_manager;
72
+		$this->_table_analysis = $table_analysis;
73
+		$this->set_status(EE_Data_Migration_Manager::status_continue);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Just gets the pretty name for this migration script or stage
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @return string
82
+	 */
83
+	public function pretty_name()
84
+	{
85
+		if ($this->_pretty_name === null) {
86
+			throw new EE_Error(
87
+				sprintf(
88
+					__(
89
+						"Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
+						"event_espresso"
91
+					),
92
+					get_class($this)
93
+				)
94
+			);
95
+		}
96
+		return $this->_pretty_name;
97
+	}
98
+
99
+	/**
100
+	 *
101
+	 * @return int
102
+	 */
103
+	public function count_records_to_migrate()
104
+	{
105
+		if ($this->_records_to_migrate == null) {
106
+			$this->_records_to_migrate = $this->_count_records_to_migrate();
107
+		}
108
+		return $this->_records_to_migrate;
109
+	}
110
+
111
+	/**
112
+	 * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
+	 * EE_Data_migration_Script_Stage
114
+	 *
115
+	 * @return int
116
+	 */
117
+	abstract public function count_records_migrated();
118
+
119
+	/**
120
+	 * Counts the records to migrate; the public version may cache it
121
+	 *
122
+	 * @return int
123
+	 */
124
+	abstract protected function _count_records_to_migrate();
125
+
126
+	/**
127
+	 * Returns a string indicating the migration script's status.
128
+	 *
129
+	 * @return string one of EE_Data_Migration_Manager::status_* constants
130
+	 * @throws EE_Error
131
+	 */
132
+	public function get_status()
133
+	{
134
+		if ($this->_status === null) {
135
+			throw new EE_Error(
136
+				sprintf(
137
+					__(
138
+						"Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
+						"event_espresso"
140
+					),
141
+					get_class($this)
142
+				)
143
+			);
144
+		}
145
+		return $this->_status;
146
+	}
147
+
148
+	/**
149
+	 *
150
+	 * @param string $status
151
+	 * @return void
152
+	 */
153
+	protected function set_status($status)
154
+	{
155
+		$this->_status = $status;
156
+	}
157
+
158
+	/**
159
+	 * @return array of strings
160
+	 */
161
+	abstract public function get_errors();
162
+
163
+	/**
164
+	 * Returns the last error that occurred. If none occurred, returns null
165
+	 *
166
+	 * @return string
167
+	 */
168
+	public function get_last_error()
169
+	{
170
+		$errors = $this->get_errors();
171
+		if ($errors) {
172
+			return end($errors);
173
+		} else {
174
+			return null;
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * Adds an error to the array of errors on this class.
180
+	 *
181
+	 * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
+	 *                       the data that led to the error, and a stack trace etc.
183
+	 * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
+	 *                       already at their limit, we will purposefully forget the first half
185
+	 */
186
+	public function add_error($error, $force = false)
187
+	{
188
+		if (! defined('EE_DMS_ERROR_LIMIT')) {
189
+			$limit = 50;
190
+		} else {
191
+			$limit = EE_DMS_ERROR_LIMIT;
192
+		}
193
+		// make sure errors is an array, see ticket #8261
194
+		if (is_string($this->_errors)) {
195
+			$this->_errors = array($this->_errors);
196
+		}
197
+		if (count($this->_errors) >= $limit) {
198
+			if ($force) {
199
+				// get rid of the first half of the errors and any above the limit
200
+				$this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
+				$this->_errors[] = "Limit reached; removed first half of errors to save space";
202
+				$this->_errors[] = $error;
203
+			} else {
204
+				$this->_errors[ $limit ] = 'More, but limit reached...';
205
+			}
206
+		} else {
207
+			$this->_errors[] = $error;
208
+		}
209
+	}
210
+
211
+	/**
212
+	 * Indicates there was a fatal error and the migration cannot possibly continue
213
+	 *
214
+	 * @return boolean
215
+	 */
216
+	public function is_broken()
217
+	{
218
+		return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
+	}
220
+
221
+	/**
222
+	 * @deprecated since 4.6.12
223
+	 */
224
+	public function is_borked()
225
+	{
226
+		EE_Error::doing_it_wrong(
227
+			'is_borked',
228
+			__(
229
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
+				'event_espresso'
231
+			),
232
+			'4.6.12'
233
+		);
234
+		return $this->is_broken();
235
+	}
236
+
237
+	/**
238
+	 * Sets the status to as having a fatal error
239
+	 */
240
+	public function set_broken()
241
+	{
242
+		$this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
+	}
244
+
245
+	/**
246
+	 *
247
+	 * @deprecated since 4.6.12
248
+	 */
249
+	public function set_borked()
250
+	{
251
+		EE_Error::doing_it_wrong(
252
+			'is_borked',
253
+			__(
254
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
+				'event_espresso'
256
+			),
257
+			'4.6.12'
258
+		);
259
+		return $this->set_broken();
260
+	}
261
+
262
+	/**
263
+	 * Checks if this thing believes it is completed
264
+	 *
265
+	 * @return boolean
266
+	 */
267
+	public function is_completed()
268
+	{
269
+		return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
+	}
271
+
272
+	/**
273
+	 * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
+	 *
275
+	 * @return boolean
276
+	 */
277
+	public function has_more_to_do()
278
+	{
279
+		return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
+	}
281
+
282
+	/**
283
+	 * Marks that we believe this migration thing is completed
284
+	 */
285
+	public function set_completed()
286
+	{
287
+		$this->_status = EE_Data_Migration_Manager::status_completed;
288
+	}
289
+
290
+	/**
291
+	 * Marks that we think this migration class can continue to migrate
292
+	 */
293
+	public function reattempt()
294
+	{
295
+		$this->_status = EE_Data_Migration_Manager::status_continue;
296
+		$this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
+	}
298
+
299
+	/**
300
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
302
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
303
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
304
+	 */
305
+	public function properties_as_array()
306
+	{
307
+		$properties = get_object_vars($this);
308
+		$properties['class'] = get_class($this);
309
+		unset($properties['_migration_script']);
310
+		unset($properties['_table_manager']);
311
+		unset($properties['_table_analysis']);
312
+		return $properties;
313
+	}
314
+
315
+	/**
316
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
+	 * to have been made from the properties_as_array() function.
318
+	 *
319
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
320
+	 */
321
+	abstract public function instantiate_from_array_of_properties($array_of_properties);
322
+
323
+	/**
324
+	 * Convenience method for showing a database insertion error
325
+	 *
326
+	 * @param string $old_table
327
+	 * @param array  $old_row_as_array
328
+	 * @param string $new_table
329
+	 * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
+	 * @param array  $data_types       numerically indexed
331
+	 * @return string
332
+	 */
333
+	protected function _create_error_message_for_db_insertion(
334
+		$old_table,
335
+		$old_row_as_array,
336
+		$new_table,
337
+		$new_row_as_array,
338
+		$data_types
339
+	) {
340
+		global $wpdb;
341
+		$old_columns_and_values_for_string = array();
342
+		foreach ($old_row_as_array as $column => $value) {
343
+			$old_columns_and_values_for_string[] = "$column => $value";
344
+		}
345
+		$new_columns_and_values_for_string = array();
346
+		$count = 0;
347
+		foreach ($new_row_as_array as $column => $value) {
348
+			$new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
+		}
350
+		return sprintf(
351
+			__(
352
+				'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
+				'event_espresso'
354
+			),
355
+			implode(", ", $new_columns_and_values_for_string),
356
+			$new_table,
357
+			implode(", ", $old_columns_and_values_for_string),
358
+			$old_table,
359
+			'<br/>',
360
+			$wpdb->last_error
361
+		);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Same as json_encode, just avoids putting
367
+	 * serialized arrays into the http build query, as that would
368
+	 *
369
+	 * @param array $array_of_data
370
+	 * @return string
371
+	 */
372
+	protected function _json_encode($array_of_data)
373
+	{
374
+		// we'd rather NOT serialize the transaction details
375
+		$fields_to_include = array();
376
+		foreach ($array_of_data as $name => $value) {
377
+			$unserialized_data = @unserialize($value);
378
+			if ($unserialized_data === false) {
379
+				$fields_to_include[ $name ] = $value;
380
+			}
381
+		}
382
+		return wp_json_encode($fields_to_include);
383
+	}
384
+
385
+	/**
386
+	 * Gets the table manager (or throws an exception if it cannot be retrieved)
387
+	 *
388
+	 * @return TableManager
389
+	 * @throws EE_Error
390
+	 */
391
+	protected function _get_table_manager()
392
+	{
393
+		if ($this->_table_manager instanceof TableManager) {
394
+			return $this->_table_manager;
395
+		} else {
396
+			throw new EE_Error(
397
+				sprintf(
398
+					__('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
+					get_class($this)
400
+				)
401
+			);
402
+		}
403
+	}
404
+
405
+	/**
406
+	 * Gets the injected table analyzer, or throws an exception
407
+	 *
408
+	 * @return TableAnalysis
409
+	 * @throws EE_Error
410
+	 */
411
+	protected function _get_table_analysis()
412
+	{
413
+		if ($this->_table_analysis instanceof TableAnalysis) {
414
+			return $this->_table_analysis;
415
+		} else {
416
+			throw new EE_Error(
417
+				sprintf(
418
+					__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
+					get_class($this)
420
+				)
421
+			);
422
+		}
423
+	}
424 424
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message_Template_Group.model.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param        $messenger
85 85
      * @param string $orderby
86 86
      * @param string $order
87
-     * @return array all (including trashed or inactive) message template group objects for the given messenger
87
+     * @return EE_Base_Class[] all (including trashed or inactive) message template group objects for the given messenger
88 88
      */
89 89
     public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
90 90
     {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
     /**
342 342
      * This sends things to the validator for the given messenger and message type.
343 343
      *
344
-     * @param  array $fields the incoming fields to check.
344
+     * @param  string $fields the incoming fields to check.
345 345
      *                       Note this array is in the formatted fields from the form fields setup.
346 346
      *                       So we need to reformat this into an array of expected field refs by the validator.
347 347
      *                       Note also that this is not only the fields for the Message Template Group
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             'WP_User' => new EE_Belongs_To_Relation()
45 45
         );
46 46
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
47
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
47
+            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global');
48 48
         }
49 49
         $this->_caps_slug = 'messages';
50 50
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         $limit = null,
72 72
         $count = false
73 73
     ) {
74
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
74
+        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit);
75 75
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
76 76
     }
77 77
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
90 90
     {
91 91
         return $this->get_all_deleted_and_undeleted(
92
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
92
+            array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order))
93 93
         );
94 94
     }
95 95
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
             && $_REQUEST['ee_messenger_filter_by'] != 'none_selected'
108 108
             && $_REQUEST['ee_messenger_filter_by'] != 'all'
109 109
         ) {
110
-            $_where['MTP_messenger'] =  $_REQUEST['ee_messenger_filter_by'] ;
110
+            $_where['MTP_messenger'] = $_REQUEST['ee_messenger_filter_by'];
111 111
         }
112 112
 
113 113
         if (isset($_REQUEST['ee_message_type_filter_by'])
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         $global = true,
142 142
         $user_check = false
143 143
     ) {
144
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
144
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
145 145
         $_where['MTP_is_active'] = true;
146 146
         $_where = $this->_maybe_mtp_filters($_where);
147 147
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $_where['MTP_user_id'] = get_current_user_id();
156 156
         }
157 157
 
158
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
158
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
159 159
 
160 160
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
161 161
     }
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     {
177 177
         $_where = $this->_maybe_mtp_filters();
178 178
 
179
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
179
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
180 180
 
181 181
         $r_templates = $count
182 182
             ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
198 198
     {
199
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
199
+        $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID));
200 200
         return $this->get_all(
201
-            array( $where )
201
+            array($where)
202 202
         );
203 203
     }
204 204
 
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
         $count = false,
224 224
         $global = true
225 225
     ) {
226
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
226
+        $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false);
227 227
         $_where['MTP_is_active'] = true;
228 228
         $_where = $this->_maybe_mtp_filters($_where);
229 229
 
230
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
230
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
231 231
 
232 232
         return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
233 233
     }
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
             'MTP_is_active' => $active
266 266
         );
267 267
 
268
-        $query_params = array( $_where, 'order_by' => array($orderby=>$order), 'limit' => $limit );
268
+        $query_params = array($_where, 'order_by' => array($orderby=>$order), 'limit' => $limit);
269 269
 
270 270
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
271 271
     }
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             $_where['MTP_is_active'] = $active;
306 306
         }
307 307
 
308
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
308
+        $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
309 309
 
310 310
         return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
311 311
     }
@@ -363,19 +363,19 @@  discard block
 block discarded – undo
363 363
             // first let's figure out if the value['content'] in the current index is an array.
364 364
             //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
365 365
             if (is_array($value['content'])) {
366
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
366
+                $assembled_fields[$value['name']] = $value['content']['main'];
367 367
                 // loop through the content and get the other fields.
368 368
                 foreach ($value['content'] as $name => $val) {
369 369
                     if ($name == 'main') {
370 370
                         continue;
371 371
                     }
372
-                    $assembled_fields[ $name ] = $val;
372
+                    $assembled_fields[$name] = $val;
373 373
                 }
374 374
                 continue;
375 375
             }
376 376
 
377 377
             // okay if we're here then this is just a straight field=>$value arrangement
378
-            $assembled_fields[ $value['name'] ] = $value['content'];
378
+            $assembled_fields[$value['name']] = $value['content'];
379 379
         }
380 380
 
381 381
         // now we've got the assembled_fields.
@@ -385,9 +385,9 @@  discard block
 block discarded – undo
385 385
         $mt_ref = ucwords(str_replace('_', ' ', $message_type));
386 386
         $mt_ref = str_replace(' ', '_', $mt_ref);
387 387
 
388
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
388
+        $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator';
389 389
 
390
-        if (!class_exists($classname)) {
390
+        if ( ! class_exists($classname)) {
391 391
             $msg[] = __('The Validator class was unable to load', 'event_espresso');
392 392
             $msg[] = sprintf(
393 393
                 __(
@@ -425,12 +425,12 @@  discard block
 block discarded – undo
425 425
         if (empty($messenger_names) && empty($message_type_names)) {
426 426
             return 0;
427 427
         }
428
-        if (! empty($messenger_names)) {
429
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
428
+        if ( ! empty($messenger_names)) {
429
+            $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names);
430 430
         }
431
-        if (! empty($message_type_names)) {
432
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
431
+        if ( ! empty($message_type_names)) {
432
+            $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names);
433 433
         }
434
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
434
+        return $this->update(array('MTP_is_active' => false), $query_args);
435 435
     }
436 436
 }
Please login to merge, or discard this patch.
Indentation   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -11,426 +11,426 @@
 block discarded – undo
11 11
 class EEM_Message_Template_Group extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    // private instance of the EEM_Message_Template_Group object
15
-    protected static $_instance = null;
16
-
17
-
18
-
19
-    protected function __construct($timezone = null)
20
-    {
21
-        $this->singular_item = __('Message Template Group', 'event_espresso');
22
-        $this->plural_item = __('Message Template Groups', 'event_espresso');
23
-        $this->_tables = array(
24
-            'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
25
-        );
26
-        $this->_fields = array(
27
-            'Message_Template_Group' => array(
28
-                'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso')),
29
-                'MTP_name' => new EE_Plain_Text_Field('MTP_name', __('The name of the template group', 'event_espresso'), false, ''),
30
-                'MTP_description' => new EE_Simple_HTML_Field('MTP_description', __('A brief description about this template.', 'event_espresso'), false, ''),
31
-                'MTP_user_id'=> new EE_WP_User_Field('MTP_user_id', __('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
32
-                'MTP_messenger'=>new EE_Plain_Text_Field('MTP_messenger', __('Messenger Used for Template', 'event_espresso'), false, 'email'),
33
-                'MTP_message_type'=>new EE_Plain_Text_Field('MTP_message_type', __('Message Type', 'event_espresso'), false, 'registration'),
34
-                'MTP_is_global'=>new EE_Boolean_Field('MTP_is_global', __('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
35
-                'MTP_is_override'=>new EE_Boolean_Field('MTP_is_override', __('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
36
-                'MTP_deleted'=>new EE_Trashed_Flag_Field('MTP_deleted', __('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
37
-                'MTP_is_active'=>new EE_Boolean_Field('MTP_is_active', __('Flag indicating whether template group is active', 'event_espresso'), false, true)
38
-            )
39
-        );
40
-        $this->_model_relations = array(
41
-            'Message_Template' => new EE_Has_Many_Relation(),
42
-            'Message' => new EE_Has_Many_Relation(),
43
-            'Event' => new EE_HABTM_Relation('Event_Message_Template'),
44
-            'WP_User' => new EE_Belongs_To_Relation()
45
-        );
46
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
47
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
48
-        }
49
-        $this->_caps_slug = 'messages';
50
-
51
-        parent::__construct($timezone);
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     * get_all_trashed_message_templates_by_event
58
-     *
59
-     * @access public
60
-     * @param int    $EVT_ID specific event id
61
-     * @param string $orderby
62
-     * @param string $order
63
-     * @param null   $limit
64
-     * @param bool   $count
65
-     * @return array message template objects that are attached to a specific event.
66
-     */
67
-    public function get_all_trashed_message_templates_by_event(
68
-        $EVT_ID,
69
-        $orderby = 'GRP_ID',
70
-        $order = 'ASC',
71
-        $limit = null,
72
-        $count = false
73
-    ) {
74
-        $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
75
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * get_all_message_templates_by_messenger
82
-     *
83
-     * @access public
84
-     * @param        $messenger
85
-     * @param string $orderby
86
-     * @param string $order
87
-     * @return array all (including trashed or inactive) message template group objects for the given messenger
88
-     */
89
-    public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
90
-    {
91
-        return $this->get_all_deleted_and_undeleted(
92
-            array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
93
-        );
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     * This simply adds on any messenger/message type filters that may be present in the $_POST global
100
-     * @param  array  $_where any existing where conditions to append these to.
101
-     * @return array          original where conditions or original with additional filters.
102
-     */
103
-    protected function _maybe_mtp_filters($_where = array())
104
-    {
105
-        // account for messenger or message type filters
106
-        if (isset($_REQUEST['ee_messenger_filter_by'])
107
-            && $_REQUEST['ee_messenger_filter_by'] != 'none_selected'
108
-            && $_REQUEST['ee_messenger_filter_by'] != 'all'
109
-        ) {
110
-            $_where['MTP_messenger'] =  $_REQUEST['ee_messenger_filter_by'] ;
111
-        }
112
-
113
-        if (isset($_REQUEST['ee_message_type_filter_by'])
114
-            && $_REQUEST['ee_message_type_filter_by'] != 'none_selected'
115
-        ) {
116
-            $_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by'];
117
-        }
118
-
119
-        return $_where;
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * get_all_active_message_templates groups
126
-     *
127
-     * @access public
128
-     * @param string $orderby
129
-     * @param string $order
130
-     * @param null   $limit
131
-     * @param bool   $count
132
-     * @param bool   $global
133
-     * @param bool   $user_check
134
-     * @return array all active (non_trashed, active) message template objects
135
-     */
136
-    public function get_all_active_message_templates(
137
-        $orderby = 'GRP_ID',
138
-        $order = 'ASC',
139
-        $limit = null,
140
-        $count = false,
141
-        $global = true,
142
-        $user_check = false
143
-    ) {
144
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
145
-        $_where['MTP_is_active'] = true;
146
-        $_where = $this->_maybe_mtp_filters($_where);
147
-
148
-        if ($user_check
149
-            && ! $global
150
-            && ! EE_Registry::instance()->CAP->current_user_can(
151
-                'ee_read_others_messages',
152
-                'get_all_active_message_templates'
153
-            )
154
-        ) {
155
-            $_where['MTP_user_id'] = get_current_user_id();
156
-        }
157
-
158
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
159
-
160
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     *    retrieve ALL message_template groups from db regardless of wht
167
-     *
168
-     * @access    public
169
-     * @param string $orderby
170
-     * @param string $order
171
-     * @param null   $limit
172
-     * @param bool   $count
173
-     * @return mixed array on success, FALSE on fail
174
-     */
175
-    public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
176
-    {
177
-        $_where = $this->_maybe_mtp_filters();
178
-
179
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
180
-
181
-        $r_templates = $count
182
-            ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
183
-            : $this->get_all_deleted_and_undeleted($query_params);
184
-
185
-        return $r_templates;
186
-    }
187
-
188
-
189
-
190
-
191
-    /**
192
-     * This gets all the custom templates attached to a specific event
193
-     * @param  int      $EVT_ID         event id
194
-     * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
195
-     * @return  EE_Message_Template_Group[]
196
-     */
197
-    public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
198
-    {
199
-        $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
200
-        return $this->get_all(
201
-            array( $where )
202
-        );
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * get_all_trashed_grouped_message_templates
209
-     * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
210
-     *
211
-     * @access public
212
-     * @param string $orderby
213
-     * @param string $order
214
-     * @param null   $limit
215
-     * @param bool   $count
216
-     * @param bool   $global
217
-     * @return \EE_Message_Template_Group[] message template groups.
218
-     */
219
-    public function get_all_trashed_grouped_message_templates(
220
-        $orderby = 'GRP_ID',
221
-        $order = 'ASC',
222
-        $limit = null,
223
-        $count = false,
224
-        $global = true
225
-    ) {
226
-        $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
227
-        $_where['MTP_is_active'] = true;
228
-        $_where = $this->_maybe_mtp_filters($_where);
229
-
230
-        $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
231
-
232
-        return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
233
-    }
234
-
235
-
236
-
237
-    /**
238
-     * this returns the message template group(s) for a given event, messenger, and message template
239
-     *
240
-     * @param  string             $messenger
241
-     * @param  string             $message_type
242
-     * @param                     $evt_id
243
-     * @param  string             $orderby pointless at this point but still included
244
-     * @param  string             $order
245
-     * @param  mixed (array|null) $limit   array($offset, $num)
246
-     * @param  bool               $count   true = just return count, false = objects
247
-     * @param  bool               $active  ignore "active" or not. (default only return active)
248
-     * @return \mixed[]) depending on $count.
249
-     */
250
-    public function get_event_message_templates_by_m_and_mt_and_evt(
251
-        $messenger,
252
-        $message_type,
253
-        $evt_id,
254
-        $orderby = 'GRP_ID',
255
-        $order = 'ASC',
256
-        $limit = null,
257
-        $count = false,
258
-        $active = true
259
-    ) {
260
-        $_where = array(
261
-            'MTP_messenger' => $messenger,
262
-            'MTP_message_type' => $message_type,
263
-            'Event.EVT_ID' => $evt_id,
264
-            'MTP_is_global' => true,
265
-            'MTP_is_active' => $active
266
-        );
267
-
268
-        $query_params = array( $_where, 'order_by' => array($orderby=>$order), 'limit' => $limit );
269
-
270
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
271
-    }
272
-
273
-
274
-
275
-
276
-    /**
277
-     * get all GLOBAL message template groups for the given messenger and message type
278
-     *
279
-     * @param  string $messenger    slug for messenger
280
-     * @param  string $message_type slug for message type
281
-     * @param  string $orderby      what column to orderby
282
-     * @param  string $order        ASC or DESC
283
-     * @param  mixed (array|null) $limit array($offset, $num)
284
-     * @param  bool   $count        true = just return count, false = objects
285
-     * @param  bool   $active       ignore "active" or not. (default only return active) -
286
-     *                              'all' means return both inactive AND inactive.
287
-     * @return array               message template objects that are global (i.e. non-event)
288
-     */
289
-    public function get_global_message_template_by_m_and_mt(
290
-        $messenger,
291
-        $message_type,
292
-        $orderby = 'GRP_ID',
293
-        $order = 'ASC',
294
-        $limit = null,
295
-        $count = false,
296
-        $active = true
297
-    ) {
298
-        $_where = array(
299
-            'MTP_messenger' => $messenger,
300
-            'MTP_message_type' => $message_type,
301
-            'MTP_is_global' => true,
302
-        );
303
-
304
-        if ($active != 'all') {
305
-            $_where['MTP_is_active'] = $active;
306
-        }
307
-
308
-        $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
309
-
310
-        return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
311
-    }
312
-
313
-
314
-
315
-
316
-    /**
317
-     * get all custom message template groups for the given messenger and message type
318
-     * @param  string $messenger    messenger
319
-     * @param  string $message_type messagetype
320
-     * @param  array  $query_params same as EEM_Base->get_all()
321
-     * @return EE_Message_Template_Group[]
322
-     */
323
-    public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
324
-    {
325
-        return $this->get_all(
326
-            array_merge(
327
-                $query_params,
328
-                array(
329
-                    array(
330
-                        'MTP_is_global'    => false,
331
-                        'MTP_messenger'    => $messenger,
332
-                        'MTP_message_type' => $message_type
333
-                    )
334
-                )
335
-            )
336
-        );
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * This sends things to the validator for the given messenger and message type.
343
-     *
344
-     * @param  array $fields the incoming fields to check.
345
-     *                       Note this array is in the formatted fields from the form fields setup.
346
-     *                       So we need to reformat this into an array of expected field refs by the validator.
347
-     *                       Note also that this is not only the fields for the Message Template Group
348
-     *                       but ALSO for Message Template.
349
-     * @param string $context      The context the fields were obtained from.
350
-     * @param string $messenger    The messenger we are validating
351
-     * @param string $message_type The message type we are validating.
352
-     * @return mixed If the fields all check out then we return true otherwise error messages are returned
353
-     *                       (indexed by field name);
354
-     * @throws \EE_Error
355
-     */
356
-    public function validate($fields, $context, $messenger, $message_type)
357
-    {
358
-
359
-        $assembled_fields = array();
360
-
361
-        // let's loop through all the fields and set them up in the right format
362
-        foreach ($fields as $index => $value) {
363
-            // first let's figure out if the value['content'] in the current index is an array.
364
-            //  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
365
-            if (is_array($value['content'])) {
366
-                $assembled_fields[ $value['name'] ] = $value['content']['main'];
367
-                // loop through the content and get the other fields.
368
-                foreach ($value['content'] as $name => $val) {
369
-                    if ($name == 'main') {
370
-                        continue;
371
-                    }
372
-                    $assembled_fields[ $name ] = $val;
373
-                }
374
-                continue;
375
-            }
376
-
377
-            // okay if we're here then this is just a straight field=>$value arrangement
378
-            $assembled_fields[ $value['name'] ] = $value['content'];
379
-        }
380
-
381
-        // now we've got the assembled_fields.
382
-        // We need to setup the string for the appropriate validator class and call that.
383
-        $m_ref = ucwords(str_replace('_', ' ', $messenger));
384
-        $m_ref = str_replace(' ', '_', $m_ref);
385
-        $mt_ref = ucwords(str_replace('_', ' ', $message_type));
386
-        $mt_ref = str_replace(' ', '_', $mt_ref);
387
-
388
-        $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
389
-
390
-        if (!class_exists($classname)) {
391
-            $msg[] = __('The Validator class was unable to load', 'event_espresso');
392
-            $msg[] = sprintf(
393
-                __(
394
-                    'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
395
-                    'event_espresso'
396
-                ),
397
-                $classname
398
-            );
399
-            throw new EE_Error(implode('||', $msg));
400
-        }
401
-
402
-        $a = new ReflectionClass($classname);
403
-        $_VLD = $a->newInstance($assembled_fields, $context);
404
-        $result = $_VLD->validate();
405
-        return $result;
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * Updates all message template groups matching the incoming arguments to inactive status.
412
-     *
413
-     * @param array $messenger_names    The messenger slugs.
414
-     *                              If empty then all templates matching the message types are marked inactive.
415
-     *                              Otherwise only templates matching the messengers and message types.
416
-     * @param array $message_type_names     The message type slugs.
417
-     *                              If empty then all templates matching the messengers are marked inactive.
418
-     *                              Otherwise only templates matching the messengers and message types.
419
-     *
420
-     * @return int  count of updated records.
421
-     */
422
-    public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
423
-    {
424
-        $query_args = array();
425
-        if (empty($messenger_names) && empty($message_type_names)) {
426
-            return 0;
427
-        }
428
-        if (! empty($messenger_names)) {
429
-            $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
430
-        }
431
-        if (! empty($message_type_names)) {
432
-            $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
433
-        }
434
-        return $this->update(array( 'MTP_is_active' => false ), $query_args);
435
-    }
14
+	// private instance of the EEM_Message_Template_Group object
15
+	protected static $_instance = null;
16
+
17
+
18
+
19
+	protected function __construct($timezone = null)
20
+	{
21
+		$this->singular_item = __('Message Template Group', 'event_espresso');
22
+		$this->plural_item = __('Message Template Groups', 'event_espresso');
23
+		$this->_tables = array(
24
+			'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID')
25
+		);
26
+		$this->_fields = array(
27
+			'Message_Template_Group' => array(
28
+				'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso')),
29
+				'MTP_name' => new EE_Plain_Text_Field('MTP_name', __('The name of the template group', 'event_espresso'), false, ''),
30
+				'MTP_description' => new EE_Simple_HTML_Field('MTP_description', __('A brief description about this template.', 'event_espresso'), false, ''),
31
+				'MTP_user_id'=> new EE_WP_User_Field('MTP_user_id', __('Template Creator ID', 'event_espresso'), false, get_current_user_id()),
32
+				'MTP_messenger'=>new EE_Plain_Text_Field('MTP_messenger', __('Messenger Used for Template', 'event_espresso'), false, 'email'),
33
+				'MTP_message_type'=>new EE_Plain_Text_Field('MTP_message_type', __('Message Type', 'event_espresso'), false, 'registration'),
34
+				'MTP_is_global'=>new EE_Boolean_Field('MTP_is_global', __('Flag indicating if Template Group is Global', 'event_espresso'), false, true),
35
+				'MTP_is_override'=>new EE_Boolean_Field('MTP_is_override', __('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false),
36
+				'MTP_deleted'=>new EE_Trashed_Flag_Field('MTP_deleted', __('Flag indicating whether this has been trashed', 'event_espresso'), false, false),
37
+				'MTP_is_active'=>new EE_Boolean_Field('MTP_is_active', __('Flag indicating whether template group is active', 'event_espresso'), false, true)
38
+			)
39
+		);
40
+		$this->_model_relations = array(
41
+			'Message_Template' => new EE_Has_Many_Relation(),
42
+			'Message' => new EE_Has_Many_Relation(),
43
+			'Event' => new EE_HABTM_Relation('Event_Message_Template'),
44
+			'WP_User' => new EE_Belongs_To_Relation()
45
+		);
46
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
47
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global');
48
+		}
49
+		$this->_caps_slug = 'messages';
50
+
51
+		parent::__construct($timezone);
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 * get_all_trashed_message_templates_by_event
58
+	 *
59
+	 * @access public
60
+	 * @param int    $EVT_ID specific event id
61
+	 * @param string $orderby
62
+	 * @param string $order
63
+	 * @param null   $limit
64
+	 * @param bool   $count
65
+	 * @return array message template objects that are attached to a specific event.
66
+	 */
67
+	public function get_all_trashed_message_templates_by_event(
68
+		$EVT_ID,
69
+		$orderby = 'GRP_ID',
70
+		$order = 'ASC',
71
+		$limit = null,
72
+		$count = false
73
+	) {
74
+		$query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit );
75
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * get_all_message_templates_by_messenger
82
+	 *
83
+	 * @access public
84
+	 * @param        $messenger
85
+	 * @param string $orderby
86
+	 * @param string $order
87
+	 * @return array all (including trashed or inactive) message template group objects for the given messenger
88
+	 */
89
+	public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC')
90
+	{
91
+		return $this->get_all_deleted_and_undeleted(
92
+			array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) )
93
+		);
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 * This simply adds on any messenger/message type filters that may be present in the $_POST global
100
+	 * @param  array  $_where any existing where conditions to append these to.
101
+	 * @return array          original where conditions or original with additional filters.
102
+	 */
103
+	protected function _maybe_mtp_filters($_where = array())
104
+	{
105
+		// account for messenger or message type filters
106
+		if (isset($_REQUEST['ee_messenger_filter_by'])
107
+			&& $_REQUEST['ee_messenger_filter_by'] != 'none_selected'
108
+			&& $_REQUEST['ee_messenger_filter_by'] != 'all'
109
+		) {
110
+			$_where['MTP_messenger'] =  $_REQUEST['ee_messenger_filter_by'] ;
111
+		}
112
+
113
+		if (isset($_REQUEST['ee_message_type_filter_by'])
114
+			&& $_REQUEST['ee_message_type_filter_by'] != 'none_selected'
115
+		) {
116
+			$_where['MTP_message_type'] = $_REQUEST['ee_message_type_filter_by'];
117
+		}
118
+
119
+		return $_where;
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * get_all_active_message_templates groups
126
+	 *
127
+	 * @access public
128
+	 * @param string $orderby
129
+	 * @param string $order
130
+	 * @param null   $limit
131
+	 * @param bool   $count
132
+	 * @param bool   $global
133
+	 * @param bool   $user_check
134
+	 * @return array all active (non_trashed, active) message template objects
135
+	 */
136
+	public function get_all_active_message_templates(
137
+		$orderby = 'GRP_ID',
138
+		$order = 'ASC',
139
+		$limit = null,
140
+		$count = false,
141
+		$global = true,
142
+		$user_check = false
143
+	) {
144
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
145
+		$_where['MTP_is_active'] = true;
146
+		$_where = $this->_maybe_mtp_filters($_where);
147
+
148
+		if ($user_check
149
+			&& ! $global
150
+			&& ! EE_Registry::instance()->CAP->current_user_can(
151
+				'ee_read_others_messages',
152
+				'get_all_active_message_templates'
153
+			)
154
+		) {
155
+			$_where['MTP_user_id'] = get_current_user_id();
156
+		}
157
+
158
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
159
+
160
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 *    retrieve ALL message_template groups from db regardless of wht
167
+	 *
168
+	 * @access    public
169
+	 * @param string $orderby
170
+	 * @param string $order
171
+	 * @param null   $limit
172
+	 * @param bool   $count
173
+	 * @return mixed array on success, FALSE on fail
174
+	 */
175
+	public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false)
176
+	{
177
+		$_where = $this->_maybe_mtp_filters();
178
+
179
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
180
+
181
+		$r_templates = $count
182
+			? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true)
183
+			: $this->get_all_deleted_and_undeleted($query_params);
184
+
185
+		return $r_templates;
186
+	}
187
+
188
+
189
+
190
+
191
+	/**
192
+	 * This gets all the custom templates attached to a specific event
193
+	 * @param  int      $EVT_ID         event id
194
+	 * @param  array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
195
+	 * @return  EE_Message_Template_Group[]
196
+	 */
197
+	public function get_all_custom_templates_by_event($EVT_ID, $query_params = array())
198
+	{
199
+		$where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID ));
200
+		return $this->get_all(
201
+			array( $where )
202
+		);
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * get_all_trashed_grouped_message_templates
209
+	 * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed
210
+	 *
211
+	 * @access public
212
+	 * @param string $orderby
213
+	 * @param string $order
214
+	 * @param null   $limit
215
+	 * @param bool   $count
216
+	 * @param bool   $global
217
+	 * @return \EE_Message_Template_Group[] message template groups.
218
+	 */
219
+	public function get_all_trashed_grouped_message_templates(
220
+		$orderby = 'GRP_ID',
221
+		$order = 'ASC',
222
+		$limit = null,
223
+		$count = false,
224
+		$global = true
225
+	) {
226
+		$_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false );
227
+		$_where['MTP_is_active'] = true;
228
+		$_where = $this->_maybe_mtp_filters($_where);
229
+
230
+		$query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit );
231
+
232
+		return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params);
233
+	}
234
+
235
+
236
+
237
+	/**
238
+	 * this returns the message template group(s) for a given event, messenger, and message template
239
+	 *
240
+	 * @param  string             $messenger
241
+	 * @param  string             $message_type
242
+	 * @param                     $evt_id
243
+	 * @param  string             $orderby pointless at this point but still included
244
+	 * @param  string             $order
245
+	 * @param  mixed (array|null) $limit   array($offset, $num)
246
+	 * @param  bool               $count   true = just return count, false = objects
247
+	 * @param  bool               $active  ignore "active" or not. (default only return active)
248
+	 * @return \mixed[]) depending on $count.
249
+	 */
250
+	public function get_event_message_templates_by_m_and_mt_and_evt(
251
+		$messenger,
252
+		$message_type,
253
+		$evt_id,
254
+		$orderby = 'GRP_ID',
255
+		$order = 'ASC',
256
+		$limit = null,
257
+		$count = false,
258
+		$active = true
259
+	) {
260
+		$_where = array(
261
+			'MTP_messenger' => $messenger,
262
+			'MTP_message_type' => $message_type,
263
+			'Event.EVT_ID' => $evt_id,
264
+			'MTP_is_global' => true,
265
+			'MTP_is_active' => $active
266
+		);
267
+
268
+		$query_params = array( $_where, 'order_by' => array($orderby=>$order), 'limit' => $limit );
269
+
270
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
271
+	}
272
+
273
+
274
+
275
+
276
+	/**
277
+	 * get all GLOBAL message template groups for the given messenger and message type
278
+	 *
279
+	 * @param  string $messenger    slug for messenger
280
+	 * @param  string $message_type slug for message type
281
+	 * @param  string $orderby      what column to orderby
282
+	 * @param  string $order        ASC or DESC
283
+	 * @param  mixed (array|null) $limit array($offset, $num)
284
+	 * @param  bool   $count        true = just return count, false = objects
285
+	 * @param  bool   $active       ignore "active" or not. (default only return active) -
286
+	 *                              'all' means return both inactive AND inactive.
287
+	 * @return array               message template objects that are global (i.e. non-event)
288
+	 */
289
+	public function get_global_message_template_by_m_and_mt(
290
+		$messenger,
291
+		$message_type,
292
+		$orderby = 'GRP_ID',
293
+		$order = 'ASC',
294
+		$limit = null,
295
+		$count = false,
296
+		$active = true
297
+	) {
298
+		$_where = array(
299
+			'MTP_messenger' => $messenger,
300
+			'MTP_message_type' => $message_type,
301
+			'MTP_is_global' => true,
302
+		);
303
+
304
+		if ($active != 'all') {
305
+			$_where['MTP_is_active'] = $active;
306
+		}
307
+
308
+		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
309
+
310
+		return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params);
311
+	}
312
+
313
+
314
+
315
+
316
+	/**
317
+	 * get all custom message template groups for the given messenger and message type
318
+	 * @param  string $messenger    messenger
319
+	 * @param  string $message_type messagetype
320
+	 * @param  array  $query_params same as EEM_Base->get_all()
321
+	 * @return EE_Message_Template_Group[]
322
+	 */
323
+	public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array())
324
+	{
325
+		return $this->get_all(
326
+			array_merge(
327
+				$query_params,
328
+				array(
329
+					array(
330
+						'MTP_is_global'    => false,
331
+						'MTP_messenger'    => $messenger,
332
+						'MTP_message_type' => $message_type
333
+					)
334
+				)
335
+			)
336
+		);
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * This sends things to the validator for the given messenger and message type.
343
+	 *
344
+	 * @param  array $fields the incoming fields to check.
345
+	 *                       Note this array is in the formatted fields from the form fields setup.
346
+	 *                       So we need to reformat this into an array of expected field refs by the validator.
347
+	 *                       Note also that this is not only the fields for the Message Template Group
348
+	 *                       but ALSO for Message Template.
349
+	 * @param string $context      The context the fields were obtained from.
350
+	 * @param string $messenger    The messenger we are validating
351
+	 * @param string $message_type The message type we are validating.
352
+	 * @return mixed If the fields all check out then we return true otherwise error messages are returned
353
+	 *                       (indexed by field name);
354
+	 * @throws \EE_Error
355
+	 */
356
+	public function validate($fields, $context, $messenger, $message_type)
357
+	{
358
+
359
+		$assembled_fields = array();
360
+
361
+		// let's loop through all the fields and set them up in the right format
362
+		foreach ($fields as $index => $value) {
363
+			// first let's figure out if the value['content'] in the current index is an array.
364
+			//  If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list').
365
+			if (is_array($value['content'])) {
366
+				$assembled_fields[ $value['name'] ] = $value['content']['main'];
367
+				// loop through the content and get the other fields.
368
+				foreach ($value['content'] as $name => $val) {
369
+					if ($name == 'main') {
370
+						continue;
371
+					}
372
+					$assembled_fields[ $name ] = $val;
373
+				}
374
+				continue;
375
+			}
376
+
377
+			// okay if we're here then this is just a straight field=>$value arrangement
378
+			$assembled_fields[ $value['name'] ] = $value['content'];
379
+		}
380
+
381
+		// now we've got the assembled_fields.
382
+		// We need to setup the string for the appropriate validator class and call that.
383
+		$m_ref = ucwords(str_replace('_', ' ', $messenger));
384
+		$m_ref = str_replace(' ', '_', $m_ref);
385
+		$mt_ref = ucwords(str_replace('_', ' ', $message_type));
386
+		$mt_ref = str_replace(' ', '_', $mt_ref);
387
+
388
+		$classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator';
389
+
390
+		if (!class_exists($classname)) {
391
+			$msg[] = __('The Validator class was unable to load', 'event_espresso');
392
+			$msg[] = sprintf(
393
+				__(
394
+					'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class',
395
+					'event_espresso'
396
+				),
397
+				$classname
398
+			);
399
+			throw new EE_Error(implode('||', $msg));
400
+		}
401
+
402
+		$a = new ReflectionClass($classname);
403
+		$_VLD = $a->newInstance($assembled_fields, $context);
404
+		$result = $_VLD->validate();
405
+		return $result;
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * Updates all message template groups matching the incoming arguments to inactive status.
412
+	 *
413
+	 * @param array $messenger_names    The messenger slugs.
414
+	 *                              If empty then all templates matching the message types are marked inactive.
415
+	 *                              Otherwise only templates matching the messengers and message types.
416
+	 * @param array $message_type_names     The message type slugs.
417
+	 *                              If empty then all templates matching the messengers are marked inactive.
418
+	 *                              Otherwise only templates matching the messengers and message types.
419
+	 *
420
+	 * @return int  count of updated records.
421
+	 */
422
+	public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array())
423
+	{
424
+		$query_args = array();
425
+		if (empty($messenger_names) && empty($message_type_names)) {
426
+			return 0;
427
+		}
428
+		if (! empty($messenger_names)) {
429
+			$query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names );
430
+		}
431
+		if (! empty($message_type_names)) {
432
+			$query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names );
433
+		}
434
+		return $this->update(array( 'MTP_is_active' => false ), $query_args);
435
+	}
436 436
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Price.model.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *      instantiate a new price object with blank/empty properties
67 67
      *
68 68
      *      @access     public
69
-     *      @return     mixed       array on success, FALSE on fail
69
+     *      @return     EE_Base_Class|null       array on success, FALSE on fail
70 70
      */
71 71
     public function get_new_price()
72 72
     {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      *
97 97
      * @access        public
98 98
      * @param int $EVT_ID
99
-     * @return array on success
99
+     * @return EE_Base_Class[] on success
100 100
      */
101 101
     public function get_all_event_prices($EVT_ID = 0)
102 102
     {
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * @access public
224 224
      * @param \EE_Price $price_a
225 225
      * @param \EE_Price $price_b
226
-     * @return bool false on fail
226
+     * @return integer false on fail
227 227
      */
228 228
     public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229 229
     {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @access public
242 242
      * @param \EE_Price $price_a
243 243
      * @param \EE_Price $price_b
244
-     * @return bool false on fail
244
+     * @return integer false on fail
245 245
      */
246 246
     public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247 247
     {
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      *
259 259
      *      @access     public
260 260
      *      @param      int                 $type - PRT_ID
261
-     *      @return         boolean     false on fail
261
+     *      @return         EE_Base_Class[]     false on fail
262 262
      */
263 263
     public function get_all_prices_that_are_type($type = 0)
264 264
     {
Please login to merge, or discard this patch.
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -10,279 +10,279 @@
 block discarded – undo
10 10
 class EEM_Price extends EEM_Soft_Delete_Base
11 11
 {
12 12
 
13
-    // private instance of the EEM_Price object
14
-    protected static $_instance = null;
15
-
16
-
17
-
18
-    /**
19
-     *      private constructor to prevent direct creation
20
-     *      @Constructor
21
-     *      @access protected
22
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
-     *      @return EEM_Price
24
-     */
25
-    protected function __construct($timezone)
26
-    {
27
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
28
-        $this->singular_item = __('Price', 'event_espresso');
29
-        $this->plural_item = __('Prices', 'event_espresso');
30
-
31
-        $this->_tables = array(
32
-            'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID')
33
-        );
34
-        $this->_fields = array(
35
-            'Price'=> array(
36
-                'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'),
37
-                'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'),
38
-                'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0),
39
-                'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''),
40
-                'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''),
41
-                'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false),
42
-                'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price  ( for replacing default prices )', true, 0),
43
-                'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1),
44
-                'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false),
45
-                'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0),
46
-                'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false),
47
-            )
48
-        );
49
-        $this->_model_relations = array(
50
-            'Ticket'=>new EE_HABTM_Relation('Ticket_Price'),
51
-            'Price_Type'=>new EE_Belongs_To_Relation(),
52
-            'WP_User' => new EE_Belongs_To_Relation(),
53
-        );
54
-        // this model is generally available for reading
55
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56
-        // account for default tickets in the caps
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60
-        parent::__construct($timezone);
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     *      instantiate a new price object with blank/empty properties
67
-     *
68
-     *      @access     public
69
-     *      @return     mixed       array on success, FALSE on fail
70
-     */
71
-    public function get_new_price()
72
-    {
73
-        return $this->create_default_object();
74
-    }
75
-
76
-
77
-
78
-
79
-
80
-    /**
81
-     *      retrieve  ALL prices from db
82
-     *
83
-     *      @access     public
84
-     *      @return     EE_PRice[]
85
-     */
86
-    public function get_all_prices()
87
-    {
88
-        // retrieve all prices
89
-        return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC')));
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     *        retrieve all active prices for a particular event
96
-     *
97
-     * @access        public
98
-     * @param int $EVT_ID
99
-     * @return array on success
100
-     */
101
-    public function get_all_event_prices($EVT_ID = 0)
102
-    {
103
-        return $this->get_all(array(
104
-            array(
105
-                'EVT_ID'=>$EVT_ID,
106
-                'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
107
-            ),
108
-            'order_by'=>$this->_order_by_array_for_get_all_method()
109
-        ));
110
-    }
111
-
112
-
113
-    /**
114
-     *      retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event
115
-     *
116
-     *      @access     public
117
-     *      @param      boolean         $count  return count
118
-     *      @return         array           on success
119
-     *      @return         boolean     false on fail
120
-     */
121
-    public function get_all_default_prices($count = false)
122
-    {
123
-        $_where = array(
124
-            'Price_Type.PBT_ID'=>array('!=',4),
125
-            'PRC_deleted' => 0,
126
-            'PRC_is_default' => 1
127
-        );
128
-        $_query_params = array(
129
-            $_where,
130
-            'order_by'=>$this->_order_by_array_for_get_all_method()
131
-        );
132
-        return $count ? $this->count(array($_where)) : $this->get_all($_query_params);
133
-    }
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-    /**
145
-     *      retrieve all prices that are taxes
146
-     *
147
-     *      @access     public
148
-     *      @return         array               on success
149
-     *      @return         array top-level keys are the price's order and their values are an array,
150
-     *                      next-level keys are the price's ID, and their values are EE_Price objects
151
-     */
152
-    public function get_all_prices_that_are_taxes()
153
-    {
154
-        $taxes = array();
155
-        $all_taxes = $this->get_all(array(
156
-            array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
-            'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
158
-        ));
159
-        foreach ($all_taxes as $tax) {
160
-            if ($tax instanceof EE_Price) {
161
-                $taxes[ $tax->order() ][ $tax->ID() ] = $tax;
162
-            }
163
-        }
164
-        return $taxes;
165
-    }
166
-
167
-
168
-
169
-
170
-
171
-    /**
172
-     *      retrieve all prices for an ticket plus default global prices, but not taxes
173
-     *
174
-     *      @access     public
175
-     *      @param int $TKT_ID          the id of the event.  If not included then we assume that this is a new ticket.
176
-     *      @return         boolean         false on fail
177
-     */
178
-    public function get_all_ticket_prices_for_admin($TKT_ID = 0)
179
-    {
180
-        $array_of_price_objects = array();
181
-        if (empty($TKT_ID)) {
182
-            // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active
183
-            // return that list
184
-            $default_prices = $this->get_all_default_prices();
185
-
186
-            if ($default_prices) {
187
-                foreach ($default_prices as $price) {
188
-                    if ($price instanceof EE_Price) {
189
-                        $array_of_price_objects[ $price->type() ][] = $price;
190
-                    }
191
-                }
192
-                return $array_of_price_objects;
193
-            } else {
194
-                return array();
195
-            }
196
-        } else {
197
-            $ticket_prices = $this->get_all(array(
198
-                array(
199
-                    'TKT_ID'=>$TKT_ID,
200
-                    'PRC_deleted' => 0
201
-                    ),
202
-                'order_by'=> array('PRC_order' => 'ASC')
203
-            ));
204
-        }
205
-
206
-        if (!empty($ticket_prices)) {
207
-            foreach ($ticket_prices as $price) {
208
-                if ($price instanceof EE_Price) {
209
-                    $array_of_price_objects[ $price->type() ][] = $price;
210
-                }
211
-            }
212
-            return $array_of_price_objects;
213
-        } else {
214
-            return false;
215
-        }
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     *        _sort_event_prices_by_type
222
-     *
223
-     * @access public
224
-     * @param \EE_Price $price_a
225
-     * @param \EE_Price $price_b
226
-     * @return bool false on fail
227
-     */
228
-    public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229
-    {
230
-        if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) {
231
-            return $this->_sort_event_prices_by_order($price_a, $price_b);
232
-        }
233
-        return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     *        _sort_event_prices_by_order
240
-     *
241
-     * @access public
242
-     * @param \EE_Price $price_a
243
-     * @param \EE_Price $price_b
244
-     * @return bool false on fail
245
-     */
246
-    public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247
-    {
248
-        if ($price_a->order() == $price_b->order()) {
249
-            return 0;
250
-        }
251
-        return $price_a->order() < $price_b->order() ? -1 : 1;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *      get all prices of a specific type
258
-     *
259
-     *      @access     public
260
-     *      @param      int                 $type - PRT_ID
261
-     *      @return         boolean     false on fail
262
-     */
263
-    public function get_all_prices_that_are_type($type = 0)
264
-    {
265
-        return $this->get_all(array(
266
-            array(
267
-                'PRT_ID'=>$type
268
-            ),
269
-            'order_by'=>$this->_order_by_array_for_get_all_method()
270
-        ));
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * Returns an array of the normal 'order_by' query parameter provided to the get_all query.
277
-     * Of course you don't have to use it, but this is the order we usually want to sort prices by
278
-     * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method()));
279
-     */
280
-    public function _order_by_array_for_get_all_method()
281
-    {
282
-        return array(
283
-                'PRC_order'=>'ASC',
284
-                'Price_Type.PRT_order'=>'ASC',
285
-                'PRC_ID'=>'ASC'
286
-        );
287
-    }
13
+	// private instance of the EEM_Price object
14
+	protected static $_instance = null;
15
+
16
+
17
+
18
+	/**
19
+	 *      private constructor to prevent direct creation
20
+	 *      @Constructor
21
+	 *      @access protected
22
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
23
+	 *      @return EEM_Price
24
+	 */
25
+	protected function __construct($timezone)
26
+	{
27
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
28
+		$this->singular_item = __('Price', 'event_espresso');
29
+		$this->plural_item = __('Prices', 'event_espresso');
30
+
31
+		$this->_tables = array(
32
+			'Price'=>new EE_Primary_Table('esp_price', 'PRC_ID')
33
+		);
34
+		$this->_fields = array(
35
+			'Price'=> array(
36
+				'PRC_ID'=>new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'),
37
+				'PRT_ID'=>new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'),
38
+				'PRC_amount'=>new EE_Money_Field('PRC_amount', 'Price Amount', false, 0),
39
+				'PRC_name'=>new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''),
40
+				'PRC_desc'=>new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''),
41
+				'PRC_is_default'=>new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false),
42
+				'PRC_overrides'=>new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price  ( for replacing default prices )', true, 0),
43
+				'PRC_order'=>new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1),
44
+				'PRC_deleted'=>new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false),
45
+				'PRC_parent' => new EE_Integer_Field('PRC_parent', __('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0),
46
+				'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', __('Price Creator ID', 'event_espresso'), false),
47
+			)
48
+		);
49
+		$this->_model_relations = array(
50
+			'Ticket'=>new EE_HABTM_Relation('Ticket_Price'),
51
+			'Price_Type'=>new EE_Belongs_To_Relation(),
52
+			'WP_User' => new EE_Belongs_To_Relation(),
53
+		);
54
+		// this model is generally available for reading
55
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56
+		// account for default tickets in the caps
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60
+		parent::__construct($timezone);
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 *      instantiate a new price object with blank/empty properties
67
+	 *
68
+	 *      @access     public
69
+	 *      @return     mixed       array on success, FALSE on fail
70
+	 */
71
+	public function get_new_price()
72
+	{
73
+		return $this->create_default_object();
74
+	}
75
+
76
+
77
+
78
+
79
+
80
+	/**
81
+	 *      retrieve  ALL prices from db
82
+	 *
83
+	 *      @access     public
84
+	 *      @return     EE_PRice[]
85
+	 */
86
+	public function get_all_prices()
87
+	{
88
+		// retrieve all prices
89
+		return $this->get_all(array('order_by'=>array('PRC_amount'=>'ASC')));
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 *        retrieve all active prices for a particular event
96
+	 *
97
+	 * @access        public
98
+	 * @param int $EVT_ID
99
+	 * @return array on success
100
+	 */
101
+	public function get_all_event_prices($EVT_ID = 0)
102
+	{
103
+		return $this->get_all(array(
104
+			array(
105
+				'EVT_ID'=>$EVT_ID,
106
+				'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
107
+			),
108
+			'order_by'=>$this->_order_by_array_for_get_all_method()
109
+		));
110
+	}
111
+
112
+
113
+	/**
114
+	 *      retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event
115
+	 *
116
+	 *      @access     public
117
+	 *      @param      boolean         $count  return count
118
+	 *      @return         array           on success
119
+	 *      @return         boolean     false on fail
120
+	 */
121
+	public function get_all_default_prices($count = false)
122
+	{
123
+		$_where = array(
124
+			'Price_Type.PBT_ID'=>array('!=',4),
125
+			'PRC_deleted' => 0,
126
+			'PRC_is_default' => 1
127
+		);
128
+		$_query_params = array(
129
+			$_where,
130
+			'order_by'=>$this->_order_by_array_for_get_all_method()
131
+		);
132
+		return $count ? $this->count(array($_where)) : $this->get_all($_query_params);
133
+	}
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+	/**
145
+	 *      retrieve all prices that are taxes
146
+	 *
147
+	 *      @access     public
148
+	 *      @return         array               on success
149
+	 *      @return         array top-level keys are the price's order and their values are an array,
150
+	 *                      next-level keys are the price's ID, and their values are EE_Price objects
151
+	 */
152
+	public function get_all_prices_that_are_taxes()
153
+	{
154
+		$taxes = array();
155
+		$all_taxes = $this->get_all(array(
156
+			array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
+			'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
158
+		));
159
+		foreach ($all_taxes as $tax) {
160
+			if ($tax instanceof EE_Price) {
161
+				$taxes[ $tax->order() ][ $tax->ID() ] = $tax;
162
+			}
163
+		}
164
+		return $taxes;
165
+	}
166
+
167
+
168
+
169
+
170
+
171
+	/**
172
+	 *      retrieve all prices for an ticket plus default global prices, but not taxes
173
+	 *
174
+	 *      @access     public
175
+	 *      @param int $TKT_ID          the id of the event.  If not included then we assume that this is a new ticket.
176
+	 *      @return         boolean         false on fail
177
+	 */
178
+	public function get_all_ticket_prices_for_admin($TKT_ID = 0)
179
+	{
180
+		$array_of_price_objects = array();
181
+		if (empty($TKT_ID)) {
182
+			// if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active
183
+			// return that list
184
+			$default_prices = $this->get_all_default_prices();
185
+
186
+			if ($default_prices) {
187
+				foreach ($default_prices as $price) {
188
+					if ($price instanceof EE_Price) {
189
+						$array_of_price_objects[ $price->type() ][] = $price;
190
+					}
191
+				}
192
+				return $array_of_price_objects;
193
+			} else {
194
+				return array();
195
+			}
196
+		} else {
197
+			$ticket_prices = $this->get_all(array(
198
+				array(
199
+					'TKT_ID'=>$TKT_ID,
200
+					'PRC_deleted' => 0
201
+					),
202
+				'order_by'=> array('PRC_order' => 'ASC')
203
+			));
204
+		}
205
+
206
+		if (!empty($ticket_prices)) {
207
+			foreach ($ticket_prices as $price) {
208
+				if ($price instanceof EE_Price) {
209
+					$array_of_price_objects[ $price->type() ][] = $price;
210
+				}
211
+			}
212
+			return $array_of_price_objects;
213
+		} else {
214
+			return false;
215
+		}
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 *        _sort_event_prices_by_type
222
+	 *
223
+	 * @access public
224
+	 * @param \EE_Price $price_a
225
+	 * @param \EE_Price $price_b
226
+	 * @return bool false on fail
227
+	 */
228
+	public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b)
229
+	{
230
+		if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) {
231
+			return $this->_sort_event_prices_by_order($price_a, $price_b);
232
+		}
233
+		return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 *        _sort_event_prices_by_order
240
+	 *
241
+	 * @access public
242
+	 * @param \EE_Price $price_a
243
+	 * @param \EE_Price $price_b
244
+	 * @return bool false on fail
245
+	 */
246
+	public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b)
247
+	{
248
+		if ($price_a->order() == $price_b->order()) {
249
+			return 0;
250
+		}
251
+		return $price_a->order() < $price_b->order() ? -1 : 1;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *      get all prices of a specific type
258
+	 *
259
+	 *      @access     public
260
+	 *      @param      int                 $type - PRT_ID
261
+	 *      @return         boolean     false on fail
262
+	 */
263
+	public function get_all_prices_that_are_type($type = 0)
264
+	{
265
+		return $this->get_all(array(
266
+			array(
267
+				'PRT_ID'=>$type
268
+			),
269
+			'order_by'=>$this->_order_by_array_for_get_all_method()
270
+		));
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * Returns an array of the normal 'order_by' query parameter provided to the get_all query.
277
+	 * Of course you don't have to use it, but this is the order we usually want to sort prices by
278
+	 * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method()));
279
+	 */
280
+	public function _order_by_array_for_get_all_method()
281
+	{
282
+		return array(
283
+				'PRC_order'=>'ASC',
284
+				'Price_Type.PRT_order'=>'ASC',
285
+				'PRC_ID'=>'ASC'
286
+		);
287
+	}
288 288
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     protected function __construct($timezone)
26 26
     {
27
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
27
+        require_once(EE_MODELS.'EEM_Price_Type.model.php');
28 28
         $this->singular_item = __('Price', 'event_espresso');
29 29
         $this->plural_item = __('Prices', 'event_espresso');
30 30
 
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
             'WP_User' => new EE_Belongs_To_Relation(),
53 53
         );
54 54
         // this model is generally available for reading
55
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
55
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event');
56 56
         // account for default tickets in the caps
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
57
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
58
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
59
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event');
60 60
         parent::__construct($timezone);
61 61
     }
62 62
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         return $this->get_all(array(
104 104
             array(
105 105
                 'EVT_ID'=>$EVT_ID,
106
-                'Price_Type.PBT_ID'=>array('!=',  EEM_Price_Type::base_type_tax)
106
+                'Price_Type.PBT_ID'=>array('!=', EEM_Price_Type::base_type_tax)
107 107
             ),
108 108
             'order_by'=>$this->_order_by_array_for_get_all_method()
109 109
         ));
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     public function get_all_default_prices($count = false)
122 122
     {
123 123
         $_where = array(
124
-            'Price_Type.PBT_ID'=>array('!=',4),
124
+            'Price_Type.PBT_ID'=>array('!=', 4),
125 125
             'PRC_deleted' => 0,
126 126
             'PRC_is_default' => 1
127 127
         );
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
     {
154 154
         $taxes = array();
155 155
         $all_taxes = $this->get_all(array(
156
-            array( 'Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax ),
157
-            'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' )
156
+            array('Price_Type.PBT_ID'=>  EEM_Price_Type::base_type_tax),
157
+            'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC')
158 158
         ));
159 159
         foreach ($all_taxes as $tax) {
160 160
             if ($tax instanceof EE_Price) {
161
-                $taxes[ $tax->order() ][ $tax->ID() ] = $tax;
161
+                $taxes[$tax->order()][$tax->ID()] = $tax;
162 162
             }
163 163
         }
164 164
         return $taxes;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             if ($default_prices) {
187 187
                 foreach ($default_prices as $price) {
188 188
                     if ($price instanceof EE_Price) {
189
-                        $array_of_price_objects[ $price->type() ][] = $price;
189
+                        $array_of_price_objects[$price->type()][] = $price;
190 190
                     }
191 191
                 }
192 192
                 return $array_of_price_objects;
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
             ));
204 204
         }
205 205
 
206
-        if (!empty($ticket_prices)) {
206
+        if ( ! empty($ticket_prices)) {
207 207
             foreach ($ticket_prices as $price) {
208 208
                 if ($price instanceof EE_Price) {
209
-                    $array_of_price_objects[ $price->type() ][] = $price;
209
+                    $array_of_price_objects[$price->type()][] = $price;
210 210
                 }
211 211
             }
212 212
             return $array_of_price_objects;
Please login to merge, or discard this patch.