Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_event_venue.dmsstage.php 2 patches
Indentation   +87 added lines, -90 removed lines patch added patch discarded remove patch
@@ -25,105 +25,102 @@
 block discarded – undo
25 25
 
26 26
             )
27 27
         );
28
-
29
-
30
-
31 28
  *
32 29
  */
33 30
 class EE_DMS_4_1_0_event_venue extends EE_Data_Migration_Script_Stage
34 31
 {
35
-    private $_old_table;
36
-    private $_new_table;
37
-    public function _migration_step($num_items = 50)
38
-    {
32
+	private $_old_table;
33
+	private $_new_table;
34
+	public function _migration_step($num_items = 50)
35
+	{
39 36
 
40
-        global $wpdb;
41
-        $start_at_record = $this->count_records_migrated();
42
-        $rows = $wpdb->get_results(
43
-            $wpdb->prepare(
44
-                "SELECT * FROM $this->_old_table AS ev 
37
+		global $wpdb;
38
+		$start_at_record = $this->count_records_migrated();
39
+		$rows = $wpdb->get_results(
40
+			$wpdb->prepare(
41
+				"SELECT * FROM $this->_old_table AS ev 
45 42
                     INNER JOIN " . $wpdb->prefix . "events_detail AS e ON ev.event_id=e.id
46 43
                     WHERE e.event_status!='D' LIMIT %d,%d",
47
-                $start_at_record,
48
-                $num_items
49
-            ),
50
-            ARRAY_A
51
-        );
52
-        $items_actually_migrated = 0;
53
-        foreach ($rows as $event_venue_rel) {
54
-            $this->_insert_new_event_to_venue_rel($event_venue_rel);
55
-            $items_actually_migrated++;
56
-        }
57
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
58
-            $this->set_completed();
59
-        }
60
-        return $items_actually_migrated;
61
-    }
62
-    public function _count_records_to_migrate()
63
-    {
64
-        global $wpdb;
65
-        $count = $wpdb->get_var(
66
-            "SELECT COUNT(ev.id) FROM " . $this->_old_table . " AS ev 
44
+				$start_at_record,
45
+				$num_items
46
+			),
47
+			ARRAY_A
48
+		);
49
+		$items_actually_migrated = 0;
50
+		foreach ($rows as $event_venue_rel) {
51
+			$this->_insert_new_event_to_venue_rel($event_venue_rel);
52
+			$items_actually_migrated++;
53
+		}
54
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
55
+			$this->set_completed();
56
+		}
57
+		return $items_actually_migrated;
58
+	}
59
+	public function _count_records_to_migrate()
60
+	{
61
+		global $wpdb;
62
+		$count = $wpdb->get_var(
63
+			"SELECT COUNT(ev.id) FROM " . $this->_old_table . " AS ev 
67 64
             INNER JOIN " . $wpdb->prefix . 'events_detail AS e ON ev.event_id=e.id
68 65
             WHERE e.event_status!="D"'
69
-        );
70
-        return $count;
71
-    }
72
-    public function __construct()
73
-    {
74
-        global $wpdb;
75
-        $this->_old_table = $wpdb->prefix . "events_venue_rel";
76
-        $this->_new_table = $wpdb->prefix . "esp_event_venue";
77
-        $this->_pretty_name = esc_html__("Event to Venue Relations", "event_espresso");
78
-        parent::__construct();
79
-    }
66
+		);
67
+		return $count;
68
+	}
69
+	public function __construct()
70
+	{
71
+		global $wpdb;
72
+		$this->_old_table = $wpdb->prefix . "events_venue_rel";
73
+		$this->_new_table = $wpdb->prefix . "esp_event_venue";
74
+		$this->_pretty_name = esc_html__("Event to Venue Relations", "event_espresso");
75
+		parent::__construct();
76
+	}
80 77
 
81
-    /**
82
-     * Attempts to insert a new question group inthe new format given an old one
83
-     * @global type $wpdb
84
-     * @param array $old_event_venue_rel
85
-     * @return int
86
-     */
87
-    private function _insert_new_event_to_venue_rel($old_event_venue_rel)
88
-    {
89
-        global $wpdb;
90
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix . "posts");
91
-        $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix . "posts");
92
-        if (! $new_event_id) {
93
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id']));
94
-            return 0;
95
-        }
96
-        if (! $new_venue_id) {
97
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id']));
98
-            return 0;
99
-        }
100
-        // first ensure there are no other relation entries for this event
101
-        // because although EE4 supports it, EE3 didn't really
102
-        $wpdb->delete(
103
-            $this->_new_table,
104
-            array(
105
-                    'EVT_ID' => $new_event_id,
106
-                ),
107
-            array(
108
-                    '%d',// EVT_ID
109
-                )
110
-        );
78
+	/**
79
+	 * Attempts to insert a new question group inthe new format given an old one
80
+	 * @global type $wpdb
81
+	 * @param array $old_event_venue_rel
82
+	 * @return int
83
+	 */
84
+	private function _insert_new_event_to_venue_rel($old_event_venue_rel)
85
+	{
86
+		global $wpdb;
87
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix . "posts");
88
+		$new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix . "posts");
89
+		if (! $new_event_id) {
90
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id']));
91
+			return 0;
92
+		}
93
+		if (! $new_venue_id) {
94
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id']));
95
+			return 0;
96
+		}
97
+		// first ensure there are no other relation entries for this event
98
+		// because although EE4 supports it, EE3 didn't really
99
+		$wpdb->delete(
100
+			$this->_new_table,
101
+			array(
102
+					'EVT_ID' => $new_event_id,
103
+				),
104
+			array(
105
+					'%d',// EVT_ID
106
+				)
107
+		);
111 108
 //      echo "last query". $wpdb->last_query;die;
112
-        $cols_n_values = array(
113
-            'EVT_ID' => $new_event_id,
114
-            'VNU_ID' => $new_venue_id,
115
-            'EVV_primary' => true
116
-        );
117
-        $datatypes = array(
118
-            '%d',// EVT_ID
119
-            '%d',// VNU_ID
120
-            '%d',// EVT_primary
121
-        );
122
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
123
-        if (! $success) {
124
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes));
125
-            return 0;
126
-        }
127
-        return $wpdb->insert_id;
128
-    }
109
+		$cols_n_values = array(
110
+			'EVT_ID' => $new_event_id,
111
+			'VNU_ID' => $new_venue_id,
112
+			'EVV_primary' => true
113
+		);
114
+		$datatypes = array(
115
+			'%d',// EVT_ID
116
+			'%d',// VNU_ID
117
+			'%d',// EVT_primary
118
+		);
119
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
120
+		if (! $success) {
121
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes));
122
+			return 0;
123
+		}
124
+		return $wpdb->insert_id;
125
+	}
129 126
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $rows = $wpdb->get_results(
43 43
             $wpdb->prepare(
44 44
                 "SELECT * FROM $this->_old_table AS ev 
45
-                    INNER JOIN " . $wpdb->prefix . "events_detail AS e ON ev.event_id=e.id
45
+                    INNER JOIN ".$wpdb->prefix."events_detail AS e ON ev.event_id=e.id
46 46
                     WHERE e.event_status!='D' LIMIT %d,%d",
47 47
                 $start_at_record,
48 48
                 $num_items
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
     {
64 64
         global $wpdb;
65 65
         $count = $wpdb->get_var(
66
-            "SELECT COUNT(ev.id) FROM " . $this->_old_table . " AS ev 
67
-            INNER JOIN " . $wpdb->prefix . 'events_detail AS e ON ev.event_id=e.id
66
+            "SELECT COUNT(ev.id) FROM ".$this->_old_table." AS ev 
67
+            INNER JOIN " . $wpdb->prefix.'events_detail AS e ON ev.event_id=e.id
68 68
             WHERE e.event_status!="D"'
69 69
         );
70 70
         return $count;
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
     public function __construct()
73 73
     {
74 74
         global $wpdb;
75
-        $this->_old_table = $wpdb->prefix . "events_venue_rel";
76
-        $this->_new_table = $wpdb->prefix . "esp_event_venue";
75
+        $this->_old_table = $wpdb->prefix."events_venue_rel";
76
+        $this->_new_table = $wpdb->prefix."esp_event_venue";
77 77
         $this->_pretty_name = esc_html__("Event to Venue Relations", "event_espresso");
78 78
         parent::__construct();
79 79
     }
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
     private function _insert_new_event_to_venue_rel($old_event_venue_rel)
88 88
     {
89 89
         global $wpdb;
90
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix . "posts");
91
-        $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix . "posts");
92
-        if (! $new_event_id) {
90
+        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix."posts");
91
+        $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix."posts");
92
+        if ( ! $new_event_id) {
93 93
             $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id']));
94 94
             return 0;
95 95
         }
96
-        if (! $new_venue_id) {
96
+        if ( ! $new_venue_id) {
97 97
             $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id']));
98 98
             return 0;
99 99
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                     'EVT_ID' => $new_event_id,
106 106
                 ),
107 107
             array(
108
-                    '%d',// EVT_ID
108
+                    '%d', // EVT_ID
109 109
                 )
110 110
         );
111 111
 //      echo "last query". $wpdb->last_query;die;
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
             'EVV_primary' => true
116 116
         );
117 117
         $datatypes = array(
118
-            '%d',// EVT_ID
119
-            '%d',// VNU_ID
120
-            '%d',// EVT_primary
118
+            '%d', // EVT_ID
119
+            '%d', // VNU_ID
120
+            '%d', // EVT_primary
121 121
         );
122 122
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
123
-        if (! $success) {
123
+        if ( ! $success) {
124 124
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes));
125 125
             return 0;
126 126
         }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_question_group_question.dmsstage.php 2 patches
Indentation   +106 added lines, -108 removed lines patch added patch discarded remove patch
@@ -12,8 +12,6 @@  discard block
 block discarded – undo
12 12
   KEY `group_id` (`group_id`),
13 13
   KEY `question_id` (`question_id`)
14 14
 ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8$$
15
-
16
-
17 15
  * 4.1 question group question model's tables and fields:
18 16
  $this->_tables = array(
19 17
             'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question','QGQ_ID')
@@ -29,114 +27,114 @@  discard block
 block discarded – undo
29 27
  */
30 28
 class EE_DMS_4_1_0_question_group_question extends EE_Data_Migration_Script_Stage
31 29
 {
32
-    private $_old_table;
33
-    private $_new_table;
34
-    public function _migration_step($num_items = 50)
35
-    {
30
+	private $_old_table;
31
+	private $_new_table;
32
+	public function _migration_step($num_items = 50)
33
+	{
36 34
 
37
-        global $wpdb;
38
-        $start_at_record = $this->count_records_migrated();
39
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
40
-        $items_actually_migrated = 0;
41
-        foreach ($rows as $question_group_question) {
42
-            $this->_insert_new_question_group_question($question_group_question);
43
-            $items_actually_migrated++;
44
-        }
45
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
46
-            $this->set_completed();
47
-        }
48
-        return $items_actually_migrated;
49
-    }
50
-    public function _count_records_to_migrate()
51
-    {
52
-        global $wpdb;
53
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
54
-        return $count;
55
-    }
56
-    public function __construct()
57
-    {
58
-        global $wpdb;
59
-        $this->_old_table = $wpdb->prefix . "events_qst_group_rel";
60
-        $this->_new_table = $wpdb->prefix . "esp_question_group_question";
61
-        $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso");
62
-        parent::__construct();
63
-    }
35
+		global $wpdb;
36
+		$start_at_record = $this->count_records_migrated();
37
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
+		$items_actually_migrated = 0;
39
+		foreach ($rows as $question_group_question) {
40
+			$this->_insert_new_question_group_question($question_group_question);
41
+			$items_actually_migrated++;
42
+		}
43
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
44
+			$this->set_completed();
45
+		}
46
+		return $items_actually_migrated;
47
+	}
48
+	public function _count_records_to_migrate()
49
+	{
50
+		global $wpdb;
51
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
52
+		return $count;
53
+	}
54
+	public function __construct()
55
+	{
56
+		global $wpdb;
57
+		$this->_old_table = $wpdb->prefix . "events_qst_group_rel";
58
+		$this->_new_table = $wpdb->prefix . "esp_question_group_question";
59
+		$this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso");
60
+		parent::__construct();
61
+	}
64 62
 
65
-    /**
66
-     * Attempts to insert a new question group inthe new format given an old one
67
-     * @global type $wpdb
68
-     * @param array $old_question_group_question
69
-     * @return int
70
-     */
71
-    private function _insert_new_question_group_question($old_question_group_question)
72
-    {
73
-        global $wpdb;
74
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question");
75
-        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group");
76
-        if (! $new_question_id) {
77
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
78
-            return 0;
79
-        }
80
-        if (! $new_question_group_id) {
81
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
82
-            return 0;
83
-        }
84
-        // if it's a system question, it needs to be in the right system group. otherwise no dice!
85
-        if (
86
-            ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
87
-                ||
88
-                ! $this->_is_system_question_for_question_group($new_question_id)
89
-        ) {
90
-            $cols_n_values = array(
91
-                'QSG_ID' => $new_question_group_id,
92
-                'QST_ID' => $new_question_id
93
-            );
94
-            $datatypes = array(
95
-                '%d',// QSG_ID
96
-                '%d',// QST_ID
97
-            );
98
-            $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
99
-            if (! $success) {
100
-                $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
101
-                return 0;
102
-            }
103
-            return $wpdb->insert_id;
104
-        } else {
105
-            return false;
106
-        }
107
-    }
63
+	/**
64
+	 * Attempts to insert a new question group inthe new format given an old one
65
+	 * @global type $wpdb
66
+	 * @param array $old_question_group_question
67
+	 * @return int
68
+	 */
69
+	private function _insert_new_question_group_question($old_question_group_question)
70
+	{
71
+		global $wpdb;
72
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question");
73
+		$new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group");
74
+		if (! $new_question_id) {
75
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
76
+			return 0;
77
+		}
78
+		if (! $new_question_group_id) {
79
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
80
+			return 0;
81
+		}
82
+		// if it's a system question, it needs to be in the right system group. otherwise no dice!
83
+		if (
84
+			($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
85
+				||
86
+				! $this->_is_system_question_for_question_group($new_question_id)
87
+		) {
88
+			$cols_n_values = array(
89
+				'QSG_ID' => $new_question_group_id,
90
+				'QST_ID' => $new_question_id
91
+			);
92
+			$datatypes = array(
93
+				'%d',// QSG_ID
94
+				'%d',// QST_ID
95
+			);
96
+			$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
97
+			if (! $success) {
98
+				$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
99
+				return 0;
100
+			}
101
+			return $wpdb->insert_id;
102
+		} else {
103
+			return false;
104
+		}
105
+	}
108 106
 
109
-    /**
110
-     * If this question is a system question, returns the QSG_system number that
111
-     * indicates the question group its permitted in.
112
-     * @global type $wpdb
113
-     * @param type $new_question_id
114
-     * @return int
115
-     */
116
-    private function _is_system_question_for_question_group($new_question_id)
117
-    {
118
-        global $wpdb;
119
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id));
120
-        if (in_array($system_id, array('fname','lname','email'))) {
121
-            return 1;
122
-        } elseif ($system_id != '' && $system_id) {
123
-            return 2;
124
-        } else {
125
-            return 0;
126
-        }
127
-    }
107
+	/**
108
+	 * If this question is a system question, returns the QSG_system number that
109
+	 * indicates the question group its permitted in.
110
+	 * @global type $wpdb
111
+	 * @param type $new_question_id
112
+	 * @return int
113
+	 */
114
+	private function _is_system_question_for_question_group($new_question_id)
115
+	{
116
+		global $wpdb;
117
+		$system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id));
118
+		if (in_array($system_id, array('fname','lname','email'))) {
119
+			return 1;
120
+		} elseif ($system_id != '' && $system_id) {
121
+			return 2;
122
+		} else {
123
+			return 0;
124
+		}
125
+	}
128 126
 
129
-    /**
130
-     * Returns the questino group's QSG_system value (1 meaning personal info, 2
131
-     * being address info, and 0 being neither)
132
-     * @global type $wpdb
133
-     * @param type $new_question_group_id
134
-     * @return boolean
135
-     */
136
-    private function _is_system_question_group($new_question_group_id)
137
-    {
138
-        global $wpdb;
139
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
140
-        return intval($system_id);
141
-    }
127
+	/**
128
+	 * Returns the questino group's QSG_system value (1 meaning personal info, 2
129
+	 * being address info, and 0 being neither)
130
+	 * @global type $wpdb
131
+	 * @param type $new_question_group_id
132
+	 * @return boolean
133
+	 */
134
+	private function _is_system_question_group($new_question_group_id)
135
+	{
136
+		global $wpdb;
137
+		$system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
138
+		return intval($system_id);
139
+	}
142 140
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
     public function _count_records_to_migrate()
51 51
     {
52 52
         global $wpdb;
53
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
53
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
54 54
         return $count;
55 55
     }
56 56
     public function __construct()
57 57
     {
58 58
         global $wpdb;
59
-        $this->_old_table = $wpdb->prefix . "events_qst_group_rel";
60
-        $this->_new_table = $wpdb->prefix . "esp_question_group_question";
59
+        $this->_old_table = $wpdb->prefix."events_qst_group_rel";
60
+        $this->_new_table = $wpdb->prefix."esp_question_group_question";
61 61
         $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso");
62 62
         parent::__construct();
63 63
     }
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
     private function _insert_new_question_group_question($old_question_group_question)
72 72
     {
73 73
         global $wpdb;
74
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question");
75
-        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group");
76
-        if (! $new_question_id) {
74
+        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question");
75
+        $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group");
76
+        if ( ! $new_question_id) {
77 77
             $this->add_error(sprintf(esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id']));
78 78
             return 0;
79 79
         }
80
-        if (! $new_question_group_id) {
80
+        if ( ! $new_question_group_id) {
81 81
             $this->add_error(sprintf(esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id']));
82 82
             return 0;
83 83
         }
84 84
         // if it's a system question, it needs to be in the right system group. otherwise no dice!
85 85
         if (
86
-            ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) )
86
+            ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id))
87 87
                 ||
88 88
                 ! $this->_is_system_question_for_question_group($new_question_id)
89 89
         ) {
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
                 'QST_ID' => $new_question_id
93 93
             );
94 94
             $datatypes = array(
95
-                '%d',// QSG_ID
96
-                '%d',// QST_ID
95
+                '%d', // QSG_ID
96
+                '%d', // QST_ID
97 97
             );
98 98
             $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
99
-            if (! $success) {
99
+            if ( ! $success) {
100 100
                 $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes));
101 101
                 return 0;
102 102
             }
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
     private function _is_system_question_for_question_group($new_question_id)
117 117
     {
118 118
         global $wpdb;
119
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id));
120
-        if (in_array($system_id, array('fname','lname','email'))) {
119
+        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id));
120
+        if (in_array($system_id, array('fname', 'lname', 'email'))) {
121 121
             return 1;
122 122
         } elseif ($system_id != '' && $system_id) {
123 123
             return 2;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     private function _is_system_question_group($new_question_group_id)
137 137
     {
138 138
         global $wpdb;
139
-        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
139
+        $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id));
140 140
         return intval($system_id);
141 141
     }
142 142
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_gateways.dmsstage.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
         // convert settings
25 25
         $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
26 26
         // just do a part of them on this request
27
-        $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate;
27
+        $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items); // $this->_gateways_we_know_how_to_migrate;
28 28
         foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
29 29
             $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
30
-            if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
30
+            if (isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) {
31 31
                 // determine the old option's name
32 32
                 $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
33
-                if (! $old_gateway_settings) {
33
+                if ( ! $old_gateway_settings) {
34 34
                     // no settings existed for this gateway anyways... weird...
35 35
                     $items_actually_migrated++;
36 36
                     continue;
37 37
                 }
38 38
                 // now prepare the settings to make sure they're in the 4.1 format
39 39
                 $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug);
40
-                $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings;
40
+                $new_gateway_config_obj->payment_settings[$new_gateway_slug] = $new_gateway_settings;
41 41
                 // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
42 42
                 // I think it's ok to do right away this time (we wont need gateway settings elsewhere)
43 43
                 delete_option($old_gateway_wp_option_name);
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
                 global $wpdb;
46 46
                 // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll
47 47
                 // only be saving users 50 milliseconds the one time this runs...
48
-                $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
48
+                $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
49 49
             }
50 50
 
51 51
             $items_actually_migrated++;
52 52
         }
53 53
         // if we can keep going, and it hasn' tbeen done yet, convert active gateways
54
-        if ($items_actually_migrated < $num_items &&  ! $this->_converted_active_gateways) {
54
+        if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) {
55 55
             $this->_convert_active_gateways();
56 56
             $this->_converted_active_gateways = true;
57 57
             $items_actually_migrated++;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         $step_of_setting_active_gateways = 1;
70 70
         $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
71 71
     //  $button_images_to_update =
72
-        return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
72
+        return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
73 73
     }
74 74
     public function __construct()
75 75
     {
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     private function _get_old_gateway_option($new_gateway_slug)
120 120
     {
121 121
         $option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
122
-        $settings =  get_option($option_name, null);
122
+        $settings = get_option($option_name, null);
123 123
     //  if( ! $settings){
124 124
     //      $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
125 125
     //  }
@@ -134,36 +134,36 @@  discard block
 block discarded – undo
134 134
     private function _get_old_gateway_option_name($new_gateway_slug)
135 135
     {
136 136
         $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone));
137
-        $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ];
137
+        $old_gateway_slug = $new_gateway_slugs_to_new[$new_gateway_slug];
138 138
         $normal_option_prefix = 'event_espresso_';
139 139
         $normal_option_postfix = '_settings';
140 140
         switch ($new_gateway_slug) {
141 141
             case 'Bank':
142
-                $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix;
142
+                $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix;
143 143
                 break;
144 144
             case 'Aim':
145
-                $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix;
145
+                $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix;
146 146
                 break;
147 147
             case 'Check':
148
-                $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix;
148
+                $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix;
149 149
                 break;
150 150
             case 'Ideal':
151
-                $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix;
151
+                $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix;
152 152
                 break;
153 153
             case 'Invoice':
154
-                $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix;
154
+                $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix;
155 155
                 break;
156 156
             case 'Purchase_Order':
157
-                $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix;
157
+                $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix;
158 158
                 break;
159 159
             case 'USAePay_Offsite':
160
-                $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix;
160
+                $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix;
161 161
                 break;
162 162
             case 'USAePay_Onsite':
163
-                $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix;
163
+                $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix;
164 164
                 break;
165 165
             default:
166
-                $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix);
166
+                $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix);
167 167
         }
168 168
         return $option_name;
169 169
     }
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
         $old_active_gateways = get_option('event_espresso_active_gateways');
175 175
         $new_active_gateways = EE_Config::instance()->gateway->active_gateways;
176 176
         foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
177
-            if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
177
+            if ( ! isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) {
178 178
                 $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
179 179
                 continue;
180 180
             }
181
-            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
181
+            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[$old_gateway_slug];
182 182
 
183 183
             // in the new format we can also upload gateways to the uploads directory and
184
-            $new_active_gateways[ $new_gateway_slug ] = false;
184
+            $new_active_gateways[$new_gateway_slug] = false;
185 185
         }
186 186
         EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
187 187
     }
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -13,68 +13,68 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage
15 15
 {
16
-    private $_converted_active_gateways = false;
16
+	private $_converted_active_gateways = false;
17 17
 
18
-    public function _migration_step($num_items = 50)
19
-    {
20
-        // loads existing EE_CONfig from DB, if it exists
21
-        $new_gateway_config_obj = EE_Config::instance()->gateway;
22
-        $items_actually_migrated = 0;
23
-        // convert settings
24
-        $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
25
-        // just do a part of them on this request
26
-        $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate;
27
-        foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
28
-            $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
29
-            if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
30
-                // determine the old option's name
31
-                $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
32
-                if (! $old_gateway_settings) {
33
-                    // no settings existed for this gateway anyways... weird...
34
-                    $items_actually_migrated++;
35
-                    continue;
36
-                }
37
-                // now prepare the settings to make sure they're in the 4.1 format
38
-                $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug);
39
-                $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings;
40
-                // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
41
-                // I think it's ok to do right away this time (we wont need gateway settings elsewhere)
42
-                delete_option($old_gateway_wp_option_name);
43
-            } else {// it must be one of the ones we mostly leave alone
44
-                global $wpdb;
45
-                // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll
46
-                // only be saving users 50 milliseconds the one time this runs...
47
-                $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
48
-            }
18
+	public function _migration_step($num_items = 50)
19
+	{
20
+		// loads existing EE_CONfig from DB, if it exists
21
+		$new_gateway_config_obj = EE_Config::instance()->gateway;
22
+		$items_actually_migrated = 0;
23
+		// convert settings
24
+		$gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone);
25
+		// just do a part of them on this request
26
+		$gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate;
27
+		foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) {
28
+			$old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
29
+			if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
30
+				// determine the old option's name
31
+				$old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug);
32
+				if (! $old_gateway_settings) {
33
+					// no settings existed for this gateway anyways... weird...
34
+					$items_actually_migrated++;
35
+					continue;
36
+				}
37
+				// now prepare the settings to make sure they're in the 4.1 format
38
+				$new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug);
39
+				$new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings;
40
+				// and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but
41
+				// I think it's ok to do right away this time (we wont need gateway settings elsewhere)
42
+				delete_option($old_gateway_wp_option_name);
43
+			} else {// it must be one of the ones we mostly leave alone
44
+				global $wpdb;
45
+				// yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll
46
+				// only be saving users 50 milliseconds the one time this runs...
47
+				$wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name));
48
+			}
49 49
 
50
-            $items_actually_migrated++;
51
-        }
52
-        // if we can keep going, and it hasn' tbeen done yet, convert active gateways
53
-        if ($items_actually_migrated < $num_items &&  ! $this->_converted_active_gateways) {
54
-            $this->_convert_active_gateways();
55
-            $this->_converted_active_gateways = true;
56
-            $items_actually_migrated++;
57
-        }
50
+			$items_actually_migrated++;
51
+		}
52
+		// if we can keep going, and it hasn' tbeen done yet, convert active gateways
53
+		if ($items_actually_migrated < $num_items &&  ! $this->_converted_active_gateways) {
54
+			$this->_convert_active_gateways();
55
+			$this->_converted_active_gateways = true;
56
+			$items_actually_migrated++;
57
+		}
58 58
 
59
-        EE_Config::instance()->update_espresso_config(false, false);
60
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
61
-            $this->set_completed();
62
-        }
63
-        return $items_actually_migrated;
64
-    }
65
-    public function _count_records_to_migrate()
66
-    {
67
-        $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate);
68
-        $step_of_setting_active_gateways = 1;
69
-        $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
70
-    //  $button_images_to_update =
71
-        return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
72
-    }
73
-    public function __construct()
74
-    {
75
-        $this->_pretty_name = esc_html__("Gateways", "event_espresso");
76
-        parent::__construct();
77
-    }
59
+		EE_Config::instance()->update_espresso_config(false, false);
60
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
61
+			$this->set_completed();
62
+		}
63
+		return $items_actually_migrated;
64
+	}
65
+	public function _count_records_to_migrate()
66
+	{
67
+		$count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate);
68
+		$step_of_setting_active_gateways = 1;
69
+		$count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone);
70
+	//  $button_images_to_update =
71
+		return $count_of_gateways_to_convert +  $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone;
72
+	}
73
+	public function __construct()
74
+	{
75
+		$this->_pretty_name = esc_html__("Gateways", "event_espresso");
76
+		parent::__construct();
77
+	}
78 78
 
79 79
 /**
80 80
  * Takes the old array of 3.1 gateway settings for this gateway and converts it
@@ -84,148 +84,148 @@  discard block
 block discarded – undo
84 84
  * @param string $new_gateway_slug
85 85
  * @return array
86 86
  */
87
-    private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug)
88
-    {
89
-        $new_gateway_settings = $old_gateway_settings;
90
-        switch ($new_gateway_slug) {
91
-            case 'Bank':
92
-                $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account'];
93
-                $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title'];
94
-                break;
95
-            case 'Invoice':
96
-                $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url'];
97
-                // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4
98
-                // it gets used in the receipts which are available to everyone. So usually it's best to not
99
-                // migrate this.
100
-                unset($new_gateway_settings['payment_address']);
101
-                break;
102
-            case 'Paypal_Pro':
103
-                $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email'];
104
-                $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username'];
105
-                $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password'];
106
-                $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature'];
107
-                $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']);
108
-                $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox'];
109
-                break;
110
-        }
111
-        return $new_gateway_settings;
112
-    }
87
+	private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug)
88
+	{
89
+		$new_gateway_settings = $old_gateway_settings;
90
+		switch ($new_gateway_slug) {
91
+			case 'Bank':
92
+				$new_gateway_settings['account_number'] = $old_gateway_settings['bank_account'];
93
+				$new_gateway_settings['page_title'] = $old_gateway_settings['bank_title'];
94
+				break;
95
+			case 'Invoice':
96
+				$new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url'];
97
+				// Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4
98
+				// it gets used in the receipts which are available to everyone. So usually it's best to not
99
+				// migrate this.
100
+				unset($new_gateway_settings['payment_address']);
101
+				break;
102
+			case 'Paypal_Pro':
103
+				$new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email'];
104
+				$new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username'];
105
+				$new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password'];
106
+				$new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature'];
107
+				$new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']);
108
+				$new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox'];
109
+				break;
110
+		}
111
+		return $new_gateway_settings;
112
+	}
113 113
 /**
114
- * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway
115
- * @param string $new_gateway_slug
116
- * @return string
117
- */
118
-    private function _get_old_gateway_option($new_gateway_slug)
119
-    {
120
-        $option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
121
-        $settings =  get_option($option_name, null);
122
-    //  if( ! $settings){
123
-    //      $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
124
-    //  }
125
-        return $settings;
126
-    }
114
+	 * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway
115
+	 * @param string $new_gateway_slug
116
+	 * @return string
117
+	 */
118
+	private function _get_old_gateway_option($new_gateway_slug)
119
+	{
120
+		$option_name = $this->_get_old_gateway_option_name($new_gateway_slug);
121
+		$settings =  get_option($option_name, null);
122
+	//  if( ! $settings){
123
+	//      $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug));
124
+	//  }
125
+		return $settings;
126
+	}
127 127
 
128 128
 /**
129 129
  * Just gets the old gateways slug
130 130
  * @param string $new_gateway_slug
131 131
  * @return string
132 132
  */
133
-    private function _get_old_gateway_option_name($new_gateway_slug)
134
-    {
135
-        $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone));
136
-        $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ];
137
-        $normal_option_prefix = 'event_espresso_';
138
-        $normal_option_postfix = '_settings';
139
-        switch ($new_gateway_slug) {
140
-            case 'Bank':
141
-                $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix;
142
-                break;
143
-            case 'Aim':
144
-                $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix;
145
-                break;
146
-            case 'Check':
147
-                $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix;
148
-                break;
149
-            case 'Ideal':
150
-                $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix;
151
-                break;
152
-            case 'Invoice':
153
-                $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix;
154
-                break;
155
-            case 'Purchase_Order':
156
-                $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix;
157
-                break;
158
-            case 'USAePay_Offsite':
159
-                $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix;
160
-                break;
161
-            case 'USAePay_Onsite':
162
-                $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix;
163
-                break;
164
-            default:
165
-                $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix);
166
-        }
167
-        return $option_name;
168
-    }
133
+	private function _get_old_gateway_option_name($new_gateway_slug)
134
+	{
135
+		$new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone));
136
+		$old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ];
137
+		$normal_option_prefix = 'event_espresso_';
138
+		$normal_option_postfix = '_settings';
139
+		switch ($new_gateway_slug) {
140
+			case 'Bank':
141
+				$option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix;
142
+				break;
143
+			case 'Aim':
144
+				$option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix;
145
+				break;
146
+			case 'Check':
147
+				$option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix;
148
+				break;
149
+			case 'Ideal':
150
+				$option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix;
151
+				break;
152
+			case 'Invoice':
153
+				$option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix;
154
+				break;
155
+			case 'Purchase_Order':
156
+				$option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix;
157
+				break;
158
+			case 'USAePay_Offsite':
159
+				$option_name = 'espresso_usaepay_offsite' . $normal_option_postfix;
160
+				break;
161
+			case 'USAePay_Onsite':
162
+				$option_name = 'espresso_usaepay_onsite' . $normal_option_postfix;
163
+				break;
164
+			default:
165
+				$option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix);
166
+		}
167
+		return $option_name;
168
+	}
169 169
 
170
-    private function _convert_active_gateways()
171
-    {
172
-        // just does it all one big swoop
173
-        $old_active_gateways = get_option('event_espresso_active_gateways');
174
-        $new_active_gateways = EE_Config::instance()->gateway->active_gateways;
175
-        foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
176
-            if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
177
-                $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
178
-                continue;
179
-            }
180
-            $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
170
+	private function _convert_active_gateways()
171
+	{
172
+		// just does it all one big swoop
173
+		$old_active_gateways = get_option('event_espresso_active_gateways');
174
+		$new_active_gateways = EE_Config::instance()->gateway->active_gateways;
175
+		foreach ($old_active_gateways as $old_gateway_slug => $filepath) {
176
+			if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) {
177
+				$this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug));
178
+				continue;
179
+			}
180
+			$new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ];
181 181
 
182
-            // in the new format we can also upload gateways to the uploads directory and
183
-            $new_active_gateways[ $new_gateway_slug ] = false;
184
-        }
185
-        EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
186
-    }
182
+			// in the new format we can also upload gateways to the uploads directory and
183
+			$new_active_gateways[ $new_gateway_slug ] = false;
184
+		}
185
+		EE_Config::instance()->gateway->active_gateways = $new_active_gateways;
186
+	}
187 187
 
188
-    protected $_gateways_we_know_how_to_migrate = array(
189
-        'aim' => 'Aim',
190
-        'bank' => 'Bank',
191
-        'check' => 'Check',
192
-        'invoice' => 'Invoice',
193
-        'paypal' => 'Paypal_Standard',
194
-        'paypal_pro' => 'Paypal_Pro',
188
+	protected $_gateways_we_know_how_to_migrate = array(
189
+		'aim' => 'Aim',
190
+		'bank' => 'Bank',
191
+		'check' => 'Check',
192
+		'invoice' => 'Invoice',
193
+		'paypal' => 'Paypal_Standard',
194
+		'paypal_pro' => 'Paypal_Pro',
195 195
 
196
-    );
196
+	);
197 197
 
198
-    protected $_gateways_we_leave_alone = array(
199
-        '2checkout' => '2checkout',
200
-        'anz' => 'Anz',
201
-        'atos' => 'Atos',
202
-        'authnet' => 'Authnet',
203
-        'beanstream' => 'Beanstream',
204
-        'evertec' => 'Evertec',
205
-        'eway' => 'Eway',
206
-        'eway_rapid3' => 'Eway_Rapid3',
207
-        'exact' => 'Exact',
208
-        'firstdata' => 'Firstdata',
209
-        'firstdat_e4' => 'Firstdata_E4',
210
-        'ideal' => 'Ideal',
211
-        'infusion_payment' => 'InfusionSoft',
212
-        'luottokunta' => 'Luottokunta',
213
-        'megasoft' => 'Megasoft',
214
-        'moneris_hpp' => 'Moneris_HPP',
215
-        'mwarrior' => 'Mwarrior',
216
-        'nab' => 'NAB',
217
-        'paychoice' => 'Paychoice',
218
-        'paytrace' => 'Paytrace',
219
-        'psigate' => 'Psigate',
220
-        'purchase_order' => 'Purchase_Order',
221
-        'qbms' => 'QBMS',
222
-        'quickpay' => 'Quickpay',
223
-        'realauth' => 'Realauth',
224
-        'securepay_aus' => 'Securepay_Aus',
225
-        'stripe' => 'Stripe',
226
-        'usaepay_offsite' => 'USAePay_Offsite',
227
-        'usaepay_onsite' => 'USAePay_Onsite',
228
-        'wepay' => 'Wepay',
229
-        'worldpay' => 'Worldpay'
230
-    );
198
+	protected $_gateways_we_leave_alone = array(
199
+		'2checkout' => '2checkout',
200
+		'anz' => 'Anz',
201
+		'atos' => 'Atos',
202
+		'authnet' => 'Authnet',
203
+		'beanstream' => 'Beanstream',
204
+		'evertec' => 'Evertec',
205
+		'eway' => 'Eway',
206
+		'eway_rapid3' => 'Eway_Rapid3',
207
+		'exact' => 'Exact',
208
+		'firstdata' => 'Firstdata',
209
+		'firstdat_e4' => 'Firstdata_E4',
210
+		'ideal' => 'Ideal',
211
+		'infusion_payment' => 'InfusionSoft',
212
+		'luottokunta' => 'Luottokunta',
213
+		'megasoft' => 'Megasoft',
214
+		'moneris_hpp' => 'Moneris_HPP',
215
+		'mwarrior' => 'Mwarrior',
216
+		'nab' => 'NAB',
217
+		'paychoice' => 'Paychoice',
218
+		'paytrace' => 'Paytrace',
219
+		'psigate' => 'Psigate',
220
+		'purchase_order' => 'Purchase_Order',
221
+		'qbms' => 'QBMS',
222
+		'quickpay' => 'Quickpay',
223
+		'realauth' => 'Realauth',
224
+		'securepay_aus' => 'Securepay_Aus',
225
+		'stripe' => 'Stripe',
226
+		'usaepay_offsite' => 'USAePay_Offsite',
227
+		'usaepay_onsite' => 'USAePay_Onsite',
228
+		'wepay' => 'Wepay',
229
+		'worldpay' => 'Worldpay'
230
+	);
231 231
 }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_event_category.dmsstage.php 2 patches
Indentation   +76 added lines, -78 removed lines patch added patch discarded remove patch
@@ -24,87 +24,85 @@
 block discarded – undo
24 24
                 'term_taxonomy_id'=>new EE_Foreign_Key_Int_Field('term_taxonomy_id', esc_html__('Term (in context of a taxonomy) ID','event_espresso'), false, 0, 'Term_Taxonomy'),
25 25
                 'term_order'=>new EE_Integer_Field('term_order', esc_html__('Term Order','event_espresso'), false, 0)
26 26
             ));
27
-
28
-
29 27
  *
30 28
  */
31 29
 class EE_DMS_4_1_0_event_category extends EE_Data_Migration_Script_Stage
32 30
 {
33
-    private $_old_table;
34
-    private $_new_table;
35
-    public function _migration_step($num_items = 50)
36
-    {
37
-        global $wpdb;
38
-        $start_at_record = $this->count_records_migrated();
39
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
40
-        $items_actually_migrated = 0;
41
-        foreach ($rows as $event_venue_rel) {
42
-            $term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel);
43
-            if ($term_relation_id) {
44
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id);
45
-            }
46
-            $items_actually_migrated++;
47
-        }
48
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
49
-            $this->set_completed();
50
-        }
51
-        return $items_actually_migrated;
52
-    }
53
-    public function _count_records_to_migrate()
54
-    {
55
-        global $wpdb;
56
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
57
-        return $count;
58
-    }
59
-    public function __construct()
60
-    {
61
-        global $wpdb;
62
-        $this->_old_table = $wpdb->prefix . "events_category_rel";
63
-        $this->_new_table = $wpdb->prefix . "term_relationships";
64
-        $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso");
65
-        parent::__construct();
66
-    }
31
+	private $_old_table;
32
+	private $_new_table;
33
+	public function _migration_step($num_items = 50)
34
+	{
35
+		global $wpdb;
36
+		$start_at_record = $this->count_records_migrated();
37
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
+		$items_actually_migrated = 0;
39
+		foreach ($rows as $event_venue_rel) {
40
+			$term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel);
41
+			if ($term_relation_id) {
42
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id);
43
+			}
44
+			$items_actually_migrated++;
45
+		}
46
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
47
+			$this->set_completed();
48
+		}
49
+		return $items_actually_migrated;
50
+	}
51
+	public function _count_records_to_migrate()
52
+	{
53
+		global $wpdb;
54
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
55
+		return $count;
56
+	}
57
+	public function __construct()
58
+	{
59
+		global $wpdb;
60
+		$this->_old_table = $wpdb->prefix . "events_category_rel";
61
+		$this->_new_table = $wpdb->prefix . "term_relationships";
62
+		$this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso");
63
+		parent::__construct();
64
+	}
67 65
 
68
-    /**
69
-     * Attempts to insert a new question group inthe new format given an old one
70
-     * @global type $wpdb
71
-     * @param array $old_event_cat_relation
72
-     * @return int
73
-     */
74
-    private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation)
75
-    {
76
-        global $wpdb;
77
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts");
78
-        $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy");
79
-        if (! $new_event_id) {
80
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id']));
81
-            return 0;
82
-        }
83
-        if (! $new_term_taxonomy_id) {
84
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id']));
85
-            return 0;
86
-        }
87
-        $cols_n_values = array(
88
-            'object_id' => $new_event_id,
89
-            'term_taxonomy_id' => $new_term_taxonomy_id,
90
-            'term_order' => 0
91
-        );
92
-        $datatypes = array(
93
-            '%d',// object_id
94
-            '%d',// term_taxonomy_id
95
-            '%d',// term_order
96
-        );
97
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
98
-        if (! $success) {
99
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes));
100
-            return 0;
101
-        } else {
102
-            // increment the term-taxonomie's count
103
-            $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id));
104
-            if (! $success) {
105
-                $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error));
106
-            }
107
-        }
108
-        return $wpdb->insert_id;
109
-    }
66
+	/**
67
+	 * Attempts to insert a new question group inthe new format given an old one
68
+	 * @global type $wpdb
69
+	 * @param array $old_event_cat_relation
70
+	 * @return int
71
+	 */
72
+	private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation)
73
+	{
74
+		global $wpdb;
75
+		$new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts");
76
+		$new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy");
77
+		if (! $new_event_id) {
78
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id']));
79
+			return 0;
80
+		}
81
+		if (! $new_term_taxonomy_id) {
82
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id']));
83
+			return 0;
84
+		}
85
+		$cols_n_values = array(
86
+			'object_id' => $new_event_id,
87
+			'term_taxonomy_id' => $new_term_taxonomy_id,
88
+			'term_order' => 0
89
+		);
90
+		$datatypes = array(
91
+			'%d',// object_id
92
+			'%d',// term_taxonomy_id
93
+			'%d',// term_order
94
+		);
95
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
96
+		if (! $success) {
97
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes));
98
+			return 0;
99
+		} else {
100
+			// increment the term-taxonomie's count
101
+			$success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id));
102
+			if (! $success) {
103
+				$this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error));
104
+			}
105
+		}
106
+		return $wpdb->insert_id;
107
+	}
110 108
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
     public function _count_records_to_migrate()
54 54
     {
55 55
         global $wpdb;
56
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
56
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
57 57
         return $count;
58 58
     }
59 59
     public function __construct()
60 60
     {
61 61
         global $wpdb;
62
-        $this->_old_table = $wpdb->prefix . "events_category_rel";
63
-        $this->_new_table = $wpdb->prefix . "term_relationships";
62
+        $this->_old_table = $wpdb->prefix."events_category_rel";
63
+        $this->_new_table = $wpdb->prefix."term_relationships";
64 64
         $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso");
65 65
         parent::__construct();
66 66
     }
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
     private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation)
75 75
     {
76 76
         global $wpdb;
77
-        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts");
78
-        $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy");
79
-        if (! $new_event_id) {
77
+        $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix."posts");
78
+        $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix."term_taxonomy");
79
+        if ( ! $new_event_id) {
80 80
             $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id']));
81 81
             return 0;
82 82
         }
83
-        if (! $new_term_taxonomy_id) {
83
+        if ( ! $new_term_taxonomy_id) {
84 84
             $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id']));
85 85
             return 0;
86 86
         }
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
             'term_order' => 0
91 91
         );
92 92
         $datatypes = array(
93
-            '%d',// object_id
94
-            '%d',// term_taxonomy_id
95
-            '%d',// term_order
93
+            '%d', // object_id
94
+            '%d', // term_taxonomy_id
95
+            '%d', // term_order
96 96
         );
97 97
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
98
-        if (! $success) {
98
+        if ( ! $success) {
99 99
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes));
100 100
             return 0;
101 101
         } else {
102 102
             // increment the term-taxonomie's count
103 103
             $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id));
104
-            if (! $success) {
104
+            if ( ! $success) {
105 105
                 $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error));
106 106
             }
107 107
         }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_answers.dmsstage.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -32,102 +32,102 @@
 block discarded – undo
32 32
 
33 33
 class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table
34 34
 {
35
-    private $_new_answer_table;
36
-    private $_new_question_table;
37
-    public function __construct()
38
-    {
39
-        global $wpdb;
40
-        $this->_pretty_name = esc_html__("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix . "events_answer";
42
-        // join to attendee and then join to events table
43
-        $this->select_expression = 'ans.*, e.event_status';
44
-        $this->_extra_where_sql = ' AS ans 
35
+	private $_new_answer_table;
36
+	private $_new_question_table;
37
+	public function __construct()
38
+	{
39
+		global $wpdb;
40
+		$this->_pretty_name = esc_html__("Answers", "event_espresso");
41
+		$this->_old_table = $wpdb->prefix . "events_answer";
42
+		// join to attendee and then join to events table
43
+		$this->select_expression = 'ans.*, e.event_status';
44
+		$this->_extra_where_sql = ' AS ans 
45 45
             INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
46 46
             INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
47 47
             WHERE e.event_status !="D"';
48
-        $this->_new_answer_table = $wpdb->prefix . "esp_answer";
49
-        $this->_new_question_table = $wpdb->prefix . "esp_question";
50
-        parent::__construct();
51
-    }
52
-    protected function _migrate_old_row($old_row)
53
-    {
54
-        // get the new REGs for the old answer
55
-        global $wpdb;
56
-        $old_attendee_table = $wpdb->prefix . "events_attendee";
57
-        $new_reg_table = $wpdb->prefix . "esp_registration";
58
-        $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
-        if (! $regs) {
60
-            $this->add_error(sprintf(esc_html__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61
-            return false;
62
-        }
63
-        // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
64
-        foreach ($regs as $new_reg_id) {
65
-            $this->_insert_new_answer($old_row, $new_reg_id);
66
-        }
67
-    }
68
-    /**
69
-     * Creates a 4.1 price base type
70
-     * @global type $wpdb
71
-     * @param array $old_price
72
-     * @param int $new_reg_id
73
-     * @return int
74
-     */
75
-    private function _insert_new_answer($old_answer, $new_reg_id)
76
-    {
77
-        global $wpdb;
78
-        $old_question_table = $wpdb->prefix . "events_question";
79
-        $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
48
+		$this->_new_answer_table = $wpdb->prefix . "esp_answer";
49
+		$this->_new_question_table = $wpdb->prefix . "esp_question";
50
+		parent::__construct();
51
+	}
52
+	protected function _migrate_old_row($old_row)
53
+	{
54
+		// get the new REGs for the old answer
55
+		global $wpdb;
56
+		$old_attendee_table = $wpdb->prefix . "events_attendee";
57
+		$new_reg_table = $wpdb->prefix . "esp_registration";
58
+		$regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
+		if (! $regs) {
60
+			$this->add_error(sprintf(esc_html__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61
+			return false;
62
+		}
63
+		// as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee)
64
+		foreach ($regs as $new_reg_id) {
65
+			$this->_insert_new_answer($old_row, $new_reg_id);
66
+		}
67
+	}
68
+	/**
69
+	 * Creates a 4.1 price base type
70
+	 * @global type $wpdb
71
+	 * @param array $old_price
72
+	 * @param int $new_reg_id
73
+	 * @return int
74
+	 */
75
+	private function _insert_new_answer($old_answer, $new_reg_id)
76
+	{
77
+		global $wpdb;
78
+		$old_question_table = $wpdb->prefix . "events_question";
79
+		$new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
80 80
 
81
-        $question_row = $this->_get_question_type_and_system($new_question_id);
82
-        if ($question_row['QST_system']) {
83
-            // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column,
84
-            // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom
85
-            // questions.
86
-            return 0;
87
-        }
88
-        if (in_array($question_row['QST_type'], array('MULTIPLE'))) {
89
-            $ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
90
-        } else {
91
-            $ans_value = stripslashes($old_answer['answer']);
92
-        }
93
-        $cols_n_values = array(
94
-            'REG_ID' => $new_reg_id,
95
-            'QST_ID' => $new_question_id,
96
-            'ANS_value' => $ans_value
97
-        );
98
-        $datatypes = array(
99
-            '%d',// REG_ID
100
-            '%d',// QST_ID
101
-            '%s',// ANS_value
102
-        );
103
-        $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
-        if (! $success) {
105
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106
-            return 0;
107
-        }
108
-        $new_id = $wpdb->insert_id;
109
-        return $new_id;
110
-    }
81
+		$question_row = $this->_get_question_type_and_system($new_question_id);
82
+		if ($question_row['QST_system']) {
83
+			// It's an answer to a system question? EE3 used to store that on both the attendee and the answers column,
84
+			// but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom
85
+			// questions.
86
+			return 0;
87
+		}
88
+		if (in_array($question_row['QST_type'], array('MULTIPLE'))) {
89
+			$ans_value = serialize(explode(",", stripslashes($old_answer['answer'])));
90
+		} else {
91
+			$ans_value = stripslashes($old_answer['answer']);
92
+		}
93
+		$cols_n_values = array(
94
+			'REG_ID' => $new_reg_id,
95
+			'QST_ID' => $new_question_id,
96
+			'ANS_value' => $ans_value
97
+		);
98
+		$datatypes = array(
99
+			'%d',// REG_ID
100
+			'%d',// QST_ID
101
+			'%s',// ANS_value
102
+		);
103
+		$success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
+		if (! $success) {
105
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106
+			return 0;
107
+		}
108
+		$new_id = $wpdb->insert_id;
109
+		return $new_id;
110
+	}
111 111
 
112
-    /**
113
-     * Gets the question's type
114
-     * @global type $wpdb
115
-     * @param type $question_id
116
-     * @return array {
117
-     *  @type string $QST_type
118
-     *  @type string $QST_system
119
-     * }
120
-     */
121
-    private function _get_question_type_and_system($question_id)
122
-    {
123
-        global $wpdb;
124
-        $row = $wpdb->get_row(
125
-            $wpdb->prepare(
126
-                "SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1",
127
-                $question_id
128
-            ),
129
-            ARRAY_A
130
-        );
131
-        return $row;
132
-    }
112
+	/**
113
+	 * Gets the question's type
114
+	 * @global type $wpdb
115
+	 * @param type $question_id
116
+	 * @return array {
117
+	 *  @type string $QST_type
118
+	 *  @type string $QST_system
119
+	 * }
120
+	 */
121
+	private function _get_question_type_and_system($question_id)
122
+	{
123
+		global $wpdb;
124
+		$row = $wpdb->get_row(
125
+			$wpdb->prepare(
126
+				"SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1",
127
+				$question_id
128
+			),
129
+			ARRAY_A
130
+		);
131
+		return $row;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -38,25 +38,25 @@  discard block
 block discarded – undo
38 38
     {
39 39
         global $wpdb;
40 40
         $this->_pretty_name = esc_html__("Answers", "event_espresso");
41
-        $this->_old_table = $wpdb->prefix . "events_answer";
41
+        $this->_old_table = $wpdb->prefix."events_answer";
42 42
         // join to attendee and then join to events table
43 43
         $this->select_expression = 'ans.*, e.event_status';
44 44
         $this->_extra_where_sql = ' AS ans 
45
-            INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id
46
-            INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id 
45
+            INNER JOIN ' . $wpdb->prefix.'events_attendee AS att ON ans.attendee_id = att.id
46
+            INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id = e.id 
47 47
             WHERE e.event_status !="D"';
48
-        $this->_new_answer_table = $wpdb->prefix . "esp_answer";
49
-        $this->_new_question_table = $wpdb->prefix . "esp_question";
48
+        $this->_new_answer_table = $wpdb->prefix."esp_answer";
49
+        $this->_new_question_table = $wpdb->prefix."esp_question";
50 50
         parent::__construct();
51 51
     }
52 52
     protected function _migrate_old_row($old_row)
53 53
     {
54 54
         // get the new REGs for the old answer
55 55
         global $wpdb;
56
-        $old_attendee_table = $wpdb->prefix . "events_attendee";
57
-        $new_reg_table = $wpdb->prefix . "esp_registration";
56
+        $old_attendee_table = $wpdb->prefix."events_attendee";
57
+        $new_reg_table = $wpdb->prefix."esp_registration";
58 58
         $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table);
59
-        if (! $regs) {
59
+        if ( ! $regs) {
60 60
             $this->add_error(sprintf(esc_html__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row)));
61 61
             return false;
62 62
         }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     private function _insert_new_answer($old_answer, $new_reg_id)
76 76
     {
77 77
         global $wpdb;
78
-        $old_question_table = $wpdb->prefix . "events_question";
78
+        $old_question_table = $wpdb->prefix."events_question";
79 79
         $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table);
80 80
 
81 81
         $question_row = $this->_get_question_type_and_system($new_question_id);
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
             'ANS_value' => $ans_value
97 97
         );
98 98
         $datatypes = array(
99
-            '%d',// REG_ID
100
-            '%d',// QST_ID
101
-            '%s',// ANS_value
99
+            '%d', // REG_ID
100
+            '%d', // QST_ID
101
+            '%s', // ANS_value
102 102
         );
103 103
         $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes);
104
-        if (! $success) {
104
+        if ( ! $success) {
105 105
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes));
106 106
             return 0;
107 107
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         global $wpdb;
124 124
         $row = $wpdb->get_row(
125 125
             $wpdb->prepare(
126
-                "SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1",
126
+                "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1",
127 127
                 $question_id
128 128
             ),
129 129
             ARRAY_A
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_events.dmsstage.php 2 patches
Indentation   +635 added lines, -640 removed lines patch added patch discarded remove patch
@@ -85,8 +85,6 @@  discard block
 block discarded – undo
85 85
   KEY `submitted` (`submitted`),
86 86
   KEY `likes` (`likes`)
87 87
 ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$
88
-
89
-
90 88
  *
91 89
  * 4.1 Event model:
92 90
  * $this->_tables = array(
@@ -125,7 +123,6 @@  discard block
 block discarded – undo
125 123
                 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', esc_html__("Accept Donations?", "event_espresso"), false, false)
126 124
 
127 125
             ));
128
-
129 126
  *
130 127
  * 3.1's start end table
131 128
  *
@@ -138,8 +135,6 @@  discard block
 block discarded – undo
138 135
   PRIMARY KEY (`id`),
139 136
   KEY `event_id` (`event_id`)
140 137
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$
141
-
142
-
143 138
  *
144 139
  * and 4.1 Datetime model's tables and fields:
145 140
  * $this->_tables = array(
@@ -161,172 +156,172 @@  discard block
 block discarded – undo
161 156
  */
162 157
 class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage
163 158
 {
164
-    private $_old_table;
165
-    private $_old_start_end_table;
166
-    private $_new_table;
167
-    private $_new_meta_table;
168
-    private $_new_datetime_table;
169
-
170
-
171
-
172
-    /**
173
-     * Just initializes the status of the migration
174
-     * @throws EE_Error
175
-     */
176
-    public function __construct()
177
-    {
178
-        global $wpdb;
179
-        $this->_old_table = $wpdb->prefix . "events_detail";
180
-        $this->_old_start_end_table = $wpdb->prefix . "events_start_end";
181
-        $this->_new_table = $wpdb->prefix . "posts";
182
-        $this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
183
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
184
-        $this->_pretty_name = esc_html__("Events", "event_espresso");
185
-        parent::__construct();
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * Counts the records to migrate; the public version may cache it
192
-     * @return int
193
-     */
194
-    public function _count_records_to_migrate()
195
-    {
196
-        global $wpdb;
197
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
198
-        return intval($count);
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
205
-     * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
206
-     * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
207
-     * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50,
208
-     * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
209
-     * @param int $num_items_to_migrate
210
-     * @return int number of items ACTUALLY migrated
211
-     */
212
-    protected function _migration_step($num_items_to_migrate = 50)
213
-    {
214
-        global $wpdb;
215
-        // because the migration of each event can be a LOT more work, make each step smaller
216
-        $num_items_to_migrate = max(1, $num_items_to_migrate / 5);
217
-        $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
218
-        $items_migrated_this_step = 0;
219
-
220
-        foreach ($events as $event_row) {
221
-            $guid = null;
222
-            // insert new 4.1 Attendee object using $wpdb
223
-            $post_id = $this->_insert_cpt($event_row);
224
-            if ($post_id) {
225
-                $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
226
-                $meta_id = $this->_insert_event_meta($event_row, $post_id);
227
-                if ($meta_id) {
228
-                    $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
229
-                }
230
-                $this->_convert_start_end_times($event_row, $post_id);
231
-                $event_meta = maybe_unserialize($event_row['event_meta']);
232
-                $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
233
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
234
-
235
-                // maybe create a venue from info on the event?
236
-                $new_venue_id = $this->_maybe_create_venue($event_row);
237
-                if ($new_venue_id) {
238
-                    $this->_insert_new_venue_to_event($post_id, $new_venue_id);
239
-                }
240
-                $this->_add_post_metas($event_row, $post_id);
241
-            }
242
-            $items_migrated_this_step++;
243
-            if ($guid) {
244
-                // if we had to check for an image attachment
245
-                // then let's call it a day (avoid timing out, because this took a long time)
246
-                break;
247
-            }
248
-        }
249
-        if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
250
-            $this->set_status(EE_Data_Migration_Manager::status_completed);
251
-        }
252
-        return $items_migrated_this_step;
253
-    }
254
-
255
-    /**
256
-     * Stores any extra 3.1 "event_meta" column things as post meta
257
-     * @param array $old_event
258
-     * @param int $post_id
259
-     * @return void
260
-     */
261
-    private function _add_post_metas($old_event, $post_id)
262
-    {
263
-        $event_meta = maybe_unserialize($old_event['event_meta']);
264
-        if (! $event_meta || ! is_array($event_meta)) {
265
-            return;
266
-        }
267
-        unset($event_meta['date_submitted']);// factored into CPT
268
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
269
-        unset($event_meta['default_payment_status']);// dido
270
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
271
-        foreach ($event_meta as $meta_key => $meta_value) {
272
-            if ($meta_key) {// if the meta key is just an empty string, ignore it
273
-                $success = add_post_meta($post_id, $meta_key, $meta_value, true);
274
-                if (! $success) {
275
-                    $this->add_error(sprintf(esc_html__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
276
-                }
277
-            }
278
-        }
279
-        if ($old_event['alt_email']) {
280
-            add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
281
-        }
282
-        if ($old_event['recurrence_id']) {
283
-            add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
284
-        }
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Finds a unique slug for this event, given its name (we could have simply used
291
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
292
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
293
-     * @param string $event_name (the name of the event for reading by humans)
294
-     * @param string $old_identifier the old EE3 identifier (a long unique string)
295
-     * @param string $new_post_status a post status
296
-     * @return string
297
-     */
298
-    private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
299
-    {
300
-        $count = 0;
301
-        $original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
302
-        return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
303
-    }
304
-
305
-    /**
306
-     * returns whether or not there is a post that has this same slug (post_title)
307
-     * @global wpdb $wpdb
308
-     * @param string $slug
309
-     * @return boolean
310
-     */
311
-    private function _other_post_exists_with_that_slug($slug)
312
-    {
313
-        global $wpdb;
314
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
315
-        $count = $wpdb->get_var($query);
316
-        return (bool) intval($count);
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * @param $old_event
323
-     * @return int
324
-     */
325
-    private function _insert_cpt($old_event)
326
-    {
327
-        global $wpdb;
328
-        // convert 3.1 event status to 4.1 CPT status
329
-        // for reference, 3.1 event stati available for setting are:
159
+	private $_old_table;
160
+	private $_old_start_end_table;
161
+	private $_new_table;
162
+	private $_new_meta_table;
163
+	private $_new_datetime_table;
164
+
165
+
166
+
167
+	/**
168
+	 * Just initializes the status of the migration
169
+	 * @throws EE_Error
170
+	 */
171
+	public function __construct()
172
+	{
173
+		global $wpdb;
174
+		$this->_old_table = $wpdb->prefix . "events_detail";
175
+		$this->_old_start_end_table = $wpdb->prefix . "events_start_end";
176
+		$this->_new_table = $wpdb->prefix . "posts";
177
+		$this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
178
+		$this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
179
+		$this->_pretty_name = esc_html__("Events", "event_espresso");
180
+		parent::__construct();
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Counts the records to migrate; the public version may cache it
187
+	 * @return int
188
+	 */
189
+	public function _count_records_to_migrate()
190
+	{
191
+		global $wpdb;
192
+		$count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
193
+		return intval($count);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
200
+	 * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
201
+	 * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
202
+	 * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50,
203
+	 * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
204
+	 * @param int $num_items_to_migrate
205
+	 * @return int number of items ACTUALLY migrated
206
+	 */
207
+	protected function _migration_step($num_items_to_migrate = 50)
208
+	{
209
+		global $wpdb;
210
+		// because the migration of each event can be a LOT more work, make each step smaller
211
+		$num_items_to_migrate = max(1, $num_items_to_migrate / 5);
212
+		$events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A);
213
+		$items_migrated_this_step = 0;
214
+
215
+		foreach ($events as $event_row) {
216
+			$guid = null;
217
+			// insert new 4.1 Attendee object using $wpdb
218
+			$post_id = $this->_insert_cpt($event_row);
219
+			if ($post_id) {
220
+				$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id);
221
+				$meta_id = $this->_insert_event_meta($event_row, $post_id);
222
+				if ($meta_id) {
223
+					$this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id);
224
+				}
225
+				$this->_convert_start_end_times($event_row, $post_id);
226
+				$event_meta = maybe_unserialize($event_row['event_meta']);
227
+				$guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null;
228
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this);
229
+
230
+				// maybe create a venue from info on the event?
231
+				$new_venue_id = $this->_maybe_create_venue($event_row);
232
+				if ($new_venue_id) {
233
+					$this->_insert_new_venue_to_event($post_id, $new_venue_id);
234
+				}
235
+				$this->_add_post_metas($event_row, $post_id);
236
+			}
237
+			$items_migrated_this_step++;
238
+			if ($guid) {
239
+				// if we had to check for an image attachment
240
+				// then let's call it a day (avoid timing out, because this took a long time)
241
+				break;
242
+			}
243
+		}
244
+		if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) {
245
+			$this->set_status(EE_Data_Migration_Manager::status_completed);
246
+		}
247
+		return $items_migrated_this_step;
248
+	}
249
+
250
+	/**
251
+	 * Stores any extra 3.1 "event_meta" column things as post meta
252
+	 * @param array $old_event
253
+	 * @param int $post_id
254
+	 * @return void
255
+	 */
256
+	private function _add_post_metas($old_event, $post_id)
257
+	{
258
+		$event_meta = maybe_unserialize($old_event['event_meta']);
259
+		if (! $event_meta || ! is_array($event_meta)) {
260
+			return;
261
+		}
262
+		unset($event_meta['date_submitted']);// factored into CPT
263
+		unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
264
+		unset($event_meta['default_payment_status']);// dido
265
+		unset($event_meta['event_thumbnail_url']);// used to find post featured image
266
+		foreach ($event_meta as $meta_key => $meta_value) {
267
+			if ($meta_key) {// if the meta key is just an empty string, ignore it
268
+				$success = add_post_meta($post_id, $meta_key, $meta_value, true);
269
+				if (! $success) {
270
+					$this->add_error(sprintf(esc_html__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
271
+				}
272
+			}
273
+		}
274
+		if ($old_event['alt_email']) {
275
+			add_post_meta($post_id, 'alt_email', $old_event['alt_email']);
276
+		}
277
+		if ($old_event['recurrence_id']) {
278
+			add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']);
279
+		}
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * Finds a unique slug for this event, given its name (we could have simply used
286
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
287
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
288
+	 * @param string $event_name (the name of the event for reading by humans)
289
+	 * @param string $old_identifier the old EE3 identifier (a long unique string)
290
+	 * @param string $new_post_status a post status
291
+	 * @return string
292
+	 */
293
+	private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish')
294
+	{
295
+		$count = 0;
296
+		$original_name = $event_name ? sanitize_title($event_name) : $old_identifier;
297
+		return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0);
298
+	}
299
+
300
+	/**
301
+	 * returns whether or not there is a post that has this same slug (post_title)
302
+	 * @global wpdb $wpdb
303
+	 * @param string $slug
304
+	 * @return boolean
305
+	 */
306
+	private function _other_post_exists_with_that_slug($slug)
307
+	{
308
+		global $wpdb;
309
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug);
310
+		$count = $wpdb->get_var($query);
311
+		return (bool) intval($count);
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param $old_event
318
+	 * @return int
319
+	 */
320
+	private function _insert_cpt($old_event)
321
+	{
322
+		global $wpdb;
323
+		// convert 3.1 event status to 4.1 CPT status
324
+		// for reference, 3.1 event stati available for setting are:
330 325
 //      $status = array(array('id' => 'A', 'text' => esc_html__('Public', 'event_espresso')), array('id' => 'S', 'text' => esc_html__('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => esc_html__('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => esc_html__('Draft', 'event_espresso')), array('id' => 'D', 'text' => esc_html__('Deleted', 'event_espresso')));
331 326
 //      and the json api uses the following to convert from 3.1 to 4.0
332 327
 //      'S'=>'secondary/waitlist',
@@ -340,487 +335,487 @@  discard block
 block discarded – undo
340 335
 //      4.1 Event Post stati are the normal post statis
341 336
 //      (publish,future,draft,pending,private,trash,auto-draft,inherit)
342 337
 //      and 3 custom ones: cancelled,postponed,sold_out
343
-        $status_conversions = array(
344
-            'R' => 'draft',
345
-            'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
346
-            'P' => 'pending',
347
-            'IA' => 'draft',// draft and in the past
338
+		$status_conversions = array(
339
+			'R' => 'draft',
340
+			'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
341
+			'P' => 'pending',
342
+			'IA' => 'draft',// draft and in the past
348 343
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
349
-            'O' => 'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
350
-            'A' => 'publish',
351
-            'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
352
-            'D' => 'trash',
353
-        );
354
-        $post_status = $status_conversions[ $old_event['event_status'] ];
355
-        // check if we've sold out
356
-        if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
357
-            $post_status = 'sold_out';
358
-        }
344
+			'O' => 'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
345
+			'A' => 'publish',
346
+			'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
347
+			'D' => 'trash',
348
+		);
349
+		$post_status = $status_conversions[ $old_event['event_status'] ];
350
+		// check if we've sold out
351
+		if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
352
+			$post_status = 'sold_out';
353
+		}
359 354
 //      FYI postponed and cancelled don't exist in 3.1
360
-        $cols_n_values = array(
361
-            'post_title' => stripslashes($old_event['event_name']),// EVT_name
362
-            'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
363
-            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
364
-            'post_date' => $old_event['submitted'],// EVT_created NOT
365
-            'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
366
-            'post_excerpt' => '',// EVT_short_desc
367
-            'post_modified' => $old_event['submitted'],// EVT_modified
368
-            'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
369
-            'post_author' => $old_event['wp_user'],// EVT_wp_user
370
-            'post_parent' => 0,// parent maybe get this from some REM field?
371
-            'menu_order' => 0,// EVT_order
372
-            'post_type' => 'espresso_events',// post_type
373
-            'post_status' => $post_status,// status
374
-        );
375
-        $cols_n_values_with_no_invalid_text = array();
376
-        foreach ($cols_n_values as $col => $value) {
377
-            $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
378
-            if (! is_wp_error($value_sans_invalid_chars)) {
379
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
380
-            } else {
381
-                // otherwise leave it as-is. It will blow everything up and stop the migration
382
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
383
-            }
384
-        }
385
-        $cols_n_values = $cols_n_values_with_no_invalid_text;
386
-        $datatypes = array(
387
-            '%s',// EVT_name
388
-            '%s',// EVT_desc
389
-            '%s',// EVT_slug
390
-            '%s',// EVT_created
391
-            '%s',
392
-            '%s',// EVT_short_desc
393
-            '%s',// EVT_modified
394
-            '%s',
395
-            '%s',// EVT_wp_user
396
-            '%d',// post_parent
397
-            '%d',// EVT_order
398
-            '%s',// post_type
399
-            '%s',// status
400
-        );
401
-        $success = $wpdb->insert(
402
-            $this->_new_table,
403
-            $cols_n_values,
404
-            $datatypes
405
-        );
406
-        if (! $success) {
407
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
408
-            return 0;
409
-        }
410
-        return $wpdb->insert_id;
411
-    }
412
-
413
-    /**
414
-     * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
415
-     * @global wpdb $wpdb
416
-     * @param int $event_id
417
-     * @return int
418
-     */
419
-    public static function count_registrations($event_id)
420
-    {
421
-        global $wpdb;
422
-        $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
423
-        return intval($count);
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @param $old_event
430
-     * @param $new_cpt_id
431
-     * @return int
432
-     */
433
-    private function _insert_event_meta($old_event, $new_cpt_id)
434
-    {
435
-        global $wpdb;
436
-        $event_meta = maybe_unserialize($old_event['event_meta']);
355
+		$cols_n_values = array(
356
+			'post_title' => stripslashes($old_event['event_name']),// EVT_name
357
+			'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
358
+			'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
359
+			'post_date' => $old_event['submitted'],// EVT_created NOT
360
+			'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
361
+			'post_excerpt' => '',// EVT_short_desc
362
+			'post_modified' => $old_event['submitted'],// EVT_modified
363
+			'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
364
+			'post_author' => $old_event['wp_user'],// EVT_wp_user
365
+			'post_parent' => 0,// parent maybe get this from some REM field?
366
+			'menu_order' => 0,// EVT_order
367
+			'post_type' => 'espresso_events',// post_type
368
+			'post_status' => $post_status,// status
369
+		);
370
+		$cols_n_values_with_no_invalid_text = array();
371
+		foreach ($cols_n_values as $col => $value) {
372
+			$value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
373
+			if (! is_wp_error($value_sans_invalid_chars)) {
374
+				$cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
375
+			} else {
376
+				// otherwise leave it as-is. It will blow everything up and stop the migration
377
+				$cols_n_values_with_no_invalid_text[ $col ] = $value;
378
+			}
379
+		}
380
+		$cols_n_values = $cols_n_values_with_no_invalid_text;
381
+		$datatypes = array(
382
+			'%s',// EVT_name
383
+			'%s',// EVT_desc
384
+			'%s',// EVT_slug
385
+			'%s',// EVT_created
386
+			'%s',
387
+			'%s',// EVT_short_desc
388
+			'%s',// EVT_modified
389
+			'%s',
390
+			'%s',// EVT_wp_user
391
+			'%d',// post_parent
392
+			'%d',// EVT_order
393
+			'%s',// post_type
394
+			'%s',// status
395
+		);
396
+		$success = $wpdb->insert(
397
+			$this->_new_table,
398
+			$cols_n_values,
399
+			$datatypes
400
+		);
401
+		if (! $success) {
402
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
403
+			return 0;
404
+		}
405
+		return $wpdb->insert_id;
406
+	}
407
+
408
+	/**
409
+	 * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations)
410
+	 * @global wpdb $wpdb
411
+	 * @param int $event_id
412
+	 * @return int
413
+	 */
414
+	public static function count_registrations($event_id)
415
+	{
416
+		global $wpdb;
417
+		$count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id));
418
+		return intval($count);
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * @param $old_event
425
+	 * @param $new_cpt_id
426
+	 * @return int
427
+	 */
428
+	private function _insert_event_meta($old_event, $new_cpt_id)
429
+	{
430
+		global $wpdb;
431
+		$event_meta = maybe_unserialize($old_event['event_meta']);
437 432
 //      for reference, 3.1 'default_payment_status' are: $default_payment_status = array(
438 433
 //  array('id' => "", 'text' => 'No Change'),
439 434
 //  array('id' => 'Incomplete', 'text' => 'Incomplete'),
440 435
 //  array('id' => 'Pending', 'text' => 'Pending'),
441 436
 //  //array('id' => 'Completed', 'text' => 'Completed')
442 437
 // );
443
-        $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
444
-        $cols_n_values = array(
445
-            'EVT_ID' => $new_cpt_id,// EVT_ID_fk
446
-            'EVT_display_desc' => 'Y' == $old_event['display_desc'],
447
-            'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
448
-            'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
449
-            'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
450
-            'EVT_default_registration_status' => $default_reg_status,
451
-            'EVT_member_only' => $old_event['member_only'],
452
-            'EVT_phone' => $old_event['phone'],
453
-            'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
454
-            'EVT_timezone_string' => $old_event['timezone_string'],
455
-            'EVT_external_URL' => $old_event['externalURL'],
456
-            'EVT_donations' => false// doesnt exist in 3.1
457
-
458
-        );
459
-        $datatypes = array(
460
-            '%s',// EVT_ID
461
-            '%d',// EVT_display_desc
462
-            '%d',// EVT_display_ticket_selector
463
-            '%s',// EVT_visible_on
464
-            '%d',// EVT_additional_limit
465
-            '%s',// EVT_default_registration_status
466
-            '%d',// EVT_member_only
467
-            '%s',// EVT_phone
468
-            '%d',// EVT_allow_overflow
469
-            '%s',// EVT_timezone_string
470
-            '%s',// EVT_external_URL
471
-            '%d',// EVT_donations
472
-        );
473
-        $success = $wpdb->insert(
474
-            $this->_new_meta_table,
475
-            $cols_n_values,
476
-            $datatypes
477
-        );
478
-        if (! $success) {
479
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
480
-            return 0;
481
-        }
482
-        return $wpdb->insert_id;
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     * @param $old_event
489
-     * @return int
490
-     */
491
-    private function _maybe_create_venue($old_event)
492
-    {
493
-        if (
494
-            $old_event['address'] ||
495
-                $old_event['address2'] ||
496
-                $old_event['city'] ||
497
-                $old_event['state'] ||
498
-                $old_event['zip'] ||
499
-                $old_event['venue_title'] ||
500
-                $old_event['venue_url'] ||
501
-                $old_event['venue_image'] ||
502
-                $old_event['venue_phone'] ||
503
-                $old_event['virtual_url'] ||
504
-                $old_event['virtual_phone']
505
-        ) {
506
-            $old_id = $this->_duplicate_venue_exists($old_event);
507
-            if ($old_id) {
508
-                return $old_id;
509
-            }
510
-            $new_id = $this->_insert_venue_into_posts($old_event);
511
-            if ($new_id) {
512
-                $this->_insert_venue_into_meta_table($new_id, $old_event);
513
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
514
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
515
-            }
516
-            // we don't bother recording the conversion from old events to venues as that
517
-            // will complicate finding the conversion from old venues to new events
518
-            return $new_id;
519
-        } else {
520
-            return 0;
521
-        }
522
-    }
523
-
524
-    /**
525
-     * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
526
-     * If so, return it. Otherwise return NULL.
527
-     * @param array $old_event
528
-     * @return int duplicate venue id
529
-     */
530
-    private function _duplicate_venue_exists($old_event)
531
-    {
532
-        global $wpdb;
533
-        $conditions = array(
534
-            'VNU_address' => $old_event ['address'],
535
-            'VNU_address2' => $old_event['address2'],
536
-            'VNU_city' => $old_event['city'],
537
-            'VNU_zip' => $old_event['zip'],
538
-            'post_title' => $this->_get_venue_title_for_event($old_event),
539
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
540
-            'VNU_url' => $old_event['venue_url'],// VNU_url
541
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
542
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
543
-        );
544
-        $sql_conditions = array();
545
-        foreach ($conditions as $column => $value) {
546
-            $sql_conditions [] = $wpdb->prepare("$column = %s", $value);
547
-        }
548
-        $query = "SELECT VNU_ID
438
+		$default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
439
+		$cols_n_values = array(
440
+			'EVT_ID' => $new_cpt_id,// EVT_ID_fk
441
+			'EVT_display_desc' => 'Y' == $old_event['display_desc'],
442
+			'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
443
+			'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
444
+			'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
445
+			'EVT_default_registration_status' => $default_reg_status,
446
+			'EVT_member_only' => $old_event['member_only'],
447
+			'EVT_phone' => $old_event['phone'],
448
+			'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'],
449
+			'EVT_timezone_string' => $old_event['timezone_string'],
450
+			'EVT_external_URL' => $old_event['externalURL'],
451
+			'EVT_donations' => false// doesnt exist in 3.1
452
+
453
+		);
454
+		$datatypes = array(
455
+			'%s',// EVT_ID
456
+			'%d',// EVT_display_desc
457
+			'%d',// EVT_display_ticket_selector
458
+			'%s',// EVT_visible_on
459
+			'%d',// EVT_additional_limit
460
+			'%s',// EVT_default_registration_status
461
+			'%d',// EVT_member_only
462
+			'%s',// EVT_phone
463
+			'%d',// EVT_allow_overflow
464
+			'%s',// EVT_timezone_string
465
+			'%s',// EVT_external_URL
466
+			'%d',// EVT_donations
467
+		);
468
+		$success = $wpdb->insert(
469
+			$this->_new_meta_table,
470
+			$cols_n_values,
471
+			$datatypes
472
+		);
473
+		if (! $success) {
474
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
475
+			return 0;
476
+		}
477
+		return $wpdb->insert_id;
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * @param $old_event
484
+	 * @return int
485
+	 */
486
+	private function _maybe_create_venue($old_event)
487
+	{
488
+		if (
489
+			$old_event['address'] ||
490
+				$old_event['address2'] ||
491
+				$old_event['city'] ||
492
+				$old_event['state'] ||
493
+				$old_event['zip'] ||
494
+				$old_event['venue_title'] ||
495
+				$old_event['venue_url'] ||
496
+				$old_event['venue_image'] ||
497
+				$old_event['venue_phone'] ||
498
+				$old_event['virtual_url'] ||
499
+				$old_event['virtual_phone']
500
+		) {
501
+			$old_id = $this->_duplicate_venue_exists($old_event);
502
+			if ($old_id) {
503
+				return $old_id;
504
+			}
505
+			$new_id = $this->_insert_venue_into_posts($old_event);
506
+			if ($new_id) {
507
+				$this->_insert_venue_into_meta_table($new_id, $old_event);
508
+				$guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
509
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
510
+			}
511
+			// we don't bother recording the conversion from old events to venues as that
512
+			// will complicate finding the conversion from old venues to new events
513
+			return $new_id;
514
+		} else {
515
+			return 0;
516
+		}
517
+	}
518
+
519
+	/**
520
+	 * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it.
521
+	 * If so, return it. Otherwise return NULL.
522
+	 * @param array $old_event
523
+	 * @return int duplicate venue id
524
+	 */
525
+	private function _duplicate_venue_exists($old_event)
526
+	{
527
+		global $wpdb;
528
+		$conditions = array(
529
+			'VNU_address' => $old_event ['address'],
530
+			'VNU_address2' => $old_event['address2'],
531
+			'VNU_city' => $old_event['city'],
532
+			'VNU_zip' => $old_event['zip'],
533
+			'post_title' => $this->_get_venue_title_for_event($old_event),
534
+			'VNU_phone' => $old_event['venue_phone'],// VNU_phone
535
+			'VNU_url' => $old_event['venue_url'],// VNU_url
536
+			'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
537
+			'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
538
+		);
539
+		$sql_conditions = array();
540
+		foreach ($conditions as $column => $value) {
541
+			$sql_conditions [] = $wpdb->prepare("$column = %s", $value);
542
+		}
543
+		$query = "SELECT VNU_ID
549 544
 					FROM
550 545
 		{$wpdb->posts} as p INNER JOIN
551 546
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
552 547
 			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
553
-        $id = $wpdb->get_var($query);
554
-        return $id;
555
-    }
556
-
557
-    /**
558
-     * Gets teh venue's title or makes one up if there is none
559
-     * @param array $event_data_array keys are events_details columns and values are their values
560
-     * @return string
561
-     */
562
-    protected function _get_venue_title_for_event($event_data_array)
563
-    {
564
-        return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(esc_html__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
565
-    }
566
-
567
-    /**
568
-     * Inserts the CPT
569
-     *
570
-     * @param array $old_event keys are cols, values are col values
571
-     * @return int
572
-     */
573
-    private function _insert_venue_into_posts($old_event)
574
-    {
575
-        global $wpdb;
576
-        $insertion_array = array(
577
-                    'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
578
-                    'post_content' => '',// VNU_desc
579
-                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
580
-                    'post_date' => current_time('mysql'),// VNU_created
581
-                    'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
582
-                    'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
583
-                    'post_modified' => current_time('mysql'),// VNU_modified
584
-                    'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
585
-                    'post_author' => $old_event['wp_user'],// VNU_wp_user
586
-                    'post_parent' => 0,// parent
587
-                    'menu_order' => 0,// VNU_order
588
-                    'post_type' => 'espresso_venues'// post_type
589
-                );
590
-        $datatypes_array = array(
591
-                    '%s',// VNU_name
592
-                    '%s',// VNU_desc
593
-                    '%s',// VNU_identifier
594
-                    '%s',// VNU_created
595
-                    '%s',
596
-                    '%s',// VNU_short_desc
597
-                    '%s',// VNU_modified
598
-                    '%s',
599
-                    '%d',// VNU_wp_user
600
-                    '%d',// parent
601
-                    '%d',// VNU_order
602
-                    '%s',// post_type
603
-                );
604
-        $success = $wpdb->insert(
605
-            $wpdb->posts,
606
-            $insertion_array,
607
-            $datatypes_array
608
-        );
609
-        if (! $success) {
610
-            $this->add_error(
611
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
612
-                    $this->_old_table,
613
-                    $old_event,
614
-                    $this->_new_table,
615
-                    $insertion_array,
616
-                    $datatypes_array
617
-                )
618
-            );
619
-            return 0;
620
-        }
621
-        return $wpdb->insert_id;
622
-    }
623
-
624
-    /**
625
-     * Inserts into the venue_meta table
626
-     * @param int $cpt_id
627
-     * @param array $old_event
628
-     * @return int
629
-     */
630
-    private function _insert_venue_into_meta_table($cpt_id, $old_event)
631
-    {
632
-        global $wpdb;
633
-
634
-        // assume the country is the same as the organization's old settings
635
-        $country_iso = $this->get_migration_script()->get_default_country_iso();
636
-        // find the state from the venue, or the organization, or just guess california
637
-        if (! $old_event['state']) {
638
-            $old_org_options = get_option('events_organization_settings');
639
-            $state_name = stripslashes($old_org_options['organization_state']);
640
-        } else {
641
-            $state_name = $old_event['state'];
642
-        }
643
-        if (! $state_name) {
644
-            $state_name = 'CA';
645
-        }
646
-        // get a state ID with the same name, if possible
647
-        try {
648
-            $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
649
-            $state_id = $state['STA_ID'];
650
-        } catch (EE_Error $e) {
651
-            $this->add_error($e->getMessage());
652
-            $state_id = 0;
653
-        }
654
-        // now insert into meta table
655
-        $insertion_array = array(
656
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
657
-            'VNU_address' => stripslashes($old_event['address']),// VNU_address
658
-            'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
659
-            'VNU_city' => stripslashes($old_event['city']),// VNU_city
660
-            'STA_ID' => $state_id,// STA_ID
661
-            'CNT_ISO' => $country_iso,// CNT_ISO
662
-            'VNU_zip' => $old_event['zip'],// VNU_zip
663
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
664
-            'VNU_capacity' => -1,// VNU_capacity
665
-            'VNU_url' => $old_event['venue_url'],// VNU_url
666
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
667
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
668
-            'VNU_google_map_link' => '',// VNU_google_map_link
669
-            'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
670
-        );
671
-        $datatypes = array(
672
-            '%d',// VNU_ID_fk
673
-            '%s',// VNU_address
674
-            '%s',// VNU_address2
675
-            '%s',// VNU_city
676
-            '%d',// STA_ID
677
-            '%s',// CNT_ISO
678
-            '%s',// VNU_zip
679
-            '%s',// VNU_phone
680
-            '%d',// VNU_capacity
681
-            '%s',// VNU_url
682
-            '%s',// VNU_virtual_phone
683
-            '%s',// VNU_virtual_url
684
-            '%s',// VNU_google_map_link
685
-            '%d',// VNU_enable_for_gmap
686
-        );
687
-        $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
688
-        if (! $success) {
689
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
690
-            return 0;
691
-        }
692
-        return $wpdb->insert_id;
693
-    }
694
-
695
-
696
-
697
-    /**
698
-     * @param $new_event_id
699
-     * @param $new_venue_id
700
-     * @return int
701
-     */
702
-    private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
703
-    {
704
-        global $wpdb;
705
-        if (! $new_event_id) {
706
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
707
-            return 0;
708
-        }
709
-        if (! $new_venue_id) {
710
-            $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
711
-            return 0;
712
-        }
713
-        $cols_n_values = array(
714
-            'EVT_ID' => $new_event_id,
715
-            'VNU_ID' => $new_venue_id,
716
-            'EVV_primary' => true
717
-        );
718
-        $datatypes = array(
719
-            '%d',// EVT_ID
720
-            '%d',// VNU_ID
721
-            '%d',// EVT_primary
722
-        );
723
-        $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
724
-        if (! $success) {
725
-            $this->add_error(
726
-                $this->get_migration_script()->_create_error_message_for_db_insertion(
727
-                    $this->_old_table,
728
-                    array(),
729
-                    $this->_new_table,
730
-                    $cols_n_values,
731
-                    $datatypes
732
-                )
733
-            );
734
-            return 0;
735
-        }
736
-        return $wpdb->insert_id;
737
-    }
738
-    /**
739
-     * Converts all the 3.1 start-end times for the event to 4.1 datetimes
740
-     * @global wpdb $wpdb
741
-     * @param array $old_event results of get_results(...,ARRAY_A)
742
-     * @param int $new_cpt_id new post ID
743
-     * @return void (if there are errors though, adds them to the stage's error list
744
-     */
745
-    private function _convert_start_end_times($old_event, $new_cpt_id)
746
-    {
747
-        $start_end_times = $this->_get_old_start_end_times($old_event['id']);
748
-        foreach ($start_end_times as $start_end_time) {
749
-            $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
750
-            if ($datetime_id) {
751
-                $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
752
-            }
753
-        }
754
-    }
755
-    /**
756
-     * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
757
-     * @global wpdb $wpdb
758
-     * @param int $old_event_id
759
-     * @return array
760
-     */
761
-    private function _get_old_start_end_times($old_event_id)
762
-    {
763
-        global $wpdb;
764
-        return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
765
-    }
766
-    /**
767
-     * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
768
-     * @param array $start_end_time_row
769
-     * @param array $old_event_row
770
-     * @param int $new_cpt_id
771
-     * @return int ID of new datetime
772
-     */
773
-    private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
774
-    {
775
-        global $wpdb;
776
-        $start_date = $old_event_row['start_date'];
777
-        $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
778
-        $end_date = $old_event_row['end_date'];
779
-        $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
780
-        $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
781
-        $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
782
-        $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
783
-        $cols_n_values = array(
784
-            'EVT_ID' => $new_cpt_id,// EVT_ID
785
-            'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
786
-            'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
787
-            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
788
-            'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
548
+		$id = $wpdb->get_var($query);
549
+		return $id;
550
+	}
551
+
552
+	/**
553
+	 * Gets teh venue's title or makes one up if there is none
554
+	 * @param array $event_data_array keys are events_details columns and values are their values
555
+	 * @return string
556
+	 */
557
+	protected function _get_venue_title_for_event($event_data_array)
558
+	{
559
+		return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(esc_html__('Venue of %s', 'event_espresso'), $event_data_array['event_name']));
560
+	}
561
+
562
+	/**
563
+	 * Inserts the CPT
564
+	 *
565
+	 * @param array $old_event keys are cols, values are col values
566
+	 * @return int
567
+	 */
568
+	private function _insert_venue_into_posts($old_event)
569
+	{
570
+		global $wpdb;
571
+		$insertion_array = array(
572
+					'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
573
+					'post_content' => '',// VNU_desc
574
+					'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
575
+					'post_date' => current_time('mysql'),// VNU_created
576
+					'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
577
+					'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
578
+					'post_modified' => current_time('mysql'),// VNU_modified
579
+					'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
580
+					'post_author' => $old_event['wp_user'],// VNU_wp_user
581
+					'post_parent' => 0,// parent
582
+					'menu_order' => 0,// VNU_order
583
+					'post_type' => 'espresso_venues'// post_type
584
+				);
585
+		$datatypes_array = array(
586
+					'%s',// VNU_name
587
+					'%s',// VNU_desc
588
+					'%s',// VNU_identifier
589
+					'%s',// VNU_created
590
+					'%s',
591
+					'%s',// VNU_short_desc
592
+					'%s',// VNU_modified
593
+					'%s',
594
+					'%d',// VNU_wp_user
595
+					'%d',// parent
596
+					'%d',// VNU_order
597
+					'%s',// post_type
598
+				);
599
+		$success = $wpdb->insert(
600
+			$wpdb->posts,
601
+			$insertion_array,
602
+			$datatypes_array
603
+		);
604
+		if (! $success) {
605
+			$this->add_error(
606
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
607
+					$this->_old_table,
608
+					$old_event,
609
+					$this->_new_table,
610
+					$insertion_array,
611
+					$datatypes_array
612
+				)
613
+			);
614
+			return 0;
615
+		}
616
+		return $wpdb->insert_id;
617
+	}
618
+
619
+	/**
620
+	 * Inserts into the venue_meta table
621
+	 * @param int $cpt_id
622
+	 * @param array $old_event
623
+	 * @return int
624
+	 */
625
+	private function _insert_venue_into_meta_table($cpt_id, $old_event)
626
+	{
627
+		global $wpdb;
628
+
629
+		// assume the country is the same as the organization's old settings
630
+		$country_iso = $this->get_migration_script()->get_default_country_iso();
631
+		// find the state from the venue, or the organization, or just guess california
632
+		if (! $old_event['state']) {
633
+			$old_org_options = get_option('events_organization_settings');
634
+			$state_name = stripslashes($old_org_options['organization_state']);
635
+		} else {
636
+			$state_name = $old_event['state'];
637
+		}
638
+		if (! $state_name) {
639
+			$state_name = 'CA';
640
+		}
641
+		// get a state ID with the same name, if possible
642
+		try {
643
+			$state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso);
644
+			$state_id = $state['STA_ID'];
645
+		} catch (EE_Error $e) {
646
+			$this->add_error($e->getMessage());
647
+			$state_id = 0;
648
+		}
649
+		// now insert into meta table
650
+		$insertion_array = array(
651
+			'VNU_ID' => $cpt_id,// VNU_ID_fk
652
+			'VNU_address' => stripslashes($old_event['address']),// VNU_address
653
+			'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
654
+			'VNU_city' => stripslashes($old_event['city']),// VNU_city
655
+			'STA_ID' => $state_id,// STA_ID
656
+			'CNT_ISO' => $country_iso,// CNT_ISO
657
+			'VNU_zip' => $old_event['zip'],// VNU_zip
658
+			'VNU_phone' => $old_event['venue_phone'],// VNU_phone
659
+			'VNU_capacity' => -1,// VNU_capacity
660
+			'VNU_url' => $old_event['venue_url'],// VNU_url
661
+			'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
662
+			'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
663
+			'VNU_google_map_link' => '',// VNU_google_map_link
664
+			'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
665
+		);
666
+		$datatypes = array(
667
+			'%d',// VNU_ID_fk
668
+			'%s',// VNU_address
669
+			'%s',// VNU_address2
670
+			'%s',// VNU_city
671
+			'%d',// STA_ID
672
+			'%s',// CNT_ISO
673
+			'%s',// VNU_zip
674
+			'%s',// VNU_phone
675
+			'%d',// VNU_capacity
676
+			'%s',// VNU_url
677
+			'%s',// VNU_virtual_phone
678
+			'%s',// VNU_virtual_url
679
+			'%s',// VNU_google_map_link
680
+			'%d',// VNU_enable_for_gmap
681
+		);
682
+		$success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
683
+		if (! $success) {
684
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
685
+			return 0;
686
+		}
687
+		return $wpdb->insert_id;
688
+	}
689
+
690
+
691
+
692
+	/**
693
+	 * @param $new_event_id
694
+	 * @param $new_venue_id
695
+	 * @return int
696
+	 */
697
+	private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
698
+	{
699
+		global $wpdb;
700
+		if (! $new_event_id) {
701
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
702
+			return 0;
703
+		}
704
+		if (! $new_venue_id) {
705
+			$this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
706
+			return 0;
707
+		}
708
+		$cols_n_values = array(
709
+			'EVT_ID' => $new_event_id,
710
+			'VNU_ID' => $new_venue_id,
711
+			'EVV_primary' => true
712
+		);
713
+		$datatypes = array(
714
+			'%d',// EVT_ID
715
+			'%d',// VNU_ID
716
+			'%d',// EVT_primary
717
+		);
718
+		$success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
719
+		if (! $success) {
720
+			$this->add_error(
721
+				$this->get_migration_script()->_create_error_message_for_db_insertion(
722
+					$this->_old_table,
723
+					array(),
724
+					$this->_new_table,
725
+					$cols_n_values,
726
+					$datatypes
727
+				)
728
+			);
729
+			return 0;
730
+		}
731
+		return $wpdb->insert_id;
732
+	}
733
+	/**
734
+	 * Converts all the 3.1 start-end times for the event to 4.1 datetimes
735
+	 * @global wpdb $wpdb
736
+	 * @param array $old_event results of get_results(...,ARRAY_A)
737
+	 * @param int $new_cpt_id new post ID
738
+	 * @return void (if there are errors though, adds them to the stage's error list
739
+	 */
740
+	private function _convert_start_end_times($old_event, $new_cpt_id)
741
+	{
742
+		$start_end_times = $this->_get_old_start_end_times($old_event['id']);
743
+		foreach ($start_end_times as $start_end_time) {
744
+			$datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id);
745
+			if ($datetime_id) {
746
+				$this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id);
747
+			}
748
+		}
749
+	}
750
+	/**
751
+	 * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event
752
+	 * @global wpdb $wpdb
753
+	 * @param int $old_event_id
754
+	 * @return array
755
+	 */
756
+	private function _get_old_start_end_times($old_event_id)
757
+	{
758
+		global $wpdb;
759
+		return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A);
760
+	}
761
+	/**
762
+	 * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row
763
+	 * @param array $start_end_time_row
764
+	 * @param array $old_event_row
765
+	 * @param int $new_cpt_id
766
+	 * @return int ID of new datetime
767
+	 */
768
+	private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id)
769
+	{
770
+		global $wpdb;
771
+		$start_date = $old_event_row['start_date'];
772
+		$start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']);
773
+		$end_date = $old_event_row['end_date'];
774
+		$end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']);
775
+		$existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id);
776
+		$start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
777
+		$end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
778
+		$cols_n_values = array(
779
+			'EVT_ID' => $new_cpt_id,// EVT_ID
780
+			'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
781
+			'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
782
+			'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
783
+			'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
789 784
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
790
-            'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
791
-            'DTT_parent' => 0,
792
-            'DTT_deleted' => false
793
-        );
794
-        $datatypes = array(
795
-            '%d',// EVT_Id
796
-            '%s',// DTT_EVT_start
797
-            '%s',// DTT_EVT_end
798
-            '%d',// DTT_reg_limit
799
-            '%d',// DTT_sold
785
+			'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
786
+			'DTT_parent' => 0,
787
+			'DTT_deleted' => false
788
+		);
789
+		$datatypes = array(
790
+			'%d',// EVT_Id
791
+			'%s',// DTT_EVT_start
792
+			'%s',// DTT_EVT_end
793
+			'%d',// DTT_reg_limit
794
+			'%d',// DTT_sold
800 795
 //          '%d',//DTT_is_primary
801
-            '%d',// DTT_order
802
-            '%d',// DTT_parent
803
-            '%d',// DTT_deleted
804
-        );
805
-        $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
806
-        if (! $success) {
807
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
808
-            return 0;
809
-        }
810
-        return $wpdb->insert_id;
811
-    }
812
-
813
-    /**
814
-     * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
815
-     * when deciding whether a datetime we're about ot insert should be the 'primary' or not
816
-     * @global wpdb $wpdb
817
-     * @param int $cpt_event_id
818
-     * @return int
819
-     */
820
-    private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
821
-    {
822
-        global $wpdb;
823
-        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
824
-        return intval($count);
825
-    }
796
+			'%d',// DTT_order
797
+			'%d',// DTT_parent
798
+			'%d',// DTT_deleted
799
+		);
800
+		$success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
801
+		if (! $success) {
802
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
803
+			return 0;
804
+		}
805
+		return $wpdb->insert_id;
806
+	}
807
+
808
+	/**
809
+	 * Checks if there's a 4.1 datetime for this event already. This is mostly only handy
810
+	 * when deciding whether a datetime we're about ot insert should be the 'primary' or not
811
+	 * @global wpdb $wpdb
812
+	 * @param int $cpt_event_id
813
+	 * @return int
814
+	 */
815
+	private function _count_other_datetimes_exist_for_new_event($cpt_event_id)
816
+	{
817
+		global $wpdb;
818
+		$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id));
819
+		return intval($count);
820
+	}
826 821
 }
Please login to merge, or discard this patch.
Spacing   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
     public function __construct()
177 177
     {
178 178
         global $wpdb;
179
-        $this->_old_table = $wpdb->prefix . "events_detail";
180
-        $this->_old_start_end_table = $wpdb->prefix . "events_start_end";
181
-        $this->_new_table = $wpdb->prefix . "posts";
182
-        $this->_new_meta_table = $wpdb->prefix . "esp_event_meta";
183
-        $this->_new_datetime_table = $wpdb->prefix . "esp_datetime";
179
+        $this->_old_table = $wpdb->prefix."events_detail";
180
+        $this->_old_start_end_table = $wpdb->prefix."events_start_end";
181
+        $this->_new_table = $wpdb->prefix."posts";
182
+        $this->_new_meta_table = $wpdb->prefix."esp_event_meta";
183
+        $this->_new_datetime_table = $wpdb->prefix."esp_datetime";
184 184
         $this->_pretty_name = esc_html__("Events", "event_espresso");
185 185
         parent::__construct();
186 186
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     public function _count_records_to_migrate()
195 195
     {
196 196
         global $wpdb;
197
-        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"');
197
+        $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"');
198 198
         return intval($count);
199 199
     }
200 200
 
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
     private function _add_post_metas($old_event, $post_id)
262 262
     {
263 263
         $event_meta = maybe_unserialize($old_event['event_meta']);
264
-        if (! $event_meta || ! is_array($event_meta)) {
264
+        if ( ! $event_meta || ! is_array($event_meta)) {
265 265
             return;
266 266
         }
267
-        unset($event_meta['date_submitted']);// factored into CPT
268
-        unset($event_meta['additional_attendee_reg_info']);// factored into event meta table
269
-        unset($event_meta['default_payment_status']);// dido
270
-        unset($event_meta['event_thumbnail_url']);// used to find post featured image
267
+        unset($event_meta['date_submitted']); // factored into CPT
268
+        unset($event_meta['additional_attendee_reg_info']); // factored into event meta table
269
+        unset($event_meta['default_payment_status']); // dido
270
+        unset($event_meta['event_thumbnail_url']); // used to find post featured image
271 271
         foreach ($event_meta as $meta_key => $meta_value) {
272 272
             if ($meta_key) {// if the meta key is just an empty string, ignore it
273 273
                 $success = add_post_meta($post_id, $meta_key, $meta_value, true);
274
-                if (! $success) {
274
+                if ( ! $success) {
275 275
                     $this->add_error(sprintf(esc_html__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event)));
276 276
                 }
277 277
             }
@@ -342,68 +342,68 @@  discard block
 block discarded – undo
342 342
 //      and 3 custom ones: cancelled,postponed,sold_out
343 343
         $status_conversions = array(
344 344
             'R' => 'draft',
345
-            'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
345
+            'X' => 'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved
346 346
             'P' => 'pending',
347
-            'IA' => 'draft',// draft and in the past
347
+            'IA' => 'draft', // draft and in the past
348 348
 // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated
349
-            'O' => 'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
349
+            'O' => 'publish', // @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing'
350 350
             'A' => 'publish',
351
-            'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
351
+            'S' => 'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS?
352 352
             'D' => 'trash',
353 353
         );
354
-        $post_status = $status_conversions[ $old_event['event_status'] ];
354
+        $post_status = $status_conversions[$old_event['event_status']];
355 355
         // check if we've sold out
356 356
         if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) {
357 357
             $post_status = 'sold_out';
358 358
         }
359 359
 //      FYI postponed and cancelled don't exist in 3.1
360 360
         $cols_n_values = array(
361
-            'post_title' => stripslashes($old_event['event_name']),// EVT_name
362
-            'post_content' => stripslashes($old_event['event_desc']),// EVT_desc
363
-            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug
364
-            'post_date' => $old_event['submitted'],// EVT_created NOT
361
+            'post_title' => stripslashes($old_event['event_name']), // EVT_name
362
+            'post_content' => stripslashes($old_event['event_desc']), // EVT_desc
363
+            'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug
364
+            'post_date' => $old_event['submitted'], // EVT_created NOT
365 365
             'post_date_gmt' => get_gmt_from_date($old_event['submitted']),
366
-            'post_excerpt' => '',// EVT_short_desc
367
-            'post_modified' => $old_event['submitted'],// EVT_modified
366
+            'post_excerpt' => '', // EVT_short_desc
367
+            'post_modified' => $old_event['submitted'], // EVT_modified
368 368
             'post_modified_gmt' => get_gmt_from_date($old_event['submitted']),
369
-            'post_author' => $old_event['wp_user'],// EVT_wp_user
370
-            'post_parent' => 0,// parent maybe get this from some REM field?
371
-            'menu_order' => 0,// EVT_order
372
-            'post_type' => 'espresso_events',// post_type
373
-            'post_status' => $post_status,// status
369
+            'post_author' => $old_event['wp_user'], // EVT_wp_user
370
+            'post_parent' => 0, // parent maybe get this from some REM field?
371
+            'menu_order' => 0, // EVT_order
372
+            'post_type' => 'espresso_events', // post_type
373
+            'post_status' => $post_status, // status
374 374
         );
375 375
         $cols_n_values_with_no_invalid_text = array();
376 376
         foreach ($cols_n_values as $col => $value) {
377 377
             $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value);
378
-            if (! is_wp_error($value_sans_invalid_chars)) {
379
-                $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars;
378
+            if ( ! is_wp_error($value_sans_invalid_chars)) {
379
+                $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars;
380 380
             } else {
381 381
                 // otherwise leave it as-is. It will blow everything up and stop the migration
382
-                $cols_n_values_with_no_invalid_text[ $col ] = $value;
382
+                $cols_n_values_with_no_invalid_text[$col] = $value;
383 383
             }
384 384
         }
385 385
         $cols_n_values = $cols_n_values_with_no_invalid_text;
386 386
         $datatypes = array(
387
-            '%s',// EVT_name
388
-            '%s',// EVT_desc
389
-            '%s',// EVT_slug
390
-            '%s',// EVT_created
387
+            '%s', // EVT_name
388
+            '%s', // EVT_desc
389
+            '%s', // EVT_slug
390
+            '%s', // EVT_created
391 391
             '%s',
392
-            '%s',// EVT_short_desc
393
-            '%s',// EVT_modified
392
+            '%s', // EVT_short_desc
393
+            '%s', // EVT_modified
394 394
             '%s',
395
-            '%s',// EVT_wp_user
396
-            '%d',// post_parent
397
-            '%d',// EVT_order
398
-            '%s',// post_type
399
-            '%s',// status
395
+            '%s', // EVT_wp_user
396
+            '%d', // post_parent
397
+            '%d', // EVT_order
398
+            '%s', // post_type
399
+            '%s', // status
400 400
         );
401 401
         $success = $wpdb->insert(
402 402
             $this->_new_table,
403 403
             $cols_n_values,
404 404
             $datatypes
405 405
         );
406
-        if (! $success) {
406
+        if ( ! $success) {
407 407
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes));
408 408
             return 0;
409 409
         }
@@ -442,10 +442,10 @@  discard block
 block discarded – undo
442 442
 // );
443 443
         $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval']));
444 444
         $cols_n_values = array(
445
-            'EVT_ID' => $new_cpt_id,// EVT_ID_fk
445
+            'EVT_ID' => $new_cpt_id, // EVT_ID_fk
446 446
             'EVT_display_desc' => 'Y' == $old_event['display_desc'],
447 447
             'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'],
448
-            'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used
448
+            'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']), // don't use the old 'visible_on', as it wasn't ever used
449 449
             'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'],
450 450
             'EVT_default_registration_status' => $default_reg_status,
451 451
             'EVT_member_only' => $old_event['member_only'],
@@ -457,25 +457,25 @@  discard block
 block discarded – undo
457 457
 
458 458
         );
459 459
         $datatypes = array(
460
-            '%s',// EVT_ID
461
-            '%d',// EVT_display_desc
462
-            '%d',// EVT_display_ticket_selector
463
-            '%s',// EVT_visible_on
464
-            '%d',// EVT_additional_limit
465
-            '%s',// EVT_default_registration_status
466
-            '%d',// EVT_member_only
467
-            '%s',// EVT_phone
468
-            '%d',// EVT_allow_overflow
469
-            '%s',// EVT_timezone_string
470
-            '%s',// EVT_external_URL
471
-            '%d',// EVT_donations
460
+            '%s', // EVT_ID
461
+            '%d', // EVT_display_desc
462
+            '%d', // EVT_display_ticket_selector
463
+            '%s', // EVT_visible_on
464
+            '%d', // EVT_additional_limit
465
+            '%s', // EVT_default_registration_status
466
+            '%d', // EVT_member_only
467
+            '%s', // EVT_phone
468
+            '%d', // EVT_allow_overflow
469
+            '%s', // EVT_timezone_string
470
+            '%s', // EVT_external_URL
471
+            '%d', // EVT_donations
472 472
         );
473 473
         $success = $wpdb->insert(
474 474
             $this->_new_meta_table,
475 475
             $cols_n_values,
476 476
             $datatypes
477 477
         );
478
-        if (! $success) {
478
+        if ( ! $success) {
479 479
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes));
480 480
             return 0;
481 481
         }
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
             $new_id = $this->_insert_venue_into_posts($old_event);
511 511
             if ($new_id) {
512 512
                 $this->_insert_venue_into_meta_table($new_id, $old_event);
513
-                $guid = isset($old_event['venue_image']) ? $old_event['venue_image']  : null;
513
+                $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null;
514 514
                 $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
515 515
             }
516 516
             // we don't bother recording the conversion from old events to venues as that
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
             'VNU_city' => $old_event['city'],
537 537
             'VNU_zip' => $old_event['zip'],
538 538
             'post_title' => $this->_get_venue_title_for_event($old_event),
539
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
540
-            'VNU_url' => $old_event['venue_url'],// VNU_url
541
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
542
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
539
+            'VNU_phone' => $old_event['venue_phone'], // VNU_phone
540
+            'VNU_url' => $old_event['venue_url'], // VNU_url
541
+            'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone
542
+            'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url
543 543
         );
544 544
         $sql_conditions = array();
545 545
         foreach ($conditions as $column => $value) {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 					FROM
550 550
 		{$wpdb->posts} as p INNER JOIN
551 551
 		{$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID
552
-			WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1";
552
+			WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1";
553 553
         $id = $wpdb->get_var($query);
554 554
         return $id;
555 555
     }
@@ -574,39 +574,39 @@  discard block
 block discarded – undo
574 574
     {
575 575
         global $wpdb;
576 576
         $insertion_array = array(
577
-                    'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name
578
-                    'post_content' => '',// VNU_desc
579
-                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier
580
-                    'post_date' => current_time('mysql'),// VNU_created
577
+                    'post_title' => $this->_get_venue_title_for_event($old_event), // VNU_name
578
+                    'post_content' => '', // VNU_desc
579
+                    'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier
580
+                    'post_date' => current_time('mysql'), // VNU_created
581 581
                     'post_date_gmt' => get_gmt_from_date(current_time('mysql')),
582
-                    'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters
583
-                    'post_modified' => current_time('mysql'),// VNU_modified
582
+                    'post_excerpt' => '', // VNU_short_desc arbitrary only 50 characters
583
+                    'post_modified' => current_time('mysql'), // VNU_modified
584 584
                     'post_modified_gmt' => get_gmt_from_date(current_time('mysql')),
585
-                    'post_author' => $old_event['wp_user'],// VNU_wp_user
586
-                    'post_parent' => 0,// parent
587
-                    'menu_order' => 0,// VNU_order
585
+                    'post_author' => $old_event['wp_user'], // VNU_wp_user
586
+                    'post_parent' => 0, // parent
587
+                    'menu_order' => 0, // VNU_order
588 588
                     'post_type' => 'espresso_venues'// post_type
589 589
                 );
590 590
         $datatypes_array = array(
591
-                    '%s',// VNU_name
592
-                    '%s',// VNU_desc
593
-                    '%s',// VNU_identifier
594
-                    '%s',// VNU_created
591
+                    '%s', // VNU_name
592
+                    '%s', // VNU_desc
593
+                    '%s', // VNU_identifier
594
+                    '%s', // VNU_created
595 595
                     '%s',
596
-                    '%s',// VNU_short_desc
597
-                    '%s',// VNU_modified
596
+                    '%s', // VNU_short_desc
597
+                    '%s', // VNU_modified
598 598
                     '%s',
599
-                    '%d',// VNU_wp_user
600
-                    '%d',// parent
601
-                    '%d',// VNU_order
602
-                    '%s',// post_type
599
+                    '%d', // VNU_wp_user
600
+                    '%d', // parent
601
+                    '%d', // VNU_order
602
+                    '%s', // post_type
603 603
                 );
604 604
         $success = $wpdb->insert(
605 605
             $wpdb->posts,
606 606
             $insertion_array,
607 607
             $datatypes_array
608 608
         );
609
-        if (! $success) {
609
+        if ( ! $success) {
610 610
             $this->add_error(
611 611
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
612 612
                     $this->_old_table,
@@ -634,13 +634,13 @@  discard block
 block discarded – undo
634 634
         // assume the country is the same as the organization's old settings
635 635
         $country_iso = $this->get_migration_script()->get_default_country_iso();
636 636
         // find the state from the venue, or the organization, or just guess california
637
-        if (! $old_event['state']) {
637
+        if ( ! $old_event['state']) {
638 638
             $old_org_options = get_option('events_organization_settings');
639 639
             $state_name = stripslashes($old_org_options['organization_state']);
640 640
         } else {
641 641
             $state_name = $old_event['state'];
642 642
         }
643
-        if (! $state_name) {
643
+        if ( ! $state_name) {
644 644
             $state_name = 'CA';
645 645
         }
646 646
         // get a state ID with the same name, if possible
@@ -653,39 +653,39 @@  discard block
 block discarded – undo
653 653
         }
654 654
         // now insert into meta table
655 655
         $insertion_array = array(
656
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
657
-            'VNU_address' => stripslashes($old_event['address']),// VNU_address
658
-            'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2
659
-            'VNU_city' => stripslashes($old_event['city']),// VNU_city
660
-            'STA_ID' => $state_id,// STA_ID
661
-            'CNT_ISO' => $country_iso,// CNT_ISO
662
-            'VNU_zip' => $old_event['zip'],// VNU_zip
663
-            'VNU_phone' => $old_event['venue_phone'],// VNU_phone
664
-            'VNU_capacity' => -1,// VNU_capacity
665
-            'VNU_url' => $old_event['venue_url'],// VNU_url
666
-            'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone
667
-            'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url
668
-            'VNU_google_map_link' => '',// VNU_google_map_link
656
+            'VNU_ID' => $cpt_id, // VNU_ID_fk
657
+            'VNU_address' => stripslashes($old_event['address']), // VNU_address
658
+            'VNU_address2' => stripslashes($old_event['address2']), // VNU_address2
659
+            'VNU_city' => stripslashes($old_event['city']), // VNU_city
660
+            'STA_ID' => $state_id, // STA_ID
661
+            'CNT_ISO' => $country_iso, // CNT_ISO
662
+            'VNU_zip' => $old_event['zip'], // VNU_zip
663
+            'VNU_phone' => $old_event['venue_phone'], // VNU_phone
664
+            'VNU_capacity' => -1, // VNU_capacity
665
+            'VNU_url' => $old_event['venue_url'], // VNU_url
666
+            'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone
667
+            'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url
668
+            'VNU_google_map_link' => '', // VNU_google_map_link
669 669
             'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
670 670
         );
671 671
         $datatypes = array(
672
-            '%d',// VNU_ID_fk
673
-            '%s',// VNU_address
674
-            '%s',// VNU_address2
675
-            '%s',// VNU_city
676
-            '%d',// STA_ID
677
-            '%s',// CNT_ISO
678
-            '%s',// VNU_zip
679
-            '%s',// VNU_phone
680
-            '%d',// VNU_capacity
681
-            '%s',// VNU_url
682
-            '%s',// VNU_virtual_phone
683
-            '%s',// VNU_virtual_url
684
-            '%s',// VNU_google_map_link
685
-            '%d',// VNU_enable_for_gmap
672
+            '%d', // VNU_ID_fk
673
+            '%s', // VNU_address
674
+            '%s', // VNU_address2
675
+            '%s', // VNU_city
676
+            '%d', // STA_ID
677
+            '%s', // CNT_ISO
678
+            '%s', // VNU_zip
679
+            '%s', // VNU_phone
680
+            '%d', // VNU_capacity
681
+            '%s', // VNU_url
682
+            '%s', // VNU_virtual_phone
683
+            '%s', // VNU_virtual_url
684
+            '%s', // VNU_google_map_link
685
+            '%d', // VNU_enable_for_gmap
686 686
         );
687
-        $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes);
688
-        if (! $success) {
687
+        $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes);
688
+        if ( ! $success) {
689 689
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes));
690 690
             return 0;
691 691
         }
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
     private function _insert_new_venue_to_event($new_event_id, $new_venue_id)
703 703
     {
704 704
         global $wpdb;
705
-        if (! $new_event_id) {
705
+        if ( ! $new_event_id) {
706 706
             $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id));
707 707
             return 0;
708 708
         }
709
-        if (! $new_venue_id) {
709
+        if ( ! $new_venue_id) {
710 710
             $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id));
711 711
             return 0;
712 712
         }
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
             'EVV_primary' => true
717 717
         );
718 718
         $datatypes = array(
719
-            '%d',// EVT_ID
720
-            '%d',// VNU_ID
721
-            '%d',// EVT_primary
719
+            '%d', // EVT_ID
720
+            '%d', // VNU_ID
721
+            '%d', // EVT_primary
722 722
         );
723
-        $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes);
724
-        if (! $success) {
723
+        $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes);
724
+        if ( ! $success) {
725 725
             $this->add_error(
726 726
                 $this->get_migration_script()->_create_error_message_for_db_insertion(
727 727
                     $this->_old_table,
@@ -781,29 +781,29 @@  discard block
 block discarded – undo
781 781
         $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']);
782 782
         $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']);
783 783
         $cols_n_values = array(
784
-            'EVT_ID' => $new_cpt_id,// EVT_ID
785
-            'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start
786
-            'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end
787
-            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit
788
-            'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration
784
+            'EVT_ID' => $new_cpt_id, // EVT_ID
785
+            'DTT_EVT_start' => $start_datetime_utc, // DTT_EVT_start
786
+            'DTT_EVT_end' => $end_datetime_utc, // DTT_EVT_end
787
+            'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit
788
+            'DTT_sold' => 0, // note: we will increment this as registrations are added during the migration
789 789
 //          'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary'
790
-            'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist
790
+            'DTT_order' => $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist
791 791
             'DTT_parent' => 0,
792 792
             'DTT_deleted' => false
793 793
         );
794 794
         $datatypes = array(
795
-            '%d',// EVT_Id
796
-            '%s',// DTT_EVT_start
797
-            '%s',// DTT_EVT_end
798
-            '%d',// DTT_reg_limit
799
-            '%d',// DTT_sold
795
+            '%d', // EVT_Id
796
+            '%s', // DTT_EVT_start
797
+            '%s', // DTT_EVT_end
798
+            '%d', // DTT_reg_limit
799
+            '%d', // DTT_sold
800 800
 //          '%d',//DTT_is_primary
801
-            '%d',// DTT_order
802
-            '%d',// DTT_parent
803
-            '%d',// DTT_deleted
801
+            '%d', // DTT_order
802
+            '%d', // DTT_parent
803
+            '%d', // DTT_deleted
804 804
         );
805 805
         $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes);
806
-        if (! $success) {
806
+        if ( ! $success) {
807 807
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes));
808 808
             return 0;
809 809
         }
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_category_details.dmsstage.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -8,53 +8,53 @@
 block discarded – undo
8 8
  */
9 9
 class EE_DMS_4_1_0_category_details extends EE_Data_Migration_Script_Stage
10 10
 {
11
-    private $_old_table;
12
-    private $_new_table;
13
-    private $_new_term_table;
14
-    public function _migration_step($num_items = 50)
15
-    {
16
-        global $wpdb;
17
-        $start_at_record = $this->count_records_migrated();
18
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
19
-        $items_actually_migrated = 0;
20
-        foreach ($rows as $category_detail_row) {
21
-            $term_and_taxonomy_ids = wp_insert_term(
22
-                stripslashes($category_detail_row['category_name']),
23
-                'espresso_event_categories',
24
-                array(
25
-                    'description' =>  stripslashes($category_detail_row['category_desc']),
26
-                    'slug' => $category_detail_row['category_identifier']
27
-                )
28
-            );
29
-            if ($term_and_taxonomy_ids instanceof WP_Error) {
30
-                $this->add_error(sprintf(esc_html__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message()));
31
-                $items_actually_migrated++;
32
-                continue;
33
-            }
34
-            $term_id = $term_and_taxonomy_ids['term_id'];
35
-            $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id'];
36
-            $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id);
37
-            $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id);
38
-            $items_actually_migrated++;
39
-        }
40
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
41
-            $this->set_completed();
42
-        }
43
-        return $items_actually_migrated;
44
-    }
45
-    public function _count_records_to_migrate()
46
-    {
47
-        global $wpdb;
48
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table");
49
-        return $count;
50
-    }
51
-    public function __construct()
52
-    {
53
-        $this->_pretty_name = esc_html__("Category Details", "event_espresso");
54
-        global $wpdb;
55
-        $this->_old_table = $wpdb->prefix . "events_category_detail";
56
-        $this->_new_table = $wpdb->prefix . "term_taxonomy";
57
-        $this->_new_term_table = $wpdb->prefix . "terms";
58
-        parent::__construct();
59
-    }
11
+	private $_old_table;
12
+	private $_new_table;
13
+	private $_new_term_table;
14
+	public function _migration_step($num_items = 50)
15
+	{
16
+		global $wpdb;
17
+		$start_at_record = $this->count_records_migrated();
18
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
19
+		$items_actually_migrated = 0;
20
+		foreach ($rows as $category_detail_row) {
21
+			$term_and_taxonomy_ids = wp_insert_term(
22
+				stripslashes($category_detail_row['category_name']),
23
+				'espresso_event_categories',
24
+				array(
25
+					'description' =>  stripslashes($category_detail_row['category_desc']),
26
+					'slug' => $category_detail_row['category_identifier']
27
+				)
28
+			);
29
+			if ($term_and_taxonomy_ids instanceof WP_Error) {
30
+				$this->add_error(sprintf(esc_html__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message()));
31
+				$items_actually_migrated++;
32
+				continue;
33
+			}
34
+			$term_id = $term_and_taxonomy_ids['term_id'];
35
+			$term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id'];
36
+			$this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id);
37
+			$this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id);
38
+			$items_actually_migrated++;
39
+		}
40
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
41
+			$this->set_completed();
42
+		}
43
+		return $items_actually_migrated;
44
+	}
45
+	public function _count_records_to_migrate()
46
+	{
47
+		global $wpdb;
48
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table");
49
+		return $count;
50
+	}
51
+	public function __construct()
52
+	{
53
+		$this->_pretty_name = esc_html__("Category Details", "event_espresso");
54
+		global $wpdb;
55
+		$this->_old_table = $wpdb->prefix . "events_category_detail";
56
+		$this->_new_table = $wpdb->prefix . "term_taxonomy";
57
+		$this->_new_term_table = $wpdb->prefix . "terms";
58
+		parent::__construct();
59
+	}
60 60
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@
 block discarded – undo
52 52
     {
53 53
         $this->_pretty_name = esc_html__("Category Details", "event_espresso");
54 54
         global $wpdb;
55
-        $this->_old_table = $wpdb->prefix . "events_category_detail";
56
-        $this->_new_table = $wpdb->prefix . "term_taxonomy";
57
-        $this->_new_term_table = $wpdb->prefix . "terms";
55
+        $this->_old_table = $wpdb->prefix."events_category_detail";
56
+        $this->_new_table = $wpdb->prefix."term_taxonomy";
57
+        $this->_new_term_table = $wpdb->prefix."terms";
58 58
         parent::__construct();
59 59
     }
60 60
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_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 = esc_html__("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 = esc_html__("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' =>  esc_html__("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' =>  esc_html__("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   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
     {
106 106
         global $wpdb;
107 107
         $this->_pretty_name = esc_html__("Prices", "event_espresso");
108
-        $this->_old_table = $wpdb->prefix . "events_prices";
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
-        $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";
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 117
         parent::__construct();
118 118
     }
119 119
     protected function _migrate_old_row($old_row)
@@ -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
         }
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
         } else {// percent surcharge
299 299
             $final_ticket_price = floatval($old_price_row['event_cost']) * (1 + floatval($old_price_row['surcharge']) / 100);
300 300
         }
301
-        $start_date = $event_row['registration_start'] . " " . $this->get_migration_script()->convertTimeFromAMPM($event_row['registration_startT']);
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']);
303
-        $end_date = $event_row['registration_end'] . " " . $this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
303
+        $end_date = $event_row['registration_end']." ".$this->get_migration_script()->convertTimeFromAMPM($event_row['registration_endT']);
304 304
         $end_date_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $old_price_row, $end_date, $event_row['timezone_string']);
305 305
         $cols_n_values = array(
306 306
             'TTM_ID' => 0,
@@ -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;
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
     private function _get_event_row($event_id)
414 414
     {
415 415
         global $wpdb;
416
-        $old_event_table = $wpdb->prefix . "events_detail";
416
+        $old_event_table = $wpdb->prefix."events_detail";
417 417
         return $wpdb->get_row($wpdb->prepare("SELECT * FROM $old_event_table WHERE id=%d", $event_id), ARRAY_A);
418 418
     }
419 419
     /**
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
     private function _get_datetime_ids_for_old_event_id($old_event_id)
435 435
     {
436 436
         global $wpdb;
437
-        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_id, $wpdb->posts);
437
+        $new_cpt_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_id, $wpdb->posts);
438 438
         $datetime_ids = $wpdb->get_col($wpdb->prepare("SELECT DTT_ID FROM {$wpdb->prefix}esp_datetime WHERE EVT_ID=%d", $new_cpt_id));
439 439
         return $datetime_ids;
440 440
     }
Please login to merge, or discard this patch.
core/data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_venues.dmsstage.php 2 patches
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -70,15 +70,15 @@  discard block
 block discarded – undo
70 70
     {
71 71
         global $wpdb;
72 72
         $start_at_record = $this->count_records_migrated();
73
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
73
+        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$this->_old_table." LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74 74
         $items_actually_migrated = 0;
75 75
         foreach ($rows as $old_venue) {
76
-            if (! $new_id = $this->_insert_into_posts($old_venue)) {
76
+            if ( ! $new_id = $this->_insert_into_posts($old_venue)) {
77 77
                 $items_actually_migrated++;
78 78
                 continue;
79 79
             }
80 80
             $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
-            if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
81
+            if ( ! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82 82
                 $items_actually_migrated++;
83 83
                 continue;
84 84
             }
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
     public function _count_records_to_migrate()
109 109
     {
110 110
         global $wpdb;
111
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
111
+        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
112 112
         return $count;
113 113
     }
114 114
     public function __construct()
115 115
     {
116 116
         $this->_pretty_name = esc_html__("Venues", "event_espresso");
117 117
         global $wpdb;
118
-        $this->_old_table = $wpdb->prefix . "events_venue";
118
+        $this->_old_table = $wpdb->prefix."events_venue";
119 119
         $this->_new_table = $wpdb->posts;
120
-        $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta";
120
+        $this->_new_meta_table = $wpdb->prefix."esp_venue_meta";
121 121
         parent::__construct();
122 122
     }
123 123
 
@@ -132,39 +132,39 @@  discard block
 block discarded – undo
132 132
         $meta = maybe_unserialize($old_venue['meta']);
133 133
         $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134 134
         $insertion_array = array(
135
-                    'post_title' => stripslashes($old_venue['name']),// VNU_name
136
-                    'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
-                    'post_name' => $slug,// VNU_identifier
138
-                    'post_date' => current_time('mysql'),// VNU_created
135
+                    'post_title' => stripslashes($old_venue['name']), // VNU_name
136
+                    'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '', // VNU_desc
137
+                    'post_name' => $slug, // VNU_identifier
138
+                    'post_date' => current_time('mysql'), // VNU_created
139 139
                     'post_date_gmt' =>  current_time('mysql', true),
140
-                    'post_excerpt' => '',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
-                    'post_modified' => current_time('mysql'),// VNU_modified
140
+                    'post_excerpt' => '', // wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
+                    'post_modified' => current_time('mysql'), // VNU_modified
142 142
                     'post_modified_gmt' => current_time('mysql', true),
143
-                    'post_author' => $old_venue['wp_user'],// VNU_wp_user
144
-                    'post_parent' => 0,// parent
145
-                    'menu_order' => 0,// VNU_order
143
+                    'post_author' => $old_venue['wp_user'], // VNU_wp_user
144
+                    'post_parent' => 0, // parent
145
+                    'menu_order' => 0, // VNU_order
146 146
                     'post_type' => 'espresso_venues'// post_type
147 147
                 );
148 148
         $datatypes_array = array(
149
-                    '%s',// VNU_name
150
-                    '%s',// VNU_desc
151
-                    '%s',// VNU_identifier
152
-                    '%s',// VNU_created
149
+                    '%s', // VNU_name
150
+                    '%s', // VNU_desc
151
+                    '%s', // VNU_identifier
152
+                    '%s', // VNU_created
153 153
                     '%s',
154
-                    '%s',// VNU_short_desc
155
-                    '%s',// VNU_modified
154
+                    '%s', // VNU_short_desc
155
+                    '%s', // VNU_modified
156 156
                     '%s',
157
-                    '%d',// VNU_wp_user
158
-                    '%d',// parent
159
-                    '%d',// VNU_order
160
-                    '%s',// post_type
157
+                    '%d', // VNU_wp_user
158
+                    '%d', // parent
159
+                    '%d', // VNU_order
160
+                    '%s', // post_type
161 161
                 );
162 162
         $success = $wpdb->insert(
163 163
             $this->_new_table,
164 164
             $insertion_array,
165 165
             $datatypes_array
166 166
         );
167
-        if (! $success) {
167
+        if ( ! $success) {
168 168
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169 169
             return 0;
170 170
         }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         $original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185 185
         $event_slug = $original_name;
186 186
         while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187
-            $event_slug = sanitize_title($original_name . "-" . ++$count);
187
+            $event_slug = sanitize_title($original_name."-".++$count);
188 188
         }
189 189
         return $event_slug;
190 190
     }
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     private function _other_post_exists_with_that_slug($slug)
199 199
     {
200 200
         global $wpdb;
201
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", $slug);
201
+        $query = $wpdb->prepare("SELECT COUNT(ID) FROM ".$this->_new_table." WHERE post_name = %s", $slug);
202 202
         $count = $wpdb->get_var($query);
203 203
         return (bool) intval($count);
204 204
     }
@@ -231,39 +231,39 @@  discard block
 block discarded – undo
231 231
         $meta = maybe_unserialize($old_venue['meta']);
232 232
         // now insert into meta table
233 233
         $insertion_array = array(
234
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
235
-            'VNU_address' => stripslashes($old_venue['address']),// VNU_address
236
-            'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2
237
-            'VNU_city' => stripslashes($old_venue['city']),// VNU_city
238
-            'STA_ID' => $state_id,// STA_ID
239
-            'CNT_ISO' => $country_iso,// CNT_ISO
240
-            'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip
241
-            'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
-            'VNU_capacity' => -1,// VNU_capacity
243
-            'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
-            'VNU_virtual_phone' => '',// VNU_virtual_phone
245
-            'VNU_virtual_url' => '',// VNU_virtual_url
246
-            'VNU_google_map_link' => '',// VNU_google_map_link
234
+            'VNU_ID' => $cpt_id, // VNU_ID_fk
235
+            'VNU_address' => stripslashes($old_venue['address']), // VNU_address
236
+            'VNU_address2' => stripslashes($old_venue['address2']), // VNU_address2
237
+            'VNU_city' => stripslashes($old_venue['city']), // VNU_city
238
+            'STA_ID' => $state_id, // STA_ID
239
+            'CNT_ISO' => $country_iso, // CNT_ISO
240
+            'VNU_zip' => stripslashes($old_venue['zip']), // VNU_zip
241
+            'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '', // VNU_phone
242
+            'VNU_capacity' => -1, // VNU_capacity
243
+            'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '', // VNU_url
244
+            'VNU_virtual_phone' => '', // VNU_virtual_phone
245
+            'VNU_virtual_url' => '', // VNU_virtual_url
246
+            'VNU_google_map_link' => '', // VNU_google_map_link
247 247
             'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
248 248
         );
249 249
         $datatypes = array(
250
-            '%d',// VNU_ID_fk
251
-            '%s',// VNU_address
252
-            '%s',// VNU_address2
253
-            '%s',// VNU_city
254
-            '%d',// STA_ID
255
-            '%s',// CNT_ISO
256
-            '%s',// VNU_zip
257
-            '%s',// VNU_phone
258
-            '%d',// VNU_capacity
259
-            '%s',// VNU_url
260
-            '%s',// VNU_virtual_phone
261
-            '%s',// VNU_virtual_url
262
-            '%s',// VNU_google_map_link
263
-            '%d',// VNU_enable_for_gmap
250
+            '%d', // VNU_ID_fk
251
+            '%s', // VNU_address
252
+            '%s', // VNU_address2
253
+            '%s', // VNU_city
254
+            '%d', // STA_ID
255
+            '%s', // CNT_ISO
256
+            '%s', // VNU_zip
257
+            '%s', // VNU_phone
258
+            '%d', // VNU_capacity
259
+            '%s', // VNU_url
260
+            '%s', // VNU_virtual_phone
261
+            '%s', // VNU_virtual_url
262
+            '%s', // VNU_google_map_link
263
+            '%d', // VNU_enable_for_gmap
264 264
         );
265 265
         $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
-        if (! $success) {
266
+        if ( ! $success) {
267 267
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268 268
             return 0;
269 269
         }
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -63,210 +63,210 @@
 block discarded – undo
63 63
  */
64 64
 class EE_DMS_4_1_0_venues extends EE_Data_Migration_Script_Stage
65 65
 {
66
-    private $_old_table;
67
-    private $_new_table;
68
-    private $_new_meta_table;
69
-    public function _migration_step($num_items = 50)
70
-    {
71
-        global $wpdb;
72
-        $start_at_record = $this->count_records_migrated();
73
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74
-        $items_actually_migrated = 0;
75
-        foreach ($rows as $old_venue) {
76
-            if (! $new_id = $this->_insert_into_posts($old_venue)) {
77
-                $items_actually_migrated++;
78
-                continue;
79
-            }
80
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
-            if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82
-                $items_actually_migrated++;
83
-                continue;
84
-            }
85
-            $this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id);
86
-            // lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it
87
-            $venue_meta = maybe_unserialize($old_venue['meta']);
88
-            if (isset($venue_meta['contact']) && $venue_meta['contact']) {
89
-                add_post_meta($new_id, 'contact', $venue_meta['contact']);
90
-            }
91
-            // is there an image on this venue?
92
-            $guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null;
93
-            if ($guid) {
94
-                $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
95
-            }
96
-            $items_actually_migrated++;
97
-            if ($guid) {
98
-                // if there was an image, we may have had to download it etc and it may have taken
99
-                // longer, then let's not bother migrating anymore on this step
100
-                break;
101
-            }
102
-        }
103
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
104
-            $this->set_completed();
105
-        }
106
-        return $items_actually_migrated;
107
-    }
108
-    public function _count_records_to_migrate()
109
-    {
110
-        global $wpdb;
111
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
112
-        return $count;
113
-    }
114
-    public function __construct()
115
-    {
116
-        $this->_pretty_name = esc_html__("Venues", "event_espresso");
117
-        global $wpdb;
118
-        $this->_old_table = $wpdb->prefix . "events_venue";
119
-        $this->_new_table = $wpdb->posts;
120
-        $this->_new_meta_table = $wpdb->prefix . "esp_venue_meta";
121
-        parent::__construct();
122
-    }
66
+	private $_old_table;
67
+	private $_new_table;
68
+	private $_new_meta_table;
69
+	public function _migration_step($num_items = 50)
70
+	{
71
+		global $wpdb;
72
+		$start_at_record = $this->count_records_migrated();
73
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $this->_old_table . " LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
74
+		$items_actually_migrated = 0;
75
+		foreach ($rows as $old_venue) {
76
+			if (! $new_id = $this->_insert_into_posts($old_venue)) {
77
+				$items_actually_migrated++;
78
+				continue;
79
+			}
80
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_table, $new_id);
81
+			if (! $new_meta_id = $this->_insert_into_meta_table($new_id, $old_venue)) {
82
+				$items_actually_migrated++;
83
+				continue;
84
+			}
85
+			$this->get_migration_script()->set_mapping($this->_old_table, $old_venue['id'], $this->_new_meta_table, $new_meta_id);
86
+			// lastly, save the 'contact' as post meta, because it doesn't exist anywhere else but someone may still want it
87
+			$venue_meta = maybe_unserialize($old_venue['meta']);
88
+			if (isset($venue_meta['contact']) && $venue_meta['contact']) {
89
+				add_post_meta($new_id, 'contact', $venue_meta['contact']);
90
+			}
91
+			// is there an image on this venue?
92
+			$guid = isset($venue_meta['image']) && $venue_meta['image'] ? $venue_meta['image'] : null;
93
+			if ($guid) {
94
+				$this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this);
95
+			}
96
+			$items_actually_migrated++;
97
+			if ($guid) {
98
+				// if there was an image, we may have had to download it etc and it may have taken
99
+				// longer, then let's not bother migrating anymore on this step
100
+				break;
101
+			}
102
+		}
103
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
104
+			$this->set_completed();
105
+		}
106
+		return $items_actually_migrated;
107
+	}
108
+	public function _count_records_to_migrate()
109
+	{
110
+		global $wpdb;
111
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table);
112
+		return $count;
113
+	}
114
+	public function __construct()
115
+	{
116
+		$this->_pretty_name = esc_html__("Venues", "event_espresso");
117
+		global $wpdb;
118
+		$this->_old_table = $wpdb->prefix . "events_venue";
119
+		$this->_new_table = $wpdb->posts;
120
+		$this->_new_meta_table = $wpdb->prefix . "esp_venue_meta";
121
+		parent::__construct();
122
+	}
123 123
 
124
-    /**
125
-     * Inserts the CPT
126
-     * @param array $old_venue keys are cols, values are col values
127
-     * @return int
128
-     */
129
-    private function _insert_into_posts($old_venue)
130
-    {
131
-        global $wpdb;
132
-        $meta = maybe_unserialize($old_venue['meta']);
133
-        $slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134
-        $insertion_array = array(
135
-                    'post_title' => stripslashes($old_venue['name']),// VNU_name
136
-                    'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
-                    'post_name' => $slug,// VNU_identifier
138
-                    'post_date' => current_time('mysql'),// VNU_created
139
-                    'post_date_gmt' =>  current_time('mysql', true),
140
-                    'post_excerpt' => '',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
-                    'post_modified' => current_time('mysql'),// VNU_modified
142
-                    'post_modified_gmt' => current_time('mysql', true),
143
-                    'post_author' => $old_venue['wp_user'],// VNU_wp_user
144
-                    'post_parent' => 0,// parent
145
-                    'menu_order' => 0,// VNU_order
146
-                    'post_type' => 'espresso_venues'// post_type
147
-                );
148
-        $datatypes_array = array(
149
-                    '%s',// VNU_name
150
-                    '%s',// VNU_desc
151
-                    '%s',// VNU_identifier
152
-                    '%s',// VNU_created
153
-                    '%s',
154
-                    '%s',// VNU_short_desc
155
-                    '%s',// VNU_modified
156
-                    '%s',
157
-                    '%d',// VNU_wp_user
158
-                    '%d',// parent
159
-                    '%d',// VNU_order
160
-                    '%s',// post_type
161
-                );
162
-        $success = $wpdb->insert(
163
-            $this->_new_table,
164
-            $insertion_array,
165
-            $datatypes_array
166
-        );
167
-        if (! $success) {
168
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169
-            return 0;
170
-        }
171
-        return $wpdb->insert_id;
172
-    }
124
+	/**
125
+	 * Inserts the CPT
126
+	 * @param array $old_venue keys are cols, values are col values
127
+	 * @return int
128
+	 */
129
+	private function _insert_into_posts($old_venue)
130
+	{
131
+		global $wpdb;
132
+		$meta = maybe_unserialize($old_venue['meta']);
133
+		$slug = $this->_find_unique_slug($old_venue['name'], $old_venue['identifier']);
134
+		$insertion_array = array(
135
+					'post_title' => stripslashes($old_venue['name']),// VNU_name
136
+					'post_content' => isset($meta['description']) ? stripslashes(strip_tags($meta['description'])) : '',// VNU_desc
137
+					'post_name' => $slug,// VNU_identifier
138
+					'post_date' => current_time('mysql'),// VNU_created
139
+					'post_date_gmt' =>  current_time('mysql', true),
140
+					'post_excerpt' => '',// wp_trim_words($meta['description'] ? $meta['description'] : '',50),//VNU_short_desc arbitraty only 50 characters
141
+					'post_modified' => current_time('mysql'),// VNU_modified
142
+					'post_modified_gmt' => current_time('mysql', true),
143
+					'post_author' => $old_venue['wp_user'],// VNU_wp_user
144
+					'post_parent' => 0,// parent
145
+					'menu_order' => 0,// VNU_order
146
+					'post_type' => 'espresso_venues'// post_type
147
+				);
148
+		$datatypes_array = array(
149
+					'%s',// VNU_name
150
+					'%s',// VNU_desc
151
+					'%s',// VNU_identifier
152
+					'%s',// VNU_created
153
+					'%s',
154
+					'%s',// VNU_short_desc
155
+					'%s',// VNU_modified
156
+					'%s',
157
+					'%d',// VNU_wp_user
158
+					'%d',// parent
159
+					'%d',// VNU_order
160
+					'%s',// post_type
161
+				);
162
+		$success = $wpdb->insert(
163
+			$this->_new_table,
164
+			$insertion_array,
165
+			$datatypes_array
166
+		);
167
+		if (! $success) {
168
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_table, $insertion_array, $datatypes_array));
169
+			return 0;
170
+		}
171
+		return $wpdb->insert_id;
172
+	}
173 173
 
174
-    /**
175
-     * Finds a unique slug for this venue, given its name (we could have simply used
176
-     * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
177
-     * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
178
-     * @param string $post_name
179
-     * @return string
180
-     */
181
-    private function _find_unique_slug($post_name, $old_identifier = '')
182
-    {
183
-        $count = 0;
184
-        $original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185
-        $event_slug = $original_name;
186
-        while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187
-            $event_slug = sanitize_title($original_name . "-" . ++$count);
188
-        }
189
-        return $event_slug;
190
-    }
174
+	/**
175
+	 * Finds a unique slug for this venue, given its name (we could have simply used
176
+	 * the old unique_identifier column, but it added a long string of seemingly random characters onto the end
177
+	 * and really wasn't that pretty for a slug, so we decided we'd make our own slug again)
178
+	 * @param string $post_name
179
+	 * @return string
180
+	 */
181
+	private function _find_unique_slug($post_name, $old_identifier = '')
182
+	{
183
+		$count = 0;
184
+		$original_name = $post_name ? sanitize_title($post_name) : $old_identifier;
185
+		$event_slug = $original_name;
186
+		while ($this->_other_post_exists_with_that_slug($event_slug) && $count < 50) {
187
+			$event_slug = sanitize_title($original_name . "-" . ++$count);
188
+		}
189
+		return $event_slug;
190
+	}
191 191
 
192
-    /**
193
-     * returns whether or not there is a post that has this same slug (post_title)
194
-     * @global type $wpdb
195
-     * @param type $slug
196
-     * @return boolean
197
-     */
198
-    private function _other_post_exists_with_that_slug($slug)
199
-    {
200
-        global $wpdb;
201
-        $query = $wpdb->prepare("SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", $slug);
202
-        $count = $wpdb->get_var($query);
203
-        return (bool) intval($count);
204
-    }
192
+	/**
193
+	 * returns whether or not there is a post that has this same slug (post_title)
194
+	 * @global type $wpdb
195
+	 * @param type $slug
196
+	 * @return boolean
197
+	 */
198
+	private function _other_post_exists_with_that_slug($slug)
199
+	{
200
+		global $wpdb;
201
+		$query = $wpdb->prepare("SELECT COUNT(ID) FROM " . $this->_new_table . " WHERE post_name = %s", $slug);
202
+		$count = $wpdb->get_var($query);
203
+		return (bool) intval($count);
204
+	}
205 205
 
206
-    /**
207
-     * Inserts into the venue_meta table
208
-     * @param type $cpt_id
209
-     * @param type $old_venue
210
-     * @return int
211
-     */
212
-    private function _insert_into_meta_table($cpt_id, $old_venue)
213
-    {
214
-        global $wpdb;
215
-        // get a country with the same name, or insert one
216
-        try {
217
-            $country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country']));
218
-            $country_iso = $country['CNT_ISO'];
219
-        } catch (EE_Error $e) {
220
-            $this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
221
-            $country_iso = null;
222
-        }
223
-        // get a state with the same name, if possible
224
-        try {
225
-            $state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags((string) $old_venue['country']));
226
-            $state_id = $state['STA_ID'];
227
-        } catch (EE_Error $e) {
228
-            $this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
229
-            $state_id = 0;
230
-        }
231
-        $meta = maybe_unserialize($old_venue['meta']);
232
-        // now insert into meta table
233
-        $insertion_array = array(
234
-            'VNU_ID' => $cpt_id,// VNU_ID_fk
235
-            'VNU_address' => stripslashes($old_venue['address']),// VNU_address
236
-            'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2
237
-            'VNU_city' => stripslashes($old_venue['city']),// VNU_city
238
-            'STA_ID' => $state_id,// STA_ID
239
-            'CNT_ISO' => $country_iso,// CNT_ISO
240
-            'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip
241
-            'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
-            'VNU_capacity' => -1,// VNU_capacity
243
-            'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
-            'VNU_virtual_phone' => '',// VNU_virtual_phone
245
-            'VNU_virtual_url' => '',// VNU_virtual_url
246
-            'VNU_google_map_link' => '',// VNU_google_map_link
247
-            'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
248
-        );
249
-        $datatypes = array(
250
-            '%d',// VNU_ID_fk
251
-            '%s',// VNU_address
252
-            '%s',// VNU_address2
253
-            '%s',// VNU_city
254
-            '%d',// STA_ID
255
-            '%s',// CNT_ISO
256
-            '%s',// VNU_zip
257
-            '%s',// VNU_phone
258
-            '%d',// VNU_capacity
259
-            '%s',// VNU_url
260
-            '%s',// VNU_virtual_phone
261
-            '%s',// VNU_virtual_url
262
-            '%s',// VNU_google_map_link
263
-            '%d',// VNU_enable_for_gmap
264
-        );
265
-        $success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
-        if (! $success) {
267
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268
-            return 0;
269
-        }
270
-        return $wpdb->insert_id;
271
-    }
206
+	/**
207
+	 * Inserts into the venue_meta table
208
+	 * @param type $cpt_id
209
+	 * @param type $old_venue
210
+	 * @return int
211
+	 */
212
+	private function _insert_into_meta_table($cpt_id, $old_venue)
213
+	{
214
+		global $wpdb;
215
+		// get a country with the same name, or insert one
216
+		try {
217
+			$country = $this->get_migration_script()->get_or_create_country(stripslashes($old_venue['country']));
218
+			$country_iso = $country['CNT_ISO'];
219
+		} catch (EE_Error $e) {
220
+			$this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
221
+			$country_iso = null;
222
+		}
223
+		// get a state with the same name, if possible
224
+		try {
225
+			$state = $this->get_migration_script()->get_or_create_state(stripslashes($old_venue['state']), isset($country['CNT_name']) ? $country['CNT_name'] : strip_tags((string) $old_venue['country']));
226
+			$state_id = $state['STA_ID'];
227
+		} catch (EE_Error $e) {
228
+			$this->add_error(sprintf(esc_html__("%s for venue %s", "event_espresso"), $e->getMessage(), $this->_json_encode($old_venue)));
229
+			$state_id = 0;
230
+		}
231
+		$meta = maybe_unserialize($old_venue['meta']);
232
+		// now insert into meta table
233
+		$insertion_array = array(
234
+			'VNU_ID' => $cpt_id,// VNU_ID_fk
235
+			'VNU_address' => stripslashes($old_venue['address']),// VNU_address
236
+			'VNU_address2' => stripslashes($old_venue['address2']),// VNU_address2
237
+			'VNU_city' => stripslashes($old_venue['city']),// VNU_city
238
+			'STA_ID' => $state_id,// STA_ID
239
+			'CNT_ISO' => $country_iso,// CNT_ISO
240
+			'VNU_zip' => stripslashes($old_venue['zip']),// VNU_zip
241
+			'VNU_phone' => isset($meta['phone']) ? stripslashes($meta['phone']) : '',// VNU_phone
242
+			'VNU_capacity' => -1,// VNU_capacity
243
+			'VNU_url' => isset($meta['website']) ? stripslashes($meta['website']) : '',// VNU_url
244
+			'VNU_virtual_phone' => '',// VNU_virtual_phone
245
+			'VNU_virtual_url' => '',// VNU_virtual_url
246
+			'VNU_google_map_link' => '',// VNU_google_map_link
247
+			'VNU_enable_for_gmap' => true // VNU_enable_for_gmap
248
+		);
249
+		$datatypes = array(
250
+			'%d',// VNU_ID_fk
251
+			'%s',// VNU_address
252
+			'%s',// VNU_address2
253
+			'%s',// VNU_city
254
+			'%d',// STA_ID
255
+			'%s',// CNT_ISO
256
+			'%s',// VNU_zip
257
+			'%s',// VNU_phone
258
+			'%d',// VNU_capacity
259
+			'%s',// VNU_url
260
+			'%s',// VNU_virtual_phone
261
+			'%s',// VNU_virtual_url
262
+			'%s',// VNU_google_map_link
263
+			'%d',// VNU_enable_for_gmap
264
+		);
265
+		$success = $wpdb->insert($this->_new_meta_table, $insertion_array, $datatypes);
266
+		if (! $success) {
267
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_venue, $this->_new_meta_table, $insertion_array, $datatypes));
268
+			return 0;
269
+		}
270
+		return $wpdb->insert_id;
271
+	}
272 272
 }
Please login to merge, or discard this patch.