Completed
Branch FIX/fix-datetime-picker-styles (49553a)
by
unknown
43:56 queued 35:31
created
4_7_0_stages/EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price.dmsstage.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -12,73 +12,73 @@  discard block
 block discarded – undo
12 12
 class EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14 14
 
15
-    protected $_ticket_table;
16
-
17
-    protected $_line_item_table;
18
-
19
-    public function __construct()
20
-    {
21
-        /** @type WPDB $wpdb */
22
-        global $wpdb;
23
-        $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso');
24
-        // define tables
25
-        $this->_old_table               = $wpdb->prefix . 'esp_registration';
26
-        $this->_ticket_table            = $wpdb->prefix . 'esp_ticket';
27
-        $this->_line_item_table     = $wpdb->prefix . 'esp_line_item';
28
-        parent::__construct();
29
-    }
30
-
31
-
32
-
33
-    /**
34
-     * @return string
35
-     */
36
-    protected function _get_rest_of_sql_for_query()
37
-    {
38
-        $SQL = "FROM {$this->_old_table} AS reg ";
39
-        $SQL .= "JOIN {$this->_ticket_table} as tkt ON reg.TKT_ID = tkt.TKT_ID ";
40
-        $SQL .= "JOIN {$this->_line_item_table} as line ON reg.TXN_ID = line.TXN_ID ";
41
-        $SQL .= "WHERE tkt.TKT_taxable = 1 ";
42
-        $SQL .= "AND line.LIN_code = 'total' ";
43
-        $SQL .= "AND reg.REG_final_price > 0 ";
44
-        return $SQL;
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * Counts the records to migrate; the public version may cache it
51
-     * @return int
52
-     */
53
-    public function _count_records_to_migrate()
54
-    {
55
-        /** @type WPDB $wpdb */
56
-        global $wpdb;
57
-        $SQL = "SELECT count( reg.REG_ID ) ";
58
-        $SQL .= $this->_get_rest_of_sql_for_query();
59
-        $count = $wpdb->get_var($SQL);
60
-        return $count;
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * Gets data for all registrations with taxable tickets in the esp_line_item table
67
-     * @global wpdb $wpdb
68
-     * @param int $limit
69
-     * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
70
-     */
71
-    protected function _get_rows($limit)
72
-    {
73
-        /** @type WPDB $wpdb */
74
-        global $wpdb;
75
-        $start_at_record = $this->count_records_migrated();
76
-        $SQL = "SELECT reg.REG_ID,  reg.REG_final_price, line.LIN_ID ";
77
-        $SQL .= $this->_get_rest_of_sql_for_query();
78
-        $SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit);
79
-
80
-        // produces something like:
81
-        /*
15
+	protected $_ticket_table;
16
+
17
+	protected $_line_item_table;
18
+
19
+	public function __construct()
20
+	{
21
+		/** @type WPDB $wpdb */
22
+		global $wpdb;
23
+		$this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso');
24
+		// define tables
25
+		$this->_old_table               = $wpdb->prefix . 'esp_registration';
26
+		$this->_ticket_table            = $wpdb->prefix . 'esp_ticket';
27
+		$this->_line_item_table     = $wpdb->prefix . 'esp_line_item';
28
+		parent::__construct();
29
+	}
30
+
31
+
32
+
33
+	/**
34
+	 * @return string
35
+	 */
36
+	protected function _get_rest_of_sql_for_query()
37
+	{
38
+		$SQL = "FROM {$this->_old_table} AS reg ";
39
+		$SQL .= "JOIN {$this->_ticket_table} as tkt ON reg.TKT_ID = tkt.TKT_ID ";
40
+		$SQL .= "JOIN {$this->_line_item_table} as line ON reg.TXN_ID = line.TXN_ID ";
41
+		$SQL .= "WHERE tkt.TKT_taxable = 1 ";
42
+		$SQL .= "AND line.LIN_code = 'total' ";
43
+		$SQL .= "AND reg.REG_final_price > 0 ";
44
+		return $SQL;
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * Counts the records to migrate; the public version may cache it
51
+	 * @return int
52
+	 */
53
+	public function _count_records_to_migrate()
54
+	{
55
+		/** @type WPDB $wpdb */
56
+		global $wpdb;
57
+		$SQL = "SELECT count( reg.REG_ID ) ";
58
+		$SQL .= $this->_get_rest_of_sql_for_query();
59
+		$count = $wpdb->get_var($SQL);
60
+		return $count;
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * Gets data for all registrations with taxable tickets in the esp_line_item table
67
+	 * @global wpdb $wpdb
68
+	 * @param int $limit
69
+	 * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
70
+	 */
71
+	protected function _get_rows($limit)
72
+	{
73
+		/** @type WPDB $wpdb */
74
+		global $wpdb;
75
+		$start_at_record = $this->count_records_migrated();
76
+		$SQL = "SELECT reg.REG_ID,  reg.REG_final_price, line.LIN_ID ";
77
+		$SQL .= $this->_get_rest_of_sql_for_query();
78
+		$SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit);
79
+
80
+		// produces something like:
81
+		/*
82 82
             SELECT
83 83
               reg.REG_ID,
84 84
               reg.REG_final_price,
@@ -95,137 +95,137 @@  discard block
 block discarded – undo
95 95
             LIMIT 1, 50
96 96
          */
97 97
 
98
-        return $wpdb->get_results($SQL, ARRAY_A);
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     * @param array $row
105
-     * @return void
106
-     */
107
-    protected function _migrate_old_row($row)
108
-    {
109
-        /** @type WPDB $wpdb */
110
-        global $wpdb;
111
-        // ensure all required values are present
112
-        if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) {
113
-            $this->add_error(
114
-                sprintf(
115
-                    __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'),
116
-                    '<br />',
117
-                    isset($row['REG_ID']) ? $row['REG_ID'] : '',
118
-                    isset($row['REG_final_price']) ? $row['REG_final_price'] : '',
119
-                    isset($row['LIN_ID']) ? $row['LIN_ID'] : '',
120
-                    $wpdb->last_error
121
-                )
122
-            );
123
-            return;
124
-        }
125
-        // get tax subtotal
126
-        $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']);
127
-        if (! $tax_subtotal_line_item_ID) {
128
-            $this->add_error(
129
-                sprintf(
130
-                    __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'),
131
-                    $wpdb->last_error
132
-                )
133
-            );
134
-            return;
135
-        }
136
-        // now get taxes
137
-        $taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID);
138
-        // apply taxes to registration final price
139
-        $this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes);
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * _get_tax_subtotal
146
-     *
147
-     * @param int $LIN_ID
148
-     * @return int
149
-     */
150
-    protected function _get_line_item_ID_for_tax_subtotal($LIN_ID)
151
-    {
152
-        /** @type WPDB $wpdb */
153
-        global $wpdb;
154
-        $SQL = "SELECT LIN_ID ";
155
-        $SQL .= "FROM {$this->_line_item_table} ";
156
-        $SQL .= "WHERE LIN_parent = %d ";
157
-        $SQL .= "AND LIN_code = 'taxes'";
158
-        return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID));
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * _get_tax_subtotal
165
-     *
166
-     * @param int $LIN_ID
167
-     * @return array
168
-     */
169
-    protected function _get_tax_amounts($LIN_ID)
170
-    {
171
-        /** @type WPDB $wpdb */
172
-        global $wpdb;
173
-        $SQL = "SELECT LIN_percent ";
174
-        $SQL .= "FROM {$this->_line_item_table} ";
175
-        $SQL .= "WHERE LIN_parent = %d";
176
-        return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K);
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * _apply_taxes
183
-     *
184
-     * @param int $REG_ID
185
-     * @param float $final_price
186
-     * @param array $taxes
187
-     * @return void
188
-     */
189
-    protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array())
190
-    {
191
-        if (is_array($taxes) && ! empty($taxes)) {
192
-            $total_taxes = 0;
193
-            foreach ($taxes as $tax) {
194
-                $total_taxes += $final_price * ( $tax->LIN_percent / 100 );
195
-            }
196
-            $final_price += $total_taxes;
197
-            $this->_update_registration_final_price($REG_ID, $final_price);
198
-        }
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * _update_registration_final_price
205
-     *
206
-     * @param int $REG_ID
207
-     * @param float $REG_final_price
208
-     * @return void
209
-     */
210
-    protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00)
211
-    {
212
-        /** @type WPDB $wpdb */
213
-        global $wpdb;
214
-        $success = $wpdb->update(
215
-            $this->_old_table,
216
-            array( 'REG_final_price' => $REG_final_price ),  // data
217
-            array( 'REG_ID' => $REG_ID ),  // where
218
-            array( '%f' ),   // data format
219
-            array( '%d' )  // where format
220
-        );
221
-        if ($success === false) {
222
-            $this->add_error(
223
-                sprintf(
224
-                    __('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'),
225
-                    $REG_ID,
226
-                    $wpdb->last_error
227
-                )
228
-            );
229
-        }
230
-    }
98
+		return $wpdb->get_results($SQL, ARRAY_A);
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 * @param array $row
105
+	 * @return void
106
+	 */
107
+	protected function _migrate_old_row($row)
108
+	{
109
+		/** @type WPDB $wpdb */
110
+		global $wpdb;
111
+		// ensure all required values are present
112
+		if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) {
113
+			$this->add_error(
114
+				sprintf(
115
+					__('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'),
116
+					'<br />',
117
+					isset($row['REG_ID']) ? $row['REG_ID'] : '',
118
+					isset($row['REG_final_price']) ? $row['REG_final_price'] : '',
119
+					isset($row['LIN_ID']) ? $row['LIN_ID'] : '',
120
+					$wpdb->last_error
121
+				)
122
+			);
123
+			return;
124
+		}
125
+		// get tax subtotal
126
+		$tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']);
127
+		if (! $tax_subtotal_line_item_ID) {
128
+			$this->add_error(
129
+				sprintf(
130
+					__('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'),
131
+					$wpdb->last_error
132
+				)
133
+			);
134
+			return;
135
+		}
136
+		// now get taxes
137
+		$taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID);
138
+		// apply taxes to registration final price
139
+		$this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes);
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * _get_tax_subtotal
146
+	 *
147
+	 * @param int $LIN_ID
148
+	 * @return int
149
+	 */
150
+	protected function _get_line_item_ID_for_tax_subtotal($LIN_ID)
151
+	{
152
+		/** @type WPDB $wpdb */
153
+		global $wpdb;
154
+		$SQL = "SELECT LIN_ID ";
155
+		$SQL .= "FROM {$this->_line_item_table} ";
156
+		$SQL .= "WHERE LIN_parent = %d ";
157
+		$SQL .= "AND LIN_code = 'taxes'";
158
+		return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID));
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * _get_tax_subtotal
165
+	 *
166
+	 * @param int $LIN_ID
167
+	 * @return array
168
+	 */
169
+	protected function _get_tax_amounts($LIN_ID)
170
+	{
171
+		/** @type WPDB $wpdb */
172
+		global $wpdb;
173
+		$SQL = "SELECT LIN_percent ";
174
+		$SQL .= "FROM {$this->_line_item_table} ";
175
+		$SQL .= "WHERE LIN_parent = %d";
176
+		return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K);
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * _apply_taxes
183
+	 *
184
+	 * @param int $REG_ID
185
+	 * @param float $final_price
186
+	 * @param array $taxes
187
+	 * @return void
188
+	 */
189
+	protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array())
190
+	{
191
+		if (is_array($taxes) && ! empty($taxes)) {
192
+			$total_taxes = 0;
193
+			foreach ($taxes as $tax) {
194
+				$total_taxes += $final_price * ( $tax->LIN_percent / 100 );
195
+			}
196
+			$final_price += $total_taxes;
197
+			$this->_update_registration_final_price($REG_ID, $final_price);
198
+		}
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * _update_registration_final_price
205
+	 *
206
+	 * @param int $REG_ID
207
+	 * @param float $REG_final_price
208
+	 * @return void
209
+	 */
210
+	protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00)
211
+	{
212
+		/** @type WPDB $wpdb */
213
+		global $wpdb;
214
+		$success = $wpdb->update(
215
+			$this->_old_table,
216
+			array( 'REG_final_price' => $REG_final_price ),  // data
217
+			array( 'REG_ID' => $REG_ID ),  // where
218
+			array( '%f' ),   // data format
219
+			array( '%d' )  // where format
220
+		);
221
+		if ($success === false) {
222
+			$this->add_error(
223
+				sprintf(
224
+					__('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'),
225
+					$REG_ID,
226
+					$wpdb->last_error
227
+				)
228
+			);
229
+		}
230
+	}
231 231
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
         global $wpdb;
23 23
         $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso');
24 24
         // define tables
25
-        $this->_old_table               = $wpdb->prefix . 'esp_registration';
26
-        $this->_ticket_table            = $wpdb->prefix . 'esp_ticket';
27
-        $this->_line_item_table     = $wpdb->prefix . 'esp_line_item';
25
+        $this->_old_table               = $wpdb->prefix.'esp_registration';
26
+        $this->_ticket_table            = $wpdb->prefix.'esp_ticket';
27
+        $this->_line_item_table = $wpdb->prefix.'esp_line_item';
28 28
         parent::__construct();
29 29
     }
30 30
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         /** @type WPDB $wpdb */
110 110
         global $wpdb;
111 111
         // ensure all required values are present
112
-        if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) {
112
+        if ( ! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) {
113 113
             $this->add_error(
114 114
                 sprintf(
115 115
                     __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'),
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         }
125 125
         // get tax subtotal
126 126
         $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']);
127
-        if (! $tax_subtotal_line_item_ID) {
127
+        if ( ! $tax_subtotal_line_item_ID) {
128 128
             $this->add_error(
129 129
                 sprintf(
130 130
                     __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'),
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         if (is_array($taxes) && ! empty($taxes)) {
192 192
             $total_taxes = 0;
193 193
             foreach ($taxes as $tax) {
194
-                $total_taxes += $final_price * ( $tax->LIN_percent / 100 );
194
+                $total_taxes += $final_price * ($tax->LIN_percent / 100);
195 195
             }
196 196
             $final_price += $total_taxes;
197 197
             $this->_update_registration_final_price($REG_ID, $final_price);
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
         global $wpdb;
214 214
         $success = $wpdb->update(
215 215
             $this->_old_table,
216
-            array( 'REG_final_price' => $REG_final_price ),  // data
217
-            array( 'REG_ID' => $REG_ID ),  // where
218
-            array( '%f' ),   // data format
219
-            array( '%d' )  // where format
216
+            array('REG_final_price' => $REG_final_price), // data
217
+            array('REG_ID' => $REG_ID), // where
218
+            array('%f'), // data format
219
+            array('%d')  // where format
220 220
         );
221 221
         if ($success === false) {
222 222
             $this->add_error(
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Unknown_1_0_0.core.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -18,44 +18,44 @@
 block discarded – undo
18 18
 class EE_DMS_Unknown_1_0_0 extends EE_Data_Migration_Script_Base
19 19
 {
20 20
 
21
-    /**
22
-     * Returns whether or not this data migration script can operate on the given version of the database.
23
-     * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
24
-     * it's passed a string like '3.1.38B', it should return true
25
-     *
26
-     * @param string $version_string
27
-     * @return boolean
28
-     */
29
-    public function can_migrate_from_version($version_string)
30
-    {
31
-        return false;
32
-    }
33
-
34
-    public function schema_changes_after_migration()
35
-    {
36
-        return;
37
-    }
38
-
39
-    public function schema_changes_before_migration()
40
-    {
41
-        return;
42
-    }
43
-
44
-
45
-    /**
46
-     * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences!
47
-     *
48
-     * @param TableManager  $table_manager
49
-     * @param TableAnalysis $table_analysis
50
-     */
51
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
52
-    {
53
-        $this->_migration_stages = array();
54
-        $this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso");
55
-        parent::__construct($table_manager, $table_analysis);
56
-    }
57
-
58
-    public function migration_page_hooks()
59
-    {
60
-    }
21
+	/**
22
+	 * Returns whether or not this data migration script can operate on the given version of the database.
23
+	 * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
24
+	 * it's passed a string like '3.1.38B', it should return true
25
+	 *
26
+	 * @param string $version_string
27
+	 * @return boolean
28
+	 */
29
+	public function can_migrate_from_version($version_string)
30
+	{
31
+		return false;
32
+	}
33
+
34
+	public function schema_changes_after_migration()
35
+	{
36
+		return;
37
+	}
38
+
39
+	public function schema_changes_before_migration()
40
+	{
41
+		return;
42
+	}
43
+
44
+
45
+	/**
46
+	 * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences!
47
+	 *
48
+	 * @param TableManager  $table_manager
49
+	 * @param TableAnalysis $table_analysis
50
+	 */
51
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
52
+	{
53
+		$this->_migration_stages = array();
54
+		$this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso");
55
+		parent::__construct($table_manager, $table_analysis);
56
+	}
57
+
58
+	public function migration_page_hooks()
59
+	{
60
+	}
61 61
 }
Please login to merge, or discard this patch.
4_9_0_stages/EE_DMS_4_9_0_Answers_With_No_Registration.dmsstage.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -15,44 +15,44 @@
 block discarded – undo
15 15
 
16 16
 
17 17
 
18
-    /**
19
-     * Just initializes the status of the migration
20
-     *
21
-     * @return EE_DMS_4_9_0_Answers_With_No_Registration
22
-     */
23
-    public function __construct()
24
-    {
25
-        $this->_pretty_name = __('Answer Cleanup', 'event_espresso');
26
-        parent::__construct();
27
-    }
18
+	/**
19
+	 * Just initializes the status of the migration
20
+	 *
21
+	 * @return EE_DMS_4_9_0_Answers_With_No_Registration
22
+	 */
23
+	public function __construct()
24
+	{
25
+		$this->_pretty_name = __('Answer Cleanup', 'event_espresso');
26
+		parent::__construct();
27
+	}
28 28
 
29
-    /**
30
-     * Counts the records to migrate; the public version may cache it
31
-     * @return int
32
-     */
33
-    protected function _count_records_to_migrate()
34
-    {
35
-        return 1;
36
-    }
29
+	/**
30
+	 * Counts the records to migrate; the public version may cache it
31
+	 * @return int
32
+	 */
33
+	protected function _count_records_to_migrate()
34
+	{
35
+		return 1;
36
+	}
37 37
 
38
-    /**
39
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
40
-     * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
41
-     * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
42
-     * 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,
43
-     * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
44
-     * @param int $num_items_to_migrate
45
-     * @return int number of items ACTUALLY migrated
46
-     */
47
-    protected function _migration_step($num_items_to_migrate = 50)
48
-    {
49
-        global $wpdb;
50
-        $wpdb->delete(
51
-            $wpdb->prefix . 'esp_answer',
52
-            array( 'REG_ID' => 0 ),
53
-            array( '%d' )
54
-        );
55
-        $this->set_completed();
56
-        return 1;
57
-    }
38
+	/**
39
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly.
40
+	 * Note: it should not alter the count of items migrated. That is done in the public function that calls this.
41
+	 * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it
42
+	 * 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,
43
+	 * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated)
44
+	 * @param int $num_items_to_migrate
45
+	 * @return int number of items ACTUALLY migrated
46
+	 */
47
+	protected function _migration_step($num_items_to_migrate = 50)
48
+	{
49
+		global $wpdb;
50
+		$wpdb->delete(
51
+			$wpdb->prefix . 'esp_answer',
52
+			array( 'REG_ID' => 0 ),
53
+			array( '%d' )
54
+		);
55
+		$this->set_completed();
56
+		return 1;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,9 +48,9 @@
 block discarded – undo
48 48
     {
49 49
         global $wpdb;
50 50
         $wpdb->delete(
51
-            $wpdb->prefix . 'esp_answer',
52
-            array( 'REG_ID' => 0 ),
53
-            array( '%d' )
51
+            $wpdb->prefix.'esp_answer',
52
+            array('REG_ID' => 0),
53
+            array('%d')
54 54
         );
55 55
         $this->set_completed();
56 56
         return 1;
Please login to merge, or discard this patch.
4_9_0_stages/EE_DMS_4_9_0_Email_System_Question.dmsstage.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,48 +14,48 @@
 block discarded – undo
14 14
 
15 15
 
16 16
 
17
-    /**
18
-     * Just initializes the status of the migration
19
-     *
20
-     * @return EE_DMS_4_9_0_Email_System_Question
21
-     */
22
-    public function __construct()
23
-    {
24
-        global $wpdb;
25
-        $this->_pretty_name = __('Email - System Question', 'event_espresso');
26
-        $this->_old_table = $wpdb->prefix.'esp_question';
27
-        $this->_extra_where_sql = "WHERE QST_system = 'email'";
28
-        parent::__construct();
29
-    }
17
+	/**
18
+	 * Just initializes the status of the migration
19
+	 *
20
+	 * @return EE_DMS_4_9_0_Email_System_Question
21
+	 */
22
+	public function __construct()
23
+	{
24
+		global $wpdb;
25
+		$this->_pretty_name = __('Email - System Question', 'event_espresso');
26
+		$this->_old_table = $wpdb->prefix.'esp_question';
27
+		$this->_extra_where_sql = "WHERE QST_system = 'email'";
28
+		parent::__construct();
29
+	}
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * updates the question with the new question type
35
-     * @param array $question an associative array where keys are column names and values are their values.
36
-     * @return null
37
-     */
38
-    protected function _migrate_old_row($question)
39
-    {
40
-        if ($question['QST_ID'] && $question['QST_system'] == 'email') {
41
-            global $wpdb;
42
-            $success = $wpdb->update(
43
-                $this->_old_table,
44
-                array( 'QST_type' => 'EMAIL' ),  // data
45
-                array( 'QST_ID' => $question['QST_ID'] ),  // where
46
-                array( '%s' ),   // data format
47
-                array( '%d' )  // where format
48
-            );
49
-            if (! $success) {
50
-                $this->add_error(
51
-                    sprintf(
52
-                        __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
53
-                        wp_json_encode($question['QST_system']),
54
-                        $question['QST_ID'],
55
-                        $wpdb->last_error
56
-                    )
57
-                );
58
-            }
59
-        }
60
-    }
33
+	/**
34
+	 * updates the question with the new question type
35
+	 * @param array $question an associative array where keys are column names and values are their values.
36
+	 * @return null
37
+	 */
38
+	protected function _migrate_old_row($question)
39
+	{
40
+		if ($question['QST_ID'] && $question['QST_system'] == 'email') {
41
+			global $wpdb;
42
+			$success = $wpdb->update(
43
+				$this->_old_table,
44
+				array( 'QST_type' => 'EMAIL' ),  // data
45
+				array( 'QST_ID' => $question['QST_ID'] ),  // where
46
+				array( '%s' ),   // data format
47
+				array( '%d' )  // where format
48
+			);
49
+			if (! $success) {
50
+				$this->add_error(
51
+					sprintf(
52
+						__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
53
+						wp_json_encode($question['QST_system']),
54
+						$question['QST_ID'],
55
+						$wpdb->last_error
56
+					)
57
+				);
58
+			}
59
+		}
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,12 +41,12 @@
 block discarded – undo
41 41
             global $wpdb;
42 42
             $success = $wpdb->update(
43 43
                 $this->_old_table,
44
-                array( 'QST_type' => 'EMAIL' ),  // data
45
-                array( 'QST_ID' => $question['QST_ID'] ),  // where
46
-                array( '%s' ),   // data format
47
-                array( '%d' )  // where format
44
+                array('QST_type' => 'EMAIL'), // data
45
+                array('QST_ID' => $question['QST_ID']), // where
46
+                array('%s'), // data format
47
+                array('%d')  // where format
48 48
             );
49
-            if (! $success) {
49
+            if ( ! $success) {
50 50
                 $this->add_error(
51 51
                     sprintf(
52 52
                         __('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
Please login to merge, or discard this patch.
4_1_0_stages/EE_DMS_4_1_0_category_details.dmsstage.php 1 patch
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(__("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 = __("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(__("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 = __("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.
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', __('Term (in context of a taxonomy) ID','event_espresso'), false, 0, 'Term_Taxonomy'),
25 25
                 'term_order'=>new EE_Integer_Field('term_order', __('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 = __("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 = __("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(__("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(__("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(__('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(__("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(__("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(__('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   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
         global $wpdb;
77 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 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) {
79
+        if ( ! $new_event_id) {
80 80
             $this->add_error(sprintf(__("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(__("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(__('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.
4_1_0_stages/EE_DMS_4_1_0_question_groups.dmsstage.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -40,119 +40,119 @@
 block discarded – undo
40 40
  */
41 41
 class EE_DMS_4_1_0_question_groups extends EE_Data_Migration_Script_Stage
42 42
 {
43
-    private $_old_table;
44
-    private $_new_table;
45
-    /**
46
-     * Keeps track of whether or not we've already added a system question group,
47
-     * in order to avoid adding more than 1 (basically, in 3.1 this would happen
48
-     * with the Roles & Permissions addon, because each user had their own set of
49
-     * question groups and questions),
50
-     * @var boolean
51
-     */
52
-    private $_already_got_system_question_group_1 = false;
53
-    public function _migration_step($num_items = 50)
54
-    {
43
+	private $_old_table;
44
+	private $_new_table;
45
+	/**
46
+	 * Keeps track of whether or not we've already added a system question group,
47
+	 * in order to avoid adding more than 1 (basically, in 3.1 this would happen
48
+	 * with the Roles & Permissions addon, because each user had their own set of
49
+	 * question groups and questions),
50
+	 * @var boolean
51
+	 */
52
+	private $_already_got_system_question_group_1 = false;
53
+	public function _migration_step($num_items = 50)
54
+	{
55 55
         
56
-        global $wpdb;
57
-        $start_at_record = $this->count_records_migrated();
58
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
59
-        $items_actually_migrated = 0;
60
-        foreach ($rows as $question_group) {
61
-            $new_id = $this->_insert_new_question_group($question_group);
56
+		global $wpdb;
57
+		$start_at_record = $this->count_records_migrated();
58
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
59
+		$items_actually_migrated = 0;
60
+		foreach ($rows as $question_group) {
61
+			$new_id = $this->_insert_new_question_group($question_group);
62 62
 
63
-            $this->get_migration_script()->set_mapping($this->_old_table, $question_group['id'], $this->_new_table, $new_id);
64
-            $items_actually_migrated++;
65
-        }
66
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
67
-            $this->set_completed();
68
-        }
69
-        return $items_actually_migrated;
70
-    }
71
-    public function _count_records_to_migrate()
72
-    {
73
-        global $wpdb;
74
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
75
-        return $count;
76
-    }
77
-    public function __construct()
78
-    {
79
-        global $wpdb;
80
-        $this->_old_table = $wpdb->prefix."events_qst_group";
81
-        $this->_new_table = $wpdb->prefix."esp_question_group";
82
-        $this->_pretty_name = __("Question Groups", "event_espresso");
83
-        parent::__construct();
84
-    }
63
+			$this->get_migration_script()->set_mapping($this->_old_table, $question_group['id'], $this->_new_table, $new_id);
64
+			$items_actually_migrated++;
65
+		}
66
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
67
+			$this->set_completed();
68
+		}
69
+		return $items_actually_migrated;
70
+	}
71
+	public function _count_records_to_migrate()
72
+	{
73
+		global $wpdb;
74
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
75
+		return $count;
76
+	}
77
+	public function __construct()
78
+	{
79
+		global $wpdb;
80
+		$this->_old_table = $wpdb->prefix."events_qst_group";
81
+		$this->_new_table = $wpdb->prefix."esp_question_group";
82
+		$this->_pretty_name = __("Question Groups", "event_espresso");
83
+		parent::__construct();
84
+	}
85 85
     
86
-    /**
87
-     * Attempts to insert a new question group inthe new format given an old one
88
-     * @global type $wpdb
89
-     * @param array $old_question_group
90
-     * @return int
91
-     */
92
-    private function _insert_new_question_group($old_question_group)
93
-    {
94
-        global $wpdb;
95
-        // try to guess what the QST_system int should be... finding the Personal info system
96
-        // question group is quite easy. But in 3.1 address info WASN'T a system group, it just exitsed by default but
97
-        // could be easily removed.
98
-        if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) {
99
-            $guess_at_system_number = 1;
100
-        } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address')!==false) {
101
-            $guess_at_system_number = 2;
102
-        } else {
103
-            $guess_at_system_number = 0;
104
-        }
105
-        // if the question group wasn't made by the normal admin,
106
-        // we'd like to keep track of who made it
107
-        if (intval($old_question_group['wp_user'])!=1) {
108
-            $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user']));
109
-            $identifier = $old_question_group['group_identifier']."-by-".$username;
110
-        } else {
111
-            $identifier = $old_question_group['group_identifier'];
112
-        }
113
-        $cols_n_values = array(
114
-            'QSG_name'=>stripslashes($old_question_group['group_name']),
115
-            'QSG_identifier'=>$identifier,
116
-            'QSG_desc'=>stripslashes($old_question_group['group_description']),
117
-            'QSG_order'=>$old_question_group['group_order'],
118
-            'QSG_show_group_name'=>$old_question_group['show_group_name'],
119
-            'QSG_show_group_desc'=>$old_question_group['show_group_description'],
120
-            'QSG_system'=>$guess_at_system_number,
121
-            'QSG_deleted'=>false
122
-        );
123
-        $datatypes = array(
124
-            '%s',// QSG_name
125
-            '%s',// QSG_identifier
126
-            '%s',// QSG_desc
127
-            '%d',// QSG_order
128
-            '%d',// QSG_show_group_name
129
-            '%d',// QSG_show_group_desc
130
-            '%d',// QSG_system
131
-            '%d',// QSG_deleted
132
-        );
133
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
134
-        if (! $success) {
135
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes));
136
-            return 0;
137
-        }
138
-        return $wpdb->insert_id;
139
-    }
86
+	/**
87
+	 * Attempts to insert a new question group inthe new format given an old one
88
+	 * @global type $wpdb
89
+	 * @param array $old_question_group
90
+	 * @return int
91
+	 */
92
+	private function _insert_new_question_group($old_question_group)
93
+	{
94
+		global $wpdb;
95
+		// try to guess what the QST_system int should be... finding the Personal info system
96
+		// question group is quite easy. But in 3.1 address info WASN'T a system group, it just exitsed by default but
97
+		// could be easily removed.
98
+		if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) {
99
+			$guess_at_system_number = 1;
100
+		} elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address')!==false) {
101
+			$guess_at_system_number = 2;
102
+		} else {
103
+			$guess_at_system_number = 0;
104
+		}
105
+		// if the question group wasn't made by the normal admin,
106
+		// we'd like to keep track of who made it
107
+		if (intval($old_question_group['wp_user'])!=1) {
108
+			$username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user']));
109
+			$identifier = $old_question_group['group_identifier']."-by-".$username;
110
+		} else {
111
+			$identifier = $old_question_group['group_identifier'];
112
+		}
113
+		$cols_n_values = array(
114
+			'QSG_name'=>stripslashes($old_question_group['group_name']),
115
+			'QSG_identifier'=>$identifier,
116
+			'QSG_desc'=>stripslashes($old_question_group['group_description']),
117
+			'QSG_order'=>$old_question_group['group_order'],
118
+			'QSG_show_group_name'=>$old_question_group['show_group_name'],
119
+			'QSG_show_group_desc'=>$old_question_group['show_group_description'],
120
+			'QSG_system'=>$guess_at_system_number,
121
+			'QSG_deleted'=>false
122
+		);
123
+		$datatypes = array(
124
+			'%s',// QSG_name
125
+			'%s',// QSG_identifier
126
+			'%s',// QSG_desc
127
+			'%d',// QSG_order
128
+			'%d',// QSG_show_group_name
129
+			'%d',// QSG_show_group_desc
130
+			'%d',// QSG_system
131
+			'%d',// QSG_deleted
132
+		);
133
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
134
+		if (! $success) {
135
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes));
136
+			return 0;
137
+		}
138
+		return $wpdb->insert_id;
139
+	}
140 140
     
141
-    /**
142
-     * Checks if we've already added a system question 1 to the new question groups table
143
-     * @global type $wpdb
144
-     * @return boolean
145
-     */
146
-    private function _already_got_system_question_group_1()
147
-    {
148
-        if (! $this->_already_got_system_question_group_1) {
149
-            // check the db
150
-            global $wpdb;
151
-            $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1");
152
-            if (intval($exists)>0) {
153
-                $this->_already_got_system_question_group_1 = true;
154
-            }
155
-        }
156
-        return $this->_already_got_system_question_group_1;
157
-    }
141
+	/**
142
+	 * Checks if we've already added a system question 1 to the new question groups table
143
+	 * @global type $wpdb
144
+	 * @return boolean
145
+	 */
146
+	private function _already_got_system_question_group_1()
147
+	{
148
+		if (! $this->_already_got_system_question_group_1) {
149
+			// check the db
150
+			global $wpdb;
151
+			$exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1");
152
+			if (intval($exists)>0) {
153
+				$this->_already_got_system_question_group_1 = true;
154
+			}
155
+		}
156
+		return $this->_already_got_system_question_group_1;
157
+	}
158 158
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
         // could be easily removed.
98 98
         if ($old_question_group['system_group'] && ! $this->_already_got_system_question_group_1()) {
99 99
             $guess_at_system_number = 1;
100
-        } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address')!==false) {
100
+        } elseif ($old_question_group['id'] == '2' && strpos($old_question_group['group_name'], 'Address') !== false) {
101 101
             $guess_at_system_number = 2;
102 102
         } else {
103 103
             $guess_at_system_number = 0;
104 104
         }
105 105
         // if the question group wasn't made by the normal admin,
106 106
         // we'd like to keep track of who made it
107
-        if (intval($old_question_group['wp_user'])!=1) {
107
+        if (intval($old_question_group['wp_user']) != 1) {
108 108
             $username = $wpdb->get_var($wpdb->prepare("SELECT user_nicename FROM ".$wpdb->users." WHERE ID = %d", $old_question_group['wp_user']));
109 109
             $identifier = $old_question_group['group_identifier']."-by-".$username;
110 110
         } else {
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
             'QSG_deleted'=>false
122 122
         );
123 123
         $datatypes = array(
124
-            '%s',// QSG_name
125
-            '%s',// QSG_identifier
126
-            '%s',// QSG_desc
127
-            '%d',// QSG_order
128
-            '%d',// QSG_show_group_name
129
-            '%d',// QSG_show_group_desc
130
-            '%d',// QSG_system
131
-            '%d',// QSG_deleted
124
+            '%s', // QSG_name
125
+            '%s', // QSG_identifier
126
+            '%s', // QSG_desc
127
+            '%d', // QSG_order
128
+            '%d', // QSG_show_group_name
129
+            '%d', // QSG_show_group_desc
130
+            '%d', // QSG_system
131
+            '%d', // QSG_deleted
132 132
         );
133 133
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
134
-        if (! $success) {
134
+        if ( ! $success) {
135 135
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group, $this->_new_table, $cols_n_values, $datatypes));
136 136
             return 0;
137 137
         }
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
      */
146 146
     private function _already_got_system_question_group_1()
147 147
     {
148
-        if (! $this->_already_got_system_question_group_1) {
148
+        if ( ! $this->_already_got_system_question_group_1) {
149 149
             // check the db
150 150
             global $wpdb;
151 151
             $exists = $wpdb->get_var("SELECT COUNT(*) FROM {$this->_new_table} WHERE QSG_system=1");
152
-            if (intval($exists)>0) {
152
+            if (intval($exists) > 0) {
153 153
                 $this->_already_got_system_question_group_1 = true;
154 154
             }
155 155
         }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_shortcodes.dmsstage.php 1 patch
Indentation   +47 added lines, -48 removed lines patch added patch discarded remove patch
@@ -2,58 +2,57 @@
 block discarded – undo
2 2
 
3 3
 /**
4 4
  * Goes through all the posts and pages, and converts old shortcodes to new ones
5
-
6
-*/
5
+ */
7 6
 
8 7
 class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage
9 8
 {
10
-    public function __construct()
11
-    {
12
-        global $wpdb;
13
-        $this->_pretty_name = __("Shortcodes", "event_espresso");
14
-        $this->_old_table = $wpdb->posts;
15
-        parent::__construct();
16
-    }
17
-    protected function _migrate_old_row($old_row)
18
-    {
19
-        $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']);
20
-        global $wpdb;
21
-        $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID']));
22
-    }
9
+	public function __construct()
10
+	{
11
+		global $wpdb;
12
+		$this->_pretty_name = __("Shortcodes", "event_espresso");
13
+		$this->_old_table = $wpdb->posts;
14
+		parent::__construct();
15
+	}
16
+	protected function _migrate_old_row($old_row)
17
+	{
18
+		$new_post_content = $this->_change_event_list_shortcode($old_row['post_content']);
19
+		global $wpdb;
20
+		$wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID']));
21
+	}
23 22
 
24
-    /**
25
-     * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...]
26
-     * @param string $old_content
27
-     */
28
-    private function _change_event_list_shortcode($old_content)
29
-    {
30
-        return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content);
31
-    }
23
+	/**
24
+	 * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...]
25
+	 * @param string $old_content
26
+	 */
27
+	private function _change_event_list_shortcode($old_content)
28
+	{
29
+		return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content);
30
+	}
32 31
 
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 {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
38
-        $items_actually_migrated = 0;
39
-        foreach ($rows as $old_row) {
40
-            $this->_migrate_old_row($old_row);
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.$this->_sql_to_only_select_non_drafts());
52
-        return $count;
53
-    }
32
+	public function _migration_step($num_items = 50)
33
+	{
34
+		global $wpdb;
35
+		$start_at_record = $this->count_records_migrated();
36
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
37
+		$items_actually_migrated = 0;
38
+		foreach ($rows as $old_row) {
39
+			$this->_migrate_old_row($old_row);
40
+			$items_actually_migrated++;
41
+		}
42
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
43
+			$this->set_completed();
44
+		}
45
+		return $items_actually_migrated;
46
+	}
47
+	public function _count_records_to_migrate()
48
+	{
49
+		global $wpdb;
50
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts());
51
+		return $count;
52
+	}
54 53
 
55
-    private function _sql_to_only_select_non_drafts()
56
-    {
57
-        return " WHERE post_type NOT IN ('revision','auto-draft') ";
58
-    }
54
+	private function _sql_to_only_select_non_drafts()
55
+	{
56
+		return " WHERE post_type NOT IN ('revision','auto-draft') ";
57
+	}
59 58
 }
Please login to merge, or discard this patch.
4_8_0_stages/EE_DMS_4_8_0_event_subtotals.dmsstage.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -11,77 +11,77 @@
 block discarded – undo
11 11
  */
12 12
 class EE_DMS_4_8_0_event_subtotals extends EE_Data_Migration_Script_Stage_Table
13 13
 {
14
-    public function __construct()
15
-    {
16
-        global $wpdb;
17
-        $this->_old_table = $wpdb->prefix . 'esp_line_item';
18
-        $this->_extra_where_sql = ' WHERE LIN_type="sub-total" AND LIN_code="pre-tax-subtotal"';
19
-        $this->_pretty_name = __('Event Sub-total line items', 'event_espresso');
20
-        parent::__construct();
21
-    }
22
-    protected function _migrate_old_row($line_item_row)
23
-    {
24
-        global $wpdb;
25
-        // what event is this line item for? this can be found by looking at its transaction's registration's EVT_ID
26
-        $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM ' . $wpdb->prefix . 'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID']));
27
-        $new_line_item_data = array(
28
-                    'LIN_code' => 'event-' . $event_id,
29
-                    'TXN_ID' => $line_item_row['TXN_ID'],
30
-                    'LIN_name' => __('Event', 'event_espresso'),
31
-                    'LIN_desc' => $line_item_row['LIN_desc'],
32
-                    'LIN_unit_price' => $line_item_row['LIN_unit_price'],
33
-                    'LIN_percent' => $line_item_row['LIN_percent'],
34
-                    'LIN_is_taxable' => $line_item_row['LIN_is_taxable'],
35
-                    'LIN_order' => $line_item_row['LIN_order'],
36
-                    'LIN_total' => $line_item_row['LIN_total'],
37
-                    'LIN_quantity' => $line_item_row['LIN_quantity'],
38
-                    'LIN_parent' => $line_item_row['LIN_ID'],
39
-                    'LIN_type' => 'sub-total',
40
-                    'OBJ_type' => 'Event',
41
-                    'OBJ_ID' => $event_id,
42
-                );
43
-        $new_line_item_datatypes = array(
44
-                    '%s',// LIN_code
45
-                    '%d',// TXN_ID
46
-                    '%s',// LIN_name
47
-                    '%s',// LIN_desc
48
-                    '%f',// LIN_unit_price
49
-                    '%f',// LIN_percent
50
-                    '%d',// LIN_is_taxable
51
-                    '%d',// LIN_order
52
-                    '%f',// LIN_total
53
-                    '%d',// LIN_quantity
54
-                    '%d',// LIN_parent
55
-                    '%s',// LIN_type
56
-                    '%s',// OBJ_type
57
-                    '%d',// OBJ_ID
58
-                );
59
-        // insert the new event subtotal line item, pointing to this line item
60
-        $success = $wpdb->insert($this->_old_table, $new_line_item_data, $new_line_item_datatypes);
61
-        if (! $success) {
62
-            $this->add_error($this->_create_error_message_for_db_insertion($this->_old_table, $line_item_row, $this->_old_table, $new_line_item_data, $new_line_item_datatypes));
63
-        }
64
-        $new_line_item_id = $wpdb->insert_id;
65
-        $this->get_migration_script()->set_mapping($this->_old_table, $line_item_row['LIN_ID'], $this->_old_table, $new_line_item_id);
66
-        $query = $wpdb->prepare(
67
-            "UPDATE {$this->_old_table} SET LIN_parent=%d WHERE LIN_parent = %d AND LIN_ID != %d LIMIT 100",
68
-            $new_line_item_id,
69
-            $line_item_row['LIN_ID'],
70
-            $new_line_item_id
71
-        );
72
-        $success = $wpdb->query($query);
73
-        if ($success === false) {
74
-            $this->add_error(
75
-                sprintf(
76
-                    __('Error updating rows to new event subtotal %1$s from %2$s. Error was: %3$s, while using query %4$s which had a result of %5$s', 'event_espresso'),
77
-                    $new_line_item_id,
78
-                    $line_item_row['LIN_ID'],
79
-                    $wpdb->last_error,
80
-                    $query,
81
-                    $success
82
-                )
83
-            );
84
-        }
85
-        return 1;
86
-    }
14
+	public function __construct()
15
+	{
16
+		global $wpdb;
17
+		$this->_old_table = $wpdb->prefix . 'esp_line_item';
18
+		$this->_extra_where_sql = ' WHERE LIN_type="sub-total" AND LIN_code="pre-tax-subtotal"';
19
+		$this->_pretty_name = __('Event Sub-total line items', 'event_espresso');
20
+		parent::__construct();
21
+	}
22
+	protected function _migrate_old_row($line_item_row)
23
+	{
24
+		global $wpdb;
25
+		// what event is this line item for? this can be found by looking at its transaction's registration's EVT_ID
26
+		$event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM ' . $wpdb->prefix . 'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID']));
27
+		$new_line_item_data = array(
28
+					'LIN_code' => 'event-' . $event_id,
29
+					'TXN_ID' => $line_item_row['TXN_ID'],
30
+					'LIN_name' => __('Event', 'event_espresso'),
31
+					'LIN_desc' => $line_item_row['LIN_desc'],
32
+					'LIN_unit_price' => $line_item_row['LIN_unit_price'],
33
+					'LIN_percent' => $line_item_row['LIN_percent'],
34
+					'LIN_is_taxable' => $line_item_row['LIN_is_taxable'],
35
+					'LIN_order' => $line_item_row['LIN_order'],
36
+					'LIN_total' => $line_item_row['LIN_total'],
37
+					'LIN_quantity' => $line_item_row['LIN_quantity'],
38
+					'LIN_parent' => $line_item_row['LIN_ID'],
39
+					'LIN_type' => 'sub-total',
40
+					'OBJ_type' => 'Event',
41
+					'OBJ_ID' => $event_id,
42
+				);
43
+		$new_line_item_datatypes = array(
44
+					'%s',// LIN_code
45
+					'%d',// TXN_ID
46
+					'%s',// LIN_name
47
+					'%s',// LIN_desc
48
+					'%f',// LIN_unit_price
49
+					'%f',// LIN_percent
50
+					'%d',// LIN_is_taxable
51
+					'%d',// LIN_order
52
+					'%f',// LIN_total
53
+					'%d',// LIN_quantity
54
+					'%d',// LIN_parent
55
+					'%s',// LIN_type
56
+					'%s',// OBJ_type
57
+					'%d',// OBJ_ID
58
+				);
59
+		// insert the new event subtotal line item, pointing to this line item
60
+		$success = $wpdb->insert($this->_old_table, $new_line_item_data, $new_line_item_datatypes);
61
+		if (! $success) {
62
+			$this->add_error($this->_create_error_message_for_db_insertion($this->_old_table, $line_item_row, $this->_old_table, $new_line_item_data, $new_line_item_datatypes));
63
+		}
64
+		$new_line_item_id = $wpdb->insert_id;
65
+		$this->get_migration_script()->set_mapping($this->_old_table, $line_item_row['LIN_ID'], $this->_old_table, $new_line_item_id);
66
+		$query = $wpdb->prepare(
67
+			"UPDATE {$this->_old_table} SET LIN_parent=%d WHERE LIN_parent = %d AND LIN_ID != %d LIMIT 100",
68
+			$new_line_item_id,
69
+			$line_item_row['LIN_ID'],
70
+			$new_line_item_id
71
+		);
72
+		$success = $wpdb->query($query);
73
+		if ($success === false) {
74
+			$this->add_error(
75
+				sprintf(
76
+					__('Error updating rows to new event subtotal %1$s from %2$s. Error was: %3$s, while using query %4$s which had a result of %5$s', 'event_espresso'),
77
+					$new_line_item_id,
78
+					$line_item_row['LIN_ID'],
79
+					$wpdb->last_error,
80
+					$query,
81
+					$success
82
+				)
83
+			);
84
+		}
85
+		return 1;
86
+	}
87 87
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     public function __construct()
15 15
     {
16 16
         global $wpdb;
17
-        $this->_old_table = $wpdb->prefix . 'esp_line_item';
17
+        $this->_old_table = $wpdb->prefix.'esp_line_item';
18 18
         $this->_extra_where_sql = ' WHERE LIN_type="sub-total" AND LIN_code="pre-tax-subtotal"';
19 19
         $this->_pretty_name = __('Event Sub-total line items', 'event_espresso');
20 20
         parent::__construct();
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
     {
24 24
         global $wpdb;
25 25
         // what event is this line item for? this can be found by looking at its transaction's registration's EVT_ID
26
-        $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM ' . $wpdb->prefix . 'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID']));
26
+        $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM '.$wpdb->prefix.'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID']));
27 27
         $new_line_item_data = array(
28
-                    'LIN_code' => 'event-' . $event_id,
28
+                    'LIN_code' => 'event-'.$event_id,
29 29
                     'TXN_ID' => $line_item_row['TXN_ID'],
30 30
                     'LIN_name' => __('Event', 'event_espresso'),
31 31
                     'LIN_desc' => $line_item_row['LIN_desc'],
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
                     'OBJ_ID' => $event_id,
42 42
                 );
43 43
         $new_line_item_datatypes = array(
44
-                    '%s',// LIN_code
45
-                    '%d',// TXN_ID
46
-                    '%s',// LIN_name
47
-                    '%s',// LIN_desc
48
-                    '%f',// LIN_unit_price
49
-                    '%f',// LIN_percent
50
-                    '%d',// LIN_is_taxable
51
-                    '%d',// LIN_order
52
-                    '%f',// LIN_total
53
-                    '%d',// LIN_quantity
54
-                    '%d',// LIN_parent
55
-                    '%s',// LIN_type
56
-                    '%s',// OBJ_type
57
-                    '%d',// OBJ_ID
44
+                    '%s', // LIN_code
45
+                    '%d', // TXN_ID
46
+                    '%s', // LIN_name
47
+                    '%s', // LIN_desc
48
+                    '%f', // LIN_unit_price
49
+                    '%f', // LIN_percent
50
+                    '%d', // LIN_is_taxable
51
+                    '%d', // LIN_order
52
+                    '%f', // LIN_total
53
+                    '%d', // LIN_quantity
54
+                    '%d', // LIN_parent
55
+                    '%s', // LIN_type
56
+                    '%s', // OBJ_type
57
+                    '%d', // OBJ_ID
58 58
                 );
59 59
         // insert the new event subtotal line item, pointing to this line item
60 60
         $success = $wpdb->insert($this->_old_table, $new_line_item_data, $new_line_item_datatypes);
61
-        if (! $success) {
61
+        if ( ! $success) {
62 62
             $this->add_error($this->_create_error_message_for_db_insertion($this->_old_table, $line_item_row, $this->_old_table, $new_line_item_data, $new_line_item_datatypes));
63 63
         }
64 64
         $new_line_item_id = $wpdb->insert_id;
Please login to merge, or discard this patch.