Completed
Branch EE5Update (bc64e6)
by
unknown
09:36 queued 05:38
created
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_gateways.dmsstage.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
         // convert settings
25 25
         $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
26 26
         // just do a part of them on this request
27
-        $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate;
27
+        $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items); // $this->_gateways_we_know_how_to_migrate;
28 28
         foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
29 29
             $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
30
-            if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
30
+            if (isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) {
31 31
                 // determine the old option's name
32 32
                 $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
33
-                if (! $old_gateway_settings) {
33
+                if ( ! $old_gateway_settings) {
34 34
                     // no settings existed for this gateway anyways... weird...
35 35
                     $items_actually_migrated++;
36 36
                     continue;
37 37
                 }
38 38
                 // now prepare the settings to make sure they're in the 4.1 format
39 39
                 $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug);
40
-                $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings;
40
+                $new_gateway_config_obj->payment_settings[$new_gateway_slug] = $new_gateway_settings;
41 41
                 // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
42 42
                 // I think it's ok to do right away this time (we wont need gateway settings elsewhere)
43 43
                 delete_option($old_gateway_wp_option_name);
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
                 global $wpdb;
46 46
                 // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll
47 47
                 // only be saving users 50 milliseconds the one time this runs...
48
-                $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
48
+                $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
49 49
             }
50 50
 
51 51
             $items_actually_migrated++;
52 52
         }
53 53
         // if we can keep going, and it hasn' tbeen done yet, convert active gateways
54
-        if ($items_actually_migrated < $num_items &&  ! $this->_converted_active_gateways) {
54
+        if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) {
55 55
             $this->_convert_active_gateways();
56 56
             $this->_converted_active_gateways = true;
57 57
             $items_actually_migrated++;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         $step_of_setting_active_gateways = 1;
70 70
         $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
71 71
     //  $button_images_to_update =
72
-        return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
72
+        return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
73 73
     }
74 74
     public function __construct()
75 75
     {
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     private function _get_old_gateway_option($new_gateway_slug)
120 120
     {
121 121
         $option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
122
-        $settings =  get_option($option_name, null);
122
+        $settings = get_option($option_name, null);
123 123
     //  if( ! $settings){
124 124
     //      $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
125 125
     //  }
@@ -134,36 +134,36 @@  discard block
 block discarded – undo
134 134
     private function _get_old_gateway_option_name($new_gateway_slug)
135 135
     {
136 136
         $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone));
137
-        $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ];
137
+        $old_gateway_slug = $new_gateway_slugs_to_new[$new_gateway_slug];
138 138
         $normal_option_prefix = 'event_espresso_';
139 139
         $normal_option_postfix = '_settings';
140 140
         switch ($new_gateway_slug) {
141 141
             case 'Bank':
142
-                $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix;
142
+                $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix;
143 143
                 break;
144 144
             case 'Aim':
145
-                $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix;
145
+                $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix;
146 146
                 break;
147 147
             case 'Check':
148
-                $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix;
148
+                $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix;
149 149
                 break;
150 150
             case 'Ideal':
151
-                $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix;
151
+                $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix;
152 152
                 break;
153 153
             case 'Invoice':
154
-                $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix;
154
+                $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix;
155 155
                 break;
156 156
             case 'Purchase_Order':
157
-                $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix;
157
+                $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix;
158 158
                 break;
159 159
             case 'USAePay_Offsite':
160
-                $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix;
160
+                $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix;
161 161
                 break;
162 162
             case 'USAePay_Onsite':
163
-                $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix;
163
+                $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix;
164 164
                 break;
165 165
             default:
166
-                $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix);
166
+                $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix);
167 167
         }
168 168
         return $option_name;
169 169
     }
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
         $old_active_gateways = get_option('event_espresso_active_gateways');
175 175
         $new_active_gateways = EE_Config::instance()->gateway->active_gateways;
176 176
         foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
177
-            if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
177
+            if ( ! isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) {
178 178
                 $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
179 179
                 continue;
180 180
             }
181
-            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
181
+            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[$old_gateway_slug];
182 182
 
183 183
             // in the new format we can also upload gateways to the uploads directory and
184
-            $new_active_gateways[ $new_gateway_slug ] = false;
184
+            $new_active_gateways[$new_gateway_slug] = false;
185 185
         }
186 186
         EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
187 187
     }
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -13,68 +13,68 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage
15 15
 {
16
-    private $_converted_active_gateways = false;
16
+	private $_converted_active_gateways = false;
17 17
 
18
-    public function _migration_step($num_items = 50)
19
-    {
20
-        // loads existing EE_CONfig from DB, if it exists
21
-        $new_gateway_config_obj = EE_Config::instance()->gateway;
22
-        $items_actually_migrated = 0;
23
-        // convert settings
24
-        $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
25
-        // just do a part of them on this request
26
-        $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate;
27
-        foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
28
-            $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
29
-            if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
30
-                // determine the old option's name
31
-                $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
32
-                if (! $old_gateway_settings) {
33
-                    // no settings existed for this gateway anyways... weird...
34
-                    $items_actually_migrated++;
35
-                    continue;
36
-                }
37
-                // now prepare the settings to make sure they're in the 4.1 format
38
-                $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug);
39
-                $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings;
40
-                // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
41
-                // I think it's ok to do right away this time (we wont need gateway settings elsewhere)
42
-                delete_option($old_gateway_wp_option_name);
43
-            } else {// it must be one of the ones we mostly leave alone
44
-                global $wpdb;
45
-                // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll
46
-                // only be saving users 50 milliseconds the one time this runs...
47
-                $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
48
-            }
18
+	public function _migration_step($num_items = 50)
19
+	{
20
+		// loads existing EE_CONfig from DB, if it exists
21
+		$new_gateway_config_obj = EE_Config::instance()->gateway;
22
+		$items_actually_migrated = 0;
23
+		// convert settings
24
+		$gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
25
+		// just do a part of them on this request
26
+		$gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate;
27
+		foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
28
+			$old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
29
+			if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
30
+				// determine the old option's name
31
+				$old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
32
+				if (! $old_gateway_settings) {
33
+					// no settings existed for this gateway anyways... weird...
34
+					$items_actually_migrated++;
35
+					continue;
36
+				}
37
+				// now prepare the settings to make sure they're in the 4.1 format
38
+				$new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug);
39
+				$new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings;
40
+				// and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
41
+				// I think it's ok to do right away this time (we wont need gateway settings elsewhere)
42
+				delete_option($old_gateway_wp_option_name);
43
+			} else {// it must be one of the ones we mostly leave alone
44
+				global $wpdb;
45
+				// yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll
46
+				// only be saving users 50 milliseconds the one time this runs...
47
+				$wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
48
+			}
49 49
 
50
-            $items_actually_migrated++;
51
-        }
52
-        // if we can keep going, and it hasn' tbeen done yet, convert active gateways
53
-        if ($items_actually_migrated < $num_items &&  ! $this->_converted_active_gateways) {
54
-            $this->_convert_active_gateways();
55
-            $this->_converted_active_gateways = true;
56
-            $items_actually_migrated++;
57
-        }
50
+			$items_actually_migrated++;
51
+		}
52
+		// if we can keep going, and it hasn' tbeen done yet, convert active gateways
53
+		if ($items_actually_migrated < $num_items &&  ! $this->_converted_active_gateways) {
54
+			$this->_convert_active_gateways();
55
+			$this->_converted_active_gateways = true;
56
+			$items_actually_migrated++;
57
+		}
58 58
 
59
-        EE_Config::instance()->update_espresso_config(false, false);
60
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
61
-            $this->set_completed();
62
-        }
63
-        return $items_actually_migrated;
64
-    }
65
-    public function _count_records_to_migrate()
66
-    {
67
-        $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate);
68
-        $step_of_setting_active_gateways = 1;
69
-        $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
70
-    //  $button_images_to_update =
71
-        return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
72
-    }
73
-    public function __construct()
74
-    {
75
-        $this->_pretty_name = esc_html__("Gateways", "event_espresso");
76
-        parent::__construct();
77
-    }
59
+		EE_Config::instance()->update_espresso_config(false, false);
60
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
61
+			$this->set_completed();
62
+		}
63
+		return $items_actually_migrated;
64
+	}
65
+	public function _count_records_to_migrate()
66
+	{
67
+		$count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate);
68
+		$step_of_setting_active_gateways = 1;
69
+		$count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
70
+	//  $button_images_to_update =
71
+		return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
72
+	}
73
+	public function __construct()
74
+	{
75
+		$this->_pretty_name = esc_html__("Gateways", "event_espresso");
76
+		parent::__construct();
77
+	}
78 78
 
79 79
 /**
80 80
  * Takes the old array of 3.1 gateway settings for this gateway and converts it
@@ -84,148 +84,148 @@  discard block
 block discarded – undo
84 84
  * @param string $new_gateway_slug
85 85
  * @return array
86 86
  */
87
-    private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug)
88
-    {
89
-        $new_gateway_settings = $old_gateway_settings;
90
-        switch ($new_gateway_slug) {
91
-            case 'Bank':
92
-                $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account'];
93
-                $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title'];
94
-                break;
95
-            case 'Invoice':
96
-                $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url'];
97
-                // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4
98
-                // it gets used in the receipts which are available to everyone. So usually it's best to not
99
-                // migrate this.
100
-                unset($new_gateway_settings['payment_address']);
101
-                break;
102
-            case 'Paypal_Pro':
103
-                $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email'];
104
-                $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username'];
105
-                $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password'];
106
-                $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature'];
107
-                $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']);
108
-                $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox'];
109
-                break;
110
-        }
111
-        return $new_gateway_settings;
112
-    }
87
+	private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug)
88
+	{
89
+		$new_gateway_settings = $old_gateway_settings;
90
+		switch ($new_gateway_slug) {
91
+			case 'Bank':
92
+				$new_gateway_settings['account_number'] = $old_gateway_settings['bank_account'];
93
+				$new_gateway_settings['page_title'] = $old_gateway_settings['bank_title'];
94
+				break;
95
+			case 'Invoice':
96
+				$new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url'];
97
+				// Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4
98
+				// it gets used in the receipts which are available to everyone. So usually it's best to not
99
+				// migrate this.
100
+				unset($new_gateway_settings['payment_address']);
101
+				break;
102
+			case 'Paypal_Pro':
103
+				$new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email'];
104
+				$new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username'];
105
+				$new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password'];
106
+				$new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature'];
107
+				$new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']);
108
+				$new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox'];
109
+				break;
110
+		}
111
+		return $new_gateway_settings;
112
+	}
113 113
 /**
114
- * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway
115
- * @param string $new_gateway_slug
116
- * @return string
117
- */
118
-    private function _get_old_gateway_option($new_gateway_slug)
119
-    {
120
-        $option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
121
-        $settings =  get_option($option_name, null);
122
-    //  if( ! $settings){
123
-    //      $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
124
-    //  }
125
-        return $settings;
126
-    }
114
+	 * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway
115
+	 * @param string $new_gateway_slug
116
+	 * @return string
117
+	 */
118
+	private function _get_old_gateway_option($new_gateway_slug)
119
+	{
120
+		$option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
121
+		$settings =  get_option($option_name, null);
122
+	//  if( ! $settings){
123
+	//      $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
124
+	//  }
125
+		return $settings;
126
+	}
127 127
 
128 128
 /**
129 129
  * Just gets the old gateways slug
130 130
  * @param string $new_gateway_slug
131 131
  * @return string
132 132
  */
133
-    private function _get_old_gateway_option_name($new_gateway_slug)
134
-    {
135
-        $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone));
136
-        $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ];
137
-        $normal_option_prefix = 'event_espresso_';
138
-        $normal_option_postfix = '_settings';
139
-        switch ($new_gateway_slug) {
140
-            case 'Bank':
141
-                $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix;
142
-                break;
143
-            case 'Aim':
144
-                $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix;
145
-                break;
146
-            case 'Check':
147
-                $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix;
148
-                break;
149
-            case 'Ideal':
150
-                $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix;
151
-                break;
152
-            case 'Invoice':
153
-                $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix;
154
-                break;
155
-            case 'Purchase_Order':
156
-                $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix;
157
-                break;
158
-            case 'USAePay_Offsite':
159
-                $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix;
160
-                break;
161
-            case 'USAePay_Onsite':
162
-                $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix;
163
-                break;
164
-            default:
165
-                $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix);
166
-        }
167
-        return $option_name;
168
-    }
133
+	private function _get_old_gateway_option_name($new_gateway_slug)
134
+	{
135
+		$new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone));
136
+		$old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ];
137
+		$normal_option_prefix = 'event_espresso_';
138
+		$normal_option_postfix = '_settings';
139
+		switch ($new_gateway_slug) {
140
+			case 'Bank':
141
+				$option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix;
142
+				break;
143
+			case 'Aim':
144
+				$option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix;
145
+				break;
146
+			case 'Check':
147
+				$option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix;
148
+				break;
149
+			case 'Ideal':
150
+				$option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix;
151
+				break;
152
+			case 'Invoice':
153
+				$option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix;
154
+				break;
155
+			case 'Purchase_Order':
156
+				$option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix;
157
+				break;
158
+			case 'USAePay_Offsite':
159
+				$option_name = 'espresso_usaepay_offsite' . $normal_option_postfix;
160
+				break;
161
+			case 'USAePay_Onsite':
162
+				$option_name = 'espresso_usaepay_onsite' . $normal_option_postfix;
163
+				break;
164
+			default:
165
+				$option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix);
166
+		}
167
+		return $option_name;
168
+	}
169 169
 
170
-    private function _convert_active_gateways()
171
-    {
172
-        // just does it all one big swoop
173
-        $old_active_gateways = get_option('event_espresso_active_gateways');
174
-        $new_active_gateways = EE_Config::instance()->gateway->active_gateways;
175
-        foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
176
-            if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
177
-                $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
178
-                continue;
179
-            }
180
-            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
170
+	private function _convert_active_gateways()
171
+	{
172
+		// just does it all one big swoop
173
+		$old_active_gateways = get_option('event_espresso_active_gateways');
174
+		$new_active_gateways = EE_Config::instance()->gateway->active_gateways;
175
+		foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
176
+			if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
177
+				$this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
178
+				continue;
179
+			}
180
+			$new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
181 181
 
182
-            // in the new format we can also upload gateways to the uploads directory and
183
-            $new_active_gateways[ $new_gateway_slug ] = false;
184
-        }
185
-        EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
186
-    }
182
+			// in the new format we can also upload gateways to the uploads directory and
183
+			$new_active_gateways[ $new_gateway_slug ] = false;
184
+		}
185
+		EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
186
+	}
187 187
 
188
-    protected $_gateways_we_know_how_to_migrate = array(
189
-        'aim' => 'Aim',
190
-        'bank' => 'Bank',
191
-        'check' => 'Check',
192
-        'invoice' => 'Invoice',
193
-        'paypal' => 'Paypal_Standard',
194
-        'paypal_pro' => 'Paypal_Pro',
188
+	protected $_gateways_we_know_how_to_migrate = array(
189
+		'aim' => 'Aim',
190
+		'bank' => 'Bank',
191
+		'check' => 'Check',
192
+		'invoice' => 'Invoice',
193
+		'paypal' => 'Paypal_Standard',
194
+		'paypal_pro' => 'Paypal_Pro',
195 195
 
196
-    );
196
+	);
197 197
 
198
-    protected $_gateways_we_leave_alone = array(
199
-        '2checkout' => '2checkout',
200
-        'anz' => 'Anz',
201
-        'atos' => 'Atos',
202
-        'authnet' => 'Authnet',
203
-        'beanstream' => 'Beanstream',
204
-        'evertec' => 'Evertec',
205
-        'eway' => 'Eway',
206
-        'eway_rapid3' => 'Eway_Rapid3',
207
-        'exact' => 'Exact',
208
-        'firstdata' => 'Firstdata',
209
-        'firstdat_e4' => 'Firstdata_E4',
210
-        'ideal' => 'Ideal',
211
-        'infusion_payment' => 'InfusionSoft',
212
-        'luottokunta' => 'Luottokunta',
213
-        'megasoft' => 'Megasoft',
214
-        'moneris_hpp' => 'Moneris_HPP',
215
-        'mwarrior' => 'Mwarrior',
216
-        'nab' => 'NAB',
217
-        'paychoice' => 'Paychoice',
218
-        'paytrace' => 'Paytrace',
219
-        'psigate' => 'Psigate',
220
-        'purchase_order' => 'Purchase_Order',
221
-        'qbms' => 'QBMS',
222
-        'quickpay' => 'Quickpay',
223
-        'realauth' => 'Realauth',
224
-        'securepay_aus' => 'Securepay_Aus',
225
-        'stripe' => 'Stripe',
226
-        'usaepay_offsite' => 'USAePay_Offsite',
227
-        'usaepay_onsite' => 'USAePay_Onsite',
228
-        'wepay' => 'Wepay',
229
-        'worldpay' => 'Worldpay'
230
-    );
198
+	protected $_gateways_we_leave_alone = array(
199
+		'2checkout' => '2checkout',
200
+		'anz' => 'Anz',
201
+		'atos' => 'Atos',
202
+		'authnet' => 'Authnet',
203
+		'beanstream' => 'Beanstream',
204
+		'evertec' => 'Evertec',
205
+		'eway' => 'Eway',
206
+		'eway_rapid3' => 'Eway_Rapid3',
207
+		'exact' => 'Exact',
208
+		'firstdata' => 'Firstdata',
209
+		'firstdat_e4' => 'Firstdata_E4',
210
+		'ideal' => 'Ideal',
211
+		'infusion_payment' => 'InfusionSoft',
212
+		'luottokunta' => 'Luottokunta',
213
+		'megasoft' => 'Megasoft',
214
+		'moneris_hpp' => 'Moneris_HPP',
215
+		'mwarrior' => 'Mwarrior',
216
+		'nab' => 'NAB',
217
+		'paychoice' => 'Paychoice',
218
+		'paytrace' => 'Paytrace',
219
+		'psigate' => 'Psigate',
220
+		'purchase_order' => 'Purchase_Order',
221
+		'qbms' => 'QBMS',
222
+		'quickpay' => 'Quickpay',
223
+		'realauth' => 'Realauth',
224
+		'securepay_aus' => 'Securepay_Aus',
225
+		'stripe' => 'Stripe',
226
+		'usaepay_offsite' => 'USAePay_Offsite',
227
+		'usaepay_onsite' => 'USAePay_Onsite',
228
+		'wepay' => 'Wepay',
229
+		'worldpay' => 'Worldpay'
230
+	);
231 231
 }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_event_category.dmsstage.php 2 patches
Indentation   +76 added lines, -78 removed lines patch added patch discarded remove patch
@@ -24,87 +24,85 @@
 block discarded – undo
24 24
                 'term_taxonomy_id'=>new EE_Foreign_Key_Int_Field('term_taxonomy_id', esc_html__('Term (in context of a taxonomy) ID','event_espresso'), false, 0, 'Term_Taxonomy'),
25 25
                 'term_order'=>new EE_Integer_Field('term_order', esc_html__('Term Order','event_espresso'), false, 0)
26 26
             ));
27
-
28
-
29 27
  *
30 28
  */
31 29
 class EE_DMS_4_1_0_event_category extends EE_Data_Migration_Script_Stage
32 30
 {
33
-    private $_old_table;
34
-    private $_new_table;
35
-    public function _migration_step($num_items = 50)
36
-    {
37
-        global $wpdb;
38
-        $start_at_record = $this->count_records_migrated();
39
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
40
-        $items_actually_migrated = 0;
41
-        foreach ($rows as $event_venue_rel) {
42
-            $term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel);
43
-            if ($term_relation_id) {
44
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id);
45
-            }
46
-            $items_actually_migrated++;
47
-        }
48
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
49
-            $this->set_completed();
50
-        }
51
-        return $items_actually_migrated;
52
-    }
53
-    public function _count_records_to_migrate()
54
-    {
55
-        global $wpdb;
56
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
57
-        return $count;
58
-    }
59
-    public function __construct()
60
-    {
61
-        global $wpdb;
62
-        $this->_old_table = $wpdb->prefix . "events_category_rel";
63
-        $this->_new_table = $wpdb->prefix . "term_relationships";
64
-        $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso");
65
-        parent::__construct();
66
-    }
31
+	private $_old_table;
32
+	private $_new_table;
33
+	public function _migration_step($num_items = 50)
34
+	{
35
+		global $wpdb;
36
+		$start_at_record = $this->count_records_migrated();
37
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
+		$items_actually_migrated = 0;
39
+		foreach ($rows as $event_venue_rel) {
40
+			$term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel);
41
+			if ($term_relation_id) {
42
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id);
43
+			}
44
+			$items_actually_migrated++;
45
+		}
46
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
47
+			$this->set_completed();
48
+		}
49
+		return $items_actually_migrated;
50
+	}
51
+	public function _count_records_to_migrate()
52
+	{
53
+		global $wpdb;
54
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
55
+		return $count;
56
+	}
57
+	public function __construct()
58
+	{
59
+		global $wpdb;
60
+		$this->_old_table = $wpdb->prefix . "events_category_rel";
61
+		$this->_new_table = $wpdb->prefix . "term_relationships";
62
+		$this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso");
63
+		parent::__construct();
64
+	}
67 65
 
68
-    /**
69
-     * Attempts to insert a new question group inthe new format given an old one
70
-     * @global type $wpdb
71
-     * @param array $old_event_cat_relation
72
-     * @return int
73
-     */
74
-    private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation)
75
-    {
76
-        global $wpdb;
77
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts");
78
-        $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy");
79
-        if (! $new_event_id) {
80
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id']));
81
-            return 0;
82
-        }
83
-        if (! $new_term_taxonomy_id) {
84
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id']));
85
-            return 0;
86
-        }
87
-        $cols_n_values = array(
88
-            'object_id' => $new_event_id,
89
-            'term_taxonomy_id' => $new_term_taxonomy_id,
90
-            'term_order' => 0
91
-        );
92
-        $datatypes = array(
93
-            '%d',// object_id
94
-            '%d',// term_taxonomy_id
95
-            '%d',// term_order
96
-        );
97
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
98
-        if (! $success) {
99
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes));
100
-            return 0;
101
-        } else {
102
-            // increment the term-taxonomie's count
103
-            $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id));
104
-            if (! $success) {
105
-                $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error));
106
-            }
107
-        }
108
-        return $wpdb->insert_id;
109
-    }
66
+	/**
67
+	 * Attempts to insert a new question group inthe new format given an old one
68
+	 * @global type $wpdb
69
+	 * @param array $old_event_cat_relation
70
+	 * @return int
71
+	 */
72
+	private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation)
73
+	{
74
+		global $wpdb;
75
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts");
76
+		$new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy");
77
+		if (! $new_event_id) {
78
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id']));
79
+			return 0;
80
+		}
81
+		if (! $new_term_taxonomy_id) {
82
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id']));
83
+			return 0;
84
+		}
85
+		$cols_n_values = array(
86
+			'object_id' => $new_event_id,
87
+			'term_taxonomy_id' => $new_term_taxonomy_id,
88
+			'term_order' => 0
89
+		);
90
+		$datatypes = array(
91
+			'%d',// object_id
92
+			'%d',// term_taxonomy_id
93
+			'%d',// term_order
94
+		);
95
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
96
+		if (! $success) {
97
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes));
98
+			return 0;
99
+		} else {
100
+			// increment the term-taxonomie's count
101
+			$success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id));
102
+			if (! $success) {
103
+				$this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error));
104
+			}
105
+		}
106
+		return $wpdb->insert_id;
107
+	}
110 108
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
     public function _count_records_to_migrate()
54 54
     {
55 55
         global $wpdb;
56
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
56
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
57 57
         return $count;
58 58
     }
59 59
     public function __construct()
60 60
     {
61 61
         global $wpdb;
62
-        $this->_old_table = $wpdb->prefix . "events_category_rel";
63
-        $this->_new_table = $wpdb->prefix . "term_relationships";
62
+        $this->_old_table = $wpdb->prefix."events_category_rel";
63
+        $this->_new_table = $wpdb->prefix."term_relationships";
64 64
         $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso");
65 65
         parent::__construct();
66 66
     }
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
     private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation)
75 75
     {
76 76
         global $wpdb;
77
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts");
78
-        $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy");
79
-        if (! $new_event_id) {
77
+        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix."posts");
78
+        $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix."term_taxonomy");
79
+        if ( ! $new_event_id) {
80 80
             $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id']));
81 81
             return 0;
82 82
         }
83
-        if (! $new_term_taxonomy_id) {
83
+        if ( ! $new_term_taxonomy_id) {
84 84
             $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id']));
85 85
             return 0;
86 86
         }
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
             'term_order' => 0
91 91
         );
92 92
         $datatypes = array(
93
-            '%d',// object_id
94
-            '%d',// term_taxonomy_id
95
-            '%d',// term_order
93
+            '%d', // object_id
94
+            '%d', // term_taxonomy_id
95
+            '%d', // term_order
96 96
         );
97 97
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
98
-        if (! $success) {
98
+        if ( ! $success) {
99 99
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes));
100 100
             return 0;
101 101
         } else {
102 102
             // increment the term-taxonomie's count
103 103
             $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id));
104
-            if (! $success) {
104
+            if ( ! $success) {
105 105
                 $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error));
106 106
             }
107 107
         }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_events.dmsstage.php 2 patches
Indentation   +635 added lines, -640 removed lines patch added patch discarded remove patch
@@ -85,8 +85,6 @@  discard block
 block discarded – undo
85 85
   KEY `submitted` (`submitted`),
86 86
   KEY `likes` (`likes`)
87 87
 ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$
88
-
89
-
90 88
  *
91 89
  * 4.1 Event model:
92 90
  * $this->_tables = array(
@@ -125,7 +123,6 @@  discard block
 block discarded – undo
125 123
                 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', esc_html__("Accept Donations?", "event_espresso"), false, false)
126 124
 
127 125
             ));
128
-
129 126
  *
130 127
  * 3.1's start end table
131 128
  *
@@ -138,8 +135,6 @@  discard block
 block discarded – undo
138 135
   PRIMARY KEY (`id`),
139 136
   KEY `event_id` (`event_id`)
140 137
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$
141
-
142
-
143 138
  *
144 139
  * and 4.1 Datetime model's tables and fields:
145 140
  * $this->_tables = array(
@@ -161,172 +156,172 @@  discard block
 block discarded – undo
161 156
  */
162 157
 class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage
163 158
 {
164
-    private $_old_table;
165
-    private $_old_start_end_table;
166
-    private $_new_table;
167
-    private $_new_meta_table;
168
-    private $_new_datetime_table;
169
-
170
-
171
-
172
-    /**
173
-     * Just initializes the status of the migration
174
-     * @throws EE_Error
175
-     */
176
-    public function __construct()
177
-    {
178
-        global $wpdb;
179
-        $this->_old_table = $wpdb->prefix . "events_detail";
180
-        $this->_old_start_end_table = $wpdb->prefix . "events_start_end";
181
-        $this->_new_table = $wpdb->prefix . "posts";
182
-        $this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
183
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
184
-        $this->_pretty_name = esc_html__("Events", "event_espresso");
185
-        parent::__construct();
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * Counts the records to migrate; the public version may cache it
192
-     * @return int
193
-     */
194
-    public function _count_records_to_migrate()
195
-    {
196
-        global $wpdb;
197
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
198
-        return intval($count);
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
205
-     * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
206
-     * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
207
-     * 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,
208
-     * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
209
-     * @param int $num_items_to_migrate
210
-     * @return int number of items ACTUALLY migrated
211
-     */
212
-    protected function _migration_step($num_items_to_migrate = 50)
213
-    {
214
-        global $wpdb;
215
-        // because the migration of each event can be a LOT more work, make each step smaller
216
-        $num_items_to_migrate = max(1, $num_items_to_migrate / 5);
217
-        $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
218
-        $items_migrated_this_step = 0;
219
-
220
-        foreach ($events as $event_row) {
221
-            $guid = null;
222
-            // insert new 4.1 Attendee object using $wpdb
223
-            $post_id = $this->_insert_cpt($event_row);
224
-            if ($post_id) {
225
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
226
-                $meta_id = $this->_insert_event_meta($event_row, $post_id);
227
-                if ($meta_id) {
228
-                    $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
229
-                }
230
-                $this->_convert_start_end_times($event_row, $post_id);
231
-                $event_meta = maybe_unserialize($event_row['event_meta']);
232
-                $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
233
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
234
-
235
-                // maybe create a venue from info on the event?
236
-                $new_venue_id = $this->_maybe_create_venue($event_row);
237
-                if ($new_venue_id) {
238
-                    $this->_insert_new_venue_to_event($post_id, $new_venue_id);
239
-                }
240
-                $this->_add_post_metas($event_row, $post_id);
241
-            }
242
-            $items_migrated_this_step++;
243
-            if ($guid) {
244
-                // if we had to check for an image attachment
245
-                // then let's call it a day (avoid timing out, because this took a long time)
246
-                break;
247
-            }
248
-        }
249
-        if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
250
-            $this->set_status(EE_Data_Migration_Manager::status_completed);
251
-        }
252
-        return $items_migrated_this_step;
253
-    }
254
-
255
-    /**
256
-     * Stores any extra 3.1 "event_meta" column things as post meta
257
-     * @param array $old_event
258
-     * @param int $post_id
259
-     * @return void
260
-     */
261
-    private function _add_post_metas($old_event, $post_id)
262
-    {
263
-        $event_meta = maybe_unserialize($old_event['event_meta']);
264
-        if (! $event_meta || ! is_array($event_meta)) {
265
-            return;
266
-        }
267
-        unset($event_meta['date_submitted']);// factored into CPT
268
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
269
-        unset($event_meta['default_payment_status']);// dido
270
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
271
-        foreach ($event_meta as $meta_key => $meta_value) {
272
-            if ($meta_key) {// if the meta key is just an empty string, ignore it
273
-                $success = add_post_meta($post_id, $meta_key, $meta_value, true);
274
-                if (! $success) {
275
-                    $this->add_error(sprintf(esc_html__("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)));
276
-                }
277
-            }
278
-        }
279
-        if ($old_event['alt_email']) {
280
-            add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
281
-        }
282
-        if ($old_event['recurrence_id']) {
283
-            add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
284
-        }
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Finds a unique slug for this event, given its name (we could have simply used
291
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
292
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
293
-     * @param string $event_name (the name of the event for reading by humans)
294
-     * @param string $old_identifier the old EE3 identifier (a long unique string)
295
-     * @param string $new_post_status a post status
296
-     * @return string
297
-     */
298
-    private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
299
-    {
300
-        $count = 0;
301
-        $original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
302
-        return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
303
-    }
304
-
305
-    /**
306
-     * returns whether or not there is a post that has this same slug (post_title)
307
-     * @global wpdb $wpdb
308
-     * @param string $slug
309
-     * @return boolean
310
-     */
311
-    private function _other_post_exists_with_that_slug($slug)
312
-    {
313
-        global $wpdb;
314
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
315
-        $count = $wpdb->get_var($query);
316
-        return (bool) intval($count);
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * @param $old_event
323
-     * @return int
324
-     */
325
-    private function _insert_cpt($old_event)
326
-    {
327
-        global $wpdb;
328
-        // convert 3.1 event status to 4.1 CPT status
329
-        // for reference, 3.1 event stati available for setting are:
159
+	private $_old_table;
160
+	private $_old_start_end_table;
161
+	private $_new_table;
162
+	private $_new_meta_table;
163
+	private $_new_datetime_table;
164
+
165
+
166
+
167
+	/**
168
+	 * Just initializes the status of the migration
169
+	 * @throws EE_Error
170
+	 */
171
+	public function __construct()
172
+	{
173
+		global $wpdb;
174
+		$this->_old_table = $wpdb->prefix . "events_detail";
175
+		$this->_old_start_end_table = $wpdb->prefix . "events_start_end";
176
+		$this->_new_table = $wpdb->prefix . "posts";
177
+		$this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
178
+		$this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
179
+		$this->_pretty_name = esc_html__("Events", "event_espresso");
180
+		parent::__construct();
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Counts the records to migrate; the public version may cache it
187
+	 * @return int
188
+	 */
189
+	public function _count_records_to_migrate()
190
+	{
191
+		global $wpdb;
192
+		$count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
193
+		return intval($count);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
200
+	 * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
201
+	 * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
202
+	 * 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,
203
+	 * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
204
+	 * @param int $num_items_to_migrate
205
+	 * @return int number of items ACTUALLY migrated
206
+	 */
207
+	protected function _migration_step($num_items_to_migrate = 50)
208
+	{
209
+		global $wpdb;
210
+		// because the migration of each event can be a LOT more work, make each step smaller
211
+		$num_items_to_migrate = max(1, $num_items_to_migrate / 5);
212
+		$events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
213
+		$items_migrated_this_step = 0;
214
+
215
+		foreach ($events as $event_row) {
216
+			$guid = null;
217
+			// insert new 4.1 Attendee object using $wpdb
218
+			$post_id = $this->_insert_cpt($event_row);
219
+			if ($post_id) {
220
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
221
+				$meta_id = $this->_insert_event_meta($event_row, $post_id);
222
+				if ($meta_id) {
223
+					$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
224
+				}
225
+				$this->_convert_start_end_times($event_row, $post_id);
226
+				$event_meta = maybe_unserialize($event_row['event_meta']);
227
+				$guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
228
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
229
+
230
+				// maybe create a venue from info on the event?
231
+				$new_venue_id = $this->_maybe_create_venue($event_row);
232
+				if ($new_venue_id) {
233
+					$this->_insert_new_venue_to_event($post_id, $new_venue_id);
234
+				}
235
+				$this->_add_post_metas($event_row, $post_id);
236
+			}
237
+			$items_migrated_this_step++;
238
+			if ($guid) {
239
+				// if we had to check for an image attachment
240
+				// then let's call it a day (avoid timing out, because this took a long time)
241
+				break;
242
+			}
243
+		}
244
+		if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
245
+			$this->set_status(EE_Data_Migration_Manager::status_completed);
246
+		}
247
+		return $items_migrated_this_step;
248
+	}
249
+
250
+	/**
251
+	 * Stores any extra 3.1 "event_meta" column things as post meta
252
+	 * @param array $old_event
253
+	 * @param int $post_id
254
+	 * @return void
255
+	 */
256
+	private function _add_post_metas($old_event, $post_id)
257
+	{
258
+		$event_meta = maybe_unserialize($old_event['event_meta']);
259
+		if (! $event_meta || ! is_array($event_meta)) {
260
+			return;
261
+		}
262
+		unset($event_meta['date_submitted']);// factored into CPT
263
+		unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
264
+		unset($event_meta['default_payment_status']);// dido
265
+		unset($event_meta['event_thumbnail_url']);// used to find post featured image
266
+		foreach ($event_meta as $meta_key => $meta_value) {
267
+			if ($meta_key) {// if the meta key is just an empty string, ignore it
268
+				$success = add_post_meta($post_id, $meta_key, $meta_value, true);
269
+				if (! $success) {
270
+					$this->add_error(sprintf(esc_html__("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)));
271
+				}
272
+			}
273
+		}
274
+		if ($old_event['alt_email']) {
275
+			add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
276
+		}
277
+		if ($old_event['recurrence_id']) {
278
+			add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
279
+		}
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * Finds a unique slug for this event, given its name (we could have simply used
286
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
287
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
288
+	 * @param string $event_name (the name of the event for reading by humans)
289
+	 * @param string $old_identifier the old EE3 identifier (a long unique string)
290
+	 * @param string $new_post_status a post status
291
+	 * @return string
292
+	 */
293
+	private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
294
+	{
295
+		$count = 0;
296
+		$original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
297
+		return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
298
+	}
299
+
300
+	/**
301
+	 * returns whether or not there is a post that has this same slug (post_title)
302
+	 * @global wpdb $wpdb
303
+	 * @param string $slug
304
+	 * @return boolean
305
+	 */
306
+	private function _other_post_exists_with_that_slug($slug)
307
+	{
308
+		global $wpdb;
309
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
310
+		$count = $wpdb->get_var($query);
311
+		return (bool) intval($count);
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param $old_event
318
+	 * @return int
319
+	 */
320
+	private function _insert_cpt($old_event)
321
+	{
322
+		global $wpdb;
323
+		// convert 3.1 event status to 4.1 CPT status
324
+		// for reference, 3.1 event stati available for setting are:
330 325
 //      $status = array(array('id' => 'A', 'text' => esc_html__('Public', 'event_espresso')), array('id' => 'S', 'text' => esc_html__('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => esc_html__('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => esc_html__('Draft', 'event_espresso')), array('id' => 'D', 'text' => esc_html__('Deleted', 'event_espresso')));
331 326
 //      and the json api uses the following to convert from 3.1 to 4.0
332 327
 //      'S'=>'secondary/waitlist',
@@ -340,487 +335,487 @@  discard block
 block discarded – undo
340 335
 //      4.1 Event Post stati are the normal post statis
341 336
 //      (publish,future,draft,pending,private,trash,auto-draft,inherit)
342 337
 //      and 3 custom ones: cancelled,postponed,sold_out
343
-        $status_conversions = array(
344
-            'R' => 'draft',
345
-            'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
346
-            'P' => 'pending',
347
-            'IA' => 'draft',// draft and in the past
338
+		$status_conversions = array(
339
+			'R' => 'draft',
340
+			'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
341
+			'P' => 'pending',
342
+			'IA' => 'draft',// draft and in the past
348 343
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
349
-            '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'
350
-            'A' => 'publish',
351
-            'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
352
-            'D' => 'trash',
353
-        );
354
-        $post_status = $status_conversions[ $old_event['event_status'] ];
355
-        // check if we've sold out
356
-        if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
357
-            $post_status = 'sold_out';
358
-        }
344
+			'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'
345
+			'A' => 'publish',
346
+			'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
347
+			'D' => 'trash',
348
+		);
349
+		$post_status = $status_conversions[ $old_event['event_status'] ];
350
+		// check if we've sold out
351
+		if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
352
+			$post_status = 'sold_out';
353
+		}
359 354
 //      FYI postponed and cancelled don't exist in 3.1
360
-        $cols_n_values = array(
361
-            'post_title' => stripslashes($old_event['event_name']),// EVT_name
362
-            'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
363
-            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
364
-            'post_date' => $old_event['submitted'],// EVT_created NOT
365
-            'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
366
-            'post_excerpt' => '',// EVT_short_desc
367
-            'post_modified' => $old_event['submitted'],// EVT_modified
368
-            'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
369
-            'post_author' => $old_event['wp_user'],// EVT_wp_user
370
-            'post_parent' => 0,// parent maybe get this from some REM field?
371
-            'menu_order' => 0,// EVT_order
372
-            'post_type' => 'espresso_events',// post_type
373
-            'post_status' => $post_status,// status
374
-        );
375
-        $cols_n_values_with_no_invalid_text = array();
376
-        foreach ($cols_n_values as $col => $value) {
377
-            $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
378
-            if (! is_wp_error($value_sans_invalid_chars)) {
379
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
380
-            } else {
381
-                // otherwise leave it as-is. It will blow everything up and stop the migration
382
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
383
-            }
384
-        }
385
-        $cols_n_values = $cols_n_values_with_no_invalid_text;
386
-        $datatypes = array(
387
-            '%s',// EVT_name
388
-            '%s',// EVT_desc
389
-            '%s',// EVT_slug
390
-            '%s',// EVT_created
391
-            '%s',
392
-            '%s',// EVT_short_desc
393
-            '%s',// EVT_modified
394
-            '%s',
395
-            '%s',// EVT_wp_user
396
-            '%d',// post_parent
397
-            '%d',// EVT_order
398
-            '%s',// post_type
399
-            '%s',// status
400
-        );
401
-        $success = $wpdb->insert(
402
-            $this->_new_table,
403
-            $cols_n_values,
404
-            $datatypes
405
-        );
406
-        if (! $success) {
407
-            $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));
408
-            return 0;
409
-        }
410
-        return $wpdb->insert_id;
411
-    }
412
-
413
-    /**
414
-     * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
415
-     * @global wpdb $wpdb
416
-     * @param int $event_id
417
-     * @return int
418
-     */
419
-    public static function count_registrations($event_id)
420
-    {
421
-        global $wpdb;
422
-        $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
423
-        return intval($count);
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @param $old_event
430
-     * @param $new_cpt_id
431
-     * @return int
432
-     */
433
-    private function _insert_event_meta($old_event, $new_cpt_id)
434
-    {
435
-        global $wpdb;
436
-        $event_meta = maybe_unserialize($old_event['event_meta']);
355
+		$cols_n_values = array(
356
+			'post_title' => stripslashes($old_event['event_name']),// EVT_name
357
+			'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
358
+			'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
359
+			'post_date' => $old_event['submitted'],// EVT_created NOT
360
+			'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
361
+			'post_excerpt' => '',// EVT_short_desc
362
+			'post_modified' => $old_event['submitted'],// EVT_modified
363
+			'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
364
+			'post_author' => $old_event['wp_user'],// EVT_wp_user
365
+			'post_parent' => 0,// parent maybe get this from some REM field?
366
+			'menu_order' => 0,// EVT_order
367
+			'post_type' => 'espresso_events',// post_type
368
+			'post_status' => $post_status,// status
369
+		);
370
+		$cols_n_values_with_no_invalid_text = array();
371
+		foreach ($cols_n_values as $col => $value) {
372
+			$value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
373
+			if (! is_wp_error($value_sans_invalid_chars)) {
374
+				$cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
375
+			} else {
376
+				// otherwise leave it as-is. It will blow everything up and stop the migration
377
+				$cols_n_values_with_no_invalid_text[ $col ] = $value;
378
+			}
379
+		}
380
+		$cols_n_values = $cols_n_values_with_no_invalid_text;
381
+		$datatypes = array(
382
+			'%s',// EVT_name
383
+			'%s',// EVT_desc
384
+			'%s',// EVT_slug
385
+			'%s',// EVT_created
386
+			'%s',
387
+			'%s',// EVT_short_desc
388
+			'%s',// EVT_modified
389
+			'%s',
390
+			'%s',// EVT_wp_user
391
+			'%d',// post_parent
392
+			'%d',// EVT_order
393
+			'%s',// post_type
394
+			'%s',// status
395
+		);
396
+		$success = $wpdb->insert(
397
+			$this->_new_table,
398
+			$cols_n_values,
399
+			$datatypes
400
+		);
401
+		if (! $success) {
402
+			$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));
403
+			return 0;
404
+		}
405
+		return $wpdb->insert_id;
406
+	}
407
+
408
+	/**
409
+	 * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
410
+	 * @global wpdb $wpdb
411
+	 * @param int $event_id
412
+	 * @return int
413
+	 */
414
+	public static function count_registrations($event_id)
415
+	{
416
+		global $wpdb;
417
+		$count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
418
+		return intval($count);
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * @param $old_event
425
+	 * @param $new_cpt_id
426
+	 * @return int
427
+	 */
428
+	private function _insert_event_meta($old_event, $new_cpt_id)
429
+	{
430
+		global $wpdb;
431
+		$event_meta = maybe_unserialize($old_event['event_meta']);
437 432
 //      for reference, 3.1 'default_payment_status' are: $default_payment_status = array(
438 433
 //  array('id' => "", 'text' => 'No Change'),
439 434
 //  array('id' => 'Incomplete', 'text' => 'Incomplete'),
440 435
 //  array('id' => 'Pending', 'text' => 'Pending'),
441 436
 //  //array('id' => 'Completed', 'text' => 'Completed')
442 437
 // );
443
-        $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']));
444
-        $cols_n_values = array(
445
-            'EVT_ID' => $new_cpt_id,// EVT_ID_fk
446
-            'EVT_display_desc' => 'Y' == $old_event['display_desc'],
447
-            'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
448
-            '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
449
-            'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
450
-            'EVT_default_registration_status' => $default_reg_status,
451
-            'EVT_member_only' => $old_event['member_only'],
452
-            'EVT_phone' => $old_event['phone'],
453
-            'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
454
-            'EVT_timezone_string' => $old_event['timezone_string'],
455
-            'EVT_external_URL' => $old_event['externalURL'],
456
-            'EVT_donations' => false// doesnt exist in 3.1
457
-
458
-        );
459
-        $datatypes = array(
460
-            '%s',// EVT_ID
461
-            '%d',// EVT_display_desc
462
-            '%d',// EVT_display_ticket_selector
463
-            '%s',// EVT_visible_on
464
-            '%d',// EVT_additional_limit
465
-            '%s',// EVT_default_registration_status
466
-            '%d',// EVT_member_only
467
-            '%s',// EVT_phone
468
-            '%d',// EVT_allow_overflow
469
-            '%s',// EVT_timezone_string
470
-            '%s',// EVT_external_URL
471
-            '%d',// EVT_donations
472
-        );
473
-        $success = $wpdb->insert(
474
-            $this->_new_meta_table,
475
-            $cols_n_values,
476
-            $datatypes
477
-        );
478
-        if (! $success) {
479
-            $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));
480
-            return 0;
481
-        }
482
-        return $wpdb->insert_id;
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     * @param $old_event
489
-     * @return int
490
-     */
491
-    private function _maybe_create_venue($old_event)
492
-    {
493
-        if (
494
-            $old_event['address'] ||
495
-                $old_event['address2'] ||
496
-                $old_event['city'] ||
497
-                $old_event['state'] ||
498
-                $old_event['zip'] ||
499
-                $old_event['venue_title'] ||
500
-                $old_event['venue_url'] ||
501
-                $old_event['venue_image'] ||
502
-                $old_event['venue_phone'] ||
503
-                $old_event['virtual_url'] ||
504
-                $old_event['virtual_phone']
505
-        ) {
506
-            $old_id = $this->_duplicate_venue_exists($old_event);
507
-            if ($old_id) {
508
-                return $old_id;
509
-            }
510
-            $new_id = $this->_insert_venue_into_posts($old_event);
511
-            if ($new_id) {
512
-                $this->_insert_venue_into_meta_table($new_id, $old_event);
513
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
514
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
515
-            }
516
-            // we don't bother recording the conversion from old events to venues as that
517
-            // will complicate finding the conversion from old venues to new events
518
-            return $new_id;
519
-        } else {
520
-            return 0;
521
-        }
522
-    }
523
-
524
-    /**
525
-     * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
526
-     * If so, return it. Otherwise return NULL.
527
-     * @param array $old_event
528
-     * @return int duplicate venue id
529
-     */
530
-    private function _duplicate_venue_exists($old_event)
531
-    {
532
-        global $wpdb;
533
-        $conditions = array(
534
-            'VNU_address' => $old_event ['address'],
535
-            'VNU_address2' => $old_event['address2'],
536
-            'VNU_city' => $old_event['city'],
537
-            'VNU_zip' => $old_event['zip'],
538
-            'post_title' => $this->_get_venue_title_for_event($old_event),
539
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
540
-            'VNU_url' => $old_event['venue_url'],// VNU_url
541
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
542
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
543
-        );
544
-        $sql_conditions = array();
545
-        foreach ($conditions as $column => $value) {
546
-            $sql_conditions [] = $wpdb->prepare("$column = %s", $value);
547
-        }
548
-        $query = "SELECT VNU_ID
438
+		$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']));
439
+		$cols_n_values = array(
440
+			'EVT_ID' => $new_cpt_id,// EVT_ID_fk
441
+			'EVT_display_desc' => 'Y' == $old_event['display_desc'],
442
+			'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
443
+			'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
444
+			'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
445
+			'EVT_default_registration_status' => $default_reg_status,
446
+			'EVT_member_only' => $old_event['member_only'],
447
+			'EVT_phone' => $old_event['phone'],
448
+			'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
449
+			'EVT_timezone_string' => $old_event['timezone_string'],
450
+			'EVT_external_URL' => $old_event['externalURL'],
451
+			'EVT_donations' => false// doesnt exist in 3.1
452
+
453
+		);
454
+		$datatypes = array(
455
+			'%s',// EVT_ID
456
+			'%d',// EVT_display_desc
457
+			'%d',// EVT_display_ticket_selector
458
+			'%s',// EVT_visible_on
459
+			'%d',// EVT_additional_limit
460
+			'%s',// EVT_default_registration_status
461
+			'%d',// EVT_member_only
462
+			'%s',// EVT_phone
463
+			'%d',// EVT_allow_overflow
464
+			'%s',// EVT_timezone_string
465
+			'%s',// EVT_external_URL
466
+			'%d',// EVT_donations
467
+		);
468
+		$success = $wpdb->insert(
469
+			$this->_new_meta_table,
470
+			$cols_n_values,
471
+			$datatypes
472
+		);
473
+		if (! $success) {
474
+			$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));
475
+			return 0;
476
+		}
477
+		return $wpdb->insert_id;
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * @param $old_event
484
+	 * @return int
485
+	 */
486
+	private function _maybe_create_venue($old_event)
487
+	{
488
+		if (
489
+			$old_event['address'] ||
490
+				$old_event['address2'] ||
491
+				$old_event['city'] ||
492
+				$old_event['state'] ||
493
+				$old_event['zip'] ||
494
+				$old_event['venue_title'] ||
495
+				$old_event['venue_url'] ||
496
+				$old_event['venue_image'] ||
497
+				$old_event['venue_phone'] ||
498
+				$old_event['virtual_url'] ||
499
+				$old_event['virtual_phone']
500
+		) {
501
+			$old_id = $this->_duplicate_venue_exists($old_event);
502
+			if ($old_id) {
503
+				return $old_id;
504
+			}
505
+			$new_id = $this->_insert_venue_into_posts($old_event);
506
+			if ($new_id) {
507
+				$this->_insert_venue_into_meta_table($new_id, $old_event);
508
+				$guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
509
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
510
+			}
511
+			// we don't bother recording the conversion from old events to venues as that
512
+			// will complicate finding the conversion from old venues to new events
513
+			return $new_id;
514
+		} else {
515
+			return 0;
516
+		}
517
+	}
518
+
519
+	/**
520
+	 * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
521
+	 * If so, return it. Otherwise return NULL.
522
+	 * @param array $old_event
523
+	 * @return int duplicate venue id
524
+	 */
525
+	private function _duplicate_venue_exists($old_event)
526
+	{
527
+		global $wpdb;
528
+		$conditions = array(
529
+			'VNU_address' => $old_event ['address'],
530
+			'VNU_address2' => $old_event['address2'],
531
+			'VNU_city' => $old_event['city'],
532
+			'VNU_zip' => $old_event['zip'],
533
+			'post_title' => $this->_get_venue_title_for_event($old_event),
534
+			'VNU_phone' => $old_event['venue_phone'],// VNU_phone
535
+			'VNU_url' => $old_event['venue_url'],// VNU_url
536
+			'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
537
+			'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
538
+		);
539
+		$sql_conditions = array();
540
+		foreach ($conditions as $column => $value) {
541
+			$sql_conditions [] = $wpdb->prepare("$column = %s", $value);
542
+		}
543
+		$query = "SELECT VNU_ID
549 544
 					FROM
550 545
 		{$wpdb->posts} as p INNER JOIN
551 546
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
552 547
 			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
553
-        $id = $wpdb->get_var($query);
554
-        return $id;
555
-    }
556
-
557
-    /**
558
-     * Gets teh venue's title or makes one up if there is none
559
-     * @param array $event_data_array keys are events_details columns and values are their values
560
-     * @return string
561
-     */
562
-    protected function _get_venue_title_for_event($event_data_array)
563
-    {
564
-        return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(esc_html__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
565
-    }
566
-
567
-    /**
568
-     * Inserts the CPT
569
-     *
570
-     * @param array $old_event keys are cols, values are col values
571
-     * @return int
572
-     */
573
-    private function _insert_venue_into_posts($old_event)
574
-    {
575
-        global $wpdb;
576
-        $insertion_array = array(
577
-                    'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
578
-                    'post_content' => '',// VNU_desc
579
-                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
580
-                    'post_date' => current_time('mysql'),// VNU_created
581
-                    'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
582
-                    'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
583
-                    'post_modified' => current_time('mysql'),// VNU_modified
584
-                    'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
585
-                    'post_author' => $old_event['wp_user'],// VNU_wp_user
586
-                    'post_parent' => 0,// parent
587
-                    'menu_order' => 0,// VNU_order
588
-                    'post_type' => 'espresso_venues'// post_type
589
-                );
590
-        $datatypes_array = array(
591
-                    '%s',// VNU_name
592
-                    '%s',// VNU_desc
593
-                    '%s',// VNU_identifier
594
-                    '%s',// VNU_created
595
-                    '%s',
596
-                    '%s',// VNU_short_desc
597
-                    '%s',// VNU_modified
598
-                    '%s',
599
-                    '%d',// VNU_wp_user
600
-                    '%d',// parent
601
-                    '%d',// VNU_order
602
-                    '%s',// post_type
603
-                );
604
-        $success = $wpdb->insert(
605
-            $wpdb->posts,
606
-            $insertion_array,
607
-            $datatypes_array
608
-        );
609
-        if (! $success) {
610
-            $this->add_error(
611
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
612
-                    $this->_old_table,
613
-                    $old_event,
614
-                    $this->_new_table,
615
-                    $insertion_array,
616
-                    $datatypes_array
617
-                )
618
-            );
619
-            return 0;
620
-        }
621
-        return $wpdb->insert_id;
622
-    }
623
-
624
-    /**
625
-     * Inserts into the venue_meta table
626
-     * @param int $cpt_id
627
-     * @param array $old_event
628
-     * @return int
629
-     */
630
-    private function _insert_venue_into_meta_table($cpt_id, $old_event)
631
-    {
632
-        global $wpdb;
633
-
634
-        // assume the country is the same as the organization's old settings
635
-        $country_iso = $this->get_migration_script()->get_default_country_iso();
636
-        // find the state from the venue, or the organization, or just guess california
637
-        if (! $old_event['state']) {
638
-            $old_org_options = get_option('events_organization_settings');
639
-            $state_name = stripslashes($old_org_options['organization_state']);
640
-        } else {
641
-            $state_name = $old_event['state'];
642
-        }
643
-        if (! $state_name) {
644
-            $state_name = 'CA';
645
-        }
646
-        // get a state ID with the same name, if possible
647
-        try {
648
-            $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
649
-            $state_id = $state['STA_ID'];
650
-        } catch (EE_Error $e) {
651
-            $this->add_error($e->getMessage());
652
-            $state_id = 0;
653
-        }
654
-        // now insert into meta table
655
-        $insertion_array = array(
656
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
657
-            'VNU_address' => stripslashes($old_event['address']),// VNU_address
658
-            'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
659
-            'VNU_city' => stripslashes($old_event['city']),// VNU_city
660
-            'STA_ID' => $state_id,// STA_ID
661
-            'CNT_ISO' => $country_iso,// CNT_ISO
662
-            'VNU_zip' => $old_event['zip'],// VNU_zip
663
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
664
-            'VNU_capacity' => -1,// VNU_capacity
665
-            'VNU_url' => $old_event['venue_url'],// VNU_url
666
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
667
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
668
-            'VNU_google_map_link' => '',// VNU_google_map_link
669
-            'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
670
-        );
671
-        $datatypes = array(
672
-            '%d',// VNU_ID_fk
673
-            '%s',// VNU_address
674
-            '%s',// VNU_address2
675
-            '%s',// VNU_city
676
-            '%d',// STA_ID
677
-            '%s',// CNT_ISO
678
-            '%s',// VNU_zip
679
-            '%s',// VNU_phone
680
-            '%d',// VNU_capacity
681
-            '%s',// VNU_url
682
-            '%s',// VNU_virtual_phone
683
-            '%s',// VNU_virtual_url
684
-            '%s',// VNU_google_map_link
685
-            '%d',// VNU_enable_for_gmap
686
-        );
687
-        $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
688
-        if (! $success) {
689
-            $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));
690
-            return 0;
691
-        }
692
-        return $wpdb->insert_id;
693
-    }
694
-
695
-
696
-
697
-    /**
698
-     * @param $new_event_id
699
-     * @param $new_venue_id
700
-     * @return int
701
-     */
702
-    private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
703
-    {
704
-        global $wpdb;
705
-        if (! $new_event_id) {
706
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
707
-            return 0;
708
-        }
709
-        if (! $new_venue_id) {
710
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
711
-            return 0;
712
-        }
713
-        $cols_n_values = array(
714
-            'EVT_ID' => $new_event_id,
715
-            'VNU_ID' => $new_venue_id,
716
-            'EVV_primary' => true
717
-        );
718
-        $datatypes = array(
719
-            '%d',// EVT_ID
720
-            '%d',// VNU_ID
721
-            '%d',// EVT_primary
722
-        );
723
-        $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
724
-        if (! $success) {
725
-            $this->add_error(
726
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
727
-                    $this->_old_table,
728
-                    array(),
729
-                    $this->_new_table,
730
-                    $cols_n_values,
731
-                    $datatypes
732
-                )
733
-            );
734
-            return 0;
735
-        }
736
-        return $wpdb->insert_id;
737
-    }
738
-    /**
739
-     * Converts all the 3.1 start-end times for the event to 4.1 datetimes
740
-     * @global wpdb $wpdb
741
-     * @param array $old_event results of get_results(...,ARRAY_A)
742
-     * @param int $new_cpt_id new post ID
743
-     * @return void (if there are errors though, adds them to the stage's error list
744
-     */
745
-    private function _convert_start_end_times($old_event, $new_cpt_id)
746
-    {
747
-        $start_end_times = $this->_get_old_start_end_times($old_event['id']);
748
-        foreach ($start_end_times as $start_end_time) {
749
-            $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
750
-            if ($datetime_id) {
751
-                $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
752
-            }
753
-        }
754
-    }
755
-    /**
756
-     * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
757
-     * @global wpdb $wpdb
758
-     * @param int $old_event_id
759
-     * @return array
760
-     */
761
-    private function _get_old_start_end_times($old_event_id)
762
-    {
763
-        global $wpdb;
764
-        return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
765
-    }
766
-    /**
767
-     * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
768
-     * @param array $start_end_time_row
769
-     * @param array $old_event_row
770
-     * @param int $new_cpt_id
771
-     * @return int ID of new datetime
772
-     */
773
-    private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
774
-    {
775
-        global $wpdb;
776
-        $start_date = $old_event_row['start_date'];
777
-        $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
778
-        $end_date = $old_event_row['end_date'];
779
-        $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
780
-        $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
781
-        $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']);
782
-        $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']);
783
-        $cols_n_values = array(
784
-            'EVT_ID' => $new_cpt_id,// EVT_ID
785
-            'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
786
-            'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
787
-            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
788
-            'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
548
+		$id = $wpdb->get_var($query);
549
+		return $id;
550
+	}
551
+
552
+	/**
553
+	 * Gets teh venue's title or makes one up if there is none
554
+	 * @param array $event_data_array keys are events_details columns and values are their values
555
+	 * @return string
556
+	 */
557
+	protected function _get_venue_title_for_event($event_data_array)
558
+	{
559
+		return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(esc_html__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
560
+	}
561
+
562
+	/**
563
+	 * Inserts the CPT
564
+	 *
565
+	 * @param array $old_event keys are cols, values are col values
566
+	 * @return int
567
+	 */
568
+	private function _insert_venue_into_posts($old_event)
569
+	{
570
+		global $wpdb;
571
+		$insertion_array = array(
572
+					'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
573
+					'post_content' => '',// VNU_desc
574
+					'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
575
+					'post_date' => current_time('mysql'),// VNU_created
576
+					'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
577
+					'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
578
+					'post_modified' => current_time('mysql'),// VNU_modified
579
+					'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
580
+					'post_author' => $old_event['wp_user'],// VNU_wp_user
581
+					'post_parent' => 0,// parent
582
+					'menu_order' => 0,// VNU_order
583
+					'post_type' => 'espresso_venues'// post_type
584
+				);
585
+		$datatypes_array = array(
586
+					'%s',// VNU_name
587
+					'%s',// VNU_desc
588
+					'%s',// VNU_identifier
589
+					'%s',// VNU_created
590
+					'%s',
591
+					'%s',// VNU_short_desc
592
+					'%s',// VNU_modified
593
+					'%s',
594
+					'%d',// VNU_wp_user
595
+					'%d',// parent
596
+					'%d',// VNU_order
597
+					'%s',// post_type
598
+				);
599
+		$success = $wpdb->insert(
600
+			$wpdb->posts,
601
+			$insertion_array,
602
+			$datatypes_array
603
+		);
604
+		if (! $success) {
605
+			$this->add_error(
606
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
607
+					$this->_old_table,
608
+					$old_event,
609
+					$this->_new_table,
610
+					$insertion_array,
611
+					$datatypes_array
612
+				)
613
+			);
614
+			return 0;
615
+		}
616
+		return $wpdb->insert_id;
617
+	}
618
+
619
+	/**
620
+	 * Inserts into the venue_meta table
621
+	 * @param int $cpt_id
622
+	 * @param array $old_event
623
+	 * @return int
624
+	 */
625
+	private function _insert_venue_into_meta_table($cpt_id, $old_event)
626
+	{
627
+		global $wpdb;
628
+
629
+		// assume the country is the same as the organization's old settings
630
+		$country_iso = $this->get_migration_script()->get_default_country_iso();
631
+		// find the state from the venue, or the organization, or just guess california
632
+		if (! $old_event['state']) {
633
+			$old_org_options = get_option('events_organization_settings');
634
+			$state_name = stripslashes($old_org_options['organization_state']);
635
+		} else {
636
+			$state_name = $old_event['state'];
637
+		}
638
+		if (! $state_name) {
639
+			$state_name = 'CA';
640
+		}
641
+		// get a state ID with the same name, if possible
642
+		try {
643
+			$state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
644
+			$state_id = $state['STA_ID'];
645
+		} catch (EE_Error $e) {
646
+			$this->add_error($e->getMessage());
647
+			$state_id = 0;
648
+		}
649
+		// now insert into meta table
650
+		$insertion_array = array(
651
+			'VNU_ID' => $cpt_id,// VNU_ID_fk
652
+			'VNU_address' => stripslashes($old_event['address']),// VNU_address
653
+			'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
654
+			'VNU_city' => stripslashes($old_event['city']),// VNU_city
655
+			'STA_ID' => $state_id,// STA_ID
656
+			'CNT_ISO' => $country_iso,// CNT_ISO
657
+			'VNU_zip' => $old_event['zip'],// VNU_zip
658
+			'VNU_phone' => $old_event['venue_phone'],// VNU_phone
659
+			'VNU_capacity' => -1,// VNU_capacity
660
+			'VNU_url' => $old_event['venue_url'],// VNU_url
661
+			'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
662
+			'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
663
+			'VNU_google_map_link' => '',// VNU_google_map_link
664
+			'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
665
+		);
666
+		$datatypes = array(
667
+			'%d',// VNU_ID_fk
668
+			'%s',// VNU_address
669
+			'%s',// VNU_address2
670
+			'%s',// VNU_city
671
+			'%d',// STA_ID
672
+			'%s',// CNT_ISO
673
+			'%s',// VNU_zip
674
+			'%s',// VNU_phone
675
+			'%d',// VNU_capacity
676
+			'%s',// VNU_url
677
+			'%s',// VNU_virtual_phone
678
+			'%s',// VNU_virtual_url
679
+			'%s',// VNU_google_map_link
680
+			'%d',// VNU_enable_for_gmap
681
+		);
682
+		$success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
683
+		if (! $success) {
684
+			$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));
685
+			return 0;
686
+		}
687
+		return $wpdb->insert_id;
688
+	}
689
+
690
+
691
+
692
+	/**
693
+	 * @param $new_event_id
694
+	 * @param $new_venue_id
695
+	 * @return int
696
+	 */
697
+	private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
698
+	{
699
+		global $wpdb;
700
+		if (! $new_event_id) {
701
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
702
+			return 0;
703
+		}
704
+		if (! $new_venue_id) {
705
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
706
+			return 0;
707
+		}
708
+		$cols_n_values = array(
709
+			'EVT_ID' => $new_event_id,
710
+			'VNU_ID' => $new_venue_id,
711
+			'EVV_primary' => true
712
+		);
713
+		$datatypes = array(
714
+			'%d',// EVT_ID
715
+			'%d',// VNU_ID
716
+			'%d',// EVT_primary
717
+		);
718
+		$success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
719
+		if (! $success) {
720
+			$this->add_error(
721
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
722
+					$this->_old_table,
723
+					array(),
724
+					$this->_new_table,
725
+					$cols_n_values,
726
+					$datatypes
727
+				)
728
+			);
729
+			return 0;
730
+		}
731
+		return $wpdb->insert_id;
732
+	}
733
+	/**
734
+	 * Converts all the 3.1 start-end times for the event to 4.1 datetimes
735
+	 * @global wpdb $wpdb
736
+	 * @param array $old_event results of get_results(...,ARRAY_A)
737
+	 * @param int $new_cpt_id new post ID
738
+	 * @return void (if there are errors though, adds them to the stage's error list
739
+	 */
740
+	private function _convert_start_end_times($old_event, $new_cpt_id)
741
+	{
742
+		$start_end_times = $this->_get_old_start_end_times($old_event['id']);
743
+		foreach ($start_end_times as $start_end_time) {
744
+			$datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
745
+			if ($datetime_id) {
746
+				$this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
747
+			}
748
+		}
749
+	}
750
+	/**
751
+	 * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
752
+	 * @global wpdb $wpdb
753
+	 * @param int $old_event_id
754
+	 * @return array
755
+	 */
756
+	private function _get_old_start_end_times($old_event_id)
757
+	{
758
+		global $wpdb;
759
+		return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
760
+	}
761
+	/**
762
+	 * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
763
+	 * @param array $start_end_time_row
764
+	 * @param array $old_event_row
765
+	 * @param int $new_cpt_id
766
+	 * @return int ID of new datetime
767
+	 */
768
+	private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
769
+	{
770
+		global $wpdb;
771
+		$start_date = $old_event_row['start_date'];
772
+		$start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
773
+		$end_date = $old_event_row['end_date'];
774
+		$end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
775
+		$existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
776
+		$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']);
777
+		$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']);
778
+		$cols_n_values = array(
779
+			'EVT_ID' => $new_cpt_id,// EVT_ID
780
+			'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
781
+			'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
782
+			'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
783
+			'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
789 784
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
790
-            'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
791
-            'DTT_parent' => 0,
792
-            'DTT_deleted' => false
793
-        );
794
-        $datatypes = array(
795
-            '%d',// EVT_Id
796
-            '%s',// DTT_EVT_start
797
-            '%s',// DTT_EVT_end
798
-            '%d',// DTT_reg_limit
799
-            '%d',// DTT_sold
785
+			'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
786
+			'DTT_parent' => 0,
787
+			'DTT_deleted' => false
788
+		);
789
+		$datatypes = array(
790
+			'%d',// EVT_Id
791
+			'%s',// DTT_EVT_start
792
+			'%s',// DTT_EVT_end
793
+			'%d',// DTT_reg_limit
794
+			'%d',// DTT_sold
800 795
 //          '%d',//DTT_is_primary
801
-            '%d',// DTT_order
802
-            '%d',// DTT_parent
803
-            '%d',// DTT_deleted
804
-        );
805
-        $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
806
-        if (! $success) {
807
-            $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));
808
-            return 0;
809
-        }
810
-        return $wpdb->insert_id;
811
-    }
812
-
813
-    /**
814
-     * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
815
-     * when deciding whether a datetime we're about ot insert should be the 'primary' or not
816
-     * @global wpdb $wpdb
817
-     * @param int $cpt_event_id
818
-     * @return int
819
-     */
820
-    private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
821
-    {
822
-        global $wpdb;
823
-        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
824
-        return intval($count);
825
-    }
796
+			'%d',// DTT_order
797
+			'%d',// DTT_parent
798
+			'%d',// DTT_deleted
799
+		);
800
+		$success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
801
+		if (! $success) {
802
+			$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));
803
+			return 0;
804
+		}
805
+		return $wpdb->insert_id;
806
+	}
807
+
808
+	/**
809
+	 * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
810
+	 * when deciding whether a datetime we're about ot insert should be the 'primary' or not
811
+	 * @global wpdb $wpdb
812
+	 * @param int $cpt_event_id
813
+	 * @return int
814
+	 */
815
+	private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
816
+	{
817
+		global $wpdb;
818
+		$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
819
+		return intval($count);
820
+	}
826 821
 }
Please login to merge, or discard this patch.
Spacing   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
     public function __construct()
177 177
     {
178 178
         global $wpdb;
179
-        $this->_old_table = $wpdb->prefix . "events_detail";
180
-        $this->_old_start_end_table = $wpdb->prefix . "events_start_end";
181
-        $this->_new_table = $wpdb->prefix . "posts";
182
-        $this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
183
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
179
+        $this->_old_table = $wpdb->prefix."events_detail";
180
+        $this->_old_start_end_table = $wpdb->prefix."events_start_end";
181
+        $this->_new_table = $wpdb->prefix."posts";
182
+        $this->_new_meta_table = $wpdb->prefix."esp_event_meta";
183
+        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
184 184
         $this->_pretty_name = esc_html__("Events", "event_espresso");
185 185
         parent::__construct();
186 186
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     public function _count_records_to_migrate()
195 195
     {
196 196
         global $wpdb;
197
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
197
+        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"');
198 198
         return intval($count);
199 199
     }
200 200
 
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
     private function _add_post_metas($old_event, $post_id)
262 262
     {
263 263
         $event_meta = maybe_unserialize($old_event['event_meta']);
264
-        if (! $event_meta || ! is_array($event_meta)) {
264
+        if ( ! $event_meta || ! is_array($event_meta)) {
265 265
             return;
266 266
         }
267
-        unset($event_meta['date_submitted']);// factored into CPT
268
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
269
-        unset($event_meta['default_payment_status']);// dido
270
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
267
+        unset($event_meta['date_submitted']); // factored into CPT
268
+        unset($event_meta['additional_attendee_reg_info']); // factored into event meta table
269
+        unset($event_meta['default_payment_status']); // dido
270
+        unset($event_meta['event_thumbnail_url']); // used to find post featured image
271 271
         foreach ($event_meta as $meta_key => $meta_value) {
272 272
             if ($meta_key) {// if the meta key is just an empty string, ignore it
273 273
                 $success = add_post_meta($post_id, $meta_key, $meta_value, true);
274
-                if (! $success) {
274
+                if ( ! $success) {
275 275
                     $this->add_error(sprintf(esc_html__("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)));
276 276
                 }
277 277
             }
@@ -342,68 +342,68 @@  discard block
 block discarded – undo
342 342
 //      and 3 custom ones: cancelled,postponed,sold_out
343 343
         $status_conversions = array(
344 344
             'R' => 'draft',
345
-            '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
+            'X' => 'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
346 346
             'P' => 'pending',
347
-            'IA' => 'draft',// draft and in the past
347
+            'IA' => 'draft', // draft and in the past
348 348
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
349
-            '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
+            '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'
350 350
             'A' => 'publish',
351
-            'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351
+            'S' => 'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
352 352
             'D' => 'trash',
353 353
         );
354
-        $post_status = $status_conversions[ $old_event['event_status'] ];
354
+        $post_status = $status_conversions[$old_event['event_status']];
355 355
         // check if we've sold out
356 356
         if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
357 357
             $post_status = 'sold_out';
358 358
         }
359 359
 //      FYI postponed and cancelled don't exist in 3.1
360 360
         $cols_n_values = array(
361
-            'post_title' => stripslashes($old_event['event_name']),// EVT_name
362
-            'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
363
-            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
364
-            'post_date' => $old_event['submitted'],// EVT_created NOT
361
+            'post_title' => stripslashes($old_event['event_name']), // EVT_name
362
+            'post_content' => stripslashes($old_event['event_desc']), // EVT_desc
363
+            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug
364
+            'post_date' => $old_event['submitted'], // EVT_created NOT
365 365
             'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
366
-            'post_excerpt' => '',// EVT_short_desc
367
-            'post_modified' => $old_event['submitted'],// EVT_modified
366
+            'post_excerpt' => '', // EVT_short_desc
367
+            'post_modified' => $old_event['submitted'], // EVT_modified
368 368
             'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
369
-            'post_author' => $old_event['wp_user'],// EVT_wp_user
370
-            'post_parent' => 0,// parent maybe get this from some REM field?
371
-            'menu_order' => 0,// EVT_order
372
-            'post_type' => 'espresso_events',// post_type
373
-            'post_status' => $post_status,// status
369
+            'post_author' => $old_event['wp_user'], // EVT_wp_user
370
+            'post_parent' => 0, // parent maybe get this from some REM field?
371
+            'menu_order' => 0, // EVT_order
372
+            'post_type' => 'espresso_events', // post_type
373
+            'post_status' => $post_status, // status
374 374
         );
375 375
         $cols_n_values_with_no_invalid_text = array();
376 376
         foreach ($cols_n_values as $col => $value) {
377 377
             $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
378
-            if (! is_wp_error($value_sans_invalid_chars)) {
379
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
378
+            if ( ! is_wp_error($value_sans_invalid_chars)) {
379
+                $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars;
380 380
             } else {
381 381
                 // otherwise leave it as-is. It will blow everything up and stop the migration
382
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
382
+                $cols_n_values_with_no_invalid_text[$col] = $value;
383 383
             }
384 384
         }
385 385
         $cols_n_values = $cols_n_values_with_no_invalid_text;
386 386
         $datatypes = array(
387
-            '%s',// EVT_name
388
-            '%s',// EVT_desc
389
-            '%s',// EVT_slug
390
-            '%s',// EVT_created
387
+            '%s', // EVT_name
388
+            '%s', // EVT_desc
389
+            '%s', // EVT_slug
390
+            '%s', // EVT_created
391 391
             '%s',
392
-            '%s',// EVT_short_desc
393
-            '%s',// EVT_modified
392
+            '%s', // EVT_short_desc
393
+            '%s', // EVT_modified
394 394
             '%s',
395
-            '%s',// EVT_wp_user
396
-            '%d',// post_parent
397
-            '%d',// EVT_order
398
-            '%s',// post_type
399
-            '%s',// status
395
+            '%s', // EVT_wp_user
396
+            '%d', // post_parent
397
+            '%d', // EVT_order
398
+            '%s', // post_type
399
+            '%s', // status
400 400
         );
401 401
         $success = $wpdb->insert(
402 402
             $this->_new_table,
403 403
             $cols_n_values,
404 404
             $datatypes
405 405
         );
406
-        if (! $success) {
406
+        if ( ! $success) {
407 407
             $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));
408 408
             return 0;
409 409
         }
@@ -442,10 +442,10 @@  discard block
 block discarded – undo
442 442
 // );
443 443
         $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']));
444 444
         $cols_n_values = array(
445
-            'EVT_ID' => $new_cpt_id,// EVT_ID_fk
445
+            'EVT_ID' => $new_cpt_id, // EVT_ID_fk
446 446
             'EVT_display_desc' => 'Y' == $old_event['display_desc'],
447 447
             'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
448
-            '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_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
449 449
             'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
450 450
             'EVT_default_registration_status' => $default_reg_status,
451 451
             'EVT_member_only' => $old_event['member_only'],
@@ -457,25 +457,25 @@  discard block
 block discarded – undo
457 457
 
458 458
         );
459 459
         $datatypes = array(
460
-            '%s',// EVT_ID
461
-            '%d',// EVT_display_desc
462
-            '%d',// EVT_display_ticket_selector
463
-            '%s',// EVT_visible_on
464
-            '%d',// EVT_additional_limit
465
-            '%s',// EVT_default_registration_status
466
-            '%d',// EVT_member_only
467
-            '%s',// EVT_phone
468
-            '%d',// EVT_allow_overflow
469
-            '%s',// EVT_timezone_string
470
-            '%s',// EVT_external_URL
471
-            '%d',// EVT_donations
460
+            '%s', // EVT_ID
461
+            '%d', // EVT_display_desc
462
+            '%d', // EVT_display_ticket_selector
463
+            '%s', // EVT_visible_on
464
+            '%d', // EVT_additional_limit
465
+            '%s', // EVT_default_registration_status
466
+            '%d', // EVT_member_only
467
+            '%s', // EVT_phone
468
+            '%d', // EVT_allow_overflow
469
+            '%s', // EVT_timezone_string
470
+            '%s', // EVT_external_URL
471
+            '%d', // EVT_donations
472 472
         );
473 473
         $success = $wpdb->insert(
474 474
             $this->_new_meta_table,
475 475
             $cols_n_values,
476 476
             $datatypes
477 477
         );
478
-        if (! $success) {
478
+        if ( ! $success) {
479 479
             $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));
480 480
             return 0;
481 481
         }
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
             $new_id = $this->_insert_venue_into_posts($old_event);
511 511
             if ($new_id) {
512 512
                 $this->_insert_venue_into_meta_table($new_id, $old_event);
513
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
513
+                $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null;
514 514
                 $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
515 515
             }
516 516
             // we don't bother recording the conversion from old events to venues as that
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
             'VNU_city' => $old_event['city'],
537 537
             'VNU_zip' => $old_event['zip'],
538 538
             'post_title' => $this->_get_venue_title_for_event($old_event),
539
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
540
-            'VNU_url' => $old_event['venue_url'],// VNU_url
541
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
542
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
539
+            'VNU_phone' => $old_event['venue_phone'], // VNU_phone
540
+            'VNU_url' => $old_event['venue_url'], // VNU_url
541
+            'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone
542
+            'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url
543 543
         );
544 544
         $sql_conditions = array();
545 545
         foreach ($conditions as $column => $value) {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 					FROM
550 550
 		{$wpdb->posts} as p INNER JOIN
551 551
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
552
-			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
552
+			WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1";
553 553
         $id = $wpdb->get_var($query);
554 554
         return $id;
555 555
     }
@@ -574,39 +574,39 @@  discard block
 block discarded – undo
574 574
     {
575 575
         global $wpdb;
576 576
         $insertion_array = array(
577
-                    'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
578
-                    'post_content' => '',// VNU_desc
579
-                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
580
-                    'post_date' => current_time('mysql'),// VNU_created
577
+                    'post_title' => $this->_get_venue_title_for_event($old_event), // VNU_name
578
+                    'post_content' => '', // VNU_desc
579
+                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier
580
+                    'post_date' => current_time('mysql'), // VNU_created
581 581
                     'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
582
-                    'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
583
-                    'post_modified' => current_time('mysql'),// VNU_modified
582
+                    'post_excerpt' => '', // VNU_short_desc arbitrary only 50 characters
583
+                    'post_modified' => current_time('mysql'), // VNU_modified
584 584
                     'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
585
-                    'post_author' => $old_event['wp_user'],// VNU_wp_user
586
-                    'post_parent' => 0,// parent
587
-                    'menu_order' => 0,// VNU_order
585
+                    'post_author' => $old_event['wp_user'], // VNU_wp_user
586
+                    'post_parent' => 0, // parent
587
+                    'menu_order' => 0, // VNU_order
588 588
                     'post_type' => 'espresso_venues'// post_type
589 589
                 );
590 590
         $datatypes_array = array(
591
-                    '%s',// VNU_name
592
-                    '%s',// VNU_desc
593
-                    '%s',// VNU_identifier
594
-                    '%s',// VNU_created
591
+                    '%s', // VNU_name
592
+                    '%s', // VNU_desc
593
+                    '%s', // VNU_identifier
594
+                    '%s', // VNU_created
595 595
                     '%s',
596
-                    '%s',// VNU_short_desc
597
-                    '%s',// VNU_modified
596
+                    '%s', // VNU_short_desc
597
+                    '%s', // VNU_modified
598 598
                     '%s',
599
-                    '%d',// VNU_wp_user
600
-                    '%d',// parent
601
-                    '%d',// VNU_order
602
-                    '%s',// post_type
599
+                    '%d', // VNU_wp_user
600
+                    '%d', // parent
601
+                    '%d', // VNU_order
602
+                    '%s', // post_type
603 603
                 );
604 604
         $success = $wpdb->insert(
605 605
             $wpdb->posts,
606 606
             $insertion_array,
607 607
             $datatypes_array
608 608
         );
609
-        if (! $success) {
609
+        if ( ! $success) {
610 610
             $this->add_error(
611 611
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
612 612
                     $this->_old_table,
@@ -634,13 +634,13 @@  discard block
 block discarded – undo
634 634
         // assume the country is the same as the organization's old settings
635 635
         $country_iso = $this->get_migration_script()->get_default_country_iso();
636 636
         // find the state from the venue, or the organization, or just guess california
637
-        if (! $old_event['state']) {
637
+        if ( ! $old_event['state']) {
638 638
             $old_org_options = get_option('events_organization_settings');
639 639
             $state_name = stripslashes($old_org_options['organization_state']);
640 640
         } else {
641 641
             $state_name = $old_event['state'];
642 642
         }
643
-        if (! $state_name) {
643
+        if ( ! $state_name) {
644 644
             $state_name = 'CA';
645 645
         }
646 646
         // get a state ID with the same name, if possible
@@ -653,39 +653,39 @@  discard block
 block discarded – undo
653 653
         }
654 654
         // now insert into meta table
655 655
         $insertion_array = array(
656
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
657
-            'VNU_address' => stripslashes($old_event['address']),// VNU_address
658
-            'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
659
-            'VNU_city' => stripslashes($old_event['city']),// VNU_city
660
-            'STA_ID' => $state_id,// STA_ID
661
-            'CNT_ISO' => $country_iso,// CNT_ISO
662
-            'VNU_zip' => $old_event['zip'],// VNU_zip
663
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
664
-            'VNU_capacity' => -1,// VNU_capacity
665
-            'VNU_url' => $old_event['venue_url'],// VNU_url
666
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
667
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
668
-            'VNU_google_map_link' => '',// VNU_google_map_link
656
+            'VNU_ID' => $cpt_id, // VNU_ID_fk
657
+            'VNU_address' => stripslashes($old_event['address']), // VNU_address
658
+            'VNU_address2' => stripslashes($old_event['address2']), // VNU_address2
659
+            'VNU_city' => stripslashes($old_event['city']), // VNU_city
660
+            'STA_ID' => $state_id, // STA_ID
661
+            'CNT_ISO' => $country_iso, // CNT_ISO
662
+            'VNU_zip' => $old_event['zip'], // VNU_zip
663
+            'VNU_phone' => $old_event['venue_phone'], // VNU_phone
664
+            'VNU_capacity' => -1, // VNU_capacity
665
+            'VNU_url' => $old_event['venue_url'], // VNU_url
666
+            'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone
667
+            'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url
668
+            'VNU_google_map_link' => '', // VNU_google_map_link
669 669
             'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
670 670
         );
671 671
         $datatypes = array(
672
-            '%d',// VNU_ID_fk
673
-            '%s',// VNU_address
674
-            '%s',// VNU_address2
675
-            '%s',// VNU_city
676
-            '%d',// STA_ID
677
-            '%s',// CNT_ISO
678
-            '%s',// VNU_zip
679
-            '%s',// VNU_phone
680
-            '%d',// VNU_capacity
681
-            '%s',// VNU_url
682
-            '%s',// VNU_virtual_phone
683
-            '%s',// VNU_virtual_url
684
-            '%s',// VNU_google_map_link
685
-            '%d',// VNU_enable_for_gmap
672
+            '%d', // VNU_ID_fk
673
+            '%s', // VNU_address
674
+            '%s', // VNU_address2
675
+            '%s', // VNU_city
676
+            '%d', // STA_ID
677
+            '%s', // CNT_ISO
678
+            '%s', // VNU_zip
679
+            '%s', // VNU_phone
680
+            '%d', // VNU_capacity
681
+            '%s', // VNU_url
682
+            '%s', // VNU_virtual_phone
683
+            '%s', // VNU_virtual_url
684
+            '%s', // VNU_google_map_link
685
+            '%d', // VNU_enable_for_gmap
686 686
         );
687
-        $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
688
-        if (! $success) {
687
+        $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
688
+        if ( ! $success) {
689 689
             $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));
690 690
             return 0;
691 691
         }
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
703 703
     {
704 704
         global $wpdb;
705
-        if (! $new_event_id) {
705
+        if ( ! $new_event_id) {
706 706
             $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
707 707
             return 0;
708 708
         }
709
-        if (! $new_venue_id) {
709
+        if ( ! $new_venue_id) {
710 710
             $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
711 711
             return 0;
712 712
         }
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
             'EVV_primary' => true
717 717
         );
718 718
         $datatypes = array(
719
-            '%d',// EVT_ID
720
-            '%d',// VNU_ID
721
-            '%d',// EVT_primary
719
+            '%d', // EVT_ID
720
+            '%d', // VNU_ID
721
+            '%d', // EVT_primary
722 722
         );
723
-        $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
724
-        if (! $success) {
723
+        $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
724
+        if ( ! $success) {
725 725
             $this->add_error(
726 726
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
727 727
                     $this->_old_table,
@@ -781,29 +781,29 @@  discard block
 block discarded – undo
781 781
         $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']);
782 782
         $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']);
783 783
         $cols_n_values = array(
784
-            'EVT_ID' => $new_cpt_id,// EVT_ID
785
-            'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
786
-            'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
787
-            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
788
-            'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
784
+            'EVT_ID' => $new_cpt_id, // EVT_ID
785
+            'DTT_EVT_start' => $start_datetime_utc, // DTT_EVT_start
786
+            'DTT_EVT_end' => $end_datetime_utc, // DTT_EVT_end
787
+            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit
788
+            'DTT_sold' => 0, // note: we will increment this as registrations are added during the migration
789 789
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
790
-            'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
790
+            'DTT_order' => $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist
791 791
             'DTT_parent' => 0,
792 792
             'DTT_deleted' => false
793 793
         );
794 794
         $datatypes = array(
795
-            '%d',// EVT_Id
796
-            '%s',// DTT_EVT_start
797
-            '%s',// DTT_EVT_end
798
-            '%d',// DTT_reg_limit
799
-            '%d',// DTT_sold
795
+            '%d', // EVT_Id
796
+            '%s', // DTT_EVT_start
797
+            '%s', // DTT_EVT_end
798
+            '%d', // DTT_reg_limit
799
+            '%d', // DTT_sold
800 800
 //          '%d',//DTT_is_primary
801
-            '%d',// DTT_order
802
-            '%d',// DTT_parent
803
-            '%d',// DTT_deleted
801
+            '%d', // DTT_order
802
+            '%d', // DTT_parent
803
+            '%d', // DTT_deleted
804 804
         );
805 805
         $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
806
-        if (! $success) {
806
+        if ( ! $success) {
807 807
             $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));
808 808
             return 0;
809 809
         }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_category_details.dmsstage.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -8,53 +8,53 @@
 block discarded – undo
8 8
  */
9 9
 class EE_DMS_4_1_0_category_details extends EE_Data_Migration_Script_Stage
10 10
 {
11
-    private $_old_table;
12
-    private $_new_table;
13
-    private $_new_term_table;
14
-    public function _migration_step($num_items = 50)
15
-    {
16
-        global $wpdb;
17
-        $start_at_record = $this->count_records_migrated();
18
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
19
-        $items_actually_migrated = 0;
20
-        foreach ($rows as $category_detail_row) {
21
-            $term_and_taxonomy_ids = wp_insert_term(
22
-                stripslashes($category_detail_row['category_name']),
23
-                'espresso_event_categories',
24
-                array(
25
-                    'description' =>  stripslashes($category_detail_row['category_desc']),
26
-                    'slug' => $category_detail_row['category_identifier']
27
-                )
28
-            );
29
-            if ($term_and_taxonomy_ids instanceof WP_Error) {
30
-                $this->add_error(sprintf(esc_html__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message()));
31
-                $items_actually_migrated++;
32
-                continue;
33
-            }
34
-            $term_id = $term_and_taxonomy_ids['term_id'];
35
-            $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id'];
36
-            $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id);
37
-            $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id);
38
-            $items_actually_migrated++;
39
-        }
40
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
41
-            $this->set_completed();
42
-        }
43
-        return $items_actually_migrated;
44
-    }
45
-    public function _count_records_to_migrate()
46
-    {
47
-        global $wpdb;
48
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table");
49
-        return $count;
50
-    }
51
-    public function __construct()
52
-    {
53
-        $this->_pretty_name = esc_html__("Category Details", "event_espresso");
54
-        global $wpdb;
55
-        $this->_old_table = $wpdb->prefix . "events_category_detail";
56
-        $this->_new_table = $wpdb->prefix . "term_taxonomy";
57
-        $this->_new_term_table = $wpdb->prefix . "terms";
58
-        parent::__construct();
59
-    }
11
+	private $_old_table;
12
+	private $_new_table;
13
+	private $_new_term_table;
14
+	public function _migration_step($num_items = 50)
15
+	{
16
+		global $wpdb;
17
+		$start_at_record = $this->count_records_migrated();
18
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
19
+		$items_actually_migrated = 0;
20
+		foreach ($rows as $category_detail_row) {
21
+			$term_and_taxonomy_ids = wp_insert_term(
22
+				stripslashes($category_detail_row['category_name']),
23
+				'espresso_event_categories',
24
+				array(
25
+					'description' =>  stripslashes($category_detail_row['category_desc']),
26
+					'slug' => $category_detail_row['category_identifier']
27
+				)
28
+			);
29
+			if ($term_and_taxonomy_ids instanceof WP_Error) {
30
+				$this->add_error(sprintf(esc_html__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message()));
31
+				$items_actually_migrated++;
32
+				continue;
33
+			}
34
+			$term_id = $term_and_taxonomy_ids['term_id'];
35
+			$term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id'];
36
+			$this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id);
37
+			$this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id);
38
+			$items_actually_migrated++;
39
+		}
40
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
41
+			$this->set_completed();
42
+		}
43
+		return $items_actually_migrated;
44
+	}
45
+	public function _count_records_to_migrate()
46
+	{
47
+		global $wpdb;
48
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table");
49
+		return $count;
50
+	}
51
+	public function __construct()
52
+	{
53
+		$this->_pretty_name = esc_html__("Category Details", "event_espresso");
54
+		global $wpdb;
55
+		$this->_old_table = $wpdb->prefix . "events_category_detail";
56
+		$this->_new_table = $wpdb->prefix . "term_taxonomy";
57
+		$this->_new_term_table = $wpdb->prefix . "terms";
58
+		parent::__construct();
59
+	}
60 60
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@
 block discarded – undo
52 52
     {
53 53
         $this->_pretty_name = esc_html__("Category Details", "event_espresso");
54 54
         global $wpdb;
55
-        $this->_old_table = $wpdb->prefix . "events_category_detail";
56
-        $this->_new_table = $wpdb->prefix . "term_taxonomy";
57
-        $this->_new_term_table = $wpdb->prefix . "terms";
55
+        $this->_old_table = $wpdb->prefix."events_category_detail";
56
+        $this->_new_table = $wpdb->prefix."term_taxonomy";
57
+        $this->_new_term_table = $wpdb->prefix."terms";
58 58
         parent::__construct();
59 59
     }
60 60
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_venues.dmsstage.php 2 patches
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -70,15 +70,15 @@  discard block
 block discarded – undo
70 70
     {
71 71
         global $wpdb;
72 72
         $start_at_record = $this->count_records_migrated();
73
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
73
+        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74 74
         $items_actually_migrated = 0;
75 75
         foreach ($rows as $old_venue) {
76
-            if (! $new_id = $this->_insert_into_posts($old_venue)) {
76
+            if ( ! $new_id = $this->_insert_into_posts($old_venue)) {
77 77
                 $items_actually_migrated++;
78 78
                 continue;
79 79
             }
80 80
             $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
-            if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
81
+            if ( ! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82 82
                 $items_actually_migrated++;
83 83
                 continue;
84 84
             }
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
     public function _count_records_to_migrate()
109 109
     {
110 110
         global $wpdb;
111
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
111
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
112 112
         return $count;
113 113
     }
114 114
     public function __construct()
115 115
     {
116 116
         $this->_pretty_name = esc_html__("Venues", "event_espresso");
117 117
         global $wpdb;
118
-        $this->_old_table = $wpdb->prefix . "events_venue";
118
+        $this->_old_table = $wpdb->prefix."events_venue";
119 119
         $this->_new_table = $wpdb->posts;
120
-        $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta";
120
+        $this->_new_meta_table = $wpdb->prefix."esp_venue_meta";
121 121
         parent::__construct();
122 122
     }
123 123
 
@@ -132,39 +132,39 @@  discard block
 block discarded – undo
132 132
         $meta = maybe_unserialize($old_venue['meta']);
133 133
         $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134 134
         $insertion_array = array(
135
-                    'post_title' => stripslashes($old_venue['name']),// VNU_name
136
-                    'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
-                    'post_name' => $slug,// VNU_identifier
138
-                    'post_date' => current_time('mysql'),// VNU_created
135
+                    'post_title' => stripslashes($old_venue['name']), // VNU_name
136
+                    'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '', // VNU_desc
137
+                    'post_name' => $slug, // VNU_identifier
138
+                    'post_date' => current_time('mysql'), // VNU_created
139 139
                     'post_date_gmt' =>  current_time('mysql', true),
140
-                    'post_excerpt' => '',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
-                    'post_modified' => current_time('mysql'),// VNU_modified
140
+                    'post_excerpt' => '', // wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
+                    'post_modified' => current_time('mysql'), // VNU_modified
142 142
                     'post_modified_gmt' => current_time('mysql', true),
143
-                    'post_author' => $old_venue['wp_user'],// VNU_wp_user
144
-                    'post_parent' => 0,// parent
145
-                    'menu_order' => 0,// VNU_order
143
+                    'post_author' => $old_venue['wp_user'], // VNU_wp_user
144
+                    'post_parent' => 0, // parent
145
+                    'menu_order' => 0, // VNU_order
146 146
                     'post_type' => 'espresso_venues'// post_type
147 147
                 );
148 148
         $datatypes_array = array(
149
-                    '%s',// VNU_name
150
-                    '%s',// VNU_desc
151
-                    '%s',// VNU_identifier
152
-                    '%s',// VNU_created
149
+                    '%s', // VNU_name
150
+                    '%s', // VNU_desc
151
+                    '%s', // VNU_identifier
152
+                    '%s', // VNU_created
153 153
                     '%s',
154
-                    '%s',// VNU_short_desc
155
-                    '%s',// VNU_modified
154
+                    '%s', // VNU_short_desc
155
+                    '%s', // VNU_modified
156 156
                     '%s',
157
-                    '%d',// VNU_wp_user
158
-                    '%d',// parent
159
-                    '%d',// VNU_order
160
-                    '%s',// post_type
157
+                    '%d', // VNU_wp_user
158
+                    '%d', // parent
159
+                    '%d', // VNU_order
160
+                    '%s', // post_type
161 161
                 );
162 162
         $success = $wpdb->insert(
163 163
             $this->_new_table,
164 164
             $insertion_array,
165 165
             $datatypes_array
166 166
         );
167
-        if (! $success) {
167
+        if ( ! $success) {
168 168
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169 169
             return 0;
170 170
         }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         $original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185 185
         $event_slug = $original_name;
186 186
         while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187
-            $event_slug = sanitize_title($original_name . "-" . ++$count);
187
+            $event_slug = sanitize_title($original_name."-".++$count);
188 188
         }
189 189
         return $event_slug;
190 190
     }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     private function _other_post_exists_with_that_slug($slug)
199 199
     {
200 200
         global $wpdb;
201
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", $slug);
201
+        $query = $wpdb->prepare("SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", $slug);
202 202
         $count = $wpdb->get_var($query);
203 203
         return (bool) intval($count);
204 204
     }
@@ -231,39 +231,39 @@  discard block
 block discarded – undo
231 231
         $meta = maybe_unserialize($old_venue['meta']);
232 232
         // now insert into meta table
233 233
         $insertion_array = array(
234
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
235
-            'VNU_address' => stripslashes($old_venue['address']),// VNU_address
236
-            'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2
237
-            'VNU_city' => stripslashes($old_venue['city']),// VNU_city
238
-            'STA_ID' => $state_id,// STA_ID
239
-            'CNT_ISO' => $country_iso,// CNT_ISO
240
-            'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip
241
-            'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
-            'VNU_capacity' => -1,// VNU_capacity
243
-            'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
-            'VNU_virtual_phone' => '',// VNU_virtual_phone
245
-            'VNU_virtual_url' => '',// VNU_virtual_url
246
-            'VNU_google_map_link' => '',// VNU_google_map_link
234
+            'VNU_ID' => $cpt_id, // VNU_ID_fk
235
+            'VNU_address' => stripslashes($old_venue['address']), // VNU_address
236
+            'VNU_address2' => stripslashes($old_venue['address2']), // VNU_address2
237
+            'VNU_city' => stripslashes($old_venue['city']), // VNU_city
238
+            'STA_ID' => $state_id, // STA_ID
239
+            'CNT_ISO' => $country_iso, // CNT_ISO
240
+            'VNU_zip' => stripslashes($old_venue['zip']), // VNU_zip
241
+            'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '', // VNU_phone
242
+            'VNU_capacity' => -1, // VNU_capacity
243
+            'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '', // VNU_url
244
+            'VNU_virtual_phone' => '', // VNU_virtual_phone
245
+            'VNU_virtual_url' => '', // VNU_virtual_url
246
+            'VNU_google_map_link' => '', // VNU_google_map_link
247 247
             'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
248 248
         );
249 249
         $datatypes = array(
250
-            '%d',// VNU_ID_fk
251
-            '%s',// VNU_address
252
-            '%s',// VNU_address2
253
-            '%s',// VNU_city
254
-            '%d',// STA_ID
255
-            '%s',// CNT_ISO
256
-            '%s',// VNU_zip
257
-            '%s',// VNU_phone
258
-            '%d',// VNU_capacity
259
-            '%s',// VNU_url
260
-            '%s',// VNU_virtual_phone
261
-            '%s',// VNU_virtual_url
262
-            '%s',// VNU_google_map_link
263
-            '%d',// VNU_enable_for_gmap
250
+            '%d', // VNU_ID_fk
251
+            '%s', // VNU_address
252
+            '%s', // VNU_address2
253
+            '%s', // VNU_city
254
+            '%d', // STA_ID
255
+            '%s', // CNT_ISO
256
+            '%s', // VNU_zip
257
+            '%s', // VNU_phone
258
+            '%d', // VNU_capacity
259
+            '%s', // VNU_url
260
+            '%s', // VNU_virtual_phone
261
+            '%s', // VNU_virtual_url
262
+            '%s', // VNU_google_map_link
263
+            '%d', // VNU_enable_for_gmap
264 264
         );
265 265
         $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
-        if (! $success) {
266
+        if ( ! $success) {
267 267
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268 268
             return 0;
269 269
         }
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -63,210 +63,210 @@
 block discarded – undo
63 63
  */
64 64
 class EE_DMS_4_1_0_venues extends EE_Data_Migration_Script_Stage
65 65
 {
66
-    private $_old_table;
67
-    private $_new_table;
68
-    private $_new_meta_table;
69
-    public function _migration_step($num_items = 50)
70
-    {
71
-        global $wpdb;
72
-        $start_at_record = $this->count_records_migrated();
73
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74
-        $items_actually_migrated = 0;
75
-        foreach ($rows as $old_venue) {
76
-            if (! $new_id = $this->_insert_into_posts($old_venue)) {
77
-                $items_actually_migrated++;
78
-                continue;
79
-            }
80
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
-            if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82
-                $items_actually_migrated++;
83
-                continue;
84
-            }
85
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id);
86
-            // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it
87
-            $venue_meta = maybe_unserialize($old_venue['meta']);
88
-            if (isset($venue_meta['contact']) && $venue_meta['contact']) {
89
-                add_post_meta($new_id, 'contact', $venue_meta['contact']);
90
-            }
91
-            // is there an image on this venue?
92
-            $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null;
93
-            if ($guid) {
94
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
95
-            }
96
-            $items_actually_migrated++;
97
-            if ($guid) {
98
-                // if there was an image, we may have had to download it etc and it may have taken
99
-                // longer, then let's not bother migrating anymore on this step
100
-                break;
101
-            }
102
-        }
103
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
104
-            $this->set_completed();
105
-        }
106
-        return $items_actually_migrated;
107
-    }
108
-    public function _count_records_to_migrate()
109
-    {
110
-        global $wpdb;
111
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
112
-        return $count;
113
-    }
114
-    public function __construct()
115
-    {
116
-        $this->_pretty_name = esc_html__("Venues", "event_espresso");
117
-        global $wpdb;
118
-        $this->_old_table = $wpdb->prefix . "events_venue";
119
-        $this->_new_table = $wpdb->posts;
120
-        $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta";
121
-        parent::__construct();
122
-    }
66
+	private $_old_table;
67
+	private $_new_table;
68
+	private $_new_meta_table;
69
+	public function _migration_step($num_items = 50)
70
+	{
71
+		global $wpdb;
72
+		$start_at_record = $this->count_records_migrated();
73
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74
+		$items_actually_migrated = 0;
75
+		foreach ($rows as $old_venue) {
76
+			if (! $new_id = $this->_insert_into_posts($old_venue)) {
77
+				$items_actually_migrated++;
78
+				continue;
79
+			}
80
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
+			if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82
+				$items_actually_migrated++;
83
+				continue;
84
+			}
85
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id);
86
+			// lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it
87
+			$venue_meta = maybe_unserialize($old_venue['meta']);
88
+			if (isset($venue_meta['contact']) && $venue_meta['contact']) {
89
+				add_post_meta($new_id, 'contact', $venue_meta['contact']);
90
+			}
91
+			// is there an image on this venue?
92
+			$guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null;
93
+			if ($guid) {
94
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
95
+			}
96
+			$items_actually_migrated++;
97
+			if ($guid) {
98
+				// if there was an image, we may have had to download it etc and it may have taken
99
+				// longer, then let's not bother migrating anymore on this step
100
+				break;
101
+			}
102
+		}
103
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
104
+			$this->set_completed();
105
+		}
106
+		return $items_actually_migrated;
107
+	}
108
+	public function _count_records_to_migrate()
109
+	{
110
+		global $wpdb;
111
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
112
+		return $count;
113
+	}
114
+	public function __construct()
115
+	{
116
+		$this->_pretty_name = esc_html__("Venues", "event_espresso");
117
+		global $wpdb;
118
+		$this->_old_table = $wpdb->prefix . "events_venue";
119
+		$this->_new_table = $wpdb->posts;
120
+		$this->_new_meta_table = $wpdb->prefix . "esp_venue_meta";
121
+		parent::__construct();
122
+	}
123 123
 
124
-    /**
125
-     * Inserts the CPT
126
-     * @param array $old_venue keys are cols, values are col values
127
-     * @return int
128
-     */
129
-    private function _insert_into_posts($old_venue)
130
-    {
131
-        global $wpdb;
132
-        $meta = maybe_unserialize($old_venue['meta']);
133
-        $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134
-        $insertion_array = array(
135
-                    'post_title' => stripslashes($old_venue['name']),// VNU_name
136
-                    'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
-                    'post_name' => $slug,// VNU_identifier
138
-                    'post_date' => current_time('mysql'),// VNU_created
139
-                    'post_date_gmt' =>  current_time('mysql', true),
140
-                    'post_excerpt' => '',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
-                    'post_modified' => current_time('mysql'),// VNU_modified
142
-                    'post_modified_gmt' => current_time('mysql', true),
143
-                    'post_author' => $old_venue['wp_user'],// VNU_wp_user
144
-                    'post_parent' => 0,// parent
145
-                    'menu_order' => 0,// VNU_order
146
-                    'post_type' => 'espresso_venues'// post_type
147
-                );
148
-        $datatypes_array = array(
149
-                    '%s',// VNU_name
150
-                    '%s',// VNU_desc
151
-                    '%s',// VNU_identifier
152
-                    '%s',// VNU_created
153
-                    '%s',
154
-                    '%s',// VNU_short_desc
155
-                    '%s',// VNU_modified
156
-                    '%s',
157
-                    '%d',// VNU_wp_user
158
-                    '%d',// parent
159
-                    '%d',// VNU_order
160
-                    '%s',// post_type
161
-                );
162
-        $success = $wpdb->insert(
163
-            $this->_new_table,
164
-            $insertion_array,
165
-            $datatypes_array
166
-        );
167
-        if (! $success) {
168
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169
-            return 0;
170
-        }
171
-        return $wpdb->insert_id;
172
-    }
124
+	/**
125
+	 * Inserts the CPT
126
+	 * @param array $old_venue keys are cols, values are col values
127
+	 * @return int
128
+	 */
129
+	private function _insert_into_posts($old_venue)
130
+	{
131
+		global $wpdb;
132
+		$meta = maybe_unserialize($old_venue['meta']);
133
+		$slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134
+		$insertion_array = array(
135
+					'post_title' => stripslashes($old_venue['name']),// VNU_name
136
+					'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
+					'post_name' => $slug,// VNU_identifier
138
+					'post_date' => current_time('mysql'),// VNU_created
139
+					'post_date_gmt' =>  current_time('mysql', true),
140
+					'post_excerpt' => '',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
+					'post_modified' => current_time('mysql'),// VNU_modified
142
+					'post_modified_gmt' => current_time('mysql', true),
143
+					'post_author' => $old_venue['wp_user'],// VNU_wp_user
144
+					'post_parent' => 0,// parent
145
+					'menu_order' => 0,// VNU_order
146
+					'post_type' => 'espresso_venues'// post_type
147
+				);
148
+		$datatypes_array = array(
149
+					'%s',// VNU_name
150
+					'%s',// VNU_desc
151
+					'%s',// VNU_identifier
152
+					'%s',// VNU_created
153
+					'%s',
154
+					'%s',// VNU_short_desc
155
+					'%s',// VNU_modified
156
+					'%s',
157
+					'%d',// VNU_wp_user
158
+					'%d',// parent
159
+					'%d',// VNU_order
160
+					'%s',// post_type
161
+				);
162
+		$success = $wpdb->insert(
163
+			$this->_new_table,
164
+			$insertion_array,
165
+			$datatypes_array
166
+		);
167
+		if (! $success) {
168
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169
+			return 0;
170
+		}
171
+		return $wpdb->insert_id;
172
+	}
173 173
 
174
-    /**
175
-     * Finds a unique slug for this venue, given its name (we could have simply used
176
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
177
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
178
-     * @param string $post_name
179
-     * @return string
180
-     */
181
-    private function _find_unique_slug($post_name, $old_identifier = '')
182
-    {
183
-        $count = 0;
184
-        $original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185
-        $event_slug = $original_name;
186
-        while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187
-            $event_slug = sanitize_title($original_name . "-" . ++$count);
188
-        }
189
-        return $event_slug;
190
-    }
174
+	/**
175
+	 * Finds a unique slug for this venue, given its name (we could have simply used
176
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
177
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
178
+	 * @param string $post_name
179
+	 * @return string
180
+	 */
181
+	private function _find_unique_slug($post_name, $old_identifier = '')
182
+	{
183
+		$count = 0;
184
+		$original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185
+		$event_slug = $original_name;
186
+		while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187
+			$event_slug = sanitize_title($original_name . "-" . ++$count);
188
+		}
189
+		return $event_slug;
190
+	}
191 191
 
192
-    /**
193
-     * returns whether or not there is a post that has this same slug (post_title)
194
-     * @global type $wpdb
195
-     * @param type $slug
196
-     * @return boolean
197
-     */
198
-    private function _other_post_exists_with_that_slug($slug)
199
-    {
200
-        global $wpdb;
201
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", $slug);
202
-        $count = $wpdb->get_var($query);
203
-        return (bool) intval($count);
204
-    }
192
+	/**
193
+	 * returns whether or not there is a post that has this same slug (post_title)
194
+	 * @global type $wpdb
195
+	 * @param type $slug
196
+	 * @return boolean
197
+	 */
198
+	private function _other_post_exists_with_that_slug($slug)
199
+	{
200
+		global $wpdb;
201
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", $slug);
202
+		$count = $wpdb->get_var($query);
203
+		return (bool) intval($count);
204
+	}
205 205
 
206
-    /**
207
-     * Inserts into the venue_meta table
208
-     * @param type $cpt_id
209
-     * @param type $old_venue
210
-     * @return int
211
-     */
212
-    private function _insert_into_meta_table($cpt_id, $old_venue)
213
-    {
214
-        global $wpdb;
215
-        // get a country with the same name, or insert one
216
-        try {
217
-            $country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country']));
218
-            $country_iso = $country['CNT_ISO'];
219
-        } catch (EE_Error $e) {
220
-            $this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
221
-            $country_iso = null;
222
-        }
223
-        // get a state with the same name, if possible
224
-        try {
225
-            $state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags((string) $old_venue['country']));
226
-            $state_id = $state['STA_ID'];
227
-        } catch (EE_Error $e) {
228
-            $this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
229
-            $state_id = 0;
230
-        }
231
-        $meta = maybe_unserialize($old_venue['meta']);
232
-        // now insert into meta table
233
-        $insertion_array = array(
234
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
235
-            'VNU_address' => stripslashes($old_venue['address']),// VNU_address
236
-            'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2
237
-            'VNU_city' => stripslashes($old_venue['city']),// VNU_city
238
-            'STA_ID' => $state_id,// STA_ID
239
-            'CNT_ISO' => $country_iso,// CNT_ISO
240
-            'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip
241
-            'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
-            'VNU_capacity' => -1,// VNU_capacity
243
-            'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
-            'VNU_virtual_phone' => '',// VNU_virtual_phone
245
-            'VNU_virtual_url' => '',// VNU_virtual_url
246
-            'VNU_google_map_link' => '',// VNU_google_map_link
247
-            'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
248
-        );
249
-        $datatypes = array(
250
-            '%d',// VNU_ID_fk
251
-            '%s',// VNU_address
252
-            '%s',// VNU_address2
253
-            '%s',// VNU_city
254
-            '%d',// STA_ID
255
-            '%s',// CNT_ISO
256
-            '%s',// VNU_zip
257
-            '%s',// VNU_phone
258
-            '%d',// VNU_capacity
259
-            '%s',// VNU_url
260
-            '%s',// VNU_virtual_phone
261
-            '%s',// VNU_virtual_url
262
-            '%s',// VNU_google_map_link
263
-            '%d',// VNU_enable_for_gmap
264
-        );
265
-        $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
-        if (! $success) {
267
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268
-            return 0;
269
-        }
270
-        return $wpdb->insert_id;
271
-    }
206
+	/**
207
+	 * Inserts into the venue_meta table
208
+	 * @param type $cpt_id
209
+	 * @param type $old_venue
210
+	 * @return int
211
+	 */
212
+	private function _insert_into_meta_table($cpt_id, $old_venue)
213
+	{
214
+		global $wpdb;
215
+		// get a country with the same name, or insert one
216
+		try {
217
+			$country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country']));
218
+			$country_iso = $country['CNT_ISO'];
219
+		} catch (EE_Error $e) {
220
+			$this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
221
+			$country_iso = null;
222
+		}
223
+		// get a state with the same name, if possible
224
+		try {
225
+			$state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags((string) $old_venue['country']));
226
+			$state_id = $state['STA_ID'];
227
+		} catch (EE_Error $e) {
228
+			$this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
229
+			$state_id = 0;
230
+		}
231
+		$meta = maybe_unserialize($old_venue['meta']);
232
+		// now insert into meta table
233
+		$insertion_array = array(
234
+			'VNU_ID' => $cpt_id,// VNU_ID_fk
235
+			'VNU_address' => stripslashes($old_venue['address']),// VNU_address
236
+			'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2
237
+			'VNU_city' => stripslashes($old_venue['city']),// VNU_city
238
+			'STA_ID' => $state_id,// STA_ID
239
+			'CNT_ISO' => $country_iso,// CNT_ISO
240
+			'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip
241
+			'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
+			'VNU_capacity' => -1,// VNU_capacity
243
+			'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
+			'VNU_virtual_phone' => '',// VNU_virtual_phone
245
+			'VNU_virtual_url' => '',// VNU_virtual_url
246
+			'VNU_google_map_link' => '',// VNU_google_map_link
247
+			'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
248
+		);
249
+		$datatypes = array(
250
+			'%d',// VNU_ID_fk
251
+			'%s',// VNU_address
252
+			'%s',// VNU_address2
253
+			'%s',// VNU_city
254
+			'%d',// STA_ID
255
+			'%s',// CNT_ISO
256
+			'%s',// VNU_zip
257
+			'%s',// VNU_phone
258
+			'%d',// VNU_capacity
259
+			'%s',// VNU_url
260
+			'%s',// VNU_virtual_phone
261
+			'%s',// VNU_virtual_url
262
+			'%s',// VNU_google_map_link
263
+			'%d',// VNU_enable_for_gmap
264
+		);
265
+		$success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
+		if (! $success) {
267
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268
+			return 0;
269
+		}
270
+		return $wpdb->insert_id;
271
+	}
272 272
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_line_items.dmsstage.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -39,172 +39,172 @@
 block discarded – undo
39 39
  */
40 40
 class EE_DMS_4_1_0_line_items extends EE_Data_Migration_Script_Stage_Table
41 41
 {
42
-    private $_new_line_table;
43
-    private $_new_transaction_table;
44
-    private $_new_reg_table;
45
-    public function __construct()
46
-    {
47
-        global $wpdb;
48
-        $this->_pretty_name = esc_html__("Line Items", "event_espresso");
49
-        $this->_old_table = $wpdb->prefix . "events_attendee";
50
-        $this->select_expression = 'att.*, e.event_status';
51
-        $this->_extra_where_sql = ' AS att
42
+	private $_new_line_table;
43
+	private $_new_transaction_table;
44
+	private $_new_reg_table;
45
+	public function __construct()
46
+	{
47
+		global $wpdb;
48
+		$this->_pretty_name = esc_html__("Line Items", "event_espresso");
49
+		$this->_old_table = $wpdb->prefix . "events_attendee";
50
+		$this->select_expression = 'att.*, e.event_status';
51
+		$this->_extra_where_sql = ' AS att
52 52
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
53 53
             WHERE e.event_status!="D"';
54
-        $this->_new_transaction_table = $wpdb->prefix . "esp_transaction";
55
-        $this->_new_line_table = $wpdb->prefix . "esp_line_item";
56
-        $this->_new_reg_table = $wpdb->prefix . "esp_registration";
57
-        parent::__construct();
58
-    }
54
+		$this->_new_transaction_table = $wpdb->prefix . "esp_transaction";
55
+		$this->_new_line_table = $wpdb->prefix . "esp_line_item";
56
+		$this->_new_reg_table = $wpdb->prefix . "esp_registration";
57
+		parent::__construct();
58
+	}
59 59
 
60
-    protected function _migrate_old_row($old_row)
61
-    {
62
-        // insert line items if its a primary id
63
-        if (intval($old_row['is_primary'])) {
64
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table);
65
-            if (! $txn_id) {
66
-                $this->add_error(sprintf(esc_html__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row)));
67
-                return;
68
-            }
69
-            $txn = $this->_get_txn($txn_id);
70
-            $new_line_items = $this->_insert_new_line_items($txn, $old_row);
71
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items);
72
-        }
73
-    }
60
+	protected function _migrate_old_row($old_row)
61
+	{
62
+		// insert line items if its a primary id
63
+		if (intval($old_row['is_primary'])) {
64
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table);
65
+			if (! $txn_id) {
66
+				$this->add_error(sprintf(esc_html__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row)));
67
+				return;
68
+			}
69
+			$txn = $this->_get_txn($txn_id);
70
+			$new_line_items = $this->_insert_new_line_items($txn, $old_row);
71
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_line_table, $new_line_items);
72
+		}
73
+	}
74 74
 
75
-    private function _get_txn($txn_id)
76
-    {
77
-        global $wpdb;
78
-        $txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A);
79
-        return $txn;
80
-    }
75
+	private function _get_txn($txn_id)
76
+	{
77
+		global $wpdb;
78
+		$txn = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->_new_transaction_table WHERE TXN_ID=%d", $txn_id), ARRAY_A);
79
+		return $txn;
80
+	}
81 81
 
82
-    /**
83
-     * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need
84
-     * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors).
85
-     * But seeing how these are REGs created from 3.1 attendee data, which have
86
-     * @param array $transaction
87
-     * @return array new line item ids
88
-     */
89
-    private function _insert_new_line_items($transaction, $old_attendee)
90
-    {
91
-        global $wpdb;
92
-        $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_new_reg_table . " WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A);
93
-        $new_line_item_ids = array();
94
-        // create a totla line item
95
-        $total_line_item_id = $this->_insert_new_line_item(array(
96
-            'LIN_code' => 'total',
97
-            'TXN_ID' => $transaction['TXN_ID'],
98
-            'LIN_name' =>  esc_html__("Total", "event_espresso"),
99
-            'LIN_total' => $transaction['TXN_total'],
100
-            'LIN_type' => 'total',
101
-            'OBJ_ID' => $transaction['TXN_ID'],
102
-            'OBJ_type' => 'Transaction'
103
-        ), $old_attendee);
104
-        $new_line_item_ids[] = $total_line_item_id;
105
-        // create a subtotal line item
106
-        $reg_total = 0;
107
-        foreach ($regs_on_this_transaction as $new_reg) {
108
-            $reg_total += floatval($new_reg['REG_final_price']);
109
-        }
110
-        $subtotal_line_item_id = $this->_insert_new_line_item(array(
111
-            'LIN_code' => 'sub-total',
112
-            'TXN_ID' => $transaction['TXN_ID'],
113
-            'LIN_name' =>  esc_html__("Subtotal", "event_espresso"),
114
-            'LIN_total' => $reg_total,
115
-            'LIN_parent' => $total_line_item_id,
116
-            'LIN_type' => 'sub-total',
117
-        ), $old_attendee);
118
-        $new_line_item_ids[] = $subtotal_line_item_id;
119
-        // group REGs by TKT_ID
120
-        $regs_by_tkt = array();
121
-        foreach ($regs_on_this_transaction as $new_reg) {
122
-            $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg;
123
-        }
82
+	/**
83
+	 * In 4.1, we'd normally need more info than just the registrations to make the line items. Ie, we'd need
84
+	 * the transaction, and tax prices at the time of registration. (And probably promotions and other price factors).
85
+	 * But seeing how these are REGs created from 3.1 attendee data, which have
86
+	 * @param array $transaction
87
+	 * @return array new line item ids
88
+	 */
89
+	private function _insert_new_line_items($transaction, $old_attendee)
90
+	{
91
+		global $wpdb;
92
+		$regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_new_reg_table . " WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A);
93
+		$new_line_item_ids = array();
94
+		// create a totla line item
95
+		$total_line_item_id = $this->_insert_new_line_item(array(
96
+			'LIN_code' => 'total',
97
+			'TXN_ID' => $transaction['TXN_ID'],
98
+			'LIN_name' =>  esc_html__("Total", "event_espresso"),
99
+			'LIN_total' => $transaction['TXN_total'],
100
+			'LIN_type' => 'total',
101
+			'OBJ_ID' => $transaction['TXN_ID'],
102
+			'OBJ_type' => 'Transaction'
103
+		), $old_attendee);
104
+		$new_line_item_ids[] = $total_line_item_id;
105
+		// create a subtotal line item
106
+		$reg_total = 0;
107
+		foreach ($regs_on_this_transaction as $new_reg) {
108
+			$reg_total += floatval($new_reg['REG_final_price']);
109
+		}
110
+		$subtotal_line_item_id = $this->_insert_new_line_item(array(
111
+			'LIN_code' => 'sub-total',
112
+			'TXN_ID' => $transaction['TXN_ID'],
113
+			'LIN_name' =>  esc_html__("Subtotal", "event_espresso"),
114
+			'LIN_total' => $reg_total,
115
+			'LIN_parent' => $total_line_item_id,
116
+			'LIN_type' => 'sub-total',
117
+		), $old_attendee);
118
+		$new_line_item_ids[] = $subtotal_line_item_id;
119
+		// group REGs by TKT_ID
120
+		$regs_by_tkt = array();
121
+		foreach ($regs_on_this_transaction as $new_reg) {
122
+			$regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg;
123
+		}
124 124
 
125
-        // create individual line items
125
+		// create individual line items
126 126
 
127
-        foreach ($regs_by_tkt as $ticket_id => $regs) {
128
-            $count = count($regs);
129
-            $line_total = 0;
130
-            foreach ($regs as $new_reg) {
131
-                $line_total += $new_reg['REG_final_price'];
132
-            }
133
-            $a_reg = reset($regs);
134
-            $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']);
135
-            $reg_line_item_id = $this->_insert_new_line_item(array(
136
-                'LIN_code' => md5('Ticket' . $ticket_id . time()),
137
-                'TXN_ID' => $transaction['TXN_ID'],
138
-                'LIN_name' => $new_ticket['TKT_name'],
139
-                'LIN_unit_price' => $a_reg['REG_final_price'],
140
-                'LIN_is_taxable' => false,
141
-                'LIN_total' => $line_total,
142
-                'LIN_quantity' => $count,
143
-                'LIN_parent' => $subtotal_line_item_id,
144
-                'OBJ_ID' => $ticket_id,
145
-                'OBJ_type' => 'Ticket'
146
-            ), $old_attendee);
147
-            $new_line_item_ids[] = $reg_line_item_id;
148
-        }
127
+		foreach ($regs_by_tkt as $ticket_id => $regs) {
128
+			$count = count($regs);
129
+			$line_total = 0;
130
+			foreach ($regs as $new_reg) {
131
+				$line_total += $new_reg['REG_final_price'];
132
+			}
133
+			$a_reg = reset($regs);
134
+			$new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']);
135
+			$reg_line_item_id = $this->_insert_new_line_item(array(
136
+				'LIN_code' => md5('Ticket' . $ticket_id . time()),
137
+				'TXN_ID' => $transaction['TXN_ID'],
138
+				'LIN_name' => $new_ticket['TKT_name'],
139
+				'LIN_unit_price' => $a_reg['REG_final_price'],
140
+				'LIN_is_taxable' => false,
141
+				'LIN_total' => $line_total,
142
+				'LIN_quantity' => $count,
143
+				'LIN_parent' => $subtotal_line_item_id,
144
+				'OBJ_ID' => $ticket_id,
145
+				'OBJ_type' => 'Ticket'
146
+			), $old_attendee);
147
+			$new_line_item_ids[] = $reg_line_item_id;
148
+		}
149 149
 
150 150
 
151 151
 
152
-        return $new_line_item_ids;
153
-    }
154
-    /**
155
-     * Gets the full ticket by ID
156
-     * @global type $wpdb
157
-     * @param type $new_ticket_id
158
-     * @return array
159
-     */
160
-    private function _get_new_ticket_row($new_ticket_id)
161
-    {
162
-        global $wpdb;
163
-        $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A);
164
-        return $ticket_row;
165
-    }
152
+		return $new_line_item_ids;
153
+	}
154
+	/**
155
+	 * Gets the full ticket by ID
156
+	 * @global type $wpdb
157
+	 * @param type $new_ticket_id
158
+	 * @return array
159
+	 */
160
+	private function _get_new_ticket_row($new_ticket_id)
161
+	{
162
+		global $wpdb;
163
+		$ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A);
164
+		return $ticket_row;
165
+	}
166 166
 
167
-    private function _insert_new_line_item($cols_n_values, $old_attendee)
168
-    {
169
-        global $wpdb;
170
-        $default_cols_n_values = array(
171
-            'LIN_code' => '',
172
-            'TXN_ID' => 0,
173
-            'LIN_name' => '',
174
-            'LIN_desc' => '',
175
-            'LIN_unit_price' => 0,
176
-            'LIN_percent' => 0,
177
-            'LIN_is_taxable' => false,
178
-            'LIN_order' => 0,
179
-            'LIN_total' => 0,
180
-            'LIN_quantity' => null,
181
-            'LIN_parent' => 0,
182
-            'LIN_type' => 'line-item',
183
-            'OBJ_ID' => null,
184
-            'OBJ_type' => null
185
-        );
186
-        $cols_n_values = array_merge($default_cols_n_values, $cols_n_values);
187
-            $datatypes = array(
188
-                '%s',// LIN_code
189
-                '%d',// TXN_ID
190
-                '%s',// LIN_name
191
-                '%s',// LIN_desc
192
-                '%f',// LIN_unit_price
193
-                '%f',// LIN_percent
194
-                '%d',// LIN_is_taxable
195
-                '%d',// LIN_order
196
-                '%f',// LIN_total
197
-                '%d',// LIN_quantity
198
-                '%d',// LIN_parent
199
-                '%s',// LIN_type
200
-                '%d',// OBJ_ID
201
-                '%s',// OBJ_type
202
-            );
203
-            $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes);
204
-            if (! $success) {
205
-                $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));
206
-                return 0;
207
-            }
208
-            return $wpdb->insert_id;
209
-    }
167
+	private function _insert_new_line_item($cols_n_values, $old_attendee)
168
+	{
169
+		global $wpdb;
170
+		$default_cols_n_values = array(
171
+			'LIN_code' => '',
172
+			'TXN_ID' => 0,
173
+			'LIN_name' => '',
174
+			'LIN_desc' => '',
175
+			'LIN_unit_price' => 0,
176
+			'LIN_percent' => 0,
177
+			'LIN_is_taxable' => false,
178
+			'LIN_order' => 0,
179
+			'LIN_total' => 0,
180
+			'LIN_quantity' => null,
181
+			'LIN_parent' => 0,
182
+			'LIN_type' => 'line-item',
183
+			'OBJ_ID' => null,
184
+			'OBJ_type' => null
185
+		);
186
+		$cols_n_values = array_merge($default_cols_n_values, $cols_n_values);
187
+			$datatypes = array(
188
+				'%s',// LIN_code
189
+				'%d',// TXN_ID
190
+				'%s',// LIN_name
191
+				'%s',// LIN_desc
192
+				'%f',// LIN_unit_price
193
+				'%f',// LIN_percent
194
+				'%d',// LIN_is_taxable
195
+				'%d',// LIN_order
196
+				'%f',// LIN_total
197
+				'%d',// LIN_quantity
198
+				'%d',// LIN_parent
199
+				'%s',// LIN_type
200
+				'%d',// OBJ_ID
201
+				'%s',// OBJ_type
202
+			);
203
+			$success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes);
204
+			if (! $success) {
205
+				$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));
206
+				return 0;
207
+			}
208
+			return $wpdb->insert_id;
209
+	}
210 210
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
     {
47 47
         global $wpdb;
48 48
         $this->_pretty_name = esc_html__("Line Items", "event_espresso");
49
-        $this->_old_table = $wpdb->prefix . "events_attendee";
49
+        $this->_old_table = $wpdb->prefix."events_attendee";
50 50
         $this->select_expression = 'att.*, e.event_status';
51 51
         $this->_extra_where_sql = ' AS att
52
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
52
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id
53 53
             WHERE e.event_status!="D"';
54
-        $this->_new_transaction_table = $wpdb->prefix . "esp_transaction";
55
-        $this->_new_line_table = $wpdb->prefix . "esp_line_item";
56
-        $this->_new_reg_table = $wpdb->prefix . "esp_registration";
54
+        $this->_new_transaction_table = $wpdb->prefix."esp_transaction";
55
+        $this->_new_line_table = $wpdb->prefix."esp_line_item";
56
+        $this->_new_reg_table = $wpdb->prefix."esp_registration";
57 57
         parent::__construct();
58 58
     }
59 59
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         // insert line items if its a primary id
63 63
         if (intval($old_row['is_primary'])) {
64 64
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table);
65
-            if (! $txn_id) {
65
+            if ( ! $txn_id) {
66 66
                 $this->add_error(sprintf(esc_html__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"), $old_row['id'], $this->_json_encode($old_row)));
67 67
                 return;
68 68
             }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     private function _insert_new_line_items($transaction, $old_attendee)
90 90
     {
91 91
         global $wpdb;
92
-        $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_new_reg_table . " WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A);
92
+        $regs_on_this_transaction = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_new_reg_table." WHERE TXN_ID=%d", $transaction['TXN_ID']), ARRAY_A);
93 93
         $new_line_item_ids = array();
94 94
         // create a totla line item
95 95
         $total_line_item_id = $this->_insert_new_line_item(array(
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         // group REGs by TKT_ID
120 120
         $regs_by_tkt = array();
121 121
         foreach ($regs_on_this_transaction as $new_reg) {
122
-            $regs_by_tkt[ $new_reg['TKT_ID'] ][] = $new_reg;
122
+            $regs_by_tkt[$new_reg['TKT_ID']][] = $new_reg;
123 123
         }
124 124
 
125 125
         // create individual line items
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             $a_reg = reset($regs);
134 134
             $new_ticket = $this->_get_new_ticket_row($a_reg['TKT_ID']);
135 135
             $reg_line_item_id = $this->_insert_new_line_item(array(
136
-                'LIN_code' => md5('Ticket' . $ticket_id . time()),
136
+                'LIN_code' => md5('Ticket'.$ticket_id.time()),
137 137
                 'TXN_ID' => $transaction['TXN_ID'],
138 138
                 'LIN_name' => $new_ticket['TKT_name'],
139 139
                 'LIN_unit_price' => $a_reg['REG_final_price'],
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     private function _get_new_ticket_row($new_ticket_id)
161 161
     {
162 162
         global $wpdb;
163
-        $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A);
163
+        $ticket_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."esp_ticket WHERE TKT_ID=%d", $new_ticket_id), ARRAY_A);
164 164
         return $ticket_row;
165 165
     }
166 166
 
@@ -185,23 +185,23 @@  discard block
 block discarded – undo
185 185
         );
186 186
         $cols_n_values = array_merge($default_cols_n_values, $cols_n_values);
187 187
             $datatypes = array(
188
-                '%s',// LIN_code
189
-                '%d',// TXN_ID
190
-                '%s',// LIN_name
191
-                '%s',// LIN_desc
192
-                '%f',// LIN_unit_price
193
-                '%f',// LIN_percent
194
-                '%d',// LIN_is_taxable
195
-                '%d',// LIN_order
196
-                '%f',// LIN_total
197
-                '%d',// LIN_quantity
198
-                '%d',// LIN_parent
199
-                '%s',// LIN_type
200
-                '%d',// OBJ_ID
201
-                '%s',// OBJ_type
188
+                '%s', // LIN_code
189
+                '%d', // TXN_ID
190
+                '%s', // LIN_name
191
+                '%s', // LIN_desc
192
+                '%f', // LIN_unit_price
193
+                '%f', // LIN_percent
194
+                '%d', // LIN_is_taxable
195
+                '%d', // LIN_order
196
+                '%f', // LIN_total
197
+                '%d', // LIN_quantity
198
+                '%d', // LIN_parent
199
+                '%s', // LIN_type
200
+                '%d', // OBJ_ID
201
+                '%s', // OBJ_type
202 202
             );
203 203
             $success = $wpdb->insert($this->_new_line_table, $cols_n_values, $datatypes);
204
-            if (! $success) {
204
+            if ( ! $success) {
205 205
                 $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));
206 206
                 return 0;
207 207
             }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_attendees.dmsstage.php 2 patches
Indentation   +636 added lines, -636 removed lines patch added patch discarded remove patch
@@ -183,647 +183,647 @@
 block discarded – undo
183 183
  */
184 184
 class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table
185 185
 {
186
-    private $_new_attendee_cpt_table;
187
-    private $_new_attendee_meta_table;
188
-    private $_new_reg_table;
189
-    private $_new_transaction_table;
190
-    private $_new_payment_table;
191
-    private $_new_line_table;
192
-    private $_old_mer_table;
193
-    private $_new_ticket_table;
194
-    private $_new_ticket_datetime_table;
195
-    private $_new_datetime_table;
196
-    private $_new_datetime_ticket_table;
197
-    private $_new_price_table;
198
-    private $_new_ticket_price_table;
199
-    /**
200
-     * Rememebrs whether or not the mer table exists
201
-     * @var boolean
202
-     */
203
-    private $_mer_tables_exist = null;
204
-
205
-    public function __construct()
206
-    {
207
-        global $wpdb;
208
-        $this->_pretty_name = esc_html__("Attendees", "event_espresso");
209
-        $this->_old_table = $wpdb->prefix . "events_attendee";
210
-        // Only select the event status column from the event table.
211
-        $this->select_expression = 'att.*, e.event_status';
212
-        // Only select attendees for events that aren't deleted.
213
-        $this->_extra_where_sql = 'AS att
186
+	private $_new_attendee_cpt_table;
187
+	private $_new_attendee_meta_table;
188
+	private $_new_reg_table;
189
+	private $_new_transaction_table;
190
+	private $_new_payment_table;
191
+	private $_new_line_table;
192
+	private $_old_mer_table;
193
+	private $_new_ticket_table;
194
+	private $_new_ticket_datetime_table;
195
+	private $_new_datetime_table;
196
+	private $_new_datetime_ticket_table;
197
+	private $_new_price_table;
198
+	private $_new_ticket_price_table;
199
+	/**
200
+	 * Rememebrs whether or not the mer table exists
201
+	 * @var boolean
202
+	 */
203
+	private $_mer_tables_exist = null;
204
+
205
+	public function __construct()
206
+	{
207
+		global $wpdb;
208
+		$this->_pretty_name = esc_html__("Attendees", "event_espresso");
209
+		$this->_old_table = $wpdb->prefix . "events_attendee";
210
+		// Only select the event status column from the event table.
211
+		$this->select_expression = 'att.*, e.event_status';
212
+		// Only select attendees for events that aren't deleted.
213
+		$this->_extra_where_sql = 'AS att
214 214
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
215 215
             WHERE e.event_status!="D"';
216
-        $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group";
217
-        $this->_new_attendee_cpt_table = $wpdb->posts;
218
-        $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta";
219
-        $this->_new_reg_table = $wpdb->prefix . "esp_registration";
220
-        $this->_new_transaction_table = $wpdb->prefix . "esp_transaction";
221
-        $this->_new_payment_table = $wpdb->prefix . "esp_payment";
222
-        $this->_new_line_table = $wpdb->prefix . "esp_line_item";
223
-        $this->_new_ticket_table = $wpdb->prefix . "esp_ticket";
224
-        $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket";
225
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
226
-        $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket";
227
-        $this->_new_price_table = $wpdb->prefix . "esp_price";
228
-        $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price";
229
-        parent::__construct();
230
-    }
231
-
232
-    protected function _migrate_old_row($old_row)
233
-    {
234
-        // first check if there's already a new attendee with similar characteristics
235
-        $new_att_id = $this->_find_attendee_cpt_matching($old_row);
236
-        if (!$new_att_id) {
237
-            $new_att_id = $this->_insert_new_attendee_cpt($old_row);
238
-            if (!$new_att_id) {
239
-                // if we couldnt even make an attendee, abandon all hope
240
-                return false;
241
-            }
242
-            $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
243
-            if ($new_att_meta_id) {
244
-                $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
245
-            }
246
-        }
247
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
248
-
249
-        $txn_id = $this->_insert_new_transaction($old_row);
250
-        if (!$txn_id) {
251
-            // if we couldnt make the transaction, also abandon all hope
252
-            return false;
253
-        }
254
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
255
-        $pay_id = $this->_insert_new_payment($old_row, $txn_id);
256
-        if ($pay_id) {
257
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
258
-        }
259
-
260
-
261
-        // even if there was no payment, we can go ahead with adding the reg
262
-        $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
263
-        if ($new_regs) {
264
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
265
-        }
266
-    }
267
-
268
-    /**
269
-     * Checks if there's already an attendee CPT in the db that has the same
270
-     * first and last name, and email. If so, returns its ID as an int.
271
-     * @global type $wpdb
272
-     * @param array $old_attendee
273
-     * @return int
274
-     */
275
-    private function _find_attendee_cpt_matching($old_attendee)
276
-    {
277
-        global $wpdb;
278
-        $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']));
279
-        return intval($existing_attendee_id);
280
-    }
281
-
282
-    private function _insert_new_attendee_cpt($old_attendee)
283
-    {
284
-        global $wpdb;
285
-        $cols_n_values = array(
286
-            'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name
287
-            'post_content' => '',// ATT_bio
288
-            'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug
289
-            'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
290
-            'post_excerpt' => '',// ATT_short_bio
291
-            'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
292
-            'post_author' => 0,// ATT_author
293
-            'post_parent' => 0,// ATT_parent
294
-            'post_type' => 'espresso_attendees',// post_type
295
-            'post_status' => 'publish'// status
296
-        );
297
-        $datatypes = array(
298
-            '%s',// ATT_full_name
299
-            '%s',// ATT_bio
300
-            '%s',// ATT_slug
301
-            '%s',// ATT_created
302
-            '%s',// ATT_short_bio
303
-            '%s',// ATT_modified
304
-            '%d',// ATT_author
305
-            '%d',// ATT_parent
306
-            '%s',// post_type
307
-            '%s',// status
308
-        );
309
-        $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
310
-        if (!$success) {
311
-            $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));
312
-            return 0;
313
-        }
314
-        $new_id = $wpdb->insert_id;
315
-        return $new_id;
316
-    }
317
-
318
-    private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
319
-    {
320
-        global $wpdb;
321
-        // get the state and country ids from the old row
322
-        try {
323
-            $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
324
-            $new_country_iso = $new_country['CNT_ISO'];
325
-        } catch (EE_Error $exception) {
326
-            $new_country_iso = $this->get_migration_script()->get_default_country_iso();
327
-        }
328
-        try {
329
-            $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
330
-            $new_state_id = $new_state['STA_ID'];
331
-        } catch (EE_Error $exception) {
332
-            $new_state_id = 0;
333
-        }
334
-        $cols_n_values = array(
335
-            'ATT_ID' => $new_attendee_cpt_id,
336
-            'ATT_fname' => stripslashes($old_attendee['fname']),
337
-            'ATT_lname' => stripslashes($old_attendee['lname']),
338
-            'ATT_address' => stripslashes($old_attendee['address']),
339
-            'ATT_address2' => stripslashes($old_attendee['address2']),
340
-            'ATT_city' => stripslashes($old_attendee['city']),
341
-            'STA_ID' => $new_state_id,
342
-            'CNT_ISO' => $new_country_iso,
343
-            'ATT_zip' => stripslashes($old_attendee['zip']),
344
-            'ATT_email' => stripslashes($old_attendee['email']),
345
-            'ATT_phone' => stripslashes($old_attendee['phone']),
346
-        );
347
-        $datatypes = array(
348
-            '%d',// ATT_ID
349
-            '%s',// ATT_fname
350
-            '%s',// ATT_lname
351
-            '%s',// ATT_address
352
-            '%s',// ATT_address2
353
-            '%s',// ATT_city
354
-            '%d',// STA_ID
355
-            '%s',// CNT_ISO
356
-            '%s',// ATT_zip
357
-            '%s',// ATT_email
358
-            '%s',// ATT_phone
359
-        );
360
-        $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
361
-        if (!$success) {
362
-            $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));
363
-            return 0;
364
-        }
365
-        $new_id = $wpdb->insert_id;
366
-        return $new_id;
367
-    }
368
-
369
-    /**
370
-     * Note: we don't necessarily create a new transaction for each attendee row.
371
-     * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
372
-     * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
373
-     * @global type $wpdb
374
-     * @param type $old_attendee
375
-     * @return int new transaction id
376
-     */
377
-    private function _insert_new_transaction($old_attendee)
378
-    {
379
-        global $wpdb;
380
-
381
-        // first: let's check for an existing transaction for this old attendee
382
-        if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
383
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
384
-        } else { // non-primary attendee, so find its primary attendee's transaction
385
-            $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']));
386
-            if (!$primary_attendee_old_id) {
387
-                $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
388
-                $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
389
-            }
390
-            $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
391
-            if (!$txn_id) {
392
-                $this->add_error(sprintf(esc_html__("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));
393
-                $txn_id = 0;
394
-            }
395
-        }
396
-        // if there isn't yet a transaction row for this, create one
397
-        // (so even if it was a non-primary attendee with no EE3 primary attendee,
398
-        // it ought to have SOME transaction, so we'll make one)
399
-        if (!$txn_id) {
400
-            // maps 3.1 payment stati onto 4.1 transaction stati
401
-            $txn_status_mapping = array(
402
-                'Completed' => 'TCM',
403
-                'Pending' => 'TIN',
404
-                'Payment Declined' => 'TIN',
405
-                'Incomplete' => 'TIN',
406
-                'Not Completed' => 'TIN',
407
-                'Cancelled' => 'TIN',
408
-                'Declined' => 'TIN'
409
-            );
410
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
411
-            $cols_n_values = array(
412
-                'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
413
-                'TXN_total' => floatval($old_attendee['total_cost']),
414
-                'TXN_paid' => floatval($old_attendee['amount_pd']),
415
-                'STS_ID' => $STS_ID,
416
-                'TXN_hash_salt' => $old_attendee['hashSalt']
417
-            );
418
-            $datatypes = array(
419
-                '%s',// TXN_timestamp
420
-                '%f',// TXN_total
421
-                '%f',// TXN_paid
422
-                '%s',// STS_ID
423
-                '%s',// TXN_hash_salt
424
-            );
425
-            $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
426
-            if (!$success) {
427
-                $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));
428
-                return 0;
429
-            }
430
-            $txn_id = $wpdb->insert_id;
431
-        }
432
-
433
-        return $txn_id;
434
-    }
435
-
436
-    /**
437
-     * Detects if the MER tables exist
438
-     * @global type $wpdb
439
-     * @return boolean
440
-     */
441
-    private function _mer_tables_exist()
442
-    {
443
-        if ($this->_mer_tables_exist === null) {
444
-            global $wpdb;
445
-
446
-            if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
447
-                $this->_mer_tables_exist = false;
448
-            } else {
449
-                $this->_mer_tables_exist = true;
450
-            }
451
-        }
452
-        return $this->_mer_tables_exist;
453
-    }
454
-
455
-    /**
456
-     * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
457
-     * whether the event required pre-approval or not,a dn the 4.1 payment status.
458
-     * @global type $wpdb
459
-     * @param type $old_attendee_row
460
-     * @return string
461
-     */
462
-    private function _get_reg_status_for_old_payment_status($old_attendee_row)
463
-    {
464
-        // need event default reg status and if pre_approval was required
465
-        global $wpdb;
466
-        $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']));
467
-        return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
468
-            $old_attendee_row['payment_status'],
469
-            intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
470
-        );
471
-    }
472
-
473
-    /**
474
-     * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
475
-     * and returns an array of their IDs
476
-     * @global type $wpdb
477
-     * @param array $old_attendee
478
-     * @param int $new_attendee_id
479
-     * @param int $new_txn_id
480
-     * @return array of new registratio ids
481
-     */
482
-    private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
483
-    {
484
-        global $wpdb;
485
-
486
-        $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
487
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts);
488
-        if (!$new_event_id) {
489
-            $this->add_error(sprintf(esc_html__("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)));
490
-        }
491
-
492
-        $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
493
-        if (!$ticket_id) {
494
-            $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
495
-            $this->add_error(sprintf(esc_html__('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));
496
-        }
497
-        $regs_on_this_row = intval($old_attendee['quantity']);
498
-        $new_regs = array();
499
-        // 4 cases we need to account for:
500
-        // 1 old attendee_details row with a quantity of X (no mer)
501
-        // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
502
-        // Y old attendee_details rows with a quantity of x (because of mer)
503
-        // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
504
-        for ($count = 1; $count <= $regs_on_this_row; $count++) {
505
-            // sum regs on older rows
506
-            $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
507
-            $cols_n_values = array(
508
-                'EVT_ID' => $new_event_id,
509
-                'ATT_ID' => $new_attendee_id,
510
-                'TXN_ID' => $new_txn_id,
511
-                'TKT_ID' => $ticket_id,
512
-                'STS_ID' => $STS_ID,
513
-                'REG_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
514
-                'REG_final_price' => $old_attendee['final_price'],
515
-                'REG_session' => substr($old_attendee['attendee_session'], 0, 44),
516
-                'REG_code' => sanitize_key($old_attendee['registration_id']),
517
-                'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count),
518
-                'REG_count' => $regs_on_this_event_and_txn + $count,
519
-                'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false),
520
-                'REG_att_is_going' => true,
521
-                'REG_deleted' => false
522
-            );
523
-            $datatypes = array(
524
-                '%d',// EVT_ID
525
-                '%d',// ATT_ID
526
-                '%d',// TXN_ID
527
-                '%d',// TKT_ID
528
-                '%s',// STS_ID
529
-                '%s',// REG_date
530
-                '%f',// REG_final_price
531
-                '%s',// REG_session
532
-                '%s',// REG_code
533
-                '%s',// REG_url_link
534
-                '%d',// REG_count
535
-                '%d',// REG_group_size
536
-                '%d',// REG_att_is_going
537
-                '%d',// REG_deleted
538
-            );
539
-            $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
540
-            if (!$success) {
541
-                $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));
542
-                return 0;
543
-            }
544
-            $cols_n_values['REG_ID'] = $wpdb->insert_id;
545
-            $new_regs[] = $wpdb->insert_id;
546
-        }
547
-        $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
548
-        return $new_regs;
549
-    }
550
-
551
-    /**
552
-     * Increments the sold values on the ticket and its related datetimes by the amount sold,
553
-     * which should be done directly after adding the rows. Yes this means we're constantly incrementing
554
-     * the sold amounts as we go, and is less efficient than a single big query,
555
-     * but its safer because we KNOW these regs have been added, rather than inferring
556
-     * that they WILL be added (because the attendees stage runs nearly last during
557
-     * the migration script)
558
-     * @param type $new_ticket_id
559
-     * @param type $sold
560
-     * @param type $STS_ID
561
-     * @return boolean whether they were successfully updated or not
562
-     */
563
-    protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
564
-    {
565
-        if ($STS_ID != 'RAP') {
566
-            return true;
567
-        }
568
-        global $wpdb;
569
-        $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));
570
-        if ($success) {
571
-            // get the ticket's datetimes, and increment them too
572
-            $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
216
+		$this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group";
217
+		$this->_new_attendee_cpt_table = $wpdb->posts;
218
+		$this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta";
219
+		$this->_new_reg_table = $wpdb->prefix . "esp_registration";
220
+		$this->_new_transaction_table = $wpdb->prefix . "esp_transaction";
221
+		$this->_new_payment_table = $wpdb->prefix . "esp_payment";
222
+		$this->_new_line_table = $wpdb->prefix . "esp_line_item";
223
+		$this->_new_ticket_table = $wpdb->prefix . "esp_ticket";
224
+		$this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket";
225
+		$this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
226
+		$this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket";
227
+		$this->_new_price_table = $wpdb->prefix . "esp_price";
228
+		$this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price";
229
+		parent::__construct();
230
+	}
231
+
232
+	protected function _migrate_old_row($old_row)
233
+	{
234
+		// first check if there's already a new attendee with similar characteristics
235
+		$new_att_id = $this->_find_attendee_cpt_matching($old_row);
236
+		if (!$new_att_id) {
237
+			$new_att_id = $this->_insert_new_attendee_cpt($old_row);
238
+			if (!$new_att_id) {
239
+				// if we couldnt even make an attendee, abandon all hope
240
+				return false;
241
+			}
242
+			$new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id);
243
+			if ($new_att_meta_id) {
244
+				$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id);
245
+			}
246
+		}
247
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
248
+
249
+		$txn_id = $this->_insert_new_transaction($old_row);
250
+		if (!$txn_id) {
251
+			// if we couldnt make the transaction, also abandon all hope
252
+			return false;
253
+		}
254
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id);
255
+		$pay_id = $this->_insert_new_payment($old_row, $txn_id);
256
+		if ($pay_id) {
257
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id);
258
+		}
259
+
260
+
261
+		// even if there was no payment, we can go ahead with adding the reg
262
+		$new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id);
263
+		if ($new_regs) {
264
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs);
265
+		}
266
+	}
267
+
268
+	/**
269
+	 * Checks if there's already an attendee CPT in the db that has the same
270
+	 * first and last name, and email. If so, returns its ID as an int.
271
+	 * @global type $wpdb
272
+	 * @param array $old_attendee
273
+	 * @return int
274
+	 */
275
+	private function _find_attendee_cpt_matching($old_attendee)
276
+	{
277
+		global $wpdb;
278
+		$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']));
279
+		return intval($existing_attendee_id);
280
+	}
281
+
282
+	private function _insert_new_attendee_cpt($old_attendee)
283
+	{
284
+		global $wpdb;
285
+		$cols_n_values = array(
286
+			'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name
287
+			'post_content' => '',// ATT_bio
288
+			'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug
289
+			'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
290
+			'post_excerpt' => '',// ATT_short_bio
291
+			'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
292
+			'post_author' => 0,// ATT_author
293
+			'post_parent' => 0,// ATT_parent
294
+			'post_type' => 'espresso_attendees',// post_type
295
+			'post_status' => 'publish'// status
296
+		);
297
+		$datatypes = array(
298
+			'%s',// ATT_full_name
299
+			'%s',// ATT_bio
300
+			'%s',// ATT_slug
301
+			'%s',// ATT_created
302
+			'%s',// ATT_short_bio
303
+			'%s',// ATT_modified
304
+			'%d',// ATT_author
305
+			'%d',// ATT_parent
306
+			'%s',// post_type
307
+			'%s',// status
308
+		);
309
+		$success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
310
+		if (!$success) {
311
+			$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));
312
+			return 0;
313
+		}
314
+		$new_id = $wpdb->insert_id;
315
+		return $new_id;
316
+	}
317
+
318
+	private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id)
319
+	{
320
+		global $wpdb;
321
+		// get the state and country ids from the old row
322
+		try {
323
+			$new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id']));
324
+			$new_country_iso = $new_country['CNT_ISO'];
325
+		} catch (EE_Error $exception) {
326
+			$new_country_iso = $this->get_migration_script()->get_default_country_iso();
327
+		}
328
+		try {
329
+			$new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso);
330
+			$new_state_id = $new_state['STA_ID'];
331
+		} catch (EE_Error $exception) {
332
+			$new_state_id = 0;
333
+		}
334
+		$cols_n_values = array(
335
+			'ATT_ID' => $new_attendee_cpt_id,
336
+			'ATT_fname' => stripslashes($old_attendee['fname']),
337
+			'ATT_lname' => stripslashes($old_attendee['lname']),
338
+			'ATT_address' => stripslashes($old_attendee['address']),
339
+			'ATT_address2' => stripslashes($old_attendee['address2']),
340
+			'ATT_city' => stripslashes($old_attendee['city']),
341
+			'STA_ID' => $new_state_id,
342
+			'CNT_ISO' => $new_country_iso,
343
+			'ATT_zip' => stripslashes($old_attendee['zip']),
344
+			'ATT_email' => stripslashes($old_attendee['email']),
345
+			'ATT_phone' => stripslashes($old_attendee['phone']),
346
+		);
347
+		$datatypes = array(
348
+			'%d',// ATT_ID
349
+			'%s',// ATT_fname
350
+			'%s',// ATT_lname
351
+			'%s',// ATT_address
352
+			'%s',// ATT_address2
353
+			'%s',// ATT_city
354
+			'%d',// STA_ID
355
+			'%s',// CNT_ISO
356
+			'%s',// ATT_zip
357
+			'%s',// ATT_email
358
+			'%s',// ATT_phone
359
+		);
360
+		$success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
361
+		if (!$success) {
362
+			$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));
363
+			return 0;
364
+		}
365
+		$new_id = $wpdb->insert_id;
366
+		return $new_id;
367
+	}
368
+
369
+	/**
370
+	 * Note: we don't necessarily create a new transaction for each attendee row.
371
+	 * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that
372
+	 * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id
373
+	 * @global type $wpdb
374
+	 * @param type $old_attendee
375
+	 * @return int new transaction id
376
+	 */
377
+	private function _insert_new_transaction($old_attendee)
378
+	{
379
+		global $wpdb;
380
+
381
+		// first: let's check for an existing transaction for this old attendee
382
+		if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
383
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
384
+		} else { // non-primary attendee, so find its primary attendee's transaction
385
+			$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']));
386
+			if (!$primary_attendee_old_id) {
387
+				$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
388
+				$primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
389
+			}
390
+			$txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
391
+			if (!$txn_id) {
392
+				$this->add_error(sprintf(esc_html__("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));
393
+				$txn_id = 0;
394
+			}
395
+		}
396
+		// if there isn't yet a transaction row for this, create one
397
+		// (so even if it was a non-primary attendee with no EE3 primary attendee,
398
+		// it ought to have SOME transaction, so we'll make one)
399
+		if (!$txn_id) {
400
+			// maps 3.1 payment stati onto 4.1 transaction stati
401
+			$txn_status_mapping = array(
402
+				'Completed' => 'TCM',
403
+				'Pending' => 'TIN',
404
+				'Payment Declined' => 'TIN',
405
+				'Incomplete' => 'TIN',
406
+				'Not Completed' => 'TIN',
407
+				'Cancelled' => 'TIN',
408
+				'Declined' => 'TIN'
409
+			);
410
+			$STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
411
+			$cols_n_values = array(
412
+				'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
413
+				'TXN_total' => floatval($old_attendee['total_cost']),
414
+				'TXN_paid' => floatval($old_attendee['amount_pd']),
415
+				'STS_ID' => $STS_ID,
416
+				'TXN_hash_salt' => $old_attendee['hashSalt']
417
+			);
418
+			$datatypes = array(
419
+				'%s',// TXN_timestamp
420
+				'%f',// TXN_total
421
+				'%f',// TXN_paid
422
+				'%s',// STS_ID
423
+				'%s',// TXN_hash_salt
424
+			);
425
+			$success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
426
+			if (!$success) {
427
+				$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));
428
+				return 0;
429
+			}
430
+			$txn_id = $wpdb->insert_id;
431
+		}
432
+
433
+		return $txn_id;
434
+	}
435
+
436
+	/**
437
+	 * Detects if the MER tables exist
438
+	 * @global type $wpdb
439
+	 * @return boolean
440
+	 */
441
+	private function _mer_tables_exist()
442
+	{
443
+		if ($this->_mer_tables_exist === null) {
444
+			global $wpdb;
445
+
446
+			if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) {
447
+				$this->_mer_tables_exist = false;
448
+			} else {
449
+				$this->_mer_tables_exist = true;
450
+			}
451
+		}
452
+		return $this->_mer_tables_exist;
453
+	}
454
+
455
+	/**
456
+	 * Gets the 4.1 registration's status given the 3.1 attendee row. We consider
457
+	 * whether the event required pre-approval or not,a dn the 4.1 payment status.
458
+	 * @global type $wpdb
459
+	 * @param type $old_attendee_row
460
+	 * @return string
461
+	 */
462
+	private function _get_reg_status_for_old_payment_status($old_attendee_row)
463
+	{
464
+		// need event default reg status and if pre_approval was required
465
+		global $wpdb;
466
+		$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']));
467
+		return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
468
+			$old_attendee_row['payment_status'],
469
+			intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
470
+		);
471
+	}
472
+
473
+	/**
474
+	 * Adds however many rgistrations are indicated by the old attendee's QUANTITY field,
475
+	 * and returns an array of their IDs
476
+	 * @global type $wpdb
477
+	 * @param array $old_attendee
478
+	 * @param int $new_attendee_id
479
+	 * @param int $new_txn_id
480
+	 * @return array of new registratio ids
481
+	 */
482
+	private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id)
483
+	{
484
+		global $wpdb;
485
+
486
+		$STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
487
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts);
488
+		if (!$new_event_id) {
489
+			$this->add_error(sprintf(esc_html__("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)));
490
+		}
491
+
492
+		$ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
493
+		if (!$ticket_id) {
494
+			$ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
495
+			$this->add_error(sprintf(esc_html__('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));
496
+		}
497
+		$regs_on_this_row = intval($old_attendee['quantity']);
498
+		$new_regs = array();
499
+		// 4 cases we need to account for:
500
+		// 1 old attendee_details row with a quantity of X (no mer)
501
+		// Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id
502
+		// Y old attendee_details rows with a quantity of x (because of mer)
503
+		// Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group
504
+		for ($count = 1; $count <= $regs_on_this_row; $count++) {
505
+			// sum regs on older rows
506
+			$regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true);
507
+			$cols_n_values = array(
508
+				'EVT_ID' => $new_event_id,
509
+				'ATT_ID' => $new_attendee_id,
510
+				'TXN_ID' => $new_txn_id,
511
+				'TKT_ID' => $ticket_id,
512
+				'STS_ID' => $STS_ID,
513
+				'REG_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
514
+				'REG_final_price' => $old_attendee['final_price'],
515
+				'REG_session' => substr($old_attendee['attendee_session'], 0, 44),
516
+				'REG_code' => sanitize_key($old_attendee['registration_id']),
517
+				'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count),
518
+				'REG_count' => $regs_on_this_event_and_txn + $count,
519
+				'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false),
520
+				'REG_att_is_going' => true,
521
+				'REG_deleted' => false
522
+			);
523
+			$datatypes = array(
524
+				'%d',// EVT_ID
525
+				'%d',// ATT_ID
526
+				'%d',// TXN_ID
527
+				'%d',// TKT_ID
528
+				'%s',// STS_ID
529
+				'%s',// REG_date
530
+				'%f',// REG_final_price
531
+				'%s',// REG_session
532
+				'%s',// REG_code
533
+				'%s',// REG_url_link
534
+				'%d',// REG_count
535
+				'%d',// REG_group_size
536
+				'%d',// REG_att_is_going
537
+				'%d',// REG_deleted
538
+			);
539
+			$success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
540
+			if (!$success) {
541
+				$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));
542
+				return 0;
543
+			}
544
+			$cols_n_values['REG_ID'] = $wpdb->insert_id;
545
+			$new_regs[] = $wpdb->insert_id;
546
+		}
547
+		$this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID);
548
+		return $new_regs;
549
+	}
550
+
551
+	/**
552
+	 * Increments the sold values on the ticket and its related datetimes by the amount sold,
553
+	 * which should be done directly after adding the rows. Yes this means we're constantly incrementing
554
+	 * the sold amounts as we go, and is less efficient than a single big query,
555
+	 * but its safer because we KNOW these regs have been added, rather than inferring
556
+	 * that they WILL be added (because the attendees stage runs nearly last during
557
+	 * the migration script)
558
+	 * @param type $new_ticket_id
559
+	 * @param type $sold
560
+	 * @param type $STS_ID
561
+	 * @return boolean whether they were successfully updated or not
562
+	 */
563
+	protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
564
+	{
565
+		if ($STS_ID != 'RAP') {
566
+			return true;
567
+		}
568
+		global $wpdb;
569
+		$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));
570
+		if ($success) {
571
+			// get the ticket's datetimes, and increment them too
572
+			$success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT
573 573
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
574 574
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
575 575
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
576
-            if (!$success_update_dateimtes) {
577
-                $this->add_error(sprintf(esc_html__("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));
578
-            }
579
-        } else {
580
-            $this->add_error(sprintf(esc_html__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
581
-        }
582
-        return true;
583
-    }
584
-
585
-    /**
586
-     * Makes a best guess at which ticket is the one the attendee purchased.
587
-     * Obviously, the old attendee's event_id narrows it down quite a bit;
588
-     * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
589
-     * however, if we don't find an exact match, see if any of those conditions match;
590
-     * and lastly if none of that works, just use the first ticket for the event we find
591
-     * @param array $old_attendee
592
-     */
593
-    private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
594
-    {
595
-        global $wpdb;
596
-        $tickets_table = $this->_new_ticket_table;
597
-        $datetime_tickets_table = $this->_new_ticket_datetime_table;
598
-        $datetime_table = $this->_new_datetime_table;
599
-
600
-        $old_att_price_option = $old_attendee['price_option'];
601
-        $old_att_price = floatval($old_attendee['orig_price']);
602
-
603
-        $old_att_start_date = $old_attendee['start_date'];
604
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
605
-        $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
606
-        // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
607
-        // the most important condition should be last, as it will be array_shift'ed off last
608
-        $conditions = array(
609
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
610
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
611
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
612
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
613
-        );
614
-        $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
576
+			if (!$success_update_dateimtes) {
577
+				$this->add_error(sprintf(esc_html__("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));
578
+			}
579
+		} else {
580
+			$this->add_error(sprintf(esc_html__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error));
581
+		}
582
+		return true;
583
+	}
584
+
585
+	/**
586
+	 * Makes a best guess at which ticket is the one the attendee purchased.
587
+	 * Obviously, the old attendee's event_id narrows it down quite a bit;
588
+	 * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket
589
+	 * however, if we don't find an exact match, see if any of those conditions match;
590
+	 * and lastly if none of that works, just use the first ticket for the event we find
591
+	 * @param array $old_attendee
592
+	 */
593
+	private function _try_to_find_new_ticket_id($old_attendee, $new_event_id)
594
+	{
595
+		global $wpdb;
596
+		$tickets_table = $this->_new_ticket_table;
597
+		$datetime_tickets_table = $this->_new_ticket_datetime_table;
598
+		$datetime_table = $this->_new_datetime_table;
599
+
600
+		$old_att_price_option = $old_attendee['price_option'];
601
+		$old_att_price = floatval($old_attendee['orig_price']);
602
+
603
+		$old_att_start_date = $old_attendee['start_date'];
604
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
605
+		$old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00");
606
+		// add all conditions to an array from which we can SHIFT conditions off in order to widen our search
607
+		// the most important condition should be last, as it will be array_shift'ed off last
608
+		$conditions = array(
609
+			$wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
610
+			$wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
611
+			$wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
612
+			$wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
613
+		);
614
+		$select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
615 615
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
616 616
 			$datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID";
617
-        // start running queries, widening search each time by removing a condition
618
-        do {
619
-            $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1";
620
-            $ticket_id_found = $wpdb->get_var($full_query);
621
-            array_shift($conditions);
622
-        } while (!$ticket_id_found && $conditions);
623
-        return $ticket_id_found;
624
-    }
625
-
626
-    /**
627
-     * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
628
-     * and it also tries to find a datetime that works, and a inserts a price, and associates
629
-     * the new ticket to that datetime and price.
630
-     * @return int ticket id
631
-     */
632
-    private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
633
-    {
634
-        global $wpdb;
635
-        $old_att_price_option = $old_attendee['price_option'];
636
-        $old_att_price = floatval($old_attendee['orig_price']);
637
-
638
-        $old_att_start_date = $old_attendee['start_date'];
639
-        $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
640
-        $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");
641
-
642
-
643
-        // insert new datetime unless we find one
644
-        $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);
645
-        if (!$datetime_id) {
646
-            $old_att_end_date = $old_attendee['start_date'];
647
-            $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
648
-            $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");
649
-            $wpdb->insert(
650
-                $this->_new_datetime_table,
651
-                array(
652
-                    'EVT_ID' => $new_event_id,
653
-                    'DTT_EVT_start' => $old_att_start_datetime,
654
-                    'DTT_EVT_end' => $old_att_end_datetime,
655
-                    'DTT_deleted' => true
656
-                ),
657
-                array(
658
-                    '%d',// EVT_ID
659
-                    '%s',// DTT_EVT_start
660
-                    '%s',// DTT_EVT_end
661
-                    '%d',// DTT_deleted
662
-                )
663
-            );
664
-            $datetime_id = $wpdb->insert_id;
665
-        }
666
-
667
-        // insert new ticket
668
-        $success = $wpdb->insert(
669
-            $wpdb->prefix . 'esp_ticket',
670
-            array(
671
-                'TKT_name' => $old_att_price_option,
672
-                'TKT_qty' => -1,
673
-                'TKT_price' => $old_att_price,
674
-                '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
675
-                'TKT_end_date' => $old_att_end_datetime,
676
-
677
-            ),
678
-            array(
679
-                '%s',// name
680
-                '%d',// qty
681
-                '%d',// price
682
-                '%s',// start_date
683
-                '%s',// end_date
684
-            )
685
-        );
686
-        $ticket_id = $wpdb->insert_id;
687
-        // associate the ticket with the datetime we found earlier
688
-        $wpdb->insert(
689
-            $this->_new_datetime_ticket_table,
690
-            array(
691
-                'DTT_ID' => $datetime_id,
692
-                'TKT_ID' => $ticket_id
693
-            ),
694
-            array(
695
-                '%d',// DTT_ID
696
-                '%d',// TKT_ID
697
-            )
698
-        );
699
-        // insert new price
700
-        $wpdb->insert(
701
-            $this->_new_price_table,
702
-            array(
703
-                'PRC_amount' => $old_att_price,
704
-                'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
705
-                'PRC_name' => $old_att_price_option,
706
-                'PRC_deleted' => true
707
-            ),
708
-            array(
709
-                '%d',// PRC_amount
710
-                '%d',// PRT_ID
711
-                '%s',// PRC_name
712
-                '%d',// PRC_deleted
713
-            )
714
-        );
715
-        $price_id = $wpdb->insert_id;
716
-        // associate the price to the ticket
717
-        $wpdb->insert(
718
-            $this->_new_ticket_price_table,
719
-            array(
720
-                'TKT_ID' => $ticket_id,
721
-                'PRC_ID' => $price_id
722
-            ),
723
-            array(
724
-                '%d',// TKT_ID
725
-                '%d',// PRC_ID
726
-            )
727
-        );
728
-        return $ticket_id;
729
-    }
730
-
731
-    /**
732
-     * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
733
-     * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
734
-     * @global type $wpdb
735
-     * @param array $old_attendee_row
736
-     * @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
737
-     * @return int
738
-     */
739
-    private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
740
-    {
741
-        global $wpdb;
742
-        $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
743
-        $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'])));
744
-
745
-        if ($this->_mer_tables_exist()) {
746
-            // if MER exists, then its a little tricky.
747
-            // when users registered by adding items to the cart, and it was a
748
-            // group registration requiring additional attendee INFO, then the attendee rows
749
-            // DO NOT have the same registration_id (although they probably should have)
750
-            // they are related just like MER attendee rows are related, through the MER group table
751
-            // BUT we want to count all the MER attendee rows for the same registration
752
-            $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
753
-
754
-            $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']));
755
-            $count = max($count_using_mer_table, $count);
756
-        }
757
-        return $count;
758
-    }
759
-
760
-    private function _insert_new_payment($old_attendee, $new_txn_id)
761
-    {
762
-        global $wpdb;
763
-        // Only add a payment for primary attendees. Important note: partial payments were marked as "Pending".
764
-        // Also, an offline payment had blank status (ie, "").
765
-        $old_pay_stati_indicating_no_payment = array('', 'Incomplete', 'Not Completed');
766
-        // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
767
-        if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
768
-            $pay_status_mapping = array(
769
-                'Completed' => 'PAP',
770
-                'Payment Declined' => 'PDC',
771
-                'Cancelled' => 'PCN',
772
-                'Declined' => 'PDC'
773
-            );
774
-            $by_admin = $old_attendee['payment'] == 'Admin';
775
-            $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
776
-            $cols_n_values = array(
777
-                'TXN_ID' => $new_txn_id,
778
-                'STS_ID' => $STS_ID,
779
-                'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
780
-                'PAY_method' => 'CART',
781
-                'PAY_amount' => $old_attendee['amount_pd'],
782
-                // 'txn_type' was used both for the gateway's name, and for other payment notes.
783
-                'PAY_gateway' => $old_attendee['txn_type'],
784
-                'PAY_extra_accntng' => $old_attendee['txn_type'],
785
-                'PAY_gateway_response' => '',
786
-                'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32),
787
-                'PAY_via_admin' => $by_admin,
788
-                'PAY_details' => $old_attendee['transaction_details']
789
-            );
790
-            $datatypes = array(
791
-                '%d',// TXN_Id
792
-                '%s',// STS_ID
793
-                '%s',// PAY_timestamp
794
-                '%s',// PAY_method
795
-                '%f',// PAY_amount
796
-                '%s',// PAY_gateway
797
-                '%s',// PAY_gateway_response
798
-                '%s',// PAY_txn_id_chq_nmbr
799
-                '%d',// PAY_via_admin
800
-                '%s',// PAY_details
801
-            );
802
-            $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
803
-            if (!$success) {
804
-                $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));
805
-                return 0;
806
-            }
807
-            $new_id = $wpdb->insert_id;
808
-            return $new_id;
809
-        } else {
810
-            return 0;
811
-        }
812
-    }
813
-
814
-    /**
815
-     * If MER is active, if you want ot fin dthe other registrations on that attendee row
816
-     * @global type $wpdb
817
-     * @param type $old_registration_id
818
-     * @return array
819
-     */
820
-    private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
821
-    {
822
-        if (!$this->_mer_tables_exist()) {
823
-            return false;
824
-        }
825
-        global $wpdb;
826
-        $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);
827
-        return $old_att_for_primary_reg;
828
-    }
617
+		// start running queries, widening search each time by removing a condition
618
+		do {
619
+			$full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1";
620
+			$ticket_id_found = $wpdb->get_var($full_query);
621
+			array_shift($conditions);
622
+		} while (!$ticket_id_found && $conditions);
623
+		return $ticket_id_found;
624
+	}
625
+
626
+	/**
627
+	 * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one;
628
+	 * and it also tries to find a datetime that works, and a inserts a price, and associates
629
+	 * the new ticket to that datetime and price.
630
+	 * @return int ticket id
631
+	 */
632
+	private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id)
633
+	{
634
+		global $wpdb;
635
+		$old_att_price_option = $old_attendee['price_option'];
636
+		$old_att_price = floatval($old_attendee['orig_price']);
637
+
638
+		$old_att_start_date = $old_attendee['start_date'];
639
+		$old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
640
+		$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");
641
+
642
+
643
+		// insert new datetime unless we find one
644
+		$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);
645
+		if (!$datetime_id) {
646
+			$old_att_end_date = $old_attendee['start_date'];
647
+			$old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
648
+			$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");
649
+			$wpdb->insert(
650
+				$this->_new_datetime_table,
651
+				array(
652
+					'EVT_ID' => $new_event_id,
653
+					'DTT_EVT_start' => $old_att_start_datetime,
654
+					'DTT_EVT_end' => $old_att_end_datetime,
655
+					'DTT_deleted' => true
656
+				),
657
+				array(
658
+					'%d',// EVT_ID
659
+					'%s',// DTT_EVT_start
660
+					'%s',// DTT_EVT_end
661
+					'%d',// DTT_deleted
662
+				)
663
+			);
664
+			$datetime_id = $wpdb->insert_id;
665
+		}
666
+
667
+		// insert new ticket
668
+		$success = $wpdb->insert(
669
+			$wpdb->prefix . 'esp_ticket',
670
+			array(
671
+				'TKT_name' => $old_att_price_option,
672
+				'TKT_qty' => -1,
673
+				'TKT_price' => $old_att_price,
674
+				'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
675
+				'TKT_end_date' => $old_att_end_datetime,
676
+
677
+			),
678
+			array(
679
+				'%s',// name
680
+				'%d',// qty
681
+				'%d',// price
682
+				'%s',// start_date
683
+				'%s',// end_date
684
+			)
685
+		);
686
+		$ticket_id = $wpdb->insert_id;
687
+		// associate the ticket with the datetime we found earlier
688
+		$wpdb->insert(
689
+			$this->_new_datetime_ticket_table,
690
+			array(
691
+				'DTT_ID' => $datetime_id,
692
+				'TKT_ID' => $ticket_id
693
+			),
694
+			array(
695
+				'%d',// DTT_ID
696
+				'%d',// TKT_ID
697
+			)
698
+		);
699
+		// insert new price
700
+		$wpdb->insert(
701
+			$this->_new_price_table,
702
+			array(
703
+				'PRC_amount' => $old_att_price,
704
+				'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base,
705
+				'PRC_name' => $old_att_price_option,
706
+				'PRC_deleted' => true
707
+			),
708
+			array(
709
+				'%d',// PRC_amount
710
+				'%d',// PRT_ID
711
+				'%s',// PRC_name
712
+				'%d',// PRC_deleted
713
+			)
714
+		);
715
+		$price_id = $wpdb->insert_id;
716
+		// associate the price to the ticket
717
+		$wpdb->insert(
718
+			$this->_new_ticket_price_table,
719
+			array(
720
+				'TKT_ID' => $ticket_id,
721
+				'PRC_ID' => $price_id
722
+			),
723
+			array(
724
+				'%d',// TKT_ID
725
+				'%d',// PRC_ID
726
+			)
727
+		);
728
+		return $ticket_id;
729
+	}
730
+
731
+	/**
732
+	 * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie,
733
+	 * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL
734
+	 * @global type $wpdb
735
+	 * @param array $old_attendee_row
736
+	 * @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
737
+	 * @return int
738
+	 */
739
+	private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false)
740
+	{
741
+		global $wpdb;
742
+		$count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
743
+		$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'])));
744
+
745
+		if ($this->_mer_tables_exist()) {
746
+			// if MER exists, then its a little tricky.
747
+			// when users registered by adding items to the cart, and it was a
748
+			// group registration requiring additional attendee INFO, then the attendee rows
749
+			// DO NOT have the same registration_id (although they probably should have)
750
+			// they are related just like MER attendee rows are related, through the MER group table
751
+			// BUT we want to count all the MER attendee rows for the same registration
752
+			$primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']);
753
+
754
+			$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']));
755
+			$count = max($count_using_mer_table, $count);
756
+		}
757
+		return $count;
758
+	}
759
+
760
+	private function _insert_new_payment($old_attendee, $new_txn_id)
761
+	{
762
+		global $wpdb;
763
+		// Only add a payment for primary attendees. Important note: partial payments were marked as "Pending".
764
+		// Also, an offline payment had blank status (ie, "").
765
+		$old_pay_stati_indicating_no_payment = array('', 'Incomplete', 'Not Completed');
766
+		// if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
767
+		if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
768
+			$pay_status_mapping = array(
769
+				'Completed' => 'PAP',
770
+				'Payment Declined' => 'PDC',
771
+				'Cancelled' => 'PCN',
772
+				'Declined' => 'PDC'
773
+			);
774
+			$by_admin = $old_attendee['payment'] == 'Admin';
775
+			$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
776
+			$cols_n_values = array(
777
+				'TXN_ID' => $new_txn_id,
778
+				'STS_ID' => $STS_ID,
779
+				'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
780
+				'PAY_method' => 'CART',
781
+				'PAY_amount' => $old_attendee['amount_pd'],
782
+				// 'txn_type' was used both for the gateway's name, and for other payment notes.
783
+				'PAY_gateway' => $old_attendee['txn_type'],
784
+				'PAY_extra_accntng' => $old_attendee['txn_type'],
785
+				'PAY_gateway_response' => '',
786
+				'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32),
787
+				'PAY_via_admin' => $by_admin,
788
+				'PAY_details' => $old_attendee['transaction_details']
789
+			);
790
+			$datatypes = array(
791
+				'%d',// TXN_Id
792
+				'%s',// STS_ID
793
+				'%s',// PAY_timestamp
794
+				'%s',// PAY_method
795
+				'%f',// PAY_amount
796
+				'%s',// PAY_gateway
797
+				'%s',// PAY_gateway_response
798
+				'%s',// PAY_txn_id_chq_nmbr
799
+				'%d',// PAY_via_admin
800
+				'%s',// PAY_details
801
+			);
802
+			$success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
803
+			if (!$success) {
804
+				$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));
805
+				return 0;
806
+			}
807
+			$new_id = $wpdb->insert_id;
808
+			return $new_id;
809
+		} else {
810
+			return 0;
811
+		}
812
+	}
813
+
814
+	/**
815
+	 * If MER is active, if you want ot fin dthe other registrations on that attendee row
816
+	 * @global type $wpdb
817
+	 * @param type $old_registration_id
818
+	 * @return array
819
+	 */
820
+	private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
821
+	{
822
+		if (!$this->_mer_tables_exist()) {
823
+			return false;
824
+		}
825
+		global $wpdb;
826
+		$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);
827
+		return $old_att_for_primary_reg;
828
+	}
829 829
 }
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -206,26 +206,26 @@  discard block
 block discarded – undo
206 206
     {
207 207
         global $wpdb;
208 208
         $this->_pretty_name = esc_html__("Attendees", "event_espresso");
209
-        $this->_old_table = $wpdb->prefix . "events_attendee";
209
+        $this->_old_table = $wpdb->prefix."events_attendee";
210 210
         // Only select the event status column from the event table.
211 211
         $this->select_expression = 'att.*, e.event_status';
212 212
         // Only select attendees for events that aren't deleted.
213 213
         $this->_extra_where_sql = 'AS att
214
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id
214
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id
215 215
             WHERE e.event_status!="D"';
216
-        $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group";
216
+        $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group";
217 217
         $this->_new_attendee_cpt_table = $wpdb->posts;
218
-        $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta";
219
-        $this->_new_reg_table = $wpdb->prefix . "esp_registration";
220
-        $this->_new_transaction_table = $wpdb->prefix . "esp_transaction";
221
-        $this->_new_payment_table = $wpdb->prefix . "esp_payment";
222
-        $this->_new_line_table = $wpdb->prefix . "esp_line_item";
223
-        $this->_new_ticket_table = $wpdb->prefix . "esp_ticket";
224
-        $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket";
225
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
226
-        $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket";
227
-        $this->_new_price_table = $wpdb->prefix . "esp_price";
228
-        $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price";
218
+        $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta";
219
+        $this->_new_reg_table = $wpdb->prefix."esp_registration";
220
+        $this->_new_transaction_table = $wpdb->prefix."esp_transaction";
221
+        $this->_new_payment_table = $wpdb->prefix."esp_payment";
222
+        $this->_new_line_table = $wpdb->prefix."esp_line_item";
223
+        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
224
+        $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket";
225
+        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
226
+        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
227
+        $this->_new_price_table = $wpdb->prefix."esp_price";
228
+        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
229 229
         parent::__construct();
230 230
     }
231 231
 
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
     {
234 234
         // first check if there's already a new attendee with similar characteristics
235 235
         $new_att_id = $this->_find_attendee_cpt_matching($old_row);
236
-        if (!$new_att_id) {
236
+        if ( ! $new_att_id) {
237 237
             $new_att_id = $this->_insert_new_attendee_cpt($old_row);
238
-            if (!$new_att_id) {
238
+            if ( ! $new_att_id) {
239 239
                 // if we couldnt even make an attendee, abandon all hope
240 240
                 return false;
241 241
             }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id);
248 248
 
249 249
         $txn_id = $this->_insert_new_transaction($old_row);
250
-        if (!$txn_id) {
250
+        if ( ! $txn_id) {
251 251
             // if we couldnt make the transaction, also abandon all hope
252 252
             return false;
253 253
         }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     private function _find_attendee_cpt_matching($old_attendee)
276 276
     {
277 277
         global $wpdb;
278
-        $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']));
278
+        $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']));
279 279
         return intval($existing_attendee_id);
280 280
     }
281 281
 
@@ -283,31 +283,31 @@  discard block
 block discarded – undo
283 283
     {
284 284
         global $wpdb;
285 285
         $cols_n_values = array(
286
-            'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name
287
-            'post_content' => '',// ATT_bio
288
-            'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug
289
-            'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created
290
-            'post_excerpt' => '',// ATT_short_bio
291
-            'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified
292
-            'post_author' => 0,// ATT_author
293
-            'post_parent' => 0,// ATT_parent
294
-            'post_type' => 'espresso_attendees',// post_type
286
+            'post_title' => stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name
287
+            'post_content' => '', // ATT_bio
288
+            'post_name' => sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug
289
+            'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created
290
+            'post_excerpt' => '', // ATT_short_bio
291
+            'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified
292
+            'post_author' => 0, // ATT_author
293
+            'post_parent' => 0, // ATT_parent
294
+            'post_type' => 'espresso_attendees', // post_type
295 295
             'post_status' => 'publish'// status
296 296
         );
297 297
         $datatypes = array(
298
-            '%s',// ATT_full_name
299
-            '%s',// ATT_bio
300
-            '%s',// ATT_slug
301
-            '%s',// ATT_created
302
-            '%s',// ATT_short_bio
303
-            '%s',// ATT_modified
304
-            '%d',// ATT_author
305
-            '%d',// ATT_parent
306
-            '%s',// post_type
307
-            '%s',// status
298
+            '%s', // ATT_full_name
299
+            '%s', // ATT_bio
300
+            '%s', // ATT_slug
301
+            '%s', // ATT_created
302
+            '%s', // ATT_short_bio
303
+            '%s', // ATT_modified
304
+            '%d', // ATT_author
305
+            '%d', // ATT_parent
306
+            '%s', // post_type
307
+            '%s', // status
308 308
         );
309 309
         $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes);
310
-        if (!$success) {
310
+        if ( ! $success) {
311 311
             $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));
312 312
             return 0;
313 313
         }
@@ -345,20 +345,20 @@  discard block
 block discarded – undo
345 345
             'ATT_phone' => stripslashes($old_attendee['phone']),
346 346
         );
347 347
         $datatypes = array(
348
-            '%d',// ATT_ID
349
-            '%s',// ATT_fname
350
-            '%s',// ATT_lname
351
-            '%s',// ATT_address
352
-            '%s',// ATT_address2
353
-            '%s',// ATT_city
354
-            '%d',// STA_ID
355
-            '%s',// CNT_ISO
356
-            '%s',// ATT_zip
357
-            '%s',// ATT_email
358
-            '%s',// ATT_phone
348
+            '%d', // ATT_ID
349
+            '%s', // ATT_fname
350
+            '%s', // ATT_lname
351
+            '%s', // ATT_address
352
+            '%s', // ATT_address2
353
+            '%s', // ATT_city
354
+            '%d', // STA_ID
355
+            '%s', // CNT_ISO
356
+            '%s', // ATT_zip
357
+            '%s', // ATT_email
358
+            '%s', // ATT_phone
359 359
         );
360 360
         $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes);
361
-        if (!$success) {
361
+        if ( ! $success) {
362 362
             $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));
363 363
             return 0;
364 364
         }
@@ -382,13 +382,13 @@  discard block
 block discarded – undo
382 382
         if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn
383 383
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table);
384 384
         } else { // non-primary attendee, so find its primary attendee's transaction
385
-            $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']));
386
-            if (!$primary_attendee_old_id) {
385
+            $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']));
386
+            if ( ! $primary_attendee_old_id) {
387 387
                 $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']);
388 388
                 $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null;
389 389
             }
390 390
             $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table);
391
-            if (!$txn_id) {
391
+            if ( ! $txn_id) {
392 392
                 $this->add_error(sprintf(esc_html__("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));
393 393
                 $txn_id = 0;
394 394
             }
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         // if there isn't yet a transaction row for this, create one
397 397
         // (so even if it was a non-primary attendee with no EE3 primary attendee,
398 398
         // it ought to have SOME transaction, so we'll make one)
399
-        if (!$txn_id) {
399
+        if ( ! $txn_id) {
400 400
             // maps 3.1 payment stati onto 4.1 transaction stati
401 401
             $txn_status_mapping = array(
402 402
                 'Completed' => 'TCM',
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
                 'Cancelled' => 'TIN',
408 408
                 'Declined' => 'TIN'
409 409
             );
410
-            $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN';
410
+            $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN';
411 411
             $cols_n_values = array(
412 412
                 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),
413 413
                 'TXN_total' => floatval($old_attendee['total_cost']),
@@ -416,14 +416,14 @@  discard block
 block discarded – undo
416 416
                 'TXN_hash_salt' => $old_attendee['hashSalt']
417 417
             );
418 418
             $datatypes = array(
419
-                '%s',// TXN_timestamp
420
-                '%f',// TXN_total
421
-                '%f',// TXN_paid
422
-                '%s',// STS_ID
423
-                '%s',// TXN_hash_salt
419
+                '%s', // TXN_timestamp
420
+                '%f', // TXN_total
421
+                '%f', // TXN_paid
422
+                '%s', // STS_ID
423
+                '%s', // TXN_hash_salt
424 424
             );
425 425
             $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes);
426
-            if (!$success) {
426
+            if ( ! $success) {
427 427
                 $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));
428 428
                 return 0;
429 429
             }
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
     {
464 464
         // need event default reg status and if pre_approval was required
465 465
         global $wpdb;
466
-        $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']));
466
+        $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']));
467 467
         return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(
468 468
             $old_attendee_row['payment_status'],
469 469
             intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve'])
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
         global $wpdb;
485 485
 
486 486
         $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee);
487
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts);
488
-        if (!$new_event_id) {
487
+        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts);
488
+        if ( ! $new_event_id) {
489 489
             $this->add_error(sprintf(esc_html__("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)));
490 490
         }
491 491
 
492 492
         $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id);
493
-        if (!$ticket_id) {
493
+        if ( ! $ticket_id) {
494 494
             $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id);
495 495
             $this->add_error(sprintf(esc_html__('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));
496 496
         }
@@ -514,30 +514,30 @@  discard block
 block discarded – undo
514 514
                 'REG_final_price' => $old_attendee['final_price'],
515 515
                 'REG_session' => substr($old_attendee['attendee_session'], 0, 44),
516 516
                 'REG_code' => sanitize_key($old_attendee['registration_id']),
517
-                'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count),
517
+                'REG_url_link' => sanitize_key($old_attendee['registration_id'].'-'.$count),
518 518
                 'REG_count' => $regs_on_this_event_and_txn + $count,
519 519
                 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false),
520 520
                 'REG_att_is_going' => true,
521 521
                 'REG_deleted' => false
522 522
             );
523 523
             $datatypes = array(
524
-                '%d',// EVT_ID
525
-                '%d',// ATT_ID
526
-                '%d',// TXN_ID
527
-                '%d',// TKT_ID
528
-                '%s',// STS_ID
529
-                '%s',// REG_date
530
-                '%f',// REG_final_price
531
-                '%s',// REG_session
532
-                '%s',// REG_code
533
-                '%s',// REG_url_link
534
-                '%d',// REG_count
535
-                '%d',// REG_group_size
536
-                '%d',// REG_att_is_going
537
-                '%d',// REG_deleted
524
+                '%d', // EVT_ID
525
+                '%d', // ATT_ID
526
+                '%d', // TXN_ID
527
+                '%d', // TKT_ID
528
+                '%s', // STS_ID
529
+                '%s', // REG_date
530
+                '%f', // REG_final_price
531
+                '%s', // REG_session
532
+                '%s', // REG_code
533
+                '%s', // REG_url_link
534
+                '%d', // REG_count
535
+                '%d', // REG_group_size
536
+                '%d', // REG_att_is_going
537
+                '%d', // REG_deleted
538 538
             );
539 539
             $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes);
540
-            if (!$success) {
540
+            if ( ! $success) {
541 541
                 $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));
542 542
                 return 0;
543 543
             }
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 				INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID
574 574
 				INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID
575 575
 				SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id));
576
-            if (!$success_update_dateimtes) {
576
+            if ( ! $success_update_dateimtes) {
577 577
                 $this->add_error(sprintf(esc_html__("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));
578 578
             }
579 579
         } else {
@@ -606,20 +606,20 @@  discard block
 block discarded – undo
606 606
         // add all conditions to an array from which we can SHIFT conditions off in order to widen our search
607 607
         // the most important condition should be last, as it will be array_shift'ed off last
608 608
         $conditions = array(
609
-            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match?
610
-            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match?
611
-            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match?
612
-            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match?
609
+            $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match?
610
+            $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match?
611
+            $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match?
612
+            $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match?
613 613
         );
614 614
         $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN
615 615
 			$datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN
616 616
 			$datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID";
617 617
         // start running queries, widening search each time by removing a condition
618 618
         do {
619
-            $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1";
619
+            $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1";
620 620
             $ticket_id_found = $wpdb->get_var($full_query);
621 621
             array_shift($conditions);
622
-        } while (!$ticket_id_found && $conditions);
622
+        }while ( ! $ticket_id_found && $conditions);
623 623
         return $ticket_id_found;
624 624
     }
625 625
 
@@ -641,8 +641,8 @@  discard block
 block discarded – undo
641 641
 
642 642
 
643 643
         // insert new datetime unless we find one
644
-        $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);
645
-        if (!$datetime_id) {
644
+        $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);
645
+        if ( ! $datetime_id) {
646 646
             $old_att_end_date = $old_attendee['start_date'];
647 647
             $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']);
648 648
             $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");
@@ -655,10 +655,10 @@  discard block
 block discarded – undo
655 655
                     'DTT_deleted' => true
656 656
                 ),
657 657
                 array(
658
-                    '%d',// EVT_ID
659
-                    '%s',// DTT_EVT_start
660
-                    '%s',// DTT_EVT_end
661
-                    '%d',// DTT_deleted
658
+                    '%d', // EVT_ID
659
+                    '%s', // DTT_EVT_start
660
+                    '%s', // DTT_EVT_end
661
+                    '%d', // DTT_deleted
662 662
                 )
663 663
             );
664 664
             $datetime_id = $wpdb->insert_id;
@@ -666,21 +666,21 @@  discard block
 block discarded – undo
666 666
 
667 667
         // insert new ticket
668 668
         $success = $wpdb->insert(
669
-            $wpdb->prefix . 'esp_ticket',
669
+            $wpdb->prefix.'esp_ticket',
670 670
             array(
671 671
                 'TKT_name' => $old_att_price_option,
672 672
                 'TKT_qty' => -1,
673 673
                 'TKT_price' => $old_att_price,
674
-                '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
674
+                '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
675 675
                 'TKT_end_date' => $old_att_end_datetime,
676 676
 
677 677
             ),
678 678
             array(
679
-                '%s',// name
680
-                '%d',// qty
681
-                '%d',// price
682
-                '%s',// start_date
683
-                '%s',// end_date
679
+                '%s', // name
680
+                '%d', // qty
681
+                '%d', // price
682
+                '%s', // start_date
683
+                '%s', // end_date
684 684
             )
685 685
         );
686 686
         $ticket_id = $wpdb->insert_id;
@@ -692,8 +692,8 @@  discard block
 block discarded – undo
692 692
                 'TKT_ID' => $ticket_id
693 693
             ),
694 694
             array(
695
-                '%d',// DTT_ID
696
-                '%d',// TKT_ID
695
+                '%d', // DTT_ID
696
+                '%d', // TKT_ID
697 697
             )
698 698
         );
699 699
         // insert new price
@@ -706,10 +706,10 @@  discard block
 block discarded – undo
706 706
                 'PRC_deleted' => true
707 707
             ),
708 708
             array(
709
-                '%d',// PRC_amount
710
-                '%d',// PRT_ID
711
-                '%s',// PRC_name
712
-                '%d',// PRC_deleted
709
+                '%d', // PRC_amount
710
+                '%d', // PRT_ID
711
+                '%s', // PRC_name
712
+                '%d', // PRC_deleted
713 713
             )
714 714
         );
715 715
         $price_id = $wpdb->insert_id;
@@ -721,8 +721,8 @@  discard block
 block discarded – undo
721 721
                 'PRC_ID' => $price_id
722 722
             ),
723 723
             array(
724
-                '%d',// TKT_ID
725
-                '%d',// PRC_ID
724
+                '%d', // TKT_ID
725
+                '%d', // PRC_ID
726 726
             )
727 727
         );
728 728
         return $ticket_id;
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
     {
741 741
         global $wpdb;
742 742
         $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : '';
743
-        $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'])));
743
+        $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'])));
744 744
 
745 745
         if ($this->_mer_tables_exist()) {
746 746
             // if MER exists, then its a little tricky.
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
         // Also, an offline payment had blank status (ie, "").
765 765
         $old_pay_stati_indicating_no_payment = array('', 'Incomplete', 'Not Completed');
766 766
         // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment...
767
-        if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
767
+        if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) {
768 768
             $pay_status_mapping = array(
769 769
                 'Completed' => 'PAP',
770 770
                 'Payment Declined' => 'PDC',
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
                 'Declined' => 'PDC'
773 773
             );
774 774
             $by_admin = $old_attendee['payment'] == 'Admin';
775
-            $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
775
+            $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
776 776
             $cols_n_values = array(
777 777
                 'TXN_ID' => $new_txn_id,
778 778
                 'STS_ID' => $STS_ID,
@@ -788,19 +788,19 @@  discard block
 block discarded – undo
788 788
                 'PAY_details' => $old_attendee['transaction_details']
789 789
             );
790 790
             $datatypes = array(
791
-                '%d',// TXN_Id
792
-                '%s',// STS_ID
793
-                '%s',// PAY_timestamp
794
-                '%s',// PAY_method
795
-                '%f',// PAY_amount
796
-                '%s',// PAY_gateway
797
-                '%s',// PAY_gateway_response
798
-                '%s',// PAY_txn_id_chq_nmbr
799
-                '%d',// PAY_via_admin
800
-                '%s',// PAY_details
791
+                '%d', // TXN_Id
792
+                '%s', // STS_ID
793
+                '%s', // PAY_timestamp
794
+                '%s', // PAY_method
795
+                '%f', // PAY_amount
796
+                '%s', // PAY_gateway
797
+                '%s', // PAY_gateway_response
798
+                '%s', // PAY_txn_id_chq_nmbr
799
+                '%d', // PAY_via_admin
800
+                '%s', // PAY_details
801 801
             );
802 802
             $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes);
803
-            if (!$success) {
803
+            if ( ! $success) {
804 804
                 $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));
805 805
                 return 0;
806 806
             }
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
      */
820 820
     private function _find_mer_primary_attendee_using_mer_tables($old_registration_id)
821 821
     {
822
-        if (!$this->_mer_tables_exist()) {
822
+        if ( ! $this->_mer_tables_exist()) {
823 823
             return false;
824 824
         }
825 825
         global $wpdb;
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_org_options.dmsstage.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
         $old_org_options = get_option('events_organization_settings');
111 111
         foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
112 112
             // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
113
-            if (isset($old_org_options[ $option_name ])) {
114
-                $this->_handle_org_option($option_name, $old_org_options[ $option_name ]);
113
+            if (isset($old_org_options[$option_name])) {
114
+                $this->_handle_org_option($option_name, $old_org_options[$option_name]);
115 115
             }
116 116
             if ($option_name == 'surcharge') {
117 117
                 $this->_insert_new_global_surcharge_price($old_org_options);
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         }
121 121
 
122 122
         $success = EE_Config::instance()->update_espresso_config(false, true);
123
-        if (! $success) {
123
+        if ( ! $success) {
124 124
             $this->add_error(sprintf(esc_html__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false)));
125 125
             EE_Error::overwrite_errors();
126 126
         }
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
                 $c->organization->email = $value;
177 177
                 break;
178 178
             case 'default_payment_status':
179
-                $c->registration->default_STS_ID =  $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
179
+                $c->registration->default_STS_ID = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
180 180
                 break;
181 181
             case 'organization_country':
182 182
                 $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value);
183 183
                 $c->organization->CNT_ISO = $iso;
184 184
                 $country_row = $this->get_migration_script()->get_or_create_country($iso);
185
-                if (! $country_row) {
185
+                if ( ! $country_row) {
186 186
                     $this->add_error(sprintf(esc_html__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso));
187 187
                 }
188 188
                 // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them)
189
-                $c->currency->code = $country_row['CNT_cur_code'];          // currency code: USD, CAD, EUR
190
-                $c->currency->name = $country_row['CNT_cur_single'];    // Dollar
191
-                $c->currency->plural = $country_row['CNT_cur_plural'];  // Dollars
192
-                $c->currency->sign =  $country_row['CNT_cur_sign'];             // currency sign: $
193
-                $c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN);        // currency sign before or after: $TRUE  or  FALSE$
194
-                $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc'];    // decimal places: 2 = 0.00  3 = 0.000
195
-                $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk'];    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
196
-                $c->currency->thsnds = $country_row['CNT_cur_thsnds'];  // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
189
+                $c->currency->code = $country_row['CNT_cur_code']; // currency code: USD, CAD, EUR
190
+                $c->currency->name = $country_row['CNT_cur_single']; // Dollar
191
+                $c->currency->plural = $country_row['CNT_cur_plural']; // Dollars
192
+                $c->currency->sign = $country_row['CNT_cur_sign']; // currency sign: $
193
+                $c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN); // currency sign before or after: $TRUE  or  FALSE$
194
+                $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc']; // decimal places: 2 = 0.00  3 = 0.000
195
+                $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk']; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
196
+                $c->currency->thsnds = $country_row['CNT_cur_thsnds']; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
197 197
   //            $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break;
198 198
   //        case 'currency_symbol': ignore the currency symbol. we'll just go by their country.
199 199
   //            $c->currency->sign = $value;break;
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 
299 299
         );
300 300
         $datatypes = array(
301
-            '%d',// PRT_ID
302
-            '%f',// PRT_amount
303
-            '%s',// PRC_name
304
-            '%d',// PRC_is_default
305
-            '%d',// PRC_overrides
306
-            '%d',// PRC_order
307
-            '%d',// PRC_deleted
308
-            '%d',// PRC_parent
301
+            '%d', // PRT_ID
302
+            '%f', // PRT_amount
303
+            '%s', // PRC_name
304
+            '%d', // PRC_is_default
305
+            '%d', // PRC_overrides
306
+            '%d', // PRC_order
307
+            '%d', // PRC_deleted
308
+            '%d', // PRC_parent
309 309
         );
310
-        $price_table = $wpdb->prefix . "esp_price";
310
+        $price_table = $wpdb->prefix."esp_price";
311 311
         $success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
312
-        if (! $success) {
312
+        if ( ! $success) {
313 313
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
314 314
                 'org_options',
315 315
                 array(
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
       'payment_message',
340 340
       'message',
341 341
       'default_payment_status',
342
-      'surcharge',// unused?
343
-      'country_id',// unused?
342
+      'surcharge', // unused?
343
+      'country_id', // unused?
344 344
       'organization_country',
345 345
 //    'currency_symbol',
346 346
       'expire_on_registration_end',
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
       'show_pending_payment_options',
353 353
       'show_reg_footer',
354 354
       'skip_confirmation_page',
355
-      'allow_mer_discounts',// no equiv
356
-      'allow_mer_vouchers',// no equiv
355
+      'allow_mer_discounts', // no equiv
356
+      'allow_mer_vouchers', // no equiv
357 357
       'display_short_description_in_event_list',
358 358
       'display_description_on_multi_reg_page',
359 359
       'display_address_in_event_list',
360 360
       'display_address_in_regform',
361
-      'use_custom_post_types',// no equiv
361
+      'use_custom_post_types', // no equiv
362 362
       'display_ical_download',
363 363
       'display_featured_image',
364 364
       'themeroller',
@@ -377,11 +377,11 @@  discard block
 block discarded – undo
377 377
       'espresso_dashboard_widget',
378 378
       'time_reg_limit',
379 379
 //    'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status
380
-      'use_personnel_manager',// no equiv
380
+      'use_personnel_manager', // no equiv
381 381
       'use_event_timezones',
382 382
       'full_logging',
383
-      'surcharge_type',// unused
384
-      'surcharge_text',// unused
383
+      'surcharge_type', // unused
384
+      'surcharge_text', // unused
385 385
       'affiliate_id',
386 386
       'site_license_key',
387 387
     );
Please login to merge, or discard this patch.
Indentation   +270 added lines, -270 removed lines patch added patch discarded remove patch
@@ -102,286 +102,286 @@
 block discarded – undo
102 102
  */
103 103
 class EE_DMS_4_1_0_org_options extends EE_Data_Migration_Script_Stage
104 104
 {
105
-    public function _migration_step($num_items = 50)
106
-    {
105
+	public function _migration_step($num_items = 50)
106
+	{
107 107
 
108
-        $items_actually_migrated = 0;
109
-        $old_org_options = get_option('events_organization_settings');
110
-        foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
111
-            // only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
112
-            if (isset($old_org_options[ $option_name ])) {
113
-                $this->_handle_org_option($option_name, $old_org_options[ $option_name ]);
114
-            }
115
-            if ($option_name == 'surcharge') {
116
-                $this->_insert_new_global_surcharge_price($old_org_options);
117
-            }
118
-            $items_actually_migrated++;
119
-        }
108
+		$items_actually_migrated = 0;
109
+		$old_org_options = get_option('events_organization_settings');
110
+		foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
111
+			// only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
112
+			if (isset($old_org_options[ $option_name ])) {
113
+				$this->_handle_org_option($option_name, $old_org_options[ $option_name ]);
114
+			}
115
+			if ($option_name == 'surcharge') {
116
+				$this->_insert_new_global_surcharge_price($old_org_options);
117
+			}
118
+			$items_actually_migrated++;
119
+		}
120 120
 
121
-        $success = EE_Config::instance()->update_espresso_config(false, true);
122
-        if (! $success) {
123
-            $this->add_error(sprintf(esc_html__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false)));
124
-            EE_Error::overwrite_errors();
125
-        }
126
-        EE_Network_Config::instance()->update_config(false, false);
127
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
128
-            // we may have added new pages and this might be necessary
129
-            flush_rewrite_rules();
130
-            $this->set_completed();
131
-        }
132
-        return $items_actually_migrated;
133
-    }
134
-    public function _count_records_to_migrate()
135
-    {
136
-        $count_of_options_to_migrate = count($this->_org_options_we_know_how_to_migrate);
137
-        return $count_of_options_to_migrate;
138
-    }
139
-    public function __construct()
140
-    {
141
-        $this->_pretty_name = esc_html__("Organization Options/Config", "event_espresso");
142
-        $this->_org_options_we_know_how_to_migrate = apply_filters('FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', $this->_org_options_we_know_how_to_migrate);
143
-        parent::__construct();
144
-    }
121
+		$success = EE_Config::instance()->update_espresso_config(false, true);
122
+		if (! $success) {
123
+			$this->add_error(sprintf(esc_html__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(false)));
124
+			EE_Error::overwrite_errors();
125
+		}
126
+		EE_Network_Config::instance()->update_config(false, false);
127
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
128
+			// we may have added new pages and this might be necessary
129
+			flush_rewrite_rules();
130
+			$this->set_completed();
131
+		}
132
+		return $items_actually_migrated;
133
+	}
134
+	public function _count_records_to_migrate()
135
+	{
136
+		$count_of_options_to_migrate = count($this->_org_options_we_know_how_to_migrate);
137
+		return $count_of_options_to_migrate;
138
+	}
139
+	public function __construct()
140
+	{
141
+		$this->_pretty_name = esc_html__("Organization Options/Config", "event_espresso");
142
+		$this->_org_options_we_know_how_to_migrate = apply_filters('FHEE__EE_DMS_4_1_0_org_options__org_options_we_know_how_to_migrate', $this->_org_options_we_know_how_to_migrate);
143
+		parent::__construct();
144
+	}
145 145
 
146
-    private function _handle_org_option($option_name, $value)
147
-    {
148
-        $c = EE_Config::instance();
149
-        $cn = EE_Network_Config::instance();
150
-        switch ($option_name) {
151
-            case 'organization':
152
-                $c->organization->name = $value;
153
-                break;
154
-            case 'organization_street1':
155
-                $c->organization->address_1 = $value;
156
-                break;
157
-            case 'organization_street2':
158
-                $c->organization->address_2 = $value;
159
-                break;
160
-            case 'organization_city':
161
-                $c->organization->city = $value;
162
-                break;
163
-            case 'organization_state':
164
-                try {
165
-                    $state = $this->get_migration_script()->get_or_create_state($value);
166
-                    $state_id = $state['STA_ID'];
167
-                    $c->organization->STA_ID = $state_id;
168
-                } catch (EE_Error $e) {
169
-                }
170
-                break;
171
-            case 'organization_zip':
172
-                $c->organization->zip = $value;
173
-                break;
174
-            case 'contact_email':
175
-                $c->organization->email = $value;
176
-                break;
177
-            case 'default_payment_status':
178
-                $c->registration->default_STS_ID =  $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
179
-                break;
180
-            case 'organization_country':
181
-                $iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value);
182
-                $c->organization->CNT_ISO = $iso;
183
-                $country_row = $this->get_migration_script()->get_or_create_country($iso);
184
-                if (! $country_row) {
185
-                    $this->add_error(sprintf(esc_html__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso));
186
-                }
187
-                // can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them)
188
-                $c->currency->code = $country_row['CNT_cur_code'];          // currency code: USD, CAD, EUR
189
-                $c->currency->name = $country_row['CNT_cur_single'];    // Dollar
190
-                $c->currency->plural = $country_row['CNT_cur_plural'];  // Dollars
191
-                $c->currency->sign =  $country_row['CNT_cur_sign'];             // currency sign: $
192
-                $c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN);        // currency sign before or after: $TRUE  or  FALSE$
193
-                $c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc'];    // decimal places: 2 = 0.00  3 = 0.000
194
-                $c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk'];    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
195
-                $c->currency->thsnds = $country_row['CNT_cur_thsnds'];  // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
146
+	private function _handle_org_option($option_name, $value)
147
+	{
148
+		$c = EE_Config::instance();
149
+		$cn = EE_Network_Config::instance();
150
+		switch ($option_name) {
151
+			case 'organization':
152
+				$c->organization->name = $value;
153
+				break;
154
+			case 'organization_street1':
155
+				$c->organization->address_1 = $value;
156
+				break;
157
+			case 'organization_street2':
158
+				$c->organization->address_2 = $value;
159
+				break;
160
+			case 'organization_city':
161
+				$c->organization->city = $value;
162
+				break;
163
+			case 'organization_state':
164
+				try {
165
+					$state = $this->get_migration_script()->get_or_create_state($value);
166
+					$state_id = $state['STA_ID'];
167
+					$c->organization->STA_ID = $state_id;
168
+				} catch (EE_Error $e) {
169
+				}
170
+				break;
171
+			case 'organization_zip':
172
+				$c->organization->zip = $value;
173
+				break;
174
+			case 'contact_email':
175
+				$c->organization->email = $value;
176
+				break;
177
+			case 'default_payment_status':
178
+				$c->registration->default_STS_ID =  $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID($value);
179
+				break;
180
+			case 'organization_country':
181
+				$iso = $this->get_migration_script()->get_iso_from_3_1_country_id($value);
182
+				$c->organization->CNT_ISO = $iso;
183
+				$country_row = $this->get_migration_script()->get_or_create_country($iso);
184
+				if (! $country_row) {
185
+					$this->add_error(sprintf(esc_html__("Could not set country's currency config because no country exists for ISO %s", "event_espresso"), $iso));
186
+				}
187
+				// can't use EE_Currency_Config's handy constructor because the models are off-limits right now (and it uses them)
188
+				$c->currency->code = $country_row['CNT_cur_code'];          // currency code: USD, CAD, EUR
189
+				$c->currency->name = $country_row['CNT_cur_single'];    // Dollar
190
+				$c->currency->plural = $country_row['CNT_cur_plural'];  // Dollars
191
+				$c->currency->sign =  $country_row['CNT_cur_sign'];             // currency sign: $
192
+				$c->currency->sign_b4 = filter_var($country_row['CNT_cur_sign_b4'], FILTER_VALIDATE_BOOLEAN);        // currency sign before or after: $TRUE  or  FALSE$
193
+				$c->currency->dec_plc = (int) $country_row['CNT_cur_dec_plc'];    // decimal places: 2 = 0.00  3 = 0.000
194
+				$c->currency->dec_mrk = $country_row['CNT_cur_dec_mrk'];    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
195
+				$c->currency->thsnds = $country_row['CNT_cur_thsnds'];  // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
196 196
   //            $c->currency = new EE_Currency_Config($c->organization->CNT_ISO);break;
197 197
   //        case 'currency_symbol': ignore the currency symbol. we'll just go by their country.
198 198
   //            $c->currency->sign = $value;break;
199
-            case 'show_pending_payment_options':
200
-                $c->registration->show_pending_payment_options = ($value == 'Y');
201
-                break;
202
-            case 'display_address_in_regform':
203
-                $c->template_settings->display_address_in_regform = ($value == 'Y');
204
-                break;
205
-            case 'default_logo_url':
206
-                $c->organization->logo_url = $value;
207
-                break;
208
-            case 'event_page_id':
209
-                // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
210
-                // to ESPRESSO_THANK_YOU
211
-                $reg_page_post = get_post($value);
212
-                $reg_page_post->post_content = str_replace("[ESPRESSO_EVENTS]", "[ESPRESSO_CHECKOUT]", $reg_page_post->post_content);
213
-                wp_update_post($reg_page_post);
214
-                $c->core->reg_page_id = $value;
215
-                break;
216
-            case 'return_url':
217
-                // also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
218
-                // to ESPRESSO_THANK_YOU
219
-                $thank_you_page_post = get_post($value);
220
-                $thank_you_page_post->post_content = str_replace("[ESPRESSO_PAYMENTS]", "[ESPRESSO_THANK_YOU]", $thank_you_page_post->post_content);
221
-                wp_update_post($thank_you_page_post);
222
-                $c->core->thank_you_page_id = $value;
223
-                break;
224
-            case 'cancel_return':
225
-                $c->core->cancel_page_id = $value;
199
+			case 'show_pending_payment_options':
200
+				$c->registration->show_pending_payment_options = ($value == 'Y');
201
+				break;
202
+			case 'display_address_in_regform':
203
+				$c->template_settings->display_address_in_regform = ($value == 'Y');
204
+				break;
205
+			case 'default_logo_url':
206
+				$c->organization->logo_url = $value;
207
+				break;
208
+			case 'event_page_id':
209
+				// also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
210
+				// to ESPRESSO_THANK_YOU
211
+				$reg_page_post = get_post($value);
212
+				$reg_page_post->post_content = str_replace("[ESPRESSO_EVENTS]", "[ESPRESSO_CHECKOUT]", $reg_page_post->post_content);
213
+				wp_update_post($reg_page_post);
214
+				$c->core->reg_page_id = $value;
215
+				break;
216
+			case 'return_url':
217
+				// also, find that post, and changes the shortcode in it from ESPRESSO_PAYMENTS
218
+				// to ESPRESSO_THANK_YOU
219
+				$thank_you_page_post = get_post($value);
220
+				$thank_you_page_post->post_content = str_replace("[ESPRESSO_PAYMENTS]", "[ESPRESSO_THANK_YOU]", $thank_you_page_post->post_content);
221
+				wp_update_post($thank_you_page_post);
222
+				$c->core->thank_you_page_id = $value;
223
+				break;
224
+			case 'cancel_return':
225
+				$c->core->cancel_page_id = $value;
226 226
 
227
-                break;
228
-            case 'notify_url':
229
-                $c->core->txn_page_id = $value;
230
-                break;
231
-            case 'use_captcha':
232
-                $c->registration->use_captcha = ($value == 'Y');
233
-                break;
234
-            case 'recaptcha_publickey':
235
-                $c->registration->recaptcha_publickey = $value;
236
-                break;
237
-            case 'recaptcha_privatekey':
238
-                $c->registration->recaptcha_privatekey = $value;
239
-                break;
240
-            case 'recaptcha_theme':
241
-                $c->registration->recaptcha_theme = $value;
242
-                break;
243
-            case 'recaptcha_width':
244
-                $c->registration->recaptcha_width = $value;
245
-                break;
246
-            case 'recaptcha_language':
247
-                $c->registration->recaptcha_language = $value;
248
-                break;
249
-            case 'espresso_dashboard_widget':
250
-                $c->admin->use_dashboard_widget = ($value == 'Y');
251
-                break;
252
-            case 'use_personnel_manager':
253
-                $c->admin->use_personnel_manager = ($value == 'Y');
254
-                break;
255
-            case 'use_event_timezones':
256
-                $c->admin->use_event_timezones = ($value == 'Y');
257
-                break;
258
-            case 'affiliate_id':
259
-                $c->admin->affiliate_id = $value;
260
-                break;
261
-            case 'site_license_key':
262
-                $cn->core->site_license_key = $value;
263
-                break;
264
-            default:
265
-                do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value);
266
-        }
267
-    }
227
+				break;
228
+			case 'notify_url':
229
+				$c->core->txn_page_id = $value;
230
+				break;
231
+			case 'use_captcha':
232
+				$c->registration->use_captcha = ($value == 'Y');
233
+				break;
234
+			case 'recaptcha_publickey':
235
+				$c->registration->recaptcha_publickey = $value;
236
+				break;
237
+			case 'recaptcha_privatekey':
238
+				$c->registration->recaptcha_privatekey = $value;
239
+				break;
240
+			case 'recaptcha_theme':
241
+				$c->registration->recaptcha_theme = $value;
242
+				break;
243
+			case 'recaptcha_width':
244
+				$c->registration->recaptcha_width = $value;
245
+				break;
246
+			case 'recaptcha_language':
247
+				$c->registration->recaptcha_language = $value;
248
+				break;
249
+			case 'espresso_dashboard_widget':
250
+				$c->admin->use_dashboard_widget = ($value == 'Y');
251
+				break;
252
+			case 'use_personnel_manager':
253
+				$c->admin->use_personnel_manager = ($value == 'Y');
254
+				break;
255
+			case 'use_event_timezones':
256
+				$c->admin->use_event_timezones = ($value == 'Y');
257
+				break;
258
+			case 'affiliate_id':
259
+				$c->admin->affiliate_id = $value;
260
+				break;
261
+			case 'site_license_key':
262
+				$cn->core->site_license_key = $value;
263
+				break;
264
+			default:
265
+				do_action('AHEE__EE_DMS_4_1_0__handle_org_option', $option_name, $value);
266
+		}
267
+	}
268 268
 
269
-    /**
270
-     * Creates a 4.1 member price discount
271
-     * @global type $wpdb
272
-     * @param type $old_price
273
-     * @return int
274
-     */
275
-    private function _insert_new_global_surcharge_price($org_options)
276
-    {
277
-        $amount = floatval($org_options['surcharge']);
278
-        // dont createa a price if the surcharge is 0
279
-        if ($amount <= .01) {
280
-            return 0;
281
-        }
282
-        if ($org_options['surcharge_type'] == 'flat_rate') {
283
-            $price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge;
284
-        } else {
285
-            $price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge;
286
-        }
287
-        global $wpdb;
288
-        $cols_n_values = array(
289
-            'PRT_ID' => $price_type,
290
-            'PRC_amount' => $amount,
291
-            'PRC_name' =>  $org_options['surcharge_text'],
292
-            'PRC_is_default' => true,
293
-            'PRC_overrides' => false,
294
-            'PRC_order' => 100,
295
-            'PRC_deleted' => false,
296
-            'PRC_parent' => null
269
+	/**
270
+	 * Creates a 4.1 member price discount
271
+	 * @global type $wpdb
272
+	 * @param type $old_price
273
+	 * @return int
274
+	 */
275
+	private function _insert_new_global_surcharge_price($org_options)
276
+	{
277
+		$amount = floatval($org_options['surcharge']);
278
+		// dont createa a price if the surcharge is 0
279
+		if ($amount <= .01) {
280
+			return 0;
281
+		}
282
+		if ($org_options['surcharge_type'] == 'flat_rate') {
283
+			$price_type = EE_DMS_4_1_0_prices::price_type_flat_surcharge;
284
+		} else {
285
+			$price_type = EE_DMS_4_1_0_prices::price_type_percent_surcharge;
286
+		}
287
+		global $wpdb;
288
+		$cols_n_values = array(
289
+			'PRT_ID' => $price_type,
290
+			'PRC_amount' => $amount,
291
+			'PRC_name' =>  $org_options['surcharge_text'],
292
+			'PRC_is_default' => true,
293
+			'PRC_overrides' => false,
294
+			'PRC_order' => 100,
295
+			'PRC_deleted' => false,
296
+			'PRC_parent' => null
297 297
 
298
-        );
299
-        $datatypes = array(
300
-            '%d',// PRT_ID
301
-            '%f',// PRT_amount
302
-            '%s',// PRC_name
303
-            '%d',// PRC_is_default
304
-            '%d',// PRC_overrides
305
-            '%d',// PRC_order
306
-            '%d',// PRC_deleted
307
-            '%d',// PRC_parent
308
-        );
309
-        $price_table = $wpdb->prefix . "esp_price";
310
-        $success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
311
-        if (! $success) {
312
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
313
-                'org_options',
314
-                array(
315
-                        'surcharge' => $org_options['surcharge'],
316
-                        'surcharge_type' => $org_options['surcharge_type'],
317
-                        'surcharge_text' => $org_options['surcharge_text']),
318
-                $price_table,
319
-                $cols_n_values,
320
-                $datatypes
321
-            ));
322
-            return 0;
323
-        }
324
-        $new_id = $wpdb->insert_id;
325
-        return $new_id;
326
-    }
298
+		);
299
+		$datatypes = array(
300
+			'%d',// PRT_ID
301
+			'%f',// PRT_amount
302
+			'%s',// PRC_name
303
+			'%d',// PRC_is_default
304
+			'%d',// PRC_overrides
305
+			'%d',// PRC_order
306
+			'%d',// PRC_deleted
307
+			'%d',// PRC_parent
308
+		);
309
+		$price_table = $wpdb->prefix . "esp_price";
310
+		$success = $wpdb->insert($price_table, $cols_n_values, $datatypes);
311
+		if (! $success) {
312
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion(
313
+				'org_options',
314
+				array(
315
+						'surcharge' => $org_options['surcharge'],
316
+						'surcharge_type' => $org_options['surcharge_type'],
317
+						'surcharge_text' => $org_options['surcharge_text']),
318
+				$price_table,
319
+				$cols_n_values,
320
+				$datatypes
321
+			));
322
+			return 0;
323
+		}
324
+		$new_id = $wpdb->insert_id;
325
+		return $new_id;
326
+	}
327 327
 
328
-    protected $_org_options_we_know_how_to_migrate = array(
329
-      'organization',
330
-      'organization_street1',
331
-      'organization_street2',
332
-      'organization_city',
333
-      'organization_state',
334
-      'organization_zip',
335
-      'contact_email',
336
-      'default_mail',
337
-      'payment_subject',
338
-      'payment_message',
339
-      'message',
340
-      'default_payment_status',
341
-      'surcharge',// unused?
342
-      'country_id',// unused?
343
-      'organization_country',
328
+	protected $_org_options_we_know_how_to_migrate = array(
329
+	  'organization',
330
+	  'organization_street1',
331
+	  'organization_street2',
332
+	  'organization_city',
333
+	  'organization_state',
334
+	  'organization_zip',
335
+	  'contact_email',
336
+	  'default_mail',
337
+	  'payment_subject',
338
+	  'payment_message',
339
+	  'message',
340
+	  'default_payment_status',
341
+	  'surcharge',// unused?
342
+	  'country_id',// unused?
343
+	  'organization_country',
344 344
 //    'currency_symbol',
345
-      'expire_on_registration_end',
346
-      'email_before_payment',
347
-      'email_fancy_headers',
348
-      'enable_default_style',
349
-      'event_ssl_active',
350
-      'selected_style',
351
-      'show_pending_payment_options',
352
-      'show_reg_footer',
353
-      'skip_confirmation_page',
354
-      'allow_mer_discounts',// no equiv
355
-      'allow_mer_vouchers',// no equiv
356
-      'display_short_description_in_event_list',
357
-      'display_description_on_multi_reg_page',
358
-      'display_address_in_event_list',
359
-      'display_address_in_regform',
360
-      'use_custom_post_types',// no equiv
361
-      'display_ical_download',
362
-      'display_featured_image',
363
-      'themeroller',
364
-      'default_logo_url',
365
-      'event_page_id',
366
-      'return_url',
367
-      'cancel_return',
368
-      'notify_url',
369
-      'events_in_dashboard',
370
-      'use_captcha',
371
-      'recaptcha_publickey',
372
-      'recaptcha_privatekey',
373
-      'recaptcha_theme',
374
-      'recaptcha_width',
375
-      'recaptcha_language',
376
-      'espresso_dashboard_widget',
377
-      'time_reg_limit',
345
+	  'expire_on_registration_end',
346
+	  'email_before_payment',
347
+	  'email_fancy_headers',
348
+	  'enable_default_style',
349
+	  'event_ssl_active',
350
+	  'selected_style',
351
+	  'show_pending_payment_options',
352
+	  'show_reg_footer',
353
+	  'skip_confirmation_page',
354
+	  'allow_mer_discounts',// no equiv
355
+	  'allow_mer_vouchers',// no equiv
356
+	  'display_short_description_in_event_list',
357
+	  'display_description_on_multi_reg_page',
358
+	  'display_address_in_event_list',
359
+	  'display_address_in_regform',
360
+	  'use_custom_post_types',// no equiv
361
+	  'display_ical_download',
362
+	  'display_featured_image',
363
+	  'themeroller',
364
+	  'default_logo_url',
365
+	  'event_page_id',
366
+	  'return_url',
367
+	  'cancel_return',
368
+	  'notify_url',
369
+	  'events_in_dashboard',
370
+	  'use_captcha',
371
+	  'recaptcha_publickey',
372
+	  'recaptcha_privatekey',
373
+	  'recaptcha_theme',
374
+	  'recaptcha_width',
375
+	  'recaptcha_language',
376
+	  'espresso_dashboard_widget',
377
+	  'time_reg_limit',
378 378
 //    'use_attendee_pre_approval', removed in 4.1- instead this is factored into the default reg status
379
-      'use_personnel_manager',// no equiv
380
-      'use_event_timezones',
381
-      'full_logging',
382
-      'surcharge_type',// unused
383
-      'surcharge_text',// unused
384
-      'affiliate_id',
385
-      'site_license_key',
386
-    );
379
+	  'use_personnel_manager',// no equiv
380
+	  'use_event_timezones',
381
+	  'full_logging',
382
+	  'surcharge_type',// unused
383
+	  'surcharge_text',// unused
384
+	  'affiliate_id',
385
+	  'site_license_key',
386
+	);
387 387
 }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_question_groups.dmsstage.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -40,119 +40,119 @@
 block discarded – undo
40 40
  */
41 41
 class EE_DMS_4_1_0_question_groups extends EE_Data_Migration_Script_Stage
42 42
 {
43
-    private $_old_table;
44
-    private $_new_table;
45
-    /**
46
-     * Keeps track of whether or not we've already added a system question group,
47
-     * in order to avoid adding more than 1 (basically, in 3.1 this would happen
48
-     * with the Roles & Permissions addon, because each user had their own set of
49
-     * question groups and questions),
50
-     * @var boolean
51
-     */
52
-    private $_already_got_system_question_group_1 = false;
53
-    public function _migration_step($num_items = 50)
54
-    {
43
+	private $_old_table;
44
+	private $_new_table;
45
+	/**
46
+	 * Keeps track of whether or not we've already added a system question group,
47
+	 * in order to avoid adding more than 1 (basically, in 3.1 this would happen
48
+	 * with the Roles & Permissions addon, because each user had their own set of
49
+	 * question groups and questions),
50
+	 * @var boolean
51
+	 */
52
+	private $_already_got_system_question_group_1 = false;
53
+	public function _migration_step($num_items = 50)
54
+	{
55 55
 
56
-        global $wpdb;
57
-        $start_at_record = $this->count_records_migrated();
58
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
59
-        $items_actually_migrated = 0;
60
-        foreach ($rows as $question_group) {
61
-            $new_id = $this->_insert_new_question_group($question_group);
56
+		global $wpdb;
57
+		$start_at_record = $this->count_records_migrated();
58
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
59
+		$items_actually_migrated = 0;
60
+		foreach ($rows as $question_group) {
61
+			$new_id = $this->_insert_new_question_group($question_group);
62 62
 
63
-            $this->get_migration_script()->set_mapping($this->_old_table, $question_group['id'], $this->_new_table, $new_id);
64
-            $items_actually_migrated++;
65
-        }
66
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
67
-            $this->set_completed();
68
-        }
69
-        return $items_actually_migrated;
70
-    }
71
-    public function _count_records_to_migrate()
72
-    {
73
-        global $wpdb;
74
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
75
-        return $count;
76
-    }
77
-    public function __construct()
78
-    {
79
-        global $wpdb;
80
-        $this->_old_table = $wpdb->prefix . "events_qst_group";
81
-        $this->_new_table = $wpdb->prefix . "esp_question_group";
82
-        $this->_pretty_name = esc_html__("Question Groups", "event_espresso");
83
-        parent::__construct();
84
-    }
63
+			$this->get_migration_script()->set_mapping($this->_old_table, $question_group['id'], $this->_new_table, $new_id);
64
+			$items_actually_migrated++;
65
+		}
66
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
67
+			$this->set_completed();
68
+		}
69
+		return $items_actually_migrated;
70
+	}
71
+	public function _count_records_to_migrate()
72
+	{
73
+		global $wpdb;
74
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
75
+		return $count;
76
+	}
77
+	public function __construct()
78
+	{
79
+		global $wpdb;
80
+		$this->_old_table = $wpdb->prefix . "events_qst_group";
81
+		$this->_new_table = $wpdb->prefix . "esp_question_group";
82
+		$this->_pretty_name = esc_html__("Question Groups", "event_espresso");
83
+		parent::__construct();
84
+	}
85 85
 
86
-    /**
87
-     * Attempts to insert a new question group inthe new format given an old one
88
-     * @global type $wpdb
89
-     * @param array $old_question_group
90
-     * @return int
91
-     */
92
-    private function _insert_new_question_group($old_question_group)
93
-    {
94
-        global $wpdb;
95
-        // try to guess what the QST_system int should be... finding the Personal info system
96
-        // question group is quite easy. But in 3.1 address info WASN'T a system group, it just exitsed by default but
97
-        // could be easily removed.
98
-        if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) {
99
-            $guess_at_system_number = 1;
100
-        } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address') !== false) {
101
-            $guess_at_system_number = 2;
102
-        } else {
103
-            $guess_at_system_number = 0;
104
-        }
105
-        // if the question group wasn't made by the normal admin,
106
-        // we'd like to keep track of who made it
107
-        if (intval($old_question_group['wp_user']) != 1) {
108
-            $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM " . $wpdb->users . " WHERE ID = %d", $old_question_group['wp_user']));
109
-            $identifier = $old_question_group['group_identifier'] . "-by-" . $username;
110
-        } else {
111
-            $identifier = $old_question_group['group_identifier'];
112
-        }
113
-        $cols_n_values = array(
114
-            'QSG_name' => stripslashes($old_question_group['group_name']),
115
-            'QSG_identifier' => $identifier,
116
-            'QSG_desc' => stripslashes($old_question_group['group_description']),
117
-            'QSG_order' => $old_question_group['group_order'],
118
-            'QSG_show_group_name' => $old_question_group['show_group_name'],
119
-            'QSG_show_group_desc' => $old_question_group['show_group_description'],
120
-            'QSG_system' => $guess_at_system_number,
121
-            'QSG_deleted' => false
122
-        );
123
-        $datatypes = array(
124
-            '%s',// QSG_name
125
-            '%s',// QSG_identifier
126
-            '%s',// QSG_desc
127
-            '%d',// QSG_order
128
-            '%d',// QSG_show_group_name
129
-            '%d',// QSG_show_group_desc
130
-            '%d',// QSG_system
131
-            '%d',// QSG_deleted
132
-        );
133
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
134
-        if (! $success) {
135
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes));
136
-            return 0;
137
-        }
138
-        return $wpdb->insert_id;
139
-    }
86
+	/**
87
+	 * Attempts to insert a new question group inthe new format given an old one
88
+	 * @global type $wpdb
89
+	 * @param array $old_question_group
90
+	 * @return int
91
+	 */
92
+	private function _insert_new_question_group($old_question_group)
93
+	{
94
+		global $wpdb;
95
+		// try to guess what the QST_system int should be... finding the Personal info system
96
+		// question group is quite easy. But in 3.1 address info WASN'T a system group, it just exitsed by default but
97
+		// could be easily removed.
98
+		if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) {
99
+			$guess_at_system_number = 1;
100
+		} elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address') !== false) {
101
+			$guess_at_system_number = 2;
102
+		} else {
103
+			$guess_at_system_number = 0;
104
+		}
105
+		// if the question group wasn't made by the normal admin,
106
+		// we'd like to keep track of who made it
107
+		if (intval($old_question_group['wp_user']) != 1) {
108
+			$username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM " . $wpdb->users . " WHERE ID = %d", $old_question_group['wp_user']));
109
+			$identifier = $old_question_group['group_identifier'] . "-by-" . $username;
110
+		} else {
111
+			$identifier = $old_question_group['group_identifier'];
112
+		}
113
+		$cols_n_values = array(
114
+			'QSG_name' => stripslashes($old_question_group['group_name']),
115
+			'QSG_identifier' => $identifier,
116
+			'QSG_desc' => stripslashes($old_question_group['group_description']),
117
+			'QSG_order' => $old_question_group['group_order'],
118
+			'QSG_show_group_name' => $old_question_group['show_group_name'],
119
+			'QSG_show_group_desc' => $old_question_group['show_group_description'],
120
+			'QSG_system' => $guess_at_system_number,
121
+			'QSG_deleted' => false
122
+		);
123
+		$datatypes = array(
124
+			'%s',// QSG_name
125
+			'%s',// QSG_identifier
126
+			'%s',// QSG_desc
127
+			'%d',// QSG_order
128
+			'%d',// QSG_show_group_name
129
+			'%d',// QSG_show_group_desc
130
+			'%d',// QSG_system
131
+			'%d',// QSG_deleted
132
+		);
133
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
134
+		if (! $success) {
135
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes));
136
+			return 0;
137
+		}
138
+		return $wpdb->insert_id;
139
+	}
140 140
 
141
-    /**
142
-     * Checks if we've already added a system question 1 to the new question groups table
143
-     * @global type $wpdb
144
-     * @return boolean
145
-     */
146
-    private function _already_got_system_question_group_1()
147
-    {
148
-        if (! $this->_already_got_system_question_group_1) {
149
-            // check the db
150
-            global $wpdb;
151
-            $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1");
152
-            if (intval($exists) > 0) {
153
-                $this->_already_got_system_question_group_1 = true;
154
-            }
155
-        }
156
-        return $this->_already_got_system_question_group_1;
157
-    }
141
+	/**
142
+	 * Checks if we've already added a system question 1 to the new question groups table
143
+	 * @global type $wpdb
144
+	 * @return boolean
145
+	 */
146
+	private function _already_got_system_question_group_1()
147
+	{
148
+		if (! $this->_already_got_system_question_group_1) {
149
+			// check the db
150
+			global $wpdb;
151
+			$exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1");
152
+			if (intval($exists) > 0) {
153
+				$this->_already_got_system_question_group_1 = true;
154
+			}
155
+		}
156
+		return $this->_already_got_system_question_group_1;
157
+	}
158 158
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
     public function _count_records_to_migrate()
72 72
     {
73 73
         global $wpdb;
74
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
74
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
75 75
         return $count;
76 76
     }
77 77
     public function __construct()
78 78
     {
79 79
         global $wpdb;
80
-        $this->_old_table = $wpdb->prefix . "events_qst_group";
81
-        $this->_new_table = $wpdb->prefix . "esp_question_group";
80
+        $this->_old_table = $wpdb->prefix."events_qst_group";
81
+        $this->_new_table = $wpdb->prefix."esp_question_group";
82 82
         $this->_pretty_name = esc_html__("Question Groups", "event_espresso");
83 83
         parent::__construct();
84 84
     }
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
         // if the question group wasn't made by the normal admin,
106 106
         // we'd like to keep track of who made it
107 107
         if (intval($old_question_group['wp_user']) != 1) {
108
-            $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM " . $wpdb->users . " WHERE ID = %d", $old_question_group['wp_user']));
109
-            $identifier = $old_question_group['group_identifier'] . "-by-" . $username;
108
+            $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user']));
109
+            $identifier = $old_question_group['group_identifier']."-by-".$username;
110 110
         } else {
111 111
             $identifier = $old_question_group['group_identifier'];
112 112
         }
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
             'QSG_deleted' => false
122 122
         );
123 123
         $datatypes = array(
124
-            '%s',// QSG_name
125
-            '%s',// QSG_identifier
126
-            '%s',// QSG_desc
127
-            '%d',// QSG_order
128
-            '%d',// QSG_show_group_name
129
-            '%d',// QSG_show_group_desc
130
-            '%d',// QSG_system
131
-            '%d',// QSG_deleted
124
+            '%s', // QSG_name
125
+            '%s', // QSG_identifier
126
+            '%s', // QSG_desc
127
+            '%d', // QSG_order
128
+            '%d', // QSG_show_group_name
129
+            '%d', // QSG_show_group_desc
130
+            '%d', // QSG_system
131
+            '%d', // QSG_deleted
132 132
         );
133 133
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
134
-        if (! $success) {
134
+        if ( ! $success) {
135 135
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes));
136 136
             return 0;
137 137
         }
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      */
146 146
     private function _already_got_system_question_group_1()
147 147
     {
148
-        if (! $this->_already_got_system_question_group_1) {
148
+        if ( ! $this->_already_got_system_question_group_1) {
149 149
             // check the db
150 150
             global $wpdb;
151 151
             $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1");
Please login to merge, or discard this patch.