Completed
Branch TASK/update-about-page (06850d)
by
unknown
83:04 queued 74:05
created
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 1 patch
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[ $matches[1] ] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[ $matches[1] ] = $filepath;
18 18
 }
19 19
 // give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
34 34
 {
35 35
 
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
-            //          echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif (! $version_string) {
68
-            //          echo "no version string provided: $version_string";
69
-            // no version string provided... this must be pre 4.3
70
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //          echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
+			//          echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif (! $version_string) {
68
+			//          echo "no version string provided: $version_string";
69
+			// no version string provided... this must be pre 4.3
70
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//          echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,29 +139,29 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code varchar(6) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        // note: although this table is no longer in use,
153
-        // it hasn't been removed because then queries to the model will have errors.
154
-        // but you should expect this table and its corresponding model to be removed in
155
-        // the next few months
156
-        $table_name = 'esp_currency_payment_method';
157
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
151
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
+		// note: although this table is no longer in use,
153
+		// it hasn't been removed because then queries to the model will have errors.
154
+		// but you should expect this table and its corresponding model to be removed in
155
+		// the next few months
156
+		$table_name = 'esp_currency_payment_method';
157
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
158 158
 				CUR_code varchar(6) NOT NULL,
159 159
 				PMD_ID int(11) NOT NULL,
160 160
 				PRIMARY KEY  (CPM_ID),
161 161
 				KEY PMD_ID (PMD_ID)";
162
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
-        $table_name = 'esp_datetime';
164
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
162
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
163
+		$table_name = 'esp_datetime';
164
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
165 165
 				EVT_ID bigint(20) unsigned NOT NULL,
166 166
 				DTT_name varchar(255) NOT NULL DEFAULT '',
167 167
 				DTT_description text NOT NULL,
@@ -178,25 +178,25 @@  discard block
 block discarded – undo
178 178
 				KEY DTT_EVT_start (DTT_EVT_start),
179 179
 				KEY EVT_ID (EVT_ID),
180 180
 				KEY DTT_is_primary (DTT_is_primary)";
181
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
-        $table_name = "esp_datetime_ticket";
183
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
181
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
182
+		$table_name = "esp_datetime_ticket";
183
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
184 184
 				DTT_ID int(10) unsigned NOT NULL,
185 185
 				TKT_ID int(10) unsigned NOT NULL,
186 186
 				PRIMARY KEY  (DTK_ID),
187 187
 				KEY DTT_ID (DTT_ID),
188 188
 				KEY TKT_ID (TKT_ID)";
189
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
-        $table_name = 'esp_event_message_template';
191
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
189
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
190
+		$table_name = 'esp_event_message_template';
191
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
192 192
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
193 193
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
194 194
 				PRIMARY KEY  (EMT_ID),
195 195
 				KEY EVT_ID (EVT_ID),
196 196
 				KEY GRP_ID (GRP_ID)";
197
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
-        $table_name = 'esp_event_meta';
199
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
197
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
198
+		$table_name = 'esp_event_meta';
199
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
200 200
 				EVT_ID bigint(20) unsigned NOT NULL,
201 201
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
202 202
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -211,34 +211,34 @@  discard block
 block discarded – undo
211 211
 				EVT_donations tinyint(1) NULL,
212 212
 				PRIMARY KEY  (EVTM_ID),
213 213
 				KEY EVT_ID (EVT_ID)";
214
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
-        $table_name = 'esp_event_question_group';
216
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
214
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
215
+		$table_name = 'esp_event_question_group';
216
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
217 217
 				EVT_ID bigint(20) unsigned NOT NULL,
218 218
 				QSG_ID int(10) unsigned NOT NULL,
219 219
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
220 220
 				PRIMARY KEY  (EQG_ID),
221 221
 				KEY EVT_ID (EVT_ID),
222 222
 				KEY QSG_ID (QSG_ID)";
223
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
-        $table_name = 'esp_event_venue';
225
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
223
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
224
+		$table_name = 'esp_event_venue';
225
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
226 226
 				EVT_ID bigint(20) unsigned NOT NULL,
227 227
 				VNU_ID bigint(20) unsigned NOT NULL,
228 228
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
229 229
 				PRIMARY KEY  (EVV_ID)";
230
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
-        $table_name = 'esp_extra_meta';
232
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
230
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
231
+		$table_name = 'esp_extra_meta';
232
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
233 233
 				OBJ_ID int(11) DEFAULT NULL,
234 234
 				EXM_type varchar(45) DEFAULT NULL,
235 235
 				EXM_key varchar(45) DEFAULT NULL,
236 236
 				EXM_value text,
237 237
 				PRIMARY KEY  (EXM_ID),
238 238
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
239
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
-        $table_name = 'esp_extra_join';
241
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
239
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
240
+		$table_name = 'esp_extra_join';
241
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
242 242
 				EXJ_first_model_id varchar(6) NOT NULL,
243 243
 				EXJ_first_model_name varchar(20) NOT NULL,
244 244
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 				PRIMARY KEY  (EXJ_ID),
247 247
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
248 248
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
249
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
-        $table_name = 'esp_line_item';
251
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
249
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
250
+		$table_name = 'esp_line_item';
251
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
252 252
 				LIN_code varchar(245) NOT NULL DEFAULT '',
253 253
 				TXN_ID int(11) DEFAULT NULL,
254 254
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 				KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp),
270 270
 				KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type),
271 271
 				KEY obj_id_obj_type (OBJ_ID,OBJ_type)";
272
-        $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID');
273
-        $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code');
274
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
275
-        $table_name = 'esp_log';
276
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
272
+		$this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID');
273
+		$this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code');
274
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
275
+		$table_name = 'esp_log';
276
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
277 277
 				LOG_time datetime DEFAULT NULL,
278 278
 				OBJ_ID varchar(45) DEFAULT NULL,
279 279
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 				KEY LOG_time (LOG_time),
285 285
 				KEY OBJ (OBJ_type,OBJ_ID),
286 286
 				KEY LOG_type (LOG_type)";
287
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
288
-        $table_name = 'esp_message';
289
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
290
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
291
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
292
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
287
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
288
+		$table_name = 'esp_message';
289
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
290
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
291
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
292
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
293 293
 				GRP_ID int(10) unsigned NULL,
294 294
 				MSG_token varchar(255) NULL,
295 295
 				TXN_ID int(10) unsigned NULL,
@@ -321,18 +321,18 @@  discard block
 block discarded – undo
321 321
 				KEY STS_ID (STS_ID),
322 322
 				KEY MSG_created (MSG_created),
323 323
 				KEY MSG_modified (MSG_modified)";
324
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
325
-        $table_name = 'esp_message_template';
326
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
324
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
325
+		$table_name = 'esp_message_template';
326
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
327 327
 				GRP_ID int(10) unsigned NOT NULL,
328 328
 				MTP_context varchar(50) NOT NULL,
329 329
 				MTP_template_field varchar(30) NOT NULL,
330 330
 				MTP_content text NOT NULL,
331 331
 				PRIMARY KEY  (MTP_ID),
332 332
 				KEY GRP_ID (GRP_ID)";
333
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
334
-        $table_name = 'esp_message_template_group';
335
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
333
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
334
+		$table_name = 'esp_message_template_group';
335
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
336 336
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
337 337
 				MTP_name varchar(245) NOT NULL DEFAULT '',
338 338
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
345 345
 				PRIMARY KEY  (GRP_ID),
346 346
 				KEY MTP_user_id (MTP_user_id)";
347
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
348
-        $table_name = 'esp_payment';
349
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
347
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
348
+		$table_name = 'esp_payment';
349
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
350 350
 				TXN_ID int(10) unsigned DEFAULT NULL,
351 351
 				STS_ID varchar(3) DEFAULT NULL,
352 352
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
 				PRIMARY KEY  (PAY_ID),
364 364
 				KEY PAY_timestamp (PAY_timestamp),
365 365
 				KEY TXN_ID (TXN_ID)";
366
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
367
-        $table_name = 'esp_payment_method';
368
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
366
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
367
+		$table_name = 'esp_payment_method';
368
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
369 369
 				PMD_type varchar(124) DEFAULT NULL,
370 370
 				PMD_name varchar(255) DEFAULT NULL,
371 371
 				PMD_desc text,
@@ -381,24 +381,24 @@  discard block
 block discarded – undo
381 381
 				PRIMARY KEY  (PMD_ID),
382 382
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
383 383
 				KEY PMD_type (PMD_type)";
384
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
385
-        $table_name = "esp_ticket_price";
386
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
384
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
385
+		$table_name = "esp_ticket_price";
386
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387 387
 				TKT_ID int(10) unsigned NOT NULL,
388 388
 				PRC_ID int(10) unsigned NOT NULL,
389 389
 				PRIMARY KEY  (TKP_ID),
390 390
 				KEY TKT_ID (TKT_ID),
391 391
 				KEY PRC_ID (PRC_ID)";
392
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
393
-        $table_name = "esp_ticket_template";
394
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
392
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
393
+		$table_name = "esp_ticket_template";
394
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
395 395
 				TTM_name varchar(45) NOT NULL,
396 396
 				TTM_description text,
397 397
 				TTM_file varchar(45),
398 398
 				PRIMARY KEY  (TTM_ID)";
399
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
400
-        $table_name = 'esp_question';
401
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
399
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
400
+		$table_name = 'esp_question';
401
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
402 402
 				QST_display_text text NOT NULL,
403 403
 				QST_admin_label varchar(255) NOT NULL,
404 404
 				QST_system varchar(25) DEFAULT NULL,
@@ -412,18 +412,18 @@  discard block
 block discarded – undo
412 412
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
413 413
 				PRIMARY KEY  (QST_ID),
414 414
 				KEY QST_order (QST_order)';
415
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
416
-        $table_name = 'esp_question_group_question';
417
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
415
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
416
+		$table_name = 'esp_question_group_question';
417
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
418 418
 				QSG_ID int(10) unsigned NOT NULL,
419 419
 				QST_ID int(10) unsigned NOT NULL,
420 420
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
421 421
 				PRIMARY KEY  (QGQ_ID),
422 422
 				KEY QST_ID (QST_ID),
423 423
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
424
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
425
-        $table_name = 'esp_question_option';
426
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
424
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
425
+		$table_name = 'esp_question_option';
426
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
427 427
 				QSO_value varchar(255) NOT NULL,
428 428
 				QSO_desc text NOT NULL,
429 429
 				QST_ID int(10) unsigned NOT NULL,
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 				PRIMARY KEY  (QSO_ID),
434 434
 				KEY QST_ID (QST_ID),
435 435
 				KEY QSO_order (QSO_order)";
436
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
437
-        $table_name = 'esp_registration';
438
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
436
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
437
+		$table_name = 'esp_registration';
438
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
439 439
 				EVT_ID bigint(20) unsigned NOT NULL,
440 440
 				ATT_ID bigint(20) unsigned NOT NULL,
441 441
 				TXN_ID int(10) unsigned NOT NULL,
@@ -459,18 +459,18 @@  discard block
 block discarded – undo
459 459
 				KEY TKT_ID (TKT_ID),
460 460
 				KEY EVT_ID (EVT_ID),
461 461
 				KEY STS_ID (STS_ID)";
462
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
463
-        $table_name = 'esp_registration_payment';
464
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
462
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
463
+		$table_name = 'esp_registration_payment';
464
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
465 465
 					  REG_ID int(10) unsigned NOT NULL,
466 466
 					  PAY_ID int(10) unsigned NULL,
467 467
 					  RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00',
468 468
 					  PRIMARY KEY  (RPY_ID),
469 469
 					  KEY REG_ID (REG_ID),
470 470
 					  KEY PAY_ID (PAY_ID)";
471
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
472
-        $table_name = 'esp_state';
473
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
471
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
472
+		$table_name = 'esp_state';
473
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
474 474
 				CNT_ISO varchar(2) NOT NULL,
475 475
 				STA_abbrev varchar(24) NOT NULL,
476 476
 				STA_name varchar(100) NOT NULL,
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 				PRIMARY KEY  (STA_ID),
479 479
 				KEY STA_abbrev (STA_abbrev),
480 480
 				KEY CNT_ISO (CNT_ISO)";
481
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
482
-        $table_name = 'esp_status';
483
-        $sql = "STS_ID varchar(3) NOT NULL,
481
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
482
+		$table_name = 'esp_status';
483
+		$sql = "STS_ID varchar(3) NOT NULL,
484 484
 				STS_code varchar(45) NOT NULL,
485 485
 				STS_type varchar(45) NOT NULL,
486 486
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
489 489
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
490 490
 				KEY STS_type (STS_type)";
491
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
492
-        $table_name = 'esp_transaction';
493
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
491
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
492
+		$table_name = 'esp_transaction';
493
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
494 494
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
495 495
 				TXN_total decimal(12,3) DEFAULT '0.00',
496 496
 				TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00',
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
 				PRIMARY KEY  (TXN_ID),
503 503
 				KEY TXN_timestamp (TXN_timestamp),
504 504
 				KEY STS_ID (STS_ID)";
505
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
506
-        $table_name = 'esp_venue_meta';
507
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
505
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
506
+		$table_name = 'esp_venue_meta';
507
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
508 508
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
509 509
 			VNU_address varchar(255) DEFAULT NULL,
510 510
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -523,10 +523,10 @@  discard block
 block discarded – undo
523 523
 			KEY VNU_ID (VNU_ID),
524 524
 			KEY STA_ID (STA_ID),
525 525
 			KEY CNT_ISO (CNT_ISO)";
526
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
527
-        // modified tables
528
-        $table_name = "esp_price";
529
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
526
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
527
+		// modified tables
528
+		$table_name = "esp_price";
529
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
530 530
 				PRT_ID tinyint(3) unsigned NOT NULL,
531 531
 				PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00',
532 532
 				PRC_name varchar(245) NOT NULL,
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
 				PRC_parent int(10) unsigned DEFAULT 0,
540 540
 				PRIMARY KEY  (PRC_ID),
541 541
 				KEY PRT_ID (PRT_ID)";
542
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
543
-        $table_name = "esp_price_type";
544
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
542
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
543
+		$table_name = "esp_price_type";
544
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
545 545
 				PRT_name varchar(45) NOT NULL,
546 546
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
547 547
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
551 551
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
552 552
 				PRIMARY KEY  (PRT_ID)";
553
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
554
-        $table_name = "esp_ticket";
555
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
553
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
554
+		$table_name = "esp_ticket";
555
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
556 556
 				TTM_ID int(10) unsigned NOT NULL,
557 557
 				TKT_name varchar(245) NOT NULL DEFAULT '',
558 558
 				TKT_description text NOT NULL,
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
576 576
 				PRIMARY KEY  (TKT_ID),
577 577
 				KEY TKT_start_date (TKT_start_date)";
578
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
579
-        $table_name = 'esp_question_group';
580
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
578
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
579
+		$table_name = 'esp_question_group';
580
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
581 581
 				QSG_name varchar(255) NOT NULL,
582 582
 				QSG_identifier varchar(100) NOT NULL,
583 583
 				QSG_desc text NULL,
@@ -590,145 +590,145 @@  discard block
 block discarded – undo
590 590
 				PRIMARY KEY  (QSG_ID),
591 591
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
592 592
 				KEY QSG_order (QSG_order)';
593
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
594
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
595
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
596
-        // (because many need to convert old string states to foreign keys into the states table)
597
-        $script_4_1_defaults->insert_default_states();
598
-        $script_4_1_defaults->insert_default_countries();
599
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
600
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
601
-        $script_4_5_defaults->insert_default_price_types();
602
-        $script_4_5_defaults->insert_default_prices();
603
-        $script_4_5_defaults->insert_default_tickets();
604
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
605
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
606
-        $script_4_6_defaults->add_default_admin_only_payments();
607
-        $script_4_6_defaults->insert_default_currencies();
608
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
609
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
610
-        $script_4_8_defaults->verify_new_countries();
611
-        $script_4_8_defaults->verify_new_currencies();
612
-        $this->verify_db_collations();
613
-        $this->verify_db_collations_again();
614
-        return true;
615
-    }
593
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
594
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
595
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
596
+		// (because many need to convert old string states to foreign keys into the states table)
597
+		$script_4_1_defaults->insert_default_states();
598
+		$script_4_1_defaults->insert_default_countries();
599
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
600
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
601
+		$script_4_5_defaults->insert_default_price_types();
602
+		$script_4_5_defaults->insert_default_prices();
603
+		$script_4_5_defaults->insert_default_tickets();
604
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
605
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
606
+		$script_4_6_defaults->add_default_admin_only_payments();
607
+		$script_4_6_defaults->insert_default_currencies();
608
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
609
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
610
+		$script_4_8_defaults->verify_new_countries();
611
+		$script_4_8_defaults->verify_new_currencies();
612
+		$this->verify_db_collations();
613
+		$this->verify_db_collations_again();
614
+		return true;
615
+	}
616 616
 
617 617
 
618 618
 
619
-    /**
620
-     * @return boolean
621
-     */
622
-    public function schema_changes_after_migration()
623
-    {
624
-        return true;
625
-    }
619
+	/**
620
+	 * @return boolean
621
+	 */
622
+	public function schema_changes_after_migration()
623
+	{
624
+		return true;
625
+	}
626 626
 
627 627
 
628 628
 
629
-    public function migration_page_hooks()
630
-    {
631
-    }
629
+	public function migration_page_hooks()
630
+	{
631
+	}
632 632
 
633 633
 
634 634
 
635
-    /**
636
-     * Verify all EE4 models' tables use utf8mb4 collation
637
-     *
638
-     * @return void
639
-     */
640
-    public function verify_db_collations()
641
-    {
642
-        global $wpdb;
643
-        // double-check we haven't already done it or that that the DB doesn't support utf8mb4
644
-        if ('utf8mb4' !== $wpdb->charset
645
-            || get_option('ee_verified_db_collations', false)) {
646
-            return;
647
-        }
648
-        // grab tables from each model
649
-        $tables_to_check = array();
650
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
651
-            if (method_exists($model_name, 'instance')) {
652
-                $model_obj = call_user_func(array($model_name, 'instance'));
653
-                if ($model_obj instanceof EEM_Base) {
654
-                    foreach ($model_obj->get_tables() as $table) {
655
-                        if (strpos($table->get_table_name(), 'esp_')
656
-                            && (is_main_site()// for main tables, verify global tables
657
-                                || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up)
658
-                            )
659
-                            && function_exists('maybe_convert_table_to_utf8mb4')
660
-                        ) {
661
-                            $tables_to_check[] = $table->get_table_name();
662
-                        }
663
-                    }
664
-                }
665
-            }
666
-        }
667
-        // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
668
-        // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
669
-        // of hard-coding this
670
-        $addon_tables = array(
671
-            // mailchimp
672
-            'esp_event_mailchimp_list_group',
673
-            'esp_event_question_mailchimp_field',
674
-            // multisite
675
-            'esp_blog_meta',
676
-            // people
677
-            'esp_people_to_post',
678
-            // promotions
679
-            'esp_promotion',
680
-            'esp_promotion_object',
681
-        );
682
-        foreach ($addon_tables as $table_name) {
683
-                $tables_to_check[] = $table_name;
684
-        }
685
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
686
-        // ok and now let's remember this was done (without needing to check the db schemas all over again)
687
-        add_option('ee_verified_db_collations', true, null, 'no');
688
-        // seeing how this ran with the fix from 10435, no need to check again
689
-        add_option('ee_verified_db_collations_again', true, null, 'no');
690
-    }
635
+	/**
636
+	 * Verify all EE4 models' tables use utf8mb4 collation
637
+	 *
638
+	 * @return void
639
+	 */
640
+	public function verify_db_collations()
641
+	{
642
+		global $wpdb;
643
+		// double-check we haven't already done it or that that the DB doesn't support utf8mb4
644
+		if ('utf8mb4' !== $wpdb->charset
645
+			|| get_option('ee_verified_db_collations', false)) {
646
+			return;
647
+		}
648
+		// grab tables from each model
649
+		$tables_to_check = array();
650
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
651
+			if (method_exists($model_name, 'instance')) {
652
+				$model_obj = call_user_func(array($model_name, 'instance'));
653
+				if ($model_obj instanceof EEM_Base) {
654
+					foreach ($model_obj->get_tables() as $table) {
655
+						if (strpos($table->get_table_name(), 'esp_')
656
+							&& (is_main_site()// for main tables, verify global tables
657
+								|| ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up)
658
+							)
659
+							&& function_exists('maybe_convert_table_to_utf8mb4')
660
+						) {
661
+							$tables_to_check[] = $table->get_table_name();
662
+						}
663
+					}
664
+				}
665
+			}
666
+		}
667
+		// and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
668
+		// when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
669
+		// of hard-coding this
670
+		$addon_tables = array(
671
+			// mailchimp
672
+			'esp_event_mailchimp_list_group',
673
+			'esp_event_question_mailchimp_field',
674
+			// multisite
675
+			'esp_blog_meta',
676
+			// people
677
+			'esp_people_to_post',
678
+			// promotions
679
+			'esp_promotion',
680
+			'esp_promotion_object',
681
+		);
682
+		foreach ($addon_tables as $table_name) {
683
+				$tables_to_check[] = $table_name;
684
+		}
685
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
686
+		// ok and now let's remember this was done (without needing to check the db schemas all over again)
687
+		add_option('ee_verified_db_collations', true, null, 'no');
688
+		// seeing how this ran with the fix from 10435, no need to check again
689
+		add_option('ee_verified_db_collations_again', true, null, 'no');
690
+	}
691 691
 
692 692
 
693 693
 
694
-    /**
695
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
696
-     * which meant some DB collations might not have been updated
697
-     * @return void
698
-     */
699
-    public function verify_db_collations_again()
700
-    {
701
-        global $wpdb;
702
-        // double-check we haven't already done this or that the DB doesn't support it
703
-        // compare to how WordPress' upgrade_430() function does this check
704
-        if ('utf8mb4' !== $wpdb->charset
705
-            || get_option('ee_verified_db_collations_again', false)) {
706
-            return;
707
-        }
708
-        $tables_to_check = array(
709
-            'esp_attendee_meta',
710
-            'esp_message'
711
-        );
712
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
713
-        add_option('ee_verified_db_collations_again', true, null, 'no');
714
-    }
694
+	/**
695
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
696
+	 * which meant some DB collations might not have been updated
697
+	 * @return void
698
+	 */
699
+	public function verify_db_collations_again()
700
+	{
701
+		global $wpdb;
702
+		// double-check we haven't already done this or that the DB doesn't support it
703
+		// compare to how WordPress' upgrade_430() function does this check
704
+		if ('utf8mb4' !== $wpdb->charset
705
+			|| get_option('ee_verified_db_collations_again', false)) {
706
+			return;
707
+		}
708
+		$tables_to_check = array(
709
+			'esp_attendee_meta',
710
+			'esp_message'
711
+		);
712
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
713
+		add_option('ee_verified_db_collations_again', true, null, 'no');
714
+	}
715 715
 
716 716
 
717 717
 
718
-    /**
719
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
720
-     * @param $tables_to_check
721
-     * @return boolean true if logic ran, false if it didn't
722
-     */
723
-    protected function _verify_db_collations_for_tables($tables_to_check)
724
-    {
725
-        foreach ($tables_to_check as $table_name) {
726
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
727
-            if (! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
728
-                && $this->_get_table_analysis()->tableExists($table_name)
729
-            ) {
730
-                maybe_convert_table_to_utf8mb4($table_name);
731
-            }
732
-        }
733
-    }
718
+	/**
719
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
720
+	 * @param $tables_to_check
721
+	 * @return boolean true if logic ran, false if it didn't
722
+	 */
723
+	protected function _verify_db_collations_for_tables($tables_to_check)
724
+	{
725
+		foreach ($tables_to_check as $table_name) {
726
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
727
+			if (! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
728
+				&& $this->_get_table_analysis()->tableExists($table_name)
729
+			) {
730
+				maybe_convert_table_to_utf8mb4($table_name);
731
+			}
732
+		}
733
+	}
734 734
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_attendees.dmsstage.php 3 patches
Doc Comments   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
      * that they WILL be added (because the attendees stage runs nearly last during
557 557
      * the migration script)
558 558
      * @param type $new_ticket_id
559
-     * @param type $sold
560
-     * @param type $STS_ID
559
+     * @param string $STS_ID
560
+     * @param integer $quantity_sold
561 561
      * @return boolean whether they were successfully updated or not
562 562
      */
563 563
     protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID)
@@ -757,6 +757,9 @@  discard block
 block discarded – undo
757 757
         return $count;
758 758
     }
759 759
 
760
+    /**
761
+     * @param integer $new_txn_id
762
+     */
760 763
     private function _insert_new_payment($old_attendee, $new_txn_id)
761 764
     {
762 765
         global $wpdb;
Please login to merge, or discard this patch.
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 = __("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 = __("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(__("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(__("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(__('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(__("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(__("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(__('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(__("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(__("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(__("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(__("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 = __("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(__("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(__("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(__('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(__("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.
caffeinated/brewing_regular.php 2 patches
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -27,322 +27,322 @@
 block discarded – undo
27 27
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
28 28
 {
29 29
 
30
-    /**
31
-     * @var TableAnalysis $table_analysis
32
-     */
33
-    protected $_table_analysis;
34
-
35
-
36
-    /**
37
-     * EE_Brewing_Regular constructor.
38
-     *
39
-     * @param TableAnalysis $table_analysis
40
-     */
41
-    public function __construct(TableAnalysis $table_analysis)
42
-    {
43
-        $this->_table_analysis = $table_analysis;
44
-        if (defined('EE_CAFF_PATH')) {
45
-            $this->setInitializationHooks();
46
-            $this->setApiRegistrationHooks();
47
-            $this->setSwitchHooks();
48
-            $this->setDefaultFilterHooks();
49
-            // caffeinated constructed
50
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
51
-        }
52
-    }
53
-
54
-
55
-    /**
56
-     * Various hooks used for extending features via registration of modules or extensions.
57
-     */
58
-    private function setApiRegistrationHooks()
59
-    {
60
-        add_filter(
61
-            'FHEE__EE_Config__register_modules__modules_to_register',
62
-            array($this, 'caffeinated_modules_to_register')
63
-        );
64
-        add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
65
-        add_filter(
66
-            'AHEE__EE_System__load_core_configuration__complete',
67
-            function () {
68
-                EE_Register_Payment_Method::register(
69
-                    'caffeinated_payment_methods',
70
-                    array(
71
-                        'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR),
72
-                    )
73
-                );
74
-            }
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * Various hooks used for modifying initialization or activation processes.
81
-     */
82
-    private function setInitializationHooks()
83
-    {
84
-        // activation
85
-        add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
86
-        // load caff init
87
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
88
-        // load caff scripts
89
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
90
-    }
91
-
92
-
93
-    /**
94
-     * Various hooks used for switch (on/off) type filters.
95
-     */
96
-    private function setSwitchHooks()
97
-    {
98
-        // remove the "powered by" credit link from receipts and invoices
99
-        add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
100
-        // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
101
-        add_filter('FHEE__ee_show_affiliate_links', '__return_false');
102
-    }
103
-
104
-
105
-    /**
106
-     * Various filters for affecting default configuration values in the caffeinated
107
-     * context.
108
-     */
109
-    private function setDefaultFilterHooks()
110
-    {
111
-        add_filter(
112
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
113
-            '__return_true'
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
120
-     *
121
-     * @param array $paths original helper paths array
122
-     * @return array             new array of paths
123
-     */
124
-    public function caf_helper_paths($paths)
125
-    {
126
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
127
-        return $paths;
128
-    }
129
-
130
-
131
-    /**
132
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
133
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
134
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
135
-     * This action should only be called when EE 4.x.0.P is initially activated.
136
-     * Right now the only CAF content are these global prices. If there's more in the future, then
137
-     * we should probably create a caf file to contain it all instead just a function like this.
138
-     * Right now, we ASSUME the only price types in the system are default ones
139
-     *
140
-     * @global wpdb $wpdb
141
-     */
142
-    public function initialize_caf_db_content()
143
-    {
144
-        global $wpdb;
145
-        // use same method of getting creator id as the version introducing the change
146
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
147
-        $price_type_table = $wpdb->prefix . "esp_price_type";
148
-        $price_table = $wpdb->prefix . "esp_price";
149
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
150
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types
151
-            $tax_price_type_count = $wpdb->get_var($SQL);
152
-            if ($tax_price_type_count <= 1) {
153
-                $wpdb->insert(
154
-                    $price_type_table,
155
-                    array(
156
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
157
-                        'PBT_ID'         => 4,
158
-                        'PRT_is_percent' => true,
159
-                        'PRT_order'      => 60,
160
-                        'PRT_deleted'    => false,
161
-                        'PRT_wp_user'    => $default_creator_id,
162
-                    ),
163
-                    array(
164
-                        '%s',// PRT_name
165
-                        '%d',// PBT_id
166
-                        '%d',// PRT_is_percent
167
-                        '%d',// PRT_order
168
-                        '%d',// PRT_deleted
169
-                        '%d', // PRT_wp_user
170
-                    )
171
-                );
172
-                // federal tax
173
-                $result = $wpdb->insert(
174
-                    $price_type_table,
175
-                    array(
176
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
177
-                        'PBT_ID'         => 4,
178
-                        'PRT_is_percent' => true,
179
-                        'PRT_order'      => 70,
180
-                        'PRT_deleted'    => false,
181
-                        'PRT_wp_user'    => $default_creator_id,
182
-                    ),
183
-                    array(
184
-                        '%s',// PRT_name
185
-                        '%d',// PBT_id
186
-                        '%d',// PRT_is_percent
187
-                        '%d',// PRT_order
188
-                        '%d',// PRT_deleted
189
-                        '%d' // PRT_wp_user
190
-                    )
191
-                );
192
-                if ($result) {
193
-                    $wpdb->insert(
194
-                        $price_table,
195
-                        array(
196
-                            'PRT_ID'         => $wpdb->insert_id,
197
-                            'PRC_amount'     => 15.00,
198
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
199
-                            'PRC_desc'       => '',
200
-                            'PRC_is_default' => true,
201
-                            'PRC_overrides'  => null,
202
-                            'PRC_deleted'    => false,
203
-                            'PRC_order'      => 50,
204
-                            'PRC_parent'     => null,
205
-                            'PRC_wp_user'    => $default_creator_id,
206
-                        ),
207
-                        array(
208
-                            '%d',// PRT_id
209
-                            '%f',// PRC_amount
210
-                            '%s',// PRC_name
211
-                            '%s',// PRC_desc
212
-                            '%d',// PRC_is_default
213
-                            '%d',// PRC_overrides
214
-                            '%d',// PRC_deleted
215
-                            '%d',// PRC_order
216
-                            '%d',// PRC_parent
217
-                            '%d' // PRC_wp_user
218
-                        )
219
-                    );
220
-                }
221
-            }
222
-        }
223
-    }
224
-
225
-
226
-    /**
227
-     *    caffeinated_modules_to_register
228
-     *
229
-     * @access public
230
-     * @param array $modules_to_register
231
-     * @return array
232
-     */
233
-    public function caffeinated_modules_to_register($modules_to_register = array())
234
-    {
235
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
236
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
237
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
238
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
239
-            }
240
-        }
241
-        return $modules_to_register;
242
-    }
243
-
244
-
245
-    /**
246
-     * @throws EE_Error
247
-     * @throws InvalidArgumentException
248
-     * @throws ReflectionException
249
-     * @throws InvalidDataTypeException
250
-     * @throws InvalidInterfaceException
251
-     */
252
-    public function caffeinated_init()
253
-    {
254
-        // Custom Post Type hooks
255
-        add_filter(
256
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
257
-            array($this, 'filter_taxonomies')
258
-        );
259
-        add_filter(
260
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
261
-            array($this, 'filter_cpts')
262
-        );
263
-        add_filter(
264
-            'FHEE__EE_Admin__get_extra_nav_menu_pages_items',
265
-            array($this, 'nav_metabox_items')
266
-        );
267
-        EE_Registry::instance()->load_file(
268
-            EE_CAFF_PATH,
269
-            'EE_Caf_Messages',
270
-            'class',
271
-            array(),
272
-            false
273
-        );
274
-        // caffeinated_init__complete hook
275
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
276
-    }
277
-
278
-
279
-    public function enqueue_caffeinated_scripts()
280
-    {
281
-        // sound of crickets...
282
-    }
283
-
284
-
285
-    /**
286
-     * callbacks below here
287
-     *
288
-     * @param array $taxonomy_array
289
-     * @return array
290
-     */
291
-    public function filter_taxonomies(array $taxonomy_array)
292
-    {
293
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
294
-        return $taxonomy_array;
295
-    }
296
-
297
-
298
-    /**
299
-     * @param array $cpt_array
300
-     * @return mixed
301
-     */
302
-    public function filter_cpts(array $cpt_array)
303
-    {
304
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
305
-        return $cpt_array;
306
-    }
307
-
308
-
309
-    /**
310
-     * @param array $menuitems
311
-     * @return array
312
-     */
313
-    public function nav_metabox_items(array $menuitems)
314
-    {
315
-        $menuitems[] = array(
316
-            'title'       => __('Venue List', 'event_espresso'),
317
-            'url'         => get_post_type_archive_link('espresso_venues'),
318
-            'description' => __('Archive page for all venues.', 'event_espresso'),
319
-        );
320
-        return $menuitems;
321
-    }
322
-
323
-
324
-    /**
325
-     * Gets the injected table analyzer, or throws an exception
326
-     *
327
-     * @return TableAnalysis
328
-     * @throws \EE_Error
329
-     */
330
-    protected function _get_table_analysis()
331
-    {
332
-        if ($this->_table_analysis instanceof TableAnalysis) {
333
-            return $this->_table_analysis;
334
-        } else {
335
-            throw new \EE_Error(
336
-                sprintf(
337
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
338
-                    get_class($this)
339
-                )
340
-            );
341
-        }
342
-    }
30
+	/**
31
+	 * @var TableAnalysis $table_analysis
32
+	 */
33
+	protected $_table_analysis;
34
+
35
+
36
+	/**
37
+	 * EE_Brewing_Regular constructor.
38
+	 *
39
+	 * @param TableAnalysis $table_analysis
40
+	 */
41
+	public function __construct(TableAnalysis $table_analysis)
42
+	{
43
+		$this->_table_analysis = $table_analysis;
44
+		if (defined('EE_CAFF_PATH')) {
45
+			$this->setInitializationHooks();
46
+			$this->setApiRegistrationHooks();
47
+			$this->setSwitchHooks();
48
+			$this->setDefaultFilterHooks();
49
+			// caffeinated constructed
50
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
51
+		}
52
+	}
53
+
54
+
55
+	/**
56
+	 * Various hooks used for extending features via registration of modules or extensions.
57
+	 */
58
+	private function setApiRegistrationHooks()
59
+	{
60
+		add_filter(
61
+			'FHEE__EE_Config__register_modules__modules_to_register',
62
+			array($this, 'caffeinated_modules_to_register')
63
+		);
64
+		add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
65
+		add_filter(
66
+			'AHEE__EE_System__load_core_configuration__complete',
67
+			function () {
68
+				EE_Register_Payment_Method::register(
69
+					'caffeinated_payment_methods',
70
+					array(
71
+						'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR),
72
+					)
73
+				);
74
+			}
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Various hooks used for modifying initialization or activation processes.
81
+	 */
82
+	private function setInitializationHooks()
83
+	{
84
+		// activation
85
+		add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
86
+		// load caff init
87
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
88
+		// load caff scripts
89
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Various hooks used for switch (on/off) type filters.
95
+	 */
96
+	private function setSwitchHooks()
97
+	{
98
+		// remove the "powered by" credit link from receipts and invoices
99
+		add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
100
+		// seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
101
+		add_filter('FHEE__ee_show_affiliate_links', '__return_false');
102
+	}
103
+
104
+
105
+	/**
106
+	 * Various filters for affecting default configuration values in the caffeinated
107
+	 * context.
108
+	 */
109
+	private function setDefaultFilterHooks()
110
+	{
111
+		add_filter(
112
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
113
+			'__return_true'
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
120
+	 *
121
+	 * @param array $paths original helper paths array
122
+	 * @return array             new array of paths
123
+	 */
124
+	public function caf_helper_paths($paths)
125
+	{
126
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
127
+		return $paths;
128
+	}
129
+
130
+
131
+	/**
132
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
133
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
134
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
135
+	 * This action should only be called when EE 4.x.0.P is initially activated.
136
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
137
+	 * we should probably create a caf file to contain it all instead just a function like this.
138
+	 * Right now, we ASSUME the only price types in the system are default ones
139
+	 *
140
+	 * @global wpdb $wpdb
141
+	 */
142
+	public function initialize_caf_db_content()
143
+	{
144
+		global $wpdb;
145
+		// use same method of getting creator id as the version introducing the change
146
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
147
+		$price_type_table = $wpdb->prefix . "esp_price_type";
148
+		$price_table = $wpdb->prefix . "esp_price";
149
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
150
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types
151
+			$tax_price_type_count = $wpdb->get_var($SQL);
152
+			if ($tax_price_type_count <= 1) {
153
+				$wpdb->insert(
154
+					$price_type_table,
155
+					array(
156
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
157
+						'PBT_ID'         => 4,
158
+						'PRT_is_percent' => true,
159
+						'PRT_order'      => 60,
160
+						'PRT_deleted'    => false,
161
+						'PRT_wp_user'    => $default_creator_id,
162
+					),
163
+					array(
164
+						'%s',// PRT_name
165
+						'%d',// PBT_id
166
+						'%d',// PRT_is_percent
167
+						'%d',// PRT_order
168
+						'%d',// PRT_deleted
169
+						'%d', // PRT_wp_user
170
+					)
171
+				);
172
+				// federal tax
173
+				$result = $wpdb->insert(
174
+					$price_type_table,
175
+					array(
176
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
177
+						'PBT_ID'         => 4,
178
+						'PRT_is_percent' => true,
179
+						'PRT_order'      => 70,
180
+						'PRT_deleted'    => false,
181
+						'PRT_wp_user'    => $default_creator_id,
182
+					),
183
+					array(
184
+						'%s',// PRT_name
185
+						'%d',// PBT_id
186
+						'%d',// PRT_is_percent
187
+						'%d',// PRT_order
188
+						'%d',// PRT_deleted
189
+						'%d' // PRT_wp_user
190
+					)
191
+				);
192
+				if ($result) {
193
+					$wpdb->insert(
194
+						$price_table,
195
+						array(
196
+							'PRT_ID'         => $wpdb->insert_id,
197
+							'PRC_amount'     => 15.00,
198
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
199
+							'PRC_desc'       => '',
200
+							'PRC_is_default' => true,
201
+							'PRC_overrides'  => null,
202
+							'PRC_deleted'    => false,
203
+							'PRC_order'      => 50,
204
+							'PRC_parent'     => null,
205
+							'PRC_wp_user'    => $default_creator_id,
206
+						),
207
+						array(
208
+							'%d',// PRT_id
209
+							'%f',// PRC_amount
210
+							'%s',// PRC_name
211
+							'%s',// PRC_desc
212
+							'%d',// PRC_is_default
213
+							'%d',// PRC_overrides
214
+							'%d',// PRC_deleted
215
+							'%d',// PRC_order
216
+							'%d',// PRC_parent
217
+							'%d' // PRC_wp_user
218
+						)
219
+					);
220
+				}
221
+			}
222
+		}
223
+	}
224
+
225
+
226
+	/**
227
+	 *    caffeinated_modules_to_register
228
+	 *
229
+	 * @access public
230
+	 * @param array $modules_to_register
231
+	 * @return array
232
+	 */
233
+	public function caffeinated_modules_to_register($modules_to_register = array())
234
+	{
235
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
236
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
237
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
238
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
239
+			}
240
+		}
241
+		return $modules_to_register;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @throws EE_Error
247
+	 * @throws InvalidArgumentException
248
+	 * @throws ReflectionException
249
+	 * @throws InvalidDataTypeException
250
+	 * @throws InvalidInterfaceException
251
+	 */
252
+	public function caffeinated_init()
253
+	{
254
+		// Custom Post Type hooks
255
+		add_filter(
256
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
257
+			array($this, 'filter_taxonomies')
258
+		);
259
+		add_filter(
260
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
261
+			array($this, 'filter_cpts')
262
+		);
263
+		add_filter(
264
+			'FHEE__EE_Admin__get_extra_nav_menu_pages_items',
265
+			array($this, 'nav_metabox_items')
266
+		);
267
+		EE_Registry::instance()->load_file(
268
+			EE_CAFF_PATH,
269
+			'EE_Caf_Messages',
270
+			'class',
271
+			array(),
272
+			false
273
+		);
274
+		// caffeinated_init__complete hook
275
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
276
+	}
277
+
278
+
279
+	public function enqueue_caffeinated_scripts()
280
+	{
281
+		// sound of crickets...
282
+	}
283
+
284
+
285
+	/**
286
+	 * callbacks below here
287
+	 *
288
+	 * @param array $taxonomy_array
289
+	 * @return array
290
+	 */
291
+	public function filter_taxonomies(array $taxonomy_array)
292
+	{
293
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
294
+		return $taxonomy_array;
295
+	}
296
+
297
+
298
+	/**
299
+	 * @param array $cpt_array
300
+	 * @return mixed
301
+	 */
302
+	public function filter_cpts(array $cpt_array)
303
+	{
304
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
305
+		return $cpt_array;
306
+	}
307
+
308
+
309
+	/**
310
+	 * @param array $menuitems
311
+	 * @return array
312
+	 */
313
+	public function nav_metabox_items(array $menuitems)
314
+	{
315
+		$menuitems[] = array(
316
+			'title'       => __('Venue List', 'event_espresso'),
317
+			'url'         => get_post_type_archive_link('espresso_venues'),
318
+			'description' => __('Archive page for all venues.', 'event_espresso'),
319
+		);
320
+		return $menuitems;
321
+	}
322
+
323
+
324
+	/**
325
+	 * Gets the injected table analyzer, or throws an exception
326
+	 *
327
+	 * @return TableAnalysis
328
+	 * @throws \EE_Error
329
+	 */
330
+	protected function _get_table_analysis()
331
+	{
332
+		if ($this->_table_analysis instanceof TableAnalysis) {
333
+			return $this->_table_analysis;
334
+		} else {
335
+			throw new \EE_Error(
336
+				sprintf(
337
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
338
+					get_class($this)
339
+				)
340
+			);
341
+		}
342
+	}
343 343
 }
344 344
 
345 345
 
346 346
 $brewing = new EE_Brewing_Regular(
347
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
347
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
348 348
 );
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@  discard block
 block discarded – undo
11 11
  * define and use the hook in a specific caffeinated/whatever class or file.
12 12
  */
13 13
 // defined some new constants related to caffeinated folder
14
-define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/');
15
-define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS);
16
-define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS);
17
-define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS);
14
+define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/');
15
+define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS);
16
+define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS);
17
+define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS);
18 18
 
19 19
 
20 20
 /**
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
         add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
65 65
         add_filter(
66 66
             'AHEE__EE_System__load_core_configuration__complete',
67
-            function () {
67
+            function() {
68 68
                 EE_Register_Payment_Method::register(
69 69
                     'caffeinated_payment_methods',
70 70
                     array(
71
-                        'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR),
71
+                        'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR),
72 72
                     )
73 73
                 );
74 74
             }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      */
124 124
     public function caf_helper_paths($paths)
125 125
     {
126
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
126
+        $paths[] = EE_CAF_CORE.'helpers'.DS;
127 127
         return $paths;
128 128
     }
129 129
 
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
         global $wpdb;
145 145
         // use same method of getting creator id as the version introducing the change
146 146
         $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
147
-        $price_type_table = $wpdb->prefix . "esp_price_type";
148
-        $price_table = $wpdb->prefix . "esp_price";
147
+        $price_type_table = $wpdb->prefix."esp_price_type";
148
+        $price_table = $wpdb->prefix."esp_price";
149 149
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
150
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types
150
+            $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; // include trashed price types
151 151
             $tax_price_type_count = $wpdb->get_var($SQL);
152 152
             if ($tax_price_type_count <= 1) {
153 153
                 $wpdb->insert(
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
                         'PRT_wp_user'    => $default_creator_id,
162 162
                     ),
163 163
                     array(
164
-                        '%s',// PRT_name
165
-                        '%d',// PBT_id
166
-                        '%d',// PRT_is_percent
167
-                        '%d',// PRT_order
168
-                        '%d',// PRT_deleted
164
+                        '%s', // PRT_name
165
+                        '%d', // PBT_id
166
+                        '%d', // PRT_is_percent
167
+                        '%d', // PRT_order
168
+                        '%d', // PRT_deleted
169 169
                         '%d', // PRT_wp_user
170 170
                     )
171 171
                 );
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
                         'PRT_wp_user'    => $default_creator_id,
182 182
                     ),
183 183
                     array(
184
-                        '%s',// PRT_name
185
-                        '%d',// PBT_id
186
-                        '%d',// PRT_is_percent
187
-                        '%d',// PRT_order
188
-                        '%d',// PRT_deleted
184
+                        '%s', // PRT_name
185
+                        '%d', // PBT_id
186
+                        '%d', // PRT_is_percent
187
+                        '%d', // PRT_order
188
+                        '%d', // PRT_deleted
189 189
                         '%d' // PRT_wp_user
190 190
                     )
191 191
                 );
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
                             'PRC_wp_user'    => $default_creator_id,
206 206
                         ),
207 207
                         array(
208
-                            '%d',// PRT_id
209
-                            '%f',// PRC_amount
210
-                            '%s',// PRC_name
211
-                            '%s',// PRC_desc
212
-                            '%d',// PRC_is_default
213
-                            '%d',// PRC_overrides
214
-                            '%d',// PRC_deleted
215
-                            '%d',// PRC_order
216
-                            '%d',// PRC_parent
208
+                            '%d', // PRT_id
209
+                            '%f', // PRC_amount
210
+                            '%s', // PRC_name
211
+                            '%s', // PRC_desc
212
+                            '%d', // PRC_is_default
213
+                            '%d', // PRC_overrides
214
+                            '%d', // PRC_deleted
215
+                            '%d', // PRC_order
216
+                            '%d', // PRC_parent
217 217
                             '%d' // PRC_wp_user
218 218
                         )
219 219
                     );
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
      */
233 233
     public function caffeinated_modules_to_register($modules_to_register = array())
234 234
     {
235
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
236
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
235
+        if (is_readable(EE_CAFF_PATH.'modules')) {
236
+            $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR);
237 237
             if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
238 238
                 $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
239 239
             }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_gateways.dmsstage.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -14,68 +14,68 @@  discard block
 block discarded – undo
14 14
 class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage
15 15
 {
16 16
 
17
-    private $_converted_active_gateways = false;
17
+	private $_converted_active_gateways = false;
18 18
 
19
-    public function _migration_step($num_items = 50)
20
-    {
21
-        // loads existing EE_CONfig from DB, if it exists
22
-        $new_gateway_config_obj = EE_Config::instance()->gateway;
23
-        $items_actually_migrated = 0;
24
-        // convert settings
25
-        $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
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;
28
-        foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
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 ])) {
31
-                // determine the old option's name
32
-                $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
33
-                if (! $old_gateway_settings) {
34
-                    // no settings existed for this gateway anyways... weird...
35
-                    $items_actually_migrated++;
36
-                    continue;
37
-                }
38
-                // now prepare the settings to make sure they're in the 4.1 format
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;
41
-                // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
42
-                // I think it's ok to do right away this time (we wont need gateway settings elsewhere)
43
-                delete_option($old_gateway_wp_option_name);
44
-            } else {// it must be one of the ones we mostly leave alone
45
-                global $wpdb;
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
-                // 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));
49
-            }
19
+	public function _migration_step($num_items = 50)
20
+	{
21
+		// loads existing EE_CONfig from DB, if it exists
22
+		$new_gateway_config_obj = EE_Config::instance()->gateway;
23
+		$items_actually_migrated = 0;
24
+		// convert settings
25
+		$gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
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;
28
+		foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
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 ])) {
31
+				// determine the old option's name
32
+				$old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
33
+				if (! $old_gateway_settings) {
34
+					// no settings existed for this gateway anyways... weird...
35
+					$items_actually_migrated++;
36
+					continue;
37
+				}
38
+				// now prepare the settings to make sure they're in the 4.1 format
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;
41
+				// and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
42
+				// I think it's ok to do right away this time (we wont need gateway settings elsewhere)
43
+				delete_option($old_gateway_wp_option_name);
44
+			} else {// it must be one of the ones we mostly leave alone
45
+				global $wpdb;
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
+				// 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));
49
+			}
50 50
         
51
-            $items_actually_migrated++;
52
-        }
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) {
55
-            $this->_convert_active_gateways();
56
-            $this->_converted_active_gateways = true;
57
-            $items_actually_migrated++;
58
-        }
51
+			$items_actually_migrated++;
52
+		}
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) {
55
+			$this->_convert_active_gateways();
56
+			$this->_converted_active_gateways = true;
57
+			$items_actually_migrated++;
58
+		}
59 59
     
60
-        EE_Config::instance()->update_espresso_config(false, false);
61
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
62
-            $this->set_completed();
63
-        }
64
-        return $items_actually_migrated;
65
-    }
66
-    public function _count_records_to_migrate()
67
-    {
68
-        $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate);
69
-        $step_of_setting_active_gateways = 1;
70
-        $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
71
-    //  $button_images_to_update =
72
-        return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
73
-    }
74
-    public function __construct()
75
-    {
76
-        $this->_pretty_name = __("Gateways", "event_espresso");
77
-        parent::__construct();
78
-    }
60
+		EE_Config::instance()->update_espresso_config(false, false);
61
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
62
+			$this->set_completed();
63
+		}
64
+		return $items_actually_migrated;
65
+	}
66
+	public function _count_records_to_migrate()
67
+	{
68
+		$count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate);
69
+		$step_of_setting_active_gateways = 1;
70
+		$count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
71
+	//  $button_images_to_update =
72
+		return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
73
+	}
74
+	public function __construct()
75
+	{
76
+		$this->_pretty_name = __("Gateways", "event_espresso");
77
+		parent::__construct();
78
+	}
79 79
 
80 80
 /**
81 81
  * Takes the old array of 3.1 gateway settings for this gateway and converts it
@@ -85,148 +85,148 @@  discard block
 block discarded – undo
85 85
  * @param string $new_gateway_slug
86 86
  * @return array
87 87
  */
88
-    private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug)
89
-    {
90
-        $new_gateway_settings = $old_gateway_settings;
91
-        switch ($new_gateway_slug) {
92
-            case 'Bank':
93
-                $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account'];
94
-                $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title'];
95
-                break;
96
-            case 'Invoice':
97
-                $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url'];
98
-                // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4
99
-                // it gets used in the receipts which are available to everyone. So usually it's best to not
100
-                // migrate this.
101
-                unset($new_gateway_settings['payment_address']);
102
-                break;
103
-            case 'Paypal_Pro':
104
-                $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email'];
105
-                $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username'];
106
-                $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password'];
107
-                $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature'];
108
-                $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']);
109
-                $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox'];
110
-                break;
111
-        }
112
-        return $new_gateway_settings;
113
-    }
88
+	private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug)
89
+	{
90
+		$new_gateway_settings = $old_gateway_settings;
91
+		switch ($new_gateway_slug) {
92
+			case 'Bank':
93
+				$new_gateway_settings['account_number'] = $old_gateway_settings['bank_account'];
94
+				$new_gateway_settings['page_title'] = $old_gateway_settings['bank_title'];
95
+				break;
96
+			case 'Invoice':
97
+				$new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url'];
98
+				// Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4
99
+				// it gets used in the receipts which are available to everyone. So usually it's best to not
100
+				// migrate this.
101
+				unset($new_gateway_settings['payment_address']);
102
+				break;
103
+			case 'Paypal_Pro':
104
+				$new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email'];
105
+				$new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username'];
106
+				$new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password'];
107
+				$new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature'];
108
+				$new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']);
109
+				$new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox'];
110
+				break;
111
+		}
112
+		return $new_gateway_settings;
113
+	}
114 114
 /**
115
- * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway
116
- * @param string $new_gateway_slug
117
- * @return string
118
- */
119
-    private function _get_old_gateway_option($new_gateway_slug)
120
-    {
121
-        $option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
122
-        $settings =  get_option($option_name, null);
123
-    //  if( ! $settings){
124
-    //      $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
125
-    //  }
126
-        return $settings;
127
-    }
115
+	 * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway
116
+	 * @param string $new_gateway_slug
117
+	 * @return string
118
+	 */
119
+	private function _get_old_gateway_option($new_gateway_slug)
120
+	{
121
+		$option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
122
+		$settings =  get_option($option_name, null);
123
+	//  if( ! $settings){
124
+	//      $this->add_error(sprintf(__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
125
+	//  }
126
+		return $settings;
127
+	}
128 128
 
129 129
 /**
130 130
  * Just gets the old gateways slug
131 131
  * @param string $new_gateway_slug
132 132
  * @return string
133 133
  */
134
-    private function _get_old_gateway_option_name($new_gateway_slug)
135
-    {
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 ];
138
-        $normal_option_prefix = 'event_espresso_';
139
-        $normal_option_postfix = '_settings';
140
-        switch ($new_gateway_slug) {
141
-            case 'Bank':
142
-                $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix;
143
-                break;
144
-            case 'Aim':
145
-                $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix;
146
-                break;
147
-            case 'Check':
148
-                $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix;
149
-                break;
150
-            case 'Ideal':
151
-                $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix;
152
-                break;
153
-            case 'Invoice':
154
-                $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix;
155
-                break;
156
-            case 'Purchase_Order':
157
-                $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix;
158
-                break;
159
-            case 'USAePay_Offsite':
160
-                $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix;
161
-                break;
162
-            case 'USAePay_Onsite':
163
-                $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix;
164
-                break;
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);
167
-        }
168
-        return $option_name;
169
-    }
134
+	private function _get_old_gateway_option_name($new_gateway_slug)
135
+	{
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 ];
138
+		$normal_option_prefix = 'event_espresso_';
139
+		$normal_option_postfix = '_settings';
140
+		switch ($new_gateway_slug) {
141
+			case 'Bank':
142
+				$option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix;
143
+				break;
144
+			case 'Aim':
145
+				$option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix;
146
+				break;
147
+			case 'Check':
148
+				$option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix;
149
+				break;
150
+			case 'Ideal':
151
+				$option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix;
152
+				break;
153
+			case 'Invoice':
154
+				$option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix;
155
+				break;
156
+			case 'Purchase_Order':
157
+				$option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix;
158
+				break;
159
+			case 'USAePay_Offsite':
160
+				$option_name = 'espresso_usaepay_offsite'.$normal_option_postfix;
161
+				break;
162
+			case 'USAePay_Onsite':
163
+				$option_name = 'espresso_usaepay_onsite'.$normal_option_postfix;
164
+				break;
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);
167
+		}
168
+		return $option_name;
169
+	}
170 170
 
171
-    private function _convert_active_gateways()
172
-    {
173
-        // just does it all one big swoop
174
-        $old_active_gateways = get_option('event_espresso_active_gateways');
175
-        $new_active_gateways = EE_Config::instance()->gateway->active_gateways;
176
-        foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
177
-            if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
178
-                $this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
179
-                continue;
180
-            }
181
-            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
171
+	private function _convert_active_gateways()
172
+	{
173
+		// just does it all one big swoop
174
+		$old_active_gateways = get_option('event_espresso_active_gateways');
175
+		$new_active_gateways = EE_Config::instance()->gateway->active_gateways;
176
+		foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
177
+			if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
178
+				$this->add_error(sprintf(__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
179
+				continue;
180
+			}
181
+			$new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
182 182
         
183
-            // in the new format we can also upload gateways to the uploads directory and
184
-            $new_active_gateways[ $new_gateway_slug ] = false;
185
-        }
186
-        EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
187
-    }
183
+			// in the new format we can also upload gateways to the uploads directory and
184
+			$new_active_gateways[ $new_gateway_slug ] = false;
185
+		}
186
+		EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
187
+	}
188 188
     
189
-    protected $_gateways_we_know_how_to_migrate = array(
190
-        'aim'=>'Aim',
191
-        'bank'=>'Bank',
192
-        'check'=>'Check',
193
-        'invoice'=>'Invoice',
194
-        'paypal'=>'Paypal_Standard',
195
-        'paypal_pro'=>'Paypal_Pro',
189
+	protected $_gateways_we_know_how_to_migrate = array(
190
+		'aim'=>'Aim',
191
+		'bank'=>'Bank',
192
+		'check'=>'Check',
193
+		'invoice'=>'Invoice',
194
+		'paypal'=>'Paypal_Standard',
195
+		'paypal_pro'=>'Paypal_Pro',
196 196
 
197
-    );
197
+	);
198 198
     
199
-    protected $_gateways_we_leave_alone = array(
200
-        '2checkout'=>'2checkout',
201
-        'anz'=>'Anz',
202
-        'atos'=>'Atos',
203
-        'authnet'=>'Authnet',
204
-        'beanstream'=>'Beanstream',
205
-        'evertec'=>'Evertec',
206
-        'eway'=>'Eway',
207
-        'eway_rapid3'=>'Eway_Rapid3',
208
-        'exact'=>'Exact',
209
-        'firstdata'=>'Firstdata',
210
-        'firstdat_e4'=>'Firstdata_E4',
211
-        'ideal'=>'Ideal',
212
-        'infusion_payment'=>'InfusionSoft',
213
-        'luottokunta'=>'Luottokunta',
214
-        'megasoft'=>'Megasoft',
215
-        'moneris_hpp'=>'Moneris_HPP',
216
-        'mwarrior'=>'Mwarrior',
217
-        'nab'=>'NAB',
218
-        'paychoice'=>'Paychoice',
219
-        'paytrace'=>'Paytrace',
220
-        'psigate'=>'Psigate',
221
-        'purchase_order'=>'Purchase_Order',
222
-        'qbms'=>'QBMS',
223
-        'quickpay'=>'Quickpay',
224
-        'realauth'=>'Realauth',
225
-        'securepay_aus'=>'Securepay_Aus',
226
-        'stripe'=>'Stripe',
227
-        'usaepay_offsite'=>'USAePay_Offsite',
228
-        'usaepay_onsite'=>'USAePay_Onsite',
229
-        'wepay'=>'Wepay',
230
-        'worldpay'=>'Worldpay'
231
-    );
199
+	protected $_gateways_we_leave_alone = array(
200
+		'2checkout'=>'2checkout',
201
+		'anz'=>'Anz',
202
+		'atos'=>'Atos',
203
+		'authnet'=>'Authnet',
204
+		'beanstream'=>'Beanstream',
205
+		'evertec'=>'Evertec',
206
+		'eway'=>'Eway',
207
+		'eway_rapid3'=>'Eway_Rapid3',
208
+		'exact'=>'Exact',
209
+		'firstdata'=>'Firstdata',
210
+		'firstdat_e4'=>'Firstdata_E4',
211
+		'ideal'=>'Ideal',
212
+		'infusion_payment'=>'InfusionSoft',
213
+		'luottokunta'=>'Luottokunta',
214
+		'megasoft'=>'Megasoft',
215
+		'moneris_hpp'=>'Moneris_HPP',
216
+		'mwarrior'=>'Mwarrior',
217
+		'nab'=>'NAB',
218
+		'paychoice'=>'Paychoice',
219
+		'paytrace'=>'Paytrace',
220
+		'psigate'=>'Psigate',
221
+		'purchase_order'=>'Purchase_Order',
222
+		'qbms'=>'QBMS',
223
+		'quickpay'=>'Quickpay',
224
+		'realauth'=>'Realauth',
225
+		'securepay_aus'=>'Securepay_Aus',
226
+		'stripe'=>'Stripe',
227
+		'usaepay_offsite'=>'USAePay_Offsite',
228
+		'usaepay_onsite'=>'USAePay_Onsite',
229
+		'wepay'=>'Wepay',
230
+		'worldpay'=>'Worldpay'
231
+	);
232 232
 }
Please login to merge, or discard this patch.
core/EE_Data_Migration_Manager.core.php 2 patches
Indentation   +1234 added lines, -1234 removed lines patch added patch discarded remove patch
@@ -32,1238 +32,1238 @@
 block discarded – undo
32 32
 class EE_Data_Migration_Manager implements ResettableInterface
33 33
 {
34 34
 
35
-    /**
36
-     *
37
-     * @var EE_Registry
38
-     */
39
-    // protected $EE;
40
-    /**
41
-     * name of the wordpress option which stores an array of data about
42
-     */
43
-    const data_migrations_option_name = 'ee_data_migration';
44
-
45
-
46
-    const data_migration_script_option_prefix = 'ee_data_migration_script_';
47
-
48
-    const data_migration_script_mapping_option_prefix = 'ee_dms_map_';
49
-
50
-    /**
51
-     * name of the wordpress option which stores the database' current version. IE, the code may be at version 4.2.0,
52
-     * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc.
53
-     */
54
-    const current_database_state = 'ee_data_migration_current_db_state';
55
-
56
-    /**
57
-     * Special status string returned when we're positive there are no more data migration
58
-     * scripts that can be run.
59
-     */
60
-    const status_no_more_migration_scripts = 'no_more_migration_scripts';
61
-    /**
62
-     * string indicating the migration should continue
63
-     */
64
-    const status_continue = 'status_continue';
65
-    /**
66
-     * string indicating the migration has completed and should be ended
67
-     */
68
-    const status_completed = 'status_completed';
69
-    /**
70
-     * string indicating a fatal error occurred and the data migration should be completely aborted
71
-     */
72
-    const status_fatal_error = 'status_fatal_error';
73
-
74
-    /**
75
-     * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent
76
-     * during migration)
77
-     */
78
-    const step_size = 50;
79
-
80
-    /**
81
-     * option name that stores the queue of ee plugins needing to have
82
-     * their data initialized (or re-initialized) once we are done migrations
83
-     */
84
-    const db_init_queue_option_name = 'ee_db_init_queue';
85
-    /**
86
-     * Array of information concerning data migrations that have ran in the history
87
-     * of this EE installation. Keys should be the name of the version the script upgraded to
88
-     *
89
-     * @var EE_Data_Migration_Script_Base[]
90
-     */
91
-    private $_data_migrations_ran = null;
92
-    /**
93
-     * The last ran script. It's nice to store this somewhere accessible, as its easiest
94
-     * to know which was the last run by which is the newest wp option; but in most of the code
95
-     * we just use the local $_data_migration_ran array, which organized the scripts differently
96
-     *
97
-     * @var EE_Data_Migration_Script_Base
98
-     */
99
-    private $_last_ran_script = null;
100
-
101
-    /**
102
-     * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script.
103
-     *
104
-     * @var EE_Data_Migration_Script_Base
105
-     */
106
-    private $_last_ran_incomplete_script = null;
107
-    /**
108
-     * array where keys are classnames, and values are filepaths of all the known migration scripts
109
-     *
110
-     * @var array
111
-     */
112
-    private $_data_migration_class_to_filepath_map;
113
-
114
-    /**
115
-     * the following 4 properties are fully set on construction.
116
-     * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished
117
-     * one, we may want to start the next one); whereas the last two indicate whether to continue running a single
118
-     * data migration script
119
-     *
120
-     * @var array
121
-     */
122
-    public $stati_that_indicate_to_continue_migrations = array();
123
-
124
-    public $stati_that_indicate_to_stop_migrations = array();
125
-
126
-    public $stati_that_indicate_to_continue_single_migration_script = array();
127
-
128
-    public $stati_that_indicate_to_stop_single_migration_script = array();
129
-
130
-    /**
131
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
132
-     */
133
-    protected $_table_manager;
134
-
135
-    /**
136
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
137
-     */
138
-    protected $_table_analysis;
139
-
140
-    /**
141
-     * @var array $script_migration_versions
142
-     */
143
-    protected $script_migration_versions;
144
-
145
-    /**
146
-     * @var EE_Data_Migration_Manager $_instance
147
-     * @access    private
148
-     */
149
-    private static $_instance = null;
150
-
151
-
152
-    /**
153
-     * @singleton method used to instantiate class object
154
-     * @access    public
155
-     * @return EE_Data_Migration_Manager instance
156
-     */
157
-    public static function instance()
158
-    {
159
-        // check if class object is instantiated
160
-        if (! self::$_instance instanceof EE_Data_Migration_Manager) {
161
-            self::$_instance = new self();
162
-        }
163
-        return self::$_instance;
164
-    }
165
-
166
-    /**
167
-     * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning,
168
-     * all new usages of the singleton should be made with Classname::instance()) and returns it
169
-     *
170
-     * @return EE_Data_Migration_Manager
171
-     */
172
-    public static function reset()
173
-    {
174
-        self::$_instance = null;
175
-        return self::instance();
176
-    }
177
-
178
-
179
-    /**
180
-     * constructor
181
-     */
182
-    private function __construct()
183
-    {
184
-        $this->stati_that_indicate_to_continue_migrations = array(
185
-            self::status_continue,
186
-            self::status_completed,
187
-        );
188
-        $this->stati_that_indicate_to_stop_migrations = array(
189
-            self::status_fatal_error,
190
-            self::status_no_more_migration_scripts,
191
-        );
192
-        $this->stati_that_indicate_to_continue_single_migration_script = array(
193
-            self::status_continue,
194
-        );
195
-        $this->stati_that_indicate_to_stop_single_migration_script = array(
196
-            self::status_completed,
197
-            self::status_fatal_error
198
-            // note: status_no_more_migration_scripts doesn't apply
199
-        );
200
-        // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class
201
-        // to be defined, because right now it doesn't get autoloaded on its own
202
-        EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), true);
203
-        EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), true);
204
-        EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), true);
205
-        EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), true);
206
-        EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), true);
207
-        $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true);
208
-        $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
209
-    }
210
-
211
-
212
-    /**
213
-     * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what
214
-     * the option names are like, but generally they're like
215
-     * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that).
216
-     * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived,
217
-     * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php (eg
218
-     * EE_DMS_Core_4_1_0.dms.php)
219
-     *
220
-     * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set)
221
-     * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of
222
-     *               that plugin (eg '4.1.0')
223
-     */
224
-    private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name)
225
-    {
226
-        $plugin_slug_and_version_string = str_replace(
227
-            EE_Data_Migration_Manager::data_migration_script_option_prefix,
228
-            "",
229
-            $option_name
230
-        );
231
-        // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style)
232
-        $parts = explode(".", $plugin_slug_and_version_string);
233
-
234
-        if (count($parts) == 4) {
235
-            // it's 4.2-style.eg Core.4.1.0
236
-            $plugin_slug = $parts[0];// eg Core
237
-            $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0
238
-        } else {
239
-            // it's 4.1-style: eg 4.1.0
240
-            $plugin_slug = 'Core';
241
-            $version_string = $plugin_slug_and_version_string;// eg 4.1.0
242
-        }
243
-        return array($plugin_slug, $version_string);
244
-    }
245
-
246
-    /**
247
-     * Gets the DMS class from the wordpress option, otherwise throws an EE_Error if it's not
248
-     * for a known DMS class.
249
-     *
250
-     * @param string $dms_option_name
251
-     * @param string $dms_option_value (serialized)
252
-     * @return EE_Data_Migration_Script_Base
253
-     * @throws EE_Error
254
-     */
255
-    private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value)
256
-    {
257
-        $data_migration_data = maybe_unserialize($dms_option_value);
258
-        if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) {
259
-            $class = new $data_migration_data['class'];
260
-            if ($class instanceof EE_Data_Migration_Script_Base) {
261
-                $class->instantiate_from_array_of_properties($data_migration_data);
262
-                return $class;
263
-            } else {
264
-                // huh, so its an object but not a data migration script?? that shouldn't happen
265
-                // just leave it as an array (which will probably just get ignored)
266
-                throw new EE_Error(
267
-                    sprintf(
268
-                        __(
269
-                            "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists",
270
-                            'event_espresso'
271
-                        ),
272
-                        $data_migration_data['class']
273
-                    )
274
-                );
275
-            }
276
-        } else {
277
-            // so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists
278
-            throw new EE_Error(
279
-                sprintf(__("The wp option  with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)
280
-            );
281
-        }
282
-    }
283
-
284
-    /**
285
-     * Gets the array describing what data migrations have run. Also has a side-effect of recording which was the last
286
-     * ran, and which was the last ran which hasn't finished yet
287
-     *
288
-     * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy
289
-     *               arrays in there - which should probably be ignored)
290
-     */
291
-    public function get_data_migrations_ran()
292
-    {
293
-        if (! $this->_data_migrations_ran) {
294
-            // setup autoloaders for each of the scripts in there
295
-            $this->get_all_data_migration_scripts_available();
296
-            $data_migrations_options = $this->get_all_migration_script_options(
297
-            );// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array()));
298
-
299
-            $data_migrations_ran = array();
300
-            // convert into data migration script classes where possible
301
-            foreach ($data_migrations_options as $data_migration_option) {
302
-                list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name(
303
-                    $data_migration_option['option_name']
304
-                );
305
-
306
-                try {
307
-                    $class = $this->_get_dms_class_from_wp_option(
308
-                        $data_migration_option['option_name'],
309
-                        $data_migration_option['option_value']
310
-                    );
311
-                    $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class;
312
-                    // ok so far THIS is the 'last-ran-script'... unless we find another on next iteration
313
-                    $this->_last_ran_script = $class;
314
-                    if (! $class->is_completed()) {
315
-                        // sometimes we also like to know which was the last incomplete script (or if there are any at all)
316
-                        $this->_last_ran_incomplete_script = $class;
317
-                    }
318
-                } catch (EE_Error $e) {
319
-                    // ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs
320
-                    $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize(
321
-                        $data_migration_option['option_value']
322
-                    );
323
-                }
324
-            }
325
-            // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays
326
-            $this->_data_migrations_ran = $data_migrations_ran;
327
-            if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) {
328
-                $this->_data_migrations_ran = array();
329
-            }
330
-        }
331
-        return $this->_data_migrations_ran;
332
-    }
333
-
334
-
335
-    /**
336
-     *
337
-     * @param string $script_name eg 'DMS_Core_4_1_0'
338
-     * @param string $old_table   eg 'wp_events_detail'
339
-     * @param string $old_pk      eg 'wp_esp_posts'
340
-     * @param        $new_table
341
-     * @return mixed string or int
342
-     */
343
-    public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table)
344
-    {
345
-        $script = EE_Registry::instance()->load_dms($script_name);
346
-        $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table);
347
-        return $mapping;
348
-    }
349
-
350
-    /**
351
-     * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that
352
-     * the last option returned in this array is the most-recently ran DMS option
353
-     *
354
-     * @return array
355
-     */
356
-    public function get_all_migration_script_options()
357
-    {
358
-        global $wpdb;
359
-        return $wpdb->get_results(
360
-            "SELECT * FROM {$wpdb->options} WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id ASC",
361
-            ARRAY_A
362
-        );
363
-    }
364
-
365
-    /**
366
-     * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded
367
-     *
368
-     * @return array where each value is the full folder path of a folder containing data migration scripts, WITH
369
-     *               slashes at the end of the folder name.
370
-     */
371
-    public function get_data_migration_script_folders()
372
-    {
373
-        return apply_filters(
374
-            'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',
375
-            array('Core' => EE_CORE . 'data_migration_scripts')
376
-        );
377
-    }
378
-
379
-    /**
380
-     * Gets the version the migration script upgrades to
381
-     *
382
-     * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0'
383
-     * @return array {
384
-     * @type string  $slug                  like 'Core','Calendar',etc
385
-     * @type string  $version               like 4.3.0
386
-     *                                      }
387
-     * @throws EE_Error
388
-     */
389
-    public function script_migrates_to_version($migration_script_name, $eeAddonClass = '')
390
-    {
391
-        if (isset($this->script_migration_versions[ $migration_script_name ])) {
392
-            return $this->script_migration_versions[ $migration_script_name ];
393
-        }
394
-        $dms_info = $this->parse_dms_classname($migration_script_name);
395
-        $this->script_migration_versions[ $migration_script_name ] = array(
396
-            'slug'    => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'],
397
-            'version' => $dms_info['major_version'] . "." . $dms_info['minor_version'] . "." . $dms_info['micro_version'],
398
-        );
399
-        return $this->script_migration_versions[ $migration_script_name ];
400
-    }
401
-
402
-    /**
403
-     * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0'
404
-     *
405
-     * @param string $classname
406
-     * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints)
407
-     * @throws EE_Error
408
-     */
409
-    public function parse_dms_classname($classname)
410
-    {
411
-        $matches = array();
412
-        preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches);
413
-        if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) {
414
-            throw new EE_Error(
415
-                sprintf(
416
-                    __(
417
-                        "%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ",
418
-                        "event_espresso"
419
-                    ),
420
-                    $classname
421
-                )
422
-            );
423
-        }
424
-        return array(
425
-            'slug'          => $matches[1],
426
-            'major_version' => intval($matches[2]),
427
-            'minor_version' => intval($matches[3]),
428
-            'micro_version' => intval($matches[4]),
429
-        );
430
-    }
431
-
432
-    /**
433
-     * Ensures that the option indicating the current DB version is set. This should only be
434
-     * a concern when activating EE for the first time, THEORETICALLY.
435
-     * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise
436
-     * to 4.1.x.
437
-     *
438
-     * @return string of current db state
439
-     */
440
-    public function ensure_current_database_state_is_set()
441
-    {
442
-        $espresso_db_core_updates = get_option('espresso_db_update', array());
443
-        $db_state = get_option(EE_Data_Migration_Manager::current_database_state);
444
-        if (! $db_state) {
445
-            // mark the DB as being in the state as the last version in there.
446
-            // this is done to trigger maintenance mode and do data migration scripts
447
-            // if the admin installed this version of EE over 3.1.x or 4.0.x
448
-            // otherwise, the normal maintenance mode code is fine
449
-            $previous_versions_installed = array_keys($espresso_db_core_updates);
450
-            $previous_version_installed = end($previous_versions_installed);
451
-            if (version_compare('4.1.0', $previous_version_installed)) {
452
-                // last installed version was less than 4.1
453
-                // so we want the data migrations to happen. SO, we're going to say the DB is at that state
454
-                $db_state = array('Core' => $previous_version_installed);
455
-            } else {
456
-                $db_state = array('Core' => EVENT_ESPRESSO_VERSION);
457
-            }
458
-            update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
459
-        }
460
-        // in 4.1, $db_state would have only been a simple string like '4.1.0',
461
-        // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's
462
-        // db, and possibly other keys for other addons like 'Calendar','Permissions',etc
463
-        if (! is_array($db_state)) {
464
-            $db_state = array('Core' => $db_state);
465
-            update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
466
-        }
467
-        return $db_state;
468
-    }
469
-
470
-    /**
471
-     * Checks if there are any data migration scripts that ought to be run. If found,
472
-     * returns the instantiated classes. If none are found (ie, they've all already been run
473
-     * or they don't apply), returns an empty array
474
-     *
475
-     * @return EE_Data_Migration_Script_Base[]
476
-     */
477
-    public function check_for_applicable_data_migration_scripts()
478
-    {
479
-        // get the option describing what options have already run
480
-        $scripts_ran = $this->get_data_migrations_ran();
481
-        // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null));
482
-        $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available();
483
-
484
-
485
-        $current_database_state = $this->ensure_current_database_state_is_set();
486
-        // determine which have already been run
487
-        $script_classes_that_should_run_per_iteration = array();
488
-        $iteration = 0;
489
-        $next_database_state_to_consider = $current_database_state;
490
-        $theoretical_database_state = null;
491
-        do {
492
-            // the next state after the currently-considered one will start off looking the same as the current, but we may make additions...
493
-            $theoretical_database_state = $next_database_state_to_consider;
494
-            // the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?)
495
-            foreach ($script_class_and_filepaths_available as $classname => $filepath) {
496
-                $migrates_to_version = $this->script_migrates_to_version($classname);
497
-                $script_converts_plugin_slug = $migrates_to_version['slug'];
498
-                $script_converts_to_version = $migrates_to_version['version'];
499
-                // check if this version script is DONE or not; or if it's never been ran
500
-                if (! $scripts_ran ||
501
-                    ! isset($scripts_ran[ $script_converts_plugin_slug ]) ||
502
-                    ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ])) {
503
-                    // we haven't ran this conversion script before
504
-                    // now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available
505
-                    $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis());
506
-                    /* @var $script EE_Data_Migration_Script_Base */
507
-                    $can_migrate = $script->can_migrate_from_version($theoretical_database_state);
508
-                    if ($can_migrate) {
509
-                        $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script;
510
-                        $migrates_to_version = $script->migrates_to_version();
511
-                        $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version'];
512
-                        unset($script_class_and_filepaths_available[ $classname ]);
513
-                    }
514
-                } elseif ($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] instanceof EE_Data_Migration_Script_Base) {
515
-                    // this script has been ran, or at least started
516
-                    $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ];
517
-                    if ($script->get_status() != self::status_completed) {
518
-                        // this script is already underway... keep going with it
519
-                        $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script;
520
-                        $migrates_to_version = $script->migrates_to_version();
521
-                        $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version'];
522
-                        unset($script_class_and_filepaths_available[ $classname ]);
523
-                    } else {
524
-                        // it must have a status that indicates it has finished, so we don't want to try and run it again
525
-                    }
526
-                } else {
527
-                    // it exists but it's not  a proper data migration script
528
-                    // maybe the script got renamed? or was simply removed from EE?
529
-                    // either way, its certainly not runnable!
530
-                }
531
-            }
532
-            $iteration++;
533
-        } while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6);
534
-        // ok we have all the scripts that should run, now let's make them into flat array
535
-        $scripts_that_should_run = array();
536
-        foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) {
537
-            ksort($scripts_at_priority);
538
-            foreach ($scripts_at_priority as $scripts) {
539
-                foreach ($scripts as $script) {
540
-                    $scripts_that_should_run[ get_class($script) ] = $script;
541
-                }
542
-            }
543
-        }
544
-
545
-        do_action(
546
-            'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run',
547
-            $scripts_that_should_run
548
-        );
549
-        return $scripts_that_should_run;
550
-    }
551
-
552
-
553
-    /**
554
-     * Gets the script which is currently being ran, if there is one. If $include_completed_scripts is set to TRUE
555
-     * it will return the last ran script even if its complete.
556
-     * This means: if you want to find the currently-executing script, leave it as FALSE.
557
-     * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE.
558
-     *
559
-     * @param bool $include_completed_scripts
560
-     * @return EE_Data_Migration_Script_Base
561
-     */
562
-    public function get_last_ran_script($include_completed_scripts = false)
563
-    {
564
-        // make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script
565
-        if (! $this->_data_migrations_ran) {
566
-            $this->get_data_migrations_ran();
567
-        }
568
-        if ($include_completed_scripts) {
569
-            return $this->_last_ran_script;
570
-        } else {
571
-            return $this->_last_ran_incomplete_script;
572
-        }
573
-    }
574
-
575
-
576
-    /**
577
-     * Runs the data migration scripts (well, each request to this method calls one of the
578
-     * data migration scripts' migration_step() functions).
579
-     *
580
-     * @param int   $step_size
581
-     * @throws EE_Error
582
-     * @return array {
583
-     *                                  // where the first item is one EE_Data_Migration_Script_Base's stati,
584
-     *                                  //and the second item is a string describing what was done
585
-     * @type int    $records_to_migrate from the current migration script
586
-     * @type int    $records_migrated
587
-     * @type string $status             one of EE_Data_Migration_Manager::status_*
588
-     * @type string $script             verbose name of the current DMS
589
-     * @type string $message            string describing what was done during this step
590
-     *                                  }
591
-     */
592
-    public function migration_step($step_size = 0)
593
-    {
594
-
595
-        // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535
596
-        if (class_exists('EE_CPT_Strategy')) {
597
-            remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5);
598
-        }
599
-
600
-        try {
601
-            $currently_executing_script = $this->get_last_ran_script();
602
-            if (! $currently_executing_script) {
603
-                // Find the next script that needs to execute
604
-                $scripts = $this->check_for_applicable_data_migration_scripts();
605
-                if (! $scripts) {
606
-                    // huh, no more scripts to run... apparently we're done!
607
-                    // but dont forget to make sure initial data is there
608
-                    // we should be good to allow them to exit maintenance mode now
609
-                    EE_Maintenance_Mode::instance()->set_maintenance_level(
610
-                        intval(EE_Maintenance_Mode::level_0_not_in_maintenance)
611
-                    );
612
-                    // saving migrations ran should actually be unnecessary, but leaving in place just in case
613
-                    // remember this migration was finished (even if we timeout initing db for core and plugins)
614
-                    $this->_save_migrations_ran();
615
-                    // make sure DB was updated AFTER we've recorded the migration was done
616
-                    $this->initialize_db_for_enqueued_ee_plugins();
617
-                    return array(
618
-                        'records_to_migrate' => 1,
619
-                        'records_migrated'   => 1,
620
-                        'status'             => self::status_no_more_migration_scripts,
621
-                        'script'             => __("Data Migration Completed Successfully", "event_espresso"),
622
-                        'message'            => __("All done!", "event_espresso"),
623
-                    );
624
-                }
625
-                $currently_executing_script = array_shift($scripts);
626
-                // and add to the array/wp option showing the scripts ran
627
-
628
-                $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script));
629
-                $plugin_slug = $migrates_to['slug'];
630
-                $version = $migrates_to['version'];
631
-                $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script;
632
-            }
633
-            $current_script_name = get_class($currently_executing_script);
634
-        } catch (Exception $e) {
635
-            // an exception occurred while trying to get migration scripts
636
-
637
-            $message = sprintf(
638
-                __("Error Message: %sStack Trace:%s", "event_espresso"),
639
-                $e->getMessage() . '<br>',
640
-                $e->getTraceAsString()
641
-            );
642
-            // record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations
643
-            // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations
644
-            $this->add_error_to_migrations_ran(
645
-                sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)
646
-            );
647
-            return array(
648
-                'records_to_migrate' => 1,
649
-                'records_migrated'   => 0,
650
-                'status'             => self::status_fatal_error,
651
-                'script'             => __("Error loading data migration scripts", "event_espresso"),
652
-                'message'            => $message,
653
-            );
654
-        }
655
-        // ok so we definitely have a data migration script
656
-        try {
657
-            // how big of a bite do we want to take? Allow users to easily override via their wp-config
658
-            if (absint($step_size) < 1) {
659
-                $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE)
660
-                    ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size;
661
-            }
662
-            // do what we came to do!
663
-            $currently_executing_script->migration_step($step_size);
664
-            // can we wrap it up and verify default data?
665
-            $init_dbs = false;
666
-            switch ($currently_executing_script->get_status()) {
667
-                case EE_Data_Migration_Manager::status_continue:
668
-                    $response_array = array(
669
-                        'records_to_migrate' => $currently_executing_script->count_records_to_migrate(),
670
-                        'records_migrated'   => $currently_executing_script->count_records_migrated(),
671
-                        'status'             => EE_Data_Migration_Manager::status_continue,
672
-                        'message'            => $currently_executing_script->get_feedback_message(),
673
-                        'script'             => $currently_executing_script->pretty_name(),
674
-                    );
675
-                    break;
676
-                case EE_Data_Migration_Manager::status_completed:
677
-                    // ok so THAT script has completed
678
-                    $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name));
679
-                    $response_array = array(
680
-                        'records_to_migrate' => $currently_executing_script->count_records_to_migrate(),
681
-                        'records_migrated'   => $currently_executing_script->count_records_migrated(),
682
-                        'status'             => EE_Data_Migration_Manager::status_completed,
683
-                        'message'            => $currently_executing_script->get_feedback_message(),
684
-                        'script'             => sprintf(
685
-                            __("%s Completed", 'event_espresso'),
686
-                            $currently_executing_script->pretty_name()
687
-                        ),
688
-                    );
689
-                    // check if there are any more after this one.
690
-                    $scripts_remaining = $this->check_for_applicable_data_migration_scripts();
691
-                    if (! $scripts_remaining) {
692
-                        // we should be good to allow them to exit maintenance mode now
693
-                        EE_Maintenance_Mode::instance()->set_maintenance_level(
694
-                            intval(EE_Maintenance_Mode::level_0_not_in_maintenance)
695
-                        );
696
-                        // huh, no more scripts to run... apparently we're done!
697
-                        // but dont forget to make sure initial data is there
698
-                        $init_dbs = true;
699
-                        $response_array['status'] = self::status_no_more_migration_scripts;
700
-                    }
701
-                    break;
702
-                default:
703
-                    $response_array = array(
704
-                        'records_to_migrate' => $currently_executing_script->count_records_to_migrate(),
705
-                        'records_migrated'   => $currently_executing_script->count_records_migrated(),
706
-                        'status'             => $currently_executing_script->get_status(),
707
-                        'message'            => sprintf(
708
-                            __("Minor errors occurred during %s: %s", "event_espresso"),
709
-                            $currently_executing_script->pretty_name(),
710
-                            implode(", ", $currently_executing_script->get_errors())
711
-                        ),
712
-                        'script'             => $currently_executing_script->pretty_name(),
713
-                    );
714
-                    break;
715
-            }
716
-        } catch (Exception $e) {
717
-            // ok so some exception was thrown which killed the data migration script
718
-            // double-check we have a real script
719
-            if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) {
720
-                $script_name = $currently_executing_script->pretty_name();
721
-                $currently_executing_script->set_broken();
722
-                $currently_executing_script->add_error($e->getMessage());
723
-            } else {
724
-                $script_name = __("Error getting Migration Script", "event_espresso");
725
-            }
726
-            $response_array = array(
727
-                'records_to_migrate' => 1,
728
-                'records_migrated'   => 0,
729
-                'status'             => self::status_fatal_error,
730
-                'message'            => sprintf(
731
-                    __("A fatal error occurred during the migration: %s", "event_espresso"),
732
-                    $e->getMessage()
733
-                ),
734
-                'script'             => $script_name,
735
-            );
736
-        }
737
-        $successful_save = $this->_save_migrations_ran();
738
-        if ($successful_save !== true) {
739
-            // ok so the current wp option didn't save. that's tricky, because we'd like to update it
740
-            // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION!
741
-            // however, if we throw an exception, and return that, then the next request
742
-            // won't have as much info in it, and it may be able to save
743
-            throw new EE_Error(
744
-                sprintf(
745
-                    __(
746
-                        "The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.",
747
-                        "event_espresso"
748
-                    ),
749
-                    $successful_save
750
-                )
751
-            );
752
-        }
753
-        // if we're all done, initialize EE plugins' default data etc.
754
-        if ($init_dbs) {
755
-            $this->initialize_db_for_enqueued_ee_plugins();
756
-        }
757
-        return $response_array;
758
-    }
759
-
760
-
761
-    /**
762
-     * Echo out JSON response to migration script AJAX requests. Takes precautions
763
-     * to buffer output so that we don't throw junk into our json.
764
-     *
765
-     * @return array with keys:
766
-     * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie,
767
-     * it's NOT the count of hwo many remain)
768
-     * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete =
769
-     * records_migrated/records_to_migrate)
770
-     * 'status'=>a string, one of EE_Data_migration_Manager::status_*
771
-     * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into
772
-     * errors, notifications, and successes
773
-     * 'script'=>a pretty name of the script currently running
774
-     */
775
-    public function response_to_migration_ajax_request()
776
-    {
777
-        ob_start();
778
-        try {
779
-            $response = $this->migration_step();
780
-        } catch (Exception $e) {
781
-            $response = array(
782
-                'records_to_migrate' => 0,
783
-                'records_migrated'   => 0,
784
-                'status'             => EE_Data_Migration_Manager::status_fatal_error,
785
-                'message'            => sprintf(
786
-                    __("Unknown fatal error occurred: %s", "event_espresso"),
787
-                    $e->getMessage()
788
-                ),
789
-                'script'             => 'Unknown',
790
-            );
791
-            $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString());
792
-        }
793
-        $warnings_etc = @ob_get_contents();
794
-        ob_end_clean();
795
-        $response['message'] .= $warnings_etc;
796
-        return $response;
797
-    }
798
-
799
-    /**
800
-     * Updates the wordpress option that keeps track of which which EE version the database
801
-     * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35)
802
-     *
803
-     * @param array $slug_and_version {
804
-     * @type string $slug             like 'Core' or 'Calendar',
805
-     * @type string $version          like '4.1.0'
806
-     *                                }
807
-     * @return void
808
-     */
809
-    public function update_current_database_state_to($slug_and_version = null)
810
-    {
811
-        if (! $slug_and_version) {
812
-            // no version was provided, assume it should be at the current code version
813
-            $slug_and_version = array('slug' => 'Core', 'version' => espresso_version());
814
-        }
815
-        $current_database_state = get_option(self::current_database_state);
816
-        $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version'];
817
-        update_option(self::current_database_state, $current_database_state);
818
-    }
819
-
820
-    /**
821
-     * Determines if the database is currently at a state matching what's indicated in $slug and $version.
822
-     *
823
-     * @param array $slug_and_version {
824
-     * @type string $slug             like 'Core' or 'Calendar',
825
-     * @type string $version          like '4.1.0'
826
-     *                                }
827
-     * @return boolean
828
-     */
829
-    public function database_needs_updating_to($slug_and_version)
830
-    {
831
-
832
-        $slug = $slug_and_version['slug'];
833
-        $version = $slug_and_version['version'];
834
-        $current_database_state = get_option(self::current_database_state);
835
-        if (! isset($current_database_state[ $slug ])) {
836
-            return true;
837
-        } else {
838
-            // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes
839
-            $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3);
840
-            $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3);
841
-            $needs_updating = false;
842
-            foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) {
843
-                if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) {
844
-                    $needs_updating = true;
845
-                    break;
846
-                }
847
-            }
848
-            return $needs_updating;
849
-        }
850
-    }
851
-
852
-
853
-    /**
854
-     * Gets all the data migration scripts available in the core folder and folders
855
-     * in addons. Has the side effect of adding them for autoloading
856
-     *
857
-     * @return array keys are expected classnames, values are their filepaths
858
-     * @throws InvalidInterfaceException
859
-     * @throws InvalidDataTypeException
860
-     * @throws EE_Error
861
-     * @throws InvalidArgumentException
862
-     */
863
-    public function get_all_data_migration_scripts_available()
864
-    {
865
-        if (! $this->_data_migration_class_to_filepath_map) {
866
-            $this->_data_migration_class_to_filepath_map = array();
867
-            foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) {
868
-                // strip any placeholders added to classname to make it a unique array key
869
-                $eeAddonClass = trim($eeAddonClass, '*');
870
-                $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass)
871
-                    ? $eeAddonClass
872
-                    : '';
873
-                $folder_path = EEH_File::end_with_directory_separator($folder_path);
874
-                $files = glob($folder_path . '*.dms.php');
875
-                if (empty($files)) {
876
-                    continue;
877
-                }
878
-                foreach ($files as $file) {
879
-                    $pos_of_last_slash = strrpos($file, DS);
880
-                    $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1));
881
-                    $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass);
882
-                    $slug = $migrates_to['slug'];
883
-                    // check that the slug as contained in the DMS is associated with
884
-                    // the slug of an addon or core
885
-                    if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) {
886
-                        EE_Error::doing_it_wrong(
887
-                            __FUNCTION__,
888
-                            sprintf(
889
-                                esc_html__(
890
-                                    'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ',
891
-                                    'event_espresso'
892
-                                ),
893
-                                $classname,
894
-                                $slug,
895
-                                implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name()))
896
-                            ),
897
-                            '4.3.0.alpha.019'
898
-                        );
899
-                    }
900
-                    $this->_data_migration_class_to_filepath_map[ $classname ] = $file;
901
-                }
902
-            }
903
-            EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map);
904
-        }
905
-        return $this->_data_migration_class_to_filepath_map;
906
-    }
907
-
908
-
909
-    /**
910
-     * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs
911
-     * from each addon, and check if they need updating,
912
-     *
913
-     * @return boolean
914
-     */
915
-    public function addons_need_updating()
916
-    {
917
-        return false;
918
-    }
919
-
920
-    /**
921
-     * Adds this error string to the data_migrations_ran array, but we dont necessarily know
922
-     * where to put it, so we just throw it in there... better than nothing...
923
-     *
924
-     * @param string $error_message
925
-     * @throws EE_Error
926
-     */
927
-    public function add_error_to_migrations_ran($error_message)
928
-    {
929
-        // get last-ran migration script
930
-        global $wpdb;
931
-        $last_migration_script_option = $wpdb->get_row(
932
-            "SELECT * FROM $wpdb->options WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id DESC LIMIT 1",
933
-            ARRAY_A
934
-        );
935
-
936
-        $last_ran_migration_script_properties = isset($last_migration_script_option['option_value'])
937
-            ? maybe_unserialize($last_migration_script_option['option_value']) : null;
938
-        // now, tread lightly because we're here because a FATAL non-catchable error
939
-        // was thrown last time when we were trying to run a data migration script
940
-        // so the fatal error could have happened while getting the migration script
941
-        // or doing running it...
942
-        $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(
943
-            EE_Data_Migration_Manager::data_migration_script_option_prefix,
944
-            "",
945
-            $last_migration_script_option['option_name']
946
-        ) : null;
947
-
948
-        // check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet
949
-        // because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done)
950
-        if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) {
951
-            // ok then just add this error to its list of errors
952
-            $last_ran_migration_script_properties['_errors'][] = $error_message;
953
-            $last_ran_migration_script_properties['_status'] = self::status_fatal_error;
954
-        } else {
955
-            // so we don't even know which script was last running
956
-            // use the data migration error stub, which is designed specifically for this type of thing
957
-            $general_migration_error = new EE_DMS_Unknown_1_0_0();
958
-            $general_migration_error->add_error($error_message);
959
-            $general_migration_error->set_broken();
960
-            $last_ran_migration_script_properties = $general_migration_error->properties_as_array();
961
-            $versions_migrated_to = 'Unknown.1.0.0';
962
-            // now just to make sure appears as last (in case the were previously a fatal error like this)
963
-            // delete the old one
964
-            delete_option(self::data_migration_script_option_prefix . $versions_migrated_to);
965
-        }
966
-        update_option(
967
-            self::data_migration_script_option_prefix . $versions_migrated_to,
968
-            $last_ran_migration_script_properties
969
-        );
970
-    }
971
-
972
-    /**
973
-     * saves what data migrations have ran to the database
974
-     *
975
-     * @return mixed TRUE if successfully saved migrations ran, string if an error occurred
976
-     */
977
-    protected function _save_migrations_ran()
978
-    {
979
-        if ($this->_data_migrations_ran == null) {
980
-            $this->get_data_migrations_ran();
981
-        }
982
-        // now, we don't want to save actual classes to the DB because that's messy
983
-        $successful_updates = true;
984
-        foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) {
985
-            foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) {
986
-                $plugin_slug_for_use_in_option_name = $plugin_slug . ".";
987
-                $option_name = self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string;
988
-                $old_option_value = get_option($option_name);
989
-                if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) {
990
-                    $script_array_for_saving = $array_or_migration_obj->properties_as_array();
991
-                    if ($old_option_value != $script_array_for_saving) {
992
-                        $successful_updates = update_option($option_name, $script_array_for_saving);
993
-                    }
994
-                } else {// we don't know what this array-thing is. So just save it as-is
995
-                    if ($old_option_value != $array_or_migration_obj) {
996
-                        $successful_updates = update_option($option_name, $array_or_migration_obj);
997
-                    }
998
-                }
999
-                if (! $successful_updates) {
1000
-                    global $wpdb;
1001
-                    return $wpdb->last_error;
1002
-                }
1003
-            }
1004
-        }
1005
-        return true;
1006
-        // $updated = update_option(self::data_migrations_option_name, $array_of_migrations);
1007
-        // if ($updated !== true) {
1008
-        //     global $wpdb;
1009
-        //     return $wpdb->last_error;
1010
-        // } else {
1011
-        //     return true;
1012
-        // }
1013
-        // wp_mail(
1014
-        //     "[email protected]",
1015
-        //     time() . " price debug info",
1016
-        //     "updated: $updated, last error: $last_error, byte length of option: " . strlen(
1017
-        //         serialize($array_of_migrations)
1018
-        //     )
1019
-        // );
1020
-    }
1021
-
1022
-    /**
1023
-     * Takes an array of data migration script properties and re-creates the class from
1024
-     * them. The argument $properties_array is assumed to have been made by
1025
-     * EE_Data_Migration_Script_Base::properties_as_array()
1026
-     *
1027
-     * @param array $properties_array
1028
-     * @return EE_Data_Migration_Script_Base
1029
-     * @throws EE_Error
1030
-     */
1031
-    public function _instantiate_script_from_properties_array($properties_array)
1032
-    {
1033
-        if (! isset($properties_array['class'])) {
1034
-            throw new EE_Error(
1035
-                sprintf(
1036
-                    __("Properties array  has no 'class' properties. Here's what it has: %s", "event_espresso"),
1037
-                    implode(",", $properties_array)
1038
-                )
1039
-            );
1040
-        }
1041
-        $class_name = $properties_array['class'];
1042
-        if (! class_exists($class_name)) {
1043
-            throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name));
1044
-        }
1045
-        $class = new $class_name;
1046
-        if (! $class instanceof EE_Data_Migration_Script_Base) {
1047
-            throw new EE_Error(
1048
-                sprintf(
1049
-                    __("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),
1050
-                    $class_name,
1051
-                    get_class($class)
1052
-                )
1053
-            );
1054
-        }
1055
-        $class->instantiate_from_array_of_properties($properties_array);
1056
-        return $class;
1057
-    }
1058
-
1059
-    /**
1060
-     * Gets the classname for the most up-to-date DMS (ie, the one that will finally
1061
-     * leave the DB in a state usable by the current plugin code).
1062
-     *
1063
-     * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core'
1064
-     * @return string
1065
-     */
1066
-    public function get_most_up_to_date_dms($plugin_slug = 'Core')
1067
-    {
1068
-        $class_to_filepath_map = $this->get_all_data_migration_scripts_available();
1069
-        $most_up_to_date_dms_classname = null;
1070
-        foreach ($class_to_filepath_map as $classname => $filepath) {
1071
-            if ($most_up_to_date_dms_classname === null) {
1072
-                $migrates_to = $this->script_migrates_to_version($classname);
1073
-                $this_plugin_slug = $migrates_to['slug'];
1074
-                if ($this_plugin_slug == $plugin_slug) {
1075
-                    // if it's for core, it wins
1076
-                    $most_up_to_date_dms_classname = $classname;
1077
-                }
1078
-                // if it wasn't for core, we must keep searching for one that is!
1079
-                continue;
1080
-            } else {
1081
-                $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname);
1082
-                $contender_migrates_to = $this->script_migrates_to_version($classname);
1083
-                if ($contender_migrates_to['slug'] == $plugin_slug
1084
-                    && version_compare(
1085
-                        $champion_migrates_to['version'],
1086
-                        $contender_migrates_to['version'],
1087
-                        '<'
1088
-                    )) {
1089
-                    // so the contenders version is higher and its for Core
1090
-                    $most_up_to_date_dms_classname = $classname;
1091
-                }
1092
-            }
1093
-        }
1094
-        return $most_up_to_date_dms_classname;
1095
-    }
1096
-
1097
-    /**
1098
-     * Gets the migration script specified but ONLY if it has already ran.
1099
-     *
1100
-     * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has ran, you would run the following code:
1101
-     * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !==
1102
-     * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or
1103
-     * other addon) DMS has ran, in case the current DMS depends on it.
1104
-     *
1105
-     * @param string $version     the version the DMS searched for migrates to. Usually just the content before the 3rd
1106
-     *                            period. Eg '4.1.0'
1107
-     * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc
1108
-     * @return EE_Data_Migration_Script_Base
1109
-     */
1110
-    public function get_migration_ran($version, $plugin_slug = 'Core')
1111
-    {
1112
-        $migrations_ran = $this->get_data_migrations_ran();
1113
-        if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) {
1114
-            return $migrations_ran[ $plugin_slug ][ $version ];
1115
-        } else {
1116
-            return null;
1117
-        }
1118
-    }
1119
-
1120
-    /**
1121
-     * Resets the borked data migration scripts so they're no longer borked
1122
-     * so we can again attempt to migrate
1123
-     *
1124
-     * @return bool
1125
-     * @throws EE_Error
1126
-     */
1127
-    public function reattempt()
1128
-    {
1129
-        // find if the last-ran script was borked
1130
-        // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize)
1131
-        // add an 'error' saying that we attempted to reset
1132
-        // does it have a stage that was borked too? if so make it no longer borked
1133
-        // add an 'error' saying we attempted to reset
1134
-        $last_ran_script = $this->get_last_ran_script();
1135
-        if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) {
1136
-            // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it)
1137
-            $last_ran_script->set_completed();
1138
-        } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) {
1139
-            $last_ran_script->reattempt();
1140
-        } else {
1141
-            throw new EE_Error(
1142
-                sprintf(
1143
-                    __(
1144
-                        'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s',
1145
-                        'event_espresso'
1146
-                    ),
1147
-                    print_r($last_ran_script, true)
1148
-                )
1149
-            );
1150
-        }
1151
-        return $this->_save_migrations_ran();
1152
-    }
1153
-
1154
-    /**
1155
-     * Gets whether or not this particular migration has run or not
1156
-     *
1157
-     * @param string $version     the version the DMS searched for migrates to. Usually just the content before the 3rd
1158
-     *                            period. Eg '4.1.0'
1159
-     * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc
1160
-     * @return boolean
1161
-     */
1162
-    public function migration_has_ran($version, $plugin_slug = 'Core')
1163
-    {
1164
-        return $this->get_migration_ran($version, $plugin_slug) !== null;
1165
-    }
1166
-
1167
-    /**
1168
-     * Enqueues this ee plugin to have its data initialized
1169
-     *
1170
-     * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value
1171
-     */
1172
-    public function enqueue_db_initialization_for($plugin_slug)
1173
-    {
1174
-        $queue = $this->get_db_initialization_queue();
1175
-        if (! in_array($plugin_slug, $queue)) {
1176
-            $queue[] = $plugin_slug;
1177
-        }
1178
-        update_option(self::db_init_queue_option_name, $queue);
1179
-    }
1180
-
1181
-    /**
1182
-     * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon
1183
-     * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is
1184
-     * in the queue, calls EE_System::initialize_db_if_no_migrations_required().
1185
-     */
1186
-    public function initialize_db_for_enqueued_ee_plugins()
1187
-    {
1188
-        $queue = $this->get_db_initialization_queue();
1189
-        foreach ($queue as $plugin_slug) {
1190
-            $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug);
1191
-            if (! $most_up_to_date_dms) {
1192
-                // if there is NO DMS for this plugin, obviously there's no schema to verify anyways
1193
-                $verify_db = false;
1194
-            } else {
1195
-                $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms);
1196
-                $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to);
1197
-            }
1198
-            if ($plugin_slug == 'Core') {
1199
-                EE_System::instance()->initialize_db_if_no_migrations_required(
1200
-                    false,
1201
-                    $verify_db
1202
-                );
1203
-            } else {
1204
-                // just loop through the addons to make sure their database is setup
1205
-                foreach (EE_Registry::instance()->addons as $addon) {
1206
-                    if ($addon->name() == $plugin_slug) {
1207
-                        $addon->initialize_db_if_no_migrations_required($verify_db);
1208
-                        break;
1209
-                    }
1210
-                }
1211
-            }
1212
-        }
1213
-        // because we just initialized the DBs for the enqueued ee plugins
1214
-        // we don't need to keep remembering which ones needed to be initialized
1215
-        delete_option(self::db_init_queue_option_name);
1216
-    }
1217
-
1218
-    /**
1219
-     * Gets a numerically-indexed array of plugin slugs that need to have their databases
1220
-     * (re-)initialized after migrations are complete. ie, each element should be either
1221
-     * 'Core', or the return value of EE_Addon::name() for an addon
1222
-     *
1223
-     * @return array
1224
-     */
1225
-    public function get_db_initialization_queue()
1226
-    {
1227
-        return get_option(self::db_init_queue_option_name, array());
1228
-    }
1229
-
1230
-    /**
1231
-     * Gets the injected table analyzer, or throws an exception
1232
-     *
1233
-     * @return TableAnalysis
1234
-     * @throws EE_Error
1235
-     */
1236
-    protected function _get_table_analysis()
1237
-    {
1238
-        if ($this->_table_analysis instanceof TableAnalysis) {
1239
-            return $this->_table_analysis;
1240
-        } else {
1241
-            throw new EE_Error(
1242
-                sprintf(
1243
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
1244
-                    get_class($this)
1245
-                )
1246
-            );
1247
-        }
1248
-    }
1249
-
1250
-    /**
1251
-     * Gets the injected table manager, or throws an exception
1252
-     *
1253
-     * @return TableManager
1254
-     * @throws EE_Error
1255
-     */
1256
-    protected function _get_table_manager()
1257
-    {
1258
-        if ($this->_table_manager instanceof TableManager) {
1259
-            return $this->_table_manager;
1260
-        } else {
1261
-            throw new EE_Error(
1262
-                sprintf(
1263
-                    __('Table manager class on class %1$s is not set properly.', 'event_espresso'),
1264
-                    get_class($this)
1265
-                )
1266
-            );
1267
-        }
1268
-    }
35
+	/**
36
+	 *
37
+	 * @var EE_Registry
38
+	 */
39
+	// protected $EE;
40
+	/**
41
+	 * name of the wordpress option which stores an array of data about
42
+	 */
43
+	const data_migrations_option_name = 'ee_data_migration';
44
+
45
+
46
+	const data_migration_script_option_prefix = 'ee_data_migration_script_';
47
+
48
+	const data_migration_script_mapping_option_prefix = 'ee_dms_map_';
49
+
50
+	/**
51
+	 * name of the wordpress option which stores the database' current version. IE, the code may be at version 4.2.0,
52
+	 * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc.
53
+	 */
54
+	const current_database_state = 'ee_data_migration_current_db_state';
55
+
56
+	/**
57
+	 * Special status string returned when we're positive there are no more data migration
58
+	 * scripts that can be run.
59
+	 */
60
+	const status_no_more_migration_scripts = 'no_more_migration_scripts';
61
+	/**
62
+	 * string indicating the migration should continue
63
+	 */
64
+	const status_continue = 'status_continue';
65
+	/**
66
+	 * string indicating the migration has completed and should be ended
67
+	 */
68
+	const status_completed = 'status_completed';
69
+	/**
70
+	 * string indicating a fatal error occurred and the data migration should be completely aborted
71
+	 */
72
+	const status_fatal_error = 'status_fatal_error';
73
+
74
+	/**
75
+	 * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent
76
+	 * during migration)
77
+	 */
78
+	const step_size = 50;
79
+
80
+	/**
81
+	 * option name that stores the queue of ee plugins needing to have
82
+	 * their data initialized (or re-initialized) once we are done migrations
83
+	 */
84
+	const db_init_queue_option_name = 'ee_db_init_queue';
85
+	/**
86
+	 * Array of information concerning data migrations that have ran in the history
87
+	 * of this EE installation. Keys should be the name of the version the script upgraded to
88
+	 *
89
+	 * @var EE_Data_Migration_Script_Base[]
90
+	 */
91
+	private $_data_migrations_ran = null;
92
+	/**
93
+	 * The last ran script. It's nice to store this somewhere accessible, as its easiest
94
+	 * to know which was the last run by which is the newest wp option; but in most of the code
95
+	 * we just use the local $_data_migration_ran array, which organized the scripts differently
96
+	 *
97
+	 * @var EE_Data_Migration_Script_Base
98
+	 */
99
+	private $_last_ran_script = null;
100
+
101
+	/**
102
+	 * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script.
103
+	 *
104
+	 * @var EE_Data_Migration_Script_Base
105
+	 */
106
+	private $_last_ran_incomplete_script = null;
107
+	/**
108
+	 * array where keys are classnames, and values are filepaths of all the known migration scripts
109
+	 *
110
+	 * @var array
111
+	 */
112
+	private $_data_migration_class_to_filepath_map;
113
+
114
+	/**
115
+	 * the following 4 properties are fully set on construction.
116
+	 * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished
117
+	 * one, we may want to start the next one); whereas the last two indicate whether to continue running a single
118
+	 * data migration script
119
+	 *
120
+	 * @var array
121
+	 */
122
+	public $stati_that_indicate_to_continue_migrations = array();
123
+
124
+	public $stati_that_indicate_to_stop_migrations = array();
125
+
126
+	public $stati_that_indicate_to_continue_single_migration_script = array();
127
+
128
+	public $stati_that_indicate_to_stop_single_migration_script = array();
129
+
130
+	/**
131
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
132
+	 */
133
+	protected $_table_manager;
134
+
135
+	/**
136
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
137
+	 */
138
+	protected $_table_analysis;
139
+
140
+	/**
141
+	 * @var array $script_migration_versions
142
+	 */
143
+	protected $script_migration_versions;
144
+
145
+	/**
146
+	 * @var EE_Data_Migration_Manager $_instance
147
+	 * @access    private
148
+	 */
149
+	private static $_instance = null;
150
+
151
+
152
+	/**
153
+	 * @singleton method used to instantiate class object
154
+	 * @access    public
155
+	 * @return EE_Data_Migration_Manager instance
156
+	 */
157
+	public static function instance()
158
+	{
159
+		// check if class object is instantiated
160
+		if (! self::$_instance instanceof EE_Data_Migration_Manager) {
161
+			self::$_instance = new self();
162
+		}
163
+		return self::$_instance;
164
+	}
165
+
166
+	/**
167
+	 * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning,
168
+	 * all new usages of the singleton should be made with Classname::instance()) and returns it
169
+	 *
170
+	 * @return EE_Data_Migration_Manager
171
+	 */
172
+	public static function reset()
173
+	{
174
+		self::$_instance = null;
175
+		return self::instance();
176
+	}
177
+
178
+
179
+	/**
180
+	 * constructor
181
+	 */
182
+	private function __construct()
183
+	{
184
+		$this->stati_that_indicate_to_continue_migrations = array(
185
+			self::status_continue,
186
+			self::status_completed,
187
+		);
188
+		$this->stati_that_indicate_to_stop_migrations = array(
189
+			self::status_fatal_error,
190
+			self::status_no_more_migration_scripts,
191
+		);
192
+		$this->stati_that_indicate_to_continue_single_migration_script = array(
193
+			self::status_continue,
194
+		);
195
+		$this->stati_that_indicate_to_stop_single_migration_script = array(
196
+			self::status_completed,
197
+			self::status_fatal_error
198
+			// note: status_no_more_migration_scripts doesn't apply
199
+		);
200
+		// make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class
201
+		// to be defined, because right now it doesn't get autoloaded on its own
202
+		EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), true);
203
+		EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), true);
204
+		EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), true);
205
+		EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), true);
206
+		EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), true);
207
+		$this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true);
208
+		$this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
209
+	}
210
+
211
+
212
+	/**
213
+	 * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what
214
+	 * the option names are like, but generally they're like
215
+	 * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that).
216
+	 * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived,
217
+	 * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php (eg
218
+	 * EE_DMS_Core_4_1_0.dms.php)
219
+	 *
220
+	 * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set)
221
+	 * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of
222
+	 *               that plugin (eg '4.1.0')
223
+	 */
224
+	private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name)
225
+	{
226
+		$plugin_slug_and_version_string = str_replace(
227
+			EE_Data_Migration_Manager::data_migration_script_option_prefix,
228
+			"",
229
+			$option_name
230
+		);
231
+		// check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style)
232
+		$parts = explode(".", $plugin_slug_and_version_string);
233
+
234
+		if (count($parts) == 4) {
235
+			// it's 4.2-style.eg Core.4.1.0
236
+			$plugin_slug = $parts[0];// eg Core
237
+			$version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0
238
+		} else {
239
+			// it's 4.1-style: eg 4.1.0
240
+			$plugin_slug = 'Core';
241
+			$version_string = $plugin_slug_and_version_string;// eg 4.1.0
242
+		}
243
+		return array($plugin_slug, $version_string);
244
+	}
245
+
246
+	/**
247
+	 * Gets the DMS class from the wordpress option, otherwise throws an EE_Error if it's not
248
+	 * for a known DMS class.
249
+	 *
250
+	 * @param string $dms_option_name
251
+	 * @param string $dms_option_value (serialized)
252
+	 * @return EE_Data_Migration_Script_Base
253
+	 * @throws EE_Error
254
+	 */
255
+	private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value)
256
+	{
257
+		$data_migration_data = maybe_unserialize($dms_option_value);
258
+		if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) {
259
+			$class = new $data_migration_data['class'];
260
+			if ($class instanceof EE_Data_Migration_Script_Base) {
261
+				$class->instantiate_from_array_of_properties($data_migration_data);
262
+				return $class;
263
+			} else {
264
+				// huh, so its an object but not a data migration script?? that shouldn't happen
265
+				// just leave it as an array (which will probably just get ignored)
266
+				throw new EE_Error(
267
+					sprintf(
268
+						__(
269
+							"Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists",
270
+							'event_espresso'
271
+						),
272
+						$data_migration_data['class']
273
+					)
274
+				);
275
+			}
276
+		} else {
277
+			// so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists
278
+			throw new EE_Error(
279
+				sprintf(__("The wp option  with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)
280
+			);
281
+		}
282
+	}
283
+
284
+	/**
285
+	 * Gets the array describing what data migrations have run. Also has a side-effect of recording which was the last
286
+	 * ran, and which was the last ran which hasn't finished yet
287
+	 *
288
+	 * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy
289
+	 *               arrays in there - which should probably be ignored)
290
+	 */
291
+	public function get_data_migrations_ran()
292
+	{
293
+		if (! $this->_data_migrations_ran) {
294
+			// setup autoloaders for each of the scripts in there
295
+			$this->get_all_data_migration_scripts_available();
296
+			$data_migrations_options = $this->get_all_migration_script_options(
297
+			);// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array()));
298
+
299
+			$data_migrations_ran = array();
300
+			// convert into data migration script classes where possible
301
+			foreach ($data_migrations_options as $data_migration_option) {
302
+				list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name(
303
+					$data_migration_option['option_name']
304
+				);
305
+
306
+				try {
307
+					$class = $this->_get_dms_class_from_wp_option(
308
+						$data_migration_option['option_name'],
309
+						$data_migration_option['option_value']
310
+					);
311
+					$data_migrations_ran[ $plugin_slug ][ $version_string ] = $class;
312
+					// ok so far THIS is the 'last-ran-script'... unless we find another on next iteration
313
+					$this->_last_ran_script = $class;
314
+					if (! $class->is_completed()) {
315
+						// sometimes we also like to know which was the last incomplete script (or if there are any at all)
316
+						$this->_last_ran_incomplete_script = $class;
317
+					}
318
+				} catch (EE_Error $e) {
319
+					// ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs
320
+					$data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize(
321
+						$data_migration_option['option_value']
322
+					);
323
+				}
324
+			}
325
+			// so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays
326
+			$this->_data_migrations_ran = $data_migrations_ran;
327
+			if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) {
328
+				$this->_data_migrations_ran = array();
329
+			}
330
+		}
331
+		return $this->_data_migrations_ran;
332
+	}
333
+
334
+
335
+	/**
336
+	 *
337
+	 * @param string $script_name eg 'DMS_Core_4_1_0'
338
+	 * @param string $old_table   eg 'wp_events_detail'
339
+	 * @param string $old_pk      eg 'wp_esp_posts'
340
+	 * @param        $new_table
341
+	 * @return mixed string or int
342
+	 */
343
+	public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table)
344
+	{
345
+		$script = EE_Registry::instance()->load_dms($script_name);
346
+		$mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table);
347
+		return $mapping;
348
+	}
349
+
350
+	/**
351
+	 * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that
352
+	 * the last option returned in this array is the most-recently ran DMS option
353
+	 *
354
+	 * @return array
355
+	 */
356
+	public function get_all_migration_script_options()
357
+	{
358
+		global $wpdb;
359
+		return $wpdb->get_results(
360
+			"SELECT * FROM {$wpdb->options} WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id ASC",
361
+			ARRAY_A
362
+		);
363
+	}
364
+
365
+	/**
366
+	 * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded
367
+	 *
368
+	 * @return array where each value is the full folder path of a folder containing data migration scripts, WITH
369
+	 *               slashes at the end of the folder name.
370
+	 */
371
+	public function get_data_migration_script_folders()
372
+	{
373
+		return apply_filters(
374
+			'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',
375
+			array('Core' => EE_CORE . 'data_migration_scripts')
376
+		);
377
+	}
378
+
379
+	/**
380
+	 * Gets the version the migration script upgrades to
381
+	 *
382
+	 * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0'
383
+	 * @return array {
384
+	 * @type string  $slug                  like 'Core','Calendar',etc
385
+	 * @type string  $version               like 4.3.0
386
+	 *                                      }
387
+	 * @throws EE_Error
388
+	 */
389
+	public function script_migrates_to_version($migration_script_name, $eeAddonClass = '')
390
+	{
391
+		if (isset($this->script_migration_versions[ $migration_script_name ])) {
392
+			return $this->script_migration_versions[ $migration_script_name ];
393
+		}
394
+		$dms_info = $this->parse_dms_classname($migration_script_name);
395
+		$this->script_migration_versions[ $migration_script_name ] = array(
396
+			'slug'    => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'],
397
+			'version' => $dms_info['major_version'] . "." . $dms_info['minor_version'] . "." . $dms_info['micro_version'],
398
+		);
399
+		return $this->script_migration_versions[ $migration_script_name ];
400
+	}
401
+
402
+	/**
403
+	 * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0'
404
+	 *
405
+	 * @param string $classname
406
+	 * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints)
407
+	 * @throws EE_Error
408
+	 */
409
+	public function parse_dms_classname($classname)
410
+	{
411
+		$matches = array();
412
+		preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches);
413
+		if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) {
414
+			throw new EE_Error(
415
+				sprintf(
416
+					__(
417
+						"%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ",
418
+						"event_espresso"
419
+					),
420
+					$classname
421
+				)
422
+			);
423
+		}
424
+		return array(
425
+			'slug'          => $matches[1],
426
+			'major_version' => intval($matches[2]),
427
+			'minor_version' => intval($matches[3]),
428
+			'micro_version' => intval($matches[4]),
429
+		);
430
+	}
431
+
432
+	/**
433
+	 * Ensures that the option indicating the current DB version is set. This should only be
434
+	 * a concern when activating EE for the first time, THEORETICALLY.
435
+	 * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise
436
+	 * to 4.1.x.
437
+	 *
438
+	 * @return string of current db state
439
+	 */
440
+	public function ensure_current_database_state_is_set()
441
+	{
442
+		$espresso_db_core_updates = get_option('espresso_db_update', array());
443
+		$db_state = get_option(EE_Data_Migration_Manager::current_database_state);
444
+		if (! $db_state) {
445
+			// mark the DB as being in the state as the last version in there.
446
+			// this is done to trigger maintenance mode and do data migration scripts
447
+			// if the admin installed this version of EE over 3.1.x or 4.0.x
448
+			// otherwise, the normal maintenance mode code is fine
449
+			$previous_versions_installed = array_keys($espresso_db_core_updates);
450
+			$previous_version_installed = end($previous_versions_installed);
451
+			if (version_compare('4.1.0', $previous_version_installed)) {
452
+				// last installed version was less than 4.1
453
+				// so we want the data migrations to happen. SO, we're going to say the DB is at that state
454
+				$db_state = array('Core' => $previous_version_installed);
455
+			} else {
456
+				$db_state = array('Core' => EVENT_ESPRESSO_VERSION);
457
+			}
458
+			update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
459
+		}
460
+		// in 4.1, $db_state would have only been a simple string like '4.1.0',
461
+		// but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's
462
+		// db, and possibly other keys for other addons like 'Calendar','Permissions',etc
463
+		if (! is_array($db_state)) {
464
+			$db_state = array('Core' => $db_state);
465
+			update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
466
+		}
467
+		return $db_state;
468
+	}
469
+
470
+	/**
471
+	 * Checks if there are any data migration scripts that ought to be run. If found,
472
+	 * returns the instantiated classes. If none are found (ie, they've all already been run
473
+	 * or they don't apply), returns an empty array
474
+	 *
475
+	 * @return EE_Data_Migration_Script_Base[]
476
+	 */
477
+	public function check_for_applicable_data_migration_scripts()
478
+	{
479
+		// get the option describing what options have already run
480
+		$scripts_ran = $this->get_data_migrations_ran();
481
+		// $scripts_ran = array('4.1.0.core'=>array('monkey'=>null));
482
+		$script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available();
483
+
484
+
485
+		$current_database_state = $this->ensure_current_database_state_is_set();
486
+		// determine which have already been run
487
+		$script_classes_that_should_run_per_iteration = array();
488
+		$iteration = 0;
489
+		$next_database_state_to_consider = $current_database_state;
490
+		$theoretical_database_state = null;
491
+		do {
492
+			// the next state after the currently-considered one will start off looking the same as the current, but we may make additions...
493
+			$theoretical_database_state = $next_database_state_to_consider;
494
+			// the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?)
495
+			foreach ($script_class_and_filepaths_available as $classname => $filepath) {
496
+				$migrates_to_version = $this->script_migrates_to_version($classname);
497
+				$script_converts_plugin_slug = $migrates_to_version['slug'];
498
+				$script_converts_to_version = $migrates_to_version['version'];
499
+				// check if this version script is DONE or not; or if it's never been ran
500
+				if (! $scripts_ran ||
501
+					! isset($scripts_ran[ $script_converts_plugin_slug ]) ||
502
+					! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ])) {
503
+					// we haven't ran this conversion script before
504
+					// now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available
505
+					$script = new $classname($this->_get_table_manager(), $this->_get_table_analysis());
506
+					/* @var $script EE_Data_Migration_Script_Base */
507
+					$can_migrate = $script->can_migrate_from_version($theoretical_database_state);
508
+					if ($can_migrate) {
509
+						$script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script;
510
+						$migrates_to_version = $script->migrates_to_version();
511
+						$next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version'];
512
+						unset($script_class_and_filepaths_available[ $classname ]);
513
+					}
514
+				} elseif ($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] instanceof EE_Data_Migration_Script_Base) {
515
+					// this script has been ran, or at least started
516
+					$script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ];
517
+					if ($script->get_status() != self::status_completed) {
518
+						// this script is already underway... keep going with it
519
+						$script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script;
520
+						$migrates_to_version = $script->migrates_to_version();
521
+						$next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version'];
522
+						unset($script_class_and_filepaths_available[ $classname ]);
523
+					} else {
524
+						// it must have a status that indicates it has finished, so we don't want to try and run it again
525
+					}
526
+				} else {
527
+					// it exists but it's not  a proper data migration script
528
+					// maybe the script got renamed? or was simply removed from EE?
529
+					// either way, its certainly not runnable!
530
+				}
531
+			}
532
+			$iteration++;
533
+		} while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6);
534
+		// ok we have all the scripts that should run, now let's make them into flat array
535
+		$scripts_that_should_run = array();
536
+		foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) {
537
+			ksort($scripts_at_priority);
538
+			foreach ($scripts_at_priority as $scripts) {
539
+				foreach ($scripts as $script) {
540
+					$scripts_that_should_run[ get_class($script) ] = $script;
541
+				}
542
+			}
543
+		}
544
+
545
+		do_action(
546
+			'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run',
547
+			$scripts_that_should_run
548
+		);
549
+		return $scripts_that_should_run;
550
+	}
551
+
552
+
553
+	/**
554
+	 * Gets the script which is currently being ran, if there is one. If $include_completed_scripts is set to TRUE
555
+	 * it will return the last ran script even if its complete.
556
+	 * This means: if you want to find the currently-executing script, leave it as FALSE.
557
+	 * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE.
558
+	 *
559
+	 * @param bool $include_completed_scripts
560
+	 * @return EE_Data_Migration_Script_Base
561
+	 */
562
+	public function get_last_ran_script($include_completed_scripts = false)
563
+	{
564
+		// make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script
565
+		if (! $this->_data_migrations_ran) {
566
+			$this->get_data_migrations_ran();
567
+		}
568
+		if ($include_completed_scripts) {
569
+			return $this->_last_ran_script;
570
+		} else {
571
+			return $this->_last_ran_incomplete_script;
572
+		}
573
+	}
574
+
575
+
576
+	/**
577
+	 * Runs the data migration scripts (well, each request to this method calls one of the
578
+	 * data migration scripts' migration_step() functions).
579
+	 *
580
+	 * @param int   $step_size
581
+	 * @throws EE_Error
582
+	 * @return array {
583
+	 *                                  // where the first item is one EE_Data_Migration_Script_Base's stati,
584
+	 *                                  //and the second item is a string describing what was done
585
+	 * @type int    $records_to_migrate from the current migration script
586
+	 * @type int    $records_migrated
587
+	 * @type string $status             one of EE_Data_Migration_Manager::status_*
588
+	 * @type string $script             verbose name of the current DMS
589
+	 * @type string $message            string describing what was done during this step
590
+	 *                                  }
591
+	 */
592
+	public function migration_step($step_size = 0)
593
+	{
594
+
595
+		// bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535
596
+		if (class_exists('EE_CPT_Strategy')) {
597
+			remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5);
598
+		}
599
+
600
+		try {
601
+			$currently_executing_script = $this->get_last_ran_script();
602
+			if (! $currently_executing_script) {
603
+				// Find the next script that needs to execute
604
+				$scripts = $this->check_for_applicable_data_migration_scripts();
605
+				if (! $scripts) {
606
+					// huh, no more scripts to run... apparently we're done!
607
+					// but dont forget to make sure initial data is there
608
+					// we should be good to allow them to exit maintenance mode now
609
+					EE_Maintenance_Mode::instance()->set_maintenance_level(
610
+						intval(EE_Maintenance_Mode::level_0_not_in_maintenance)
611
+					);
612
+					// saving migrations ran should actually be unnecessary, but leaving in place just in case
613
+					// remember this migration was finished (even if we timeout initing db for core and plugins)
614
+					$this->_save_migrations_ran();
615
+					// make sure DB was updated AFTER we've recorded the migration was done
616
+					$this->initialize_db_for_enqueued_ee_plugins();
617
+					return array(
618
+						'records_to_migrate' => 1,
619
+						'records_migrated'   => 1,
620
+						'status'             => self::status_no_more_migration_scripts,
621
+						'script'             => __("Data Migration Completed Successfully", "event_espresso"),
622
+						'message'            => __("All done!", "event_espresso"),
623
+					);
624
+				}
625
+				$currently_executing_script = array_shift($scripts);
626
+				// and add to the array/wp option showing the scripts ran
627
+
628
+				$migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script));
629
+				$plugin_slug = $migrates_to['slug'];
630
+				$version = $migrates_to['version'];
631
+				$this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script;
632
+			}
633
+			$current_script_name = get_class($currently_executing_script);
634
+		} catch (Exception $e) {
635
+			// an exception occurred while trying to get migration scripts
636
+
637
+			$message = sprintf(
638
+				__("Error Message: %sStack Trace:%s", "event_espresso"),
639
+				$e->getMessage() . '<br>',
640
+				$e->getTraceAsString()
641
+			);
642
+			// record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations
643
+			// but that's ok-- it's just an FYI to support that we couldn't even run any data migrations
644
+			$this->add_error_to_migrations_ran(
645
+				sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)
646
+			);
647
+			return array(
648
+				'records_to_migrate' => 1,
649
+				'records_migrated'   => 0,
650
+				'status'             => self::status_fatal_error,
651
+				'script'             => __("Error loading data migration scripts", "event_espresso"),
652
+				'message'            => $message,
653
+			);
654
+		}
655
+		// ok so we definitely have a data migration script
656
+		try {
657
+			// how big of a bite do we want to take? Allow users to easily override via their wp-config
658
+			if (absint($step_size) < 1) {
659
+				$step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE)
660
+					? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size;
661
+			}
662
+			// do what we came to do!
663
+			$currently_executing_script->migration_step($step_size);
664
+			// can we wrap it up and verify default data?
665
+			$init_dbs = false;
666
+			switch ($currently_executing_script->get_status()) {
667
+				case EE_Data_Migration_Manager::status_continue:
668
+					$response_array = array(
669
+						'records_to_migrate' => $currently_executing_script->count_records_to_migrate(),
670
+						'records_migrated'   => $currently_executing_script->count_records_migrated(),
671
+						'status'             => EE_Data_Migration_Manager::status_continue,
672
+						'message'            => $currently_executing_script->get_feedback_message(),
673
+						'script'             => $currently_executing_script->pretty_name(),
674
+					);
675
+					break;
676
+				case EE_Data_Migration_Manager::status_completed:
677
+					// ok so THAT script has completed
678
+					$this->update_current_database_state_to($this->script_migrates_to_version($current_script_name));
679
+					$response_array = array(
680
+						'records_to_migrate' => $currently_executing_script->count_records_to_migrate(),
681
+						'records_migrated'   => $currently_executing_script->count_records_migrated(),
682
+						'status'             => EE_Data_Migration_Manager::status_completed,
683
+						'message'            => $currently_executing_script->get_feedback_message(),
684
+						'script'             => sprintf(
685
+							__("%s Completed", 'event_espresso'),
686
+							$currently_executing_script->pretty_name()
687
+						),
688
+					);
689
+					// check if there are any more after this one.
690
+					$scripts_remaining = $this->check_for_applicable_data_migration_scripts();
691
+					if (! $scripts_remaining) {
692
+						// we should be good to allow them to exit maintenance mode now
693
+						EE_Maintenance_Mode::instance()->set_maintenance_level(
694
+							intval(EE_Maintenance_Mode::level_0_not_in_maintenance)
695
+						);
696
+						// huh, no more scripts to run... apparently we're done!
697
+						// but dont forget to make sure initial data is there
698
+						$init_dbs = true;
699
+						$response_array['status'] = self::status_no_more_migration_scripts;
700
+					}
701
+					break;
702
+				default:
703
+					$response_array = array(
704
+						'records_to_migrate' => $currently_executing_script->count_records_to_migrate(),
705
+						'records_migrated'   => $currently_executing_script->count_records_migrated(),
706
+						'status'             => $currently_executing_script->get_status(),
707
+						'message'            => sprintf(
708
+							__("Minor errors occurred during %s: %s", "event_espresso"),
709
+							$currently_executing_script->pretty_name(),
710
+							implode(", ", $currently_executing_script->get_errors())
711
+						),
712
+						'script'             => $currently_executing_script->pretty_name(),
713
+					);
714
+					break;
715
+			}
716
+		} catch (Exception $e) {
717
+			// ok so some exception was thrown which killed the data migration script
718
+			// double-check we have a real script
719
+			if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) {
720
+				$script_name = $currently_executing_script->pretty_name();
721
+				$currently_executing_script->set_broken();
722
+				$currently_executing_script->add_error($e->getMessage());
723
+			} else {
724
+				$script_name = __("Error getting Migration Script", "event_espresso");
725
+			}
726
+			$response_array = array(
727
+				'records_to_migrate' => 1,
728
+				'records_migrated'   => 0,
729
+				'status'             => self::status_fatal_error,
730
+				'message'            => sprintf(
731
+					__("A fatal error occurred during the migration: %s", "event_espresso"),
732
+					$e->getMessage()
733
+				),
734
+				'script'             => $script_name,
735
+			);
736
+		}
737
+		$successful_save = $this->_save_migrations_ran();
738
+		if ($successful_save !== true) {
739
+			// ok so the current wp option didn't save. that's tricky, because we'd like to update it
740
+			// and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION!
741
+			// however, if we throw an exception, and return that, then the next request
742
+			// won't have as much info in it, and it may be able to save
743
+			throw new EE_Error(
744
+				sprintf(
745
+					__(
746
+						"The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.",
747
+						"event_espresso"
748
+					),
749
+					$successful_save
750
+				)
751
+			);
752
+		}
753
+		// if we're all done, initialize EE plugins' default data etc.
754
+		if ($init_dbs) {
755
+			$this->initialize_db_for_enqueued_ee_plugins();
756
+		}
757
+		return $response_array;
758
+	}
759
+
760
+
761
+	/**
762
+	 * Echo out JSON response to migration script AJAX requests. Takes precautions
763
+	 * to buffer output so that we don't throw junk into our json.
764
+	 *
765
+	 * @return array with keys:
766
+	 * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie,
767
+	 * it's NOT the count of hwo many remain)
768
+	 * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete =
769
+	 * records_migrated/records_to_migrate)
770
+	 * 'status'=>a string, one of EE_Data_migration_Manager::status_*
771
+	 * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into
772
+	 * errors, notifications, and successes
773
+	 * 'script'=>a pretty name of the script currently running
774
+	 */
775
+	public function response_to_migration_ajax_request()
776
+	{
777
+		ob_start();
778
+		try {
779
+			$response = $this->migration_step();
780
+		} catch (Exception $e) {
781
+			$response = array(
782
+				'records_to_migrate' => 0,
783
+				'records_migrated'   => 0,
784
+				'status'             => EE_Data_Migration_Manager::status_fatal_error,
785
+				'message'            => sprintf(
786
+					__("Unknown fatal error occurred: %s", "event_espresso"),
787
+					$e->getMessage()
788
+				),
789
+				'script'             => 'Unknown',
790
+			);
791
+			$this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString());
792
+		}
793
+		$warnings_etc = @ob_get_contents();
794
+		ob_end_clean();
795
+		$response['message'] .= $warnings_etc;
796
+		return $response;
797
+	}
798
+
799
+	/**
800
+	 * Updates the wordpress option that keeps track of which which EE version the database
801
+	 * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35)
802
+	 *
803
+	 * @param array $slug_and_version {
804
+	 * @type string $slug             like 'Core' or 'Calendar',
805
+	 * @type string $version          like '4.1.0'
806
+	 *                                }
807
+	 * @return void
808
+	 */
809
+	public function update_current_database_state_to($slug_and_version = null)
810
+	{
811
+		if (! $slug_and_version) {
812
+			// no version was provided, assume it should be at the current code version
813
+			$slug_and_version = array('slug' => 'Core', 'version' => espresso_version());
814
+		}
815
+		$current_database_state = get_option(self::current_database_state);
816
+		$current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version'];
817
+		update_option(self::current_database_state, $current_database_state);
818
+	}
819
+
820
+	/**
821
+	 * Determines if the database is currently at a state matching what's indicated in $slug and $version.
822
+	 *
823
+	 * @param array $slug_and_version {
824
+	 * @type string $slug             like 'Core' or 'Calendar',
825
+	 * @type string $version          like '4.1.0'
826
+	 *                                }
827
+	 * @return boolean
828
+	 */
829
+	public function database_needs_updating_to($slug_and_version)
830
+	{
831
+
832
+		$slug = $slug_and_version['slug'];
833
+		$version = $slug_and_version['version'];
834
+		$current_database_state = get_option(self::current_database_state);
835
+		if (! isset($current_database_state[ $slug ])) {
836
+			return true;
837
+		} else {
838
+			// just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes
839
+			$version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3);
840
+			$version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3);
841
+			$needs_updating = false;
842
+			foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) {
843
+				if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) {
844
+					$needs_updating = true;
845
+					break;
846
+				}
847
+			}
848
+			return $needs_updating;
849
+		}
850
+	}
851
+
852
+
853
+	/**
854
+	 * Gets all the data migration scripts available in the core folder and folders
855
+	 * in addons. Has the side effect of adding them for autoloading
856
+	 *
857
+	 * @return array keys are expected classnames, values are their filepaths
858
+	 * @throws InvalidInterfaceException
859
+	 * @throws InvalidDataTypeException
860
+	 * @throws EE_Error
861
+	 * @throws InvalidArgumentException
862
+	 */
863
+	public function get_all_data_migration_scripts_available()
864
+	{
865
+		if (! $this->_data_migration_class_to_filepath_map) {
866
+			$this->_data_migration_class_to_filepath_map = array();
867
+			foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) {
868
+				// strip any placeholders added to classname to make it a unique array key
869
+				$eeAddonClass = trim($eeAddonClass, '*');
870
+				$eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass)
871
+					? $eeAddonClass
872
+					: '';
873
+				$folder_path = EEH_File::end_with_directory_separator($folder_path);
874
+				$files = glob($folder_path . '*.dms.php');
875
+				if (empty($files)) {
876
+					continue;
877
+				}
878
+				foreach ($files as $file) {
879
+					$pos_of_last_slash = strrpos($file, DS);
880
+					$classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1));
881
+					$migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass);
882
+					$slug = $migrates_to['slug'];
883
+					// check that the slug as contained in the DMS is associated with
884
+					// the slug of an addon or core
885
+					if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) {
886
+						EE_Error::doing_it_wrong(
887
+							__FUNCTION__,
888
+							sprintf(
889
+								esc_html__(
890
+									'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ',
891
+									'event_espresso'
892
+								),
893
+								$classname,
894
+								$slug,
895
+								implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name()))
896
+							),
897
+							'4.3.0.alpha.019'
898
+						);
899
+					}
900
+					$this->_data_migration_class_to_filepath_map[ $classname ] = $file;
901
+				}
902
+			}
903
+			EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map);
904
+		}
905
+		return $this->_data_migration_class_to_filepath_map;
906
+	}
907
+
908
+
909
+	/**
910
+	 * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs
911
+	 * from each addon, and check if they need updating,
912
+	 *
913
+	 * @return boolean
914
+	 */
915
+	public function addons_need_updating()
916
+	{
917
+		return false;
918
+	}
919
+
920
+	/**
921
+	 * Adds this error string to the data_migrations_ran array, but we dont necessarily know
922
+	 * where to put it, so we just throw it in there... better than nothing...
923
+	 *
924
+	 * @param string $error_message
925
+	 * @throws EE_Error
926
+	 */
927
+	public function add_error_to_migrations_ran($error_message)
928
+	{
929
+		// get last-ran migration script
930
+		global $wpdb;
931
+		$last_migration_script_option = $wpdb->get_row(
932
+			"SELECT * FROM $wpdb->options WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id DESC LIMIT 1",
933
+			ARRAY_A
934
+		);
935
+
936
+		$last_ran_migration_script_properties = isset($last_migration_script_option['option_value'])
937
+			? maybe_unserialize($last_migration_script_option['option_value']) : null;
938
+		// now, tread lightly because we're here because a FATAL non-catchable error
939
+		// was thrown last time when we were trying to run a data migration script
940
+		// so the fatal error could have happened while getting the migration script
941
+		// or doing running it...
942
+		$versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(
943
+			EE_Data_Migration_Manager::data_migration_script_option_prefix,
944
+			"",
945
+			$last_migration_script_option['option_name']
946
+		) : null;
947
+
948
+		// check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet
949
+		// because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done)
950
+		if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) {
951
+			// ok then just add this error to its list of errors
952
+			$last_ran_migration_script_properties['_errors'][] = $error_message;
953
+			$last_ran_migration_script_properties['_status'] = self::status_fatal_error;
954
+		} else {
955
+			// so we don't even know which script was last running
956
+			// use the data migration error stub, which is designed specifically for this type of thing
957
+			$general_migration_error = new EE_DMS_Unknown_1_0_0();
958
+			$general_migration_error->add_error($error_message);
959
+			$general_migration_error->set_broken();
960
+			$last_ran_migration_script_properties = $general_migration_error->properties_as_array();
961
+			$versions_migrated_to = 'Unknown.1.0.0';
962
+			// now just to make sure appears as last (in case the were previously a fatal error like this)
963
+			// delete the old one
964
+			delete_option(self::data_migration_script_option_prefix . $versions_migrated_to);
965
+		}
966
+		update_option(
967
+			self::data_migration_script_option_prefix . $versions_migrated_to,
968
+			$last_ran_migration_script_properties
969
+		);
970
+	}
971
+
972
+	/**
973
+	 * saves what data migrations have ran to the database
974
+	 *
975
+	 * @return mixed TRUE if successfully saved migrations ran, string if an error occurred
976
+	 */
977
+	protected function _save_migrations_ran()
978
+	{
979
+		if ($this->_data_migrations_ran == null) {
980
+			$this->get_data_migrations_ran();
981
+		}
982
+		// now, we don't want to save actual classes to the DB because that's messy
983
+		$successful_updates = true;
984
+		foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) {
985
+			foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) {
986
+				$plugin_slug_for_use_in_option_name = $plugin_slug . ".";
987
+				$option_name = self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string;
988
+				$old_option_value = get_option($option_name);
989
+				if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) {
990
+					$script_array_for_saving = $array_or_migration_obj->properties_as_array();
991
+					if ($old_option_value != $script_array_for_saving) {
992
+						$successful_updates = update_option($option_name, $script_array_for_saving);
993
+					}
994
+				} else {// we don't know what this array-thing is. So just save it as-is
995
+					if ($old_option_value != $array_or_migration_obj) {
996
+						$successful_updates = update_option($option_name, $array_or_migration_obj);
997
+					}
998
+				}
999
+				if (! $successful_updates) {
1000
+					global $wpdb;
1001
+					return $wpdb->last_error;
1002
+				}
1003
+			}
1004
+		}
1005
+		return true;
1006
+		// $updated = update_option(self::data_migrations_option_name, $array_of_migrations);
1007
+		// if ($updated !== true) {
1008
+		//     global $wpdb;
1009
+		//     return $wpdb->last_error;
1010
+		// } else {
1011
+		//     return true;
1012
+		// }
1013
+		// wp_mail(
1014
+		//     "[email protected]",
1015
+		//     time() . " price debug info",
1016
+		//     "updated: $updated, last error: $last_error, byte length of option: " . strlen(
1017
+		//         serialize($array_of_migrations)
1018
+		//     )
1019
+		// );
1020
+	}
1021
+
1022
+	/**
1023
+	 * Takes an array of data migration script properties and re-creates the class from
1024
+	 * them. The argument $properties_array is assumed to have been made by
1025
+	 * EE_Data_Migration_Script_Base::properties_as_array()
1026
+	 *
1027
+	 * @param array $properties_array
1028
+	 * @return EE_Data_Migration_Script_Base
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	public function _instantiate_script_from_properties_array($properties_array)
1032
+	{
1033
+		if (! isset($properties_array['class'])) {
1034
+			throw new EE_Error(
1035
+				sprintf(
1036
+					__("Properties array  has no 'class' properties. Here's what it has: %s", "event_espresso"),
1037
+					implode(",", $properties_array)
1038
+				)
1039
+			);
1040
+		}
1041
+		$class_name = $properties_array['class'];
1042
+		if (! class_exists($class_name)) {
1043
+			throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name));
1044
+		}
1045
+		$class = new $class_name;
1046
+		if (! $class instanceof EE_Data_Migration_Script_Base) {
1047
+			throw new EE_Error(
1048
+				sprintf(
1049
+					__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),
1050
+					$class_name,
1051
+					get_class($class)
1052
+				)
1053
+			);
1054
+		}
1055
+		$class->instantiate_from_array_of_properties($properties_array);
1056
+		return $class;
1057
+	}
1058
+
1059
+	/**
1060
+	 * Gets the classname for the most up-to-date DMS (ie, the one that will finally
1061
+	 * leave the DB in a state usable by the current plugin code).
1062
+	 *
1063
+	 * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core'
1064
+	 * @return string
1065
+	 */
1066
+	public function get_most_up_to_date_dms($plugin_slug = 'Core')
1067
+	{
1068
+		$class_to_filepath_map = $this->get_all_data_migration_scripts_available();
1069
+		$most_up_to_date_dms_classname = null;
1070
+		foreach ($class_to_filepath_map as $classname => $filepath) {
1071
+			if ($most_up_to_date_dms_classname === null) {
1072
+				$migrates_to = $this->script_migrates_to_version($classname);
1073
+				$this_plugin_slug = $migrates_to['slug'];
1074
+				if ($this_plugin_slug == $plugin_slug) {
1075
+					// if it's for core, it wins
1076
+					$most_up_to_date_dms_classname = $classname;
1077
+				}
1078
+				// if it wasn't for core, we must keep searching for one that is!
1079
+				continue;
1080
+			} else {
1081
+				$champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname);
1082
+				$contender_migrates_to = $this->script_migrates_to_version($classname);
1083
+				if ($contender_migrates_to['slug'] == $plugin_slug
1084
+					&& version_compare(
1085
+						$champion_migrates_to['version'],
1086
+						$contender_migrates_to['version'],
1087
+						'<'
1088
+					)) {
1089
+					// so the contenders version is higher and its for Core
1090
+					$most_up_to_date_dms_classname = $classname;
1091
+				}
1092
+			}
1093
+		}
1094
+		return $most_up_to_date_dms_classname;
1095
+	}
1096
+
1097
+	/**
1098
+	 * Gets the migration script specified but ONLY if it has already ran.
1099
+	 *
1100
+	 * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has ran, you would run the following code:
1101
+	 * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !==
1102
+	 * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or
1103
+	 * other addon) DMS has ran, in case the current DMS depends on it.
1104
+	 *
1105
+	 * @param string $version     the version the DMS searched for migrates to. Usually just the content before the 3rd
1106
+	 *                            period. Eg '4.1.0'
1107
+	 * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc
1108
+	 * @return EE_Data_Migration_Script_Base
1109
+	 */
1110
+	public function get_migration_ran($version, $plugin_slug = 'Core')
1111
+	{
1112
+		$migrations_ran = $this->get_data_migrations_ran();
1113
+		if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) {
1114
+			return $migrations_ran[ $plugin_slug ][ $version ];
1115
+		} else {
1116
+			return null;
1117
+		}
1118
+	}
1119
+
1120
+	/**
1121
+	 * Resets the borked data migration scripts so they're no longer borked
1122
+	 * so we can again attempt to migrate
1123
+	 *
1124
+	 * @return bool
1125
+	 * @throws EE_Error
1126
+	 */
1127
+	public function reattempt()
1128
+	{
1129
+		// find if the last-ran script was borked
1130
+		// set it as being non-borked (we shouldn't ever get DMSs that we don't recognize)
1131
+		// add an 'error' saying that we attempted to reset
1132
+		// does it have a stage that was borked too? if so make it no longer borked
1133
+		// add an 'error' saying we attempted to reset
1134
+		$last_ran_script = $this->get_last_ran_script();
1135
+		if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) {
1136
+			// if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it)
1137
+			$last_ran_script->set_completed();
1138
+		} elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) {
1139
+			$last_ran_script->reattempt();
1140
+		} else {
1141
+			throw new EE_Error(
1142
+				sprintf(
1143
+					__(
1144
+						'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s',
1145
+						'event_espresso'
1146
+					),
1147
+					print_r($last_ran_script, true)
1148
+				)
1149
+			);
1150
+		}
1151
+		return $this->_save_migrations_ran();
1152
+	}
1153
+
1154
+	/**
1155
+	 * Gets whether or not this particular migration has run or not
1156
+	 *
1157
+	 * @param string $version     the version the DMS searched for migrates to. Usually just the content before the 3rd
1158
+	 *                            period. Eg '4.1.0'
1159
+	 * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc
1160
+	 * @return boolean
1161
+	 */
1162
+	public function migration_has_ran($version, $plugin_slug = 'Core')
1163
+	{
1164
+		return $this->get_migration_ran($version, $plugin_slug) !== null;
1165
+	}
1166
+
1167
+	/**
1168
+	 * Enqueues this ee plugin to have its data initialized
1169
+	 *
1170
+	 * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value
1171
+	 */
1172
+	public function enqueue_db_initialization_for($plugin_slug)
1173
+	{
1174
+		$queue = $this->get_db_initialization_queue();
1175
+		if (! in_array($plugin_slug, $queue)) {
1176
+			$queue[] = $plugin_slug;
1177
+		}
1178
+		update_option(self::db_init_queue_option_name, $queue);
1179
+	}
1180
+
1181
+	/**
1182
+	 * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon
1183
+	 * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is
1184
+	 * in the queue, calls EE_System::initialize_db_if_no_migrations_required().
1185
+	 */
1186
+	public function initialize_db_for_enqueued_ee_plugins()
1187
+	{
1188
+		$queue = $this->get_db_initialization_queue();
1189
+		foreach ($queue as $plugin_slug) {
1190
+			$most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug);
1191
+			if (! $most_up_to_date_dms) {
1192
+				// if there is NO DMS for this plugin, obviously there's no schema to verify anyways
1193
+				$verify_db = false;
1194
+			} else {
1195
+				$most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms);
1196
+				$verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to);
1197
+			}
1198
+			if ($plugin_slug == 'Core') {
1199
+				EE_System::instance()->initialize_db_if_no_migrations_required(
1200
+					false,
1201
+					$verify_db
1202
+				);
1203
+			} else {
1204
+				// just loop through the addons to make sure their database is setup
1205
+				foreach (EE_Registry::instance()->addons as $addon) {
1206
+					if ($addon->name() == $plugin_slug) {
1207
+						$addon->initialize_db_if_no_migrations_required($verify_db);
1208
+						break;
1209
+					}
1210
+				}
1211
+			}
1212
+		}
1213
+		// because we just initialized the DBs for the enqueued ee plugins
1214
+		// we don't need to keep remembering which ones needed to be initialized
1215
+		delete_option(self::db_init_queue_option_name);
1216
+	}
1217
+
1218
+	/**
1219
+	 * Gets a numerically-indexed array of plugin slugs that need to have their databases
1220
+	 * (re-)initialized after migrations are complete. ie, each element should be either
1221
+	 * 'Core', or the return value of EE_Addon::name() for an addon
1222
+	 *
1223
+	 * @return array
1224
+	 */
1225
+	public function get_db_initialization_queue()
1226
+	{
1227
+		return get_option(self::db_init_queue_option_name, array());
1228
+	}
1229
+
1230
+	/**
1231
+	 * Gets the injected table analyzer, or throws an exception
1232
+	 *
1233
+	 * @return TableAnalysis
1234
+	 * @throws EE_Error
1235
+	 */
1236
+	protected function _get_table_analysis()
1237
+	{
1238
+		if ($this->_table_analysis instanceof TableAnalysis) {
1239
+			return $this->_table_analysis;
1240
+		} else {
1241
+			throw new EE_Error(
1242
+				sprintf(
1243
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
1244
+					get_class($this)
1245
+				)
1246
+			);
1247
+		}
1248
+	}
1249
+
1250
+	/**
1251
+	 * Gets the injected table manager, or throws an exception
1252
+	 *
1253
+	 * @return TableManager
1254
+	 * @throws EE_Error
1255
+	 */
1256
+	protected function _get_table_manager()
1257
+	{
1258
+		if ($this->_table_manager instanceof TableManager) {
1259
+			return $this->_table_manager;
1260
+		} else {
1261
+			throw new EE_Error(
1262
+				sprintf(
1263
+					__('Table manager class on class %1$s is not set properly.', 'event_espresso'),
1264
+					get_class($this)
1265
+				)
1266
+			);
1267
+		}
1268
+	}
1269 1269
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
     public static function instance()
158 158
     {
159 159
         // check if class object is instantiated
160
-        if (! self::$_instance instanceof EE_Data_Migration_Manager) {
160
+        if ( ! self::$_instance instanceof EE_Data_Migration_Manager) {
161 161
             self::$_instance = new self();
162 162
         }
163 163
         return self::$_instance;
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
 
234 234
         if (count($parts) == 4) {
235 235
             // it's 4.2-style.eg Core.4.1.0
236
-            $plugin_slug = $parts[0];// eg Core
237
-            $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0
236
+            $plugin_slug = $parts[0]; // eg Core
237
+            $version_string = $parts[1].".".$parts[2].".".$parts[3]; // eg 4.1.0
238 238
         } else {
239 239
             // it's 4.1-style: eg 4.1.0
240 240
             $plugin_slug = 'Core';
241
-            $version_string = $plugin_slug_and_version_string;// eg 4.1.0
241
+            $version_string = $plugin_slug_and_version_string; // eg 4.1.0
242 242
         }
243 243
         return array($plugin_slug, $version_string);
244 244
     }
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function get_data_migrations_ran()
292 292
     {
293
-        if (! $this->_data_migrations_ran) {
293
+        if ( ! $this->_data_migrations_ran) {
294 294
             // setup autoloaders for each of the scripts in there
295 295
             $this->get_all_data_migration_scripts_available();
296 296
             $data_migrations_options = $this->get_all_migration_script_options(
297
-            );// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array()));
297
+            ); // get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array()));
298 298
 
299 299
             $data_migrations_ran = array();
300 300
             // convert into data migration script classes where possible
@@ -308,23 +308,23 @@  discard block
 block discarded – undo
308 308
                         $data_migration_option['option_name'],
309 309
                         $data_migration_option['option_value']
310 310
                     );
311
-                    $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class;
311
+                    $data_migrations_ran[$plugin_slug][$version_string] = $class;
312 312
                     // ok so far THIS is the 'last-ran-script'... unless we find another on next iteration
313 313
                     $this->_last_ran_script = $class;
314
-                    if (! $class->is_completed()) {
314
+                    if ( ! $class->is_completed()) {
315 315
                         // sometimes we also like to know which was the last incomplete script (or if there are any at all)
316 316
                         $this->_last_ran_incomplete_script = $class;
317 317
                     }
318 318
                 } catch (EE_Error $e) {
319 319
                     // ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs
320
-                    $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize(
320
+                    $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize(
321 321
                         $data_migration_option['option_value']
322 322
                     );
323 323
                 }
324 324
             }
325 325
             // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays
326 326
             $this->_data_migrations_ran = $data_migrations_ran;
327
-            if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) {
327
+            if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) {
328 328
                 $this->_data_migrations_ran = array();
329 329
             }
330 330
         }
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
     {
358 358
         global $wpdb;
359 359
         return $wpdb->get_results(
360
-            "SELECT * FROM {$wpdb->options} WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id ASC",
360
+            "SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",
361 361
             ARRAY_A
362 362
         );
363 363
     }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
     {
373 373
         return apply_filters(
374 374
             'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',
375
-            array('Core' => EE_CORE . 'data_migration_scripts')
375
+            array('Core' => EE_CORE.'data_migration_scripts')
376 376
         );
377 377
     }
378 378
 
@@ -388,15 +388,15 @@  discard block
 block discarded – undo
388 388
      */
389 389
     public function script_migrates_to_version($migration_script_name, $eeAddonClass = '')
390 390
     {
391
-        if (isset($this->script_migration_versions[ $migration_script_name ])) {
392
-            return $this->script_migration_versions[ $migration_script_name ];
391
+        if (isset($this->script_migration_versions[$migration_script_name])) {
392
+            return $this->script_migration_versions[$migration_script_name];
393 393
         }
394 394
         $dms_info = $this->parse_dms_classname($migration_script_name);
395
-        $this->script_migration_versions[ $migration_script_name ] = array(
395
+        $this->script_migration_versions[$migration_script_name] = array(
396 396
             'slug'    => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'],
397
-            'version' => $dms_info['major_version'] . "." . $dms_info['minor_version'] . "." . $dms_info['micro_version'],
397
+            'version' => $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'],
398 398
         );
399
-        return $this->script_migration_versions[ $migration_script_name ];
399
+        return $this->script_migration_versions[$migration_script_name];
400 400
     }
401 401
 
402 402
     /**
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
     {
411 411
         $matches = array();
412 412
         preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches);
413
-        if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) {
413
+        if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) {
414 414
             throw new EE_Error(
415 415
                 sprintf(
416 416
                     __(
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
     {
442 442
         $espresso_db_core_updates = get_option('espresso_db_update', array());
443 443
         $db_state = get_option(EE_Data_Migration_Manager::current_database_state);
444
-        if (! $db_state) {
444
+        if ( ! $db_state) {
445 445
             // mark the DB as being in the state as the last version in there.
446 446
             // this is done to trigger maintenance mode and do data migration scripts
447 447
             // if the admin installed this version of EE over 3.1.x or 4.0.x
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
         // in 4.1, $db_state would have only been a simple string like '4.1.0',
461 461
         // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's
462 462
         // db, and possibly other keys for other addons like 'Calendar','Permissions',etc
463
-        if (! is_array($db_state)) {
463
+        if ( ! is_array($db_state)) {
464 464
             $db_state = array('Core' => $db_state);
465 465
             update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
466 466
         }
@@ -497,29 +497,29 @@  discard block
 block discarded – undo
497 497
                 $script_converts_plugin_slug = $migrates_to_version['slug'];
498 498
                 $script_converts_to_version = $migrates_to_version['version'];
499 499
                 // check if this version script is DONE or not; or if it's never been ran
500
-                if (! $scripts_ran ||
501
-                    ! isset($scripts_ran[ $script_converts_plugin_slug ]) ||
502
-                    ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ])) {
500
+                if ( ! $scripts_ran ||
501
+                    ! isset($scripts_ran[$script_converts_plugin_slug]) ||
502
+                    ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) {
503 503
                     // we haven't ran this conversion script before
504 504
                     // now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available
505 505
                     $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis());
506 506
                     /* @var $script EE_Data_Migration_Script_Base */
507 507
                     $can_migrate = $script->can_migrate_from_version($theoretical_database_state);
508 508
                     if ($can_migrate) {
509
-                        $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script;
509
+                        $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script;
510 510
                         $migrates_to_version = $script->migrates_to_version();
511
-                        $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version'];
512
-                        unset($script_class_and_filepaths_available[ $classname ]);
511
+                        $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version'];
512
+                        unset($script_class_and_filepaths_available[$classname]);
513 513
                     }
514
-                } elseif ($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] instanceof EE_Data_Migration_Script_Base) {
514
+                } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) {
515 515
                     // this script has been ran, or at least started
516
-                    $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ];
516
+                    $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version];
517 517
                     if ($script->get_status() != self::status_completed) {
518 518
                         // this script is already underway... keep going with it
519
-                        $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script;
519
+                        $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script;
520 520
                         $migrates_to_version = $script->migrates_to_version();
521
-                        $next_database_state_to_consider[ $migrates_to_version['slug'] ] = $migrates_to_version['version'];
522
-                        unset($script_class_and_filepaths_available[ $classname ]);
521
+                        $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version'];
522
+                        unset($script_class_and_filepaths_available[$classname]);
523 523
                     } else {
524 524
                         // it must have a status that indicates it has finished, so we don't want to try and run it again
525 525
                     }
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
                 }
531 531
             }
532 532
             $iteration++;
533
-        } while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6);
533
+        }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6);
534 534
         // ok we have all the scripts that should run, now let's make them into flat array
535 535
         $scripts_that_should_run = array();
536 536
         foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) {
537 537
             ksort($scripts_at_priority);
538 538
             foreach ($scripts_at_priority as $scripts) {
539 539
                 foreach ($scripts as $script) {
540
-                    $scripts_that_should_run[ get_class($script) ] = $script;
540
+                    $scripts_that_should_run[get_class($script)] = $script;
541 541
                 }
542 542
             }
543 543
         }
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
     public function get_last_ran_script($include_completed_scripts = false)
563 563
     {
564 564
         // make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script
565
-        if (! $this->_data_migrations_ran) {
565
+        if ( ! $this->_data_migrations_ran) {
566 566
             $this->get_data_migrations_ran();
567 567
         }
568 568
         if ($include_completed_scripts) {
@@ -599,10 +599,10 @@  discard block
 block discarded – undo
599 599
 
600 600
         try {
601 601
             $currently_executing_script = $this->get_last_ran_script();
602
-            if (! $currently_executing_script) {
602
+            if ( ! $currently_executing_script) {
603 603
                 // Find the next script that needs to execute
604 604
                 $scripts = $this->check_for_applicable_data_migration_scripts();
605
-                if (! $scripts) {
605
+                if ( ! $scripts) {
606 606
                     // huh, no more scripts to run... apparently we're done!
607 607
                     // but dont forget to make sure initial data is there
608 608
                     // we should be good to allow them to exit maintenance mode now
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
                 $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script));
629 629
                 $plugin_slug = $migrates_to['slug'];
630 630
                 $version = $migrates_to['version'];
631
-                $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script;
631
+                $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script;
632 632
             }
633 633
             $current_script_name = get_class($currently_executing_script);
634 634
         } catch (Exception $e) {
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 
637 637
             $message = sprintf(
638 638
                 __("Error Message: %sStack Trace:%s", "event_espresso"),
639
-                $e->getMessage() . '<br>',
639
+                $e->getMessage().'<br>',
640 640
                 $e->getTraceAsString()
641 641
             );
642 642
             // record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
                     );
689 689
                     // check if there are any more after this one.
690 690
                     $scripts_remaining = $this->check_for_applicable_data_migration_scripts();
691
-                    if (! $scripts_remaining) {
691
+                    if ( ! $scripts_remaining) {
692 692
                         // we should be good to allow them to exit maintenance mode now
693 693
                         EE_Maintenance_Mode::instance()->set_maintenance_level(
694 694
                             intval(EE_Maintenance_Mode::level_0_not_in_maintenance)
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
                 ),
789 789
                 'script'             => 'Unknown',
790 790
             );
791
-            $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString());
791
+            $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString());
792 792
         }
793 793
         $warnings_etc = @ob_get_contents();
794 794
         ob_end_clean();
@@ -808,12 +808,12 @@  discard block
 block discarded – undo
808 808
      */
809 809
     public function update_current_database_state_to($slug_and_version = null)
810 810
     {
811
-        if (! $slug_and_version) {
811
+        if ( ! $slug_and_version) {
812 812
             // no version was provided, assume it should be at the current code version
813 813
             $slug_and_version = array('slug' => 'Core', 'version' => espresso_version());
814 814
         }
815 815
         $current_database_state = get_option(self::current_database_state);
816
-        $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version'];
816
+        $current_database_state[$slug_and_version['slug']] = $slug_and_version['version'];
817 817
         update_option(self::current_database_state, $current_database_state);
818 818
     }
819 819
 
@@ -832,15 +832,15 @@  discard block
 block discarded – undo
832 832
         $slug = $slug_and_version['slug'];
833 833
         $version = $slug_and_version['version'];
834 834
         $current_database_state = get_option(self::current_database_state);
835
-        if (! isset($current_database_state[ $slug ])) {
835
+        if ( ! isset($current_database_state[$slug])) {
836 836
             return true;
837 837
         } else {
838 838
             // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes
839
-            $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3);
839
+            $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3);
840 840
             $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3);
841 841
             $needs_updating = false;
842 842
             foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) {
843
-                if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) {
843
+                if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) {
844 844
                     $needs_updating = true;
845 845
                     break;
846 846
                 }
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
      */
863 863
     public function get_all_data_migration_scripts_available()
864 864
     {
865
-        if (! $this->_data_migration_class_to_filepath_map) {
865
+        if ( ! $this->_data_migration_class_to_filepath_map) {
866 866
             $this->_data_migration_class_to_filepath_map = array();
867 867
             foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) {
868 868
                 // strip any placeholders added to classname to make it a unique array key
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
                     ? $eeAddonClass
872 872
                     : '';
873 873
                 $folder_path = EEH_File::end_with_directory_separator($folder_path);
874
-                $files = glob($folder_path . '*.dms.php');
874
+                $files = glob($folder_path.'*.dms.php');
875 875
                 if (empty($files)) {
876 876
                     continue;
877 877
                 }
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                             '4.3.0.alpha.019'
898 898
                         );
899 899
                     }
900
-                    $this->_data_migration_class_to_filepath_map[ $classname ] = $file;
900
+                    $this->_data_migration_class_to_filepath_map[$classname] = $file;
901 901
                 }
902 902
             }
903 903
             EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map);
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
         // get last-ran migration script
930 930
         global $wpdb;
931 931
         $last_migration_script_option = $wpdb->get_row(
932
-            "SELECT * FROM $wpdb->options WHERE option_name like '" . EE_Data_Migration_Manager::data_migration_script_option_prefix . "%' ORDER BY option_id DESC LIMIT 1",
932
+            "SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",
933 933
             ARRAY_A
934 934
         );
935 935
 
@@ -961,10 +961,10 @@  discard block
 block discarded – undo
961 961
             $versions_migrated_to = 'Unknown.1.0.0';
962 962
             // now just to make sure appears as last (in case the were previously a fatal error like this)
963 963
             // delete the old one
964
-            delete_option(self::data_migration_script_option_prefix . $versions_migrated_to);
964
+            delete_option(self::data_migration_script_option_prefix.$versions_migrated_to);
965 965
         }
966 966
         update_option(
967
-            self::data_migration_script_option_prefix . $versions_migrated_to,
967
+            self::data_migration_script_option_prefix.$versions_migrated_to,
968 968
             $last_ran_migration_script_properties
969 969
         );
970 970
     }
@@ -983,8 +983,8 @@  discard block
 block discarded – undo
983 983
         $successful_updates = true;
984 984
         foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) {
985 985
             foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) {
986
-                $plugin_slug_for_use_in_option_name = $plugin_slug . ".";
987
-                $option_name = self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string;
986
+                $plugin_slug_for_use_in_option_name = $plugin_slug.".";
987
+                $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string;
988 988
                 $old_option_value = get_option($option_name);
989 989
                 if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) {
990 990
                     $script_array_for_saving = $array_or_migration_obj->properties_as_array();
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
                         $successful_updates = update_option($option_name, $array_or_migration_obj);
997 997
                     }
998 998
                 }
999
-                if (! $successful_updates) {
999
+                if ( ! $successful_updates) {
1000 1000
                     global $wpdb;
1001 1001
                     return $wpdb->last_error;
1002 1002
                 }
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
      */
1031 1031
     public function _instantiate_script_from_properties_array($properties_array)
1032 1032
     {
1033
-        if (! isset($properties_array['class'])) {
1033
+        if ( ! isset($properties_array['class'])) {
1034 1034
             throw new EE_Error(
1035 1035
                 sprintf(
1036 1036
                     __("Properties array  has no 'class' properties. Here's what it has: %s", "event_espresso"),
@@ -1039,11 +1039,11 @@  discard block
 block discarded – undo
1039 1039
             );
1040 1040
         }
1041 1041
         $class_name = $properties_array['class'];
1042
-        if (! class_exists($class_name)) {
1042
+        if ( ! class_exists($class_name)) {
1043 1043
             throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name));
1044 1044
         }
1045 1045
         $class = new $class_name;
1046
-        if (! $class instanceof EE_Data_Migration_Script_Base) {
1046
+        if ( ! $class instanceof EE_Data_Migration_Script_Base) {
1047 1047
             throw new EE_Error(
1048 1048
                 sprintf(
1049 1049
                     __("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),
@@ -1110,8 +1110,8 @@  discard block
 block discarded – undo
1110 1110
     public function get_migration_ran($version, $plugin_slug = 'Core')
1111 1111
     {
1112 1112
         $migrations_ran = $this->get_data_migrations_ran();
1113
-        if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) {
1114
-            return $migrations_ran[ $plugin_slug ][ $version ];
1113
+        if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) {
1114
+            return $migrations_ran[$plugin_slug][$version];
1115 1115
         } else {
1116 1116
             return null;
1117 1117
         }
@@ -1172,7 +1172,7 @@  discard block
 block discarded – undo
1172 1172
     public function enqueue_db_initialization_for($plugin_slug)
1173 1173
     {
1174 1174
         $queue = $this->get_db_initialization_queue();
1175
-        if (! in_array($plugin_slug, $queue)) {
1175
+        if ( ! in_array($plugin_slug, $queue)) {
1176 1176
             $queue[] = $plugin_slug;
1177 1177
         }
1178 1178
         update_option(self::db_init_queue_option_name, $queue);
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
         $queue = $this->get_db_initialization_queue();
1189 1189
         foreach ($queue as $plugin_slug) {
1190 1190
             $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug);
1191
-            if (! $most_up_to_date_dms) {
1191
+            if ( ! $most_up_to_date_dms) {
1192 1192
                 // if there is NO DMS for this plugin, obviously there's no schema to verify anyways
1193 1193
                 $verify_db = false;
1194 1194
             } else {
Please login to merge, or discard this patch.
core/espresso_definitions.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
 define('EE_SUPPORT_EMAIL', '[email protected]');
8 8
 // used to be DIRECTORY_SEPARATOR, but that caused issues on windows
9 9
 if (! defined('DS')) {
10
-    define('DS', '/');
10
+	define('DS', '/');
11 11
 }
12 12
 if (! defined('PS')) {
13
-    define('PS', PATH_SEPARATOR);
13
+	define('PS', PATH_SEPARATOR);
14 14
 }
15 15
 if (! defined('SP')) {
16
-    define('SP', ' ');
16
+	define('SP', ' ');
17 17
 }
18 18
 if (! defined('EENL')) {
19
-    define('EENL', "\n");
19
+	define('EENL', "\n");
20 20
 }
21 21
 // define the plugin directory and URL
22 22
 define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
@@ -70,16 +70,16 @@  discard block
 block discarded – undo
70 70
 define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
71 71
 // check for DOMPDF fonts in uploads
72 72
 if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
73
-    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
73
+	define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
74 74
 }
75 75
 // ajax constants
76 76
 define(
77
-    'EE_FRONT_AJAX',
78
-    isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax'])
77
+	'EE_FRONT_AJAX',
78
+	isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax'])
79 79
 );
80 80
 define(
81
-    'EE_ADMIN_AJAX',
82
-    isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax'])
81
+	'EE_ADMIN_AJAX',
82
+	isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax'])
83 83
 );
84 84
 // just a handy constant occasionally needed for finding values representing infinity in the DB
85 85
 // you're better to use this than its straight value (currently -1) in case you ever
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 define('EE_INF_IN_DB', -1);
88 88
 define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
89 89
 if (! defined('EE_DEBUG')) {
90
-    define('EE_DEBUG', false);
90
+	define('EE_DEBUG', false);
91 91
 }
92 92
 // for older WP versions
93 93
 if (! defined('MONTH_IN_SECONDS')) {
94
-    define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
94
+	define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
95 95
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -6,71 +6,71 @@  discard block
 block discarded – undo
6 6
 define('EE_MIN_PHP_VER_RECOMMENDED', '5.6.32');
7 7
 define('EE_SUPPORT_EMAIL', '[email protected]');
8 8
 // used to be DIRECTORY_SEPARATOR, but that caused issues on windows
9
-if (! defined('DS')) {
9
+if ( ! defined('DS')) {
10 10
     define('DS', '/');
11 11
 }
12
-if (! defined('PS')) {
12
+if ( ! defined('PS')) {
13 13
     define('PS', PATH_SEPARATOR);
14 14
 }
15
-if (! defined('SP')) {
15
+if ( ! defined('SP')) {
16 16
     define('SP', ' ');
17 17
 }
18
-if (! defined('EENL')) {
18
+if ( ! defined('EENL')) {
19 19
     define('EENL', "\n");
20 20
 }
21 21
 // define the plugin directory and URL
22 22
 define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
23
-define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . DS);
23
+define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).DS);
24 24
 define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
25 25
 // main root folder paths
26
-define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
27
-define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
28
-define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
29
-define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
30
-define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
31
-define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
32
-define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
33
-define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
26
+define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS);
27
+define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS);
28
+define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS);
29
+define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS);
30
+define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS);
31
+define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS);
32
+define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS);
33
+define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS);
34 34
 // core system paths
35
-define('EE_ADMIN', EE_CORE . 'admin' . DS);
36
-define('EE_CPTS', EE_CORE . 'CPTs' . DS);
37
-define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
38
-define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
39
-define('EE_BUSINESS', EE_CORE . 'business' . DS);
40
-define('EE_MODELS', EE_CORE . 'db_models' . DS);
41
-define('EE_HELPERS', EE_CORE . 'helpers' . DS);
42
-define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
43
-define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
44
-define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
45
-define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
46
-define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
35
+define('EE_ADMIN', EE_CORE.'admin'.DS);
36
+define('EE_CPTS', EE_CORE.'CPTs'.DS);
37
+define('EE_CLASSES', EE_CORE.'db_classes'.DS);
38
+define('EE_INTERFACES', EE_CORE.'interfaces'.DS);
39
+define('EE_BUSINESS', EE_CORE.'business'.DS);
40
+define('EE_MODELS', EE_CORE.'db_models'.DS);
41
+define('EE_HELPERS', EE_CORE.'helpers'.DS);
42
+define('EE_LIBRARIES', EE_CORE.'libraries'.DS);
43
+define('EE_TEMPLATES', EE_CORE.'templates'.DS);
44
+define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS);
45
+define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS);
46
+define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS);
47 47
 // gateways
48
-define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
49
-define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
48
+define('EE_GATEWAYS', EE_MODULES.'gateways'.DS);
49
+define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS);
50 50
 // asset URL paths
51
-define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
52
-define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
53
-define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
54
-define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
55
-define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
56
-define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
51
+define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS);
52
+define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS);
53
+define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS);
54
+define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS);
55
+define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/');
56
+define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/');
57 57
 // define upload paths
58 58
 $uploads = wp_upload_dir();
59 59
 // define the uploads directory and URL
60
-define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
61
-define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
60
+define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS);
61
+define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS);
62 62
 // define the templates directory and URL
63
-define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
64
-define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
63
+define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS);
64
+define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS);
65 65
 // define the gateway directory and URL
66
-define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
67
-define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
66
+define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS);
67
+define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS);
68 68
 // languages folder/path
69
-define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
70
-define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
69
+define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS);
70
+define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS);
71 71
 // check for DOMPDF fonts in uploads
72
-if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
73
-    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
72
+if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) {
73
+    define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS);
74 74
 }
75 75
 // ajax constants
76 76
 define(
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
 // want to change its default value! or find when -1 means infinity
87 87
 define('EE_INF_IN_DB', -1);
88 88
 define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
89
-if (! defined('EE_DEBUG')) {
89
+if ( ! defined('EE_DEBUG')) {
90 90
     define('EE_DEBUG', false);
91 91
 }
92 92
 // for older WP versions
93
-if (! defined('MONTH_IN_SECONDS')) {
93
+if ( ! defined('MONTH_IN_SECONDS')) {
94 94
     define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
95 95
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 2 patches
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -27,268 +27,268 @@
 block discarded – undo
27 27
 class InvisibleRecaptcha
28 28
 {
29 29
 
30
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
30
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
31 31
 
32
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
32
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
33 33
 
34
-    /**
35
-     * @var EE_Registration_Config $config
36
-     */
37
-    private $config;
34
+	/**
35
+	 * @var EE_Registration_Config $config
36
+	 */
37
+	private $config;
38 38
 
39
-    /**
40
-     * @var EE_Session $session
41
-     */
42
-    private $session;
39
+	/**
40
+	 * @var EE_Session $session
41
+	 */
42
+	private $session;
43 43
 
44
-    /**
45
-     * @var boolean $recaptcha_passed
46
-     */
47
-    private $recaptcha_passed;
44
+	/**
45
+	 * @var boolean $recaptcha_passed
46
+	 */
47
+	private $recaptcha_passed;
48 48
 
49 49
 
50
-    /**
51
-     * InvisibleRecaptcha constructor.
52
-     *
53
-     * @param EE_Registration_Config $registration_config
54
-     * @param EE_Session             $session
55
-     */
56
-    public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
-    {
58
-        $this->config = $registration_config;
59
-        $this->session = $session;
60
-    }
50
+	/**
51
+	 * InvisibleRecaptcha constructor.
52
+	 *
53
+	 * @param EE_Registration_Config $registration_config
54
+	 * @param EE_Session             $session
55
+	 */
56
+	public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
+	{
58
+		$this->config = $registration_config;
59
+		$this->session = $session;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return boolean
65
-     */
66
-    public function useInvisibleRecaptcha()
67
-    {
68
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
-    }
63
+	/**
64
+	 * @return boolean
65
+	 */
66
+	public function useInvisibleRecaptcha()
67
+	{
68
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * @param array $input_settings
74
-     * @return EE_Invisible_Recaptcha_Input
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws InvalidArgumentException
78
-     * @throws DomainException
79
-     */
80
-    public function getInput(array $input_settings = array())
81
-    {
82
-        return new EE_Invisible_Recaptcha_Input(
83
-            $input_settings,
84
-            $this->config
85
-        );
86
-    }
72
+	/**
73
+	 * @param array $input_settings
74
+	 * @return EE_Invisible_Recaptcha_Input
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws InvalidArgumentException
78
+	 * @throws DomainException
79
+	 */
80
+	public function getInput(array $input_settings = array())
81
+	{
82
+		return new EE_Invisible_Recaptcha_Input(
83
+			$input_settings,
84
+			$this->config
85
+		);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * @param array $input_settings
91
-     * @return string
92
-     * @throws EE_Error
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidArgumentException
96
-     * @throws DomainException
97
-     */
98
-    public function getInputHtml(array $input_settings = array())
99
-    {
100
-        return $this->getInput($input_settings)->get_html_for_input();
101
-    }
89
+	/**
90
+	 * @param array $input_settings
91
+	 * @return string
92
+	 * @throws EE_Error
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidArgumentException
96
+	 * @throws DomainException
97
+	 */
98
+	public function getInputHtml(array $input_settings = array())
99
+	{
100
+		return $this->getInput($input_settings)->get_html_for_input();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @param EE_Form_Section_Proper $form
106
-     * @param array                  $input_settings
107
-     * @throws EE_Error
108
-     * @throws InvalidArgumentException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws DomainException
112
-     */
113
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
-    {
115
-        $form->add_subsections(
116
-            array(
117
-                'espresso_recaptcha' => $this->getInput($input_settings),
118
-            ),
119
-            null,
120
-            false
121
-        );
122
-    }
104
+	/**
105
+	 * @param EE_Form_Section_Proper $form
106
+	 * @param array                  $input_settings
107
+	 * @throws EE_Error
108
+	 * @throws InvalidArgumentException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws DomainException
112
+	 */
113
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
+	{
115
+		$form->add_subsections(
116
+			array(
117
+				'espresso_recaptcha' => $this->getInput($input_settings),
118
+			),
119
+			null,
120
+			false
121
+		);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * @param RequestInterface $request
127
-     * @return boolean
128
-     * @throws InvalidArgumentException
129
-     * @throws InvalidDataTypeException
130
-     * @throws InvalidInterfaceException
131
-     * @throws RuntimeException
132
-     */
133
-    public function verifyToken(RequestInterface $request)
134
-    {
135
-        static $previous_recaptcha_response = array();
136
-        $grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137
-        // if this token has already been verified, then return previous response
138
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
-            return $previous_recaptcha_response[ $grecaptcha_response ];
140
-        }
141
-        // still here but no g-recaptcha-response ? - verification failed
142
-        if (! $grecaptcha_response) {
143
-            EE_Error::add_error(
144
-                sprintf(
145
-                    /* translators: 1: missing parameter */
146
-                    esc_html__(
147
-                        // @codingStandardsIgnoreStart
148
-                        'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.',
149
-                        // @codingStandardsIgnoreEnd
150
-                        'event_espresso'
151
-                    ),
152
-                    'g-recaptcha-response'
153
-                ),
154
-                __FILE__,
155
-                __FUNCTION__,
156
-                __LINE__
157
-            );
158
-            return false;
159
-        }
160
-        // will update to true if everything passes
161
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
162
-        $response                                            = wp_safe_remote_post(
163
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164
-            array(
165
-                'body' => array(
166
-                    'secret'   => $this->config->recaptcha_privatekey,
167
-                    'response' => $grecaptcha_response,
168
-                    'remoteip' => $request->ipAddress(),
169
-                ),
170
-            )
171
-        );
172
-        if ($response instanceof WP_Error) {
173
-            $this->generateError($response->get_error_messages());
174
-            return false;
175
-        }
176
-        $results = json_decode(wp_remote_retrieve_body($response), true);
177
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
-            $errors   = array_map(
179
-                array($this, 'getErrorCode'),
180
-                $results['error-codes']
181
-            );
182
-            if (isset($results['challenge_ts'])) {
183
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
184
-            }
185
-            $this->generateError(implode(' ', $errors), true);
186
-        }
187
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
188
-        add_action('shutdown', array($this, 'setSessionData'));
189
-        return true;
190
-    }
125
+	/**
126
+	 * @param RequestInterface $request
127
+	 * @return boolean
128
+	 * @throws InvalidArgumentException
129
+	 * @throws InvalidDataTypeException
130
+	 * @throws InvalidInterfaceException
131
+	 * @throws RuntimeException
132
+	 */
133
+	public function verifyToken(RequestInterface $request)
134
+	{
135
+		static $previous_recaptcha_response = array();
136
+		$grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137
+		// if this token has already been verified, then return previous response
138
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
+			return $previous_recaptcha_response[ $grecaptcha_response ];
140
+		}
141
+		// still here but no g-recaptcha-response ? - verification failed
142
+		if (! $grecaptcha_response) {
143
+			EE_Error::add_error(
144
+				sprintf(
145
+					/* translators: 1: missing parameter */
146
+					esc_html__(
147
+						// @codingStandardsIgnoreStart
148
+						'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.',
149
+						// @codingStandardsIgnoreEnd
150
+						'event_espresso'
151
+					),
152
+					'g-recaptcha-response'
153
+				),
154
+				__FILE__,
155
+				__FUNCTION__,
156
+				__LINE__
157
+			);
158
+			return false;
159
+		}
160
+		// will update to true if everything passes
161
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
162
+		$response                                            = wp_safe_remote_post(
163
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164
+			array(
165
+				'body' => array(
166
+					'secret'   => $this->config->recaptcha_privatekey,
167
+					'response' => $grecaptcha_response,
168
+					'remoteip' => $request->ipAddress(),
169
+				),
170
+			)
171
+		);
172
+		if ($response instanceof WP_Error) {
173
+			$this->generateError($response->get_error_messages());
174
+			return false;
175
+		}
176
+		$results = json_decode(wp_remote_retrieve_body($response), true);
177
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
+			$errors   = array_map(
179
+				array($this, 'getErrorCode'),
180
+				$results['error-codes']
181
+			);
182
+			if (isset($results['challenge_ts'])) {
183
+				$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
184
+			}
185
+			$this->generateError(implode(' ', $errors), true);
186
+		}
187
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
188
+		add_action('shutdown', array($this, 'setSessionData'));
189
+		return true;
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * @param string $error_response
195
-     * @param bool   $show_errors
196
-     * @return void
197
-     * @throws RuntimeException
198
-     */
199
-    public function generateError($error_response = '', $show_errors = false)
200
-    {
201
-        throw new RuntimeException(
202
-            sprintf(
203
-                esc_html__(
204
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
205
-                    'event_espresso'
206
-                ),
207
-                '<br />',
208
-                $show_errors || current_user_can('manage_options') ? $error_response : ''
209
-            )
210
-        );
211
-    }
193
+	/**
194
+	 * @param string $error_response
195
+	 * @param bool   $show_errors
196
+	 * @return void
197
+	 * @throws RuntimeException
198
+	 */
199
+	public function generateError($error_response = '', $show_errors = false)
200
+	{
201
+		throw new RuntimeException(
202
+			sprintf(
203
+				esc_html__(
204
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
205
+					'event_espresso'
206
+				),
207
+				'<br />',
208
+				$show_errors || current_user_can('manage_options') ? $error_response : ''
209
+			)
210
+		);
211
+	}
212 212
 
213 213
 
214
-    /**
215
-     * @param string $error_code
216
-     * @return string
217
-     */
218
-    public function getErrorCode(&$error_code)
219
-    {
220
-        $error_codes = array(
221
-            'missing-input-secret'   => 'The secret parameter is missing.',
222
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
223
-            'missing-input-response' => 'The response parameter is missing.',
224
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
225
-            'bad-request'            => 'The request is invalid or malformed.',
226
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227
-        );
228
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
229
-    }
214
+	/**
215
+	 * @param string $error_code
216
+	 * @return string
217
+	 */
218
+	public function getErrorCode(&$error_code)
219
+	{
220
+		$error_codes = array(
221
+			'missing-input-secret'   => 'The secret parameter is missing.',
222
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
223
+			'missing-input-response' => 'The response parameter is missing.',
224
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
225
+			'bad-request'            => 'The request is invalid or malformed.',
226
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227
+		);
228
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
229
+	}
230 230
 
231 231
 
232
-    /**
233
-     * @return array
234
-     * @throws InvalidInterfaceException
235
-     * @throws InvalidDataTypeException
236
-     * @throws InvalidArgumentException
237
-     */
238
-    public function getLocalizedVars()
239
-    {
240
-        return (array) apply_filters(
241
-            'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
242
-            array(
243
-                'siteKey'          => $this->config->recaptcha_publickey,
244
-                'recaptcha_passed' => $this->recaptchaPassed(),
245
-                'wp_debug'         => WP_DEBUG,
246
-                'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
247
-                'failed_message'   => esc_html__(
248
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.',
249
-                    'event_espresso'
250
-                )
251
-            )
252
-        );
253
-    }
232
+	/**
233
+	 * @return array
234
+	 * @throws InvalidInterfaceException
235
+	 * @throws InvalidDataTypeException
236
+	 * @throws InvalidArgumentException
237
+	 */
238
+	public function getLocalizedVars()
239
+	{
240
+		return (array) apply_filters(
241
+			'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
242
+			array(
243
+				'siteKey'          => $this->config->recaptcha_publickey,
244
+				'recaptcha_passed' => $this->recaptchaPassed(),
245
+				'wp_debug'         => WP_DEBUG,
246
+				'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
247
+				'failed_message'   => esc_html__(
248
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.',
249
+					'event_espresso'
250
+				)
251
+			)
252
+		);
253
+	}
254 254
 
255 255
 
256
-    /**
257
-     * @return boolean
258
-     * @throws InvalidInterfaceException
259
-     * @throws InvalidDataTypeException
260
-     * @throws InvalidArgumentException
261
-     */
262
-    public function recaptchaPassed()
263
-    {
264
-        if ($this->recaptcha_passed !== null) {
265
-            return $this->recaptcha_passed;
266
-        }
267
-        // logged in means you have already passed a turing test of sorts
268
-        if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
269
-            $this->recaptcha_passed = true;
270
-            return $this->recaptcha_passed;
271
-        }
272
-        // was test already passed?
273
-        $this->recaptcha_passed = filter_var(
274
-            $this->session->get_session_data(
275
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
276
-            ),
277
-            FILTER_VALIDATE_BOOLEAN
278
-        );
279
-        return $this->recaptcha_passed;
280
-    }
256
+	/**
257
+	 * @return boolean
258
+	 * @throws InvalidInterfaceException
259
+	 * @throws InvalidDataTypeException
260
+	 * @throws InvalidArgumentException
261
+	 */
262
+	public function recaptchaPassed()
263
+	{
264
+		if ($this->recaptcha_passed !== null) {
265
+			return $this->recaptcha_passed;
266
+		}
267
+		// logged in means you have already passed a turing test of sorts
268
+		if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
269
+			$this->recaptcha_passed = true;
270
+			return $this->recaptcha_passed;
271
+		}
272
+		// was test already passed?
273
+		$this->recaptcha_passed = filter_var(
274
+			$this->session->get_session_data(
275
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
276
+			),
277
+			FILTER_VALIDATE_BOOLEAN
278
+		);
279
+		return $this->recaptcha_passed;
280
+	}
281 281
 
282 282
 
283
-    /**
284
-     * @throws InvalidArgumentException
285
-     * @throws InvalidDataTypeException
286
-     * @throws InvalidInterfaceException
287
-     */
288
-    public function setSessionData()
289
-    {
290
-        $this->session->set_session_data(
291
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
292
-        );
293
-    }
283
+	/**
284
+	 * @throws InvalidArgumentException
285
+	 * @throws InvalidDataTypeException
286
+	 * @throws InvalidInterfaceException
287
+	 */
288
+	public function setSessionData()
289
+	{
290
+		$this->session->set_session_data(
291
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
292
+		);
293
+	}
294 294
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
         static $previous_recaptcha_response = array();
136 136
         $grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137 137
         // if this token has already been verified, then return previous response
138
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
-            return $previous_recaptcha_response[ $grecaptcha_response ];
138
+        if (isset($previous_recaptcha_response[$grecaptcha_response])) {
139
+            return $previous_recaptcha_response[$grecaptcha_response];
140 140
         }
141 141
         // still here but no g-recaptcha-response ? - verification failed
142
-        if (! $grecaptcha_response) {
142
+        if ( ! $grecaptcha_response) {
143 143
             EE_Error::add_error(
144 144
                 sprintf(
145 145
                     /* translators: 1: missing parameter */
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             return false;
159 159
         }
160 160
         // will update to true if everything passes
161
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
161
+        $previous_recaptcha_response[$grecaptcha_response] = false;
162 162
         $response                                            = wp_safe_remote_post(
163 163
             InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164 164
             array(
@@ -175,16 +175,16 @@  discard block
 block discarded – undo
175 175
         }
176 176
         $results = json_decode(wp_remote_retrieve_body($response), true);
177 177
         if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
-            $errors   = array_map(
178
+            $errors = array_map(
179 179
                 array($this, 'getErrorCode'),
180 180
                 $results['error-codes']
181 181
             );
182 182
             if (isset($results['challenge_ts'])) {
183
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
183
+                $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.';
184 184
             }
185 185
             $this->generateError(implode(' ', $errors), true);
186 186
         }
187
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
187
+        $previous_recaptcha_response[$grecaptcha_response] = true;
188 188
         add_action('shutdown', array($this, 'setSessionData'));
189 189
         return true;
190 190
     }
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
             'bad-request'            => 'The request is invalid or malformed.',
226 226
             'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227 227
         );
228
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
228
+        return isset($error_codes[$error_code]) ? $error_codes[$error_code] : '';
229 229
     }
230 230
 
231 231
 
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_invoice_settings.dmsstage.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
     protected function _migration_step($num_items = 1)
53 53
     {
54 54
         // if this isn't set then something is really wrong
55
-        if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
55
+        if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
56 56
             throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
57 57
         }
58 58
         $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null;
59
-        if (! $invoice_settings) {
59
+        if ( ! $invoice_settings) {
60 60
             $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
61 61
         } else {
62 62
             $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
                 );
90 90
             }
91 91
             $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
92
-            $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
93
-            $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
92
+            $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true);
93
+            $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true);
94 94
             if ($overridden_invoice_body || $overridden_receipt_body) {
95 95
                 new PersistentAdminNotice(
96 96
                     'invoice_overriding_templates',
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -15,95 +15,95 @@
 block discarded – undo
15 15
 class EE_DMS_4_5_0_invoice_settings extends EE_Data_Migration_Script_Stage
16 16
 {
17 17
 
18
-    /**
19
-     * Just initializes the status of the migration
20
-     */
21
-    public function __construct()
22
-    {
23
-        $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso');
24
-        parent::__construct();
25
-    }
18
+	/**
19
+	 * Just initializes the status of the migration
20
+	 */
21
+	public function __construct()
22
+	{
23
+		$this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso');
24
+		parent::__construct();
25
+	}
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * _count_records_to_migrate
31
-     * Counts the records to migrate; the public version may cache it
32
-     *
33
-     * @access protected
34
-     * @return int
35
-     */
36
-    protected function _count_records_to_migrate()
37
-    {
38
-        return 1;
39
-    }
29
+	/**
30
+	 * _count_records_to_migrate
31
+	 * Counts the records to migrate; the public version may cache it
32
+	 *
33
+	 * @access protected
34
+	 * @return int
35
+	 */
36
+	protected function _count_records_to_migrate()
37
+	{
38
+		return 1;
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     *    _migration_step
45
-     *
46
-     * @access protected
47
-     * @param int $num_items
48
-     * @throws EE_Error
49
-     * @return int number of items ACTUALLY migrated
50
-     * @throws InvalidDataTypeException
51
-     */
52
-    protected function _migration_step($num_items = 1)
53
-    {
54
-        // if this isn't set then something is really wrong
55
-        if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
56
-            throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
57
-        }
58
-        $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null;
59
-        if (! $invoice_settings) {
60
-            $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
61
-        } else {
62
-            $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
63
-            $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to'];
64
-            $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address'];
65
-            $invoice_settings['template_invoice_email'] = '';
66
-            $invoice_settings['template_invoice_tax_number'] = '';
67
-            unset($invoice_settings['pdf_instructions']);
68
-            unset($invoice_settings['payable_to']);
69
-            unset($invoice_settings['payment_address']);
70
-            EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings;
71
-            EE_Config::instance()->update_espresso_config(false, false);
43
+	/**
44
+	 *    _migration_step
45
+	 *
46
+	 * @access protected
47
+	 * @param int $num_items
48
+	 * @throws EE_Error
49
+	 * @return int number of items ACTUALLY migrated
50
+	 * @throws InvalidDataTypeException
51
+	 */
52
+	protected function _migration_step($num_items = 1)
53
+	{
54
+		// if this isn't set then something is really wrong
55
+		if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
56
+			throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
57
+		}
58
+		$invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null;
59
+		if (! $invoice_settings) {
60
+			$this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
61
+		} else {
62
+			$invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
63
+			$invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to'];
64
+			$invoice_settings['template_invoice_address'] = $invoice_settings['payment_address'];
65
+			$invoice_settings['template_invoice_email'] = '';
66
+			$invoice_settings['template_invoice_tax_number'] = '';
67
+			unset($invoice_settings['pdf_instructions']);
68
+			unset($invoice_settings['payable_to']);
69
+			unset($invoice_settings['payment_address']);
70
+			EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings;
71
+			EE_Config::instance()->update_espresso_config(false, false);
72 72
 
73
-            // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice
74
-            // (why is it tough to change? because we want to update the receipt and invoice message template, but
75
-            // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
76
-            // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
77
-            // also we don't want to build a dependency on the messages code because it is likely to change soon
78
-            if (isset($invoice_settings['invoice_css'])
79
-                && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css'])) {
80
-                new PersistentAdminNotice(
81
-                    'invoice_css_not_updated',
82
-                    sprintf(
83
-                        esc_html__(
84
-                            'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.',
85
-                            'event_espresso'
86
-                        ),
87
-                        $invoice_settings['invoice_css']
88
-                    )
89
-                );
90
-            }
91
-            $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
92
-            $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
93
-            $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
94
-            if ($overridden_invoice_body || $overridden_receipt_body) {
95
-                new PersistentAdminNotice(
96
-                    'invoice_overriding_templates',
97
-                    esc_html__(
98
-                        'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
99
-                        'event_espresso'
100
-                    ),
101
-                    true
102
-                );
103
-            }
104
-        }
105
-        // regardless of whether it worked or not, we ought to continue the migration
106
-        $this->set_completed();
107
-        return 1;
108
-    }
73
+			// @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice
74
+			// (why is it tough to change? because we want to update the receipt and invoice message template, but
75
+			// message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
76
+			// update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
77
+			// also we don't want to build a dependency on the messages code because it is likely to change soon
78
+			if (isset($invoice_settings['invoice_css'])
79
+				&& ! in_array($invoice_settings['invoice_css'], ['', 'simple.css'])) {
80
+				new PersistentAdminNotice(
81
+					'invoice_css_not_updated',
82
+					sprintf(
83
+						esc_html__(
84
+							'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.',
85
+							'event_espresso'
86
+						),
87
+						$invoice_settings['invoice_css']
88
+					)
89
+				);
90
+			}
91
+			$templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
92
+			$overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
93
+			$overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
94
+			if ($overridden_invoice_body || $overridden_receipt_body) {
95
+				new PersistentAdminNotice(
96
+					'invoice_overriding_templates',
97
+					esc_html__(
98
+						'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
99
+						'event_espresso'
100
+					),
101
+					true
102
+				);
103
+			}
104
+		}
105
+		// regardless of whether it worked or not, we ought to continue the migration
106
+		$this->set_completed();
107
+		return 1;
108
+	}
109 109
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_prices.dmsstage.php 2 patches
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -87,57 +87,57 @@  discard block
 block discarded – undo
87 87
  */
88 88
 class EE_DMS_4_1_0_prices extends EE_Data_Migration_Script_Stage_Table
89 89
 {
90
-    private $_new_price_table;
91
-    private $_new_ticket_table;
92
-    private $_new_ticket_price_table;
93
-    private $_new_datetime_ticket_table;
94
-    /**
95
-     * A count of all the different tickets created, used for setting the new ones' TKT_Order
96
-     * @var int
97
-     */
98
-    private $_ticket_count = 0;
99
-    const price_type_base = 1;
100
-    const price_type_member_discount = 3;
101
-    const price_type_percent_surcharge = 4;
102
-    const price_type_flat_surcharge = 5;
90
+	private $_new_price_table;
91
+	private $_new_ticket_table;
92
+	private $_new_ticket_price_table;
93
+	private $_new_datetime_ticket_table;
94
+	/**
95
+	 * A count of all the different tickets created, used for setting the new ones' TKT_Order
96
+	 * @var int
97
+	 */
98
+	private $_ticket_count = 0;
99
+	const price_type_base = 1;
100
+	const price_type_member_discount = 3;
101
+	const price_type_percent_surcharge = 4;
102
+	const price_type_flat_surcharge = 5;
103 103
 
104
-    public function __construct()
105
-    {
106
-        global $wpdb;
107
-        $this->_pretty_name = __("Prices", "event_espresso");
108
-        $this->_old_table = $wpdb->prefix."events_prices";
109
-        $this->select_expression = 'p.*, e.event_status';
110
-        $this->_extra_where_sql = ' AS p 
104
+	public function __construct()
105
+	{
106
+		global $wpdb;
107
+		$this->_pretty_name = __("Prices", "event_espresso");
108
+		$this->_old_table = $wpdb->prefix."events_prices";
109
+		$this->select_expression = 'p.*, e.event_status';
110
+		$this->_extra_where_sql = ' AS p 
111 111
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id
112 112
             WHERE e.event_status!="D"';
113
-        $this->_new_price_table = $wpdb->prefix."esp_price";
114
-        $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
115
-        $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
116
-        $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
117
-        parent::__construct();
118
-    }
119
-    protected function _migrate_old_row($old_row)
120
-    {
121
-        // create the base price
122
-        $new_price_id = $this->_insert_new_price($old_row);
123
-        // create the member discount if there is any
124
-        // commented-out because we may actually NOT be supporting this in 4.1
113
+		$this->_new_price_table = $wpdb->prefix."esp_price";
114
+		$this->_new_ticket_table = $wpdb->prefix."esp_ticket";
115
+		$this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price";
116
+		$this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket";
117
+		parent::__construct();
118
+	}
119
+	protected function _migrate_old_row($old_row)
120
+	{
121
+		// create the base price
122
+		$new_price_id = $this->_insert_new_price($old_row);
123
+		// create the member discount if there is any
124
+		// commented-out because we may actually NOT be supporting this in 4.1
125 125
 //      if($old_row['event_cost'] != $old_row['member_price']){
126 126
 //          $member_price_discount_id = $this->_insert_new_member_price($old_row);
127 127
 //      }else{
128 128
 //          $member_price_discount_id = 0;
129 129
 //      }
130
-        // create the surcharge if there is any
131
-        if (floatval($old_row['surcharge']) >= 0.01) {
132
-            $surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
134
-        } else {
135
-            $surcharge_price_id = 0;
136
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
137
-        }
138
-        // associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice.
139
-        // if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one)
140
-        // create ticket
130
+		// create the surcharge if there is any
131
+		if (floatval($old_row['surcharge']) >= 0.01) {
132
+			$surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
134
+		} else {
135
+			$surcharge_price_id = 0;
136
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
137
+		}
138
+		// associate the ticket to all datetimes for event (ie, this ONE ticket grants access to ALL datetimes, not just one of the attendee's choice.
139
+		// if the latter were the case, then we'd create a separate ticket for each datetime and ahve their association be one-to-one)
140
+		// create ticket
141 141
 //      $ticket_id = $this->_insert_new_ticket($old_row);
142 142
 //      if($ticket_id){
143 143
 //          $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $ticket_id);
@@ -149,62 +149,62 @@  discard block
 block discarded – undo
149 149
 //              $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
150 150
 //          }
151 151
 //      }
152
-        // create a ticket for each old price -old datetime combo
153
-        $tickets_for_old_price = array();
154
-        foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) {
155
-            $ticket_id = $this->_insert_new_ticket($old_row);
156
-            $tickets_for_old_price[] = $ticket_id;
157
-            // associate to old prices
158
-            $this->_insert_ticket_price_relation($ticket_id, $new_price_id);
159
-            $this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id);
160
-            $this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
161
-        }
162
-        $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price);
163
-    }
164
-    /**
165
-     * Creates a 4.1 price base type
166
-     * @global type $wpdb
167
-     * @param type $old_price
168
-     * @return int
169
-     */
170
-    private function _insert_new_price($old_price)
171
-    {
172
-        global $wpdb;
173
-        $cols_n_values = array(
174
-            'PRT_ID'=>self::price_type_base,
175
-            'PRC_amount'=>floatval($old_price['event_cost']),
176
-            'PRC_name'=>$old_price['price_type'],
177
-            'PRC_is_default'=>false,
178
-            'PRC_overrides'=>false,
179
-            'PRC_order'=>0,
180
-            'PRC_deleted'=>false,
181
-            'PRC_parent'=>null
152
+		// create a ticket for each old price -old datetime combo
153
+		$tickets_for_old_price = array();
154
+		foreach ($this->_get_datetime_ids_for_old_event_id($old_row['event_id']) as $new_datetime_id) {
155
+			$ticket_id = $this->_insert_new_ticket($old_row);
156
+			$tickets_for_old_price[] = $ticket_id;
157
+			// associate to old prices
158
+			$this->_insert_ticket_price_relation($ticket_id, $new_price_id);
159
+			$this->_insert_ticket_price_relation($ticket_id, $surcharge_price_id);
160
+			$this->_insert_datetime_ticket_relation($new_datetime_id, $ticket_id);
161
+		}
162
+		$this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_ticket_table, $tickets_for_old_price);
163
+	}
164
+	/**
165
+	 * Creates a 4.1 price base type
166
+	 * @global type $wpdb
167
+	 * @param type $old_price
168
+	 * @return int
169
+	 */
170
+	private function _insert_new_price($old_price)
171
+	{
172
+		global $wpdb;
173
+		$cols_n_values = array(
174
+			'PRT_ID'=>self::price_type_base,
175
+			'PRC_amount'=>floatval($old_price['event_cost']),
176
+			'PRC_name'=>$old_price['price_type'],
177
+			'PRC_is_default'=>false,
178
+			'PRC_overrides'=>false,
179
+			'PRC_order'=>0,
180
+			'PRC_deleted'=>false,
181
+			'PRC_parent'=>null
182 182
 
183
-        );
184
-        $datatypes = array(
185
-            '%d',// PRT_ID
186
-            '%f',// PRT_amount
187
-            '%s',// PRC_name
188
-            '%d',// PRC_is_default
189
-            '%d',// PRC_overrides
190
-            '%d',// PRC_order
191
-            '%d',// PRC_deleted
192
-            '%d',// PRC_parent
193
-        );
194
-        $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
-        if (! $success) {
196
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197
-            return 0;
198
-        }
199
-        $new_id = $wpdb->insert_id;
200
-        return $new_id;
201
-    }
202
-    /**
203
-     * Creates a 4.1 member price discount
204
-     * @global type $wpdb
205
-     * @param type $old_price
206
-     * @return int
207
-     */
183
+		);
184
+		$datatypes = array(
185
+			'%d',// PRT_ID
186
+			'%f',// PRT_amount
187
+			'%s',// PRC_name
188
+			'%d',// PRC_is_default
189
+			'%d',// PRC_overrides
190
+			'%d',// PRC_order
191
+			'%d',// PRC_deleted
192
+			'%d',// PRC_parent
193
+		);
194
+		$success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
+		if (! $success) {
196
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197
+			return 0;
198
+		}
199
+		$new_id = $wpdb->insert_id;
200
+		return $new_id;
201
+	}
202
+	/**
203
+	 * Creates a 4.1 member price discount
204
+	 * @global type $wpdb
205
+	 * @param type $old_price
206
+	 * @return int
207
+	 */
208 208
 //  private function _insert_new_member_price($old_price){
209 209
 //      $discount_amount = floatval($old_price['event_cost']) - floatval($old_price['member_price']);
210 210
 //      global $wpdb;
@@ -237,207 +237,207 @@  discard block
 block discarded – undo
237 237
 //      $new_id = $wpdb->insert_id;
238 238
 //      return $new_id;
239 239
 //  }
240
-    /**
241
-     * Creates a 4.1 member price discount
242
-     * @global type $wpdb
243
-     * @param type $old_price
244
-     * @return int
245
-     */
246
-    private function _insert_new_surcharge_price($old_price)
247
-    {
240
+	/**
241
+	 * Creates a 4.1 member price discount
242
+	 * @global type $wpdb
243
+	 * @param type $old_price
244
+	 * @return int
245
+	 */
246
+	private function _insert_new_surcharge_price($old_price)
247
+	{
248 248
 
249
-        if ($old_price['surcharge_type'] == 'flat_rate') {
250
-            $price_type = self::price_type_flat_surcharge;
251
-        } else {
252
-            $price_type = self::price_type_percent_surcharge;
253
-        }
254
-        global $wpdb;
255
-        $cols_n_values = array(
256
-            'PRT_ID'=>$price_type,
257
-            'PRC_amount'=>floatval($old_price['surcharge']),
258
-            'PRC_name'=>  __("Surcharge", "event_espresso"),
259
-            'PRC_is_default'=>false,
260
-            'PRC_overrides'=>false,
261
-            'PRC_order'=>20,
262
-            'PRC_deleted'=>false,
263
-            'PRC_parent'=>null
249
+		if ($old_price['surcharge_type'] == 'flat_rate') {
250
+			$price_type = self::price_type_flat_surcharge;
251
+		} else {
252
+			$price_type = self::price_type_percent_surcharge;
253
+		}
254
+		global $wpdb;
255
+		$cols_n_values = array(
256
+			'PRT_ID'=>$price_type,
257
+			'PRC_amount'=>floatval($old_price['surcharge']),
258
+			'PRC_name'=>  __("Surcharge", "event_espresso"),
259
+			'PRC_is_default'=>false,
260
+			'PRC_overrides'=>false,
261
+			'PRC_order'=>20,
262
+			'PRC_deleted'=>false,
263
+			'PRC_parent'=>null
264 264
 
265
-        );
266
-        $datatypes = array(
267
-            '%d',// PRT_ID
268
-            '%f',// PRT_amount
269
-            '%s',// PRC_name
270
-            '%d',// PRC_is_default
271
-            '%d',// PRC_overrides
272
-            '%d',// PRC_order
273
-            '%d',// PRC_deleted
274
-            '%d',// PRC_parent
275
-        );
276
-        $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
-        if (! $success) {
278
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279
-            return 0;
280
-        }
281
-        $new_id = $wpdb->insert_id;
282
-        return $new_id;
283
-    }
284
-    /**
285
-     * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price
286
-     * @param $old_price_row array where keys are columns
287
-     * @param $new_base_price_id int
288
-     * @param $new_member_discount_id int
289
-     * @param $new_surcharge_id int
290
-     * @return int new ticket id
291
-     */
292
-    private function _insert_new_ticket($old_price_row)
293
-    {
294
-        global $wpdb;
295
-        $event_row = $this->_get_event_row($old_price_row['event_id']);
296
-        if ($old_price_row['surcharge_type'] == 'flat_rate') {
297
-            $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298
-        } else {// percent surcharge
299
-            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
300
-        }
301
-        $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302
-        $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
303
-        $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304
-        $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305
-        $cols_n_values = array(
306
-            'TTM_ID'=>0,
307
-            'TKT_name'=>$old_price_row['price_type'],
308
-            'TKT_description'=>'',
309
-            'TKT_start_date'=>$start_date_utc,
310
-            'TKT_end_date'=>$end_date_utc,
311
-            'TKT_min'=>0,
312
-            'TKT_max'=>-1,
313
-            'TKT_price'=>$final_ticket_price,
314
-            'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
315
-            'TKT_qty'=> -1,
316
-            'TKT_uses'=> 1,
317
-            'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318
-            'TKT_is_default'=>false,
319
-            'TKT_order'=>$this->_get_ticket_count(),
320
-            'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
321
-            'TKT_deleted'=>false,
322
-            'TKT_parent'=>0
265
+		);
266
+		$datatypes = array(
267
+			'%d',// PRT_ID
268
+			'%f',// PRT_amount
269
+			'%s',// PRC_name
270
+			'%d',// PRC_is_default
271
+			'%d',// PRC_overrides
272
+			'%d',// PRC_order
273
+			'%d',// PRC_deleted
274
+			'%d',// PRC_parent
275
+		);
276
+		$success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
+		if (! $success) {
278
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279
+			return 0;
280
+		}
281
+		$new_id = $wpdb->insert_id;
282
+		return $new_id;
283
+	}
284
+	/**
285
+	 * Inserts a 4.1 ticket based off the 3.1 price, and the price IDs we've already made from the 3.1 price
286
+	 * @param $old_price_row array where keys are columns
287
+	 * @param $new_base_price_id int
288
+	 * @param $new_member_discount_id int
289
+	 * @param $new_surcharge_id int
290
+	 * @return int new ticket id
291
+	 */
292
+	private function _insert_new_ticket($old_price_row)
293
+	{
294
+		global $wpdb;
295
+		$event_row = $this->_get_event_row($old_price_row['event_id']);
296
+		if ($old_price_row['surcharge_type'] == 'flat_rate') {
297
+			$final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298
+		} else {// percent surcharge
299
+			$final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
300
+		}
301
+		$start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302
+		$start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
303
+		$end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304
+		$end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305
+		$cols_n_values = array(
306
+			'TTM_ID'=>0,
307
+			'TKT_name'=>$old_price_row['price_type'],
308
+			'TKT_description'=>'',
309
+			'TKT_start_date'=>$start_date_utc,
310
+			'TKT_end_date'=>$end_date_utc,
311
+			'TKT_min'=>0,
312
+			'TKT_max'=>-1,
313
+			'TKT_price'=>$final_ticket_price,
314
+			'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
315
+			'TKT_qty'=> -1,
316
+			'TKT_uses'=> 1,
317
+			'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318
+			'TKT_is_default'=>false,
319
+			'TKT_order'=>$this->_get_ticket_count(),
320
+			'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
321
+			'TKT_deleted'=>false,
322
+			'TKT_parent'=>0
323 323
 
324
-        );
325
-        $datatypes = array(
326
-            '%d',// TTM_ID
327
-            '%s',// TKT_name
328
-            '%s',// TKT_description
329
-            '%s',// TKT_start_date
330
-            '%s',// TKT_end_date
331
-            '%d',// TKT_min
332
-            '%d',// TKT_max
333
-            '%f',// TKT_price
334
-            '%d',// TKT_sold
335
-            '%d',// TKT_qty
336
-            '%d',// TKT_uses
337
-            '%d',// TKT_taxable
338
-            '%d',// TKT_is_default
339
-            '%d',// TKT_order
340
-            '%d',// TKT_row
341
-            '%d',// TKT_deleted
342
-            '%d',// TKT_parent
343
-        );
344
-        $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
-        if (! $success) {
346
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347
-            return 0;
348
-        }
349
-        $new_id = $wpdb->insert_id;
350
-        return $new_id;
351
-    }
324
+		);
325
+		$datatypes = array(
326
+			'%d',// TTM_ID
327
+			'%s',// TKT_name
328
+			'%s',// TKT_description
329
+			'%s',// TKT_start_date
330
+			'%s',// TKT_end_date
331
+			'%d',// TKT_min
332
+			'%d',// TKT_max
333
+			'%f',// TKT_price
334
+			'%d',// TKT_sold
335
+			'%d',// TKT_qty
336
+			'%d',// TKT_uses
337
+			'%d',// TKT_taxable
338
+			'%d',// TKT_is_default
339
+			'%d',// TKT_order
340
+			'%d',// TKT_row
341
+			'%d',// TKT_deleted
342
+			'%d',// TKT_parent
343
+		);
344
+		$success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
+		if (! $success) {
346
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347
+			return 0;
348
+		}
349
+		$new_id = $wpdb->insert_id;
350
+		return $new_id;
351
+	}
352 352
 
353
-    /**
354
-     * Adds a join between a ticket and a price
355
-     * @global type $wpdb
356
-     * @param type $new_ticket_id
357
-     * @param type $new_price_id
358
-     * @return int
359
-     */
360
-    private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
361
-    {
362
-        global $wpdb;
363
-        $cols_n_values = array(
364
-            'TKT_ID'=>$new_ticket_id,
365
-            'PRC_ID'=>$new_price_id,
366
-        );
367
-        $datatypes = array(
368
-            '%d',// TKT_ID
369
-            '%d',// PRC_ID
370
-        );
371
-        $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
-        if (! $success) {
373
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374
-            return 0;
375
-        }
376
-        $new_id = $wpdb->insert_id;
377
-        return $new_id;
378
-    }
353
+	/**
354
+	 * Adds a join between a ticket and a price
355
+	 * @global type $wpdb
356
+	 * @param type $new_ticket_id
357
+	 * @param type $new_price_id
358
+	 * @return int
359
+	 */
360
+	private function _insert_ticket_price_relation($new_ticket_id, $new_price_id)
361
+	{
362
+		global $wpdb;
363
+		$cols_n_values = array(
364
+			'TKT_ID'=>$new_ticket_id,
365
+			'PRC_ID'=>$new_price_id,
366
+		);
367
+		$datatypes = array(
368
+			'%d',// TKT_ID
369
+			'%d',// PRC_ID
370
+		);
371
+		$success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
+		if (! $success) {
373
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374
+			return 0;
375
+		}
376
+		$new_id = $wpdb->insert_id;
377
+		return $new_id;
378
+	}
379 379
 
380
-    /**
381
-     * Adds a join between a ticket and a datetime
382
-     * @global type $wpdb
383
-     * @param type $new_ticket_id
384
-     * @param type $new_price_id
385
-     * @return int
386
-     */
387
-    private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
388
-    {
389
-        global $wpdb;
390
-        $cols_n_values = array(
391
-            'TKT_ID'=>$new_ticket_id,
392
-            'DTT_ID'=>$new_datetime_id,
393
-        );
394
-        $datatypes = array(
395
-            '%d',// TKT_ID
396
-            '%d',// DTT_ID
397
-        );
398
-        $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
-        if (! $success) {
400
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401
-            return 0;
402
-        }
403
-        $new_id = $wpdb->insert_id;
404
-        return $new_id;
405
-    }
380
+	/**
381
+	 * Adds a join between a ticket and a datetime
382
+	 * @global type $wpdb
383
+	 * @param type $new_ticket_id
384
+	 * @param type $new_price_id
385
+	 * @return int
386
+	 */
387
+	private function _insert_datetime_ticket_relation($new_datetime_id, $new_ticket_id)
388
+	{
389
+		global $wpdb;
390
+		$cols_n_values = array(
391
+			'TKT_ID'=>$new_ticket_id,
392
+			'DTT_ID'=>$new_datetime_id,
393
+		);
394
+		$datatypes = array(
395
+			'%d',// TKT_ID
396
+			'%d',// DTT_ID
397
+		);
398
+		$success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
+		if (! $success) {
400
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401
+			return 0;
402
+		}
403
+		$new_id = $wpdb->insert_id;
404
+		return $new_id;
405
+	}
406 406
 
407
-    /**
408
-     * Simply gets the 3.1 event row data
409
-     * @global type $wpdb
410
-     * @param type $event_id
411
-     * @return array
412
-     */
413
-    private function _get_event_row($event_id)
414
-    {
415
-        global $wpdb;
416
-        $old_event_table = $wpdb->prefix."events_detail";
417
-        return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418
-    }
419
-    /**
420
-     * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests).
421
-     * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too
422
-     * @return int
423
-     */
424
-    private function _get_ticket_count()
425
-    {
426
-        return $this->_ticket_count++;
427
-    }
407
+	/**
408
+	 * Simply gets the 3.1 event row data
409
+	 * @global type $wpdb
410
+	 * @param type $event_id
411
+	 * @return array
412
+	 */
413
+	private function _get_event_row($event_id)
414
+	{
415
+		global $wpdb;
416
+		$old_event_table = $wpdb->prefix."events_detail";
417
+		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418
+	}
419
+	/**
420
+	 * Gets a higher ticket count than last time it was called (and is persisted between HTTP requests).
421
+	 * Yes we COULD run a query joining events->datetimes->ticket_datetimes->tickets, but this should work fine too
422
+	 * @return int
423
+	 */
424
+	private function _get_ticket_count()
425
+	{
426
+		return $this->_ticket_count++;
427
+	}
428 428
 
429
-    /**
430
-     * Using the 3.1 event id, gets the 4.1 datetimes for it
431
-     * @param int $old_event_id
432
-     * @return array where values are datetime ids
433
-     */
434
-    private function _get_datetime_ids_for_old_event_id($old_event_id)
435
-    {
436
-        global $wpdb;
437
-        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438
-        $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439
-        return $datetime_ids;
440
-    }
429
+	/**
430
+	 * Using the 3.1 event id, gets the 4.1 datetimes for it
431
+	 * @param int $old_event_id
432
+	 * @return array where values are datetime ids
433
+	 */
434
+	private function _get_datetime_ids_for_old_event_id($old_event_id)
435
+	{
436
+		global $wpdb;
437
+		$new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438
+		$datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439
+		return $datetime_ids;
440
+	}
441 441
 }
442 442
 // @todo: tell users that in 3.1 the limit was on registration PER event,in 4.1 it's limit PER TICKET... SO, if they sell 2 different types of tickets
443 443
 //
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         $this->_old_table = $wpdb->prefix."events_prices";
109 109
         $this->select_expression = 'p.*, e.event_status';
110 110
         $this->_extra_where_sql = ' AS p 
111
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON p.event_id=e.id
111
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON p.event_id=e.id
112 112
             WHERE e.event_status!="D"';
113 113
         $this->_new_price_table = $wpdb->prefix."esp_price";
114 114
         $this->_new_ticket_table = $wpdb->prefix."esp_ticket";
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         // create the surcharge if there is any
131 131
         if (floatval($old_row['surcharge']) >= 0.01) {
132 132
             $surcharge_price_id = $this->_insert_new_surcharge_price($old_row);
133
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id,$surcharge_price_id));
133
+            $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id, $surcharge_price_id));
134 134
         } else {
135 135
             $surcharge_price_id = 0;
136 136
             $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_price_table, array($new_price_id));
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
 
183 183
         );
184 184
         $datatypes = array(
185
-            '%d',// PRT_ID
186
-            '%f',// PRT_amount
187
-            '%s',// PRC_name
188
-            '%d',// PRC_is_default
189
-            '%d',// PRC_overrides
190
-            '%d',// PRC_order
191
-            '%d',// PRC_deleted
192
-            '%d',// PRC_parent
185
+            '%d', // PRT_ID
186
+            '%f', // PRT_amount
187
+            '%s', // PRC_name
188
+            '%d', // PRC_is_default
189
+            '%d', // PRC_overrides
190
+            '%d', // PRC_order
191
+            '%d', // PRC_deleted
192
+            '%d', // PRC_parent
193 193
         );
194 194
         $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
195
-        if (! $success) {
195
+        if ( ! $success) {
196 196
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
197 197
             return 0;
198 198
         }
@@ -264,17 +264,17 @@  discard block
 block discarded – undo
264 264
 
265 265
         );
266 266
         $datatypes = array(
267
-            '%d',// PRT_ID
268
-            '%f',// PRT_amount
269
-            '%s',// PRC_name
270
-            '%d',// PRC_is_default
271
-            '%d',// PRC_overrides
272
-            '%d',// PRC_order
273
-            '%d',// PRC_deleted
274
-            '%d',// PRC_parent
267
+            '%d', // PRT_ID
268
+            '%f', // PRT_amount
269
+            '%s', // PRC_name
270
+            '%d', // PRC_is_default
271
+            '%d', // PRC_overrides
272
+            '%d', // PRC_order
273
+            '%d', // PRC_deleted
274
+            '%d', // PRC_parent
275 275
         );
276 276
         $success = $wpdb->insert($this->_new_price_table, $cols_n_values, $datatypes);
277
-        if (! $success) {
277
+        if ( ! $success) {
278 278
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price, $this->_new_price_table, $cols_n_values, $datatypes));
279 279
             return 0;
280 280
         }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
         if ($old_price_row['surcharge_type'] == 'flat_rate') {
297 297
             $final_ticket_price = floatval($old_price_row['event_cost']) + floatval($old_price_row['surcharge']);
298 298
         } else {// percent surcharge
299
-            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge'])/100);
299
+            $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100);
300 300
         }
301 301
         $start_date = $event_row['registration_start']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
302 302
         $start_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $start_date, $event_row['timezone_string']);
@@ -311,38 +311,38 @@  discard block
 block discarded – undo
311 311
             'TKT_min'=>0,
312 312
             'TKT_max'=>-1,
313 313
             'TKT_price'=>$final_ticket_price,
314
-            'TKT_sold'=> 0,// note: this will get calculated as we actually add registrations during the migration
314
+            'TKT_sold'=> 0, // note: this will get calculated as we actually add registrations during the migration
315 315
             'TKT_qty'=> -1,
316 316
             'TKT_uses'=> 1,
317
-            'TKT_taxable'=>false,// so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
317
+            'TKT_taxable'=>false, // so by default, old prices are NOT taxable. This way they don't suddenly have a sudden spike in prices
318 318
             'TKT_is_default'=>false,
319 319
             'TKT_order'=>$this->_get_ticket_count(),
320
-            'TKT_row'=>0,// doesn't matter because UI reset this on first save anyways
320
+            'TKT_row'=>0, // doesn't matter because UI reset this on first save anyways
321 321
             'TKT_deleted'=>false,
322 322
             'TKT_parent'=>0
323 323
 
324 324
         );
325 325
         $datatypes = array(
326
-            '%d',// TTM_ID
327
-            '%s',// TKT_name
328
-            '%s',// TKT_description
329
-            '%s',// TKT_start_date
330
-            '%s',// TKT_end_date
331
-            '%d',// TKT_min
332
-            '%d',// TKT_max
333
-            '%f',// TKT_price
334
-            '%d',// TKT_sold
335
-            '%d',// TKT_qty
336
-            '%d',// TKT_uses
337
-            '%d',// TKT_taxable
338
-            '%d',// TKT_is_default
339
-            '%d',// TKT_order
340
-            '%d',// TKT_row
341
-            '%d',// TKT_deleted
342
-            '%d',// TKT_parent
326
+            '%d', // TTM_ID
327
+            '%s', // TKT_name
328
+            '%s', // TKT_description
329
+            '%s', // TKT_start_date
330
+            '%s', // TKT_end_date
331
+            '%d', // TKT_min
332
+            '%d', // TKT_max
333
+            '%f', // TKT_price
334
+            '%d', // TKT_sold
335
+            '%d', // TKT_qty
336
+            '%d', // TKT_uses
337
+            '%d', // TKT_taxable
338
+            '%d', // TKT_is_default
339
+            '%d', // TKT_order
340
+            '%d', // TKT_row
341
+            '%d', // TKT_deleted
342
+            '%d', // TKT_parent
343 343
         );
344 344
         $success = $wpdb->insert($this->_new_ticket_table, $cols_n_values, $datatypes);
345
-        if (! $success) {
345
+        if ( ! $success) {
346 346
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_price_row, $this->_new_ticket_table, $cols_n_values, $datatypes));
347 347
             return 0;
348 348
         }
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
             'PRC_ID'=>$new_price_id,
366 366
         );
367 367
         $datatypes = array(
368
-            '%d',// TKT_ID
369
-            '%d',// PRC_ID
368
+            '%d', // TKT_ID
369
+            '%d', // PRC_ID
370 370
         );
371 371
         $success = $wpdb->insert($this->_new_ticket_price_table, $cols_n_values, $datatypes);
372
-        if (! $success) {
373
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
372
+        if ( ! $success) {
373
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'price id'=>$new_price_id), $this->_new_ticket_price_table, $cols_n_values, $datatypes));
374 374
             return 0;
375 375
         }
376 376
         $new_id = $wpdb->insert_id;
@@ -392,12 +392,12 @@  discard block
 block discarded – undo
392 392
             'DTT_ID'=>$new_datetime_id,
393 393
         );
394 394
         $datatypes = array(
395
-            '%d',// TKT_ID
396
-            '%d',// DTT_ID
395
+            '%d', // TKT_ID
396
+            '%d', // DTT_ID
397 397
         );
398 398
         $success = $wpdb->insert($this->_new_datetime_ticket_table, $cols_n_values, $datatypes);
399
-        if (! $success) {
400
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id,'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
399
+        if ( ! $success) {
400
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('ticket id'=>$new_ticket_id, 'datetime id'=>$new_datetime_id), $this->_new_datetime_ticket_table, $cols_n_values, $datatypes));
401 401
             return 0;
402 402
         }
403 403
         $new_id = $wpdb->insert_id;
Please login to merge, or discard this patch.