Completed
Branch Gutenberg/event-attendees-bloc... (011228)
by
unknown
66:29 queued 53:26
created
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      *
343 343
      * @param $template
344 344
      * @param $template_args
345
-     * @return mixed
345
+     * @return string
346 346
      * @throws DomainException
347 347
      */
348 348
     public function add_additional_datetime_button($template, $template_args)
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      *
361 361
      * @param $template
362 362
      * @param $template_args
363
-     * @return mixed
363
+     * @return string
364 364
      * @throws DomainException
365 365
      */
366 366
     public function add_datetime_clone_button($template, $template_args)
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
      *
379 379
      * @param $template
380 380
      * @param $template_args
381
-     * @return mixed
381
+     * @return string
382 382
      * @throws DomainException
383 383
      */
384 384
     public function datetime_timezones_template($template, $template_args)
Please login to merge, or discard this patch.
Indentation   +1278 added lines, -1278 removed lines patch added patch discarded remove patch
@@ -16,1282 +16,1282 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-    /**
36
-     * Sets routes.
37
-     */
38
-    protected function _extend_page_config()
39
-    {
40
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
41
-        // is there a evt_id in the request?
42
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
43
-            ? $this->_req_data['EVT_ID']
44
-            : 0;
45
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
46
-        // tkt_id?
47
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
48
-            ? $this->_req_data['TKT_ID']
49
-            : 0;
50
-        $new_page_routes = array(
51
-            'duplicate_event'          => array(
52
-                'func'       => '_duplicate_event',
53
-                'capability' => 'ee_edit_event',
54
-                'obj_id'     => $evt_id,
55
-                'noheader'   => true,
56
-            ),
57
-            'ticket_list_table'        => array(
58
-                'func'       => '_tickets_overview_list_table',
59
-                'capability' => 'ee_read_default_tickets',
60
-            ),
61
-            'trash_ticket'             => array(
62
-                'func'       => '_trash_or_restore_ticket',
63
-                'capability' => 'ee_delete_default_ticket',
64
-                'obj_id'     => $tkt_id,
65
-                'noheader'   => true,
66
-                'args'       => array('trash' => true),
67
-            ),
68
-            'trash_tickets'            => array(
69
-                'func'       => '_trash_or_restore_ticket',
70
-                'capability' => 'ee_delete_default_tickets',
71
-                'noheader'   => true,
72
-                'args'       => array('trash' => true),
73
-            ),
74
-            'restore_ticket'           => array(
75
-                'func'       => '_trash_or_restore_ticket',
76
-                'capability' => 'ee_delete_default_ticket',
77
-                'obj_id'     => $tkt_id,
78
-                'noheader'   => true,
79
-            ),
80
-            'restore_tickets'          => array(
81
-                'func'       => '_trash_or_restore_ticket',
82
-                'capability' => 'ee_delete_default_tickets',
83
-                'noheader'   => true,
84
-            ),
85
-            'delete_ticket'            => array(
86
-                'func'       => '_delete_ticket',
87
-                'capability' => 'ee_delete_default_ticket',
88
-                'obj_id'     => $tkt_id,
89
-                'noheader'   => true,
90
-            ),
91
-            'delete_tickets'           => array(
92
-                'func'       => '_delete_ticket',
93
-                'capability' => 'ee_delete_default_tickets',
94
-                'noheader'   => true,
95
-            ),
96
-            'import_page'              => array(
97
-                'func'       => '_import_page',
98
-                'capability' => 'import',
99
-            ),
100
-            'import'                   => array(
101
-                'func'       => '_import_events',
102
-                'capability' => 'import',
103
-                'noheader'   => true,
104
-            ),
105
-            'import_events'            => array(
106
-                'func'       => '_import_events',
107
-                'capability' => 'import',
108
-                'noheader'   => true,
109
-            ),
110
-            'export_events'            => array(
111
-                'func'       => '_events_export',
112
-                'capability' => 'export',
113
-                'noheader'   => true,
114
-            ),
115
-            'export_categories'        => array(
116
-                'func'       => '_categories_export',
117
-                'capability' => 'export',
118
-                'noheader'   => true,
119
-            ),
120
-            'sample_export_file'       => array(
121
-                'func'       => '_sample_export_file',
122
-                'capability' => 'export',
123
-                'noheader'   => true,
124
-            ),
125
-            'update_template_settings' => array(
126
-                'func'       => '_update_template_settings',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-        );
131
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
132
-        // partial route/config override
133
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
134
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
135
-        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
136
-        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
137
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
138
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
139
-        // add tickets tab but only if there are more than one default ticket!
140
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
141
-            array(array('TKT_is_default' => 1)),
142
-            'TKT_ID',
143
-            true
144
-        );
145
-        if ($tkt_count > 1) {
146
-            $new_page_config = array(
147
-                'ticket_list_table' => array(
148
-                    'nav'           => array(
149
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
150
-                        'order' => 60,
151
-                    ),
152
-                    'list_table'    => 'Tickets_List_Table',
153
-                    'require_nonce' => false,
154
-                ),
155
-            );
156
-        }
157
-        // template settings
158
-        $new_page_config['template_settings'] = array(
159
-            'nav'           => array(
160
-                'label' => esc_html__('Templates', 'event_espresso'),
161
-                'order' => 30,
162
-            ),
163
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
164
-            'help_tabs'     => array(
165
-                'general_settings_templates_help_tab' => array(
166
-                    'title'    => esc_html__('Templates', 'event_espresso'),
167
-                    'filename' => 'general_settings_templates',
168
-                ),
169
-            ),
170
-            'help_tour'     => array('Templates_Help_Tour'),
171
-            'require_nonce' => false,
172
-        );
173
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
174
-        // add filters and actions
175
-        // modifying _views
176
-        add_filter(
177
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
178
-            array($this, 'add_additional_datetime_button'),
179
-            10,
180
-            2
181
-        );
182
-        add_filter(
183
-            'FHEE_event_datetime_metabox_clone_button_template',
184
-            array($this, 'add_datetime_clone_button'),
185
-            10,
186
-            2
187
-        );
188
-        add_filter(
189
-            'FHEE_event_datetime_metabox_timezones_template',
190
-            array($this, 'datetime_timezones_template'),
191
-            10,
192
-            2
193
-        );
194
-        // filters for event list table
195
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
196
-        add_filter(
197
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
198
-            array($this, 'extra_list_table_actions'),
199
-            10,
200
-            2
201
-        );
202
-        // legend item
203
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
204
-        add_action('admin_init', array($this, 'admin_init'));
205
-        // heartbeat stuff
206
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
207
-    }
208
-
209
-
210
-    /**
211
-     * admin_init
212
-     */
213
-    public function admin_init()
214
-    {
215
-        EE_Registry::$i18n_js_strings = array_merge(
216
-            EE_Registry::$i18n_js_strings,
217
-            array(
218
-                'image_confirm'          => esc_html__(
219
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
220
-                    'event_espresso'
221
-                ),
222
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
223
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
224
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
225
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
226
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
227
-            )
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
-     * accordingly.
235
-     *
236
-     * @param array $response The existing heartbeat response array.
237
-     * @param array $data     The incoming data package.
238
-     * @return array  possibly appended response.
239
-     */
240
-    public function heartbeat_response($response, $data)
241
-    {
242
-        /**
243
-         * check whether count of tickets is approaching the potential
244
-         * limits for the server.
245
-         */
246
-        if (! empty($data['input_count'])) {
247
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
-                $data['input_count']
249
-            );
250
-        }
251
-        return $response;
252
-    }
253
-
254
-
255
-    /**
256
-     * Add per page screen options to the default ticket list table view.
257
-     */
258
-    protected function _add_screen_options_ticket_list_table()
259
-    {
260
-        $this->_per_page_screen_option();
261
-    }
262
-
263
-
264
-    /**
265
-     * @param string $return
266
-     * @param int    $id
267
-     * @param string $new_title
268
-     * @param string $new_slug
269
-     * @return string
270
-     */
271
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
272
-    {
273
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
274
-        // make sure this is only when editing
275
-        if (! empty($id)) {
276
-            $href = EE_Admin_Page::add_query_args_and_nonce(
277
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
278
-                $this->_admin_base_url
279
-            );
280
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
281
-            $return .= '<a href="'
282
-                       . $href
283
-                       . '" title="'
284
-                       . $title
285
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
286
-                       . $title
287
-                       . '</a>';
288
-        }
289
-        return $return;
290
-    }
291
-
292
-
293
-    /**
294
-     * Set the list table views for the default ticket list table view.
295
-     */
296
-    public function _set_list_table_views_ticket_list_table()
297
-    {
298
-        $this->_views = array(
299
-            'all'     => array(
300
-                'slug'        => 'all',
301
-                'label'       => esc_html__('All', 'event_espresso'),
302
-                'count'       => 0,
303
-                'bulk_action' => array(
304
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
305
-                ),
306
-            ),
307
-            'trashed' => array(
308
-                'slug'        => 'trashed',
309
-                'label'       => esc_html__('Trash', 'event_espresso'),
310
-                'count'       => 0,
311
-                'bulk_action' => array(
312
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
313
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
314
-                ),
315
-            ),
316
-        );
317
-    }
318
-
319
-
320
-    /**
321
-     * Enqueue scripts and styles for the event editor.
322
-     */
323
-    public function load_scripts_styles_edit()
324
-    {
325
-        wp_register_script(
326
-            'ee-event-editor-heartbeat',
327
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
328
-            array('ee_admin_js', 'heartbeat'),
329
-            EVENT_ESPRESSO_VERSION,
330
-            true
331
-        );
332
-        wp_enqueue_script('ee-accounting');
333
-        // styles
334
-        wp_enqueue_style('espresso-ui-theme');
335
-        wp_enqueue_script('event_editor_js');
336
-        wp_enqueue_script('ee-event-editor-heartbeat');
337
-    }
338
-
339
-
340
-    /**
341
-     * Returns template for the additional datetime.
342
-     *
343
-     * @param $template
344
-     * @param $template_args
345
-     * @return mixed
346
-     * @throws DomainException
347
-     */
348
-    public function add_additional_datetime_button($template, $template_args)
349
-    {
350
-        return EEH_Template::display_template(
351
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
352
-            $template_args,
353
-            true
354
-        );
355
-    }
356
-
357
-
358
-    /**
359
-     * Returns the template for cloning a datetime.
360
-     *
361
-     * @param $template
362
-     * @param $template_args
363
-     * @return mixed
364
-     * @throws DomainException
365
-     */
366
-    public function add_datetime_clone_button($template, $template_args)
367
-    {
368
-        return EEH_Template::display_template(
369
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
370
-            $template_args,
371
-            true
372
-        );
373
-    }
374
-
375
-
376
-    /**
377
-     * Returns the template for datetime timezones.
378
-     *
379
-     * @param $template
380
-     * @param $template_args
381
-     * @return mixed
382
-     * @throws DomainException
383
-     */
384
-    public function datetime_timezones_template($template, $template_args)
385
-    {
386
-        return EEH_Template::display_template(
387
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
388
-            $template_args,
389
-            true
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * Sets the views for the default list table view.
396
-     */
397
-    protected function _set_list_table_views_default()
398
-    {
399
-        parent::_set_list_table_views_default();
400
-        $new_views = array(
401
-            'today' => array(
402
-                'slug'        => 'today',
403
-                'label'       => esc_html__('Today', 'event_espresso'),
404
-                'count'       => $this->total_events_today(),
405
-                'bulk_action' => array(
406
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
407
-                ),
408
-            ),
409
-            'month' => array(
410
-                'slug'        => 'month',
411
-                'label'       => esc_html__('This Month', 'event_espresso'),
412
-                'count'       => $this->total_events_this_month(),
413
-                'bulk_action' => array(
414
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
415
-                ),
416
-            ),
417
-        );
418
-        $this->_views = array_merge($this->_views, $new_views);
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns the extra action links for the default list table view.
424
-     *
425
-     * @param array     $action_links
426
-     * @param \EE_Event $event
427
-     * @return array
428
-     * @throws EE_Error
429
-     */
430
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
431
-    {
432
-        if (EE_Registry::instance()->CAP->current_user_can(
433
-            'ee_read_registrations',
434
-            'espresso_registrations_reports',
435
-            $event->ID()
436
-        )
437
-        ) {
438
-            $reports_query_args = array(
439
-                'action' => 'reports',
440
-                'EVT_ID' => $event->ID(),
441
-            );
442
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
443
-            $action_links[] = '<a href="'
444
-                              . $reports_link
445
-                              . '" title="'
446
-                              . esc_attr__('View Report', 'event_espresso')
447
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
448
-                              . "\n\t";
449
-        }
450
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
451
-            EE_Registry::instance()->load_helper('MSG_Template');
452
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
453
-                'see_notifications_for',
454
-                null,
455
-                array('EVT_ID' => $event->ID())
456
-            );
457
-        }
458
-        return $action_links;
459
-    }
460
-
461
-
462
-    /**
463
-     * @param $items
464
-     * @return mixed
465
-     */
466
-    public function additional_legend_items($items)
467
-    {
468
-        if (EE_Registry::instance()->CAP->current_user_can(
469
-            'ee_read_registrations',
470
-            'espresso_registrations_reports'
471
-        )
472
-        ) {
473
-            $items['reports'] = array(
474
-                'class' => 'dashicons dashicons-chart-bar',
475
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
476
-            );
477
-        }
478
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
479
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
480
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
481
-                $items['view_related_messages'] = array(
482
-                    'class' => $related_for_icon['css_class'],
483
-                    'desc'  => $related_for_icon['label'],
484
-                );
485
-            }
486
-        }
487
-        return $items;
488
-    }
489
-
490
-
491
-    /**
492
-     * This is the callback method for the duplicate event route
493
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
494
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
495
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
496
-     * After duplication the redirect is to the new event edit page.
497
-     *
498
-     * @return void
499
-     * @access protected
500
-     * @throws EE_Error If EE_Event is not available with given ID
501
-     */
502
-    protected function _duplicate_event()
503
-    {
504
-        // first make sure the ID for the event is in the request.
505
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
506
-        if (! isset($this->_req_data['EVT_ID'])) {
507
-            EE_Error::add_error(
508
-                esc_html__(
509
-                    'In order to duplicate an event an Event ID is required.  None was given.',
510
-                    'event_espresso'
511
-                ),
512
-                __FILE__,
513
-                __FUNCTION__,
514
-                __LINE__
515
-            );
516
-            $this->_redirect_after_action(false, '', '', array(), true);
517
-            return;
518
-        }
519
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
520
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
521
-        if (! $orig_event instanceof EE_Event) {
522
-            throw new EE_Error(
523
-                sprintf(
524
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
525
-                    $this->_req_data['EVT_ID']
526
-                )
527
-            );
528
-        }
529
-        // k now let's clone the $orig_event before getting relations
530
-        $new_event = clone $orig_event;
531
-        // original datetimes
532
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
533
-        // other original relations
534
-        $orig_ven = $orig_event->get_many_related('Venue');
535
-        // reset the ID and modify other details to make it clear this is a dupe
536
-        $new_event->set('EVT_ID', 0);
537
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
538
-        $new_event->set('EVT_name', $new_name);
539
-        $new_event->set(
540
-            'EVT_slug',
541
-            wp_unique_post_slug(
542
-                sanitize_title($orig_event->name()),
543
-                0,
544
-                'publish',
545
-                'espresso_events',
546
-                0
547
-            )
548
-        );
549
-        $new_event->set('status', 'draft');
550
-        // duplicate discussion settings
551
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
552
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
553
-        // save the new event
554
-        $new_event->save();
555
-        // venues
556
-        foreach ($orig_ven as $ven) {
557
-            $new_event->_add_relation_to($ven, 'Venue');
558
-        }
559
-        $new_event->save();
560
-        // now we need to get the question group relations and handle that
561
-        // first primary question groups
562
-        $orig_primary_qgs = $orig_event->get_many_related(
563
-            'Question_Group',
564
-            array(array('Event_Question_Group.EQG_primary' => 1))
565
-        );
566
-        if (! empty($orig_primary_qgs)) {
567
-            foreach ($orig_primary_qgs as $id => $obj) {
568
-                if ($obj instanceof EE_Question_Group) {
569
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
570
-                }
571
-            }
572
-        }
573
-        // next additional attendee question groups
574
-        $orig_additional_qgs = $orig_event->get_many_related(
575
-            'Question_Group',
576
-            array(array('Event_Question_Group.EQG_primary' => 0))
577
-        );
578
-        if (! empty($orig_additional_qgs)) {
579
-            foreach ($orig_additional_qgs as $id => $obj) {
580
-                if ($obj instanceof EE_Question_Group) {
581
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
582
-                }
583
-            }
584
-        }
585
-
586
-        $new_event->save();
587
-
588
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
589
-        $cloned_tickets = array();
590
-        foreach ($orig_datetimes as $orig_dtt) {
591
-            if (! $orig_dtt instanceof EE_Datetime) {
592
-                continue;
593
-            }
594
-            $new_dtt = clone $orig_dtt;
595
-            $orig_tkts = $orig_dtt->tickets();
596
-            // save new dtt then add to event
597
-            $new_dtt->set('DTT_ID', 0);
598
-            $new_dtt->set('DTT_sold', 0);
599
-            $new_dtt->set_reserved(0);
600
-            $new_dtt->save();
601
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
602
-            $new_event->save();
603
-            // now let's get the ticket relations setup.
604
-            foreach ((array) $orig_tkts as $orig_tkt) {
605
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
606
-                if (! $orig_tkt instanceof EE_Ticket) {
607
-                    continue;
608
-                }
609
-                // is this ticket archived?  If it is then let's skip
610
-                if ($orig_tkt->get('TKT_deleted')) {
611
-                    continue;
612
-                }
613
-                // does this original ticket already exist in the clone_tickets cache?
614
-                //  If so we'll just use the new ticket from it.
615
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
616
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
617
-                } else {
618
-                    $new_tkt = clone $orig_tkt;
619
-                    // get relations on the $orig_tkt that we need to setup.
620
-                    $orig_prices = $orig_tkt->prices();
621
-                    $new_tkt->set('TKT_ID', 0);
622
-                    $new_tkt->set('TKT_sold', 0);
623
-                    $new_tkt->set('TKT_reserved', 0);
624
-                    $new_tkt->save(); // make sure new ticket has ID.
625
-                    // price relations on new ticket need to be setup.
626
-                    foreach ($orig_prices as $orig_price) {
627
-                        $new_price = clone $orig_price;
628
-                        $new_price->set('PRC_ID', 0);
629
-                        $new_price->save();
630
-                        $new_tkt->_add_relation_to($new_price, 'Price');
631
-                        $new_tkt->save();
632
-                    }
633
-
634
-                    do_action(
635
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
636
-                        $orig_tkt,
637
-                        $new_tkt,
638
-                        $orig_prices,
639
-                        $orig_event,
640
-                        $orig_dtt,
641
-                        $new_dtt
642
-                    );
643
-                }
644
-                // k now we can add the new ticket as a relation to the new datetime
645
-                // and make sure its added to our cached $cloned_tickets array
646
-                // for use with later datetimes that have the same ticket.
647
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
648
-                $new_dtt->save();
649
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
650
-            }
651
-        }
652
-        // clone taxonomy information
653
-        $taxonomies_to_clone_with = apply_filters(
654
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
655
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
656
-        );
657
-        // get terms for original event (notice)
658
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
659
-        // loop through terms and add them to new event.
660
-        foreach ($orig_terms as $term) {
661
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
662
-        }
663
-
664
-        // duplicate other core WP_Post items for this event.
665
-        // post thumbnail (feature image).
666
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
667
-        if ($feature_image_id) {
668
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
669
-        }
670
-
671
-        // duplicate page_template setting
672
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
673
-        if ($page_template) {
674
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
675
-        }
676
-
677
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
678
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
679
-        if ($new_event->ID()) {
680
-            $redirect_args = array(
681
-                'post'   => $new_event->ID(),
682
-                'action' => 'edit',
683
-            );
684
-            EE_Error::add_success(
685
-                esc_html__(
686
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
687
-                    'event_espresso'
688
-                )
689
-            );
690
-        } else {
691
-            $redirect_args = array(
692
-                'action' => 'default',
693
-            );
694
-            EE_Error::add_error(
695
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
696
-                __FILE__,
697
-                __FUNCTION__,
698
-                __LINE__
699
-            );
700
-        }
701
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
702
-    }
703
-
704
-
705
-    /**
706
-     * Generates output for the import page.
707
-     *
708
-     * @throws DomainException
709
-     */
710
-    protected function _import_page()
711
-    {
712
-        $title = esc_html__('Import', 'event_espresso');
713
-        $intro = esc_html__(
714
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
715
-            'event_espresso'
716
-        );
717
-        $form_url = EVENTS_ADMIN_URL;
718
-        $action = 'import_events';
719
-        $type = 'csv';
720
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
721
-            $title,
722
-            $intro,
723
-            $form_url,
724
-            $action,
725
-            $type
726
-        );
727
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
728
-            array('action' => 'sample_export_file'),
729
-            $this->_admin_base_url
730
-        );
731
-        $content = EEH_Template::display_template(
732
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
733
-            $this->_template_args,
734
-            true
735
-        );
736
-        $this->_template_args['admin_page_content'] = $content;
737
-        $this->display_admin_page_with_sidebar();
738
-    }
739
-
740
-
741
-    /**
742
-     * _import_events
743
-     * This handles displaying the screen and running imports for importing events.
744
-     *
745
-     * @return void
746
-     */
747
-    protected function _import_events()
748
-    {
749
-        require_once(EE_CLASSES . 'EE_Import.class.php');
750
-        $success = EE_Import::instance()->import();
751
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
752
-    }
753
-
754
-
755
-    /**
756
-     * _events_export
757
-     * Will export all (or just the given event) to a Excel compatible file.
758
-     *
759
-     * @access protected
760
-     * @return void
761
-     */
762
-    protected function _events_export()
763
-    {
764
-        if (isset($this->_req_data['EVT_ID'])) {
765
-            $event_ids = $this->_req_data['EVT_ID'];
766
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
767
-            $event_ids = $this->_req_data['EVT_IDs'];
768
-        } else {
769
-            $event_ids = null;
770
-        }
771
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
772
-        $new_request_args = array(
773
-            'export' => 'report',
774
-            'action' => 'all_event_data',
775
-            'EVT_ID' => $event_ids,
776
-        );
777
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
778
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
779
-            require_once(EE_CLASSES . 'EE_Export.class.php');
780
-            $EE_Export = EE_Export::instance($this->_req_data);
781
-            $EE_Export->export();
782
-        }
783
-    }
784
-
785
-
786
-    /**
787
-     * handle category exports()
788
-     *
789
-     * @return void
790
-     */
791
-    protected function _categories_export()
792
-    {
793
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
794
-        $new_request_args = array(
795
-            'export'       => 'report',
796
-            'action'       => 'categories',
797
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
798
-        );
799
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
800
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
801
-            require_once(EE_CLASSES . 'EE_Export.class.php');
802
-            $EE_Export = EE_Export::instance($this->_req_data);
803
-            $EE_Export->export();
804
-        }
805
-    }
806
-
807
-
808
-    /**
809
-     * Creates a sample CSV file for importing
810
-     */
811
-    protected function _sample_export_file()
812
-    {
813
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
814
-        EE_Export::instance()->export_sample();
815
-    }
816
-
817
-
818
-    /*************        Template Settings        *************/
819
-    /**
820
-     * Generates template settings page output
821
-     *
822
-     * @throws DomainException
823
-     * @throws EE_Error
824
-     */
825
-    protected function _template_settings()
826
-    {
827
-        $this->_template_args['values'] = $this->_yes_no_values;
828
-        /**
829
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
830
-         * from General_Settings_Admin_Page to here.
831
-         */
832
-        $this->_template_args = apply_filters(
833
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
834
-            $this->_template_args
835
-        );
836
-        $this->_set_add_edit_form_tags('update_template_settings');
837
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
838
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
839
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
840
-            $this->_template_args,
841
-            true
842
-        );
843
-        $this->display_admin_page_with_sidebar();
844
-    }
845
-
846
-
847
-    /**
848
-     * Handler for updating template settings.
849
-     *
850
-     * @throws InvalidInterfaceException
851
-     * @throws InvalidDataTypeException
852
-     * @throws InvalidArgumentException
853
-     */
854
-    protected function _update_template_settings()
855
-    {
856
-        /**
857
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
858
-         * from General_Settings_Admin_Page to here.
859
-         */
860
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
861
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
862
-            EE_Registry::instance()->CFG->template_settings,
863
-            $this->_req_data
864
-        );
865
-        // update custom post type slugs and detect if we need to flush rewrite rules
866
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
867
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
868
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
869
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
870
-        $what = 'Template Settings';
871
-        $success = $this->_update_espresso_configuration(
872
-            $what,
873
-            EE_Registry::instance()->CFG->template_settings,
874
-            __FILE__,
875
-            __FUNCTION__,
876
-            __LINE__
877
-        );
878
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
879
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
880
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
881
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
882
-            );
883
-            $rewrite_rules->flush();
884
-        }
885
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
886
-    }
887
-
888
-
889
-    /**
890
-     * _premium_event_editor_meta_boxes
891
-     * add all metaboxes related to the event_editor
892
-     *
893
-     * @access protected
894
-     * @return void
895
-     * @throws EE_Error
896
-     */
897
-    protected function _premium_event_editor_meta_boxes()
898
-    {
899
-        $this->verify_cpt_object();
900
-        add_meta_box(
901
-            'espresso_event_editor_event_options',
902
-            esc_html__('Event Registration Options', 'event_espresso'),
903
-            array($this, 'registration_options_meta_box'),
904
-            $this->page_slug,
905
-            'side',
906
-            'core'
907
-        );
908
-    }
909
-
910
-
911
-    /**
912
-     * override caf metabox
913
-     *
914
-     * @return void
915
-     * @throws DomainException
916
-     */
917
-    public function registration_options_meta_box()
918
-    {
919
-        $yes_no_values = array(
920
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
921
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
922
-        );
923
-        $default_reg_status_values = EEM_Registration::reg_status_array(
924
-            array(
925
-                EEM_Registration::status_id_cancelled,
926
-                EEM_Registration::status_id_declined,
927
-                EEM_Registration::status_id_incomplete,
928
-                EEM_Registration::status_id_wait_list,
929
-            ),
930
-            true
931
-        );
932
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
933
-        $template_args['_event'] = $this->_cpt_model_obj;
934
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
935
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
936
-            'default_reg_status',
937
-            $default_reg_status_values,
938
-            $this->_cpt_model_obj->default_registration_status()
939
-        );
940
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
941
-            'display_desc',
942
-            $yes_no_values,
943
-            $this->_cpt_model_obj->display_description()
944
-        );
945
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
946
-            'display_ticket_selector',
947
-            $yes_no_values,
948
-            $this->_cpt_model_obj->display_ticket_selector(),
949
-            '',
950
-            '',
951
-            false
952
-        );
953
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
954
-            'EVT_default_registration_status',
955
-            $default_reg_status_values,
956
-            $this->_cpt_model_obj->default_registration_status()
957
-        );
958
-        $template_args['additional_registration_options'] = apply_filters(
959
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
960
-            '',
961
-            $template_args,
962
-            $yes_no_values,
963
-            $default_reg_status_values
964
-        );
965
-        EEH_Template::display_template(
966
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
967
-            $template_args
968
-        );
969
-    }
970
-
971
-
972
-
973
-    /**
974
-     * wp_list_table_mods for caf
975
-     * ============================
976
-     */
977
-    /**
978
-     * hook into list table filters and provide filters for caffeinated list table
979
-     *
980
-     * @param  array $old_filters    any existing filters present
981
-     * @param  array $list_table_obj the list table object
982
-     * @return array                  new filters
983
-     */
984
-    public function list_table_filters($old_filters, $list_table_obj)
985
-    {
986
-        $filters = array();
987
-        // first month/year filters
988
-        $filters[] = $this->espresso_event_months_dropdown();
989
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
990
-        // active status dropdown
991
-        if ($status !== 'draft') {
992
-            $filters[] = $this->active_status_dropdown(
993
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
994
-            );
995
-        }
996
-        // category filter
997
-        $filters[] = $this->category_dropdown();
998
-        return array_merge($old_filters, $filters);
999
-    }
1000
-
1001
-
1002
-    /**
1003
-     * espresso_event_months_dropdown
1004
-     *
1005
-     * @access public
1006
-     * @return string                dropdown listing month/year selections for events.
1007
-     */
1008
-    public function espresso_event_months_dropdown()
1009
-    {
1010
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1011
-        // Note we need to include any other filters that are set!
1012
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1013
-        // categories?
1014
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1015
-            ? $this->_req_data['EVT_CAT']
1016
-            : null;
1017
-        // active status?
1018
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1019
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1020
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * returns a list of "active" statuses on the event
1026
-     *
1027
-     * @param  string $current_value whatever the current active status is
1028
-     * @return string
1029
-     */
1030
-    public function active_status_dropdown($current_value = '')
1031
-    {
1032
-        $select_name = 'active_status';
1033
-        $values = array(
1034
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1035
-            'active'   => esc_html__('Active', 'event_espresso'),
1036
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1037
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1038
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1039
-        );
1040
-        $id = 'id="espresso-active-status-dropdown-filter"';
1041
-        $class = 'wide';
1042
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1043
-    }
1044
-
1045
-
1046
-    /**
1047
-     * output a dropdown of the categories for the category filter on the event admin list table
1048
-     *
1049
-     * @access  public
1050
-     * @return string html
1051
-     */
1052
-    public function category_dropdown()
1053
-    {
1054
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1055
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     * get total number of events today
1061
-     *
1062
-     * @access public
1063
-     * @return int
1064
-     * @throws EE_Error
1065
-     */
1066
-    public function total_events_today()
1067
-    {
1068
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1069
-            'DTT_EVT_start',
1070
-            date('Y-m-d') . ' 00:00:00',
1071
-            'Y-m-d H:i:s',
1072
-            'UTC'
1073
-        );
1074
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1075
-            'DTT_EVT_start',
1076
-            date('Y-m-d') . ' 23:59:59',
1077
-            'Y-m-d H:i:s',
1078
-            'UTC'
1079
-        );
1080
-        $where = array(
1081
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1082
-        );
1083
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1084
-        return $count;
1085
-    }
1086
-
1087
-
1088
-    /**
1089
-     * get total number of events this month
1090
-     *
1091
-     * @access public
1092
-     * @return int
1093
-     * @throws EE_Error
1094
-     */
1095
-    public function total_events_this_month()
1096
-    {
1097
-        // Dates
1098
-        $this_year_r = date('Y');
1099
-        $this_month_r = date('m');
1100
-        $days_this_month = date('t');
1101
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1102
-            'DTT_EVT_start',
1103
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1104
-            'Y-m-d H:i:s',
1105
-            'UTC'
1106
-        );
1107
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1108
-            'DTT_EVT_start',
1109
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1110
-            'Y-m-d H:i:s',
1111
-            'UTC'
1112
-        );
1113
-        $where = array(
1114
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1115
-        );
1116
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1117
-        return $count;
1118
-    }
1119
-
1120
-
1121
-    /** DEFAULT TICKETS STUFF **/
1122
-
1123
-    /**
1124
-     * Output default tickets list table view.
1125
-     */
1126
-    public function _tickets_overview_list_table()
1127
-    {
1128
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1129
-        $this->display_admin_list_table_page_with_no_sidebar();
1130
-    }
1131
-
1132
-
1133
-    /**
1134
-     * @param int  $per_page
1135
-     * @param bool $count
1136
-     * @param bool $trashed
1137
-     * @return \EE_Soft_Delete_Base_Class[]|int
1138
-     */
1139
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1140
-    {
1141
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1142
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1143
-        switch ($orderby) {
1144
-            case 'TKT_name':
1145
-                $orderby = array('TKT_name' => $order);
1146
-                break;
1147
-            case 'TKT_price':
1148
-                $orderby = array('TKT_price' => $order);
1149
-                break;
1150
-            case 'TKT_uses':
1151
-                $orderby = array('TKT_uses' => $order);
1152
-                break;
1153
-            case 'TKT_min':
1154
-                $orderby = array('TKT_min' => $order);
1155
-                break;
1156
-            case 'TKT_max':
1157
-                $orderby = array('TKT_max' => $order);
1158
-                break;
1159
-            case 'TKT_qty':
1160
-                $orderby = array('TKT_qty' => $order);
1161
-                break;
1162
-        }
1163
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1164
-            ? $this->_req_data['paged']
1165
-            : 1;
1166
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1167
-            ? $this->_req_data['perpage']
1168
-            : $per_page;
1169
-        $_where = array(
1170
-            'TKT_is_default' => 1,
1171
-            'TKT_deleted'    => $trashed,
1172
-        );
1173
-        $offset = ($current_page - 1) * $per_page;
1174
-        $limit = array($offset, $per_page);
1175
-        if (isset($this->_req_data['s'])) {
1176
-            $sstr = '%' . $this->_req_data['s'] . '%';
1177
-            $_where['OR'] = array(
1178
-                'TKT_name'        => array('LIKE', $sstr),
1179
-                'TKT_description' => array('LIKE', $sstr),
1180
-            );
1181
-        }
1182
-        $query_params = array(
1183
-            $_where,
1184
-            'order_by' => $orderby,
1185
-            'limit'    => $limit,
1186
-            'group_by' => 'TKT_ID',
1187
-        );
1188
-        if ($count) {
1189
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1190
-        } else {
1191
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1192
-        }
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * @param bool $trash
1198
-     * @throws EE_Error
1199
-     */
1200
-    protected function _trash_or_restore_ticket($trash = false)
1201
-    {
1202
-        $success = 1;
1203
-        $TKT = EEM_Ticket::instance();
1204
-        // checkboxes?
1205
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1206
-            // if array has more than one element then success message should be plural
1207
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1208
-            // cycle thru the boxes
1209
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1210
-                if ($trash) {
1211
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1212
-                        $success = 0;
1213
-                    }
1214
-                } else {
1215
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1216
-                        $success = 0;
1217
-                    }
1218
-                }
1219
-            }
1220
-        } else {
1221
-            // grab single id and trash
1222
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1223
-            if ($trash) {
1224
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1225
-                    $success = 0;
1226
-                }
1227
-            } else {
1228
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1229
-                    $success = 0;
1230
-                }
1231
-            }
1232
-        }
1233
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1234
-        $query_args = array(
1235
-            'action' => 'ticket_list_table',
1236
-            'status' => $trash ? '' : 'trashed',
1237
-        );
1238
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1239
-    }
1240
-
1241
-
1242
-    /**
1243
-     * Handles trashing default ticket.
1244
-     */
1245
-    protected function _delete_ticket()
1246
-    {
1247
-        $success = 1;
1248
-        // checkboxes?
1249
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1250
-            // if array has more than one element then success message should be plural
1251
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1252
-            // cycle thru the boxes
1253
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1254
-                // delete
1255
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1256
-                    $success = 0;
1257
-                }
1258
-            }
1259
-        } else {
1260
-            // grab single id and trash
1261
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1262
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1263
-                $success = 0;
1264
-            }
1265
-        }
1266
-        $action_desc = 'deleted';
1267
-        $query_args = array(
1268
-            'action' => 'ticket_list_table',
1269
-            'status' => 'trashed',
1270
-        );
1271
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1272
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1273
-            array(array('TKT_is_default' => 1)),
1274
-            'TKT_ID',
1275
-            true
1276
-        )
1277
-        ) {
1278
-            $query_args = array();
1279
-        }
1280
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * @param int $TKT_ID
1286
-     * @return bool|int
1287
-     * @throws EE_Error
1288
-     */
1289
-    protected function _delete_the_ticket($TKT_ID)
1290
-    {
1291
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1292
-        $tkt->_remove_relations('Datetime');
1293
-        // delete all related prices first
1294
-        $tkt->delete_related_permanently('Price');
1295
-        return $tkt->delete_permanently();
1296
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+	/**
36
+	 * Sets routes.
37
+	 */
38
+	protected function _extend_page_config()
39
+	{
40
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
41
+		// is there a evt_id in the request?
42
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
43
+			? $this->_req_data['EVT_ID']
44
+			: 0;
45
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
46
+		// tkt_id?
47
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
48
+			? $this->_req_data['TKT_ID']
49
+			: 0;
50
+		$new_page_routes = array(
51
+			'duplicate_event'          => array(
52
+				'func'       => '_duplicate_event',
53
+				'capability' => 'ee_edit_event',
54
+				'obj_id'     => $evt_id,
55
+				'noheader'   => true,
56
+			),
57
+			'ticket_list_table'        => array(
58
+				'func'       => '_tickets_overview_list_table',
59
+				'capability' => 'ee_read_default_tickets',
60
+			),
61
+			'trash_ticket'             => array(
62
+				'func'       => '_trash_or_restore_ticket',
63
+				'capability' => 'ee_delete_default_ticket',
64
+				'obj_id'     => $tkt_id,
65
+				'noheader'   => true,
66
+				'args'       => array('trash' => true),
67
+			),
68
+			'trash_tickets'            => array(
69
+				'func'       => '_trash_or_restore_ticket',
70
+				'capability' => 'ee_delete_default_tickets',
71
+				'noheader'   => true,
72
+				'args'       => array('trash' => true),
73
+			),
74
+			'restore_ticket'           => array(
75
+				'func'       => '_trash_or_restore_ticket',
76
+				'capability' => 'ee_delete_default_ticket',
77
+				'obj_id'     => $tkt_id,
78
+				'noheader'   => true,
79
+			),
80
+			'restore_tickets'          => array(
81
+				'func'       => '_trash_or_restore_ticket',
82
+				'capability' => 'ee_delete_default_tickets',
83
+				'noheader'   => true,
84
+			),
85
+			'delete_ticket'            => array(
86
+				'func'       => '_delete_ticket',
87
+				'capability' => 'ee_delete_default_ticket',
88
+				'obj_id'     => $tkt_id,
89
+				'noheader'   => true,
90
+			),
91
+			'delete_tickets'           => array(
92
+				'func'       => '_delete_ticket',
93
+				'capability' => 'ee_delete_default_tickets',
94
+				'noheader'   => true,
95
+			),
96
+			'import_page'              => array(
97
+				'func'       => '_import_page',
98
+				'capability' => 'import',
99
+			),
100
+			'import'                   => array(
101
+				'func'       => '_import_events',
102
+				'capability' => 'import',
103
+				'noheader'   => true,
104
+			),
105
+			'import_events'            => array(
106
+				'func'       => '_import_events',
107
+				'capability' => 'import',
108
+				'noheader'   => true,
109
+			),
110
+			'export_events'            => array(
111
+				'func'       => '_events_export',
112
+				'capability' => 'export',
113
+				'noheader'   => true,
114
+			),
115
+			'export_categories'        => array(
116
+				'func'       => '_categories_export',
117
+				'capability' => 'export',
118
+				'noheader'   => true,
119
+			),
120
+			'sample_export_file'       => array(
121
+				'func'       => '_sample_export_file',
122
+				'capability' => 'export',
123
+				'noheader'   => true,
124
+			),
125
+			'update_template_settings' => array(
126
+				'func'       => '_update_template_settings',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+		);
131
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
132
+		// partial route/config override
133
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
134
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
135
+		$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
136
+		$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
137
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
138
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
139
+		// add tickets tab but only if there are more than one default ticket!
140
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
141
+			array(array('TKT_is_default' => 1)),
142
+			'TKT_ID',
143
+			true
144
+		);
145
+		if ($tkt_count > 1) {
146
+			$new_page_config = array(
147
+				'ticket_list_table' => array(
148
+					'nav'           => array(
149
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
150
+						'order' => 60,
151
+					),
152
+					'list_table'    => 'Tickets_List_Table',
153
+					'require_nonce' => false,
154
+				),
155
+			);
156
+		}
157
+		// template settings
158
+		$new_page_config['template_settings'] = array(
159
+			'nav'           => array(
160
+				'label' => esc_html__('Templates', 'event_espresso'),
161
+				'order' => 30,
162
+			),
163
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
164
+			'help_tabs'     => array(
165
+				'general_settings_templates_help_tab' => array(
166
+					'title'    => esc_html__('Templates', 'event_espresso'),
167
+					'filename' => 'general_settings_templates',
168
+				),
169
+			),
170
+			'help_tour'     => array('Templates_Help_Tour'),
171
+			'require_nonce' => false,
172
+		);
173
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
174
+		// add filters and actions
175
+		// modifying _views
176
+		add_filter(
177
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
178
+			array($this, 'add_additional_datetime_button'),
179
+			10,
180
+			2
181
+		);
182
+		add_filter(
183
+			'FHEE_event_datetime_metabox_clone_button_template',
184
+			array($this, 'add_datetime_clone_button'),
185
+			10,
186
+			2
187
+		);
188
+		add_filter(
189
+			'FHEE_event_datetime_metabox_timezones_template',
190
+			array($this, 'datetime_timezones_template'),
191
+			10,
192
+			2
193
+		);
194
+		// filters for event list table
195
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
196
+		add_filter(
197
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
198
+			array($this, 'extra_list_table_actions'),
199
+			10,
200
+			2
201
+		);
202
+		// legend item
203
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
204
+		add_action('admin_init', array($this, 'admin_init'));
205
+		// heartbeat stuff
206
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
207
+	}
208
+
209
+
210
+	/**
211
+	 * admin_init
212
+	 */
213
+	public function admin_init()
214
+	{
215
+		EE_Registry::$i18n_js_strings = array_merge(
216
+			EE_Registry::$i18n_js_strings,
217
+			array(
218
+				'image_confirm'          => esc_html__(
219
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
220
+					'event_espresso'
221
+				),
222
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
223
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
224
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
225
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
226
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
227
+			)
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
+	 * accordingly.
235
+	 *
236
+	 * @param array $response The existing heartbeat response array.
237
+	 * @param array $data     The incoming data package.
238
+	 * @return array  possibly appended response.
239
+	 */
240
+	public function heartbeat_response($response, $data)
241
+	{
242
+		/**
243
+		 * check whether count of tickets is approaching the potential
244
+		 * limits for the server.
245
+		 */
246
+		if (! empty($data['input_count'])) {
247
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
+				$data['input_count']
249
+			);
250
+		}
251
+		return $response;
252
+	}
253
+
254
+
255
+	/**
256
+	 * Add per page screen options to the default ticket list table view.
257
+	 */
258
+	protected function _add_screen_options_ticket_list_table()
259
+	{
260
+		$this->_per_page_screen_option();
261
+	}
262
+
263
+
264
+	/**
265
+	 * @param string $return
266
+	 * @param int    $id
267
+	 * @param string $new_title
268
+	 * @param string $new_slug
269
+	 * @return string
270
+	 */
271
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
272
+	{
273
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
274
+		// make sure this is only when editing
275
+		if (! empty($id)) {
276
+			$href = EE_Admin_Page::add_query_args_and_nonce(
277
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
278
+				$this->_admin_base_url
279
+			);
280
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
281
+			$return .= '<a href="'
282
+					   . $href
283
+					   . '" title="'
284
+					   . $title
285
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
286
+					   . $title
287
+					   . '</a>';
288
+		}
289
+		return $return;
290
+	}
291
+
292
+
293
+	/**
294
+	 * Set the list table views for the default ticket list table view.
295
+	 */
296
+	public function _set_list_table_views_ticket_list_table()
297
+	{
298
+		$this->_views = array(
299
+			'all'     => array(
300
+				'slug'        => 'all',
301
+				'label'       => esc_html__('All', 'event_espresso'),
302
+				'count'       => 0,
303
+				'bulk_action' => array(
304
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
305
+				),
306
+			),
307
+			'trashed' => array(
308
+				'slug'        => 'trashed',
309
+				'label'       => esc_html__('Trash', 'event_espresso'),
310
+				'count'       => 0,
311
+				'bulk_action' => array(
312
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
313
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
314
+				),
315
+			),
316
+		);
317
+	}
318
+
319
+
320
+	/**
321
+	 * Enqueue scripts and styles for the event editor.
322
+	 */
323
+	public function load_scripts_styles_edit()
324
+	{
325
+		wp_register_script(
326
+			'ee-event-editor-heartbeat',
327
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
328
+			array('ee_admin_js', 'heartbeat'),
329
+			EVENT_ESPRESSO_VERSION,
330
+			true
331
+		);
332
+		wp_enqueue_script('ee-accounting');
333
+		// styles
334
+		wp_enqueue_style('espresso-ui-theme');
335
+		wp_enqueue_script('event_editor_js');
336
+		wp_enqueue_script('ee-event-editor-heartbeat');
337
+	}
338
+
339
+
340
+	/**
341
+	 * Returns template for the additional datetime.
342
+	 *
343
+	 * @param $template
344
+	 * @param $template_args
345
+	 * @return mixed
346
+	 * @throws DomainException
347
+	 */
348
+	public function add_additional_datetime_button($template, $template_args)
349
+	{
350
+		return EEH_Template::display_template(
351
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
352
+			$template_args,
353
+			true
354
+		);
355
+	}
356
+
357
+
358
+	/**
359
+	 * Returns the template for cloning a datetime.
360
+	 *
361
+	 * @param $template
362
+	 * @param $template_args
363
+	 * @return mixed
364
+	 * @throws DomainException
365
+	 */
366
+	public function add_datetime_clone_button($template, $template_args)
367
+	{
368
+		return EEH_Template::display_template(
369
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
370
+			$template_args,
371
+			true
372
+		);
373
+	}
374
+
375
+
376
+	/**
377
+	 * Returns the template for datetime timezones.
378
+	 *
379
+	 * @param $template
380
+	 * @param $template_args
381
+	 * @return mixed
382
+	 * @throws DomainException
383
+	 */
384
+	public function datetime_timezones_template($template, $template_args)
385
+	{
386
+		return EEH_Template::display_template(
387
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
388
+			$template_args,
389
+			true
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * Sets the views for the default list table view.
396
+	 */
397
+	protected function _set_list_table_views_default()
398
+	{
399
+		parent::_set_list_table_views_default();
400
+		$new_views = array(
401
+			'today' => array(
402
+				'slug'        => 'today',
403
+				'label'       => esc_html__('Today', 'event_espresso'),
404
+				'count'       => $this->total_events_today(),
405
+				'bulk_action' => array(
406
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
407
+				),
408
+			),
409
+			'month' => array(
410
+				'slug'        => 'month',
411
+				'label'       => esc_html__('This Month', 'event_espresso'),
412
+				'count'       => $this->total_events_this_month(),
413
+				'bulk_action' => array(
414
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
415
+				),
416
+			),
417
+		);
418
+		$this->_views = array_merge($this->_views, $new_views);
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns the extra action links for the default list table view.
424
+	 *
425
+	 * @param array     $action_links
426
+	 * @param \EE_Event $event
427
+	 * @return array
428
+	 * @throws EE_Error
429
+	 */
430
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
431
+	{
432
+		if (EE_Registry::instance()->CAP->current_user_can(
433
+			'ee_read_registrations',
434
+			'espresso_registrations_reports',
435
+			$event->ID()
436
+		)
437
+		) {
438
+			$reports_query_args = array(
439
+				'action' => 'reports',
440
+				'EVT_ID' => $event->ID(),
441
+			);
442
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
443
+			$action_links[] = '<a href="'
444
+							  . $reports_link
445
+							  . '" title="'
446
+							  . esc_attr__('View Report', 'event_espresso')
447
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
448
+							  . "\n\t";
449
+		}
450
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
451
+			EE_Registry::instance()->load_helper('MSG_Template');
452
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
453
+				'see_notifications_for',
454
+				null,
455
+				array('EVT_ID' => $event->ID())
456
+			);
457
+		}
458
+		return $action_links;
459
+	}
460
+
461
+
462
+	/**
463
+	 * @param $items
464
+	 * @return mixed
465
+	 */
466
+	public function additional_legend_items($items)
467
+	{
468
+		if (EE_Registry::instance()->CAP->current_user_can(
469
+			'ee_read_registrations',
470
+			'espresso_registrations_reports'
471
+		)
472
+		) {
473
+			$items['reports'] = array(
474
+				'class' => 'dashicons dashicons-chart-bar',
475
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
476
+			);
477
+		}
478
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
479
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
480
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
481
+				$items['view_related_messages'] = array(
482
+					'class' => $related_for_icon['css_class'],
483
+					'desc'  => $related_for_icon['label'],
484
+				);
485
+			}
486
+		}
487
+		return $items;
488
+	}
489
+
490
+
491
+	/**
492
+	 * This is the callback method for the duplicate event route
493
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
494
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
495
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
496
+	 * After duplication the redirect is to the new event edit page.
497
+	 *
498
+	 * @return void
499
+	 * @access protected
500
+	 * @throws EE_Error If EE_Event is not available with given ID
501
+	 */
502
+	protected function _duplicate_event()
503
+	{
504
+		// first make sure the ID for the event is in the request.
505
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
506
+		if (! isset($this->_req_data['EVT_ID'])) {
507
+			EE_Error::add_error(
508
+				esc_html__(
509
+					'In order to duplicate an event an Event ID is required.  None was given.',
510
+					'event_espresso'
511
+				),
512
+				__FILE__,
513
+				__FUNCTION__,
514
+				__LINE__
515
+			);
516
+			$this->_redirect_after_action(false, '', '', array(), true);
517
+			return;
518
+		}
519
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
520
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
521
+		if (! $orig_event instanceof EE_Event) {
522
+			throw new EE_Error(
523
+				sprintf(
524
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
525
+					$this->_req_data['EVT_ID']
526
+				)
527
+			);
528
+		}
529
+		// k now let's clone the $orig_event before getting relations
530
+		$new_event = clone $orig_event;
531
+		// original datetimes
532
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
533
+		// other original relations
534
+		$orig_ven = $orig_event->get_many_related('Venue');
535
+		// reset the ID and modify other details to make it clear this is a dupe
536
+		$new_event->set('EVT_ID', 0);
537
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
538
+		$new_event->set('EVT_name', $new_name);
539
+		$new_event->set(
540
+			'EVT_slug',
541
+			wp_unique_post_slug(
542
+				sanitize_title($orig_event->name()),
543
+				0,
544
+				'publish',
545
+				'espresso_events',
546
+				0
547
+			)
548
+		);
549
+		$new_event->set('status', 'draft');
550
+		// duplicate discussion settings
551
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
552
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
553
+		// save the new event
554
+		$new_event->save();
555
+		// venues
556
+		foreach ($orig_ven as $ven) {
557
+			$new_event->_add_relation_to($ven, 'Venue');
558
+		}
559
+		$new_event->save();
560
+		// now we need to get the question group relations and handle that
561
+		// first primary question groups
562
+		$orig_primary_qgs = $orig_event->get_many_related(
563
+			'Question_Group',
564
+			array(array('Event_Question_Group.EQG_primary' => 1))
565
+		);
566
+		if (! empty($orig_primary_qgs)) {
567
+			foreach ($orig_primary_qgs as $id => $obj) {
568
+				if ($obj instanceof EE_Question_Group) {
569
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
570
+				}
571
+			}
572
+		}
573
+		// next additional attendee question groups
574
+		$orig_additional_qgs = $orig_event->get_many_related(
575
+			'Question_Group',
576
+			array(array('Event_Question_Group.EQG_primary' => 0))
577
+		);
578
+		if (! empty($orig_additional_qgs)) {
579
+			foreach ($orig_additional_qgs as $id => $obj) {
580
+				if ($obj instanceof EE_Question_Group) {
581
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
582
+				}
583
+			}
584
+		}
585
+
586
+		$new_event->save();
587
+
588
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
589
+		$cloned_tickets = array();
590
+		foreach ($orig_datetimes as $orig_dtt) {
591
+			if (! $orig_dtt instanceof EE_Datetime) {
592
+				continue;
593
+			}
594
+			$new_dtt = clone $orig_dtt;
595
+			$orig_tkts = $orig_dtt->tickets();
596
+			// save new dtt then add to event
597
+			$new_dtt->set('DTT_ID', 0);
598
+			$new_dtt->set('DTT_sold', 0);
599
+			$new_dtt->set_reserved(0);
600
+			$new_dtt->save();
601
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
602
+			$new_event->save();
603
+			// now let's get the ticket relations setup.
604
+			foreach ((array) $orig_tkts as $orig_tkt) {
605
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
606
+				if (! $orig_tkt instanceof EE_Ticket) {
607
+					continue;
608
+				}
609
+				// is this ticket archived?  If it is then let's skip
610
+				if ($orig_tkt->get('TKT_deleted')) {
611
+					continue;
612
+				}
613
+				// does this original ticket already exist in the clone_tickets cache?
614
+				//  If so we'll just use the new ticket from it.
615
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
616
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
617
+				} else {
618
+					$new_tkt = clone $orig_tkt;
619
+					// get relations on the $orig_tkt that we need to setup.
620
+					$orig_prices = $orig_tkt->prices();
621
+					$new_tkt->set('TKT_ID', 0);
622
+					$new_tkt->set('TKT_sold', 0);
623
+					$new_tkt->set('TKT_reserved', 0);
624
+					$new_tkt->save(); // make sure new ticket has ID.
625
+					// price relations on new ticket need to be setup.
626
+					foreach ($orig_prices as $orig_price) {
627
+						$new_price = clone $orig_price;
628
+						$new_price->set('PRC_ID', 0);
629
+						$new_price->save();
630
+						$new_tkt->_add_relation_to($new_price, 'Price');
631
+						$new_tkt->save();
632
+					}
633
+
634
+					do_action(
635
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
636
+						$orig_tkt,
637
+						$new_tkt,
638
+						$orig_prices,
639
+						$orig_event,
640
+						$orig_dtt,
641
+						$new_dtt
642
+					);
643
+				}
644
+				// k now we can add the new ticket as a relation to the new datetime
645
+				// and make sure its added to our cached $cloned_tickets array
646
+				// for use with later datetimes that have the same ticket.
647
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
648
+				$new_dtt->save();
649
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
650
+			}
651
+		}
652
+		// clone taxonomy information
653
+		$taxonomies_to_clone_with = apply_filters(
654
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
655
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
656
+		);
657
+		// get terms for original event (notice)
658
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
659
+		// loop through terms and add them to new event.
660
+		foreach ($orig_terms as $term) {
661
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
662
+		}
663
+
664
+		// duplicate other core WP_Post items for this event.
665
+		// post thumbnail (feature image).
666
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
667
+		if ($feature_image_id) {
668
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
669
+		}
670
+
671
+		// duplicate page_template setting
672
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
673
+		if ($page_template) {
674
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
675
+		}
676
+
677
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
678
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
679
+		if ($new_event->ID()) {
680
+			$redirect_args = array(
681
+				'post'   => $new_event->ID(),
682
+				'action' => 'edit',
683
+			);
684
+			EE_Error::add_success(
685
+				esc_html__(
686
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
687
+					'event_espresso'
688
+				)
689
+			);
690
+		} else {
691
+			$redirect_args = array(
692
+				'action' => 'default',
693
+			);
694
+			EE_Error::add_error(
695
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
696
+				__FILE__,
697
+				__FUNCTION__,
698
+				__LINE__
699
+			);
700
+		}
701
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
702
+	}
703
+
704
+
705
+	/**
706
+	 * Generates output for the import page.
707
+	 *
708
+	 * @throws DomainException
709
+	 */
710
+	protected function _import_page()
711
+	{
712
+		$title = esc_html__('Import', 'event_espresso');
713
+		$intro = esc_html__(
714
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
715
+			'event_espresso'
716
+		);
717
+		$form_url = EVENTS_ADMIN_URL;
718
+		$action = 'import_events';
719
+		$type = 'csv';
720
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
721
+			$title,
722
+			$intro,
723
+			$form_url,
724
+			$action,
725
+			$type
726
+		);
727
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
728
+			array('action' => 'sample_export_file'),
729
+			$this->_admin_base_url
730
+		);
731
+		$content = EEH_Template::display_template(
732
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
733
+			$this->_template_args,
734
+			true
735
+		);
736
+		$this->_template_args['admin_page_content'] = $content;
737
+		$this->display_admin_page_with_sidebar();
738
+	}
739
+
740
+
741
+	/**
742
+	 * _import_events
743
+	 * This handles displaying the screen and running imports for importing events.
744
+	 *
745
+	 * @return void
746
+	 */
747
+	protected function _import_events()
748
+	{
749
+		require_once(EE_CLASSES . 'EE_Import.class.php');
750
+		$success = EE_Import::instance()->import();
751
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
752
+	}
753
+
754
+
755
+	/**
756
+	 * _events_export
757
+	 * Will export all (or just the given event) to a Excel compatible file.
758
+	 *
759
+	 * @access protected
760
+	 * @return void
761
+	 */
762
+	protected function _events_export()
763
+	{
764
+		if (isset($this->_req_data['EVT_ID'])) {
765
+			$event_ids = $this->_req_data['EVT_ID'];
766
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
767
+			$event_ids = $this->_req_data['EVT_IDs'];
768
+		} else {
769
+			$event_ids = null;
770
+		}
771
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
772
+		$new_request_args = array(
773
+			'export' => 'report',
774
+			'action' => 'all_event_data',
775
+			'EVT_ID' => $event_ids,
776
+		);
777
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
778
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
779
+			require_once(EE_CLASSES . 'EE_Export.class.php');
780
+			$EE_Export = EE_Export::instance($this->_req_data);
781
+			$EE_Export->export();
782
+		}
783
+	}
784
+
785
+
786
+	/**
787
+	 * handle category exports()
788
+	 *
789
+	 * @return void
790
+	 */
791
+	protected function _categories_export()
792
+	{
793
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
794
+		$new_request_args = array(
795
+			'export'       => 'report',
796
+			'action'       => 'categories',
797
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
798
+		);
799
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
800
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
801
+			require_once(EE_CLASSES . 'EE_Export.class.php');
802
+			$EE_Export = EE_Export::instance($this->_req_data);
803
+			$EE_Export->export();
804
+		}
805
+	}
806
+
807
+
808
+	/**
809
+	 * Creates a sample CSV file for importing
810
+	 */
811
+	protected function _sample_export_file()
812
+	{
813
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
814
+		EE_Export::instance()->export_sample();
815
+	}
816
+
817
+
818
+	/*************        Template Settings        *************/
819
+	/**
820
+	 * Generates template settings page output
821
+	 *
822
+	 * @throws DomainException
823
+	 * @throws EE_Error
824
+	 */
825
+	protected function _template_settings()
826
+	{
827
+		$this->_template_args['values'] = $this->_yes_no_values;
828
+		/**
829
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
830
+		 * from General_Settings_Admin_Page to here.
831
+		 */
832
+		$this->_template_args = apply_filters(
833
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
834
+			$this->_template_args
835
+		);
836
+		$this->_set_add_edit_form_tags('update_template_settings');
837
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
838
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
839
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
840
+			$this->_template_args,
841
+			true
842
+		);
843
+		$this->display_admin_page_with_sidebar();
844
+	}
845
+
846
+
847
+	/**
848
+	 * Handler for updating template settings.
849
+	 *
850
+	 * @throws InvalidInterfaceException
851
+	 * @throws InvalidDataTypeException
852
+	 * @throws InvalidArgumentException
853
+	 */
854
+	protected function _update_template_settings()
855
+	{
856
+		/**
857
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
858
+		 * from General_Settings_Admin_Page to here.
859
+		 */
860
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
861
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
862
+			EE_Registry::instance()->CFG->template_settings,
863
+			$this->_req_data
864
+		);
865
+		// update custom post type slugs and detect if we need to flush rewrite rules
866
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
867
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
868
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
869
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
870
+		$what = 'Template Settings';
871
+		$success = $this->_update_espresso_configuration(
872
+			$what,
873
+			EE_Registry::instance()->CFG->template_settings,
874
+			__FILE__,
875
+			__FUNCTION__,
876
+			__LINE__
877
+		);
878
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
879
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
880
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
881
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
882
+			);
883
+			$rewrite_rules->flush();
884
+		}
885
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
886
+	}
887
+
888
+
889
+	/**
890
+	 * _premium_event_editor_meta_boxes
891
+	 * add all metaboxes related to the event_editor
892
+	 *
893
+	 * @access protected
894
+	 * @return void
895
+	 * @throws EE_Error
896
+	 */
897
+	protected function _premium_event_editor_meta_boxes()
898
+	{
899
+		$this->verify_cpt_object();
900
+		add_meta_box(
901
+			'espresso_event_editor_event_options',
902
+			esc_html__('Event Registration Options', 'event_espresso'),
903
+			array($this, 'registration_options_meta_box'),
904
+			$this->page_slug,
905
+			'side',
906
+			'core'
907
+		);
908
+	}
909
+
910
+
911
+	/**
912
+	 * override caf metabox
913
+	 *
914
+	 * @return void
915
+	 * @throws DomainException
916
+	 */
917
+	public function registration_options_meta_box()
918
+	{
919
+		$yes_no_values = array(
920
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
921
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
922
+		);
923
+		$default_reg_status_values = EEM_Registration::reg_status_array(
924
+			array(
925
+				EEM_Registration::status_id_cancelled,
926
+				EEM_Registration::status_id_declined,
927
+				EEM_Registration::status_id_incomplete,
928
+				EEM_Registration::status_id_wait_list,
929
+			),
930
+			true
931
+		);
932
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
933
+		$template_args['_event'] = $this->_cpt_model_obj;
934
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
935
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
936
+			'default_reg_status',
937
+			$default_reg_status_values,
938
+			$this->_cpt_model_obj->default_registration_status()
939
+		);
940
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
941
+			'display_desc',
942
+			$yes_no_values,
943
+			$this->_cpt_model_obj->display_description()
944
+		);
945
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
946
+			'display_ticket_selector',
947
+			$yes_no_values,
948
+			$this->_cpt_model_obj->display_ticket_selector(),
949
+			'',
950
+			'',
951
+			false
952
+		);
953
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
954
+			'EVT_default_registration_status',
955
+			$default_reg_status_values,
956
+			$this->_cpt_model_obj->default_registration_status()
957
+		);
958
+		$template_args['additional_registration_options'] = apply_filters(
959
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
960
+			'',
961
+			$template_args,
962
+			$yes_no_values,
963
+			$default_reg_status_values
964
+		);
965
+		EEH_Template::display_template(
966
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
967
+			$template_args
968
+		);
969
+	}
970
+
971
+
972
+
973
+	/**
974
+	 * wp_list_table_mods for caf
975
+	 * ============================
976
+	 */
977
+	/**
978
+	 * hook into list table filters and provide filters for caffeinated list table
979
+	 *
980
+	 * @param  array $old_filters    any existing filters present
981
+	 * @param  array $list_table_obj the list table object
982
+	 * @return array                  new filters
983
+	 */
984
+	public function list_table_filters($old_filters, $list_table_obj)
985
+	{
986
+		$filters = array();
987
+		// first month/year filters
988
+		$filters[] = $this->espresso_event_months_dropdown();
989
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
990
+		// active status dropdown
991
+		if ($status !== 'draft') {
992
+			$filters[] = $this->active_status_dropdown(
993
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
994
+			);
995
+		}
996
+		// category filter
997
+		$filters[] = $this->category_dropdown();
998
+		return array_merge($old_filters, $filters);
999
+	}
1000
+
1001
+
1002
+	/**
1003
+	 * espresso_event_months_dropdown
1004
+	 *
1005
+	 * @access public
1006
+	 * @return string                dropdown listing month/year selections for events.
1007
+	 */
1008
+	public function espresso_event_months_dropdown()
1009
+	{
1010
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1011
+		// Note we need to include any other filters that are set!
1012
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1013
+		// categories?
1014
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1015
+			? $this->_req_data['EVT_CAT']
1016
+			: null;
1017
+		// active status?
1018
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1019
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1020
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * returns a list of "active" statuses on the event
1026
+	 *
1027
+	 * @param  string $current_value whatever the current active status is
1028
+	 * @return string
1029
+	 */
1030
+	public function active_status_dropdown($current_value = '')
1031
+	{
1032
+		$select_name = 'active_status';
1033
+		$values = array(
1034
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1035
+			'active'   => esc_html__('Active', 'event_espresso'),
1036
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1037
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1038
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1039
+		);
1040
+		$id = 'id="espresso-active-status-dropdown-filter"';
1041
+		$class = 'wide';
1042
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1043
+	}
1044
+
1045
+
1046
+	/**
1047
+	 * output a dropdown of the categories for the category filter on the event admin list table
1048
+	 *
1049
+	 * @access  public
1050
+	 * @return string html
1051
+	 */
1052
+	public function category_dropdown()
1053
+	{
1054
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1055
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 * get total number of events today
1061
+	 *
1062
+	 * @access public
1063
+	 * @return int
1064
+	 * @throws EE_Error
1065
+	 */
1066
+	public function total_events_today()
1067
+	{
1068
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1069
+			'DTT_EVT_start',
1070
+			date('Y-m-d') . ' 00:00:00',
1071
+			'Y-m-d H:i:s',
1072
+			'UTC'
1073
+		);
1074
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1075
+			'DTT_EVT_start',
1076
+			date('Y-m-d') . ' 23:59:59',
1077
+			'Y-m-d H:i:s',
1078
+			'UTC'
1079
+		);
1080
+		$where = array(
1081
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1082
+		);
1083
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1084
+		return $count;
1085
+	}
1086
+
1087
+
1088
+	/**
1089
+	 * get total number of events this month
1090
+	 *
1091
+	 * @access public
1092
+	 * @return int
1093
+	 * @throws EE_Error
1094
+	 */
1095
+	public function total_events_this_month()
1096
+	{
1097
+		// Dates
1098
+		$this_year_r = date('Y');
1099
+		$this_month_r = date('m');
1100
+		$days_this_month = date('t');
1101
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1102
+			'DTT_EVT_start',
1103
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1104
+			'Y-m-d H:i:s',
1105
+			'UTC'
1106
+		);
1107
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1108
+			'DTT_EVT_start',
1109
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1110
+			'Y-m-d H:i:s',
1111
+			'UTC'
1112
+		);
1113
+		$where = array(
1114
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1115
+		);
1116
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1117
+		return $count;
1118
+	}
1119
+
1120
+
1121
+	/** DEFAULT TICKETS STUFF **/
1122
+
1123
+	/**
1124
+	 * Output default tickets list table view.
1125
+	 */
1126
+	public function _tickets_overview_list_table()
1127
+	{
1128
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1129
+		$this->display_admin_list_table_page_with_no_sidebar();
1130
+	}
1131
+
1132
+
1133
+	/**
1134
+	 * @param int  $per_page
1135
+	 * @param bool $count
1136
+	 * @param bool $trashed
1137
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1138
+	 */
1139
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1140
+	{
1141
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1142
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1143
+		switch ($orderby) {
1144
+			case 'TKT_name':
1145
+				$orderby = array('TKT_name' => $order);
1146
+				break;
1147
+			case 'TKT_price':
1148
+				$orderby = array('TKT_price' => $order);
1149
+				break;
1150
+			case 'TKT_uses':
1151
+				$orderby = array('TKT_uses' => $order);
1152
+				break;
1153
+			case 'TKT_min':
1154
+				$orderby = array('TKT_min' => $order);
1155
+				break;
1156
+			case 'TKT_max':
1157
+				$orderby = array('TKT_max' => $order);
1158
+				break;
1159
+			case 'TKT_qty':
1160
+				$orderby = array('TKT_qty' => $order);
1161
+				break;
1162
+		}
1163
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1164
+			? $this->_req_data['paged']
1165
+			: 1;
1166
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1167
+			? $this->_req_data['perpage']
1168
+			: $per_page;
1169
+		$_where = array(
1170
+			'TKT_is_default' => 1,
1171
+			'TKT_deleted'    => $trashed,
1172
+		);
1173
+		$offset = ($current_page - 1) * $per_page;
1174
+		$limit = array($offset, $per_page);
1175
+		if (isset($this->_req_data['s'])) {
1176
+			$sstr = '%' . $this->_req_data['s'] . '%';
1177
+			$_where['OR'] = array(
1178
+				'TKT_name'        => array('LIKE', $sstr),
1179
+				'TKT_description' => array('LIKE', $sstr),
1180
+			);
1181
+		}
1182
+		$query_params = array(
1183
+			$_where,
1184
+			'order_by' => $orderby,
1185
+			'limit'    => $limit,
1186
+			'group_by' => 'TKT_ID',
1187
+		);
1188
+		if ($count) {
1189
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1190
+		} else {
1191
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1192
+		}
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * @param bool $trash
1198
+	 * @throws EE_Error
1199
+	 */
1200
+	protected function _trash_or_restore_ticket($trash = false)
1201
+	{
1202
+		$success = 1;
1203
+		$TKT = EEM_Ticket::instance();
1204
+		// checkboxes?
1205
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1206
+			// if array has more than one element then success message should be plural
1207
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1208
+			// cycle thru the boxes
1209
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1210
+				if ($trash) {
1211
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1212
+						$success = 0;
1213
+					}
1214
+				} else {
1215
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1216
+						$success = 0;
1217
+					}
1218
+				}
1219
+			}
1220
+		} else {
1221
+			// grab single id and trash
1222
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1223
+			if ($trash) {
1224
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1225
+					$success = 0;
1226
+				}
1227
+			} else {
1228
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1229
+					$success = 0;
1230
+				}
1231
+			}
1232
+		}
1233
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1234
+		$query_args = array(
1235
+			'action' => 'ticket_list_table',
1236
+			'status' => $trash ? '' : 'trashed',
1237
+		);
1238
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1239
+	}
1240
+
1241
+
1242
+	/**
1243
+	 * Handles trashing default ticket.
1244
+	 */
1245
+	protected function _delete_ticket()
1246
+	{
1247
+		$success = 1;
1248
+		// checkboxes?
1249
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1250
+			// if array has more than one element then success message should be plural
1251
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1252
+			// cycle thru the boxes
1253
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1254
+				// delete
1255
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1256
+					$success = 0;
1257
+				}
1258
+			}
1259
+		} else {
1260
+			// grab single id and trash
1261
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1262
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1263
+				$success = 0;
1264
+			}
1265
+		}
1266
+		$action_desc = 'deleted';
1267
+		$query_args = array(
1268
+			'action' => 'ticket_list_table',
1269
+			'status' => 'trashed',
1270
+		);
1271
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1272
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1273
+			array(array('TKT_is_default' => 1)),
1274
+			'TKT_ID',
1275
+			true
1276
+		)
1277
+		) {
1278
+			$query_args = array();
1279
+		}
1280
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * @param int $TKT_ID
1286
+	 * @return bool|int
1287
+	 * @throws EE_Error
1288
+	 */
1289
+	protected function _delete_the_ticket($TKT_ID)
1290
+	{
1291
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1292
+		$tkt->_remove_relations('Datetime');
1293
+		// delete all related prices first
1294
+		$tkt->delete_related_permanently('Price');
1295
+		return $tkt->delete_permanently();
1296
+	}
1297 1297
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
     public function __construct($routing = true)
25 25
     {
26 26
         parent::__construct($routing);
27
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
27
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
29
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
30
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
31 31
         }
32 32
     }
33 33
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     protected function _extend_page_config()
39 39
     {
40
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
40
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
41 41
         // is there a evt_id in the request?
42 42
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
43 43
             ? $this->_req_data['EVT_ID']
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
          * check whether count of tickets is approaching the potential
244 244
          * limits for the server.
245 245
          */
246
-        if (! empty($data['input_count'])) {
246
+        if ( ! empty($data['input_count'])) {
247 247
             $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248 248
                 $data['input_count']
249 249
             );
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     {
273 273
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
274 274
         // make sure this is only when editing
275
-        if (! empty($id)) {
275
+        if ( ! empty($id)) {
276 276
             $href = EE_Admin_Page::add_query_args_and_nonce(
277 277
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
278 278
                 $this->_admin_base_url
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
     {
325 325
         wp_register_script(
326 326
             'ee-event-editor-heartbeat',
327
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
327
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
328 328
             array('ee_admin_js', 'heartbeat'),
329 329
             EVENT_ESPRESSO_VERSION,
330 330
             true
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
     public function add_additional_datetime_button($template, $template_args)
349 349
     {
350 350
         return EEH_Template::display_template(
351
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
351
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
352 352
             $template_args,
353 353
             true
354 354
         );
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
     public function add_datetime_clone_button($template, $template_args)
367 367
     {
368 368
         return EEH_Template::display_template(
369
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
369
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
370 370
             $template_args,
371 371
             true
372 372
         );
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
     public function datetime_timezones_template($template, $template_args)
385 385
     {
386 386
         return EEH_Template::display_template(
387
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
387
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
388 388
             $template_args,
389 389
             true
390 390
         );
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
     {
504 504
         // first make sure the ID for the event is in the request.
505 505
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
506
-        if (! isset($this->_req_data['EVT_ID'])) {
506
+        if ( ! isset($this->_req_data['EVT_ID'])) {
507 507
             EE_Error::add_error(
508 508
                 esc_html__(
509 509
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         }
519 519
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
520 520
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
521
-        if (! $orig_event instanceof EE_Event) {
521
+        if ( ! $orig_event instanceof EE_Event) {
522 522
             throw new EE_Error(
523 523
                 sprintf(
524 524
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         $orig_ven = $orig_event->get_many_related('Venue');
535 535
         // reset the ID and modify other details to make it clear this is a dupe
536 536
         $new_event->set('EVT_ID', 0);
537
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
537
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
538 538
         $new_event->set('EVT_name', $new_name);
539 539
         $new_event->set(
540 540
             'EVT_slug',
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
             'Question_Group',
564 564
             array(array('Event_Question_Group.EQG_primary' => 1))
565 565
         );
566
-        if (! empty($orig_primary_qgs)) {
566
+        if ( ! empty($orig_primary_qgs)) {
567 567
             foreach ($orig_primary_qgs as $id => $obj) {
568 568
                 if ($obj instanceof EE_Question_Group) {
569 569
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
             'Question_Group',
576 576
             array(array('Event_Question_Group.EQG_primary' => 0))
577 577
         );
578
-        if (! empty($orig_additional_qgs)) {
578
+        if ( ! empty($orig_additional_qgs)) {
579 579
             foreach ($orig_additional_qgs as $id => $obj) {
580 580
                 if ($obj instanceof EE_Question_Group) {
581 581
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
589 589
         $cloned_tickets = array();
590 590
         foreach ($orig_datetimes as $orig_dtt) {
591
-            if (! $orig_dtt instanceof EE_Datetime) {
591
+            if ( ! $orig_dtt instanceof EE_Datetime) {
592 592
                 continue;
593 593
             }
594 594
             $new_dtt = clone $orig_dtt;
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
             // now let's get the ticket relations setup.
604 604
             foreach ((array) $orig_tkts as $orig_tkt) {
605 605
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
606
-                if (! $orig_tkt instanceof EE_Ticket) {
606
+                if ( ! $orig_tkt instanceof EE_Ticket) {
607 607
                     continue;
608 608
                 }
609 609
                 // is this ticket archived?  If it is then let's skip
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
                 }
613 613
                 // does this original ticket already exist in the clone_tickets cache?
614 614
                 //  If so we'll just use the new ticket from it.
615
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
616
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
615
+                if (isset($cloned_tickets[$orig_tkt->ID()])) {
616
+                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
617 617
                 } else {
618 618
                     $new_tkt = clone $orig_tkt;
619 619
                     // get relations on the $orig_tkt that we need to setup.
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
                 // for use with later datetimes that have the same ticket.
647 647
                 $new_dtt->_add_relation_to($new_tkt, 'Ticket');
648 648
                 $new_dtt->save();
649
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
649
+                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
650 650
             }
651 651
         }
652 652
         // clone taxonomy information
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
             $this->_admin_base_url
730 730
         );
731 731
         $content = EEH_Template::display_template(
732
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
732
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
733 733
             $this->_template_args,
734 734
             true
735 735
         );
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
      */
747 747
     protected function _import_events()
748 748
     {
749
-        require_once(EE_CLASSES . 'EE_Import.class.php');
749
+        require_once(EE_CLASSES.'EE_Import.class.php');
750 750
         $success = EE_Import::instance()->import();
751 751
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
752 752
     }
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
             'EVT_ID' => $event_ids,
776 776
         );
777 777
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
778
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
779
-            require_once(EE_CLASSES . 'EE_Export.class.php');
778
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
779
+            require_once(EE_CLASSES.'EE_Export.class.php');
780 780
             $EE_Export = EE_Export::instance($this->_req_data);
781 781
             $EE_Export->export();
782 782
         }
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
798 798
         );
799 799
         $this->_req_data = array_merge($this->_req_data, $new_request_args);
800
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
801
-            require_once(EE_CLASSES . 'EE_Export.class.php');
800
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
801
+            require_once(EE_CLASSES.'EE_Export.class.php');
802 802
             $EE_Export = EE_Export::instance($this->_req_data);
803 803
             $EE_Export->export();
804 804
         }
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
         $this->_set_add_edit_form_tags('update_template_settings');
837 837
         $this->_set_publish_post_box_vars(null, false, false, null, false);
838 838
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
839
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
839
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
840 840
             $this->_template_args,
841 841
             true
842 842
         );
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
             $default_reg_status_values
964 964
         );
965 965
         EEH_Template::display_template(
966
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
966
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
967 967
             $template_args
968 968
         );
969 969
     }
@@ -1067,13 +1067,13 @@  discard block
 block discarded – undo
1067 1067
     {
1068 1068
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1069 1069
             'DTT_EVT_start',
1070
-            date('Y-m-d') . ' 00:00:00',
1070
+            date('Y-m-d').' 00:00:00',
1071 1071
             'Y-m-d H:i:s',
1072 1072
             'UTC'
1073 1073
         );
1074 1074
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1075 1075
             'DTT_EVT_start',
1076
-            date('Y-m-d') . ' 23:59:59',
1076
+            date('Y-m-d').' 23:59:59',
1077 1077
             'Y-m-d H:i:s',
1078 1078
             'UTC'
1079 1079
         );
@@ -1100,13 +1100,13 @@  discard block
 block discarded – undo
1100 1100
         $days_this_month = date('t');
1101 1101
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1102 1102
             'DTT_EVT_start',
1103
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1103
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1104 1104
             'Y-m-d H:i:s',
1105 1105
             'UTC'
1106 1106
         );
1107 1107
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1108 1108
             'DTT_EVT_start',
1109
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1109
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1110 1110
             'Y-m-d H:i:s',
1111 1111
             'UTC'
1112 1112
         );
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
         $offset = ($current_page - 1) * $per_page;
1174 1174
         $limit = array($offset, $per_page);
1175 1175
         if (isset($this->_req_data['s'])) {
1176
-            $sstr = '%' . $this->_req_data['s'] . '%';
1176
+            $sstr = '%'.$this->_req_data['s'].'%';
1177 1177
             $_where['OR'] = array(
1178 1178
                 'TKT_name'        => array('LIKE', $sstr),
1179 1179
                 'TKT_description' => array('LIKE', $sstr),
@@ -1202,17 +1202,17 @@  discard block
 block discarded – undo
1202 1202
         $success = 1;
1203 1203
         $TKT = EEM_Ticket::instance();
1204 1204
         // checkboxes?
1205
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1205
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1206 1206
             // if array has more than one element then success message should be plural
1207 1207
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1208 1208
             // cycle thru the boxes
1209 1209
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1210 1210
                 if ($trash) {
1211
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1211
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1212 1212
                         $success = 0;
1213 1213
                     }
1214 1214
                 } else {
1215
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1215
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1216 1216
                         $success = 0;
1217 1217
                     }
1218 1218
                 }
@@ -1221,11 +1221,11 @@  discard block
 block discarded – undo
1221 1221
             // grab single id and trash
1222 1222
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1223 1223
             if ($trash) {
1224
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1224
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1225 1225
                     $success = 0;
1226 1226
                 }
1227 1227
             } else {
1228
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1228
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1229 1229
                     $success = 0;
1230 1230
                 }
1231 1231
             }
@@ -1246,20 +1246,20 @@  discard block
 block discarded – undo
1246 1246
     {
1247 1247
         $success = 1;
1248 1248
         // checkboxes?
1249
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1249
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1250 1250
             // if array has more than one element then success message should be plural
1251 1251
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1252 1252
             // cycle thru the boxes
1253 1253
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1254 1254
                 // delete
1255
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1255
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1256 1256
                     $success = 0;
1257 1257
                 }
1258 1258
             }
1259 1259
         } else {
1260 1260
             // grab single id and trash
1261 1261
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1262
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1262
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1263 1263
                 $success = 0;
1264 1264
             }
1265 1265
         }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Loader.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
4
-use EventEspresso\core\exceptions\InvalidDataTypeException;
5 4
 
6 5
 /**
7 6
  * Event Espresso
Please login to merge, or discard this patch.
Indentation   +674 added lines, -674 removed lines patch added patch discarded remove patch
@@ -24,678 +24,678 @@
 block discarded – undo
24 24
 class EE_Admin_Page_Loader
25 25
 {
26 26
 
27
-    /**
28
-     * _installed_pages
29
-     * objects for page_init objects detected and loaded
30
-     *
31
-     * @access private
32
-     * @var \EE_Admin_Page_Init[]
33
-     */
34
-    private $_installed_pages = array();
35
-
36
-
37
-    /**
38
-     * this is used to hold the registry of menu slugs for all the installed admin pages
39
-     *
40
-     * @var array
41
-     */
42
-    private $_menu_slugs = array();
43
-
44
-
45
-    /**
46
-     * _caffeinated_extends
47
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
48
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
49
-     *
50
-     * @var array
51
-     */
52
-    private $_caffeinated_extends = array();
53
-
54
-
55
-    /**
56
-     * _current_caf_extend_slug
57
-     * This property is used for holding the page slug that is required for referencing the correct
58
-     * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
59
-     *
60
-     * @var array
61
-     */
62
-    private $_current_caf_extend_slug;
63
-
64
-    /**
65
-     * _prepped_menu_maps
66
-     * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
67
-     *
68
-     * @since  4.4.0
69
-     * @var EE_Admin_Page_Menu_Map[]
70
-     */
71
-    private $_prepped_menu_maps = array();
72
-
73
-
74
-    /**
75
-     * _admin_menu_groups
76
-     * array that holds the group headings and details for
77
-     *
78
-     * @access private
79
-     * @var array
80
-     */
81
-    private $_admin_menu_groups = array();
82
-
83
-
84
-    /**
85
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
86
-     * pages.
87
-     *
88
-     * @var string
89
-     */
90
-    public $hook_file;
91
-
92
-
93
-    /**
94
-     * constructor
95
-     *
96
-     * @access public
97
-     * @return \EE_Admin_Page_Loader
98
-     */
99
-    public function __construct()
100
-    {
101
-        // load menu_map classes
102
-        EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
103
-        // define the default "groups" for the admin_pages
104
-        $this->_set_menu_groups();
105
-
106
-        // let's do a scan and see what installed pages we have
107
-        $this->_get_installed_pages();
108
-        // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
109
-        add_action('admin_menu', array($this, 'set_menus'));
110
-        add_action('network_admin_menu', array($this, 'set_network_menus'));
111
-    }
112
-
113
-
114
-    /**
115
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
116
-     * files in the caffeinated folder.
117
-     *
118
-     * @access private
119
-     * @return void
120
-     */
121
-    private function _define_caffeinated_constants()
122
-    {
123
-        if (! defined('EE_CORE_CAF_ADMIN')) {
124
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
130
-        }
131
-    }
132
-
133
-
134
-    /**
135
-     * _set_menu_groups
136
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
137
-     *
138
-     * @access private
139
-     * @return void
140
-     */
141
-    private function _set_menu_groups()
142
-    {
143
-
144
-        // set array of EE_Admin_Page_Menu_Group objects
145
-        $groups = array(
146
-            'main'       => new EE_Admin_Page_Menu_Group(
147
-                array(
148
-                    'menu_label'   => __('Main', 'event_espresso'),
149
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
150
-                    'menu_slug'    => 'main',
151
-                    'capability'   => 'ee_read_ee',
152
-                    'menu_order'   => 0,
153
-                    'parent_slug'  => 'espresso_events',
154
-                )
155
-            ),
156
-            'management' => new EE_Admin_Page_Menu_Group(
157
-                array(
158
-                    'menu_label'   => __('Management', 'event_espresso'),
159
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
160
-                    'menu_slug'    => 'management',
161
-                    'capability'   => 'ee_read_ee',
162
-                    'menu_order'   => 10,
163
-                    'parent_slug'  => 'espresso_events',
164
-                )
165
-            ),
166
-            'settings'   => new EE_Admin_Page_Menu_Group(
167
-                array(
168
-                    'menu_label'   => __('Settings', 'event_espresso'),
169
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
-                    'menu_slug'    => 'settings',
171
-                    'capability'   => 'ee_read_ee',
172
-                    'menu_order'   => 30,
173
-                    'parent_slug'  => 'espresso_events',
174
-                )
175
-            ),
176
-            'templates'  => new EE_Admin_Page_Menu_Group(
177
-                array(
178
-                    'menu_label'   => __('Templates', 'event_espresso'),
179
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
-                    'menu_slug'    => 'templates',
181
-                    'capability'   => 'ee_read_ee',
182
-                    'menu_order'   => 40,
183
-                    'parent_slug'  => 'espresso_events',
184
-                )
185
-            ),
186
-            'extras'     => new EE_Admin_Page_Menu_Group(
187
-                array(
188
-                    'menu_label'              => __('Extras', 'event_espresso'),
189
-                    'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
190
-                    'menu_slug'               => 'extras',
191
-                    'capability'              => 'ee_read_ee',
192
-                    'menu_order'              => 50,
193
-                    'parent_slug'             => 'espresso_events',
194
-                    'maintenance_mode_parent' => 'espresso_maintenance_settings',
195
-                )
196
-            ),
197
-            'tools'      => new EE_Admin_Page_Menu_Group(
198
-                array(
199
-                    'menu_label'   => __("Tools", "event_espresso"),
200
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
-                    'menu_slug'    => 'tools',
202
-                    'capability'   => 'ee_read_ee',
203
-                    'menu_order'   => 60,
204
-                    'parent_slug'  => 'espresso_events',
205
-                )
206
-            ),
207
-            'addons'     => new EE_Admin_Page_Menu_Group(
208
-                array(
209
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
210
-                    'menu_label'   => __('Add-ons', 'event_espresso'),
211
-                    'menu_slug'    => 'addons',
212
-                    'capability'   => 'ee_read_ee',
213
-                    'menu_order'   => 20,
214
-                    'parent_slug'  => 'espresso_events',
215
-                )
216
-            ),
217
-        );
218
-        $this->_admin_menu_groups = apply_filters(
219
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
220
-            $groups
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
227
-     * slug.  The other utility with this function is it validates that all the groups are instances of
228
-     * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
229
-     *
230
-     * @since  4.4.0
231
-     * @throws \EE_Error
232
-     * @return EE_Admin_Page_Menu_Group[]
233
-     */
234
-    private function _rearrange_menu_groups()
235
-    {
236
-        $groups = array();
237
-        // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238
-        usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239
-        foreach ($this->_admin_menu_groups as $group) {
240
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
241
-                throw new EE_Error(
242
-                    sprintf(
243
-                        __(
244
-                            'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
245
-                            'event_espresso'
246
-                        ),
247
-                        print_r($group, true)
248
-                    )
249
-                );
250
-            }
251
-            $groups[ $group->menu_slug ] = $group;
252
-        }
253
-        return $groups;
254
-    }
255
-
256
-
257
-    /**
258
-     * _get_installed_pages
259
-     * This just gets the list of installed EE_Admin_pages.
260
-     *
261
-     * @access private
262
-     * @throws EE_Error
263
-     * @return void
264
-     */
265
-    private function _get_installed_pages()
266
-    {
267
-        $installed_refs = array();
268
-        $exclude = array('assets', 'templates');
269
-        // grab everything in the  admin core directory
270
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
271
-        if ($admin_screens) {
272
-            foreach ($admin_screens as $admin_screen) {
273
-                // files and anything in the exclude array need not apply
274
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275
-                    // these folders represent the different EE admin pages
276
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
277
-                }
278
-            }
279
-        }
280
-        if (empty($installed_refs)) {
281
-            $error_msg[] = __(
282
-                'There are no EE_Admin pages detected, it looks like EE did not install properly',
283
-                'event_espresso'
284
-            );
285
-            $error_msg[] = $error_msg[0] . "\r\n"
286
-                           . sprintf(
287
-                               __(
288
-                                   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
289
-                                   'event_espresso'
290
-                               ),
291
-                               EE_ADMIN_PAGES
292
-                           );
293
-            throw new EE_Error(implode('||', $error_msg));
294
-        }
295
-        // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
296
-        $installed_refs = $this->_set_caffeinated($installed_refs);
297
-        // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
298
-        $installed_refs = apply_filters(
299
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
300
-            $installed_refs
301
-        );
302
-        $this->_caffeinated_extends = apply_filters(
303
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
304
-            $this->_caffeinated_extends
305
-        );
306
-        // loop through admin pages and setup the $_installed_pages array.
307
-        $hooks_ref = array();
308
-        foreach ($installed_refs as $page => $path) {
309
-            // set autoloaders for our admin page classes based on included path information
310
-            EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311
-            // build list of installed pages
312
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
313
-            // verify returned object
314
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316
-                    continue;
317
-                }
318
-                // skip if in full maintenance mode and maintenance_mode_parent is set
319
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
320
-                if (empty($maintenance_mode_parent)
321
-                    && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322
-                ) {
323
-                    unset($installed_refs[ $page ]);
324
-                    continue;
325
-                }
326
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
-                $this->_menu_slugs[ $menu_slug ] = $page;
328
-                // flag for register hooks on extended pages b/c extended pages use the default INIT.
329
-                $extend = false;
330
-                // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
-                if (isset($this->_caffeinated_extends[ $page ])) {
332
-                    $this->_current_caf_extend_slug = $page;
333
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
336
-                    add_filter(
337
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
-                        function ($path_to_file) use ($caf_path) {
339
-                            return $caf_path;
340
-                        }
341
-                    );
342
-                    add_filter(
343
-                        "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
-                        function ($admin_page) use ($caf_admin_page) {
345
-                            return $caf_admin_page;
346
-                        }
347
-                    );
348
-                    $extend = true;
349
-                }
350
-                // let's do the registered hooks
351
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
352
-                $hooks_ref = array_merge($hooks_ref, $extended_hooks);
353
-            }
354
-        }
355
-        // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
356
-        // first make sure we've got unique values
357
-        $hooks_ref = array_unique($hooks_ref);
358
-        // now let's loop and require!
359
-        foreach ($hooks_ref as $path) {
360
-            require_once($path);
361
-        }
362
-        // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
363
-        global $ee_menu_slugs;
364
-        $ee_menu_slugs = $this->_menu_slugs;
365
-        // we need to loop again to run any early code
366
-        foreach ($installed_refs as $page => $path) {
367
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
-                $this->_installed_pages[ $page ]->do_initial_loads();
369
-            }
370
-        }
371
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
372
-    }
373
-
374
-
375
-    /**
376
-     * get_admin_page_object
377
-     *
378
-     * @param string $page_slug
379
-     * @return EE_Admin_Page
380
-     */
381
-    public function get_admin_page_object($page_slug = '')
382
-    {
383
-        if (isset($this->_installed_pages[ $page_slug ])) {
384
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
385
-        }
386
-        return null;
387
-    }
388
-
389
-
390
-    /**
391
-     * _get_classname_for_admin_page
392
-     * generates an "Admin Page" class based on the directory  name
393
-     *
394
-     * @param $dir_name
395
-     * @return string
396
-     */
397
-    private function _get_classname_for_admin_page($dir_name = '')
398
-    {
399
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
400
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
401
-    }
402
-
403
-
404
-    /**
405
-     * _get_classname_for_admin_init_page
406
-     * generates an "Admin Page Init" class based on the directory  name
407
-     *
408
-     * @param $dir_name
409
-     * @return string
410
-     */
411
-    private function _get_classname_for_admin_init_page($dir_name = '')
412
-    {
413
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
414
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
415
-    }
416
-
417
-
418
-    /**
419
-     * _load_admin_page
420
-     * Loads and instantiates page_init object for a single EE_admin page.
421
-     *
422
-     * @param  string $page page_reference
423
-     * @param string  $path
424
-     * @throws EE_Error
425
-     * @return object|bool  return page object if valid, bool false if not.
426
-     */
427
-    private function _load_admin_page($page = '', $path = '')
428
-    {
429
-        $class_name = $this->_get_classname_for_admin_init_page($page);
430
-        EE_Registry::instance()->load_file($path, $class_name, 'core');
431
-        if (! class_exists($class_name)) {
432
-            $inner_error_msg = '<br />'
433
-                               . sprintf(
434
-                                   esc_html__(
435
-                                       'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436
-                                       'event_espresso'
437
-                                   ),
438
-                                   '<strong>' . $class_name . '</strong>'
439
-                               );
440
-            $error_msg[] = sprintf(
441
-                __('Something went wrong with loading the %s admin page.', 'event_espresso'),
442
-                $page
443
-            );
444
-            $error_msg[] = $error_msg[0]
445
-                           . "\r\n"
446
-                           . sprintf(
447
-                               esc_html__(
448
-                                   'There is no Init class in place for the %s admin page.',
449
-                                   'event_espresso'
450
-                               ),
451
-                               $page
452
-                           )
453
-                           . $inner_error_msg;
454
-            throw new EE_Error(implode('||', $error_msg));
455
-        }
456
-        $a = new ReflectionClass($class_name);
457
-        return $a->newInstance();
458
-    }
459
-
460
-
461
-    /**
462
-     * set_menus
463
-     * This method sets up the menus for EE Admin Pages
464
-     *
465
-     * @access private
466
-     * @return void
467
-     */
468
-    public function set_menus()
469
-    {
470
-        // prep the menu pages (sort, group.)
471
-        $this->_prep_pages();
472
-        foreach ($this->_prepped_menu_maps as $menu_map) {
473
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
474
-                $menu_map->add_menu_page(false);
475
-            }
476
-        }
477
-    }
478
-
479
-
480
-    /**
481
-     * set_network_menus
482
-     * This method sets up the menus for network EE Admin Pages.
483
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
484
-     * are only added to the menu map if they are intended for the admin menu
485
-     *
486
-     * @return void
487
-     */
488
-    public function set_network_menus()
489
-    {
490
-        $this->_prep_pages();
491
-        foreach ($this->_prepped_menu_maps as $menu_map) {
492
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
493
-                $menu_map->add_menu_page(true);
494
-            }
495
-        }
496
-    }
497
-
498
-
499
-    /**
500
-     * _prep_pages
501
-     * sets the _prepped_menu_maps property
502
-     *
503
-     * @access private
504
-     * @throws EE_Error
505
-     * @return void
506
-     */
507
-    private function _prep_pages()
508
-    {
509
-        $pages_array = array();
510
-        // rearrange _admin_menu_groups to be indexed by group slug.
511
-        $menu_groups = $this->_rearrange_menu_groups();
512
-        foreach ($this->_installed_pages as $page) {
513
-            if ($page instanceof EE_Admin_page_Init) {
514
-                $page_map = $page->get_menu_map();
515
-                // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516
-                if (is_array($page_map) || empty($page_map)) {
517
-                    new PersistentAdminNotice(
518
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
519
-                        sprintf(
520
-                            __(
521
-                                'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
522
-                                'event_espresso'
523
-                            ),
524
-                            $page->label
525
-                        )
526
-                    );
527
-                    continue;
528
-                }
529
-                // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
531
-                    throw new EE_Error(
532
-                        sprintf(
533
-                            __(
534
-                                'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
535
-                                'event_espresso'
536
-                            ),
537
-                            $page->label,
538
-                            $page_map
539
-                        )
540
-                    );
541
-                }
542
-                // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
543
-                if (empty($page_map->maintenance_mode_parent)
544
-                    && EE_Maintenance_Mode::instance()->level()
545
-                       == EE_Maintenance_Mode::level_2_complete_maintenance) {
546
-                    continue;
547
-                }
548
-                // assign to group (remember $page_map has the admin page stored in it).
549
-                $pages_array[ $page_map->menu_group ][] = $page_map;
550
-            }
551
-        }
552
-        if (empty($pages_array)) {
553
-            throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
554
-        }
555
-        // let's sort the groups, make sure it's a valid group, add header (if to show).
556
-        foreach ($pages_array as $group => $menu_maps) {
557
-            // valid_group?
558
-            if (! array_key_exists($group, $menu_groups)) {
559
-                continue;
560
-            }
561
-            // sort pages.
562
-            usort($menu_maps, array($this, '_sort_menu_maps'));
563
-            // prepend header
564
-            array_unshift($menu_maps, $menu_groups[ $group ]);
565
-            // reset $pages_array with prepped data
566
-            $pages_array[ $group ] = $menu_maps;
567
-        }
568
-        // now let's setup the _prepped_menu_maps property
569
-        foreach ($menu_groups as $group => $group_objs) {
570
-            if (isset($pages_array[ $group ])) {
571
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
572
-            }
573
-        }/**/
574
-    }
575
-
576
-
577
-    /**
578
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
579
-     * In this method there are three checks being done:
580
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
581
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
582
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
583
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
584
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
585
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
586
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
587
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
588
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
589
-     * admin_pages)
590
-     *
591
-     * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
592
-     *                              loaded.
593
-     * @return array
594
-     */
595
-    private function _set_caffeinated($installed_refs)
596
-    {
597
-
598
-        // first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
600
-            return $installed_refs;
601
-        }
602
-        $this->_define_caffeinated_constants();
603
-        $exclude = array('tickets');
604
-        // okay let's setup an "New" pages first (we'll return installed refs later)
605
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
606
-        if ($new_admin_screens) {
607
-            foreach ($new_admin_screens as $admin_screen) {
608
-                // files and anything in the exclude array need not apply
609
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610
-                    // these folders represent the different NEW EE admin pages
611
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
612
-                    // set autoloaders for our admin page classes based on included path information
613
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614
-                }
615
-            }
616
-        }
617
-        // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
619
-        if ($extends) {
620
-            foreach ($extends as $extend) {
621
-                if (is_dir($extend)) {
622
-                    $extend_ref = basename($extend);
623
-                    // now let's make sure there is a file that matches the expected format
624
-                    $filename = str_replace(
625
-                        ' ',
626
-                        '_',
627
-                        ucwords(
628
-                            str_replace(
629
-                                '_',
630
-                                ' ',
631
-                                $extend_ref
632
-                            )
633
-                        )
634
-                    );
635
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
636
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
637
-                        array('\\', '/'),
638
-                        DS,
639
-                        EE_CORE_CAF_ADMIN
640
-                        . 'extend'
641
-                        . DS
642
-                        . $extend_ref
643
-                        . DS
644
-                        . $filename
645
-                        . '.core.php'
646
-                    );
647
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
648
-                    // set autoloaders for our admin page classes based on included path information
649
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
650
-                }
651
-            }
652
-        }
653
-        // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
654
-        $ee_admin_hooks = array();
655
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
656
-        if ($hooks) {
657
-            foreach ($hooks as $hook) {
658
-                if (is_readable($hook)) {
659
-                    require_once $hook;
660
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
661
-                    $classname = str_replace('.class.php', '', $classname);
662
-                    if (class_exists($classname)) {
663
-                        $a = new ReflectionClass($classname);
664
-                        $ee_admin_hooks[] = $a->newInstance();
665
-                    }
666
-                }
667
-            }
668
-        }/**/
669
-        $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
670
-        return $installed_refs;
671
-    }
672
-
673
-
674
-    /**
675
-     * Utility method for sorting the _menu_maps (callback for usort php function)
676
-     *
677
-     * @since  4.4.0
678
-     * @param  EE_Admin_Page_Menu_Map $a menu_map object
679
-     * @param  EE_Admin_Page_Menu_Map $b being compared to
680
-     * @return int    sort order
681
-     */
682
-    private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
683
-    {
684
-        if ($a->menu_order == $b->menu_order) {
685
-            return 0;
686
-        }
687
-        return ($a->menu_order < $b->menu_order) ? -1 : 1;
688
-    }
689
-
690
-
691
-    /**
692
-     * _default_header_link
693
-     * This is just a dummy method to use with header submenu items
694
-     *
695
-     * @return bool false
696
-     */
697
-    public function _default_header_link()
698
-    {
699
-        return false;
700
-    }
27
+	/**
28
+	 * _installed_pages
29
+	 * objects for page_init objects detected and loaded
30
+	 *
31
+	 * @access private
32
+	 * @var \EE_Admin_Page_Init[]
33
+	 */
34
+	private $_installed_pages = array();
35
+
36
+
37
+	/**
38
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $_menu_slugs = array();
43
+
44
+
45
+	/**
46
+	 * _caffeinated_extends
47
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
48
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	private $_caffeinated_extends = array();
53
+
54
+
55
+	/**
56
+	 * _current_caf_extend_slug
57
+	 * This property is used for holding the page slug that is required for referencing the correct
58
+	 * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	private $_current_caf_extend_slug;
63
+
64
+	/**
65
+	 * _prepped_menu_maps
66
+	 * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
67
+	 *
68
+	 * @since  4.4.0
69
+	 * @var EE_Admin_Page_Menu_Map[]
70
+	 */
71
+	private $_prepped_menu_maps = array();
72
+
73
+
74
+	/**
75
+	 * _admin_menu_groups
76
+	 * array that holds the group headings and details for
77
+	 *
78
+	 * @access private
79
+	 * @var array
80
+	 */
81
+	private $_admin_menu_groups = array();
82
+
83
+
84
+	/**
85
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
86
+	 * pages.
87
+	 *
88
+	 * @var string
89
+	 */
90
+	public $hook_file;
91
+
92
+
93
+	/**
94
+	 * constructor
95
+	 *
96
+	 * @access public
97
+	 * @return \EE_Admin_Page_Loader
98
+	 */
99
+	public function __construct()
100
+	{
101
+		// load menu_map classes
102
+		EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
103
+		// define the default "groups" for the admin_pages
104
+		$this->_set_menu_groups();
105
+
106
+		// let's do a scan and see what installed pages we have
107
+		$this->_get_installed_pages();
108
+		// set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
109
+		add_action('admin_menu', array($this, 'set_menus'));
110
+		add_action('network_admin_menu', array($this, 'set_network_menus'));
111
+	}
112
+
113
+
114
+	/**
115
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
116
+	 * files in the caffeinated folder.
117
+	 *
118
+	 * @access private
119
+	 * @return void
120
+	 */
121
+	private function _define_caffeinated_constants()
122
+	{
123
+		if (! defined('EE_CORE_CAF_ADMIN')) {
124
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
130
+		}
131
+	}
132
+
133
+
134
+	/**
135
+	 * _set_menu_groups
136
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
137
+	 *
138
+	 * @access private
139
+	 * @return void
140
+	 */
141
+	private function _set_menu_groups()
142
+	{
143
+
144
+		// set array of EE_Admin_Page_Menu_Group objects
145
+		$groups = array(
146
+			'main'       => new EE_Admin_Page_Menu_Group(
147
+				array(
148
+					'menu_label'   => __('Main', 'event_espresso'),
149
+					'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
150
+					'menu_slug'    => 'main',
151
+					'capability'   => 'ee_read_ee',
152
+					'menu_order'   => 0,
153
+					'parent_slug'  => 'espresso_events',
154
+				)
155
+			),
156
+			'management' => new EE_Admin_Page_Menu_Group(
157
+				array(
158
+					'menu_label'   => __('Management', 'event_espresso'),
159
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
160
+					'menu_slug'    => 'management',
161
+					'capability'   => 'ee_read_ee',
162
+					'menu_order'   => 10,
163
+					'parent_slug'  => 'espresso_events',
164
+				)
165
+			),
166
+			'settings'   => new EE_Admin_Page_Menu_Group(
167
+				array(
168
+					'menu_label'   => __('Settings', 'event_espresso'),
169
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
170
+					'menu_slug'    => 'settings',
171
+					'capability'   => 'ee_read_ee',
172
+					'menu_order'   => 30,
173
+					'parent_slug'  => 'espresso_events',
174
+				)
175
+			),
176
+			'templates'  => new EE_Admin_Page_Menu_Group(
177
+				array(
178
+					'menu_label'   => __('Templates', 'event_espresso'),
179
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
180
+					'menu_slug'    => 'templates',
181
+					'capability'   => 'ee_read_ee',
182
+					'menu_order'   => 40,
183
+					'parent_slug'  => 'espresso_events',
184
+				)
185
+			),
186
+			'extras'     => new EE_Admin_Page_Menu_Group(
187
+				array(
188
+					'menu_label'              => __('Extras', 'event_espresso'),
189
+					'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
190
+					'menu_slug'               => 'extras',
191
+					'capability'              => 'ee_read_ee',
192
+					'menu_order'              => 50,
193
+					'parent_slug'             => 'espresso_events',
194
+					'maintenance_mode_parent' => 'espresso_maintenance_settings',
195
+				)
196
+			),
197
+			'tools'      => new EE_Admin_Page_Menu_Group(
198
+				array(
199
+					'menu_label'   => __("Tools", "event_espresso"),
200
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
+					'menu_slug'    => 'tools',
202
+					'capability'   => 'ee_read_ee',
203
+					'menu_order'   => 60,
204
+					'parent_slug'  => 'espresso_events',
205
+				)
206
+			),
207
+			'addons'     => new EE_Admin_Page_Menu_Group(
208
+				array(
209
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
210
+					'menu_label'   => __('Add-ons', 'event_espresso'),
211
+					'menu_slug'    => 'addons',
212
+					'capability'   => 'ee_read_ee',
213
+					'menu_order'   => 20,
214
+					'parent_slug'  => 'espresso_events',
215
+				)
216
+			),
217
+		);
218
+		$this->_admin_menu_groups = apply_filters(
219
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
220
+			$groups
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
227
+	 * slug.  The other utility with this function is it validates that all the groups are instances of
228
+	 * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
229
+	 *
230
+	 * @since  4.4.0
231
+	 * @throws \EE_Error
232
+	 * @return EE_Admin_Page_Menu_Group[]
233
+	 */
234
+	private function _rearrange_menu_groups()
235
+	{
236
+		$groups = array();
237
+		// first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238
+		usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239
+		foreach ($this->_admin_menu_groups as $group) {
240
+			if (! $group instanceof EE_Admin_Page_Menu_Group) {
241
+				throw new EE_Error(
242
+					sprintf(
243
+						__(
244
+							'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
245
+							'event_espresso'
246
+						),
247
+						print_r($group, true)
248
+					)
249
+				);
250
+			}
251
+			$groups[ $group->menu_slug ] = $group;
252
+		}
253
+		return $groups;
254
+	}
255
+
256
+
257
+	/**
258
+	 * _get_installed_pages
259
+	 * This just gets the list of installed EE_Admin_pages.
260
+	 *
261
+	 * @access private
262
+	 * @throws EE_Error
263
+	 * @return void
264
+	 */
265
+	private function _get_installed_pages()
266
+	{
267
+		$installed_refs = array();
268
+		$exclude = array('assets', 'templates');
269
+		// grab everything in the  admin core directory
270
+		$admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
271
+		if ($admin_screens) {
272
+			foreach ($admin_screens as $admin_screen) {
273
+				// files and anything in the exclude array need not apply
274
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275
+					// these folders represent the different EE admin pages
276
+					$installed_refs[ basename($admin_screen) ] = $admin_screen;
277
+				}
278
+			}
279
+		}
280
+		if (empty($installed_refs)) {
281
+			$error_msg[] = __(
282
+				'There are no EE_Admin pages detected, it looks like EE did not install properly',
283
+				'event_espresso'
284
+			);
285
+			$error_msg[] = $error_msg[0] . "\r\n"
286
+						   . sprintf(
287
+							   __(
288
+								   'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
289
+								   'event_espresso'
290
+							   ),
291
+							   EE_ADMIN_PAGES
292
+						   );
293
+			throw new EE_Error(implode('||', $error_msg));
294
+		}
295
+		// this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
296
+		$installed_refs = $this->_set_caffeinated($installed_refs);
297
+		// allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
298
+		$installed_refs = apply_filters(
299
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
300
+			$installed_refs
301
+		);
302
+		$this->_caffeinated_extends = apply_filters(
303
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
304
+			$this->_caffeinated_extends
305
+		);
306
+		// loop through admin pages and setup the $_installed_pages array.
307
+		$hooks_ref = array();
308
+		foreach ($installed_refs as $page => $path) {
309
+			// set autoloaders for our admin page classes based on included path information
310
+			EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311
+			// build list of installed pages
312
+			$this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
313
+			// verify returned object
314
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
+				if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316
+					continue;
317
+				}
318
+				// skip if in full maintenance mode and maintenance_mode_parent is set
319
+				$maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
320
+				if (empty($maintenance_mode_parent)
321
+					&& EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322
+				) {
323
+					unset($installed_refs[ $page ]);
324
+					continue;
325
+				}
326
+				$menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
+				$this->_menu_slugs[ $menu_slug ] = $page;
328
+				// flag for register hooks on extended pages b/c extended pages use the default INIT.
329
+				$extend = false;
330
+				// now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
+				if (isset($this->_caffeinated_extends[ $page ])) {
332
+					$this->_current_caf_extend_slug = $page;
333
+					$admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
+					$caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
+					$caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
336
+					add_filter(
337
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
+						function ($path_to_file) use ($caf_path) {
339
+							return $caf_path;
340
+						}
341
+					);
342
+					add_filter(
343
+						"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
+						function ($admin_page) use ($caf_admin_page) {
345
+							return $caf_admin_page;
346
+						}
347
+					);
348
+					$extend = true;
349
+				}
350
+				// let's do the registered hooks
351
+				$extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
352
+				$hooks_ref = array_merge($hooks_ref, $extended_hooks);
353
+			}
354
+		}
355
+		// the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
356
+		// first make sure we've got unique values
357
+		$hooks_ref = array_unique($hooks_ref);
358
+		// now let's loop and require!
359
+		foreach ($hooks_ref as $path) {
360
+			require_once($path);
361
+		}
362
+		// make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
363
+		global $ee_menu_slugs;
364
+		$ee_menu_slugs = $this->_menu_slugs;
365
+		// we need to loop again to run any early code
366
+		foreach ($installed_refs as $page => $path) {
367
+			if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
+				$this->_installed_pages[ $page ]->do_initial_loads();
369
+			}
370
+		}
371
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
372
+	}
373
+
374
+
375
+	/**
376
+	 * get_admin_page_object
377
+	 *
378
+	 * @param string $page_slug
379
+	 * @return EE_Admin_Page
380
+	 */
381
+	public function get_admin_page_object($page_slug = '')
382
+	{
383
+		if (isset($this->_installed_pages[ $page_slug ])) {
384
+			return $this->_installed_pages[ $page_slug ]->loaded_page_object();
385
+		}
386
+		return null;
387
+	}
388
+
389
+
390
+	/**
391
+	 * _get_classname_for_admin_page
392
+	 * generates an "Admin Page" class based on the directory  name
393
+	 *
394
+	 * @param $dir_name
395
+	 * @return string
396
+	 */
397
+	private function _get_classname_for_admin_page($dir_name = '')
398
+	{
399
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
400
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
401
+	}
402
+
403
+
404
+	/**
405
+	 * _get_classname_for_admin_init_page
406
+	 * generates an "Admin Page Init" class based on the directory  name
407
+	 *
408
+	 * @param $dir_name
409
+	 * @return string
410
+	 */
411
+	private function _get_classname_for_admin_init_page($dir_name = '')
412
+	{
413
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
414
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
415
+	}
416
+
417
+
418
+	/**
419
+	 * _load_admin_page
420
+	 * Loads and instantiates page_init object for a single EE_admin page.
421
+	 *
422
+	 * @param  string $page page_reference
423
+	 * @param string  $path
424
+	 * @throws EE_Error
425
+	 * @return object|bool  return page object if valid, bool false if not.
426
+	 */
427
+	private function _load_admin_page($page = '', $path = '')
428
+	{
429
+		$class_name = $this->_get_classname_for_admin_init_page($page);
430
+		EE_Registry::instance()->load_file($path, $class_name, 'core');
431
+		if (! class_exists($class_name)) {
432
+			$inner_error_msg = '<br />'
433
+							   . sprintf(
434
+								   esc_html__(
435
+									   'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436
+									   'event_espresso'
437
+								   ),
438
+								   '<strong>' . $class_name . '</strong>'
439
+							   );
440
+			$error_msg[] = sprintf(
441
+				__('Something went wrong with loading the %s admin page.', 'event_espresso'),
442
+				$page
443
+			);
444
+			$error_msg[] = $error_msg[0]
445
+						   . "\r\n"
446
+						   . sprintf(
447
+							   esc_html__(
448
+								   'There is no Init class in place for the %s admin page.',
449
+								   'event_espresso'
450
+							   ),
451
+							   $page
452
+						   )
453
+						   . $inner_error_msg;
454
+			throw new EE_Error(implode('||', $error_msg));
455
+		}
456
+		$a = new ReflectionClass($class_name);
457
+		return $a->newInstance();
458
+	}
459
+
460
+
461
+	/**
462
+	 * set_menus
463
+	 * This method sets up the menus for EE Admin Pages
464
+	 *
465
+	 * @access private
466
+	 * @return void
467
+	 */
468
+	public function set_menus()
469
+	{
470
+		// prep the menu pages (sort, group.)
471
+		$this->_prep_pages();
472
+		foreach ($this->_prepped_menu_maps as $menu_map) {
473
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
474
+				$menu_map->add_menu_page(false);
475
+			}
476
+		}
477
+	}
478
+
479
+
480
+	/**
481
+	 * set_network_menus
482
+	 * This method sets up the menus for network EE Admin Pages.
483
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
484
+	 * are only added to the menu map if they are intended for the admin menu
485
+	 *
486
+	 * @return void
487
+	 */
488
+	public function set_network_menus()
489
+	{
490
+		$this->_prep_pages();
491
+		foreach ($this->_prepped_menu_maps as $menu_map) {
492
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
493
+				$menu_map->add_menu_page(true);
494
+			}
495
+		}
496
+	}
497
+
498
+
499
+	/**
500
+	 * _prep_pages
501
+	 * sets the _prepped_menu_maps property
502
+	 *
503
+	 * @access private
504
+	 * @throws EE_Error
505
+	 * @return void
506
+	 */
507
+	private function _prep_pages()
508
+	{
509
+		$pages_array = array();
510
+		// rearrange _admin_menu_groups to be indexed by group slug.
511
+		$menu_groups = $this->_rearrange_menu_groups();
512
+		foreach ($this->_installed_pages as $page) {
513
+			if ($page instanceof EE_Admin_page_Init) {
514
+				$page_map = $page->get_menu_map();
515
+				// if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516
+				if (is_array($page_map) || empty($page_map)) {
517
+					new PersistentAdminNotice(
518
+						'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
519
+						sprintf(
520
+							__(
521
+								'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
522
+								'event_espresso'
523
+							),
524
+							$page->label
525
+						)
526
+					);
527
+					continue;
528
+				}
529
+				// if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
+				if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
531
+					throw new EE_Error(
532
+						sprintf(
533
+							__(
534
+								'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
535
+								'event_espresso'
536
+							),
537
+							$page->label,
538
+							$page_map
539
+						)
540
+					);
541
+				}
542
+				// use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
543
+				if (empty($page_map->maintenance_mode_parent)
544
+					&& EE_Maintenance_Mode::instance()->level()
545
+					   == EE_Maintenance_Mode::level_2_complete_maintenance) {
546
+					continue;
547
+				}
548
+				// assign to group (remember $page_map has the admin page stored in it).
549
+				$pages_array[ $page_map->menu_group ][] = $page_map;
550
+			}
551
+		}
552
+		if (empty($pages_array)) {
553
+			throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
554
+		}
555
+		// let's sort the groups, make sure it's a valid group, add header (if to show).
556
+		foreach ($pages_array as $group => $menu_maps) {
557
+			// valid_group?
558
+			if (! array_key_exists($group, $menu_groups)) {
559
+				continue;
560
+			}
561
+			// sort pages.
562
+			usort($menu_maps, array($this, '_sort_menu_maps'));
563
+			// prepend header
564
+			array_unshift($menu_maps, $menu_groups[ $group ]);
565
+			// reset $pages_array with prepped data
566
+			$pages_array[ $group ] = $menu_maps;
567
+		}
568
+		// now let's setup the _prepped_menu_maps property
569
+		foreach ($menu_groups as $group => $group_objs) {
570
+			if (isset($pages_array[ $group ])) {
571
+				$this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
572
+			}
573
+		}/**/
574
+	}
575
+
576
+
577
+	/**
578
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
579
+	 * In this method there are three checks being done:
580
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
581
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
582
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
583
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
584
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
585
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
586
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
587
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
588
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
589
+	 * admin_pages)
590
+	 *
591
+	 * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
592
+	 *                              loaded.
593
+	 * @return array
594
+	 */
595
+	private function _set_caffeinated($installed_refs)
596
+	{
597
+
598
+		// first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
+		if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
600
+			return $installed_refs;
601
+		}
602
+		$this->_define_caffeinated_constants();
603
+		$exclude = array('tickets');
604
+		// okay let's setup an "New" pages first (we'll return installed refs later)
605
+		$new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
606
+		if ($new_admin_screens) {
607
+			foreach ($new_admin_screens as $admin_screen) {
608
+				// files and anything in the exclude array need not apply
609
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610
+					// these folders represent the different NEW EE admin pages
611
+					$installed_refs[ basename($admin_screen) ] = $admin_screen;
612
+					// set autoloaders for our admin page classes based on included path information
613
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614
+				}
615
+			}
616
+		}
617
+		// let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
+		$extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
619
+		if ($extends) {
620
+			foreach ($extends as $extend) {
621
+				if (is_dir($extend)) {
622
+					$extend_ref = basename($extend);
623
+					// now let's make sure there is a file that matches the expected format
624
+					$filename = str_replace(
625
+						' ',
626
+						'_',
627
+						ucwords(
628
+							str_replace(
629
+								'_',
630
+								' ',
631
+								$extend_ref
632
+							)
633
+						)
634
+					);
635
+					$filename = 'Extend_' . $filename . '_Admin_Page';
636
+					$this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
637
+						array('\\', '/'),
638
+						DS,
639
+						EE_CORE_CAF_ADMIN
640
+						. 'extend'
641
+						. DS
642
+						. $extend_ref
643
+						. DS
644
+						. $filename
645
+						. '.core.php'
646
+					);
647
+					$this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
648
+					// set autoloaders for our admin page classes based on included path information
649
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
650
+				}
651
+			}
652
+		}
653
+		// let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
654
+		$ee_admin_hooks = array();
655
+		$hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
656
+		if ($hooks) {
657
+			foreach ($hooks as $hook) {
658
+				if (is_readable($hook)) {
659
+					require_once $hook;
660
+					$classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
661
+					$classname = str_replace('.class.php', '', $classname);
662
+					if (class_exists($classname)) {
663
+						$a = new ReflectionClass($classname);
664
+						$ee_admin_hooks[] = $a->newInstance();
665
+					}
666
+				}
667
+			}
668
+		}/**/
669
+		$ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
670
+		return $installed_refs;
671
+	}
672
+
673
+
674
+	/**
675
+	 * Utility method for sorting the _menu_maps (callback for usort php function)
676
+	 *
677
+	 * @since  4.4.0
678
+	 * @param  EE_Admin_Page_Menu_Map $a menu_map object
679
+	 * @param  EE_Admin_Page_Menu_Map $b being compared to
680
+	 * @return int    sort order
681
+	 */
682
+	private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
683
+	{
684
+		if ($a->menu_order == $b->menu_order) {
685
+			return 0;
686
+		}
687
+		return ($a->menu_order < $b->menu_order) ? -1 : 1;
688
+	}
689
+
690
+
691
+	/**
692
+	 * _default_header_link
693
+	 * This is just a dummy method to use with header submenu items
694
+	 *
695
+	 * @return bool false
696
+	 */
697
+	public function _default_header_link()
698
+	{
699
+		return false;
700
+	}
701 701
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
      */
121 121
     private function _define_caffeinated_constants()
122 122
     {
123
-        if (! defined('EE_CORE_CAF_ADMIN')) {
124
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
125
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
126
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
127
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
128
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
129
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
123
+        if ( ! defined('EE_CORE_CAF_ADMIN')) {
124
+            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/');
125
+            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/');
126
+            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/');
127
+            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/');
128
+            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/');
129
+            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/');
130 130
         }
131 131
     }
132 132
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         // first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
238 238
         usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
239 239
         foreach ($this->_admin_menu_groups as $group) {
240
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
240
+            if ( ! $group instanceof EE_Admin_Page_Menu_Group) {
241 241
                 throw new EE_Error(
242 242
                     sprintf(
243 243
                         __(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                     )
249 249
                 );
250 250
             }
251
-            $groups[ $group->menu_slug ] = $group;
251
+            $groups[$group->menu_slug] = $group;
252 252
         }
253 253
         return $groups;
254 254
     }
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
         $installed_refs = array();
268 268
         $exclude = array('assets', 'templates');
269 269
         // grab everything in the  admin core directory
270
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
270
+        $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR);
271 271
         if ($admin_screens) {
272 272
             foreach ($admin_screens as $admin_screen) {
273 273
                 // files and anything in the exclude array need not apply
274 274
                 if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
275 275
                     // these folders represent the different EE admin pages
276
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
276
+                    $installed_refs[basename($admin_screen)] = $admin_screen;
277 277
                 }
278 278
             }
279 279
         }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 'There are no EE_Admin pages detected, it looks like EE did not install properly',
283 283
                 'event_espresso'
284 284
             );
285
-            $error_msg[] = $error_msg[0] . "\r\n"
285
+            $error_msg[] = $error_msg[0]."\r\n"
286 286
                            . sprintf(
287 287
                                __(
288 288
                                    'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
@@ -309,46 +309,46 @@  discard block
 block discarded – undo
309 309
             // set autoloaders for our admin page classes based on included path information
310 310
             EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
311 311
             // build list of installed pages
312
-            $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path);
312
+            $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
313 313
             // verify returned object
314
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
315
-                if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
314
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
315
+                if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
316 316
                     continue;
317 317
                 }
318 318
                 // skip if in full maintenance mode and maintenance_mode_parent is set
319
-                $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent;
319
+                $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
320 320
                 if (empty($maintenance_mode_parent)
321 321
                     && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance
322 322
                 ) {
323
-                    unset($installed_refs[ $page ]);
323
+                    unset($installed_refs[$page]);
324 324
                     continue;
325 325
                 }
326
-                $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug;
327
-                $this->_menu_slugs[ $menu_slug ] = $page;
326
+                $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug;
327
+                $this->_menu_slugs[$menu_slug] = $page;
328 328
                 // flag for register hooks on extended pages b/c extended pages use the default INIT.
329 329
                 $extend = false;
330 330
                 // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
331
-                if (isset($this->_caffeinated_extends[ $page ])) {
331
+                if (isset($this->_caffeinated_extends[$page])) {
332 332
                     $this->_current_caf_extend_slug = $page;
333
-                    $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name();
334
-                    $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path'];
335
-                    $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page'];
333
+                    $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name();
334
+                    $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path'];
335
+                    $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page'];
336 336
                     add_filter(
337 337
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}",
338
-                        function ($path_to_file) use ($caf_path) {
338
+                        function($path_to_file) use ($caf_path) {
339 339
                             return $caf_path;
340 340
                         }
341 341
                     );
342 342
                     add_filter(
343 343
                         "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}",
344
-                        function ($admin_page) use ($caf_admin_page) {
344
+                        function($admin_page) use ($caf_admin_page) {
345 345
                             return $caf_admin_page;
346 346
                         }
347 347
                     );
348 348
                     $extend = true;
349 349
                 }
350 350
                 // let's do the registered hooks
351
-                $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend);
351
+                $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
352 352
                 $hooks_ref = array_merge($hooks_ref, $extended_hooks);
353 353
             }
354 354
         }
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
         $ee_menu_slugs = $this->_menu_slugs;
365 365
         // we need to loop again to run any early code
366 366
         foreach ($installed_refs as $page => $path) {
367
-            if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) {
368
-                $this->_installed_pages[ $page ]->do_initial_loads();
367
+            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
368
+                $this->_installed_pages[$page]->do_initial_loads();
369 369
             }
370 370
         }
371 371
         do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function get_admin_page_object($page_slug = '')
382 382
     {
383
-        if (isset($this->_installed_pages[ $page_slug ])) {
384
-            return $this->_installed_pages[ $page_slug ]->loaded_page_object();
383
+        if (isset($this->_installed_pages[$page_slug])) {
384
+            return $this->_installed_pages[$page_slug]->loaded_page_object();
385 385
         }
386 386
         return null;
387 387
     }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
     private function _get_classname_for_admin_page($dir_name = '')
398 398
     {
399 399
         $class_name = str_replace('_', ' ', strtolower($dir_name));
400
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
400
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page';
401 401
     }
402 402
 
403 403
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     private function _get_classname_for_admin_init_page($dir_name = '')
412 412
     {
413 413
         $class_name = str_replace('_', ' ', strtolower($dir_name));
414
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
414
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init';
415 415
     }
416 416
 
417 417
 
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
     {
429 429
         $class_name = $this->_get_classname_for_admin_init_page($page);
430 430
         EE_Registry::instance()->load_file($path, $class_name, 'core');
431
-        if (! class_exists($class_name)) {
431
+        if ( ! class_exists($class_name)) {
432 432
             $inner_error_msg = '<br />'
433 433
                                . sprintf(
434 434
                                    esc_html__(
435 435
                                        'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
436 436
                                        'event_espresso'
437 437
                                    ),
438
-                                   '<strong>' . $class_name . '</strong>'
438
+                                   '<strong>'.$class_name.'</strong>'
439 439
                                );
440 440
             $error_msg[] = sprintf(
441 441
                 __('Something went wrong with loading the %s admin page.', 'event_espresso'),
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
                 // if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
516 516
                 if (is_array($page_map) || empty($page_map)) {
517 517
                     new PersistentAdminNotice(
518
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
518
+                        'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION,
519 519
                         sprintf(
520 520
                             __(
521 521
                                 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
                     continue;
528 528
                 }
529 529
                 // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
530
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
530
+                if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) {
531 531
                     throw new EE_Error(
532 532
                         sprintf(
533 533
                             __(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                     continue;
547 547
                 }
548 548
                 // assign to group (remember $page_map has the admin page stored in it).
549
-                $pages_array[ $page_map->menu_group ][] = $page_map;
549
+                $pages_array[$page_map->menu_group][] = $page_map;
550 550
             }
551 551
         }
552 552
         if (empty($pages_array)) {
@@ -555,20 +555,20 @@  discard block
 block discarded – undo
555 555
         // let's sort the groups, make sure it's a valid group, add header (if to show).
556 556
         foreach ($pages_array as $group => $menu_maps) {
557 557
             // valid_group?
558
-            if (! array_key_exists($group, $menu_groups)) {
558
+            if ( ! array_key_exists($group, $menu_groups)) {
559 559
                 continue;
560 560
             }
561 561
             // sort pages.
562 562
             usort($menu_maps, array($this, '_sort_menu_maps'));
563 563
             // prepend header
564
-            array_unshift($menu_maps, $menu_groups[ $group ]);
564
+            array_unshift($menu_maps, $menu_groups[$group]);
565 565
             // reset $pages_array with prepped data
566
-            $pages_array[ $group ] = $menu_maps;
566
+            $pages_array[$group] = $menu_maps;
567 567
         }
568 568
         // now let's setup the _prepped_menu_maps property
569 569
         foreach ($menu_groups as $group => $group_objs) {
570
-            if (isset($pages_array[ $group ])) {
571
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[ $group ]);
570
+            if (isset($pages_array[$group])) {
571
+                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
572 572
             }
573 573
         }/**/
574 574
     }
@@ -596,26 +596,26 @@  discard block
 block discarded – undo
596 596
     {
597 597
 
598 598
         // first let's check if there IS a caffeinated folder. If there is not then lets get out.
599
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
599
+        if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) {
600 600
             return $installed_refs;
601 601
         }
602 602
         $this->_define_caffeinated_constants();
603 603
         $exclude = array('tickets');
604 604
         // okay let's setup an "New" pages first (we'll return installed refs later)
605
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
605
+        $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR);
606 606
         if ($new_admin_screens) {
607 607
             foreach ($new_admin_screens as $admin_screen) {
608 608
                 // files and anything in the exclude array need not apply
609 609
                 if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
610 610
                     // these folders represent the different NEW EE admin pages
611
-                    $installed_refs[ basename($admin_screen) ] = $admin_screen;
611
+                    $installed_refs[basename($admin_screen)] = $admin_screen;
612 612
                     // set autoloaders for our admin page classes based on included path information
613 613
                     EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
614 614
                 }
615 615
             }
616 616
         }
617 617
         // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
618
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
618
+        $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR);
619 619
         if ($extends) {
620 620
             foreach ($extends as $extend) {
621 621
                 if (is_dir($extend)) {
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
                             )
633 633
                         )
634 634
                     );
635
-                    $filename = 'Extend_' . $filename . '_Admin_Page';
636
-                    $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace(
635
+                    $filename = 'Extend_'.$filename.'_Admin_Page';
636
+                    $this->_caffeinated_extends[$extend_ref]['path'] = str_replace(
637 637
                         array('\\', '/'),
638 638
                         DS,
639 639
                         EE_CORE_CAF_ADMIN
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
                         . $filename
645 645
                         . '.core.php'
646 646
                     );
647
-                    $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename;
647
+                    $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
648 648
                     // set autoloaders for our admin page classes based on included path information
649 649
                     EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
650 650
                 }
@@ -652,12 +652,12 @@  discard block
 block discarded – undo
652 652
         }
653 653
         // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
654 654
         $ee_admin_hooks = array();
655
-        $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
655
+        $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php');
656 656
         if ($hooks) {
657 657
             foreach ($hooks as $hook) {
658 658
                 if (is_readable($hook)) {
659 659
                     require_once $hook;
660
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
660
+                    $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook);
661 661
                     $classname = str_replace('.class.php', '', $classname);
662 662
                     if (class_exists($classname)) {
663 663
                         $a = new ReflectionClass($classname);
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Menu_Map.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@
 block discarded – undo
124 124
      *
125 125
      * @param  array $menu_args           An array of arguments used to setup the menu
126 126
      *                                    properties on construct.
127
-     * @param  array $required            An array of keys that should be in the $menu_args, this
127
+     * @param  string[] $required            An array of keys that should be in the $menu_args, this
128 128
      *                                    is used to validate that the items that should be defined
129 129
      *                                    are present.
130 130
      * @return void
Please login to merge, or discard this patch.
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -11,257 +11,257 @@  discard block
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    /**
15
-     * The title for the menu page. (the page the menu links to)
16
-     *
17
-     * @since  4.4.0
18
-     * @var string
19
-     */
20
-    public $title;
21
-
22
-
23
-    /**
24
-     * The label for the menu item. (What shows up in the actual menu).
25
-     *
26
-     * @since 4.4.0
27
-     * @var string
28
-     */
29
-    public $menu_label;
30
-
31
-
32
-    /**
33
-     * What menu item is the parent of this menu item.
34
-     *
35
-     * @since 4.4.0
36
-     * @var string
37
-     */
38
-    public $parent_slug;
39
-
40
-
41
-    /**
42
-     * What capability is required to access this page.
43
-     *
44
-     * @since 4.4.0
45
-     * @var string
46
-     */
47
-    public $capability = 'administrator';
48
-
49
-
50
-    /**
51
-     * What slug should be used to reference this menu item.
52
-     *
53
-     * @since 4.4.0
54
-     * @var string
55
-     */
56
-    public $menu_slug;
57
-
58
-
59
-    /**
60
-     * The callback for displaying the page that the menu references.
61
-     *
62
-     * @since 4.4.0
63
-     * @var string
64
-     */
65
-    public $menu_callback;
66
-
67
-
68
-    /**
69
-     * The EE_Admin_Page_Init attached to this map.
70
-     *
71
-     * @var EE_Admin_Page_Init
72
-     */
73
-    public $admin_init_page;
74
-
75
-
76
-    /**
77
-     * The EE specific group this menu item belongs in (group slug).
78
-     *
79
-     * @since 4.4.0
80
-     * @var string
81
-     */
82
-    public $menu_group;
83
-
84
-
85
-    /**
86
-     * What order this item should be in the menu.
87
-     *
88
-     * @since 4.4.0
89
-     * @var int
90
-     */
91
-    public $menu_order;
92
-
93
-
94
-    const NONE = 0;
95
-    const BLOG_ADMIN_ONLY = 1;
96
-    const BLOG_AND_NETWORK_ADMIN = 2;
97
-    const NETWORK_ADMIN_ONLY = 3;
98
-
99
-
100
-    /**
101
-     * Whether this item is displayed in the menu or not.
102
-     * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress
103
-     * admin menu.
104
-     *
105
-     * @since 4.4.0
106
-     * @var int
107
-     */
108
-    public $show_on_menu = self::BLOG_ADMIN_ONLY;
109
-
110
-
111
-    /**
112
-     * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when
113
-     * EE_Maintenance_Mode::level_2_complete_maintenance is active.
114
-     *
115
-     * @var bool
116
-     */
117
-    public $maintenance_mode_parent = '';
118
-
119
-
120
-    /**
121
-     * Constructor.
122
-     *
123
-     * @since 4.4.0
124
-     *
125
-     * @param  array $menu_args           An array of arguments used to setup the menu
126
-     *                                    properties on construct.
127
-     * @param  array $required            An array of keys that should be in the $menu_args, this
128
-     *                                    is used to validate that the items that should be defined
129
-     *                                    are present.
130
-     * @return void
131
-     */
132
-    public function __construct($menu_args, $required)
133
-    {
134
-        // filter all args before processing so plugins can manipulate various settings for menus.
135
-        $menu_args = apply_filters(
136
-            'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args',
137
-            $menu_args,
138
-            $required,
139
-            get_class($this)
140
-        );
141
-
142
-
143
-        // verify that required keys are present in the incoming array.
144
-        $missing = array_diff((array) $required, array_keys((array) $menu_args));
145
-
146
-        if (! empty($missing)) {
147
-            throw new EE_Error(
148
-                sprintf(
149
-                    __(
150
-                        '%s is missing some expected keys in the argument array.  The following keys are missing: %s',
151
-                        'event_espresso'
152
-                    ),
153
-                    get_class($this),
154
-                    implode(', ', $missing)
155
-                )
156
-            );
157
-        }
158
-
159
-        // made it here okay, so let's set the properties!
160
-        foreach ($menu_args as $prop => $value) {
161
-            switch ($prop) {
162
-                case 'show_on_menu':
163
-                    $value = (int) $value;
164
-                    break;
165
-                case 'admin_init_page':
166
-                    if (in_array('admin_init_page', $required) && ! $value instanceof EE_Admin_Page_Init) {
167
-                        throw new EE_Error(
168
-                            sprintf(
169
-                                __(
170
-                                    'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object.  Instead %s was given as the value.',
171
-                                    'event_espresso'
172
-                                ),
173
-                                print_r($value, true)
174
-                            )
175
-                        );
176
-                    }
177
-                    break;
178
-                case 'menu_callback':
179
-                    break;
180
-
181
-                default:
182
-                    $value = (string) $value;
183
-                    break;
184
-            }
185
-            if (! EEH_Class_Tools::has_property($this, $prop)) {
186
-                throw new EE_Error(
187
-                    sprintf(
188
-                        __(
189
-                            'The $menu_args coming into %s has a index key (%s) representing a property that is not defined by the class.  Perhaps there is a typo?',
190
-                            'event_espresso'
191
-                        ),
192
-                        get_class($this),
193
-                        $prop
194
-                    )
195
-                );
196
-            }
197
-            $this->{$prop} = $value;
198
-        }
199
-
200
-        // filter capabilities (both static and dynamic)
201
-        $this->capability = apply_filters('FHEE_management_capability', $this->capability, null);
202
-        $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null);
203
-
204
-        // Might need to change parent slug depending on maintenance mode.
205
-        if (! empty($this->maintenance_mode_parent)
206
-            && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
207
-        ) {
208
-            $this->parent_slug = $this->maintenance_mode_parent;
209
-        }
210
-
211
-        // if empty menu_callback let's set default (but only if we have admin page init object)
212
-        if (empty($this->menu_callback) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
213
-            $this->menu_callback = array($this->admin_init_page, 'initialize_admin_page');
214
-        }
215
-    }
216
-
217
-
218
-    /**
219
-     * This method should define how the menu page gets added for this particular item
220
-     * and go ahead and define it.  Note that child classes MUST also return the result of
221
-     * the function used to register the WordPress admin page (the wp_page_slug string)
222
-     *
223
-     * @since  4.4.0
224
-     * @return string wp_page_slug.
225
-     */
226
-    abstract protected function _add_menu_page();
227
-
228
-
229
-    /**
230
-     * Called by client code to use this menu map for registering a WordPress admin page
231
-     *
232
-     * @param boolean $network_admin whether this is being added to the network admin page or not
233
-     * @since  4.4.0
234
-     */
235
-    public function add_menu_page($network_admin = false)
236
-    {
237
-
238
-        $show_on_menu_int = (int) $this->show_on_menu;
239
-        if (($network_admin
240
-             && in_array(
241
-                 $show_on_menu_int,
242
-                 array(self::BLOG_AND_NETWORK_ADMIN, self::NETWORK_ADMIN_ONLY),
243
-                 true
244
-             ))
245
-            ||
246
-            (! $network_admin
247
-             && in_array(
248
-                 $show_on_menu_int,
249
-                 array(self::BLOG_AND_NETWORK_ADMIN, self::BLOG_ADMIN_ONLY),
250
-                 true
251
-             ))) {
252
-            $wp_page_slug = $this->_add_menu_page();
253
-        } else {
254
-            $wp_page_slug = '';
255
-        }
256
-
257
-        if (! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
258
-            try {
259
-                $this->admin_init_page->set_page_dependencies($wp_page_slug);
260
-            } catch (EE_Error $e) {
261
-                $e->get_error();
262
-            }
263
-        }
264
-    }
14
+	/**
15
+	 * The title for the menu page. (the page the menu links to)
16
+	 *
17
+	 * @since  4.4.0
18
+	 * @var string
19
+	 */
20
+	public $title;
21
+
22
+
23
+	/**
24
+	 * The label for the menu item. (What shows up in the actual menu).
25
+	 *
26
+	 * @since 4.4.0
27
+	 * @var string
28
+	 */
29
+	public $menu_label;
30
+
31
+
32
+	/**
33
+	 * What menu item is the parent of this menu item.
34
+	 *
35
+	 * @since 4.4.0
36
+	 * @var string
37
+	 */
38
+	public $parent_slug;
39
+
40
+
41
+	/**
42
+	 * What capability is required to access this page.
43
+	 *
44
+	 * @since 4.4.0
45
+	 * @var string
46
+	 */
47
+	public $capability = 'administrator';
48
+
49
+
50
+	/**
51
+	 * What slug should be used to reference this menu item.
52
+	 *
53
+	 * @since 4.4.0
54
+	 * @var string
55
+	 */
56
+	public $menu_slug;
57
+
58
+
59
+	/**
60
+	 * The callback for displaying the page that the menu references.
61
+	 *
62
+	 * @since 4.4.0
63
+	 * @var string
64
+	 */
65
+	public $menu_callback;
66
+
67
+
68
+	/**
69
+	 * The EE_Admin_Page_Init attached to this map.
70
+	 *
71
+	 * @var EE_Admin_Page_Init
72
+	 */
73
+	public $admin_init_page;
74
+
75
+
76
+	/**
77
+	 * The EE specific group this menu item belongs in (group slug).
78
+	 *
79
+	 * @since 4.4.0
80
+	 * @var string
81
+	 */
82
+	public $menu_group;
83
+
84
+
85
+	/**
86
+	 * What order this item should be in the menu.
87
+	 *
88
+	 * @since 4.4.0
89
+	 * @var int
90
+	 */
91
+	public $menu_order;
92
+
93
+
94
+	const NONE = 0;
95
+	const BLOG_ADMIN_ONLY = 1;
96
+	const BLOG_AND_NETWORK_ADMIN = 2;
97
+	const NETWORK_ADMIN_ONLY = 3;
98
+
99
+
100
+	/**
101
+	 * Whether this item is displayed in the menu or not.
102
+	 * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress
103
+	 * admin menu.
104
+	 *
105
+	 * @since 4.4.0
106
+	 * @var int
107
+	 */
108
+	public $show_on_menu = self::BLOG_ADMIN_ONLY;
109
+
110
+
111
+	/**
112
+	 * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when
113
+	 * EE_Maintenance_Mode::level_2_complete_maintenance is active.
114
+	 *
115
+	 * @var bool
116
+	 */
117
+	public $maintenance_mode_parent = '';
118
+
119
+
120
+	/**
121
+	 * Constructor.
122
+	 *
123
+	 * @since 4.4.0
124
+	 *
125
+	 * @param  array $menu_args           An array of arguments used to setup the menu
126
+	 *                                    properties on construct.
127
+	 * @param  array $required            An array of keys that should be in the $menu_args, this
128
+	 *                                    is used to validate that the items that should be defined
129
+	 *                                    are present.
130
+	 * @return void
131
+	 */
132
+	public function __construct($menu_args, $required)
133
+	{
134
+		// filter all args before processing so plugins can manipulate various settings for menus.
135
+		$menu_args = apply_filters(
136
+			'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args',
137
+			$menu_args,
138
+			$required,
139
+			get_class($this)
140
+		);
141
+
142
+
143
+		// verify that required keys are present in the incoming array.
144
+		$missing = array_diff((array) $required, array_keys((array) $menu_args));
145
+
146
+		if (! empty($missing)) {
147
+			throw new EE_Error(
148
+				sprintf(
149
+					__(
150
+						'%s is missing some expected keys in the argument array.  The following keys are missing: %s',
151
+						'event_espresso'
152
+					),
153
+					get_class($this),
154
+					implode(', ', $missing)
155
+				)
156
+			);
157
+		}
158
+
159
+		// made it here okay, so let's set the properties!
160
+		foreach ($menu_args as $prop => $value) {
161
+			switch ($prop) {
162
+				case 'show_on_menu':
163
+					$value = (int) $value;
164
+					break;
165
+				case 'admin_init_page':
166
+					if (in_array('admin_init_page', $required) && ! $value instanceof EE_Admin_Page_Init) {
167
+						throw new EE_Error(
168
+							sprintf(
169
+								__(
170
+									'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object.  Instead %s was given as the value.',
171
+									'event_espresso'
172
+								),
173
+								print_r($value, true)
174
+							)
175
+						);
176
+					}
177
+					break;
178
+				case 'menu_callback':
179
+					break;
180
+
181
+				default:
182
+					$value = (string) $value;
183
+					break;
184
+			}
185
+			if (! EEH_Class_Tools::has_property($this, $prop)) {
186
+				throw new EE_Error(
187
+					sprintf(
188
+						__(
189
+							'The $menu_args coming into %s has a index key (%s) representing a property that is not defined by the class.  Perhaps there is a typo?',
190
+							'event_espresso'
191
+						),
192
+						get_class($this),
193
+						$prop
194
+					)
195
+				);
196
+			}
197
+			$this->{$prop} = $value;
198
+		}
199
+
200
+		// filter capabilities (both static and dynamic)
201
+		$this->capability = apply_filters('FHEE_management_capability', $this->capability, null);
202
+		$this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null);
203
+
204
+		// Might need to change parent slug depending on maintenance mode.
205
+		if (! empty($this->maintenance_mode_parent)
206
+			&& EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
207
+		) {
208
+			$this->parent_slug = $this->maintenance_mode_parent;
209
+		}
210
+
211
+		// if empty menu_callback let's set default (but only if we have admin page init object)
212
+		if (empty($this->menu_callback) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
213
+			$this->menu_callback = array($this->admin_init_page, 'initialize_admin_page');
214
+		}
215
+	}
216
+
217
+
218
+	/**
219
+	 * This method should define how the menu page gets added for this particular item
220
+	 * and go ahead and define it.  Note that child classes MUST also return the result of
221
+	 * the function used to register the WordPress admin page (the wp_page_slug string)
222
+	 *
223
+	 * @since  4.4.0
224
+	 * @return string wp_page_slug.
225
+	 */
226
+	abstract protected function _add_menu_page();
227
+
228
+
229
+	/**
230
+	 * Called by client code to use this menu map for registering a WordPress admin page
231
+	 *
232
+	 * @param boolean $network_admin whether this is being added to the network admin page or not
233
+	 * @since  4.4.0
234
+	 */
235
+	public function add_menu_page($network_admin = false)
236
+	{
237
+
238
+		$show_on_menu_int = (int) $this->show_on_menu;
239
+		if (($network_admin
240
+			 && in_array(
241
+				 $show_on_menu_int,
242
+				 array(self::BLOG_AND_NETWORK_ADMIN, self::NETWORK_ADMIN_ONLY),
243
+				 true
244
+			 ))
245
+			||
246
+			(! $network_admin
247
+			 && in_array(
248
+				 $show_on_menu_int,
249
+				 array(self::BLOG_AND_NETWORK_ADMIN, self::BLOG_ADMIN_ONLY),
250
+				 true
251
+			 ))) {
252
+			$wp_page_slug = $this->_add_menu_page();
253
+		} else {
254
+			$wp_page_slug = '';
255
+		}
256
+
257
+		if (! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
258
+			try {
259
+				$this->admin_init_page->set_page_dependencies($wp_page_slug);
260
+			} catch (EE_Error $e) {
261
+				$e->get_error();
262
+			}
263
+		}
264
+	}
265 265
 }
266 266
 
267 267
 
@@ -275,75 +275,75 @@  discard block
 block discarded – undo
275 275
 class EE_Admin_Page_Main_Menu extends EE_Admin_Page_Menu_Map
276 276
 {
277 277
 
278
-    /**
279
-     * If included int incoming params, then this class will also register a Sub Menue Admin page with a different
280
-     * subtitle than the main menu item.
281
-     *
282
-     * @since 4.4.0
283
-     *
284
-     * @var string
285
-     */
286
-    public $subtitle;
287
-
288
-    /**
289
-     * The page to a icon used for this menu.
290
-     *
291
-     * @since  4.4.0
292
-     * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
293
-     *        for what can be set for this property.
294
-     * @var string
295
-     */
296
-    public $icon_url;
297
-
298
-
299
-    /**
300
-     * What position in the main menu order for the WP admin menu this menu item
301
-     * should show.
302
-     *
303
-     * @since  4.4.0
304
-     * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
305
-     *        for what can be set for this property.
306
-     * @var integer
307
-     */
308
-    public $position;
309
-
310
-
311
-    public function __construct($menu_args)
312
-    {
313
-        $required = array('menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page');
314
-
315
-        parent::__construct($menu_args, $required);
316
-
317
-        $this->position = ! empty($this->position) ? (int) $this->position : $this->position;
318
-    }
319
-
320
-
321
-    /**
322
-     * Uses the proper WP utility for registering a menu page for the main WP pages.
323
-     */
324
-    protected function _add_menu_page()
325
-    {
326
-        $main = add_menu_page(
327
-            $this->title,
328
-            $this->menu_label,
329
-            $this->capability,
330
-            $this->parent_slug,
331
-            $this->menu_callback,
332
-            $this->icon_url,
333
-            $this->position
334
-        );
335
-        if (! empty($this->subtitle)) {
336
-            add_submenu_page(
337
-                $this->parent_slug,
338
-                $this->subtitle,
339
-                $this->subtitle,
340
-                $this->capability,
341
-                $this->menu_slug,
342
-                $this->menu_callback
343
-            );
344
-        }
345
-        return $main;
346
-    }
278
+	/**
279
+	 * If included int incoming params, then this class will also register a Sub Menue Admin page with a different
280
+	 * subtitle than the main menu item.
281
+	 *
282
+	 * @since 4.4.0
283
+	 *
284
+	 * @var string
285
+	 */
286
+	public $subtitle;
287
+
288
+	/**
289
+	 * The page to a icon used for this menu.
290
+	 *
291
+	 * @since  4.4.0
292
+	 * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
293
+	 *        for what can be set for this property.
294
+	 * @var string
295
+	 */
296
+	public $icon_url;
297
+
298
+
299
+	/**
300
+	 * What position in the main menu order for the WP admin menu this menu item
301
+	 * should show.
302
+	 *
303
+	 * @since  4.4.0
304
+	 * @see    http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters
305
+	 *        for what can be set for this property.
306
+	 * @var integer
307
+	 */
308
+	public $position;
309
+
310
+
311
+	public function __construct($menu_args)
312
+	{
313
+		$required = array('menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page');
314
+
315
+		parent::__construct($menu_args, $required);
316
+
317
+		$this->position = ! empty($this->position) ? (int) $this->position : $this->position;
318
+	}
319
+
320
+
321
+	/**
322
+	 * Uses the proper WP utility for registering a menu page for the main WP pages.
323
+	 */
324
+	protected function _add_menu_page()
325
+	{
326
+		$main = add_menu_page(
327
+			$this->title,
328
+			$this->menu_label,
329
+			$this->capability,
330
+			$this->parent_slug,
331
+			$this->menu_callback,
332
+			$this->icon_url,
333
+			$this->position
334
+		);
335
+		if (! empty($this->subtitle)) {
336
+			add_submenu_page(
337
+				$this->parent_slug,
338
+				$this->subtitle,
339
+				$this->subtitle,
340
+				$this->capability,
341
+				$this->menu_slug,
342
+				$this->menu_callback
343
+			);
344
+		}
345
+		return $main;
346
+	}
347 347
 } //end EE_Admin_Page_Main_Menu
348 348
 
349 349
 
@@ -357,23 +357,23 @@  discard block
 block discarded – undo
357 357
 class EE_Admin_Page_Sub_Menu extends EE_Admin_Page_Main_Menu
358 358
 {
359 359
 
360
-    public function __construct($menu_args)
361
-    {
362
-        parent::__construct($menu_args);
363
-    }
364
-
365
-
366
-    protected function _add_menu_page()
367
-    {
368
-        return add_submenu_page(
369
-            $this->parent_slug,
370
-            $this->title,
371
-            $this->menu_label,
372
-            $this->capability,
373
-            $this->menu_slug,
374
-            $this->menu_callback
375
-        );
376
-    }
360
+	public function __construct($menu_args)
361
+	{
362
+		parent::__construct($menu_args);
363
+	}
364
+
365
+
366
+	protected function _add_menu_page()
367
+	{
368
+		return add_submenu_page(
369
+			$this->parent_slug,
370
+			$this->title,
371
+			$this->menu_label,
372
+			$this->capability,
373
+			$this->menu_slug,
374
+			$this->menu_callback
375
+		);
376
+	}
377 377
 }
378 378
 
379 379
 
@@ -392,28 +392,28 @@  discard block
 block discarded – undo
392 392
 {
393 393
 
394 394
 
395
-    public function __construct($menu_args = array())
396
-    {
397
-        $required = array('menu_label', 'menu_slug', 'menu_order', 'parent_slug');
398
-        parent::__construct($menu_args, $required);
399
-    }
395
+	public function __construct($menu_args = array())
396
+	{
397
+		$required = array('menu_label', 'menu_slug', 'menu_order', 'parent_slug');
398
+		parent::__construct($menu_args, $required);
399
+	}
400 400
 
401 401
 
402
-    protected function _add_menu_page()
403
-    {
404
-        return add_submenu_page(
405
-            $this->parent_slug,
406
-            $this->menu_label,
407
-            $this->_group_link(),
408
-            $this->capability,
409
-            $this->menu_slug,
410
-            '__return_false'
411
-        );
412
-    }
402
+	protected function _add_menu_page()
403
+	{
404
+		return add_submenu_page(
405
+			$this->parent_slug,
406
+			$this->menu_label,
407
+			$this->_group_link(),
408
+			$this->capability,
409
+			$this->menu_slug,
410
+			'__return_false'
411
+		);
412
+	}
413 413
 
414 414
 
415
-    private function _group_link()
416
-    {
417
-        return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
418
-    }
415
+	private function _group_link()
416
+	{
417
+		return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
418
+	}
419 419
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         // verify that required keys are present in the incoming array.
144 144
         $missing = array_diff((array) $required, array_keys((array) $menu_args));
145 145
 
146
-        if (! empty($missing)) {
146
+        if ( ! empty($missing)) {
147 147
             throw new EE_Error(
148 148
                 sprintf(
149 149
                     __(
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                     $value = (string) $value;
183 183
                     break;
184 184
             }
185
-            if (! EEH_Class_Tools::has_property($this, $prop)) {
185
+            if ( ! EEH_Class_Tools::has_property($this, $prop)) {
186 186
                 throw new EE_Error(
187 187
                     sprintf(
188 188
                         __(
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 
200 200
         // filter capabilities (both static and dynamic)
201 201
         $this->capability = apply_filters('FHEE_management_capability', $this->capability, null);
202
-        $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null);
202
+        $this->capability = apply_filters('FHEE_'.$this->menu_slug.'_capability', $this->capability, null);
203 203
 
204 204
         // Might need to change parent slug depending on maintenance mode.
205
-        if (! empty($this->maintenance_mode_parent)
205
+        if ( ! empty($this->maintenance_mode_parent)
206 206
             && EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
207 207
         ) {
208 208
             $this->parent_slug = $this->maintenance_mode_parent;
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
                  true
244 244
              ))
245 245
             ||
246
-            (! $network_admin
246
+            ( ! $network_admin
247 247
              && in_array(
248 248
                  $show_on_menu_int,
249 249
                  array(self::BLOG_AND_NETWORK_ADMIN, self::BLOG_ADMIN_ONLY),
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             $wp_page_slug = '';
255 255
         }
256 256
 
257
-        if (! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
257
+        if ( ! empty($wp_page_slug) && $this->admin_init_page instanceof EE_Admin_Page_Init) {
258 258
             try {
259 259
                 $this->admin_init_page->set_page_dependencies($wp_page_slug);
260 260
             } catch (EE_Error $e) {
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
             $this->icon_url,
333 333
             $this->position
334 334
         );
335
-        if (! empty($this->subtitle)) {
335
+        if ( ! empty($this->subtitle)) {
336 336
             add_submenu_page(
337 337
                 $this->parent_slug,
338 338
                 $this->subtitle,
@@ -414,6 +414,6 @@  discard block
 block discarded – undo
414 414
 
415 415
     private function _group_link()
416 416
     {
417
-        return '<span class="ee_menu_group"  onclick="return false;">' . $this->menu_label . '</span>';
417
+        return '<span class="ee_menu_group"  onclick="return false;">'.$this->menu_label.'</span>';
418 418
     }
419 419
 }
Please login to merge, or discard this patch.
core/admin/EE_Help_Tour.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
      *
97 97
      * @access public
98 98
      * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
-     * @return void
99
+     * @return EE_Help_Tour
100 100
      */
101 101
     public function __construct($caf = false)
102 102
     {
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -15,268 +15,268 @@
 block discarded – undo
15 15
 abstract class EE_Help_Tour extends EE_Base
16 16
 {
17 17
 
18
-    /**
19
-     * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the
20
-     * constructor of the child class.
21
-     *
22
-     * @access protected
23
-     * @var string
24
-     */
25
-    protected $_label = '';
26
-
27
-
28
-    /**
29
-     * This is the slug for the tour.  It should be unique from all tours and is used for starting a tour and setting
30
-     * cookies for the tour. Set this in the constructor of the child class.
31
-     *
32
-     * @access protected
33
-     * @var string
34
-     */
35
-    protected $_slug = '';
36
-
37
-
38
-    /**
39
-     * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for
40
-     * setting up a tour on a given page. format for array is: array(
41
-     *        0 => array(
42
-     *            'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take
43
-     *            precendence even if you also set class.
44
-     *            'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use
45
-     *            this param. The first element for that class is the anchor. If the class or the id are empty then the
46
-     *            stop will be a modal on the page anchored to the main body.
47
-     *            'custom_class' => 'some_custom_class', //optional custom class to add for this stop.
48
-     *            'button_text' => 'custom text for button', //optional
49
-     *            'content' => 'The content for the stop', //required
50
-     *            'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get
51
-     *            added to the pauseAfter global option array setup for the joyride instance. This is only applicable
52
-     *            when this tour has been set to run on timer.
53
-     *            'options' => array(
54
-     *                //override any of the global options set via the help_tour "option_callback" for the joyride
55
-     *                instance on this specific stop.
56
-     *                )
57
-     *            )
58
-     *        );
59
-     *
60
-     * @access protected
61
-     * @var array
62
-     */
63
-    protected $_stops = array();
64
-
65
-
66
-    /**
67
-     * This contains any stop specific options for the tour.
68
-     * defaults are set but child classes can override.
69
-     *
70
-     * @access protected
71
-     * @var array
72
-     */
73
-    protected $_options = array();
74
-
75
-
76
-    /**
77
-     * holds anything found in the $_REQUEST object (however we override any _gets with _post data).
78
-     *
79
-     * @access protected
80
-     * @var array
81
-     */
82
-    protected $_req_data = array();
83
-
84
-
85
-    /**
86
-     * a flag that is set on init for whether this help_tour is happening on a caf install or not.
87
-     *
88
-     * @var boolean
89
-     */
90
-    protected $_is_caf = false;
91
-
92
-
93
-    /**
94
-     * _constructor
95
-     * initialized the tour object and sets up important properties required to setup the tour.
96
-     *
97
-     * @access public
98
-     * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
-     * @return void
100
-     */
101
-    public function __construct($caf = false)
102
-    {
103
-        $this->_is_caf = $caf;
104
-        $this->_req_data = array_merge($_GET, $_POST);
105
-        $this->_set_tour_properties();
106
-        $this->_set_tour_stops();
107
-        $this->_set_tour_options();
108
-
109
-        // make sure the last tour stop has "end tour" for its button
110
-        $end = array_pop($this->_stops);
111
-        $end['button_text'] = __('End Tour', 'event_espresso');
112
-        // add back to stops
113
-        $this->_stops[] = $end;
114
-    }
115
-
116
-
117
-    /**
118
-     * required method that has the sole purpose of setting up the tour $_label and $_slug properties
119
-     *
120
-     * @abstract
121
-     * @access protected
122
-     * @return void
123
-     */
124
-    abstract protected function _set_tour_properties();
125
-
126
-
127
-    /**
128
-     * required method that's sole purpose is to setup the $_stops property
129
-     *
130
-     * @abstract
131
-     * @access protected
132
-     * @return void
133
-     */
134
-    abstract protected function _set_tour_stops();
135
-
136
-
137
-    /**
138
-     * The method can optionally be overridden by child classes to set the _options array if there are any default
139
-     * options the child wishes to override for a this tour. See property definition for more info
140
-     *
141
-     * @access protected
142
-     * @return void
143
-     */
144
-    protected function _set_tour_options($options = array())
145
-    {
146
-        $defaults = array(
147
-            'tipLocation'           => 'bottom',
148
-            // 'top', 'bottom', 'right', 'left' in relation to parent
149
-            'nubPosition'           => 'auto',
150
-            // override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left"
151
-            'tipAdjustmentY'        => 0,
152
-            // allow for adjustment of tip
153
-            'tipAdjustmentX'        => 0,
154
-            // allow for adjustment of tip
155
-            'scroll'                => true,
156
-            // whether to scrollTo the next step or not
157
-            'scrollSpeed'           => 300,
158
-            // Page scrolling speed in ms
159
-            'timer'                 => 0,
160
-            // 0 = off, all other numbers = time(ms)
161
-            'autoStart'             => true,
162
-            // true or false - false tour starts when restart called
163
-            'startTimerOnClick'     => true,
164
-            // true/false to start timer on first click
165
-            'nextButton'            => true,
166
-            // true/false for next button visibility
167
-            'button_text'           => __('Next', 'event_espresso'),
168
-            'tipAnimation'          => 'fade',
169
-            // 'pop' or 'fade' in each tip
170
-            'pauseAfter'            => array(),
171
-            // array of indexes where to pause the tour after
172
-            'tipAnimationFadeSpeed' => 300,
173
-            // if 'fade'- speed in ms of transition
174
-            'cookieMonster'         => true,
175
-            // true/false for whether cookies are used
176
-            'cookieName'            => $this->get_slug(),
177
-            // choose your own cookie name (setup will add the prefix for the specific page joyride)
178
-            'cookieDomain'          => false,
179
-            // set to false or yoursite.com
180
-            // 'tipContainer' => 'body',            // Where the tip be attached if not inline
181
-            'modal'                 => false,
182
-            // Whether to cover page with modal during the tour
183
-            'expose'                => false,
184
-            // Whether to expose the elements at each step in the tour (requires modal:true),
185
-            'postExposeCallback'    => 'EEHelpTour.postExposeCallback',
186
-            // A method to call after an element has been exposed
187
-            'preRideCallback'       => 'EEHelpTour_preRideCallback',
188
-            // A method to call before the tour starts (passed index, tip, and cloned exposed element)
189
-            'postRideCallback'      => 'EEHelpTour_postRideCallback',
190
-            // a method to call once the tour closes.  This will correspond to the name of a js method that will have to be defined in loaded js.
191
-            'preStepCallback'       => 'EEHelpTour_preStepCallback',
192
-            // A method to call before each step
193
-            'postStepCallback'      => 'EEHelpTour_postStepCallback',
194
-            // A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/
195
-        );
196
-
197
-        $options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults;
198
-        $this->_options = $options;
199
-    }
200
-
201
-
202
-    /**
203
-     * getter functions to return all the properties for the tour.
204
-     */
205
-
206
-
207
-    /**
208
-     * get_slug
209
-     *
210
-     * @return string slug for the tour
211
-     */
212
-    public function get_slug()
213
-    {
214
-        if (empty($this->_slug)) {
215
-            throw new EE_Error(
216
-                sprintf(
217
-                    __(
218
-                        'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor',
219
-                        'event_espresso'
220
-                    ),
221
-                    get_class($this)
222
-                )
223
-            );
224
-        }
225
-        return $this->_slug;
226
-    }
227
-
228
-
229
-    /**
230
-     * get_label
231
-     *
232
-     * @return string
233
-     */
234
-    public function get_label()
235
-    {
236
-        if (empty($this->_label)) {
237
-            throw new EE_Error(
238
-                sprintf(
239
-                    __(
240
-                        'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor',
241
-                        'event_espresso'
242
-                    ),
243
-                    get_class($this)
244
-                )
245
-            );
246
-        }
247
-        return $this->_label;
248
-    }
249
-
250
-
251
-    /**
252
-     * get_stops
253
-     *
254
-     * @return array
255
-     */
256
-    public function get_stops()
257
-    {
258
-        foreach ($this->_stops as $ind => $stop) {
259
-            if (! isset($stop['button_text'])) {
260
-                $this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
261
-            }
262
-        }
263
-        return $this->_stops;
264
-    }
265
-
266
-
267
-    /**
268
-     * get options
269
-     *
270
-     * @return array
271
-     */
272
-    public function get_options()
273
-    {
274
-        // let's make sure there are not pauses set
275
-        foreach ($this->_stops as $ind => $stop) {
276
-            if (isset($stop['pause_after']) && $stop['pause_after']) {
277
-                $this->_options['pauseAfter'][] = $ind;
278
-            }
279
-        }
280
-        return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
281
-    }
18
+	/**
19
+	 * This is the label for the tour. It is used when regenerating restart buttons for the tour. Set this in the
20
+	 * constructor of the child class.
21
+	 *
22
+	 * @access protected
23
+	 * @var string
24
+	 */
25
+	protected $_label = '';
26
+
27
+
28
+	/**
29
+	 * This is the slug for the tour.  It should be unique from all tours and is used for starting a tour and setting
30
+	 * cookies for the tour. Set this in the constructor of the child class.
31
+	 *
32
+	 * @access protected
33
+	 * @var string
34
+	 */
35
+	protected $_slug = '';
36
+
37
+
38
+	/**
39
+	 * This will contain the formatted array for the stops that gets used by EE_Admin_Page->_add_help_tour() for
40
+	 * setting up a tour on a given page. format for array is: array(
41
+	 *        0 => array(
42
+	 *            'id' => 'id_element', //if attached to an css id for an element then use this param. id's will take
43
+	 *            precendence even if you also set class.
44
+	 *            'class' => 'class_element', //if attached to a css class for an element anchoring the stop then use
45
+	 *            this param. The first element for that class is the anchor. If the class or the id are empty then the
46
+	 *            stop will be a modal on the page anchored to the main body.
47
+	 *            'custom_class' => 'some_custom_class', //optional custom class to add for this stop.
48
+	 *            'button_text' => 'custom text for button', //optional
49
+	 *            'content' => 'The content for the stop', //required
50
+	 *            'pause_after' => false, //indicate if you want the tour to pause after this stop and it will get
51
+	 *            added to the pauseAfter global option array setup for the joyride instance. This is only applicable
52
+	 *            when this tour has been set to run on timer.
53
+	 *            'options' => array(
54
+	 *                //override any of the global options set via the help_tour "option_callback" for the joyride
55
+	 *                instance on this specific stop.
56
+	 *                )
57
+	 *            )
58
+	 *        );
59
+	 *
60
+	 * @access protected
61
+	 * @var array
62
+	 */
63
+	protected $_stops = array();
64
+
65
+
66
+	/**
67
+	 * This contains any stop specific options for the tour.
68
+	 * defaults are set but child classes can override.
69
+	 *
70
+	 * @access protected
71
+	 * @var array
72
+	 */
73
+	protected $_options = array();
74
+
75
+
76
+	/**
77
+	 * holds anything found in the $_REQUEST object (however we override any _gets with _post data).
78
+	 *
79
+	 * @access protected
80
+	 * @var array
81
+	 */
82
+	protected $_req_data = array();
83
+
84
+
85
+	/**
86
+	 * a flag that is set on init for whether this help_tour is happening on a caf install or not.
87
+	 *
88
+	 * @var boolean
89
+	 */
90
+	protected $_is_caf = false;
91
+
92
+
93
+	/**
94
+	 * _constructor
95
+	 * initialized the tour object and sets up important properties required to setup the tour.
96
+	 *
97
+	 * @access public
98
+	 * @param boolean $caf used to indicate if this tour is happening on caf install or not.
99
+	 * @return void
100
+	 */
101
+	public function __construct($caf = false)
102
+	{
103
+		$this->_is_caf = $caf;
104
+		$this->_req_data = array_merge($_GET, $_POST);
105
+		$this->_set_tour_properties();
106
+		$this->_set_tour_stops();
107
+		$this->_set_tour_options();
108
+
109
+		// make sure the last tour stop has "end tour" for its button
110
+		$end = array_pop($this->_stops);
111
+		$end['button_text'] = __('End Tour', 'event_espresso');
112
+		// add back to stops
113
+		$this->_stops[] = $end;
114
+	}
115
+
116
+
117
+	/**
118
+	 * required method that has the sole purpose of setting up the tour $_label and $_slug properties
119
+	 *
120
+	 * @abstract
121
+	 * @access protected
122
+	 * @return void
123
+	 */
124
+	abstract protected function _set_tour_properties();
125
+
126
+
127
+	/**
128
+	 * required method that's sole purpose is to setup the $_stops property
129
+	 *
130
+	 * @abstract
131
+	 * @access protected
132
+	 * @return void
133
+	 */
134
+	abstract protected function _set_tour_stops();
135
+
136
+
137
+	/**
138
+	 * The method can optionally be overridden by child classes to set the _options array if there are any default
139
+	 * options the child wishes to override for a this tour. See property definition for more info
140
+	 *
141
+	 * @access protected
142
+	 * @return void
143
+	 */
144
+	protected function _set_tour_options($options = array())
145
+	{
146
+		$defaults = array(
147
+			'tipLocation'           => 'bottom',
148
+			// 'top', 'bottom', 'right', 'left' in relation to parent
149
+			'nubPosition'           => 'auto',
150
+			// override on a per tooltip bases. can be "auto", "right", "top", "bottom", "left"
151
+			'tipAdjustmentY'        => 0,
152
+			// allow for adjustment of tip
153
+			'tipAdjustmentX'        => 0,
154
+			// allow for adjustment of tip
155
+			'scroll'                => true,
156
+			// whether to scrollTo the next step or not
157
+			'scrollSpeed'           => 300,
158
+			// Page scrolling speed in ms
159
+			'timer'                 => 0,
160
+			// 0 = off, all other numbers = time(ms)
161
+			'autoStart'             => true,
162
+			// true or false - false tour starts when restart called
163
+			'startTimerOnClick'     => true,
164
+			// true/false to start timer on first click
165
+			'nextButton'            => true,
166
+			// true/false for next button visibility
167
+			'button_text'           => __('Next', 'event_espresso'),
168
+			'tipAnimation'          => 'fade',
169
+			// 'pop' or 'fade' in each tip
170
+			'pauseAfter'            => array(),
171
+			// array of indexes where to pause the tour after
172
+			'tipAnimationFadeSpeed' => 300,
173
+			// if 'fade'- speed in ms of transition
174
+			'cookieMonster'         => true,
175
+			// true/false for whether cookies are used
176
+			'cookieName'            => $this->get_slug(),
177
+			// choose your own cookie name (setup will add the prefix for the specific page joyride)
178
+			'cookieDomain'          => false,
179
+			// set to false or yoursite.com
180
+			// 'tipContainer' => 'body',            // Where the tip be attached if not inline
181
+			'modal'                 => false,
182
+			// Whether to cover page with modal during the tour
183
+			'expose'                => false,
184
+			// Whether to expose the elements at each step in the tour (requires modal:true),
185
+			'postExposeCallback'    => 'EEHelpTour.postExposeCallback',
186
+			// A method to call after an element has been exposed
187
+			'preRideCallback'       => 'EEHelpTour_preRideCallback',
188
+			// A method to call before the tour starts (passed index, tip, and cloned exposed element)
189
+			'postRideCallback'      => 'EEHelpTour_postRideCallback',
190
+			// a method to call once the tour closes.  This will correspond to the name of a js method that will have to be defined in loaded js.
191
+			'preStepCallback'       => 'EEHelpTour_preStepCallback',
192
+			// A method to call before each step
193
+			'postStepCallback'      => 'EEHelpTour_postStepCallback',
194
+			// A method to call after each step (remember this will correspond with a js method that you will have to define in a js file BEFORE ee-help-tour.js loads, if the default methods do not exist, then ee-help-tour.js just substitues empty functions $.noop)/**/
195
+		);
196
+
197
+		$options = ! empty($options) && is_array($options) ? array_merge($defaults, $options) : $defaults;
198
+		$this->_options = $options;
199
+	}
200
+
201
+
202
+	/**
203
+	 * getter functions to return all the properties for the tour.
204
+	 */
205
+
206
+
207
+	/**
208
+	 * get_slug
209
+	 *
210
+	 * @return string slug for the tour
211
+	 */
212
+	public function get_slug()
213
+	{
214
+		if (empty($this->_slug)) {
215
+			throw new EE_Error(
216
+				sprintf(
217
+					__(
218
+						'There is no slug set for the help tour class (%s). Make sure that the $_slug property is set in the class constructor',
219
+						'event_espresso'
220
+					),
221
+					get_class($this)
222
+				)
223
+			);
224
+		}
225
+		return $this->_slug;
226
+	}
227
+
228
+
229
+	/**
230
+	 * get_label
231
+	 *
232
+	 * @return string
233
+	 */
234
+	public function get_label()
235
+	{
236
+		if (empty($this->_label)) {
237
+			throw new EE_Error(
238
+				sprintf(
239
+					__(
240
+						'There is no label set for the help tour class (%s). Make sure that the $_label property is set in the class constructor',
241
+						'event_espresso'
242
+					),
243
+					get_class($this)
244
+				)
245
+			);
246
+		}
247
+		return $this->_label;
248
+	}
249
+
250
+
251
+	/**
252
+	 * get_stops
253
+	 *
254
+	 * @return array
255
+	 */
256
+	public function get_stops()
257
+	{
258
+		foreach ($this->_stops as $ind => $stop) {
259
+			if (! isset($stop['button_text'])) {
260
+				$this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
261
+			}
262
+		}
263
+		return $this->_stops;
264
+	}
265
+
266
+
267
+	/**
268
+	 * get options
269
+	 *
270
+	 * @return array
271
+	 */
272
+	public function get_options()
273
+	{
274
+		// let's make sure there are not pauses set
275
+		foreach ($this->_stops as $ind => $stop) {
276
+			if (isset($stop['pause_after']) && $stop['pause_after']) {
277
+				$this->_options['pauseAfter'][] = $ind;
278
+			}
279
+		}
280
+		return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
     public function get_stops()
257 257
     {
258 258
         foreach ($this->_stops as $ind => $stop) {
259
-            if (! isset($stop['button_text'])) {
260
-                $this->_stops[ $ind ]['button_text'] = $this->_options['button_text'];
259
+            if ( ! isset($stop['button_text'])) {
260
+                $this->_stops[$ind]['button_text'] = $this->_options['button_text'];
261 261
             }
262 262
         }
263 263
         return $this->_stops;
@@ -277,6 +277,6 @@  discard block
 block discarded – undo
277 277
                 $this->_options['pauseAfter'][] = $ind;
278 278
             }
279 279
         }
280
-        return apply_filters('FHEE__' . get_class($this) . '__get_options', $this->_options, $this);
280
+        return apply_filters('FHEE__'.get_class($this).'__get_options', $this->_options, $this);
281 281
     }
282 282
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_answers.dmsstage.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,6 @@
 block discarded – undo
62 62
     /**
63 63
      * Creates a 4.1 price base type
64 64
      * @global type $wpdb
65
-     * @param array $old_price
66 65
      * @param int $new_reg_id
67 66
      * @return int
68 67
      */
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -32,81 +32,81 @@
 block discarded – undo
32 32
 
33 33
 class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table
34 34
 {
35
-    private $_new_answer_table;
36
-    private $_new_question_table;
37
-    public function __construct()
38
-    {
39
-        global $wpdb;
40
-        $this->_pretty_name = __("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix."events_answer";
42
-        $this->_new_answer_table = $wpdb->prefix."esp_answer";
43
-        $this->_new_question_table = $wpdb->prefix."esp_question";
44
-        parent::__construct();
45
-    }
46
-    protected function _migrate_old_row($old_row)
47
-    {
48
-        // get the new REGs for the old answer
49
-        global $wpdb;
50
-        $old_attendee_table = $wpdb->prefix."events_attendee";
51
-        $new_reg_table = $wpdb->prefix."esp_registration";
52
-        $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
53
-        if (! $regs) {
54
-            $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
55
-            return false;
56
-        }
57
-        // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
58
-        foreach ($regs as $new_reg_id) {
59
-            $new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id);
60
-        }
61
-    }
62
-    /**
63
-     * Creates a 4.1 price base type
64
-     * @global type $wpdb
65
-     * @param array $old_price
66
-     * @param int $new_reg_id
67
-     * @return int
68
-     */
69
-    private function _insert_new_answer($old_answer, $new_reg_id)
70
-    {
71
-        global $wpdb;
72
-        $old_question_table = $wpdb->prefix."events_question";
73
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
35
+	private $_new_answer_table;
36
+	private $_new_question_table;
37
+	public function __construct()
38
+	{
39
+		global $wpdb;
40
+		$this->_pretty_name = __("Answers", "event_espresso");
41
+		$this->_old_table = $wpdb->prefix."events_answer";
42
+		$this->_new_answer_table = $wpdb->prefix."esp_answer";
43
+		$this->_new_question_table = $wpdb->prefix."esp_question";
44
+		parent::__construct();
45
+	}
46
+	protected function _migrate_old_row($old_row)
47
+	{
48
+		// get the new REGs for the old answer
49
+		global $wpdb;
50
+		$old_attendee_table = $wpdb->prefix."events_attendee";
51
+		$new_reg_table = $wpdb->prefix."esp_registration";
52
+		$regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
53
+		if (! $regs) {
54
+			$this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
55
+			return false;
56
+		}
57
+		// as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
58
+		foreach ($regs as $new_reg_id) {
59
+			$new_answer_id = $this->_insert_new_answer($old_row, $new_reg_id);
60
+		}
61
+	}
62
+	/**
63
+	 * Creates a 4.1 price base type
64
+	 * @global type $wpdb
65
+	 * @param array $old_price
66
+	 * @param int $new_reg_id
67
+	 * @return int
68
+	 */
69
+	private function _insert_new_answer($old_answer, $new_reg_id)
70
+	{
71
+		global $wpdb;
72
+		$old_question_table = $wpdb->prefix."events_question";
73
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
74 74
 
75
-        $question_type = $this->_get_question_type($new_question_id);
76
-        if (in_array($question_type, array('MULTIPLE'))) {
77
-            $ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
78
-        } else {
79
-            $ans_value = stripslashes($old_answer['answer']);
80
-        }
81
-        $cols_n_values = array(
82
-            'REG_ID'=>$new_reg_id,
83
-            'QST_ID'=>$new_question_id,
84
-            'ANS_value'=>$ans_value
85
-        );
86
-        $datatypes = array(
87
-            '%d',// REG_ID
88
-            '%d',// QST_ID
89
-            '%s',// ANS_value
90
-        );
91
-        $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
92
-        if (! $success) {
93
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
94
-            return 0;
95
-        }
96
-        $new_id = $wpdb->insert_id;
97
-        return $new_id;
98
-    }
75
+		$question_type = $this->_get_question_type($new_question_id);
76
+		if (in_array($question_type, array('MULTIPLE'))) {
77
+			$ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
78
+		} else {
79
+			$ans_value = stripslashes($old_answer['answer']);
80
+		}
81
+		$cols_n_values = array(
82
+			'REG_ID'=>$new_reg_id,
83
+			'QST_ID'=>$new_question_id,
84
+			'ANS_value'=>$ans_value
85
+		);
86
+		$datatypes = array(
87
+			'%d',// REG_ID
88
+			'%d',// QST_ID
89
+			'%s',// ANS_value
90
+		);
91
+		$success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
92
+		if (! $success) {
93
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
94
+			return 0;
95
+		}
96
+		$new_id = $wpdb->insert_id;
97
+		return $new_id;
98
+	}
99 99
 
100
-    /**
101
-     * Gets the question's type
102
-     * @global type $wpdb
103
-     * @param type $question_id
104
-     * @return string
105
-     */
106
-    private function _get_question_type($question_id)
107
-    {
108
-        global $wpdb;
109
-        $type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id));
110
-        return $type;
111
-    }
100
+	/**
101
+	 * Gets the question's type
102
+	 * @global type $wpdb
103
+	 * @param type $question_id
104
+	 * @return string
105
+	 */
106
+	private function _get_question_type($question_id)
107
+	{
108
+		global $wpdb;
109
+		$type = $wpdb->get_var($wpdb->prepare("SELECT QST_type FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", $question_id));
110
+		return $type;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         $old_attendee_table = $wpdb->prefix."events_attendee";
51 51
         $new_reg_table = $wpdb->prefix."esp_registration";
52 52
         $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
53
-        if (! $regs) {
53
+        if ( ! $regs) {
54 54
             $this->add_error(sprintf(__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
55 55
             return false;
56 56
         }
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
             'ANS_value'=>$ans_value
85 85
         );
86 86
         $datatypes = array(
87
-            '%d',// REG_ID
88
-            '%d',// QST_ID
89
-            '%s',// ANS_value
87
+            '%d', // REG_ID
88
+            '%d', // QST_ID
89
+            '%s', // ANS_value
90 90
         );
91 91
         $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
92
-        if (! $success) {
92
+        if ( ! $success) {
93 93
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
94 94
             return 0;
95 95
         }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_attendees.dmsstage.php 3 patches
Doc Comments   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
      * that they WILL be added (because the attendees stage runs nearly last during
580 580
      * the migration script)
581 581
      * @param type $new_ticket_id
582
-     * @param type $sold
583
-     * @param type $STS_ID
582
+     * @param string $STS_ID
583
+     * @param integer $quantity_sold
584 584
      * @return boolean whether they were successfully updated or not
585 585
      */
586 586
     protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
@@ -777,6 +777,10 @@  discard block
 block discarded – undo
777 777
         }
778 778
         return $count;
779 779
     }
780
+
781
+    /**
782
+     * @param integer $new_txn_id
783
+     */
780 784
     private function _insert_new_payment($old_attendee, $new_txn_id)
781 785
     {
782 786
         global $wpdb;
Please login to merge, or discard this patch.
Indentation   +598 added lines, -601 removed lines patch added patch discarded remove patch
@@ -84,9 +84,6 @@  discard block
 block discarded – undo
84 84
   KEY `submitted` (`submitted`),
85 85
   KEY `likes` (`likes`)
86 86
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8$$
87
-
88
-
89
-
90 87
  * 4.1 Attendee tables and fields:
91 88
  * $this->_tables = array(
92 89
             'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'),
@@ -216,632 +213,632 @@  discard block
 block discarded – undo
216 213
  */
217 214
 class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table
218 215
 {
219
-    private $_new_attendee_cpt_table;
220
-    private $_new_attendee_meta_table;
221
-    private $_new_reg_table;
222
-    private $_new_transaction_table;
223
-    private $_new_payment_table;
224
-    private $_new_line_table;
225
-    private $_old_mer_table;
226
-    private $_new_ticket_table;
227
-    private $_new_ticket_datetime_table;
228
-    private $_new_datetime_table;
229
-    private $_new_datetime_ticket_table;
230
-    private $_new_price_table;
231
-    private $_new_ticket_price_table;
232
-    /**
233
-     * Rememebrs whether or not the mer table exists
234
-     * @var boolean
235
-     */
236
-    private $_mer_tables_exist = null;
237
-    public function __construct()
238
-    {
239
-        global $wpdb;
240
-        $this->_pretty_name = __("Attendees", "event_espresso");
241
-        $this->_old_table = $wpdb->prefix."events_attendee";
242
-        $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
243
-        ;
244
-        $this->_new_attendee_cpt_table = $wpdb->posts;
245
-        $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
246
-        $this->_new_reg_table = $wpdb->prefix."esp_registration";
247
-        $this->_new_transaction_table = $wpdb->prefix."esp_transaction";
248
-        $this->_new_payment_table = $wpdb->prefix."esp_payment";
249
-        $this->_new_line_table = $wpdb->prefix."esp_line_item";
250
-        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
251
-        $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
252
-        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
253
-        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
254
-        $this->_new_price_table = $wpdb->prefix."esp_price";
255
-        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
256
-        parent::__construct();
257
-    }
216
+	private $_new_attendee_cpt_table;
217
+	private $_new_attendee_meta_table;
218
+	private $_new_reg_table;
219
+	private $_new_transaction_table;
220
+	private $_new_payment_table;
221
+	private $_new_line_table;
222
+	private $_old_mer_table;
223
+	private $_new_ticket_table;
224
+	private $_new_ticket_datetime_table;
225
+	private $_new_datetime_table;
226
+	private $_new_datetime_ticket_table;
227
+	private $_new_price_table;
228
+	private $_new_ticket_price_table;
229
+	/**
230
+	 * Rememebrs whether or not the mer table exists
231
+	 * @var boolean
232
+	 */
233
+	private $_mer_tables_exist = null;
234
+	public function __construct()
235
+	{
236
+		global $wpdb;
237
+		$this->_pretty_name = __("Attendees", "event_espresso");
238
+		$this->_old_table = $wpdb->prefix."events_attendee";
239
+		$this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
240
+		;
241
+		$this->_new_attendee_cpt_table = $wpdb->posts;
242
+		$this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
243
+		$this->_new_reg_table = $wpdb->prefix."esp_registration";
244
+		$this->_new_transaction_table = $wpdb->prefix."esp_transaction";
245
+		$this->_new_payment_table = $wpdb->prefix."esp_payment";
246
+		$this->_new_line_table = $wpdb->prefix."esp_line_item";
247
+		$this->_new_ticket_table = $wpdb->prefix."esp_ticket";
248
+		$this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
249
+		$this->_new_datetime_table = $wpdb->prefix."esp_datetime";
250
+		$this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
251
+		$this->_new_price_table = $wpdb->prefix."esp_price";
252
+		$this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
253
+		parent::__construct();
254
+	}
258 255
 
259
-    protected function _migrate_old_row($old_row)
260
-    {
261
-        // first check if there's already a new attendee with similar characteristics
262
-        $new_att_id = $this->_find_attendee_cpt_matching($old_row);
263
-        if (! $new_att_id) {
264
-            $new_att_id = $this->_insert_new_attendee_cpt($old_row);
265
-            if (! $new_att_id) {
266
-                // if we couldnt even make an attendee, abandon all hope
267
-                return false;
268
-            }
269
-            $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
270
-            if ($new_att_meta_id) {
271
-                $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
272
-            }
273
-        }
274
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
256
+	protected function _migrate_old_row($old_row)
257
+	{
258
+		// first check if there's already a new attendee with similar characteristics
259
+		$new_att_id = $this->_find_attendee_cpt_matching($old_row);
260
+		if (! $new_att_id) {
261
+			$new_att_id = $this->_insert_new_attendee_cpt($old_row);
262
+			if (! $new_att_id) {
263
+				// if we couldnt even make an attendee, abandon all hope
264
+				return false;
265
+			}
266
+			$new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
267
+			if ($new_att_meta_id) {
268
+				$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
269
+			}
270
+		}
271
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
275 272
 
276
-        $txn_id = $this->_insert_new_transaction($old_row);
277
-        if (! $txn_id) {
278
-            // if we couldnt make the transaction, also abandon all hope
279
-            return false;
280
-        }
281
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
282
-        $pay_id = $this->_insert_new_payment($old_row, $txn_id);
283
-        if ($pay_id) {
284
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
285
-        }
273
+		$txn_id = $this->_insert_new_transaction($old_row);
274
+		if (! $txn_id) {
275
+			// if we couldnt make the transaction, also abandon all hope
276
+			return false;
277
+		}
278
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
279
+		$pay_id = $this->_insert_new_payment($old_row, $txn_id);
280
+		if ($pay_id) {
281
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
282
+		}
286 283
 
287 284
 
288
-        // even if there was no payment, we can go ahead with adding the reg
289
-        $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
290
-        if ($new_regs) {
291
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
292
-        }
293
-    }
294
-    /**
295
-     * Checks if there's already an attendee CPT in the db that has the same
296
-     * first and last name, and email. If so, returns its ID as an int.
297
-     * @global type $wpdb
298
-     * @param array $old_attendee
299
-     * @return int
300
-     */
301
-    private function _find_attendee_cpt_matching($old_attendee)
302
-    {
303
-        global $wpdb;
304
-        $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email']));
305
-        return intval($existing_attendee_id);
306
-    }
307
-    private function _insert_new_attendee_cpt($old_attendee)
308
-    {
309
-        global $wpdb;
310
-        $cols_n_values = array(
311
-            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
312
-            'post_content'=>'',// ATT_bio
313
-            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
314
-            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
315
-            'post_excerpt'=>'',// ATT_short_bio
316
-            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
317
-            'post_author'=>0,// ATT_author
318
-            'post_parent'=>0,// ATT_parent
319
-            'post_type'=>'espresso_attendees',// post_type
320
-            'post_status'=>'publish'// status
321
-        );
322
-        $datatypes = array(
323
-            '%s',// ATT_full_name
324
-            '%s',// ATT_bio
325
-            '%s',// ATT_slug
326
-            '%s',// ATT_created
327
-            '%s',// ATT_short_bio
328
-            '%s',// ATT_modified
329
-            '%d',// ATT_author
330
-            '%d',// ATT_parent
331
-            '%s',// post_type
332
-            '%s',// status
333
-        );
334
-        $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
335
-        if (! $success) {
336
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
337
-            return 0;
338
-        }
339
-        $new_id = $wpdb->insert_id;
340
-        return $new_id;
341
-    }
285
+		// even if there was no payment, we can go ahead with adding the reg
286
+		$new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
287
+		if ($new_regs) {
288
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
289
+		}
290
+	}
291
+	/**
292
+	 * Checks if there's already an attendee CPT in the db that has the same
293
+	 * first and last name, and email. If so, returns its ID as an int.
294
+	 * @global type $wpdb
295
+	 * @param array $old_attendee
296
+	 * @return int
297
+	 */
298
+	private function _find_attendee_cpt_matching($old_attendee)
299
+	{
300
+		global $wpdb;
301
+		$existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email']));
302
+		return intval($existing_attendee_id);
303
+	}
304
+	private function _insert_new_attendee_cpt($old_attendee)
305
+	{
306
+		global $wpdb;
307
+		$cols_n_values = array(
308
+			'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
309
+			'post_content'=>'',// ATT_bio
310
+			'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
311
+			'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
312
+			'post_excerpt'=>'',// ATT_short_bio
313
+			'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
314
+			'post_author'=>0,// ATT_author
315
+			'post_parent'=>0,// ATT_parent
316
+			'post_type'=>'espresso_attendees',// post_type
317
+			'post_status'=>'publish'// status
318
+		);
319
+		$datatypes = array(
320
+			'%s',// ATT_full_name
321
+			'%s',// ATT_bio
322
+			'%s',// ATT_slug
323
+			'%s',// ATT_created
324
+			'%s',// ATT_short_bio
325
+			'%s',// ATT_modified
326
+			'%d',// ATT_author
327
+			'%d',// ATT_parent
328
+			'%s',// post_type
329
+			'%s',// status
330
+		);
331
+		$success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
332
+		if (! $success) {
333
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
334
+			return 0;
335
+		}
336
+		$new_id = $wpdb->insert_id;
337
+		return $new_id;
338
+	}
342 339
 
343
-    private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
344
-    {
345
-        global $wpdb;
346
-        // get the state and country ids from the old row
347
-        try {
348
-            $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
349
-            $new_country_iso = $new_country['CNT_ISO'];
350
-        } catch (EE_Error $exception) {
351
-            $new_country_iso = $this->get_migration_script()->get_default_country_iso();
352
-        }
353
-        try {
354
-            $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
355
-            $new_state_id = $new_state['STA_ID'];
356
-        } catch (EE_Error $exception) {
357
-            $new_state_id = 0;
358
-        }
359
-        $cols_n_values = array(
360
-            'ATT_ID'=>$new_attendee_cpt_id,
361
-            'ATT_fname'=>stripslashes($old_attendee['fname']),
362
-            'ATT_lname'=>stripslashes($old_attendee['lname']),
363
-            'ATT_address'=>stripslashes($old_attendee['address']),
364
-            'ATT_address2'=>stripslashes($old_attendee['address2']),
365
-            'ATT_city'=>stripslashes($old_attendee['city']),
366
-            'STA_ID'=>$new_state_id,
367
-            'CNT_ISO'=>$new_country_iso,
368
-            'ATT_zip'=>stripslashes($old_attendee['zip']),
369
-            'ATT_email'=>stripslashes($old_attendee['email']),
370
-            'ATT_phone'=>stripslashes($old_attendee['phone']),
371
-        );
372
-        $datatypes = array(
373
-            '%d',// ATT_ID
374
-            '%s',// ATT_fname
375
-            '%s',// ATT_lname
376
-            '%s',// ATT_address
377
-            '%s',// ATT_address2
378
-            '%s',// ATT_city
379
-            '%d',// STA_ID
380
-            '%s',// CNT_ISO
381
-            '%s',// ATT_zip
382
-            '%s',// ATT_email
383
-            '%s',// ATT_phone
384
-        );
385
-        $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
386
-        if (! $success) {
387
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
388
-            return 0;
389
-        }
390
-        $new_id = $wpdb->insert_id;
391
-        return $new_id;
392
-    }
340
+	private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
341
+	{
342
+		global $wpdb;
343
+		// get the state and country ids from the old row
344
+		try {
345
+			$new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
346
+			$new_country_iso = $new_country['CNT_ISO'];
347
+		} catch (EE_Error $exception) {
348
+			$new_country_iso = $this->get_migration_script()->get_default_country_iso();
349
+		}
350
+		try {
351
+			$new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
352
+			$new_state_id = $new_state['STA_ID'];
353
+		} catch (EE_Error $exception) {
354
+			$new_state_id = 0;
355
+		}
356
+		$cols_n_values = array(
357
+			'ATT_ID'=>$new_attendee_cpt_id,
358
+			'ATT_fname'=>stripslashes($old_attendee['fname']),
359
+			'ATT_lname'=>stripslashes($old_attendee['lname']),
360
+			'ATT_address'=>stripslashes($old_attendee['address']),
361
+			'ATT_address2'=>stripslashes($old_attendee['address2']),
362
+			'ATT_city'=>stripslashes($old_attendee['city']),
363
+			'STA_ID'=>$new_state_id,
364
+			'CNT_ISO'=>$new_country_iso,
365
+			'ATT_zip'=>stripslashes($old_attendee['zip']),
366
+			'ATT_email'=>stripslashes($old_attendee['email']),
367
+			'ATT_phone'=>stripslashes($old_attendee['phone']),
368
+		);
369
+		$datatypes = array(
370
+			'%d',// ATT_ID
371
+			'%s',// ATT_fname
372
+			'%s',// ATT_lname
373
+			'%s',// ATT_address
374
+			'%s',// ATT_address2
375
+			'%s',// ATT_city
376
+			'%d',// STA_ID
377
+			'%s',// CNT_ISO
378
+			'%s',// ATT_zip
379
+			'%s',// ATT_email
380
+			'%s',// ATT_phone
381
+		);
382
+		$success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
383
+		if (! $success) {
384
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
385
+			return 0;
386
+		}
387
+		$new_id = $wpdb->insert_id;
388
+		return $new_id;
389
+	}
393 390
 
394
-    /**
395
-     * Note: we don't necessarily create a new transaction for each attendee row.
396
-     * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
397
-     * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
398
-     * @global type $wpdb
399
-     * @param type $old_attendee
400
-     * @return int new transaction id
401
-     */
402
-    private function _insert_new_transaction($old_attendee)
403
-    {
404
-        global $wpdb;
391
+	/**
392
+	 * Note: we don't necessarily create a new transaction for each attendee row.
393
+	 * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
394
+	 * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
395
+	 * @global type $wpdb
396
+	 * @param type $old_attendee
397
+	 * @return int new transaction id
398
+	 */
399
+	private function _insert_new_transaction($old_attendee)
400
+	{
401
+		global $wpdb;
405 402
 
406
-        // first: let's check for an existing transaction for this old attendee
407
-        if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
408
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
409
-        } else { // non-primary attendee, so find its primary attendee's transaction
410
-            $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
411
-            if (! $primary_attendee_old_id) {
412
-                $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
413
-                $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
414
-            }
415
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
416
-            if (! $txn_id) {
417
-                $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
418
-                $txn_id = 0;
419
-            }
420
-        }
421
-        // if there isn't yet a transaction row for this, create one
422
-        // (so even if it was a non-primary attendee with no EE3 primary attendee,
423
-        // it ought to have SOME transaction, so we'll make one)
424
-        if (! $txn_id) {
425
-            // maps 3.1 payment stati onto 4.1 transaction stati
426
-            $txn_status_mapping = array(
427
-                'Completed'=>'TCM',
428
-                'Pending'=>'TIN',
429
-                'Payment Declined'=>'TIN',
430
-                'Incomplete'=>'TIN',
431
-                'Not Completed'=>'TIN',
432
-                'Cancelled'=>'TIN',
433
-                'Declined'=>'TIN'
434
-            );
435
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
436
-            $cols_n_values = array(
437
-                'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
438
-                'TXN_total'=>floatval($old_attendee['total_cost']),
439
-                'TXN_paid'=>floatval($old_attendee['amount_pd']),
440
-                'STS_ID'=>$STS_ID,
441
-                'TXN_hash_salt'=>$old_attendee['hashSalt']
442
-            );
443
-            $datatypes = array(
444
-                '%s',// TXN_timestamp
445
-                '%f',// TXN_total
446
-                '%f',// TXN_paid
447
-                '%s',// STS_ID
448
-                '%s',// TXN_hash_salt
449
-            );
450
-            $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
451
-            if (! $success) {
452
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
453
-                return 0;
454
-            }
455
-            $txn_id = $wpdb->insert_id;
456
-        }
403
+		// first: let's check for an existing transaction for this old attendee
404
+		if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
405
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
406
+		} else { // non-primary attendee, so find its primary attendee's transaction
407
+			$primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
408
+			if (! $primary_attendee_old_id) {
409
+				$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
410
+				$primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
411
+			}
412
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
413
+			if (! $txn_id) {
414
+				$this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
415
+				$txn_id = 0;
416
+			}
417
+		}
418
+		// if there isn't yet a transaction row for this, create one
419
+		// (so even if it was a non-primary attendee with no EE3 primary attendee,
420
+		// it ought to have SOME transaction, so we'll make one)
421
+		if (! $txn_id) {
422
+			// maps 3.1 payment stati onto 4.1 transaction stati
423
+			$txn_status_mapping = array(
424
+				'Completed'=>'TCM',
425
+				'Pending'=>'TIN',
426
+				'Payment Declined'=>'TIN',
427
+				'Incomplete'=>'TIN',
428
+				'Not Completed'=>'TIN',
429
+				'Cancelled'=>'TIN',
430
+				'Declined'=>'TIN'
431
+			);
432
+			$STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
433
+			$cols_n_values = array(
434
+				'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
435
+				'TXN_total'=>floatval($old_attendee['total_cost']),
436
+				'TXN_paid'=>floatval($old_attendee['amount_pd']),
437
+				'STS_ID'=>$STS_ID,
438
+				'TXN_hash_salt'=>$old_attendee['hashSalt']
439
+			);
440
+			$datatypes = array(
441
+				'%s',// TXN_timestamp
442
+				'%f',// TXN_total
443
+				'%f',// TXN_paid
444
+				'%s',// STS_ID
445
+				'%s',// TXN_hash_salt
446
+			);
447
+			$success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
448
+			if (! $success) {
449
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
450
+				return 0;
451
+			}
452
+			$txn_id = $wpdb->insert_id;
453
+		}
457 454
 
458
-        return $txn_id;
459
-    }
460
-    /**
461
-     * Detects if the MER tables exist
462
-     * @global type $wpdb
463
-     * @return boolean
464
-     */
465
-    private function _mer_tables_exist()
466
-    {
467
-        if ($this->_mer_tables_exist === null) {
468
-            global $wpdb;
455
+		return $txn_id;
456
+	}
457
+	/**
458
+	 * Detects if the MER tables exist
459
+	 * @global type $wpdb
460
+	 * @return boolean
461
+	 */
462
+	private function _mer_tables_exist()
463
+	{
464
+		if ($this->_mer_tables_exist === null) {
465
+			global $wpdb;
469 466
 
470
-            if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
471
-                $this->_mer_tables_exist = false;
472
-            } else {
473
-                $this->_mer_tables_exist = true;
474
-            }
475
-        }
476
-        return $this->_mer_tables_exist;
477
-    }
467
+			if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
468
+				$this->_mer_tables_exist = false;
469
+			} else {
470
+				$this->_mer_tables_exist = true;
471
+			}
472
+		}
473
+		return $this->_mer_tables_exist;
474
+	}
478 475
 
479
-    /**
480
-     * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
481
-     * whether the event required pre-approval or not,a dn the 4.1 payment status.
482
-     * @global type $wpdb
483
-     * @param type $old_attendee_row
484
-     * @return string
485
-     */
486
-    private function _get_reg_status_for_old_payment_status($old_attendee_row)
487
-    {
488
-        // need event default reg status and if pre_approval was required
489
-        global $wpdb;
490
-        $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id']));
491
-        return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
492
-            $old_attendee_row['payment_status'],
493
-            intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
494
-        );
495
-    }
496
-    /**
497
-     * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
498
-     * and returns an array of their IDs
499
-     * @global type $wpdb
500
-     * @param array $old_attendee
501
-     * @param int $new_attendee_id
502
-     * @param int $new_txn_id
503
-     * @return array of new registratio ids
504
-     */
505
-    private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
506
-    {
507
-        global $wpdb;
476
+	/**
477
+	 * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
478
+	 * whether the event required pre-approval or not,a dn the 4.1 payment status.
479
+	 * @global type $wpdb
480
+	 * @param type $old_attendee_row
481
+	 * @return string
482
+	 */
483
+	private function _get_reg_status_for_old_payment_status($old_attendee_row)
484
+	{
485
+		// need event default reg status and if pre_approval was required
486
+		global $wpdb;
487
+		$event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id']));
488
+		return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
489
+			$old_attendee_row['payment_status'],
490
+			intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
491
+		);
492
+	}
493
+	/**
494
+	 * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
495
+	 * and returns an array of their IDs
496
+	 * @global type $wpdb
497
+	 * @param array $old_attendee
498
+	 * @param int $new_attendee_id
499
+	 * @param int $new_txn_id
500
+	 * @return array of new registratio ids
501
+	 */
502
+	private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
503
+	{
504
+		global $wpdb;
508 505
 
509
-        $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
510
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
511
-        if (! $new_event_id) {
512
-            $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
513
-        }
506
+		$STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
507
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
508
+		if (! $new_event_id) {
509
+			$this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
510
+		}
514 511
 
515
-        $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
516
-        if (! $ticket_id) {
517
-            $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
518
-            $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id));
519
-        }
520
-        $regs_on_this_row = intval($old_attendee['quantity']);
521
-        $new_regs = array();
522
-        // 4 cases we need to account for:
523
-        // 1 old attendee_details row with a quantity of X (no mer)
524
-        // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
525
-        // Y old attendee_details rows with a quantity of x (because of mer)
526
-        // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
527
-        for ($count = 1; $count <= $regs_on_this_row; $count++) {
528
-            // sum regs on older rows
529
-            $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
530
-            $cols_n_values = array(
531
-                'EVT_ID'=>$new_event_id,
532
-                'ATT_ID'=>$new_attendee_id,
533
-                'TXN_ID'=>$new_txn_id,
534
-                'TKT_ID'=>$ticket_id,
535
-                'STS_ID'=>$STS_ID,
536
-                'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
537
-                'REG_final_price'=>$old_attendee['final_price'],
538
-                'REG_session'=> substr($old_attendee['attendee_session'], 0, 44),
539
-                'REG_code'=>sanitize_key($old_attendee['registration_id']),
540
-                'REG_url_link'=>  sanitize_key($old_attendee['registration_id'].'-'.$count),
541
-                'REG_count'=>$regs_on_this_event_and_txn + $count,
542
-                'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false),
543
-                'REG_att_is_going'=>true,
544
-                'REG_deleted'=>false
545
-            );
546
-            $datatypes = array(
547
-                '%d',// EVT_ID
548
-                '%d',// ATT_ID
549
-                '%d',// TXN_ID
550
-                '%d',// TKT_ID
551
-                '%s',// STS_ID
552
-                '%s',// REG_date
553
-                '%f',// REG_final_price
554
-                '%s',// REG_session
555
-                '%s',// REG_code
556
-                '%s',// REG_url_link
557
-                '%d',// REG_count
558
-                '%d',// REG_group_size
559
-                '%d',// REG_att_is_going
560
-                '%d',// REG_deleted
561
-            );
562
-            $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
563
-            if (! $success) {
564
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes));
565
-                return 0;
566
-            }
567
-            $cols_n_values['REG_ID'] = $wpdb->insert_id;
568
-            $new_regs[] = $wpdb->insert_id;
569
-        }
570
-        $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
571
-        return $new_regs;
572
-    }
512
+		$ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
513
+		if (! $ticket_id) {
514
+			$ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
515
+			$this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id));
516
+		}
517
+		$regs_on_this_row = intval($old_attendee['quantity']);
518
+		$new_regs = array();
519
+		// 4 cases we need to account for:
520
+		// 1 old attendee_details row with a quantity of X (no mer)
521
+		// Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
522
+		// Y old attendee_details rows with a quantity of x (because of mer)
523
+		// Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
524
+		for ($count = 1; $count <= $regs_on_this_row; $count++) {
525
+			// sum regs on older rows
526
+			$regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
527
+			$cols_n_values = array(
528
+				'EVT_ID'=>$new_event_id,
529
+				'ATT_ID'=>$new_attendee_id,
530
+				'TXN_ID'=>$new_txn_id,
531
+				'TKT_ID'=>$ticket_id,
532
+				'STS_ID'=>$STS_ID,
533
+				'REG_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
534
+				'REG_final_price'=>$old_attendee['final_price'],
535
+				'REG_session'=> substr($old_attendee['attendee_session'], 0, 44),
536
+				'REG_code'=>sanitize_key($old_attendee['registration_id']),
537
+				'REG_url_link'=>  sanitize_key($old_attendee['registration_id'].'-'.$count),
538
+				'REG_count'=>$regs_on_this_event_and_txn + $count,
539
+				'REG_group_size'=>$this->_sum_old_attendees_on_old_txn($old_attendee, false),
540
+				'REG_att_is_going'=>true,
541
+				'REG_deleted'=>false
542
+			);
543
+			$datatypes = array(
544
+				'%d',// EVT_ID
545
+				'%d',// ATT_ID
546
+				'%d',// TXN_ID
547
+				'%d',// TKT_ID
548
+				'%s',// STS_ID
549
+				'%s',// REG_date
550
+				'%f',// REG_final_price
551
+				'%s',// REG_session
552
+				'%s',// REG_code
553
+				'%s',// REG_url_link
554
+				'%d',// REG_count
555
+				'%d',// REG_group_size
556
+				'%d',// REG_att_is_going
557
+				'%d',// REG_deleted
558
+			);
559
+			$success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
560
+			if (! $success) {
561
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes));
562
+				return 0;
563
+			}
564
+			$cols_n_values['REG_ID'] = $wpdb->insert_id;
565
+			$new_regs[] = $wpdb->insert_id;
566
+		}
567
+		$this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
568
+		return $new_regs;
569
+	}
573 570
 
574
-    /**
575
-     * Increments the sold values on the ticket and its related datetimes by the amount sold,
576
-     * which should be done directly after adding the rows. Yes this means we're constantly incrementing
577
-     * the sold amounts as we go, and is less efficient than a single big query,
578
-     * but its safer because we KNOW these regs have been added, rather than inferring
579
-     * that they WILL be added (because the attendees stage runs nearly last during
580
-     * the migration script)
581
-     * @param type $new_ticket_id
582
-     * @param type $sold
583
-     * @param type $STS_ID
584
-     * @return boolean whether they were successfully updated or not
585
-     */
586
-    protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
587
-    {
588
-        if ($STS_ID != 'RAP') {
589
-            return true;
590
-        }
591
-        global $wpdb;
592
-        $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id));
593
-        if ($success) {
594
-            // get the ticket's datetimes, and increment them too
595
-            $success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
571
+	/**
572
+	 * Increments the sold values on the ticket and its related datetimes by the amount sold,
573
+	 * which should be done directly after adding the rows. Yes this means we're constantly incrementing
574
+	 * the sold amounts as we go, and is less efficient than a single big query,
575
+	 * but its safer because we KNOW these regs have been added, rather than inferring
576
+	 * that they WILL be added (because the attendees stage runs nearly last during
577
+	 * the migration script)
578
+	 * @param type $new_ticket_id
579
+	 * @param type $sold
580
+	 * @param type $STS_ID
581
+	 * @return boolean whether they were successfully updated or not
582
+	 */
583
+	protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
584
+	{
585
+		if ($STS_ID != 'RAP') {
586
+			return true;
587
+		}
588
+		global $wpdb;
589
+		$success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id));
590
+		if ($success) {
591
+			// get the ticket's datetimes, and increment them too
592
+			$success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
596 593
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
597 594
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
598 595
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
599
-            if (! $success_update_dateimtes) {
600
-                $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
601
-            }
602
-        } else {
603
-            $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
604
-        }
605
-        return true;
606
-    }
607
-    /**
608
-     * Makes a best guess at which ticket is the one the attendee purchased.
609
-     * Obviously, the old attendee's event_id narrows it down quite a bit;
610
-     * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
611
-     * however, if we don't find an exact match, see if any of those conditions match;
612
-     * and lastly if none of that works, just use the first ticket for the event we find
613
-     * @param array $old_attendee
614
-     */
615
-    private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
616
-    {
617
-        global $wpdb;
618
-        $tickets_table = $this->_new_ticket_table;
619
-        $datetime_tickets_table = $this->_new_ticket_datetime_table;
620
-        $datetime_table = $this->_new_datetime_table;
596
+			if (! $success_update_dateimtes) {
597
+				$this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
598
+			}
599
+		} else {
600
+			$this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
601
+		}
602
+		return true;
603
+	}
604
+	/**
605
+	 * Makes a best guess at which ticket is the one the attendee purchased.
606
+	 * Obviously, the old attendee's event_id narrows it down quite a bit;
607
+	 * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
608
+	 * however, if we don't find an exact match, see if any of those conditions match;
609
+	 * and lastly if none of that works, just use the first ticket for the event we find
610
+	 * @param array $old_attendee
611
+	 */
612
+	private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
613
+	{
614
+		global $wpdb;
615
+		$tickets_table = $this->_new_ticket_table;
616
+		$datetime_tickets_table = $this->_new_ticket_datetime_table;
617
+		$datetime_table = $this->_new_datetime_table;
621 618
 
622
-        $old_att_price_option = $old_attendee['price_option'];
623
-        $old_att_price = floatval($old_attendee['orig_price']);
619
+		$old_att_price_option = $old_attendee['price_option'];
620
+		$old_att_price = floatval($old_attendee['orig_price']);
624 621
 
625
-        $old_att_start_date = $old_attendee['start_date'];
626
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
627
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
628
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
629
-        // the most important condition should be last, as it will be array_shift'ed off last
630
-        $conditions = array(
631
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
632
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
633
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
634
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
635
-        );
636
-        $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
622
+		$old_att_start_date = $old_attendee['start_date'];
623
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
624
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
625
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
626
+		// the most important condition should be last, as it will be array_shift'ed off last
627
+		$conditions = array(
628
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
629
+			$wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
630
+			$wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
631
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
632
+		);
633
+		$select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
637 634
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
638 635
 			$datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID";
639
-        // start running queries, widening search each time by removing a condition
640
-        do {
641
-            $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
642
-            $ticket_id_found = $wpdb->get_var($full_query);
643
-            array_shift($conditions);
644
-        } while (! $ticket_id_found && $conditions);
645
-        return $ticket_id_found;
646
-    }
636
+		// start running queries, widening search each time by removing a condition
637
+		do {
638
+			$full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
639
+			$ticket_id_found = $wpdb->get_var($full_query);
640
+			array_shift($conditions);
641
+		} while (! $ticket_id_found && $conditions);
642
+		return $ticket_id_found;
643
+	}
647 644
 
648
-    /**
649
-     * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
650
-     * and it also tries to find a datetime that works, and a inserts a price, and associates
651
-     * the new ticket to that datetime and price.
652
-     * @return int ticket id
653
-     */
654
-    private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
655
-    {
656
-        global $wpdb;
657
-        $old_att_price_option = $old_attendee['price_option'];
658
-        $old_att_price = floatval($old_attendee['orig_price']);
645
+	/**
646
+	 * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
647
+	 * and it also tries to find a datetime that works, and a inserts a price, and associates
648
+	 * the new ticket to that datetime and price.
649
+	 * @return int ticket id
650
+	 */
651
+	private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
652
+	{
653
+		global $wpdb;
654
+		$old_att_price_option = $old_attendee['price_option'];
655
+		$old_att_price = floatval($old_attendee['orig_price']);
659 656
 
660
-        $old_att_start_date = $old_attendee['start_date'];
661
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
662
-        $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
657
+		$old_att_start_date = $old_attendee['start_date'];
658
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
659
+		$old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
663 660
 
664 661
 
665
-        // insert new datetime unless we find one
666
-        $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
667
-        if (! $datetime_id) {
668
-            $old_att_end_date = $old_attendee['start_date'];
669
-            $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
670
-            $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00");
671
-            $wpdb->insert(
672
-                $this->_new_datetime_table,
673
-                array(
674
-                        'EVT_ID' => $new_event_id,
675
-                        'DTT_EVT_start' => $old_att_start_datetime,
676
-                        'DTT_EVT_end' => $old_att_end_datetime,
677
-                        'DTT_deleted' => true
678
-                    ),
679
-                array(
680
-                        '%d',// EVT_ID
681
-                        '%s',// DTT_EVT_start
682
-                        '%s',// DTT_EVT_end
683
-                        '%d',// DTT_deleted
684
-                    )
685
-            );
686
-            $datetime_id = $wpdb->insert_id;
687
-        }
662
+		// insert new datetime unless we find one
663
+		$datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
664
+		if (! $datetime_id) {
665
+			$old_att_end_date = $old_attendee['start_date'];
666
+			$old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
667
+			$old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00");
668
+			$wpdb->insert(
669
+				$this->_new_datetime_table,
670
+				array(
671
+						'EVT_ID' => $new_event_id,
672
+						'DTT_EVT_start' => $old_att_start_datetime,
673
+						'DTT_EVT_end' => $old_att_end_datetime,
674
+						'DTT_deleted' => true
675
+					),
676
+				array(
677
+						'%d',// EVT_ID
678
+						'%s',// DTT_EVT_start
679
+						'%s',// DTT_EVT_end
680
+						'%d',// DTT_deleted
681
+					)
682
+			);
683
+			$datetime_id = $wpdb->insert_id;
684
+		}
688 685
 
689
-        // insert new ticket
690
-        $success = $wpdb->insert(
691
-            $wpdb->prefix . 'esp_ticket',
692
-            array(
693
-                    'TKT_name' => $old_att_price_option,
694
-                    'TKT_qty' => -1,
695
-                    'TKT_price' => $old_att_price,
696
-                    'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended
697
-                    'TKT_end_date' => $old_att_end_datetime,
686
+		// insert new ticket
687
+		$success = $wpdb->insert(
688
+			$wpdb->prefix . 'esp_ticket',
689
+			array(
690
+					'TKT_name' => $old_att_price_option,
691
+					'TKT_qty' => -1,
692
+					'TKT_price' => $old_att_price,
693
+					'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended
694
+					'TKT_end_date' => $old_att_end_datetime,
698 695
 
699
-                ),
700
-            array(
701
-                    '%s',// name
702
-                    '%d',// qty
703
-                    '%d',// price
704
-                    '%s',// start_date
705
-                    '%s',// end_date
706
-                )
707
-        );
708
-        $ticket_id = $wpdb->insert_id;
709
-        // associate the ticket with the datetime we found earlier
710
-        $wpdb->insert(
711
-            $this->_new_datetime_ticket_table,
712
-            array(
713
-                    'DTT_ID' => $datetime_id,
714
-                    'TKT_ID' => $ticket_id
715
-                ),
716
-            array(
717
-                    '%d',// DTT_ID
718
-                    '%d',// TKT_ID
719
-                )
720
-        );
721
-        // insert new price
722
-        $wpdb->insert(
723
-            $this->_new_price_table,
724
-            array(
725
-                    'PRC_amount' => $old_att_price,
726
-                    'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
727
-                    'PRC_name' => $old_att_price_option,
728
-                    'PRC_deleted' => true
729
-                ),
730
-            array(
731
-                    '%d',// PRC_amount
732
-                    '%d',// PRT_ID
733
-                    '%s',// PRC_name
734
-                    '%d',// PRC_deleted
735
-                )
736
-        );
737
-        $price_id = $wpdb->insert_id;
738
-        // associate the price to the ticket
739
-        $wpdb->insert(
740
-            $this->_new_ticket_price_table,
741
-            array(
742
-                    'TKT_ID' => $ticket_id,
743
-                    'PRC_ID' => $price_id
744
-                ),
745
-            array(
746
-                    '%d',// TKT_ID
747
-                    '%d',// PRC_ID
748
-                )
749
-        );
750
-        return $ticket_id;
751
-    }
752
-    /**
753
-     * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
754
-     * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
755
-     * @global type $wpdb
756
-     * @param array $old_attendee_row
757
-     * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL
758
-     * @return int
759
-     */
760
-    private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
761
-    {
762
-        global $wpdb;
763
-        $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
764
-        $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id'])));
696
+				),
697
+			array(
698
+					'%s',// name
699
+					'%d',// qty
700
+					'%d',// price
701
+					'%s',// start_date
702
+					'%s',// end_date
703
+				)
704
+		);
705
+		$ticket_id = $wpdb->insert_id;
706
+		// associate the ticket with the datetime we found earlier
707
+		$wpdb->insert(
708
+			$this->_new_datetime_ticket_table,
709
+			array(
710
+					'DTT_ID' => $datetime_id,
711
+					'TKT_ID' => $ticket_id
712
+				),
713
+			array(
714
+					'%d',// DTT_ID
715
+					'%d',// TKT_ID
716
+				)
717
+		);
718
+		// insert new price
719
+		$wpdb->insert(
720
+			$this->_new_price_table,
721
+			array(
722
+					'PRC_amount' => $old_att_price,
723
+					'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
724
+					'PRC_name' => $old_att_price_option,
725
+					'PRC_deleted' => true
726
+				),
727
+			array(
728
+					'%d',// PRC_amount
729
+					'%d',// PRT_ID
730
+					'%s',// PRC_name
731
+					'%d',// PRC_deleted
732
+				)
733
+		);
734
+		$price_id = $wpdb->insert_id;
735
+		// associate the price to the ticket
736
+		$wpdb->insert(
737
+			$this->_new_ticket_price_table,
738
+			array(
739
+					'TKT_ID' => $ticket_id,
740
+					'PRC_ID' => $price_id
741
+				),
742
+			array(
743
+					'%d',// TKT_ID
744
+					'%d',// PRC_ID
745
+				)
746
+		);
747
+		return $ticket_id;
748
+	}
749
+	/**
750
+	 * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
751
+	 * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
752
+	 * @global type $wpdb
753
+	 * @param array $old_attendee_row
754
+	 * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL
755
+	 * @return int
756
+	 */
757
+	private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
758
+	{
759
+		global $wpdb;
760
+		$count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
761
+		$count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id'])));
765 762
 
766
-        if ($this->_mer_tables_exist()) {
767
-            // if MER exists, then its a little tricky.
768
-            // when users registered by adding items to the cart, and it was a
769
-            // group registration requiring additional attendee INFO, then the attendee rows
770
-            // DO NOT have the same registration_id (although they probably should have)
771
-            // they are related just like MER attendee rows are related, through the MER group table
772
-            // BUT we want to count all the MER attendee rows for the same registration
773
-            $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
763
+		if ($this->_mer_tables_exist()) {
764
+			// if MER exists, then its a little tricky.
765
+			// when users registered by adding items to the cart, and it was a
766
+			// group registration requiring additional attendee INFO, then the attendee rows
767
+			// DO NOT have the same registration_id (although they probably should have)
768
+			// they are related just like MER attendee rows are related, through the MER group table
769
+			// BUT we want to count all the MER attendee rows for the same registration
770
+			$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
774 771
 
775
-            $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id']));
776
-            $count = max($count_using_mer_table, $count);
777
-        }
778
-        return $count;
779
-    }
780
-    private function _insert_new_payment($old_attendee, $new_txn_id)
781
-    {
782
-        global $wpdb;
783
-        // only add a payment for primary attendees
784
-        $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
785
-        // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
786
-        if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
787
-            $pay_status_mapping = array(
788
-                'Completed'=>'PAP',
789
-                'Payment Declined'=>'PDC',
790
-                'Cancelled'=>'PCN',
791
-                'Declined'=>'PDC'
792
-            );
793
-            $by_admin = $old_attendee['payment'] == 'Admin';
794
-            $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed
795
-            $cols_n_values = array(
796
-                'TXN_ID'=>$new_txn_id,
797
-                'STS_ID'=>$STS_ID,
798
-                'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
799
-                'PAY_method'=>'CART',
800
-                'PAY_amount'=>$old_attendee['amount_pd'],
801
-                'PAY_gateway'=>$old_attendee['txn_type'],
802
-                'PAY_gateway_response'=>'',
803
-                'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32),
804
-                'PAY_via_admin'=>$by_admin,
805
-                'PAY_details'=>$old_attendee['transaction_details']
772
+			$count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id']));
773
+			$count = max($count_using_mer_table, $count);
774
+		}
775
+		return $count;
776
+	}
777
+	private function _insert_new_payment($old_attendee, $new_txn_id)
778
+	{
779
+		global $wpdb;
780
+		// only add a payment for primary attendees
781
+		$old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
782
+		// if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
783
+		if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
784
+			$pay_status_mapping = array(
785
+				'Completed'=>'PAP',
786
+				'Payment Declined'=>'PDC',
787
+				'Cancelled'=>'PCN',
788
+				'Declined'=>'PDC'
789
+			);
790
+			$by_admin = $old_attendee['payment'] == 'Admin';
791
+			$STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed
792
+			$cols_n_values = array(
793
+				'TXN_ID'=>$new_txn_id,
794
+				'STS_ID'=>$STS_ID,
795
+				'PAY_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
796
+				'PAY_method'=>'CART',
797
+				'PAY_amount'=>$old_attendee['amount_pd'],
798
+				'PAY_gateway'=>$old_attendee['txn_type'],
799
+				'PAY_gateway_response'=>'',
800
+				'PAY_txn_id_chq_nmbr'=>substr($old_attendee['txn_id'], 0, 32),
801
+				'PAY_via_admin'=>$by_admin,
802
+				'PAY_details'=>$old_attendee['transaction_details']
806 803
 
807
-            );
808
-            $datatypes = array(
809
-                '%d',// TXN_Id
810
-                '%s',// STS_ID
811
-                '%s',// PAY_timestamp
812
-                '%s',// PAY_method
813
-                '%f',// PAY_amount
814
-                '%s',// PAY_gateway
815
-                '%s',// PAY_gateway_response
816
-                '%s',// PAY_txn_id_chq_nmbr
817
-                '%d',// PAY_via_admin
818
-                '%s',// PAY_details
819
-            );
820
-            $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
821
-            if (! $success) {
822
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
823
-                return 0;
824
-            }
825
-            $new_id = $wpdb->insert_id;
826
-            return $new_id;
827
-        } else {
828
-            return 0;
829
-        }
830
-    }
804
+			);
805
+			$datatypes = array(
806
+				'%d',// TXN_Id
807
+				'%s',// STS_ID
808
+				'%s',// PAY_timestamp
809
+				'%s',// PAY_method
810
+				'%f',// PAY_amount
811
+				'%s',// PAY_gateway
812
+				'%s',// PAY_gateway_response
813
+				'%s',// PAY_txn_id_chq_nmbr
814
+				'%d',// PAY_via_admin
815
+				'%s',// PAY_details
816
+			);
817
+			$success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
818
+			if (! $success) {
819
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
820
+				return 0;
821
+			}
822
+			$new_id = $wpdb->insert_id;
823
+			return $new_id;
824
+		} else {
825
+			return 0;
826
+		}
827
+	}
831 828
 
832
-    /**
833
-     * If MER is active, if you want ot fin dthe other registrations on that attendee row
834
-     * @global type $wpdb
835
-     * @param type $old_registration_id
836
-     * @return array
837
-     */
838
-    private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
839
-    {
840
-        if (! $this->_mer_tables_exist()) {
841
-            return false;
842
-        }
843
-        global $wpdb;
844
-        $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A);
845
-        return $old_att_for_primary_reg;
846
-    }
829
+	/**
830
+	 * If MER is active, if you want ot fin dthe other registrations on that attendee row
831
+	 * @global type $wpdb
832
+	 * @param type $old_registration_id
833
+	 * @return array
834
+	 */
835
+	private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
836
+	{
837
+		if (! $this->_mer_tables_exist()) {
838
+			return false;
839
+		}
840
+		global $wpdb;
841
+		$old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A);
842
+		return $old_att_for_primary_reg;
843
+	}
847 844
 }
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
     {
261 261
         // first check if there's already a new attendee with similar characteristics
262 262
         $new_att_id = $this->_find_attendee_cpt_matching($old_row);
263
-        if (! $new_att_id) {
263
+        if ( ! $new_att_id) {
264 264
             $new_att_id = $this->_insert_new_attendee_cpt($old_row);
265
-            if (! $new_att_id) {
265
+            if ( ! $new_att_id) {
266 266
                 // if we couldnt even make an attendee, abandon all hope
267 267
                 return false;
268 268
             }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
         $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
275 275
 
276 276
         $txn_id = $this->_insert_new_transaction($old_row);
277
-        if (! $txn_id) {
277
+        if ( ! $txn_id) {
278 278
             // if we couldnt make the transaction, also abandon all hope
279 279
             return false;
280 280
         }
@@ -308,31 +308,31 @@  discard block
 block discarded – undo
308 308
     {
309 309
         global $wpdb;
310 310
         $cols_n_values = array(
311
-            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']),// ATT_full_name
312
-            'post_content'=>'',// ATT_bio
313
-            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']),// ATT_slug
314
-            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
315
-            'post_excerpt'=>'',// ATT_short_bio
316
-            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
317
-            'post_author'=>0,// ATT_author
318
-            'post_parent'=>0,// ATT_parent
319
-            'post_type'=>'espresso_attendees',// post_type
311
+            'post_title'=>stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name
312
+            'post_content'=>'', // ATT_bio
313
+            'post_name'=>sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug
314
+            'post_date'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created
315
+            'post_excerpt'=>'', // ATT_short_bio
316
+            'post_modified'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified
317
+            'post_author'=>0, // ATT_author
318
+            'post_parent'=>0, // ATT_parent
319
+            'post_type'=>'espresso_attendees', // post_type
320 320
             'post_status'=>'publish'// status
321 321
         );
322 322
         $datatypes = array(
323
-            '%s',// ATT_full_name
324
-            '%s',// ATT_bio
325
-            '%s',// ATT_slug
326
-            '%s',// ATT_created
327
-            '%s',// ATT_short_bio
328
-            '%s',// ATT_modified
329
-            '%d',// ATT_author
330
-            '%d',// ATT_parent
331
-            '%s',// post_type
332
-            '%s',// status
323
+            '%s', // ATT_full_name
324
+            '%s', // ATT_bio
325
+            '%s', // ATT_slug
326
+            '%s', // ATT_created
327
+            '%s', // ATT_short_bio
328
+            '%s', // ATT_modified
329
+            '%d', // ATT_author
330
+            '%d', // ATT_parent
331
+            '%s', // post_type
332
+            '%s', // status
333 333
         );
334 334
         $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
335
-        if (! $success) {
335
+        if ( ! $success) {
336 336
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
337 337
             return 0;
338 338
         }
@@ -370,20 +370,20 @@  discard block
 block discarded – undo
370 370
             'ATT_phone'=>stripslashes($old_attendee['phone']),
371 371
         );
372 372
         $datatypes = array(
373
-            '%d',// ATT_ID
374
-            '%s',// ATT_fname
375
-            '%s',// ATT_lname
376
-            '%s',// ATT_address
377
-            '%s',// ATT_address2
378
-            '%s',// ATT_city
379
-            '%d',// STA_ID
380
-            '%s',// CNT_ISO
381
-            '%s',// ATT_zip
382
-            '%s',// ATT_email
383
-            '%s',// ATT_phone
373
+            '%d', // ATT_ID
374
+            '%s', // ATT_fname
375
+            '%s', // ATT_lname
376
+            '%s', // ATT_address
377
+            '%s', // ATT_address2
378
+            '%s', // ATT_city
379
+            '%d', // STA_ID
380
+            '%s', // CNT_ISO
381
+            '%s', // ATT_zip
382
+            '%s', // ATT_email
383
+            '%s', // ATT_phone
384 384
         );
385 385
         $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
386
-        if (! $success) {
386
+        if ( ! $success) {
387 387
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes));
388 388
             return 0;
389 389
         }
@@ -408,12 +408,12 @@  discard block
 block discarded – undo
408 408
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
409 409
         } else { // non-primary attendee, so find its primary attendee's transaction
410 410
             $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id']));
411
-            if (! $primary_attendee_old_id) {
411
+            if ( ! $primary_attendee_old_id) {
412 412
                 $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
413 413
                 $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
414 414
             }
415 415
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
416
-            if (! $txn_id) {
416
+            if ( ! $txn_id) {
417 417
                 $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id));
418 418
                 $txn_id = 0;
419 419
             }
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         // if there isn't yet a transaction row for this, create one
422 422
         // (so even if it was a non-primary attendee with no EE3 primary attendee,
423 423
         // it ought to have SOME transaction, so we'll make one)
424
-        if (! $txn_id) {
424
+        if ( ! $txn_id) {
425 425
             // maps 3.1 payment stati onto 4.1 transaction stati
426 426
             $txn_status_mapping = array(
427 427
                 'Completed'=>'TCM',
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
                 'Cancelled'=>'TIN',
433 433
                 'Declined'=>'TIN'
434 434
             );
435
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
435
+            $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN';
436 436
             $cols_n_values = array(
437 437
                 'TXN_timestamp'=>$this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
438 438
                 'TXN_total'=>floatval($old_attendee['total_cost']),
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
                 'TXN_hash_salt'=>$old_attendee['hashSalt']
442 442
             );
443 443
             $datatypes = array(
444
-                '%s',// TXN_timestamp
445
-                '%f',// TXN_total
446
-                '%f',// TXN_paid
447
-                '%s',// STS_ID
448
-                '%s',// TXN_hash_salt
444
+                '%s', // TXN_timestamp
445
+                '%f', // TXN_total
446
+                '%f', // TXN_paid
447
+                '%s', // STS_ID
448
+                '%s', // TXN_hash_salt
449 449
             );
450 450
             $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
451
-            if (! $success) {
451
+            if ( ! $success) {
452 452
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes));
453 453
                 return 0;
454 454
             }
@@ -508,12 +508,12 @@  discard block
 block discarded – undo
508 508
 
509 509
         $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
510 510
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
511
-        if (! $new_event_id) {
511
+        if ( ! $new_event_id) {
512 512
             $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
513 513
         }
514 514
 
515 515
         $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
516
-        if (! $ticket_id) {
516
+        if ( ! $ticket_id) {
517 517
             $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
518 518
             $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id));
519 519
         }
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
                 'REG_deleted'=>false
545 545
             );
546 546
             $datatypes = array(
547
-                '%d',// EVT_ID
548
-                '%d',// ATT_ID
549
-                '%d',// TXN_ID
550
-                '%d',// TKT_ID
551
-                '%s',// STS_ID
552
-                '%s',// REG_date
553
-                '%f',// REG_final_price
554
-                '%s',// REG_session
555
-                '%s',// REG_code
556
-                '%s',// REG_url_link
557
-                '%d',// REG_count
558
-                '%d',// REG_group_size
559
-                '%d',// REG_att_is_going
560
-                '%d',// REG_deleted
547
+                '%d', // EVT_ID
548
+                '%d', // ATT_ID
549
+                '%d', // TXN_ID
550
+                '%d', // TKT_ID
551
+                '%s', // STS_ID
552
+                '%s', // REG_date
553
+                '%f', // REG_final_price
554
+                '%s', // REG_session
555
+                '%s', // REG_code
556
+                '%s', // REG_url_link
557
+                '%d', // REG_count
558
+                '%d', // REG_group_size
559
+                '%d', // REG_att_is_going
560
+                '%d', // REG_deleted
561 561
             );
562 562
             $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
563
-            if (! $success) {
563
+            if ( ! $success) {
564 564
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes));
565 565
                 return 0;
566 566
             }
@@ -592,11 +592,11 @@  discard block
 block discarded – undo
592 592
         $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id));
593 593
         if ($success) {
594 594
             // get the ticket's datetimes, and increment them too
595
-            $success_update_dateimtes =  $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
595
+            $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
596 596
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
597 597
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
598 598
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
599
-            if (! $success_update_dateimtes) {
599
+            if ( ! $success_update_dateimtes) {
600 600
                 $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
601 601
             }
602 602
         } else {
@@ -628,10 +628,10 @@  discard block
 block discarded – undo
628 628
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
629 629
         // the most important condition should be last, as it will be array_shift'ed off last
630 630
         $conditions = array(
631
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
632
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
633
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
634
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
631
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
632
+            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match?
633
+            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match?
634
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
635 635
         );
636 636
         $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
637 637
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
             $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
642 642
             $ticket_id_found = $wpdb->get_var($full_query);
643 643
             array_shift($conditions);
644
-        } while (! $ticket_id_found && $conditions);
644
+        }while ( ! $ticket_id_found && $conditions);
645 645
         return $ticket_id_found;
646 646
     }
647 647
 
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
 
664 664
 
665 665
         // insert new datetime unless we find one
666
-        $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
667
-        if (! $datetime_id) {
666
+        $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM ".$this->_new_datetime_table." WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A);
667
+        if ( ! $datetime_id) {
668 668
             $old_att_end_date = $old_attendee['start_date'];
669 669
             $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
670 670
             $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00");
@@ -677,10 +677,10 @@  discard block
 block discarded – undo
677 677
                         'DTT_deleted' => true
678 678
                     ),
679 679
                 array(
680
-                        '%d',// EVT_ID
681
-                        '%s',// DTT_EVT_start
682
-                        '%s',// DTT_EVT_end
683
-                        '%d',// DTT_deleted
680
+                        '%d', // EVT_ID
681
+                        '%s', // DTT_EVT_start
682
+                        '%s', // DTT_EVT_end
683
+                        '%d', // DTT_deleted
684 684
                     )
685 685
             );
686 686
             $datetime_id = $wpdb->insert_id;
@@ -688,21 +688,21 @@  discard block
 block discarded – undo
688 688
 
689 689
         // insert new ticket
690 690
         $success = $wpdb->insert(
691
-            $wpdb->prefix . 'esp_ticket',
691
+            $wpdb->prefix.'esp_ticket',
692 692
             array(
693 693
                     'TKT_name' => $old_att_price_option,
694 694
                     'TKT_qty' => -1,
695 695
                     'TKT_price' => $old_att_price,
696
-                    'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended
696
+                    'TKT_start_date' => $old_att_start_datetime, // we really have no clue what the time should be, but at least it was available when they attended
697 697
                     'TKT_end_date' => $old_att_end_datetime,
698 698
 
699 699
                 ),
700 700
             array(
701
-                    '%s',// name
702
-                    '%d',// qty
703
-                    '%d',// price
704
-                    '%s',// start_date
705
-                    '%s',// end_date
701
+                    '%s', // name
702
+                    '%d', // qty
703
+                    '%d', // price
704
+                    '%s', // start_date
705
+                    '%s', // end_date
706 706
                 )
707 707
         );
708 708
         $ticket_id = $wpdb->insert_id;
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
                     'TKT_ID' => $ticket_id
715 715
                 ),
716 716
             array(
717
-                    '%d',// DTT_ID
718
-                    '%d',// TKT_ID
717
+                    '%d', // DTT_ID
718
+                    '%d', // TKT_ID
719 719
                 )
720 720
         );
721 721
         // insert new price
@@ -728,10 +728,10 @@  discard block
 block discarded – undo
728 728
                     'PRC_deleted' => true
729 729
                 ),
730 730
             array(
731
-                    '%d',// PRC_amount
732
-                    '%d',// PRT_ID
733
-                    '%s',// PRC_name
734
-                    '%d',// PRC_deleted
731
+                    '%d', // PRC_amount
732
+                    '%d', // PRT_ID
733
+                    '%s', // PRC_name
734
+                    '%d', // PRC_deleted
735 735
                 )
736 736
         );
737 737
         $price_id = $wpdb->insert_id;
@@ -743,8 +743,8 @@  discard block
 block discarded – undo
743 743
                     'PRC_ID' => $price_id
744 744
                 ),
745 745
             array(
746
-                    '%d',// TKT_ID
747
-                    '%d',// PRC_ID
746
+                    '%d', // TKT_ID
747
+                    '%d', // PRC_ID
748 748
                 )
749 749
         );
750 750
         return $ticket_id;
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
     {
782 782
         global $wpdb;
783 783
         // only add a payment for primary attendees
784
-        $old_pay_stati_indicating_no_payment = array('Pending','Incomplete','Not Completed');
784
+        $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed');
785 785
         // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
786 786
         if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
787 787
             $pay_status_mapping = array(
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
                 'Declined'=>'PDC'
792 792
             );
793 793
             $by_admin = $old_attendee['payment'] == 'Admin';
794
-            $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed
794
+            $STS_ID = isset($pay_status_mapping[$old_attendee['payment_status']]) ? $pay_status_mapping[$old_attendee['payment_status']] : 'PFL'; // IE, if we don't recognize the status, assume payment failed
795 795
             $cols_n_values = array(
796 796
                 'TXN_ID'=>$new_txn_id,
797 797
                 'STS_ID'=>$STS_ID,
@@ -806,19 +806,19 @@  discard block
 block discarded – undo
806 806
 
807 807
             );
808 808
             $datatypes = array(
809
-                '%d',// TXN_Id
810
-                '%s',// STS_ID
811
-                '%s',// PAY_timestamp
812
-                '%s',// PAY_method
813
-                '%f',// PAY_amount
814
-                '%s',// PAY_gateway
815
-                '%s',// PAY_gateway_response
816
-                '%s',// PAY_txn_id_chq_nmbr
817
-                '%d',// PAY_via_admin
818
-                '%s',// PAY_details
809
+                '%d', // TXN_Id
810
+                '%s', // STS_ID
811
+                '%s', // PAY_timestamp
812
+                '%s', // PAY_method
813
+                '%f', // PAY_amount
814
+                '%s', // PAY_gateway
815
+                '%s', // PAY_gateway_response
816
+                '%s', // PAY_txn_id_chq_nmbr
817
+                '%d', // PAY_via_admin
818
+                '%s', // PAY_details
819 819
             );
820 820
             $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
821
-            if (! $success) {
821
+            if ( ! $success) {
822 822
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes));
823 823
                 return 0;
824 824
             }
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
      */
838 838
     private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
839 839
     {
840
-        if (! $this->_mer_tables_exist()) {
840
+        if ( ! $this->_mer_tables_exist()) {
841 841
             return false;
842 842
         }
843 843
         global $wpdb;
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_checkins.dmsstage.php 3 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * (because we know the attendee was for an event as a specific time, and we know
86 86
      * the event's OLD ID...)
87 87
      * @global type $wpdb
88
-     * @param array $old_attendee_row
88
+     * @param array $old_attendee
89 89
      * @return array row of datetime from DB
90 90
      */
91 91
     private function _try_to_find_datetime($old_attendee)
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
     /**
122 122
      * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
123 123
      * @param int $new_reg_id
124
-     * @param int $new_datetime_id
125
-     * @param string $timestamp mysql datetime
124
+     * @param int $new_datetime
126 125
      * @return int new Check-in id
127 126
      */
128 127
     private function _insert_checkin_record($new_reg_id, $new_datetime)
Please login to merge, or discard this patch.
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -26,129 +26,129 @@
 block discarded – undo
26 26
 
27 27
 class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table
28 28
 {
29
-    private $_new_table;
30
-    public function __construct()
31
-    {
32
-        global $wpdb;
33
-        $this->_pretty_name = __("Checkins", "event_espresso");
34
-        $this->_old_table = $wpdb->prefix."events_attendee";
35
-        $this->_new_table = $wpdb->prefix."esp_checkin";
36
-        parent::__construct();
37
-    }
38
-    protected function _migrate_old_row($old_row)
39
-    {
40
-        global $wpdb;
41
-        $new_reg_table = $wpdb->prefix."esp_registration";
29
+	private $_new_table;
30
+	public function __construct()
31
+	{
32
+		global $wpdb;
33
+		$this->_pretty_name = __("Checkins", "event_espresso");
34
+		$this->_old_table = $wpdb->prefix."events_attendee";
35
+		$this->_new_table = $wpdb->prefix."esp_checkin";
36
+		parent::__construct();
37
+	}
38
+	protected function _migrate_old_row($old_row)
39
+	{
40
+		global $wpdb;
41
+		$new_reg_table = $wpdb->prefix."esp_registration";
42 42
 
43
-        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
43
+		$num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
44 44
 
45
-        $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
46
-        if (! $new_registrations_for_attendee) {
47
-            $new_registrations_for_attendee = array();
48
-        }
49
-        $new_datetime = $this->_try_to_find_datetime($old_row);
45
+		$new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
46
+		if (! $new_registrations_for_attendee) {
47
+			$new_registrations_for_attendee = array();
48
+		}
49
+		$new_datetime = $this->_try_to_find_datetime($old_row);
50 50
 
51
-        // make sure registrations array is numerically indexed starting at 0 (it probably already is)
52
-        $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
53
-        $new_checkin_ids = array();
54
-        for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
55
-            $new_reg_id = $new_registrations_for_attendee[ $i ];
56
-            if (! $new_reg_id) {
57
-                $this->add_error(sprintf(
58
-                    __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"),
59
-                    $this->_json_encode($old_row),
60
-                    abs($num_to_checkin_at_this_time),
61
-                    count($new_registrations_for_attendee),
62
-                    $this->_json_encode($new_registrations_for_attendee)
63
-                ));
64
-                break;
65
-            }
66
-            $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id));
67
-            if (! $new_last_checkin_record) {
68
-                $is_checked_in = false;
69
-            } else {
70
-                $is_checked_in = intval($new_last_checkin_record['CHK_in']);
71
-            }
72
-            $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
73
-            if ($new_id) {
74
-                $new_checkin_ids[]= $new_id;
75
-            }
76
-        }
77
-        if ($new_checkin_ids) {
78
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_table, $new_checkin_ids);
79
-        }
80
-    }
51
+		// make sure registrations array is numerically indexed starting at 0 (it probably already is)
52
+		$new_registrations_for_attendee = array_values($new_registrations_for_attendee);
53
+		$new_checkin_ids = array();
54
+		for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
55
+			$new_reg_id = $new_registrations_for_attendee[ $i ];
56
+			if (! $new_reg_id) {
57
+				$this->add_error(sprintf(
58
+					__('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"),
59
+					$this->_json_encode($old_row),
60
+					abs($num_to_checkin_at_this_time),
61
+					count($new_registrations_for_attendee),
62
+					$this->_json_encode($new_registrations_for_attendee)
63
+				));
64
+				break;
65
+			}
66
+			$new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id));
67
+			if (! $new_last_checkin_record) {
68
+				$is_checked_in = false;
69
+			} else {
70
+				$is_checked_in = intval($new_last_checkin_record['CHK_in']);
71
+			}
72
+			$new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
73
+			if ($new_id) {
74
+				$new_checkin_ids[]= $new_id;
75
+			}
76
+		}
77
+		if ($new_checkin_ids) {
78
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_table, $new_checkin_ids);
79
+		}
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Tries to find the new datetime the Check-in was for, based on the attendee row
85
-     * (because we know the attendee was for an event as a specific time, and we know
86
-     * the event's OLD ID...)
87
-     * @global type $wpdb
88
-     * @param array $old_attendee_row
89
-     * @return array row of datetime from DB
90
-     */
91
-    private function _try_to_find_datetime($old_attendee)
92
-    {
93
-        global $wpdb;
83
+	/**
84
+	 * Tries to find the new datetime the Check-in was for, based on the attendee row
85
+	 * (because we know the attendee was for an event as a specific time, and we know
86
+	 * the event's OLD ID...)
87
+	 * @global type $wpdb
88
+	 * @param array $old_attendee_row
89
+	 * @return array row of datetime from DB
90
+	 */
91
+	private function _try_to_find_datetime($old_attendee)
92
+	{
93
+		global $wpdb;
94 94
 
95
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
96
-        if (! $new_event_id) {
97
-            $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
98
-            return 0;
99
-        }
100
-        $old_att_start_date = $old_attendee['start_date'];
101
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
102
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
95
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
96
+		if (! $new_event_id) {
97
+			$this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
98
+			return 0;
99
+		}
100
+		$old_att_start_date = $old_attendee['start_date'];
101
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
102
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
103 103
 
104
-        $datetime_table = $wpdb->prefix."esp_datetime";
105
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
106
-        // the most important condition should be last, as it will be array_shift'ed off last
107
-        $conditions = array(
108
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
109
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
110
-        );
111
-        // start running queries, widening search each time by removing a condition
112
-        $datetime_found = null;
113
-        do {
114
-            $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
115
-            $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
116
-            array_shift($conditions);
117
-        } while (! $datetime_found && $conditions);
118
-        return $datetime_found;
119
-    }
104
+		$datetime_table = $wpdb->prefix."esp_datetime";
105
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
106
+		// the most important condition should be last, as it will be array_shift'ed off last
107
+		$conditions = array(
108
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
109
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
110
+		);
111
+		// start running queries, widening search each time by removing a condition
112
+		$datetime_found = null;
113
+		do {
114
+			$full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
115
+			$datetime_found = $wpdb->get_row($full_query, ARRAY_A);
116
+			array_shift($conditions);
117
+		} while (! $datetime_found && $conditions);
118
+		return $datetime_found;
119
+	}
120 120
 
121
-    /**
122
-     * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
123
-     * @param int $new_reg_id
124
-     * @param int $new_datetime_id
125
-     * @param string $timestamp mysql datetime
126
-     * @return int new Check-in id
127
-     */
128
-    private function _insert_checkin_record($new_reg_id, $new_datetime)
129
-    {
130
-        global $wpdb;
121
+	/**
122
+	 * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap
123
+	 * @param int $new_reg_id
124
+	 * @param int $new_datetime_id
125
+	 * @param string $timestamp mysql datetime
126
+	 * @return int new Check-in id
127
+	 */
128
+	private function _insert_checkin_record($new_reg_id, $new_datetime)
129
+	{
130
+		global $wpdb;
131 131
 
132 132
 
133
-        // ok we can actually do what we set out to do: add a checkin/checkout record
134
-        $cols_n_values = array(
135
-            'REG_ID'=>$new_reg_id,
136
-            'DTT_ID'=>$new_datetime['DTT_ID'],
137
-            'CHK_in'=>true,
138
-            'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
139
-        );
140
-        $datatypes = array(
141
-            '%d',// REG_ID
142
-            '%d',// DTT_ID
143
-            '%d',// CHK_in
144
-            '%s',// CHK_timestamp
145
-        );
146
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
147
-        if (! $success) {
148
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
149
-            return 0;
150
-        }
151
-        $new_id = $wpdb->insert_id;
152
-        return $new_id;
153
-    }
133
+		// ok we can actually do what we set out to do: add a checkin/checkout record
134
+		$cols_n_values = array(
135
+			'REG_ID'=>$new_reg_id,
136
+			'DTT_ID'=>$new_datetime['DTT_ID'],
137
+			'CHK_in'=>true,
138
+			'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
139
+		);
140
+		$datatypes = array(
141
+			'%d',// REG_ID
142
+			'%d',// DTT_ID
143
+			'%d',// CHK_in
144
+			'%s',// CHK_timestamp
145
+		);
146
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
147
+		if (! $success) {
148
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
149
+			return 0;
150
+		}
151
+		$new_id = $wpdb->insert_id;
152
+		return $new_id;
153
+	}
154 154
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
         global $wpdb;
41 41
         $new_reg_table = $wpdb->prefix."esp_registration";
42 42
 
43
-        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ;
43
+        $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])));
44 44
 
45 45
         $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table);
46
-        if (! $new_registrations_for_attendee) {
46
+        if ( ! $new_registrations_for_attendee) {
47 47
             $new_registrations_for_attendee = array();
48 48
         }
49 49
         $new_datetime = $this->_try_to_find_datetime($old_row);
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
         // make sure registrations array is numerically indexed starting at 0 (it probably already is)
52 52
         $new_registrations_for_attendee = array_values($new_registrations_for_attendee);
53 53
         $new_checkin_ids = array();
54
-        for ($i = 0; $i<abs($num_to_checkin_at_this_time); $i++) {
55
-            $new_reg_id = $new_registrations_for_attendee[ $i ];
56
-            if (! $new_reg_id) {
54
+        for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) {
55
+            $new_reg_id = $new_registrations_for_attendee[$i];
56
+            if ( ! $new_reg_id) {
57 57
                 $this->add_error(sprintf(
58 58
                     __('It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', "event_espresso"),
59 59
                     $this->_json_encode($old_row),
@@ -64,14 +64,14 @@  discard block
 block discarded – undo
64 64
                 break;
65 65
             }
66 66
             $new_last_checkin_record = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", $new_reg_id));
67
-            if (! $new_last_checkin_record) {
67
+            if ( ! $new_last_checkin_record) {
68 68
                 $is_checked_in = false;
69 69
             } else {
70 70
                 $is_checked_in = intval($new_last_checkin_record['CHK_in']);
71 71
             }
72 72
             $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime);
73 73
             if ($new_id) {
74
-                $new_checkin_ids[]= $new_id;
74
+                $new_checkin_ids[] = $new_id;
75 75
             }
76 76
         }
77 77
         if ($new_checkin_ids) {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         global $wpdb;
94 94
 
95 95
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts);
96
-        if (! $new_event_id) {
96
+        if ( ! $new_event_id) {
97 97
             $this->add_error(sprintf(__("Could nto find new event ID with old event id '%d', on attendee row %s; and because of that couldnt find the correct datetime for Check-in", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee)));
98 98
             return 0;
99 99
         }
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
106 106
         // the most important condition should be last, as it will be array_shift'ed off last
107 107
         $conditions = array(
108
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
109
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
108
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
109
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
110 110
         );
111 111
         // start running queries, widening search each time by removing a condition
112 112
         $datetime_found = null;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1";
115 115
             $datetime_found = $wpdb->get_row($full_query, ARRAY_A);
116 116
             array_shift($conditions);
117
-        } while (! $datetime_found && $conditions);
117
+        }while ( ! $datetime_found && $conditions);
118 118
         return $datetime_found;
119 119
     }
120 120
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
             'CHK_timestamp'=>$new_datetime['DTT_EVT_start']
139 139
         );
140 140
         $datatypes = array(
141
-            '%d',// REG_ID
142
-            '%d',// DTT_ID
143
-            '%d',// CHK_in
144
-            '%s',// CHK_timestamp
141
+            '%d', // REG_ID
142
+            '%d', // DTT_ID
143
+            '%d', // CHK_in
144
+            '%s', // CHK_timestamp
145 145
         );
146 146
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
147
-        if (! $success) {
147
+        if ( ! $success) {
148 148
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes));
149 149
             return 0;
150 150
         }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_event_question_group.dmsstage.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -98,6 +98,9 @@
 block discarded – undo
98 98
         $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids);
99 99
     }
100 100
 
101
+    /**
102
+     * @param boolean $primary
103
+     */
101 104
     private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
102 105
     {
103 106
         global $wpdb;
Please login to merge, or discard this patch.
Indentation   +74 added lines, -76 removed lines patch added patch discarded remove patch
@@ -16,15 +16,13 @@  discard block
 block discarded – undo
16 16
             'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees','event_espresso'), false, false)
17 17
         )
18 18
     );
19
-
20
-
21 19
  *
22 20
  */
23 21
 class EE_DMS_4_1_0_event_question_group extends EE_Data_Migration_Script_Stage_Table
24 22
 {
25
-    private $_new_table;
26
-    public function _migrate_old_row($old_row)
27
-    {
23
+	private $_new_table;
24
+	public function _migrate_old_row($old_row)
25
+	{
28 26
 //      $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table);
29 27
 //          if ( ! $txn_id ){
30 28
 //              $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"),$old_row['id'],$this->_json_encode($old_row)));
@@ -34,8 +32,8 @@  discard block
 block discarded – undo
34 32
 //          $new_line_items = $this->_insert_new_line_items($txn,$old_row);
35 33
 //          $this->get_migration_script()->set_mapping($this->_old_table,$old_row['id'],$this->_new_line_table,$new_line_items);
36 34
 
37
-            $this->_insert_new_event_question_groups($old_row);
38
-    }
35
+			$this->_insert_new_event_question_groups($old_row);
36
+	}
39 37
 //  function _migration_step($num_items=50){
40 38
 //      global $wpdb;
41 39
 //      $start_at_record = $this->count_records_migrated();
@@ -55,78 +53,78 @@  discard block
 block discarded – undo
55 53
 //      $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
56 54
 //      return $count;
57 55
 //  }
58
-    public function __construct()
59
-    {
60
-        global $wpdb;
61
-        $this->_old_table = $wpdb->prefix."events_detail";
62
-        $this->_new_table = $wpdb->prefix."esp_event_question_group";
63
-        $this->_pretty_name = __("Question Groups in each Event", "event_espresso");
64
-        parent::__construct();
65
-    }
56
+	public function __construct()
57
+	{
58
+		global $wpdb;
59
+		$this->_old_table = $wpdb->prefix."events_detail";
60
+		$this->_new_table = $wpdb->prefix."esp_event_question_group";
61
+		$this->_pretty_name = __("Question Groups in each Event", "event_espresso");
62
+		parent::__construct();
63
+	}
66 64
 
67
-    /**
68
-     * Attempts to insert a new question group inthe new format given an old one
69
-     * @global type $wpdb
70
-     * @param array $old_event
71
-     * @return void
72
-     */
73
-    private function _insert_new_event_question_groups($old_event)
74
-    {
75
-        $new_event_question_group_ids = array();
76
-        $question_groups_for_primary = maybe_unserialize($old_event['question_groups']);
77
-        if (is_array($question_groups_for_primary)) {
78
-            foreach ($question_groups_for_primary as $old_question_group_id) {
79
-                $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true);
80
-                if ($new_id) {
81
-                    $new_event_question_group_ids[] = $new_id;
82
-                }
83
-            }
84
-        }
85
-        $event_meta = maybe_unserialize($old_event['event_meta']);
86
-        if (isset($event_meta['add_attendee_question_groups'])) {
87
-            if (is_array($event_meta['add_attendee_question_groups'])) {
88
-                foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) {
89
-                    $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false);
90
-                    if ($new_id) {
91
-                        $new_event_question_group_ids[] = $new_id;
92
-                    }
93
-                }
94
-            }
95
-        }
65
+	/**
66
+	 * Attempts to insert a new question group inthe new format given an old one
67
+	 * @global type $wpdb
68
+	 * @param array $old_event
69
+	 * @return void
70
+	 */
71
+	private function _insert_new_event_question_groups($old_event)
72
+	{
73
+		$new_event_question_group_ids = array();
74
+		$question_groups_for_primary = maybe_unserialize($old_event['question_groups']);
75
+		if (is_array($question_groups_for_primary)) {
76
+			foreach ($question_groups_for_primary as $old_question_group_id) {
77
+				$new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true);
78
+				if ($new_id) {
79
+					$new_event_question_group_ids[] = $new_id;
80
+				}
81
+			}
82
+		}
83
+		$event_meta = maybe_unserialize($old_event['event_meta']);
84
+		if (isset($event_meta['add_attendee_question_groups'])) {
85
+			if (is_array($event_meta['add_attendee_question_groups'])) {
86
+				foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) {
87
+					$new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false);
88
+					if ($new_id) {
89
+						$new_event_question_group_ids[] = $new_id;
90
+					}
91
+				}
92
+			}
93
+		}
96 94
 
97 95
 
98
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids);
99
-    }
96
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids);
97
+	}
100 98
 
101
-    private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
102
-    {
103
-        global $wpdb;
104
-        $new_question_group_id =$this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group");
99
+	private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
100
+	{
101
+		global $wpdb;
102
+		$new_question_group_id =$this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group");
105 103
 
106
-        if (! $new_question_group_id) {
107
-            $this->add_error(sprintf(__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), $old_question_group_id, $old_event['id']));
108
-            return 0;
109
-        }
110
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event['id']), $wpdb->posts);
111
-        if (! $new_question_group_id) {
112
-            $this->add_error(sprintf(__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), $old_event['id']));
113
-            return 0;
114
-        }
115
-        $cols_n_values = array(
116
-            'EVT_ID'=>$new_event_id,
117
-            'QSG_ID'=>$new_question_group_id,
118
-            'EQG_primary'=>$primary
119
-        );
120
-        $datatypes = array(
121
-            '%d',// EVT_ID
122
-            '%d',// QSG_ID
123
-            '%d',// EQG_primary
124
-        );
125
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
126
-        if (! $success) {
127
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
128
-            return 0;
129
-        }
130
-        return $wpdb->insert_id;
131
-    }
104
+		if (! $new_question_group_id) {
105
+			$this->add_error(sprintf(__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), $old_question_group_id, $old_event['id']));
106
+			return 0;
107
+		}
108
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event['id']), $wpdb->posts);
109
+		if (! $new_question_group_id) {
110
+			$this->add_error(sprintf(__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), $old_event['id']));
111
+			return 0;
112
+		}
113
+		$cols_n_values = array(
114
+			'EVT_ID'=>$new_event_id,
115
+			'QSG_ID'=>$new_question_group_id,
116
+			'EQG_primary'=>$primary
117
+		);
118
+		$datatypes = array(
119
+			'%d',// EVT_ID
120
+			'%d',// QSG_ID
121
+			'%d',// EQG_primary
122
+		);
123
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
124
+		if (! $success) {
125
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
126
+			return 0;
127
+		}
128
+		return $wpdb->insert_id;
129
+	}
132 130
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
     private function _insert_event_question_group($old_event, $old_question_group_id, $primary)
102 102
     {
103 103
         global $wpdb;
104
-        $new_question_group_id =$this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group");
104
+        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", intval($old_question_group_id), $wpdb->prefix."esp_question_group");
105 105
 
106
-        if (! $new_question_group_id) {
106
+        if ( ! $new_question_group_id) {
107 107
             $this->add_error(sprintf(__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), $old_question_group_id, $old_event['id']));
108 108
             return 0;
109 109
         }
110 110
         $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event['id']), $wpdb->posts);
111
-        if (! $new_question_group_id) {
111
+        if ( ! $new_question_group_id) {
112 112
             $this->add_error(sprintf(__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), $old_event['id']));
113 113
             return 0;
114 114
         }
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
             'EQG_primary'=>$primary
119 119
         );
120 120
         $datatypes = array(
121
-            '%d',// EVT_ID
122
-            '%d',// QSG_ID
123
-            '%d',// EQG_primary
121
+            '%d', // EVT_ID
122
+            '%d', // QSG_ID
123
+            '%d', // EQG_primary
124 124
         );
125 125
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
126
-        if (! $success) {
126
+        if ( ! $success) {
127 127
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
128 128
             return 0;
129 129
         }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_events.dmsstage.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
     /**
428 428
      * @param $old_event
429
-     * @param $new_cpt_id
429
+     * @param integer $new_cpt_id
430 430
      * @return int
431 431
      */
432 432
     private function _insert_event_meta($old_event, $new_cpt_id)
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 
694 694
 
695 695
     /**
696
-     * @param $new_event_id
697
-     * @param $new_venue_id
696
+     * @param integer $new_event_id
697
+     * @param integer $new_venue_id
698 698
      * @return int
699 699
      */
700 700
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
Please login to merge, or discard this patch.
Indentation   +634 added lines, -639 removed lines patch added patch discarded remove patch
@@ -84,8 +84,6 @@  discard block
 block discarded – undo
84 84
   KEY `submitted` (`submitted`),
85 85
   KEY `likes` (`likes`)
86 86
 ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$
87
-
88
-
89 87
  *
90 88
  * 4.1 Event model:
91 89
  * $this->_tables = array(
@@ -124,7 +122,6 @@  discard block
 block discarded – undo
124 122
                 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __("Accept Donations?", "event_espresso"), false, false)
125 123
 
126 124
             ));
127
-
128 125
  *
129 126
  * 3.1's start end table
130 127
  *
@@ -137,8 +134,6 @@  discard block
 block discarded – undo
137 134
   PRIMARY KEY (`id`),
138 135
   KEY `event_id` (`event_id`)
139 136
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$
140
-
141
-
142 137
  *
143 138
  * and 4.1 Datetime model's tables and fields:
144 139
  * $this->_tables = array(
@@ -160,172 +155,172 @@  discard block
 block discarded – undo
160 155
  */
161 156
 class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage
162 157
 {
163
-    private $_old_table;
164
-    private $_old_start_end_table;
165
-    private $_new_table;
166
-    private $_new_meta_table;
167
-    private $_new_datetime_table;
168
-
169
-
170
-
171
-    /**
172
-     * Just initializes the status of the migration
173
-     * @throws EE_Error
174
-     */
175
-    public function __construct()
176
-    {
177
-        global $wpdb;
178
-        $this->_old_table = $wpdb->prefix."events_detail";
179
-        $this->_old_start_end_table = $wpdb->prefix."events_start_end";
180
-        $this->_new_table = $wpdb->prefix."posts";
181
-        $this->_new_meta_table = $wpdb->prefix."esp_event_meta";
182
-        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
183
-        $this->_pretty_name = __("Events", "event_espresso");
184
-        parent::__construct();
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * Counts the records to migrate; the public version may cache it
191
-     * @return int
192
-     */
193
-    public function _count_records_to_migrate()
194
-    {
195
-        global $wpdb;
196
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table);
197
-        return intval($count);
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
204
-     * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
205
-     * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
206
-     * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50,
207
-     * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
208
-     * @param int $num_items_to_migrate
209
-     * @return int number of items ACTUALLY migrated
210
-     */
211
-    protected function _migration_step($num_items_to_migrate = 50)
212
-    {
213
-        global $wpdb;
214
-        // because the migration of each event can be a LOT more work, make each step smaller
215
-        $num_items_to_migrate = max(1, $num_items_to_migrate/5);
216
-        $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
217
-        $items_migrated_this_step = 0;
218
-
219
-        foreach ($events as $event_row) {
220
-            $guid = null;
221
-            // insert new 4.1 Attendee object using $wpdb
222
-            $post_id = $this->_insert_cpt($event_row);
223
-            if ($post_id) {
224
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
225
-                $meta_id = $this->_insert_event_meta($event_row, $post_id);
226
-                if ($meta_id) {
227
-                    $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
228
-                }
229
-                $this->_convert_start_end_times($event_row, $post_id);
230
-                $event_meta = maybe_unserialize($event_row['event_meta']);
231
-                $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
232
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
233
-
234
-                // maybe create a venue from info on the event?
235
-                $new_venue_id = $this->_maybe_create_venue($event_row);
236
-                if ($new_venue_id) {
237
-                    $this->_insert_new_venue_to_event($post_id, $new_venue_id);
238
-                }
239
-                $this->_add_post_metas($event_row, $post_id);
240
-            }
241
-            $items_migrated_this_step++;
242
-            if ($guid) {
243
-                // if we had to check for an image attachment
244
-                // then let's call it a day (avoid timing out, because this took a long time)
245
-                break;
246
-            }
247
-        }
248
-        if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
249
-            $this->set_status(EE_Data_Migration_Manager::status_completed);
250
-        }
251
-        return $items_migrated_this_step;
252
-    }
253
-
254
-    /**
255
-     * Stores any extra 3.1 "event_meta" column things as post meta
256
-     * @param array $old_event
257
-     * @param int $post_id
258
-     * @return void
259
-     */
260
-    private function _add_post_metas($old_event, $post_id)
261
-    {
262
-        $event_meta = maybe_unserialize($old_event['event_meta']);
263
-        if (! $event_meta || ! is_array($event_meta)) {
264
-            return;
265
-        }
266
-        unset($event_meta['date_submitted']);// factored into CPT
267
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
268
-        unset($event_meta['default_payment_status']);// dido
269
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
270
-        foreach ($event_meta as $meta_key => $meta_value) {
271
-            if ($meta_key) {// if the meta key is just an empty string, ignore it
272
-                $success = add_post_meta($post_id, $meta_key, $meta_value, true);
273
-                if (! $success) {
274
-                    $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
275
-                }
276
-            }
277
-        }
278
-        if ($old_event['alt_email']) {
279
-            add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
280
-        }
281
-        if ($old_event['recurrence_id']) {
282
-            add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
283
-        }
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * Finds a unique slug for this event, given its name (we could have simply used
290
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
291
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
292
-     * @param string $event_name (the name of the event for reading by humans)
293
-     * @param string $old_identifier the old EE3 identifier (a long unique string)
294
-     * @param string $new_post_status a post status
295
-     * @return string
296
-     */
297
-    private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
298
-    {
299
-        $count = 0;
300
-        $original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
301
-        return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
302
-    }
303
-
304
-    /**
305
-     * returns whether or not there is a post that has this same slug (post_title)
306
-     * @global wpdb $wpdb
307
-     * @param string $slug
308
-     * @return boolean
309
-     */
310
-    private function _other_post_exists_with_that_slug($slug)
311
-    {
312
-        global $wpdb;
313
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE post_name = %s", $slug);
314
-        $count = $wpdb->get_var($query);
315
-        return (boolean) intval($count);
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * @param $old_event
322
-     * @return int
323
-     */
324
-    private function _insert_cpt($old_event)
325
-    {
326
-        global $wpdb;
327
-        // convert 3.1 event status to 4.1 CPT status
328
-        // for reference, 3.1 event stati available for setting are:
158
+	private $_old_table;
159
+	private $_old_start_end_table;
160
+	private $_new_table;
161
+	private $_new_meta_table;
162
+	private $_new_datetime_table;
163
+
164
+
165
+
166
+	/**
167
+	 * Just initializes the status of the migration
168
+	 * @throws EE_Error
169
+	 */
170
+	public function __construct()
171
+	{
172
+		global $wpdb;
173
+		$this->_old_table = $wpdb->prefix."events_detail";
174
+		$this->_old_start_end_table = $wpdb->prefix."events_start_end";
175
+		$this->_new_table = $wpdb->prefix."posts";
176
+		$this->_new_meta_table = $wpdb->prefix."esp_event_meta";
177
+		$this->_new_datetime_table = $wpdb->prefix."esp_datetime";
178
+		$this->_pretty_name = __("Events", "event_espresso");
179
+		parent::__construct();
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * Counts the records to migrate; the public version may cache it
186
+	 * @return int
187
+	 */
188
+	public function _count_records_to_migrate()
189
+	{
190
+		global $wpdb;
191
+		$count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table);
192
+		return intval($count);
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
199
+	 * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
200
+	 * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
201
+	 * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50,
202
+	 * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
203
+	 * @param int $num_items_to_migrate
204
+	 * @return int number of items ACTUALLY migrated
205
+	 */
206
+	protected function _migration_step($num_items_to_migrate = 50)
207
+	{
208
+		global $wpdb;
209
+		// because the migration of each event can be a LOT more work, make each step smaller
210
+		$num_items_to_migrate = max(1, $num_items_to_migrate/5);
211
+		$events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
212
+		$items_migrated_this_step = 0;
213
+
214
+		foreach ($events as $event_row) {
215
+			$guid = null;
216
+			// insert new 4.1 Attendee object using $wpdb
217
+			$post_id = $this->_insert_cpt($event_row);
218
+			if ($post_id) {
219
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
220
+				$meta_id = $this->_insert_event_meta($event_row, $post_id);
221
+				if ($meta_id) {
222
+					$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
223
+				}
224
+				$this->_convert_start_end_times($event_row, $post_id);
225
+				$event_meta = maybe_unserialize($event_row['event_meta']);
226
+				$guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
227
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
228
+
229
+				// maybe create a venue from info on the event?
230
+				$new_venue_id = $this->_maybe_create_venue($event_row);
231
+				if ($new_venue_id) {
232
+					$this->_insert_new_venue_to_event($post_id, $new_venue_id);
233
+				}
234
+				$this->_add_post_metas($event_row, $post_id);
235
+			}
236
+			$items_migrated_this_step++;
237
+			if ($guid) {
238
+				// if we had to check for an image attachment
239
+				// then let's call it a day (avoid timing out, because this took a long time)
240
+				break;
241
+			}
242
+		}
243
+		if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
244
+			$this->set_status(EE_Data_Migration_Manager::status_completed);
245
+		}
246
+		return $items_migrated_this_step;
247
+	}
248
+
249
+	/**
250
+	 * Stores any extra 3.1 "event_meta" column things as post meta
251
+	 * @param array $old_event
252
+	 * @param int $post_id
253
+	 * @return void
254
+	 */
255
+	private function _add_post_metas($old_event, $post_id)
256
+	{
257
+		$event_meta = maybe_unserialize($old_event['event_meta']);
258
+		if (! $event_meta || ! is_array($event_meta)) {
259
+			return;
260
+		}
261
+		unset($event_meta['date_submitted']);// factored into CPT
262
+		unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
263
+		unset($event_meta['default_payment_status']);// dido
264
+		unset($event_meta['event_thumbnail_url']);// used to find post featured image
265
+		foreach ($event_meta as $meta_key => $meta_value) {
266
+			if ($meta_key) {// if the meta key is just an empty string, ignore it
267
+				$success = add_post_meta($post_id, $meta_key, $meta_value, true);
268
+				if (! $success) {
269
+					$this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
270
+				}
271
+			}
272
+		}
273
+		if ($old_event['alt_email']) {
274
+			add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
275
+		}
276
+		if ($old_event['recurrence_id']) {
277
+			add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
278
+		}
279
+	}
280
+
281
+
282
+
283
+	/**
284
+	 * Finds a unique slug for this event, given its name (we could have simply used
285
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
286
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
287
+	 * @param string $event_name (the name of the event for reading by humans)
288
+	 * @param string $old_identifier the old EE3 identifier (a long unique string)
289
+	 * @param string $new_post_status a post status
290
+	 * @return string
291
+	 */
292
+	private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
293
+	{
294
+		$count = 0;
295
+		$original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
296
+		return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
297
+	}
298
+
299
+	/**
300
+	 * returns whether or not there is a post that has this same slug (post_title)
301
+	 * @global wpdb $wpdb
302
+	 * @param string $slug
303
+	 * @return boolean
304
+	 */
305
+	private function _other_post_exists_with_that_slug($slug)
306
+	{
307
+		global $wpdb;
308
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE post_name = %s", $slug);
309
+		$count = $wpdb->get_var($query);
310
+		return (boolean) intval($count);
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * @param $old_event
317
+	 * @return int
318
+	 */
319
+	private function _insert_cpt($old_event)
320
+	{
321
+		global $wpdb;
322
+		// convert 3.1 event status to 4.1 CPT status
323
+		// for reference, 3.1 event stati available for setting are:
329 324
 //      $status = array(array('id' => 'A', 'text' => __('Public', 'event_espresso')), array('id' => 'S', 'text' => __('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => __('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => __('Draft', 'event_espresso')), array('id' => 'D', 'text' => __('Deleted', 'event_espresso')));
330 325
 //      and the json api uses the following to convert from 3.1 to 4.0
331 326
 //      'S'=>'secondary/waitlist',
@@ -339,486 +334,486 @@  discard block
 block discarded – undo
339 334
 //      4.1 Event Post stati are the normal post statis
340 335
 //      (publish,future,draft,pending,private,trash,auto-draft,inherit)
341 336
 //      and 3 custom ones: cancelled,postponed,sold_out
342
-        $status_conversions = array(
343
-            'R'=>'draft',
344
-            'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
345
-            'P'=>'pending',
346
-            'IA'=>'draft',// draft and in the past
337
+		$status_conversions = array(
338
+			'R'=>'draft',
339
+			'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
340
+			'P'=>'pending',
341
+			'IA'=>'draft',// draft and in the past
347 342
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
348
-            'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
349
-            'A'=>'publish',
350
-            'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351
-            'D'=>'trash',
352
-        );
353
-        $post_status = $status_conversions[ $old_event['event_status'] ];
354
-        // check if we've sold out
355
-        if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
356
-            $post_status = 'sold_out';
357
-        }
343
+			'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
344
+			'A'=>'publish',
345
+			'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
346
+			'D'=>'trash',
347
+		);
348
+		$post_status = $status_conversions[ $old_event['event_status'] ];
349
+		// check if we've sold out
350
+		if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
351
+			$post_status = 'sold_out';
352
+		}
358 353
 //      FYI postponed and cancelled don't exist in 3.1
359
-        $cols_n_values = array(
360
-            'post_title'=>stripslashes($old_event['event_name']),// EVT_name
361
-            'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc
362
-            'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
363
-            'post_date'=>$old_event['submitted'],// EVT_created NOT
364
-            'post_date_gmt'=>get_gmt_from_date($old_event['submitted']),
365
-            'post_excerpt'=>'',// EVT_short_desc
366
-            'post_modified'=>$old_event['submitted'],// EVT_modified
367
-            'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']),
368
-            'post_author'=>$old_event['wp_user'],// EVT_wp_user
369
-            'post_parent'=>0,// parent maybe get this from some REM field?
370
-            'menu_order'=>0,// EVT_order
371
-            'post_type'=>'espresso_events',// post_type
372
-            'post_status'=>$post_status,// status
373
-        );
374
-        $cols_n_values_with_no_invalid_text = array();
375
-        foreach ($cols_n_values as $col => $value) {
376
-            $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
377
-            if (! is_wp_error($value_sans_invalid_chars)) {
378
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
379
-            } else {
380
-                // otherwise leave it as-is. It will blow everything up and stop the migration
381
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
382
-            }
383
-        }
384
-        $cols_n_values = $cols_n_values_with_no_invalid_text;
385
-        $datatypes = array(
386
-            '%s',// EVT_name
387
-            '%s',// EVT_desc
388
-            '%s',// EVT_slug
389
-            '%s',// EVT_created
390
-            '%s',
391
-            '%s',// EVT_short_desc
392
-            '%s',// EVT_modified
393
-            '%s',
394
-            '%s',// EVT_wp_user
395
-            '%d',// post_parent
396
-            '%d',// EVT_order
397
-            '%s',// post_type
398
-            '%s',// status
399
-        );
400
-        $success = $wpdb->insert(
401
-            $this->_new_table,
402
-            $cols_n_values,
403
-            $datatypes
404
-        );
405
-        if (! $success) {
406
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
407
-            return 0;
408
-        }
409
-        return $wpdb->insert_id;
410
-    }
411
-
412
-    /**
413
-     * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
414
-     * @global wpdb $wpdb
415
-     * @param int $event_id
416
-     * @return int
417
-     */
418
-    public static function count_registrations($event_id)
419
-    {
420
-        global $wpdb;
421
-        $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
422
-        return intval($count);
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * @param $old_event
429
-     * @param $new_cpt_id
430
-     * @return int
431
-     */
432
-    private function _insert_event_meta($old_event, $new_cpt_id)
433
-    {
434
-        global $wpdb;
435
-        $event_meta = maybe_unserialize($old_event['event_meta']);
354
+		$cols_n_values = array(
355
+			'post_title'=>stripslashes($old_event['event_name']),// EVT_name
356
+			'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc
357
+			'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
358
+			'post_date'=>$old_event['submitted'],// EVT_created NOT
359
+			'post_date_gmt'=>get_gmt_from_date($old_event['submitted']),
360
+			'post_excerpt'=>'',// EVT_short_desc
361
+			'post_modified'=>$old_event['submitted'],// EVT_modified
362
+			'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']),
363
+			'post_author'=>$old_event['wp_user'],// EVT_wp_user
364
+			'post_parent'=>0,// parent maybe get this from some REM field?
365
+			'menu_order'=>0,// EVT_order
366
+			'post_type'=>'espresso_events',// post_type
367
+			'post_status'=>$post_status,// status
368
+		);
369
+		$cols_n_values_with_no_invalid_text = array();
370
+		foreach ($cols_n_values as $col => $value) {
371
+			$value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
372
+			if (! is_wp_error($value_sans_invalid_chars)) {
373
+				$cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
374
+			} else {
375
+				// otherwise leave it as-is. It will blow everything up and stop the migration
376
+				$cols_n_values_with_no_invalid_text[ $col ] = $value;
377
+			}
378
+		}
379
+		$cols_n_values = $cols_n_values_with_no_invalid_text;
380
+		$datatypes = array(
381
+			'%s',// EVT_name
382
+			'%s',// EVT_desc
383
+			'%s',// EVT_slug
384
+			'%s',// EVT_created
385
+			'%s',
386
+			'%s',// EVT_short_desc
387
+			'%s',// EVT_modified
388
+			'%s',
389
+			'%s',// EVT_wp_user
390
+			'%d',// post_parent
391
+			'%d',// EVT_order
392
+			'%s',// post_type
393
+			'%s',// status
394
+		);
395
+		$success = $wpdb->insert(
396
+			$this->_new_table,
397
+			$cols_n_values,
398
+			$datatypes
399
+		);
400
+		if (! $success) {
401
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
402
+			return 0;
403
+		}
404
+		return $wpdb->insert_id;
405
+	}
406
+
407
+	/**
408
+	 * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
409
+	 * @global wpdb $wpdb
410
+	 * @param int $event_id
411
+	 * @return int
412
+	 */
413
+	public static function count_registrations($event_id)
414
+	{
415
+		global $wpdb;
416
+		$count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
417
+		return intval($count);
418
+	}
419
+
420
+
421
+
422
+	/**
423
+	 * @param $old_event
424
+	 * @param $new_cpt_id
425
+	 * @return int
426
+	 */
427
+	private function _insert_event_meta($old_event, $new_cpt_id)
428
+	{
429
+		global $wpdb;
430
+		$event_meta = maybe_unserialize($old_event['event_meta']);
436 431
 //      for reference, 3.1 'default_payment_status' are: $default_payment_status = array(
437 432
 //  array('id' => "", 'text' => 'No Change'),
438 433
 //  array('id' => 'Incomplete', 'text' => 'Incomplete'),
439 434
 //  array('id' => 'Pending', 'text' => 'Pending'),
440 435
 //  //array('id' => 'Completed', 'text' => 'Completed')
441 436
 // );
442
-        $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
443
-        $cols_n_values = array(
444
-            'EVT_ID'=>$new_cpt_id,// EVT_ID_fk
445
-            'EVT_display_desc'=> 'Y' == $old_event['display_desc'],
446
-            'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'],
447
-            'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
448
-            'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
449
-            'EVT_default_registration_status' => $default_reg_status,
450
-            'EVT_member_only'=>$old_event['member_only'],
451
-            'EVT_phone'=> $old_event['phone'],
452
-            'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
453
-            'EVT_timezone_string'=> $old_event['timezone_string'],
454
-            'EVT_external_URL'=>$old_event['externalURL'],
455
-            'EVT_donations'=>false// doesnt exist in 3.1
456
-
457
-        );
458
-        $datatypes = array(
459
-            '%s',// EVT_ID
460
-            '%d',// EVT_display_desc
461
-            '%d',// EVT_display_ticket_selector
462
-            '%s',// EVT_visible_on
463
-            '%d',// EVT_additional_limit
464
-            '%s',// EVT_default_registration_status
465
-            '%d',// EVT_member_only
466
-            '%s',// EVT_phone
467
-            '%d',// EVT_allow_overflow
468
-            '%s',// EVT_timezone_string
469
-            '%s',// EVT_external_URL
470
-            '%d',// EVT_donations
471
-        );
472
-        $success = $wpdb->insert(
473
-            $this->_new_meta_table,
474
-            $cols_n_values,
475
-            $datatypes
476
-        );
477
-        if (! $success) {
478
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
479
-            return 0;
480
-        }
481
-        return $wpdb->insert_id;
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * @param $old_event
488
-     * @return int
489
-     */
490
-    private function _maybe_create_venue($old_event)
491
-    {
492
-        if ($old_event['address'] ||
493
-                $old_event['address2'] ||
494
-                $old_event['city'] ||
495
-                $old_event['state'] ||
496
-                $old_event['zip'] ||
497
-                $old_event['venue_title'] ||
498
-                $old_event['venue_url'] ||
499
-                $old_event['venue_image'] ||
500
-                $old_event['venue_phone'] ||
501
-                $old_event['virtual_url'] ||
502
-                $old_event['virtual_phone']
503
-                ) {
504
-            $old_id = $this->_duplicate_venue_exists($old_event);
505
-            if ($old_id) {
506
-                return $old_id;
507
-            }
508
-            $new_id = $this->_insert_venue_into_posts($old_event);
509
-            if ($new_id) {
510
-                $this->_insert_venue_into_meta_table($new_id, $old_event);
511
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
512
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
513
-            }
514
-            // we don't bother recording the conversion from old events to venues as that
515
-            // will complicate finding the conversion from old venues to new events
516
-            return $new_id;
517
-        } else {
518
-            return 0;
519
-        }
520
-    }
521
-
522
-    /**
523
-     * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
524
-     * If so, return it. Otherwise return NULL.
525
-     * @param array $old_event
526
-     * @return int duplicate venue id
527
-     */
528
-    private function _duplicate_venue_exists($old_event)
529
-    {
530
-        global $wpdb;
531
-        $conditions = array(
532
-            'VNU_address' => $old_event ['address'],
533
-            'VNU_address2' => $old_event['address2'],
534
-            'VNU_city' => $old_event['city'],
535
-            'VNU_zip' => $old_event['zip'],
536
-            'post_title'=> $this->_get_venue_title_for_event($old_event),
537
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
538
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
539
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
540
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
541
-        );
542
-        $sql_conditions = array();
543
-        foreach ($conditions as $column => $value) {
544
-            $sql_conditions [] = $wpdb->prepare("$column = %s", $value);
545
-        }
546
-        $query = "SELECT VNU_ID
437
+		$default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
438
+		$cols_n_values = array(
439
+			'EVT_ID'=>$new_cpt_id,// EVT_ID_fk
440
+			'EVT_display_desc'=> 'Y' == $old_event['display_desc'],
441
+			'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'],
442
+			'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
443
+			'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
444
+			'EVT_default_registration_status' => $default_reg_status,
445
+			'EVT_member_only'=>$old_event['member_only'],
446
+			'EVT_phone'=> $old_event['phone'],
447
+			'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
448
+			'EVT_timezone_string'=> $old_event['timezone_string'],
449
+			'EVT_external_URL'=>$old_event['externalURL'],
450
+			'EVT_donations'=>false// doesnt exist in 3.1
451
+
452
+		);
453
+		$datatypes = array(
454
+			'%s',// EVT_ID
455
+			'%d',// EVT_display_desc
456
+			'%d',// EVT_display_ticket_selector
457
+			'%s',// EVT_visible_on
458
+			'%d',// EVT_additional_limit
459
+			'%s',// EVT_default_registration_status
460
+			'%d',// EVT_member_only
461
+			'%s',// EVT_phone
462
+			'%d',// EVT_allow_overflow
463
+			'%s',// EVT_timezone_string
464
+			'%s',// EVT_external_URL
465
+			'%d',// EVT_donations
466
+		);
467
+		$success = $wpdb->insert(
468
+			$this->_new_meta_table,
469
+			$cols_n_values,
470
+			$datatypes
471
+		);
472
+		if (! $success) {
473
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
474
+			return 0;
475
+		}
476
+		return $wpdb->insert_id;
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * @param $old_event
483
+	 * @return int
484
+	 */
485
+	private function _maybe_create_venue($old_event)
486
+	{
487
+		if ($old_event['address'] ||
488
+				$old_event['address2'] ||
489
+				$old_event['city'] ||
490
+				$old_event['state'] ||
491
+				$old_event['zip'] ||
492
+				$old_event['venue_title'] ||
493
+				$old_event['venue_url'] ||
494
+				$old_event['venue_image'] ||
495
+				$old_event['venue_phone'] ||
496
+				$old_event['virtual_url'] ||
497
+				$old_event['virtual_phone']
498
+				) {
499
+			$old_id = $this->_duplicate_venue_exists($old_event);
500
+			if ($old_id) {
501
+				return $old_id;
502
+			}
503
+			$new_id = $this->_insert_venue_into_posts($old_event);
504
+			if ($new_id) {
505
+				$this->_insert_venue_into_meta_table($new_id, $old_event);
506
+				$guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
507
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
508
+			}
509
+			// we don't bother recording the conversion from old events to venues as that
510
+			// will complicate finding the conversion from old venues to new events
511
+			return $new_id;
512
+		} else {
513
+			return 0;
514
+		}
515
+	}
516
+
517
+	/**
518
+	 * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
519
+	 * If so, return it. Otherwise return NULL.
520
+	 * @param array $old_event
521
+	 * @return int duplicate venue id
522
+	 */
523
+	private function _duplicate_venue_exists($old_event)
524
+	{
525
+		global $wpdb;
526
+		$conditions = array(
527
+			'VNU_address' => $old_event ['address'],
528
+			'VNU_address2' => $old_event['address2'],
529
+			'VNU_city' => $old_event['city'],
530
+			'VNU_zip' => $old_event['zip'],
531
+			'post_title'=> $this->_get_venue_title_for_event($old_event),
532
+			'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
533
+			'VNU_url'=>$old_event['venue_url'],// VNU_url
534
+			'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
535
+			'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
536
+		);
537
+		$sql_conditions = array();
538
+		foreach ($conditions as $column => $value) {
539
+			$sql_conditions [] = $wpdb->prepare("$column = %s", $value);
540
+		}
541
+		$query = "SELECT VNU_ID
547 542
 					FROM
548 543
 		{$wpdb->posts} as p INNER JOIN
549 544
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
550 545
 			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
551
-        $id = $wpdb->get_var($query);
552
-        return $id;
553
-    }
554
-
555
-    /**
556
-     * Gets teh venue's title or makes one up if there is none
557
-     * @param array $event_data_array keys are events_details columns and values are their values
558
-     * @return string
559
-     */
560
-    protected function _get_venue_title_for_event($event_data_array)
561
-    {
562
-        return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
563
-    }
564
-
565
-    /**
566
-     * Inserts the CPT
567
-     *
568
-     * @param array $old_event keys are cols, values are col values
569
-     * @return int
570
-     */
571
-    private function _insert_venue_into_posts($old_event)
572
-    {
573
-        global $wpdb;
574
-        $insertion_array = array(
575
-                    'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name
576
-                    'post_content'=>'',// VNU_desc
577
-                    'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
578
-                    'post_date'=>current_time('mysql'),// VNU_created
579
-                    'post_date_gmt'=>get_gmt_from_date(current_time('mysql')),
580
-                    'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters
581
-                    'post_modified'=>current_time('mysql'),// VNU_modified
582
-                    'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')),
583
-                    'post_author'=>$old_event['wp_user'],// VNU_wp_user
584
-                    'post_parent'=>0,// parent
585
-                    'menu_order'=>0,// VNU_order
586
-                    'post_type'=>'espresso_venues'// post_type
587
-                );
588
-        $datatypes_array = array(
589
-                    '%s',// VNU_name
590
-                    '%s',// VNU_desc
591
-                    '%s',// VNU_identifier
592
-                    '%s',// VNU_created
593
-                    '%s',
594
-                    '%s',// VNU_short_desc
595
-                    '%s',// VNU_modified
596
-                    '%s',
597
-                    '%d',// VNU_wp_user
598
-                    '%d',// parent
599
-                    '%d',// VNU_order
600
-                    '%s',// post_type
601
-                );
602
-        $success = $wpdb->insert(
603
-            $wpdb->posts,
604
-            $insertion_array,
605
-            $datatypes_array
606
-        );
607
-        if (! $success) {
608
-            $this->add_error(
609
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
610
-                    $this->_old_table,
611
-                    $old_event,
612
-                    $this->_new_table,
613
-                    $insertion_array,
614
-                    $datatypes_array
615
-                )
616
-            );
617
-            return 0;
618
-        }
619
-        return $wpdb->insert_id;
620
-    }
621
-
622
-    /**
623
-     * Inserts into the venue_meta table
624
-     * @param int $cpt_id
625
-     * @param array $old_event
626
-     * @return int
627
-     */
628
-    private function _insert_venue_into_meta_table($cpt_id, $old_event)
629
-    {
630
-        global $wpdb;
631
-
632
-        // assume the country is the same as the organization's old settings
633
-        $country_iso = $this->get_migration_script()->get_default_country_iso();
634
-        // find the state from the venue, or the organization, or just guess california
635
-        if (! $old_event['state']) {
636
-            $old_org_options = get_option('events_organization_settings');
637
-            $state_name = stripslashes($old_org_options['organization_state']);
638
-        } else {
639
-            $state_name = $old_event['state'];
640
-        }
641
-        if (! $state_name) {
642
-            $state_name = 'CA';
643
-        }
644
-        // get a state ID with the same name, if possible
645
-        try {
646
-            $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
647
-            $state_id = $state['STA_ID'];
648
-        } catch (EE_Error $e) {
649
-            $this->add_error($e->getMessage());
650
-            $state_id = 0;
651
-        }
652
-        // now insert into meta table
653
-        $insertion_array = array(
654
-            'VNU_ID'=>$cpt_id,// VNU_ID_fk
655
-            'VNU_address'=>stripslashes($old_event['address']),// VNU_address
656
-            'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2
657
-            'VNU_city'=>stripslashes($old_event['city']),// VNU_city
658
-            'STA_ID'=>$state_id,// STA_ID
659
-            'CNT_ISO'=>$country_iso,// CNT_ISO
660
-            'VNU_zip'=>$old_event['zip'],// VNU_zip
661
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
662
-            'VNU_capacity'=>-1,// VNU_capacity
663
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
664
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
665
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
666
-            'VNU_google_map_link'=>'',// VNU_google_map_link
667
-            'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
668
-        );
669
-        $datatypes = array(
670
-            '%d',// VNU_ID_fk
671
-            '%s',// VNU_address
672
-            '%s',// VNU_address2
673
-            '%s',// VNU_city
674
-            '%d',// STA_ID
675
-            '%s',// CNT_ISO
676
-            '%s',// VNU_zip
677
-            '%s',// VNU_phone
678
-            '%d',// VNU_capacity
679
-            '%s',// VNU_url
680
-            '%s',// VNU_virtual_phone
681
-            '%s',// VNU_virtual_url
682
-            '%s',// VNU_google_map_link
683
-            '%d',// VNU_enable_for_gmap
684
-        );
685
-        $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
686
-        if (! $success) {
687
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
688
-            return 0;
689
-        }
690
-        return $wpdb->insert_id;
691
-    }
692
-
693
-
694
-
695
-    /**
696
-     * @param $new_event_id
697
-     * @param $new_venue_id
698
-     * @return int
699
-     */
700
-    private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
701
-    {
702
-        global $wpdb;
703
-        if (! $new_event_id) {
704
-            $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
705
-            return 0;
706
-        }
707
-        if (! $new_venue_id) {
708
-            $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
709
-            return 0;
710
-        }
711
-        $cols_n_values = array(
712
-            'EVT_ID'=>$new_event_id,
713
-            'VNU_ID'=>$new_venue_id,
714
-            'EVV_primary'=>true
715
-        );
716
-        $datatypes = array(
717
-            '%d',// EVT_ID
718
-            '%d',// VNU_ID
719
-            '%d',// EVT_primary
720
-        );
721
-        $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
722
-        if (! $success) {
723
-            $this->add_error(
724
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
725
-                    $this->_old_table,
726
-                    array(),
727
-                    $this->_new_table,
728
-                    $cols_n_values,
729
-                    $datatypes
730
-                )
731
-            );
732
-            return 0;
733
-        }
734
-        return $wpdb->insert_id;
735
-    }
736
-    /**
737
-     * Converts all the 3.1 start-end times for the event to 4.1 datetimes
738
-     * @global wpdb $wpdb
739
-     * @param array $old_event results of get_results(...,ARRAY_A)
740
-     * @param int $new_cpt_id new post ID
741
-     * @return void (if there are errors though, adds them to the stage's error list
742
-     */
743
-    private function _convert_start_end_times($old_event, $new_cpt_id)
744
-    {
745
-        $start_end_times = $this->_get_old_start_end_times($old_event['id']);
746
-        foreach ($start_end_times as $start_end_time) {
747
-            $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
748
-            if ($datetime_id) {
749
-                $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
750
-            }
751
-        }
752
-    }
753
-    /**
754
-     * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
755
-     * @global wpdb $wpdb
756
-     * @param int $old_event_id
757
-     * @return array
758
-     */
759
-    private function _get_old_start_end_times($old_event_id)
760
-    {
761
-        global $wpdb;
762
-        return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
763
-    }
764
-    /**
765
-     * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
766
-     * @param array $start_end_time_row
767
-     * @param array $old_event_row
768
-     * @param int $new_cpt_id
769
-     * @return int ID of new datetime
770
-     */
771
-    private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
772
-    {
773
-        global $wpdb;
774
-        $start_date = $old_event_row['start_date'];
775
-        $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
776
-        $end_date = $old_event_row['end_date'];
777
-        $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
778
-        $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
779
-        $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
780
-        $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
781
-        $cols_n_values = array(
782
-            'EVT_ID'=>$new_cpt_id,// EVT_ID
783
-            'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start
784
-            'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end
785
-            'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
786
-            'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration
546
+		$id = $wpdb->get_var($query);
547
+		return $id;
548
+	}
549
+
550
+	/**
551
+	 * Gets teh venue's title or makes one up if there is none
552
+	 * @param array $event_data_array keys are events_details columns and values are their values
553
+	 * @return string
554
+	 */
555
+	protected function _get_venue_title_for_event($event_data_array)
556
+	{
557
+		return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
558
+	}
559
+
560
+	/**
561
+	 * Inserts the CPT
562
+	 *
563
+	 * @param array $old_event keys are cols, values are col values
564
+	 * @return int
565
+	 */
566
+	private function _insert_venue_into_posts($old_event)
567
+	{
568
+		global $wpdb;
569
+		$insertion_array = array(
570
+					'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name
571
+					'post_content'=>'',// VNU_desc
572
+					'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
573
+					'post_date'=>current_time('mysql'),// VNU_created
574
+					'post_date_gmt'=>get_gmt_from_date(current_time('mysql')),
575
+					'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters
576
+					'post_modified'=>current_time('mysql'),// VNU_modified
577
+					'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')),
578
+					'post_author'=>$old_event['wp_user'],// VNU_wp_user
579
+					'post_parent'=>0,// parent
580
+					'menu_order'=>0,// VNU_order
581
+					'post_type'=>'espresso_venues'// post_type
582
+				);
583
+		$datatypes_array = array(
584
+					'%s',// VNU_name
585
+					'%s',// VNU_desc
586
+					'%s',// VNU_identifier
587
+					'%s',// VNU_created
588
+					'%s',
589
+					'%s',// VNU_short_desc
590
+					'%s',// VNU_modified
591
+					'%s',
592
+					'%d',// VNU_wp_user
593
+					'%d',// parent
594
+					'%d',// VNU_order
595
+					'%s',// post_type
596
+				);
597
+		$success = $wpdb->insert(
598
+			$wpdb->posts,
599
+			$insertion_array,
600
+			$datatypes_array
601
+		);
602
+		if (! $success) {
603
+			$this->add_error(
604
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
605
+					$this->_old_table,
606
+					$old_event,
607
+					$this->_new_table,
608
+					$insertion_array,
609
+					$datatypes_array
610
+				)
611
+			);
612
+			return 0;
613
+		}
614
+		return $wpdb->insert_id;
615
+	}
616
+
617
+	/**
618
+	 * Inserts into the venue_meta table
619
+	 * @param int $cpt_id
620
+	 * @param array $old_event
621
+	 * @return int
622
+	 */
623
+	private function _insert_venue_into_meta_table($cpt_id, $old_event)
624
+	{
625
+		global $wpdb;
626
+
627
+		// assume the country is the same as the organization's old settings
628
+		$country_iso = $this->get_migration_script()->get_default_country_iso();
629
+		// find the state from the venue, or the organization, or just guess california
630
+		if (! $old_event['state']) {
631
+			$old_org_options = get_option('events_organization_settings');
632
+			$state_name = stripslashes($old_org_options['organization_state']);
633
+		} else {
634
+			$state_name = $old_event['state'];
635
+		}
636
+		if (! $state_name) {
637
+			$state_name = 'CA';
638
+		}
639
+		// get a state ID with the same name, if possible
640
+		try {
641
+			$state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
642
+			$state_id = $state['STA_ID'];
643
+		} catch (EE_Error $e) {
644
+			$this->add_error($e->getMessage());
645
+			$state_id = 0;
646
+		}
647
+		// now insert into meta table
648
+		$insertion_array = array(
649
+			'VNU_ID'=>$cpt_id,// VNU_ID_fk
650
+			'VNU_address'=>stripslashes($old_event['address']),// VNU_address
651
+			'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2
652
+			'VNU_city'=>stripslashes($old_event['city']),// VNU_city
653
+			'STA_ID'=>$state_id,// STA_ID
654
+			'CNT_ISO'=>$country_iso,// CNT_ISO
655
+			'VNU_zip'=>$old_event['zip'],// VNU_zip
656
+			'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
657
+			'VNU_capacity'=>-1,// VNU_capacity
658
+			'VNU_url'=>$old_event['venue_url'],// VNU_url
659
+			'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
660
+			'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
661
+			'VNU_google_map_link'=>'',// VNU_google_map_link
662
+			'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
663
+		);
664
+		$datatypes = array(
665
+			'%d',// VNU_ID_fk
666
+			'%s',// VNU_address
667
+			'%s',// VNU_address2
668
+			'%s',// VNU_city
669
+			'%d',// STA_ID
670
+			'%s',// CNT_ISO
671
+			'%s',// VNU_zip
672
+			'%s',// VNU_phone
673
+			'%d',// VNU_capacity
674
+			'%s',// VNU_url
675
+			'%s',// VNU_virtual_phone
676
+			'%s',// VNU_virtual_url
677
+			'%s',// VNU_google_map_link
678
+			'%d',// VNU_enable_for_gmap
679
+		);
680
+		$success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
681
+		if (! $success) {
682
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
683
+			return 0;
684
+		}
685
+		return $wpdb->insert_id;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * @param $new_event_id
692
+	 * @param $new_venue_id
693
+	 * @return int
694
+	 */
695
+	private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
696
+	{
697
+		global $wpdb;
698
+		if (! $new_event_id) {
699
+			$this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
700
+			return 0;
701
+		}
702
+		if (! $new_venue_id) {
703
+			$this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
704
+			return 0;
705
+		}
706
+		$cols_n_values = array(
707
+			'EVT_ID'=>$new_event_id,
708
+			'VNU_ID'=>$new_venue_id,
709
+			'EVV_primary'=>true
710
+		);
711
+		$datatypes = array(
712
+			'%d',// EVT_ID
713
+			'%d',// VNU_ID
714
+			'%d',// EVT_primary
715
+		);
716
+		$success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
717
+		if (! $success) {
718
+			$this->add_error(
719
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
720
+					$this->_old_table,
721
+					array(),
722
+					$this->_new_table,
723
+					$cols_n_values,
724
+					$datatypes
725
+				)
726
+			);
727
+			return 0;
728
+		}
729
+		return $wpdb->insert_id;
730
+	}
731
+	/**
732
+	 * Converts all the 3.1 start-end times for the event to 4.1 datetimes
733
+	 * @global wpdb $wpdb
734
+	 * @param array $old_event results of get_results(...,ARRAY_A)
735
+	 * @param int $new_cpt_id new post ID
736
+	 * @return void (if there are errors though, adds them to the stage's error list
737
+	 */
738
+	private function _convert_start_end_times($old_event, $new_cpt_id)
739
+	{
740
+		$start_end_times = $this->_get_old_start_end_times($old_event['id']);
741
+		foreach ($start_end_times as $start_end_time) {
742
+			$datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
743
+			if ($datetime_id) {
744
+				$this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
745
+			}
746
+		}
747
+	}
748
+	/**
749
+	 * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
750
+	 * @global wpdb $wpdb
751
+	 * @param int $old_event_id
752
+	 * @return array
753
+	 */
754
+	private function _get_old_start_end_times($old_event_id)
755
+	{
756
+		global $wpdb;
757
+		return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
758
+	}
759
+	/**
760
+	 * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
761
+	 * @param array $start_end_time_row
762
+	 * @param array $old_event_row
763
+	 * @param int $new_cpt_id
764
+	 * @return int ID of new datetime
765
+	 */
766
+	private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
767
+	{
768
+		global $wpdb;
769
+		$start_date = $old_event_row['start_date'];
770
+		$start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
771
+		$end_date = $old_event_row['end_date'];
772
+		$end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
773
+		$existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
774
+		$start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
775
+		$end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
776
+		$cols_n_values = array(
777
+			'EVT_ID'=>$new_cpt_id,// EVT_ID
778
+			'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start
779
+			'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end
780
+			'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
781
+			'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration
787 782
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
788
-            'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
789
-            'DTT_parent'=>0,
790
-            'DTT_deleted'=>false
791
-        );
792
-        $datatypes = array(
793
-            '%d',// EVT_Id
794
-            '%s',// DTT_EVT_start
795
-            '%s',// DTT_EVT_end
796
-            '%d',// DTT_reg_limit
797
-            '%d',// DTT_sold
783
+			'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
784
+			'DTT_parent'=>0,
785
+			'DTT_deleted'=>false
786
+		);
787
+		$datatypes = array(
788
+			'%d',// EVT_Id
789
+			'%s',// DTT_EVT_start
790
+			'%s',// DTT_EVT_end
791
+			'%d',// DTT_reg_limit
792
+			'%d',// DTT_sold
798 793
 //          '%d',//DTT_is_primary
799
-            '%d',// DTT_order
800
-            '%d',// DTT_parent
801
-            '%d',// DTT_deleted
802
-        );
803
-        $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
804
-        if (! $success) {
805
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
806
-            return 0;
807
-        }
808
-        return $wpdb->insert_id;
809
-    }
810
-
811
-    /**
812
-     * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
813
-     * when deciding whether a datetime we're about ot insert should be the 'primary' or not
814
-     * @global wpdb $wpdb
815
-     * @param int $cpt_event_id
816
-     * @return int
817
-     */
818
-    private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
819
-    {
820
-        global $wpdb;
821
-        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
822
-        return intval($count);
823
-    }
794
+			'%d',// DTT_order
795
+			'%d',// DTT_parent
796
+			'%d',// DTT_deleted
797
+		);
798
+		$success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
799
+		if (! $success) {
800
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
801
+			return 0;
802
+		}
803
+		return $wpdb->insert_id;
804
+	}
805
+
806
+	/**
807
+	 * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
808
+	 * when deciding whether a datetime we're about ot insert should be the 'primary' or not
809
+	 * @global wpdb $wpdb
810
+	 * @param int $cpt_event_id
811
+	 * @return int
812
+	 */
813
+	private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
814
+	{
815
+		global $wpdb;
816
+		$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
817
+		return intval($count);
818
+	}
824 819
 }
Please login to merge, or discard this patch.
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     {
213 213
         global $wpdb;
214 214
         // because the migration of each event can be a LOT more work, make each step smaller
215
-        $num_items_to_migrate = max(1, $num_items_to_migrate/5);
215
+        $num_items_to_migrate = max(1, $num_items_to_migrate / 5);
216 216
         $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
217 217
         $items_migrated_this_step = 0;
218 218
 
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
     private function _add_post_metas($old_event, $post_id)
261 261
     {
262 262
         $event_meta = maybe_unserialize($old_event['event_meta']);
263
-        if (! $event_meta || ! is_array($event_meta)) {
263
+        if ( ! $event_meta || ! is_array($event_meta)) {
264 264
             return;
265 265
         }
266
-        unset($event_meta['date_submitted']);// factored into CPT
267
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
268
-        unset($event_meta['default_payment_status']);// dido
269
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
266
+        unset($event_meta['date_submitted']); // factored into CPT
267
+        unset($event_meta['additional_attendee_reg_info']); // factored into event meta table
268
+        unset($event_meta['default_payment_status']); // dido
269
+        unset($event_meta['event_thumbnail_url']); // used to find post featured image
270 270
         foreach ($event_meta as $meta_key => $meta_value) {
271 271
             if ($meta_key) {// if the meta key is just an empty string, ignore it
272 272
                 $success = add_post_meta($post_id, $meta_key, $meta_value, true);
273
-                if (! $success) {
273
+                if ( ! $success) {
274 274
                     $this->add_error(sprintf(__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
275 275
                 }
276 276
             }
@@ -341,68 +341,68 @@  discard block
 block discarded – undo
341 341
 //      and 3 custom ones: cancelled,postponed,sold_out
342 342
         $status_conversions = array(
343 343
             'R'=>'draft',
344
-            'X'=>'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
344
+            'X'=>'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
345 345
             'P'=>'pending',
346
-            'IA'=>'draft',// draft and in the past
346
+            'IA'=>'draft', // draft and in the past
347 347
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
348
-            'O'=>'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
348
+            'O'=>'publish', // @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
349 349
             'A'=>'publish',
350
-            'S'=>'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
350
+            'S'=>'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351 351
             'D'=>'trash',
352 352
         );
353
-        $post_status = $status_conversions[ $old_event['event_status'] ];
353
+        $post_status = $status_conversions[$old_event['event_status']];
354 354
         // check if we've sold out
355 355
         if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
356 356
             $post_status = 'sold_out';
357 357
         }
358 358
 //      FYI postponed and cancelled don't exist in 3.1
359 359
         $cols_n_values = array(
360
-            'post_title'=>stripslashes($old_event['event_name']),// EVT_name
361
-            'post_content'=>stripslashes($old_event['event_desc']),// EVT_desc
362
-            'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
363
-            'post_date'=>$old_event['submitted'],// EVT_created NOT
360
+            'post_title'=>stripslashes($old_event['event_name']), // EVT_name
361
+            'post_content'=>stripslashes($old_event['event_desc']), // EVT_desc
362
+            'post_name'=>$this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug
363
+            'post_date'=>$old_event['submitted'], // EVT_created NOT
364 364
             'post_date_gmt'=>get_gmt_from_date($old_event['submitted']),
365
-            'post_excerpt'=>'',// EVT_short_desc
366
-            'post_modified'=>$old_event['submitted'],// EVT_modified
365
+            'post_excerpt'=>'', // EVT_short_desc
366
+            'post_modified'=>$old_event['submitted'], // EVT_modified
367 367
             'post_modified_gmt'=>get_gmt_from_date($old_event['submitted']),
368
-            'post_author'=>$old_event['wp_user'],// EVT_wp_user
369
-            'post_parent'=>0,// parent maybe get this from some REM field?
370
-            'menu_order'=>0,// EVT_order
371
-            'post_type'=>'espresso_events',// post_type
372
-            'post_status'=>$post_status,// status
368
+            'post_author'=>$old_event['wp_user'], // EVT_wp_user
369
+            'post_parent'=>0, // parent maybe get this from some REM field?
370
+            'menu_order'=>0, // EVT_order
371
+            'post_type'=>'espresso_events', // post_type
372
+            'post_status'=>$post_status, // status
373 373
         );
374 374
         $cols_n_values_with_no_invalid_text = array();
375 375
         foreach ($cols_n_values as $col => $value) {
376 376
             $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
377
-            if (! is_wp_error($value_sans_invalid_chars)) {
378
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
377
+            if ( ! is_wp_error($value_sans_invalid_chars)) {
378
+                $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars;
379 379
             } else {
380 380
                 // otherwise leave it as-is. It will blow everything up and stop the migration
381
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
381
+                $cols_n_values_with_no_invalid_text[$col] = $value;
382 382
             }
383 383
         }
384 384
         $cols_n_values = $cols_n_values_with_no_invalid_text;
385 385
         $datatypes = array(
386
-            '%s',// EVT_name
387
-            '%s',// EVT_desc
388
-            '%s',// EVT_slug
389
-            '%s',// EVT_created
386
+            '%s', // EVT_name
387
+            '%s', // EVT_desc
388
+            '%s', // EVT_slug
389
+            '%s', // EVT_created
390 390
             '%s',
391
-            '%s',// EVT_short_desc
392
-            '%s',// EVT_modified
391
+            '%s', // EVT_short_desc
392
+            '%s', // EVT_modified
393 393
             '%s',
394
-            '%s',// EVT_wp_user
395
-            '%d',// post_parent
396
-            '%d',// EVT_order
397
-            '%s',// post_type
398
-            '%s',// status
394
+            '%s', // EVT_wp_user
395
+            '%d', // post_parent
396
+            '%d', // EVT_order
397
+            '%s', // post_type
398
+            '%s', // status
399 399
         );
400 400
         $success = $wpdb->insert(
401 401
             $this->_new_table,
402 402
             $cols_n_values,
403 403
             $datatypes
404 404
         );
405
-        if (! $success) {
405
+        if ( ! $success) {
406 406
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
407 407
             return 0;
408 408
         }
@@ -441,10 +441,10 @@  discard block
 block discarded – undo
441 441
 // );
442 442
         $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
443 443
         $cols_n_values = array(
444
-            'EVT_ID'=>$new_cpt_id,// EVT_ID_fk
444
+            'EVT_ID'=>$new_cpt_id, // EVT_ID_fk
445 445
             'EVT_display_desc'=> 'Y' == $old_event['display_desc'],
446
-            'EVT_display_ticket_selector'=> 'Y'== $old_event['display_reg_form'],
447
-            'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
446
+            'EVT_display_ticket_selector'=> 'Y' == $old_event['display_reg_form'],
447
+            'EVT_visible_on'=> $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']), // don't use the old 'visible_on', as it wasn't ever used
448 448
             'EVT_additional_limit'=> $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
449 449
             'EVT_default_registration_status' => $default_reg_status,
450 450
             'EVT_member_only'=>$old_event['member_only'],
@@ -456,25 +456,25 @@  discard block
 block discarded – undo
456 456
 
457 457
         );
458 458
         $datatypes = array(
459
-            '%s',// EVT_ID
460
-            '%d',// EVT_display_desc
461
-            '%d',// EVT_display_ticket_selector
462
-            '%s',// EVT_visible_on
463
-            '%d',// EVT_additional_limit
464
-            '%s',// EVT_default_registration_status
465
-            '%d',// EVT_member_only
466
-            '%s',// EVT_phone
467
-            '%d',// EVT_allow_overflow
468
-            '%s',// EVT_timezone_string
469
-            '%s',// EVT_external_URL
470
-            '%d',// EVT_donations
459
+            '%s', // EVT_ID
460
+            '%d', // EVT_display_desc
461
+            '%d', // EVT_display_ticket_selector
462
+            '%s', // EVT_visible_on
463
+            '%d', // EVT_additional_limit
464
+            '%s', // EVT_default_registration_status
465
+            '%d', // EVT_member_only
466
+            '%s', // EVT_phone
467
+            '%d', // EVT_allow_overflow
468
+            '%s', // EVT_timezone_string
469
+            '%s', // EVT_external_URL
470
+            '%d', // EVT_donations
471 471
         );
472 472
         $success = $wpdb->insert(
473 473
             $this->_new_meta_table,
474 474
             $cols_n_values,
475 475
             $datatypes
476 476
         );
477
-        if (! $success) {
477
+        if ( ! $success) {
478 478
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
479 479
             return 0;
480 480
         }
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
             $new_id = $this->_insert_venue_into_posts($old_event);
509 509
             if ($new_id) {
510 510
                 $this->_insert_venue_into_meta_table($new_id, $old_event);
511
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
511
+                $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null;
512 512
                 $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
513 513
             }
514 514
             // we don't bother recording the conversion from old events to venues as that
@@ -534,10 +534,10 @@  discard block
 block discarded – undo
534 534
             'VNU_city' => $old_event['city'],
535 535
             'VNU_zip' => $old_event['zip'],
536 536
             'post_title'=> $this->_get_venue_title_for_event($old_event),
537
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
538
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
539
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
540
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
537
+            'VNU_phone'=>$old_event['venue_phone'], // VNU_phone
538
+            'VNU_url'=>$old_event['venue_url'], // VNU_url
539
+            'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone
540
+            'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url
541 541
         );
542 542
         $sql_conditions = array();
543 543
         foreach ($conditions as $column => $value) {
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 					FROM
548 548
 		{$wpdb->posts} as p INNER JOIN
549 549
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
550
-			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
550
+			WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1";
551 551
         $id = $wpdb->get_var($query);
552 552
         return $id;
553 553
     }
@@ -572,39 +572,39 @@  discard block
 block discarded – undo
572 572
     {
573 573
         global $wpdb;
574 574
         $insertion_array = array(
575
-                    'post_title'=> $this->_get_venue_title_for_event($old_event),// VNU_name
576
-                    'post_content'=>'',// VNU_desc
577
-                    'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
578
-                    'post_date'=>current_time('mysql'),// VNU_created
575
+                    'post_title'=> $this->_get_venue_title_for_event($old_event), // VNU_name
576
+                    'post_content'=>'', // VNU_desc
577
+                    'post_name'=> $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier
578
+                    'post_date'=>current_time('mysql'), // VNU_created
579 579
                     'post_date_gmt'=>get_gmt_from_date(current_time('mysql')),
580
-                    'post_excerpt'=>'',// VNU_short_desc arbitrary only 50 characters
581
-                    'post_modified'=>current_time('mysql'),// VNU_modified
580
+                    'post_excerpt'=>'', // VNU_short_desc arbitrary only 50 characters
581
+                    'post_modified'=>current_time('mysql'), // VNU_modified
582 582
                     'post_modified_gmt'=>get_gmt_from_date(current_time('mysql')),
583
-                    'post_author'=>$old_event['wp_user'],// VNU_wp_user
584
-                    'post_parent'=>0,// parent
585
-                    'menu_order'=>0,// VNU_order
583
+                    'post_author'=>$old_event['wp_user'], // VNU_wp_user
584
+                    'post_parent'=>0, // parent
585
+                    'menu_order'=>0, // VNU_order
586 586
                     'post_type'=>'espresso_venues'// post_type
587 587
                 );
588 588
         $datatypes_array = array(
589
-                    '%s',// VNU_name
590
-                    '%s',// VNU_desc
591
-                    '%s',// VNU_identifier
592
-                    '%s',// VNU_created
589
+                    '%s', // VNU_name
590
+                    '%s', // VNU_desc
591
+                    '%s', // VNU_identifier
592
+                    '%s', // VNU_created
593 593
                     '%s',
594
-                    '%s',// VNU_short_desc
595
-                    '%s',// VNU_modified
594
+                    '%s', // VNU_short_desc
595
+                    '%s', // VNU_modified
596 596
                     '%s',
597
-                    '%d',// VNU_wp_user
598
-                    '%d',// parent
599
-                    '%d',// VNU_order
600
-                    '%s',// post_type
597
+                    '%d', // VNU_wp_user
598
+                    '%d', // parent
599
+                    '%d', // VNU_order
600
+                    '%s', // post_type
601 601
                 );
602 602
         $success = $wpdb->insert(
603 603
             $wpdb->posts,
604 604
             $insertion_array,
605 605
             $datatypes_array
606 606
         );
607
-        if (! $success) {
607
+        if ( ! $success) {
608 608
             $this->add_error(
609 609
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
610 610
                     $this->_old_table,
@@ -632,13 +632,13 @@  discard block
 block discarded – undo
632 632
         // assume the country is the same as the organization's old settings
633 633
         $country_iso = $this->get_migration_script()->get_default_country_iso();
634 634
         // find the state from the venue, or the organization, or just guess california
635
-        if (! $old_event['state']) {
635
+        if ( ! $old_event['state']) {
636 636
             $old_org_options = get_option('events_organization_settings');
637 637
             $state_name = stripslashes($old_org_options['organization_state']);
638 638
         } else {
639 639
             $state_name = $old_event['state'];
640 640
         }
641
-        if (! $state_name) {
641
+        if ( ! $state_name) {
642 642
             $state_name = 'CA';
643 643
         }
644 644
         // get a state ID with the same name, if possible
@@ -651,39 +651,39 @@  discard block
 block discarded – undo
651 651
         }
652 652
         // now insert into meta table
653 653
         $insertion_array = array(
654
-            'VNU_ID'=>$cpt_id,// VNU_ID_fk
655
-            'VNU_address'=>stripslashes($old_event['address']),// VNU_address
656
-            'VNU_address2'=>stripslashes($old_event['address2']),// VNU_address2
657
-            'VNU_city'=>stripslashes($old_event['city']),// VNU_city
658
-            'STA_ID'=>$state_id,// STA_ID
659
-            'CNT_ISO'=>$country_iso,// CNT_ISO
660
-            'VNU_zip'=>$old_event['zip'],// VNU_zip
661
-            'VNU_phone'=>$old_event['venue_phone'],// VNU_phone
662
-            'VNU_capacity'=>-1,// VNU_capacity
663
-            'VNU_url'=>$old_event['venue_url'],// VNU_url
664
-            'VNU_virtual_phone'=>$old_event['virtual_phone'],// VNU_virtual_phone
665
-            'VNU_virtual_url'=>$old_event['virtual_url'],// VNU_virtual_url
666
-            'VNU_google_map_link'=>'',// VNU_google_map_link
654
+            'VNU_ID'=>$cpt_id, // VNU_ID_fk
655
+            'VNU_address'=>stripslashes($old_event['address']), // VNU_address
656
+            'VNU_address2'=>stripslashes($old_event['address2']), // VNU_address2
657
+            'VNU_city'=>stripslashes($old_event['city']), // VNU_city
658
+            'STA_ID'=>$state_id, // STA_ID
659
+            'CNT_ISO'=>$country_iso, // CNT_ISO
660
+            'VNU_zip'=>$old_event['zip'], // VNU_zip
661
+            'VNU_phone'=>$old_event['venue_phone'], // VNU_phone
662
+            'VNU_capacity'=>-1, // VNU_capacity
663
+            'VNU_url'=>$old_event['venue_url'], // VNU_url
664
+            'VNU_virtual_phone'=>$old_event['virtual_phone'], // VNU_virtual_phone
665
+            'VNU_virtual_url'=>$old_event['virtual_url'], // VNU_virtual_url
666
+            'VNU_google_map_link'=>'', // VNU_google_map_link
667 667
             'VNU_enable_for_gmap'=>true // VNU_enable_for_gmap
668 668
         );
669 669
         $datatypes = array(
670
-            '%d',// VNU_ID_fk
671
-            '%s',// VNU_address
672
-            '%s',// VNU_address2
673
-            '%s',// VNU_city
674
-            '%d',// STA_ID
675
-            '%s',// CNT_ISO
676
-            '%s',// VNU_zip
677
-            '%s',// VNU_phone
678
-            '%d',// VNU_capacity
679
-            '%s',// VNU_url
680
-            '%s',// VNU_virtual_phone
681
-            '%s',// VNU_virtual_url
682
-            '%s',// VNU_google_map_link
683
-            '%d',// VNU_enable_for_gmap
670
+            '%d', // VNU_ID_fk
671
+            '%s', // VNU_address
672
+            '%s', // VNU_address2
673
+            '%s', // VNU_city
674
+            '%d', // STA_ID
675
+            '%s', // CNT_ISO
676
+            '%s', // VNU_zip
677
+            '%s', // VNU_phone
678
+            '%d', // VNU_capacity
679
+            '%s', // VNU_url
680
+            '%s', // VNU_virtual_phone
681
+            '%s', // VNU_virtual_url
682
+            '%s', // VNU_google_map_link
683
+            '%d', // VNU_enable_for_gmap
684 684
         );
685 685
         $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
686
-        if (! $success) {
686
+        if ( ! $success) {
687 687
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
688 688
             return 0;
689 689
         }
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
701 701
     {
702 702
         global $wpdb;
703
-        if (! $new_event_id) {
703
+        if ( ! $new_event_id) {
704 704
             $this->add_error(sprintf(__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
705 705
             return 0;
706 706
         }
707
-        if (! $new_venue_id) {
707
+        if ( ! $new_venue_id) {
708 708
             $this->add_error(sprintf(__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
709 709
             return 0;
710 710
         }
@@ -714,12 +714,12 @@  discard block
 block discarded – undo
714 714
             'EVV_primary'=>true
715 715
         );
716 716
         $datatypes = array(
717
-            '%d',// EVT_ID
718
-            '%d',// VNU_ID
719
-            '%d',// EVT_primary
717
+            '%d', // EVT_ID
718
+            '%d', // VNU_ID
719
+            '%d', // EVT_primary
720 720
         );
721 721
         $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
722
-        if (! $success) {
722
+        if ( ! $success) {
723 723
             $this->add_error(
724 724
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
725 725
                     $this->_old_table,
@@ -779,29 +779,29 @@  discard block
 block discarded – undo
779 779
         $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
780 780
         $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
781 781
         $cols_n_values = array(
782
-            'EVT_ID'=>$new_cpt_id,// EVT_ID
783
-            'DTT_EVT_start'=>$start_datetime_utc,// DTT_EVT_start
784
-            'DTT_EVT_end'=> $end_datetime_utc,// DTT_EVT_end
785
-            'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
786
-            'DTT_sold'=>0,// note: we will increment this as registrations are added during the migration
782
+            'EVT_ID'=>$new_cpt_id, // EVT_ID
783
+            'DTT_EVT_start'=>$start_datetime_utc, // DTT_EVT_start
784
+            'DTT_EVT_end'=> $end_datetime_utc, // DTT_EVT_end
785
+            'DTT_reg_limit'=>intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit
786
+            'DTT_sold'=>0, // note: we will increment this as registrations are added during the migration
787 787
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
788
-            'DTT_order'=> $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
788
+            'DTT_order'=> $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist
789 789
             'DTT_parent'=>0,
790 790
             'DTT_deleted'=>false
791 791
         );
792 792
         $datatypes = array(
793
-            '%d',// EVT_Id
794
-            '%s',// DTT_EVT_start
795
-            '%s',// DTT_EVT_end
796
-            '%d',// DTT_reg_limit
797
-            '%d',// DTT_sold
793
+            '%d', // EVT_Id
794
+            '%s', // DTT_EVT_start
795
+            '%s', // DTT_EVT_end
796
+            '%d', // DTT_reg_limit
797
+            '%d', // DTT_sold
798 798
 //          '%d',//DTT_is_primary
799
-            '%d',// DTT_order
800
-            '%d',// DTT_parent
801
-            '%d',// DTT_deleted
799
+            '%d', // DTT_order
800
+            '%d', // DTT_parent
801
+            '%d', // DTT_deleted
802 802
         );
803 803
         $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
804
-        if (! $success) {
804
+        if ( ! $success) {
805 805
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
806 806
             return 0;
807 807
         }
Please login to merge, or discard this patch.