Completed
Branch dev (68dcfc)
by
unknown
04:58 queued 02:19
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.
core/data_migration_scripts/EE_Data_Migration_Class_Base.core.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function add_error($error, $force = false)
187 187
     {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
188
+        if ( ! defined('EE_DMS_ERROR_LIMIT')) {
189 189
             $limit = 50;
190 190
         } else {
191 191
             $limit = EE_DMS_ERROR_LIMIT;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                 $this->_errors[] = "Limit reached; removed first half of errors to save space";
202 202
                 $this->_errors[] = $error;
203 203
             } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
204
+                $this->_errors[$limit] = 'More, but limit reached...';
205 205
             }
206 206
         } else {
207 207
             $this->_errors[] = $error;
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
         $new_columns_and_values_for_string = array();
344 344
         $count = 0;
345 345
         foreach ($new_row_as_array as $column => $value) {
346
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
346
+            $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")";
347 347
         }
348 348
         return sprintf(
349 349
             __(
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
         foreach ($array_of_data as $name => $value) {
375 375
             $unserialized_data = @unserialize($value);
376 376
             if ($unserialized_data === false) {
377
-                $fields_to_include[ $name ] = $value;
377
+                $fields_to_include[$name] = $value;
378 378
             }
379 379
         }
380 380
         return wp_json_encode($fields_to_include);
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -17,408 +17,408 @@
 block discarded – undo
17 17
 abstract class EE_Data_Migration_Class_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var $records_to_migrate int count of all that have been migrated
22
-     */
23
-    protected $_records_to_migrate = 0;
24
-
25
-    /**
26
-     *
27
-     * @var $records_migrated int
28
-     */
29
-    protected $_records_migrated = 0;
30
-
31
-    /**
32
-     * Whether this migration script is done or not. This COULD be deduced by
33
-     * _records_to_migrate and _records_migrated, but that might nto be accurate
34
-     *
35
-     * @var string one of EE_Data_migration_Manager::status_* constants
36
-     */
37
-    protected $_status = null;
38
-
39
-    /**
40
-     * internationalized name of this class. Convention is to NOT restate that
41
-     * this class if a migration script or a migration script stage
42
-     *
43
-     * @var string (i18ned)
44
-     */
45
-    protected $_pretty_name = null;
46
-
47
-    /**
48
-     * @var array
49
-     */
50
-    protected $_errors = array();
51
-
52
-    /**
53
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
54
-     */
55
-    protected $_table_manager;
56
-
57
-    /**
58
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
-     */
60
-    protected $_table_analysis;
61
-
62
-
63
-    /**
64
-     * Just initializes the status of the migration
65
-     *
66
-     * @param TableManager  $table_manager
67
-     * @param TableAnalysis $table_analysis
68
-     */
69
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
-    {
71
-        $this->_table_manager = $table_manager;
72
-        $this->_table_analysis = $table_analysis;
73
-        $this->set_status(EE_Data_Migration_Manager::status_continue);
74
-    }
75
-
76
-
77
-    /**
78
-     * Just gets the pretty name for this migration script or stage
79
-     *
80
-     * @throws EE_Error
81
-     * @return string
82
-     */
83
-    public function pretty_name()
84
-    {
85
-        if ($this->_pretty_name === null) {
86
-            throw new EE_Error(
87
-                sprintf(
88
-                    __(
89
-                        "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
-                        "event_espresso"
91
-                    ),
92
-                    get_class($this)
93
-                )
94
-            );
95
-        }
96
-        return $this->_pretty_name;
97
-    }
98
-
99
-    /**
100
-     *
101
-     * @return int
102
-     */
103
-    public function count_records_to_migrate()
104
-    {
105
-        if ($this->_records_to_migrate == null) {
106
-            $this->_records_to_migrate = $this->_count_records_to_migrate();
107
-        }
108
-        return $this->_records_to_migrate;
109
-    }
110
-
111
-    /**
112
-     * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
-     * EE_Data_migration_Script_Stage
114
-     *
115
-     * @return int
116
-     */
117
-    abstract public function count_records_migrated();
118
-
119
-    /**
120
-     * Counts the records to migrate; the public version may cache it
121
-     *
122
-     * @return int
123
-     */
124
-    abstract protected function _count_records_to_migrate();
125
-
126
-    /**
127
-     * Returns a string indicating the migration script's status.
128
-     *
129
-     * @return string one of EE_Data_Migration_Manager::status_* constants
130
-     * @throws EE_Error
131
-     */
132
-    public function get_status()
133
-    {
134
-        if ($this->_status === null) {
135
-            throw new EE_Error(
136
-                sprintf(
137
-                    __(
138
-                        "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
-                        "event_espresso"
140
-                    ),
141
-                    get_class($this)
142
-                )
143
-            );
144
-        }
145
-        return $this->_status;
146
-    }
147
-
148
-    /**
149
-     *
150
-     * @param string $status
151
-     * @return void
152
-     */
153
-    protected function set_status($status)
154
-    {
155
-        $this->_status = $status;
156
-    }
157
-
158
-    /**
159
-     * @return array of strings
160
-     */
161
-    abstract public function get_errors();
162
-
163
-    /**
164
-     * Returns the last error that occurred. If none occurred, returns null
165
-     *
166
-     * @return string
167
-     */
168
-    public function get_last_error()
169
-    {
170
-        $errors = $this->get_errors();
171
-        if ($errors) {
172
-            return end($errors);
173
-        } else {
174
-            return null;
175
-        }
176
-    }
177
-
178
-    /**
179
-     * Adds an error to the array of errors on this class.
180
-     *
181
-     * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
-     *                       the data that led to the error, and a stack trace etc.
183
-     * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
-     *                       already at their limit, we will purposefully forget the first half
185
-     */
186
-    public function add_error($error, $force = false)
187
-    {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
189
-            $limit = 50;
190
-        } else {
191
-            $limit = EE_DMS_ERROR_LIMIT;
192
-        }
193
-        // make sure errors is an array, see ticket #8261
194
-        if (is_string($this->_errors)) {
195
-            $this->_errors = array($this->_errors);
196
-        }
197
-        if (count($this->_errors) >= $limit) {
198
-            if ($force) {
199
-                // get rid of the first half of the errors and any above the limit
200
-                $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
-                $this->_errors[] = "Limit reached; removed first half of errors to save space";
202
-                $this->_errors[] = $error;
203
-            } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
205
-            }
206
-        } else {
207
-            $this->_errors[] = $error;
208
-        }
209
-    }
210
-
211
-    /**
212
-     * Indicates there was a fatal error and the migration cannot possibly continue
213
-     *
214
-     * @return boolean
215
-     */
216
-    public function is_broken()
217
-    {
218
-        return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
-    }
220
-
221
-    /**
222
-     * @deprecated since 4.6.12
223
-     */
224
-    public function is_borked()
225
-    {
226
-        EE_Error::doing_it_wrong(
227
-            'is_borked',
228
-            __(
229
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
-                'event_espresso'
231
-            ),
232
-            '4.6.12'
233
-        );
234
-        return $this->is_broken();
235
-    }
236
-
237
-    /**
238
-     * Sets the status to as having a fatal error
239
-     */
240
-    public function set_broken()
241
-    {
242
-        $this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
-    }
244
-
245
-    /**
246
-     *
247
-     * @deprecated since 4.6.12
248
-     */
249
-    public function set_borked()
250
-    {
251
-        EE_Error::doing_it_wrong(
252
-            'is_borked',
253
-            __(
254
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
-                'event_espresso'
256
-            ),
257
-            '4.6.12'
258
-        );
259
-        return $this->set_broken();
260
-    }
261
-
262
-    /**
263
-     * Checks if this thing believes it is completed
264
-     *
265
-     * @return boolean
266
-     */
267
-    public function is_completed()
268
-    {
269
-        return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
-    }
271
-
272
-    /**
273
-     * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
-     *
275
-     * @return boolean
276
-     */
277
-    public function has_more_to_do()
278
-    {
279
-        return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
-    }
281
-
282
-    /**
283
-     * Marks that we believe this migration thing is completed
284
-     */
285
-    public function set_completed()
286
-    {
287
-        $this->_status = EE_Data_Migration_Manager::status_completed;
288
-    }
289
-
290
-    /**
291
-     * Marks that we think this migration class can continue to migrate
292
-     */
293
-    public function reattempt()
294
-    {
295
-        $this->_status = EE_Data_Migration_Manager::status_continue;
296
-        $this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
-    }
298
-
299
-    /**
300
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
-     * properties to the DB. However, we don't want to use __sleep() because its quite
302
-     * possible that this class is defined when it goes to sleep, but NOT available when it
303
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
304
-     */
305
-    public function properties_as_array()
306
-    {
307
-        $properties = get_object_vars($this);
308
-        $properties['class'] = get_class($this);
309
-        unset($properties['_migration_script']);
310
-        unset($properties['_table_manager']);
311
-        unset($properties['_table_analysis']);
312
-        return $properties;
313
-    }
314
-
315
-    /**
316
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
-     * to have been made from the properties_as_array() function.
318
-     *
319
-     * @param array $array_of_properties like what's produced from properties_as_array() method
320
-     */
321
-    abstract public function instantiate_from_array_of_properties($array_of_properties);
322
-
323
-    /**
324
-     * Convenience method for showing a database insertion error
325
-     *
326
-     * @param string $old_table
327
-     * @param array  $old_row_as_array
328
-     * @param string $new_table
329
-     * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
-     * @param array  $data_types       numerically indexed
331
-     * @return string
332
-     */
333
-    protected function _create_error_message_for_db_insertion(
334
-        $old_table,
335
-        $old_row_as_array,
336
-        $new_table,
337
-        $new_row_as_array,
338
-        $data_types
339
-    ) {
340
-        global $wpdb;
341
-        $old_columns_and_values_for_string = array();
342
-        foreach ($old_row_as_array as $column => $value) {
343
-            $old_columns_and_values_for_string[] = "$column => $value";
344
-        }
345
-        $new_columns_and_values_for_string = array();
346
-        $count = 0;
347
-        foreach ($new_row_as_array as $column => $value) {
348
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
-        }
350
-        return sprintf(
351
-            __(
352
-                'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
-                'event_espresso'
354
-            ),
355
-            implode(", ", $new_columns_and_values_for_string),
356
-            $new_table,
357
-            implode(", ", $old_columns_and_values_for_string),
358
-            $old_table,
359
-            '<br/>',
360
-            $wpdb->last_error
361
-        );
362
-    }
363
-
364
-
365
-    /**
366
-     * Same as json_encode, just avoids putting
367
-     * serialized arrays into the http build query, as that would
368
-     *
369
-     * @param array $array_of_data
370
-     * @return string
371
-     */
372
-    protected function _json_encode($array_of_data)
373
-    {
374
-        // we'd rather NOT serialize the transaction details
375
-        $fields_to_include = array();
376
-        foreach ($array_of_data as $name => $value) {
377
-            $unserialized_data = @unserialize($value);
378
-            if ($unserialized_data === false) {
379
-                $fields_to_include[ $name ] = $value;
380
-            }
381
-        }
382
-        return wp_json_encode($fields_to_include);
383
-    }
384
-
385
-    /**
386
-     * Gets the table manager (or throws an exception if it cannot be retrieved)
387
-     *
388
-     * @return TableManager
389
-     * @throws EE_Error
390
-     */
391
-    protected function _get_table_manager()
392
-    {
393
-        if ($this->_table_manager instanceof TableManager) {
394
-            return $this->_table_manager;
395
-        } else {
396
-            throw new EE_Error(
397
-                sprintf(
398
-                    __('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
-                    get_class($this)
400
-                )
401
-            );
402
-        }
403
-    }
404
-
405
-    /**
406
-     * Gets the injected table analyzer, or throws an exception
407
-     *
408
-     * @return TableAnalysis
409
-     * @throws EE_Error
410
-     */
411
-    protected function _get_table_analysis()
412
-    {
413
-        if ($this->_table_analysis instanceof TableAnalysis) {
414
-            return $this->_table_analysis;
415
-        } else {
416
-            throw new EE_Error(
417
-                sprintf(
418
-                    __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
-                    get_class($this)
420
-                )
421
-            );
422
-        }
423
-    }
20
+	/**
21
+	 * @var $records_to_migrate int count of all that have been migrated
22
+	 */
23
+	protected $_records_to_migrate = 0;
24
+
25
+	/**
26
+	 *
27
+	 * @var $records_migrated int
28
+	 */
29
+	protected $_records_migrated = 0;
30
+
31
+	/**
32
+	 * Whether this migration script is done or not. This COULD be deduced by
33
+	 * _records_to_migrate and _records_migrated, but that might nto be accurate
34
+	 *
35
+	 * @var string one of EE_Data_migration_Manager::status_* constants
36
+	 */
37
+	protected $_status = null;
38
+
39
+	/**
40
+	 * internationalized name of this class. Convention is to NOT restate that
41
+	 * this class if a migration script or a migration script stage
42
+	 *
43
+	 * @var string (i18ned)
44
+	 */
45
+	protected $_pretty_name = null;
46
+
47
+	/**
48
+	 * @var array
49
+	 */
50
+	protected $_errors = array();
51
+
52
+	/**
53
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
54
+	 */
55
+	protected $_table_manager;
56
+
57
+	/**
58
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
59
+	 */
60
+	protected $_table_analysis;
61
+
62
+
63
+	/**
64
+	 * Just initializes the status of the migration
65
+	 *
66
+	 * @param TableManager  $table_manager
67
+	 * @param TableAnalysis $table_analysis
68
+	 */
69
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
70
+	{
71
+		$this->_table_manager = $table_manager;
72
+		$this->_table_analysis = $table_analysis;
73
+		$this->set_status(EE_Data_Migration_Manager::status_continue);
74
+	}
75
+
76
+
77
+	/**
78
+	 * Just gets the pretty name for this migration script or stage
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @return string
82
+	 */
83
+	public function pretty_name()
84
+	{
85
+		if ($this->_pretty_name === null) {
86
+			throw new EE_Error(
87
+				sprintf(
88
+					__(
89
+						"Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
90
+						"event_espresso"
91
+					),
92
+					get_class($this)
93
+				)
94
+			);
95
+		}
96
+		return $this->_pretty_name;
97
+	}
98
+
99
+	/**
100
+	 *
101
+	 * @return int
102
+	 */
103
+	public function count_records_to_migrate()
104
+	{
105
+		if ($this->_records_to_migrate == null) {
106
+			$this->_records_to_migrate = $this->_count_records_to_migrate();
107
+		}
108
+		return $this->_records_to_migrate;
109
+	}
110
+
111
+	/**
112
+	 * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
113
+	 * EE_Data_migration_Script_Stage
114
+	 *
115
+	 * @return int
116
+	 */
117
+	abstract public function count_records_migrated();
118
+
119
+	/**
120
+	 * Counts the records to migrate; the public version may cache it
121
+	 *
122
+	 * @return int
123
+	 */
124
+	abstract protected function _count_records_to_migrate();
125
+
126
+	/**
127
+	 * Returns a string indicating the migration script's status.
128
+	 *
129
+	 * @return string one of EE_Data_Migration_Manager::status_* constants
130
+	 * @throws EE_Error
131
+	 */
132
+	public function get_status()
133
+	{
134
+		if ($this->_status === null) {
135
+			throw new EE_Error(
136
+				sprintf(
137
+					__(
138
+						"Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
139
+						"event_espresso"
140
+					),
141
+					get_class($this)
142
+				)
143
+			);
144
+		}
145
+		return $this->_status;
146
+	}
147
+
148
+	/**
149
+	 *
150
+	 * @param string $status
151
+	 * @return void
152
+	 */
153
+	protected function set_status($status)
154
+	{
155
+		$this->_status = $status;
156
+	}
157
+
158
+	/**
159
+	 * @return array of strings
160
+	 */
161
+	abstract public function get_errors();
162
+
163
+	/**
164
+	 * Returns the last error that occurred. If none occurred, returns null
165
+	 *
166
+	 * @return string
167
+	 */
168
+	public function get_last_error()
169
+	{
170
+		$errors = $this->get_errors();
171
+		if ($errors) {
172
+			return end($errors);
173
+		} else {
174
+			return null;
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * Adds an error to the array of errors on this class.
180
+	 *
181
+	 * @param string  $error a string describing the error that will be useful for debugging. Consider including all
182
+	 *                       the data that led to the error, and a stack trace etc.
183
+	 * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
184
+	 *                       already at their limit, we will purposefully forget the first half
185
+	 */
186
+	public function add_error($error, $force = false)
187
+	{
188
+		if (! defined('EE_DMS_ERROR_LIMIT')) {
189
+			$limit = 50;
190
+		} else {
191
+			$limit = EE_DMS_ERROR_LIMIT;
192
+		}
193
+		// make sure errors is an array, see ticket #8261
194
+		if (is_string($this->_errors)) {
195
+			$this->_errors = array($this->_errors);
196
+		}
197
+		if (count($this->_errors) >= $limit) {
198
+			if ($force) {
199
+				// get rid of the first half of the errors and any above the limit
200
+				$this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
201
+				$this->_errors[] = "Limit reached; removed first half of errors to save space";
202
+				$this->_errors[] = $error;
203
+			} else {
204
+				$this->_errors[ $limit ] = 'More, but limit reached...';
205
+			}
206
+		} else {
207
+			$this->_errors[] = $error;
208
+		}
209
+	}
210
+
211
+	/**
212
+	 * Indicates there was a fatal error and the migration cannot possibly continue
213
+	 *
214
+	 * @return boolean
215
+	 */
216
+	public function is_broken()
217
+	{
218
+		return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
219
+	}
220
+
221
+	/**
222
+	 * @deprecated since 4.6.12
223
+	 */
224
+	public function is_borked()
225
+	{
226
+		EE_Error::doing_it_wrong(
227
+			'is_borked',
228
+			__(
229
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
230
+				'event_espresso'
231
+			),
232
+			'4.6.12'
233
+		);
234
+		return $this->is_broken();
235
+	}
236
+
237
+	/**
238
+	 * Sets the status to as having a fatal error
239
+	 */
240
+	public function set_broken()
241
+	{
242
+		$this->_status = EE_Data_Migration_Manager::status_fatal_error;
243
+	}
244
+
245
+	/**
246
+	 *
247
+	 * @deprecated since 4.6.12
248
+	 */
249
+	public function set_borked()
250
+	{
251
+		EE_Error::doing_it_wrong(
252
+			'is_borked',
253
+			__(
254
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
255
+				'event_espresso'
256
+			),
257
+			'4.6.12'
258
+		);
259
+		return $this->set_broken();
260
+	}
261
+
262
+	/**
263
+	 * Checks if this thing believes it is completed
264
+	 *
265
+	 * @return boolean
266
+	 */
267
+	public function is_completed()
268
+	{
269
+		return $this->get_status() == EE_Data_Migration_Manager::status_completed;
270
+	}
271
+
272
+	/**
273
+	 * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
274
+	 *
275
+	 * @return boolean
276
+	 */
277
+	public function has_more_to_do()
278
+	{
279
+		return $this->get_status() == EE_Data_Migration_Manager::status_continue;
280
+	}
281
+
282
+	/**
283
+	 * Marks that we believe this migration thing is completed
284
+	 */
285
+	public function set_completed()
286
+	{
287
+		$this->_status = EE_Data_Migration_Manager::status_completed;
288
+	}
289
+
290
+	/**
291
+	 * Marks that we think this migration class can continue to migrate
292
+	 */
293
+	public function reattempt()
294
+	{
295
+		$this->_status = EE_Data_Migration_Manager::status_continue;
296
+		$this->add_error(__('Reattempt migration', 'event_espresso'), true);
297
+	}
298
+
299
+	/**
300
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
301
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
302
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
303
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
304
+	 */
305
+	public function properties_as_array()
306
+	{
307
+		$properties = get_object_vars($this);
308
+		$properties['class'] = get_class($this);
309
+		unset($properties['_migration_script']);
310
+		unset($properties['_table_manager']);
311
+		unset($properties['_table_analysis']);
312
+		return $properties;
313
+	}
314
+
315
+	/**
316
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
317
+	 * to have been made from the properties_as_array() function.
318
+	 *
319
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
320
+	 */
321
+	abstract public function instantiate_from_array_of_properties($array_of_properties);
322
+
323
+	/**
324
+	 * Convenience method for showing a database insertion error
325
+	 *
326
+	 * @param string $old_table
327
+	 * @param array  $old_row_as_array
328
+	 * @param string $new_table
329
+	 * @param array  $new_row_as_array columns=>values like used in wpdb->insert
330
+	 * @param array  $data_types       numerically indexed
331
+	 * @return string
332
+	 */
333
+	protected function _create_error_message_for_db_insertion(
334
+		$old_table,
335
+		$old_row_as_array,
336
+		$new_table,
337
+		$new_row_as_array,
338
+		$data_types
339
+	) {
340
+		global $wpdb;
341
+		$old_columns_and_values_for_string = array();
342
+		foreach ($old_row_as_array as $column => $value) {
343
+			$old_columns_and_values_for_string[] = "$column => $value";
344
+		}
345
+		$new_columns_and_values_for_string = array();
346
+		$count = 0;
347
+		foreach ($new_row_as_array as $column => $value) {
348
+			$new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
349
+		}
350
+		return sprintf(
351
+			__(
352
+				'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
353
+				'event_espresso'
354
+			),
355
+			implode(", ", $new_columns_and_values_for_string),
356
+			$new_table,
357
+			implode(", ", $old_columns_and_values_for_string),
358
+			$old_table,
359
+			'<br/>',
360
+			$wpdb->last_error
361
+		);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Same as json_encode, just avoids putting
367
+	 * serialized arrays into the http build query, as that would
368
+	 *
369
+	 * @param array $array_of_data
370
+	 * @return string
371
+	 */
372
+	protected function _json_encode($array_of_data)
373
+	{
374
+		// we'd rather NOT serialize the transaction details
375
+		$fields_to_include = array();
376
+		foreach ($array_of_data as $name => $value) {
377
+			$unserialized_data = @unserialize($value);
378
+			if ($unserialized_data === false) {
379
+				$fields_to_include[ $name ] = $value;
380
+			}
381
+		}
382
+		return wp_json_encode($fields_to_include);
383
+	}
384
+
385
+	/**
386
+	 * Gets the table manager (or throws an exception if it cannot be retrieved)
387
+	 *
388
+	 * @return TableManager
389
+	 * @throws EE_Error
390
+	 */
391
+	protected function _get_table_manager()
392
+	{
393
+		if ($this->_table_manager instanceof TableManager) {
394
+			return $this->_table_manager;
395
+		} else {
396
+			throw new EE_Error(
397
+				sprintf(
398
+					__('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
399
+					get_class($this)
400
+				)
401
+			);
402
+		}
403
+	}
404
+
405
+	/**
406
+	 * Gets the injected table analyzer, or throws an exception
407
+	 *
408
+	 * @return TableAnalysis
409
+	 * @throws EE_Error
410
+	 */
411
+	protected function _get_table_analysis()
412
+	{
413
+		if ($this->_table_analysis instanceof TableAnalysis) {
414
+			return $this->_table_analysis;
415
+		} else {
416
+			throw new EE_Error(
417
+				sprintf(
418
+					__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
419
+					get_class($this)
420
+				)
421
+			);
422
+		}
423
+	}
424 424
 }
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.
4_2_0_stages/EE_DMS_4_2_0_datetime_fields.dmsstage.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -8,49 +8,49 @@
 block discarded – undo
8 8
 
9 9
 class EE_DMS_4_2_0_datetime_fields extends EE_Data_Migration_Script_Stage_Table
10 10
 {
11
-    public function __construct()
12
-    {
13
-        global $wpdb;
14
-        $this->_pretty_name = __("Datetime Fields", "event_espresso");
15
-        $this->_old_table = $wpdb->prefix . "esp_datetime";
16
-        parent::__construct();
17
-    }
11
+	public function __construct()
12
+	{
13
+		global $wpdb;
14
+		$this->_pretty_name = __("Datetime Fields", "event_espresso");
15
+		$this->_old_table = $wpdb->prefix . "esp_datetime";
16
+		parent::__construct();
17
+	}
18 18
 
19
-    protected function _migrate_old_row($old_row)
20
-    {
21
-        // foreach question_group_question entry with this QST_ID, we want to set its
22
-        // QSG_order equal to this question's QST_order
23
-        global $wpdb;
19
+	protected function _migrate_old_row($old_row)
20
+	{
21
+		// foreach question_group_question entry with this QST_ID, we want to set its
22
+		// QSG_order equal to this question's QST_order
23
+		global $wpdb;
24 24
 
25
-        $updated = $wpdb->update(
26
-            $this->_old_table,
27
-            array(
28
-                'DTT_name' => '',
29
-                'DTT_description' => '',
30
-            ),
31
-            array(
32
-                'DTT_ID' => $old_row['DTT_ID'],
33
-            ),
34
-            array(
35
-                '%s',// DTT_name,
36
-                '%s',// DTT_description
37
-            ),
38
-            array(
39
-                '%d',// DTT_ID
40
-            )
41
-        );
42
-        if (false === $updated) {
43
-            $this->add_error(
44
-                sprintf(
45
-                    __(
46
-                        "Error in updating table %s setting DTT_name = '' and DTT_description = '' where DTT_ID = %d",
47
-                        'event_espresso'
48
-                    ),
49
-                    $this->_old_table,
50
-                    $old_row['QST_ID']
51
-                )
52
-            );
53
-        }
54
-        // nothing to map really
55
-    }
25
+		$updated = $wpdb->update(
26
+			$this->_old_table,
27
+			array(
28
+				'DTT_name' => '',
29
+				'DTT_description' => '',
30
+			),
31
+			array(
32
+				'DTT_ID' => $old_row['DTT_ID'],
33
+			),
34
+			array(
35
+				'%s',// DTT_name,
36
+				'%s',// DTT_description
37
+			),
38
+			array(
39
+				'%d',// DTT_ID
40
+			)
41
+		);
42
+		if (false === $updated) {
43
+			$this->add_error(
44
+				sprintf(
45
+					__(
46
+						"Error in updating table %s setting DTT_name = '' and DTT_description = '' where DTT_ID = %d",
47
+						'event_espresso'
48
+					),
49
+					$this->_old_table,
50
+					$old_row['QST_ID']
51
+				)
52
+			);
53
+		}
54
+		// nothing to map really
55
+	}
56 56
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     {
13 13
         global $wpdb;
14 14
         $this->_pretty_name = __("Datetime Fields", "event_espresso");
15
-        $this->_old_table = $wpdb->prefix . "esp_datetime";
15
+        $this->_old_table = $wpdb->prefix."esp_datetime";
16 16
         parent::__construct();
17 17
     }
18 18
 
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
                 'DTT_ID' => $old_row['DTT_ID'],
33 33
             ),
34 34
             array(
35
-                '%s',// DTT_name,
36
-                '%s',// DTT_description
35
+                '%s', // DTT_name,
36
+                '%s', // DTT_description
37 37
             ),
38 38
             array(
39
-                '%d',// DTT_ID
39
+                '%d', // DTT_ID
40 40
             )
41 41
         );
42 42
         if (false === $updated) {
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Script_Stage.core.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -37,103 +37,103 @@
 block discarded – undo
37 37
  */
38 38
 abstract class EE_Data_Migration_Script_Stage extends EE_Data_Migration_Class_Base
39 39
 {
40
-    /**
41
-     * The migration script this is a stage of
42
-     *
43
-     * @var EE_Data_Migration_Script_Base
44
-     */
45
-    protected $_migration_script;
40
+	/**
41
+	 * The migration script this is a stage of
42
+	 *
43
+	 * @var EE_Data_Migration_Script_Base
44
+	 */
45
+	protected $_migration_script;
46 46
 
47
-    /**
48
-     * This should eb called to essentially 'finalize' construction of the stage.
49
-     * This isn't done on the main constructor in order to avoid repetitive code. Instead, this is
50
-     * called by EE_Data_Migration_Script_Base's __construct() method so children don't have to
51
-     *
52
-     * @param EE_Data_Migration_Script_Base $migration_script
53
-     */
54
-    public function _construct_finalize($migration_script)
55
-    {
56
-        $this->_migration_script = $migration_script;
57
-    }
47
+	/**
48
+	 * This should eb called to essentially 'finalize' construction of the stage.
49
+	 * This isn't done on the main constructor in order to avoid repetitive code. Instead, this is
50
+	 * called by EE_Data_Migration_Script_Base's __construct() method so children don't have to
51
+	 *
52
+	 * @param EE_Data_Migration_Script_Base $migration_script
53
+	 */
54
+	public function _construct_finalize($migration_script)
55
+	{
56
+		$this->_migration_script = $migration_script;
57
+	}
58 58
 
59
-    /**
60
-     * Migrates X old records to the new format. If a fatal error is encountered it is NOT caught here,
61
-     * but is propagated upwards for catching. So basically, the _migration_step() function implemented by children
62
-     * needs to catch exceptions and decide what's a fatal error and what isn't.
63
-     *
64
-     * @param int $num_items_to_migrate
65
-     * @return int
66
-     */
67
-    public function migration_step($num_items_to_migrate = 50)
68
-    {
69
-        // before we run the migration step, we want ot take note of warnings that get outputted
70
-        ob_start();
71
-        $items_migrated = $this->_migration_step($num_items_to_migrate);
72
-        $output = ob_get_contents();
73
-        ob_end_clean();
74
-        if ($output) {
75
-            $this->add_error($output);
76
-        }
77
-        $this->_records_migrated += $items_migrated;
78
-        return $items_migrated;
79
-    }
59
+	/**
60
+	 * Migrates X old records to the new format. If a fatal error is encountered it is NOT caught here,
61
+	 * but is propagated upwards for catching. So basically, the _migration_step() function implemented by children
62
+	 * needs to catch exceptions and decide what's a fatal error and what isn't.
63
+	 *
64
+	 * @param int $num_items_to_migrate
65
+	 * @return int
66
+	 */
67
+	public function migration_step($num_items_to_migrate = 50)
68
+	{
69
+		// before we run the migration step, we want ot take note of warnings that get outputted
70
+		ob_start();
71
+		$items_migrated = $this->_migration_step($num_items_to_migrate);
72
+		$output = ob_get_contents();
73
+		ob_end_clean();
74
+		if ($output) {
75
+			$this->add_error($output);
76
+		}
77
+		$this->_records_migrated += $items_migrated;
78
+		return $items_migrated;
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property
84
-     * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that
85
-     * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the
86
-     * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees
87
-     * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at
88
-     * very least we MUST report/return 50 items migrated)
89
-     *
90
-     * @param int $num_items_to_migrate
91
-     * @return int number of items ACTUALLY migrated
92
-     */
93
-    abstract protected function _migration_step($num_items_to_migrate = 50);
82
+	/**
83
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property
84
+	 * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that
85
+	 * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the
86
+	 * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees
87
+	 * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at
88
+	 * very least we MUST report/return 50 items migrated)
89
+	 *
90
+	 * @param int $num_items_to_migrate
91
+	 * @return int number of items ACTUALLY migrated
92
+	 */
93
+	abstract protected function _migration_step($num_items_to_migrate = 50);
94 94
 
95
-    /**
96
-     * Counts the records that have been migrated so far
97
-     *
98
-     * @return int
99
-     */
100
-    public function count_records_migrated()
101
-    {
102
-        return $this->_records_migrated;
103
-    }
95
+	/**
96
+	 * Counts the records that have been migrated so far
97
+	 *
98
+	 * @return int
99
+	 */
100
+	public function count_records_migrated()
101
+	{
102
+		return $this->_records_migrated;
103
+	}
104 104
 
105
-    /**
106
-     * returns an array of strings describing errors
107
-     *
108
-     * @return array
109
-     */
110
-    public function get_errors()
111
-    {
112
-        return $this->_errors;
113
-    }
105
+	/**
106
+	 * returns an array of strings describing errors
107
+	 *
108
+	 * @return array
109
+	 */
110
+	public function get_errors()
111
+	{
112
+		return $this->_errors;
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
118
-     * to have been made from the properties_as_array() function.
119
-     *
120
-     * @param array $array_of_properties like what's produced from properties_as_array() method
121
-     */
122
-    public function instantiate_from_array_of_properties($array_of_properties)
123
-    {
124
-        unset($array_of_properties['class']);
125
-        foreach ($array_of_properties as $property_name => $property_value) {
126
-            $this->{$property_name} = $property_value;
127
-        }
128
-    }
116
+	/**
117
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
118
+	 * to have been made from the properties_as_array() function.
119
+	 *
120
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
121
+	 */
122
+	public function instantiate_from_array_of_properties($array_of_properties)
123
+	{
124
+		unset($array_of_properties['class']);
125
+		foreach ($array_of_properties as $property_name => $property_value) {
126
+			$this->{$property_name} = $property_value;
127
+		}
128
+	}
129 129
 
130
-    /**
131
-     * Gets the script this is a stage of
132
-     *
133
-     * @return EE_Data_Migration_Script_Base
134
-     */
135
-    protected function get_migration_script()
136
-    {
137
-        return $this->_migration_script;
138
-    }
130
+	/**
131
+	 * Gets the script this is a stage of
132
+	 *
133
+	 * @return EE_Data_Migration_Script_Base
134
+	 */
135
+	protected function get_migration_script()
136
+	{
137
+		return $this->_migration_script;
138
+	}
139 139
 }
Please login to merge, or discard this patch.
core/EE_Object_Repository.core.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -16,98 +16,98 @@
 block discarded – undo
16 16
 abstract class EE_Object_Repository extends EE_Object_Collection implements EEI_Repository
17 17
 {
18 18
 
19
-    /**
20
-     * default persist method called on repository objects if none supplied
21
-     *
22
-     * @type string $persist_method
23
-     */
24
-    protected $persist_method;
19
+	/**
20
+	 * default persist method called on repository objects if none supplied
21
+	 *
22
+	 * @type string $persist_method
23
+	 */
24
+	protected $persist_method;
25 25
 
26 26
 
27
-    /**
28
-     * _call_user_func_array_on_current
29
-     *
30
-     * calls the supplied callback method name on the current repository object,
31
-     * an array of arguments can also be supplied that will be passed along to the callback method,
32
-     * where each element of the $arguments array corresponds to a parameter for the callback method
33
-     * PLZ NOTE: if the first argument of the callback requires an array, for example array( 'key' => 'value' )
34
-     * then $arguments needs to be a DOUBLE array ie: array( array( 'key' => 'value' ) )
35
-     *
36
-     * @access public
37
-     * @param string $callback  name of method found on object to be called.
38
-     * @param array  $arguments arrays of arguments that will be passed to the object's callback method
39
-     * @return bool | int
40
-     */
41
-    protected function _call_user_func_array_on_current($callback = '', $arguments = array())
42
-    {
43
-        if ($callback !== '' && method_exists($this->current(), $callback)) {
44
-            return call_user_func_array(array($this->current(), $callback), $arguments);
45
-        }
46
-        return false;
47
-    }
27
+	/**
28
+	 * _call_user_func_array_on_current
29
+	 *
30
+	 * calls the supplied callback method name on the current repository object,
31
+	 * an array of arguments can also be supplied that will be passed along to the callback method,
32
+	 * where each element of the $arguments array corresponds to a parameter for the callback method
33
+	 * PLZ NOTE: if the first argument of the callback requires an array, for example array( 'key' => 'value' )
34
+	 * then $arguments needs to be a DOUBLE array ie: array( array( 'key' => 'value' ) )
35
+	 *
36
+	 * @access public
37
+	 * @param string $callback  name of method found on object to be called.
38
+	 * @param array  $arguments arrays of arguments that will be passed to the object's callback method
39
+	 * @return bool | int
40
+	 */
41
+	protected function _call_user_func_array_on_current($callback = '', $arguments = array())
42
+	{
43
+		if ($callback !== '' && method_exists($this->current(), $callback)) {
44
+			return call_user_func_array(array($this->current(), $callback), $arguments);
45
+		}
46
+		return false;
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * _call_user_func_on_all
52
-     *
53
-     * calls the supplied callback method name on ALL repository objects,
54
-     *
55
-     * @access public
56
-     * @param string $callback name of method found on repository objects to be called
57
-     * @return bool | int
58
-     */
59
-    protected function _call_user_func_on_all($callback = '')
60
-    {
61
-        $success = true;
62
-        if ($this->valid()) {
63
-            $this->rewind();
64
-            while ($this->valid()) {
65
-                // any negative result will toggle success to false
66
-                $success = $this->_call_user_func_array_on_current($callback) ? $success : false;
67
-                $this->next();
68
-            }
69
-            $this->rewind();
70
-        }
71
-        return $success;
72
-    }
50
+	/**
51
+	 * _call_user_func_on_all
52
+	 *
53
+	 * calls the supplied callback method name on ALL repository objects,
54
+	 *
55
+	 * @access public
56
+	 * @param string $callback name of method found on repository objects to be called
57
+	 * @return bool | int
58
+	 */
59
+	protected function _call_user_func_on_all($callback = '')
60
+	{
61
+		$success = true;
62
+		if ($this->valid()) {
63
+			$this->rewind();
64
+			while ($this->valid()) {
65
+				// any negative result will toggle success to false
66
+				$success = $this->_call_user_func_array_on_current($callback) ? $success : false;
67
+				$this->next();
68
+			}
69
+			$this->rewind();
70
+		}
71
+		return $success;
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * persist
77
-     *
78
-     * primarily used for saving EE_Base_Class classes to the database,
79
-     * but can be supplied with a "persistence callback" that can be used for classes that are not instances of
80
-     * EE_Base_Class, or for providing alternate ways to persist an object such as session caching, etc... an array of
81
-     * arguments can also be supplied that will be passed along to the object's persistence method
82
-     *
83
-     * @access public
84
-     * @param string $persistence_callback                                    name of method found on object that can
85
-     *                                                                        be used for persisting the object
86
-     *                                                                        defaults to
87
-     *                                                                        EE_Object_Repository::$persist_method
88
-     * @param array  $persistence_arguments                                   arrays of arguments that will be passed
89
-     *                                                                        to the object's persistence method
90
-     * @return bool | int
91
-     */
92
-    public function persist($persistence_callback = '', $persistence_arguments = array())
93
-    {
94
-        $persistence_callback = ! empty($persistence_callback) ? $persistence_callback : $this->persist_method;
95
-        return $this->_call_user_func_array_on_current($persistence_callback, $persistence_arguments);
96
-    }
75
+	/**
76
+	 * persist
77
+	 *
78
+	 * primarily used for saving EE_Base_Class classes to the database,
79
+	 * but can be supplied with a "persistence callback" that can be used for classes that are not instances of
80
+	 * EE_Base_Class, or for providing alternate ways to persist an object such as session caching, etc... an array of
81
+	 * arguments can also be supplied that will be passed along to the object's persistence method
82
+	 *
83
+	 * @access public
84
+	 * @param string $persistence_callback                                    name of method found on object that can
85
+	 *                                                                        be used for persisting the object
86
+	 *                                                                        defaults to
87
+	 *                                                                        EE_Object_Repository::$persist_method
88
+	 * @param array  $persistence_arguments                                   arrays of arguments that will be passed
89
+	 *                                                                        to the object's persistence method
90
+	 * @return bool | int
91
+	 */
92
+	public function persist($persistence_callback = '', $persistence_arguments = array())
93
+	{
94
+		$persistence_callback = ! empty($persistence_callback) ? $persistence_callback : $this->persist_method;
95
+		return $this->_call_user_func_array_on_current($persistence_callback, $persistence_arguments);
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * persist_all
101
-     *
102
-     * calls \EE_Object_Repository::persist() on all objects within the repository
103
-     *
104
-     * @access public
105
-     * @param string $persistence_callback name of method found on object that can be used for persisting the object
106
-     * @return bool | int
107
-     */
108
-    public function persist_all($persistence_callback = '')
109
-    {
110
-        $persistence_callback = ! empty($persistence_callback) ? $persistence_callback : $this->persist_method;
111
-        return $this->_call_user_func_on_all($persistence_callback);
112
-    }
99
+	/**
100
+	 * persist_all
101
+	 *
102
+	 * calls \EE_Object_Repository::persist() on all objects within the repository
103
+	 *
104
+	 * @access public
105
+	 * @param string $persistence_callback name of method found on object that can be used for persisting the object
106
+	 * @return bool | int
107
+	 */
108
+	public function persist_all($persistence_callback = '')
109
+	{
110
+		$persistence_callback = ! empty($persistence_callback) ? $persistence_callback : $this->persist_method;
111
+		return $this->_call_user_func_on_all($persistence_callback);
112
+	}
113 113
 }
Please login to merge, or discard this patch.
core/EE_Request_Handler.core.php 2 patches
Indentation   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -12,369 +12,369 @@
 block discarded – undo
12 12
 final class EE_Request_Handler implements InterminableInterface
13 13
 {
14 14
 
15
-    /**
16
-     * @var EE_Request $request
17
-     */
18
-    private $request;
19
-
20
-    /**
21
-     * @var array $_notice
22
-     */
23
-    private $_notice = array();
24
-
25
-    /**
26
-     * rendered output to be returned to WP
27
-     *
28
-     * @var string $_output
29
-     */
30
-    private $_output = '';
31
-
32
-    /**
33
-     * whether current request is via AJAX
34
-     *
35
-     * @var boolean $ajax
36
-     */
37
-    public $ajax = false;
38
-
39
-    /**
40
-     * whether current request is via AJAX from the frontend of the site
41
-     *
42
-     * @var boolean $front_ajax
43
-     */
44
-    public $front_ajax = false;
45
-
46
-
47
-    /**
48
-     * @param  EE_Request $request
49
-     */
50
-    public function __construct(EE_Request $request)
51
-    {
52
-        $this->request = $request;
53
-        $this->ajax = $this->request->ajax;
54
-        $this->front_ajax = $this->request->front_ajax;
55
-        do_action('AHEE__EE_Request_Handler__construct__complete');
56
-    }
57
-
58
-
59
-    /**
60
-     * @param WP $wp
61
-     * @return void
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public function parse_request($wp = null)
66
-    {
67
-        // if somebody forgot to provide us with WP, that's ok because its global
68
-        if (! $wp instanceof WP) {
69
-            global $wp;
70
-        }
71
-        $this->set_request_vars($wp);
72
-    }
73
-
74
-
75
-    /**
76
-     * @param WP $wp
77
-     * @return void
78
-     * @throws EE_Error
79
-     * @throws ReflectionException
80
-     */
81
-    public function set_request_vars($wp = null)
82
-    {
83
-        if (! is_admin()) {
84
-            // set request post_id
85
-            $this->request->set('post_id', $this->get_post_id_from_request($wp));
86
-            // set request post name
87
-            $this->request->set('post_name', $this->get_post_name_from_request($wp));
88
-            // set request post_type
89
-            $this->request->set('post_type', $this->get_post_type_from_request($wp));
90
-            // true or false ? is this page being used by EE ?
91
-            $this->set_espresso_page();
92
-        }
93
-    }
94
-
95
-
96
-    /**
97
-     * @param WP $wp
98
-     * @return int
99
-     */
100
-    public function get_post_id_from_request($wp = null)
101
-    {
102
-        if (! $wp instanceof WP) {
103
-            global $wp;
104
-        }
105
-        $post_id = null;
106
-        if (isset($wp->query_vars['p'])) {
107
-            $post_id = $wp->query_vars['p'];
108
-        }
109
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
110
-            $post_id = $wp->query_vars['page_id'];
111
-        }
112
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
113
-            $post_id = basename($wp->request);
114
-        }
115
-        return $post_id;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param WP $wp
121
-     * @return string
122
-     */
123
-    public function get_post_name_from_request($wp = null)
124
-    {
125
-        if (! $wp instanceof WP) {
126
-            global $wp;
127
-        }
128
-        $post_name = null;
129
-        if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
130
-            $post_name = $wp->query_vars['name'];
131
-        }
132
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
133
-            $post_name = $wp->query_vars['pagename'];
134
-        }
135
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
136
-            $possible_post_name = basename($wp->request);
137
-            if (! is_numeric($possible_post_name)) {
138
-                /** @type WPDB $wpdb */
139
-                global $wpdb;
140
-                $SQL =
141
-                    "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
142
-                $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
143
-                if ($possible_post_name) {
144
-                    $post_name = $possible_post_name;
145
-                }
146
-            }
147
-        }
148
-        if (! $post_name && $this->get('post_id')) {
149
-            /** @type WPDB $wpdb */
150
-            global $wpdb;
151
-            $SQL =
152
-                "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
153
-            $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
154
-            if ($possible_post_name) {
155
-                $post_name = $possible_post_name;
156
-            }
157
-        }
158
-        return $post_name;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param WP $wp
164
-     * @return mixed
165
-     */
166
-    public function get_post_type_from_request($wp = null)
167
-    {
168
-        if (! $wp instanceof WP) {
169
-            global $wp;
170
-        }
171
-        return isset($wp->query_vars['post_type'])
172
-            ? $wp->query_vars['post_type']
173
-            : null;
174
-    }
175
-
176
-
177
-    /**
178
-     * Just a helper method for getting the url for the displayed page.
179
-     *
180
-     * @param  WP $wp
181
-     * @return string
182
-     */
183
-    public function get_current_page_permalink($wp = null)
184
-    {
185
-        $post_id = $this->get_post_id_from_request($wp);
186
-        if ($post_id) {
187
-            $current_page_permalink = get_permalink($post_id);
188
-        } else {
189
-            if (! $wp instanceof WP) {
190
-                global $wp;
191
-            }
192
-            if ($wp->request) {
193
-                $current_page_permalink = site_url($wp->request);
194
-            } else {
195
-                $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
196
-            }
197
-        }
198
-        return $current_page_permalink;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return bool
204
-     * @throws EE_Error
205
-     * @throws ReflectionException
206
-     */
207
-    public function test_for_espresso_page()
208
-    {
209
-        global $wp;
210
-        /** @type EE_CPT_Strategy $EE_CPT_Strategy */
211
-        $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
212
-        $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
213
-        if (is_array($espresso_CPT_taxonomies)) {
214
-            foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
215
-                if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) {
216
-                    return true;
217
-                }
218
-            }
219
-        }
220
-        // load espresso CPT endpoints
221
-        $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
222
-        $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
223
-        $post_types = (array) $this->get('post_type');
224
-        foreach ($post_types as $post_type) {
225
-            // was a post name passed ?
226
-            if (isset($post_type_CPT_endpoints[ $post_type ])) {
227
-                // kk we know this is an espresso page, but is it a specific post ?
228
-                if (! $this->get('post_name')) {
229
-                    // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
230
-                    $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ])
231
-                        ? $post_type_CPT_endpoints[ $this->get('post_type') ]
232
-                        : '';
233
-                    // if the post type matches on of our then set the endpoint
234
-                    if ($post_name) {
235
-                        $this->set('post_name', $post_name);
236
-                    }
237
-                }
238
-                return true;
239
-            }
240
-        }
241
-        return false;
242
-    }
243
-
244
-    /**
245
-     * @param $key
246
-     * @param $value
247
-     * @return    void
248
-     */
249
-    public function set_notice($key, $value)
250
-    {
251
-        $this->_notice[ $key ] = $value;
252
-    }
253
-
254
-
255
-    /**
256
-     * @param $key
257
-     * @return    mixed
258
-     */
259
-    public function get_notice($key)
260
-    {
261
-        return isset($this->_notice[ $key ])
262
-            ? $this->_notice[ $key ]
263
-            : null;
264
-    }
265
-
266
-
267
-    /**
268
-     * @param $string
269
-     * @return void
270
-     */
271
-    public function add_output($string)
272
-    {
273
-        $this->_output .= $string;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return string
279
-     */
280
-    public function get_output()
281
-    {
282
-        return $this->_output;
283
-    }
284
-
285
-
286
-    /**
287
-     * @param $item
288
-     * @param $key
289
-     */
290
-    public function sanitize_text_field_for_array_walk(&$item, &$key)
291
-    {
292
-        $item = strpos($item, 'email') !== false
293
-            ? sanitize_email($item)
294
-            : sanitize_text_field($item);
295
-    }
296
-
297
-
298
-    /**
299
-     * @param null|bool $value
300
-     * @return void
301
-     * @throws EE_Error
302
-     * @throws ReflectionException
303
-     */
304
-    public function set_espresso_page($value = null)
305
-    {
306
-        $this->request->set(
307
-            'is_espresso_page',
308
-            ! empty($value)
309
-                ? $value
310
-                : $this->test_for_espresso_page()
311
-        );
312
-    }
313
-
314
-
315
-    /**
316
-     * @return    mixed
317
-     */
318
-    public function is_espresso_page()
319
-    {
320
-        return $this->request->is_set('is_espresso_page');
321
-    }
322
-
323
-
324
-    /**
325
-     * returns contents of $_REQUEST
326
-     *
327
-     * @return array
328
-     */
329
-    public function params()
330
-    {
331
-        return $this->request->params();
332
-    }
333
-
334
-
335
-    /**
336
-     * @param      $key
337
-     * @param      $value
338
-     * @param bool $override_ee
339
-     * @return    void
340
-     */
341
-    public function set($key, $value, $override_ee = false)
342
-    {
343
-        $this->request->set($key, $value, $override_ee);
344
-    }
345
-
346
-
347
-    /**
348
-     * @param      $key
349
-     * @param null $default
350
-     * @return    mixed
351
-     */
352
-    public function get($key, $default = null)
353
-    {
354
-        return $this->request->get($key, $default);
355
-    }
356
-
357
-
358
-    /**
359
-     * check if param exists
360
-     *
361
-     * @param $key
362
-     * @return    boolean
363
-     */
364
-    public function is_set($key)
365
-    {
366
-        return $this->request->is_set($key);
367
-    }
368
-
369
-
370
-    /**
371
-     * remove param
372
-     *
373
-     * @param $key
374
-     * @return    void
375
-     */
376
-    public function un_set($key)
377
-    {
378
-        $this->request->un_set($key);
379
-    }
15
+	/**
16
+	 * @var EE_Request $request
17
+	 */
18
+	private $request;
19
+
20
+	/**
21
+	 * @var array $_notice
22
+	 */
23
+	private $_notice = array();
24
+
25
+	/**
26
+	 * rendered output to be returned to WP
27
+	 *
28
+	 * @var string $_output
29
+	 */
30
+	private $_output = '';
31
+
32
+	/**
33
+	 * whether current request is via AJAX
34
+	 *
35
+	 * @var boolean $ajax
36
+	 */
37
+	public $ajax = false;
38
+
39
+	/**
40
+	 * whether current request is via AJAX from the frontend of the site
41
+	 *
42
+	 * @var boolean $front_ajax
43
+	 */
44
+	public $front_ajax = false;
45
+
46
+
47
+	/**
48
+	 * @param  EE_Request $request
49
+	 */
50
+	public function __construct(EE_Request $request)
51
+	{
52
+		$this->request = $request;
53
+		$this->ajax = $this->request->ajax;
54
+		$this->front_ajax = $this->request->front_ajax;
55
+		do_action('AHEE__EE_Request_Handler__construct__complete');
56
+	}
57
+
58
+
59
+	/**
60
+	 * @param WP $wp
61
+	 * @return void
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public function parse_request($wp = null)
66
+	{
67
+		// if somebody forgot to provide us with WP, that's ok because its global
68
+		if (! $wp instanceof WP) {
69
+			global $wp;
70
+		}
71
+		$this->set_request_vars($wp);
72
+	}
73
+
74
+
75
+	/**
76
+	 * @param WP $wp
77
+	 * @return void
78
+	 * @throws EE_Error
79
+	 * @throws ReflectionException
80
+	 */
81
+	public function set_request_vars($wp = null)
82
+	{
83
+		if (! is_admin()) {
84
+			// set request post_id
85
+			$this->request->set('post_id', $this->get_post_id_from_request($wp));
86
+			// set request post name
87
+			$this->request->set('post_name', $this->get_post_name_from_request($wp));
88
+			// set request post_type
89
+			$this->request->set('post_type', $this->get_post_type_from_request($wp));
90
+			// true or false ? is this page being used by EE ?
91
+			$this->set_espresso_page();
92
+		}
93
+	}
94
+
95
+
96
+	/**
97
+	 * @param WP $wp
98
+	 * @return int
99
+	 */
100
+	public function get_post_id_from_request($wp = null)
101
+	{
102
+		if (! $wp instanceof WP) {
103
+			global $wp;
104
+		}
105
+		$post_id = null;
106
+		if (isset($wp->query_vars['p'])) {
107
+			$post_id = $wp->query_vars['p'];
108
+		}
109
+		if (! $post_id && isset($wp->query_vars['page_id'])) {
110
+			$post_id = $wp->query_vars['page_id'];
111
+		}
112
+		if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
113
+			$post_id = basename($wp->request);
114
+		}
115
+		return $post_id;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param WP $wp
121
+	 * @return string
122
+	 */
123
+	public function get_post_name_from_request($wp = null)
124
+	{
125
+		if (! $wp instanceof WP) {
126
+			global $wp;
127
+		}
128
+		$post_name = null;
129
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
130
+			$post_name = $wp->query_vars['name'];
131
+		}
132
+		if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
133
+			$post_name = $wp->query_vars['pagename'];
134
+		}
135
+		if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
136
+			$possible_post_name = basename($wp->request);
137
+			if (! is_numeric($possible_post_name)) {
138
+				/** @type WPDB $wpdb */
139
+				global $wpdb;
140
+				$SQL =
141
+					"SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
142
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
143
+				if ($possible_post_name) {
144
+					$post_name = $possible_post_name;
145
+				}
146
+			}
147
+		}
148
+		if (! $post_name && $this->get('post_id')) {
149
+			/** @type WPDB $wpdb */
150
+			global $wpdb;
151
+			$SQL =
152
+				"SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
153
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
154
+			if ($possible_post_name) {
155
+				$post_name = $possible_post_name;
156
+			}
157
+		}
158
+		return $post_name;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param WP $wp
164
+	 * @return mixed
165
+	 */
166
+	public function get_post_type_from_request($wp = null)
167
+	{
168
+		if (! $wp instanceof WP) {
169
+			global $wp;
170
+		}
171
+		return isset($wp->query_vars['post_type'])
172
+			? $wp->query_vars['post_type']
173
+			: null;
174
+	}
175
+
176
+
177
+	/**
178
+	 * Just a helper method for getting the url for the displayed page.
179
+	 *
180
+	 * @param  WP $wp
181
+	 * @return string
182
+	 */
183
+	public function get_current_page_permalink($wp = null)
184
+	{
185
+		$post_id = $this->get_post_id_from_request($wp);
186
+		if ($post_id) {
187
+			$current_page_permalink = get_permalink($post_id);
188
+		} else {
189
+			if (! $wp instanceof WP) {
190
+				global $wp;
191
+			}
192
+			if ($wp->request) {
193
+				$current_page_permalink = site_url($wp->request);
194
+			} else {
195
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
196
+			}
197
+		}
198
+		return $current_page_permalink;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return bool
204
+	 * @throws EE_Error
205
+	 * @throws ReflectionException
206
+	 */
207
+	public function test_for_espresso_page()
208
+	{
209
+		global $wp;
210
+		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
211
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
212
+		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
213
+		if (is_array($espresso_CPT_taxonomies)) {
214
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
215
+				if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) {
216
+					return true;
217
+				}
218
+			}
219
+		}
220
+		// load espresso CPT endpoints
221
+		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
222
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
223
+		$post_types = (array) $this->get('post_type');
224
+		foreach ($post_types as $post_type) {
225
+			// was a post name passed ?
226
+			if (isset($post_type_CPT_endpoints[ $post_type ])) {
227
+				// kk we know this is an espresso page, but is it a specific post ?
228
+				if (! $this->get('post_name')) {
229
+					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
230
+					$post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ])
231
+						? $post_type_CPT_endpoints[ $this->get('post_type') ]
232
+						: '';
233
+					// if the post type matches on of our then set the endpoint
234
+					if ($post_name) {
235
+						$this->set('post_name', $post_name);
236
+					}
237
+				}
238
+				return true;
239
+			}
240
+		}
241
+		return false;
242
+	}
243
+
244
+	/**
245
+	 * @param $key
246
+	 * @param $value
247
+	 * @return    void
248
+	 */
249
+	public function set_notice($key, $value)
250
+	{
251
+		$this->_notice[ $key ] = $value;
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param $key
257
+	 * @return    mixed
258
+	 */
259
+	public function get_notice($key)
260
+	{
261
+		return isset($this->_notice[ $key ])
262
+			? $this->_notice[ $key ]
263
+			: null;
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param $string
269
+	 * @return void
270
+	 */
271
+	public function add_output($string)
272
+	{
273
+		$this->_output .= $string;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return string
279
+	 */
280
+	public function get_output()
281
+	{
282
+		return $this->_output;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @param $item
288
+	 * @param $key
289
+	 */
290
+	public function sanitize_text_field_for_array_walk(&$item, &$key)
291
+	{
292
+		$item = strpos($item, 'email') !== false
293
+			? sanitize_email($item)
294
+			: sanitize_text_field($item);
295
+	}
296
+
297
+
298
+	/**
299
+	 * @param null|bool $value
300
+	 * @return void
301
+	 * @throws EE_Error
302
+	 * @throws ReflectionException
303
+	 */
304
+	public function set_espresso_page($value = null)
305
+	{
306
+		$this->request->set(
307
+			'is_espresso_page',
308
+			! empty($value)
309
+				? $value
310
+				: $this->test_for_espresso_page()
311
+		);
312
+	}
313
+
314
+
315
+	/**
316
+	 * @return    mixed
317
+	 */
318
+	public function is_espresso_page()
319
+	{
320
+		return $this->request->is_set('is_espresso_page');
321
+	}
322
+
323
+
324
+	/**
325
+	 * returns contents of $_REQUEST
326
+	 *
327
+	 * @return array
328
+	 */
329
+	public function params()
330
+	{
331
+		return $this->request->params();
332
+	}
333
+
334
+
335
+	/**
336
+	 * @param      $key
337
+	 * @param      $value
338
+	 * @param bool $override_ee
339
+	 * @return    void
340
+	 */
341
+	public function set($key, $value, $override_ee = false)
342
+	{
343
+		$this->request->set($key, $value, $override_ee);
344
+	}
345
+
346
+
347
+	/**
348
+	 * @param      $key
349
+	 * @param null $default
350
+	 * @return    mixed
351
+	 */
352
+	public function get($key, $default = null)
353
+	{
354
+		return $this->request->get($key, $default);
355
+	}
356
+
357
+
358
+	/**
359
+	 * check if param exists
360
+	 *
361
+	 * @param $key
362
+	 * @return    boolean
363
+	 */
364
+	public function is_set($key)
365
+	{
366
+		return $this->request->is_set($key);
367
+	}
368
+
369
+
370
+	/**
371
+	 * remove param
372
+	 *
373
+	 * @param $key
374
+	 * @return    void
375
+	 */
376
+	public function un_set($key)
377
+	{
378
+		$this->request->un_set($key);
379
+	}
380 380
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     public function parse_request($wp = null)
66 66
     {
67 67
         // if somebody forgot to provide us with WP, that's ok because its global
68
-        if (! $wp instanceof WP) {
68
+        if ( ! $wp instanceof WP) {
69 69
             global $wp;
70 70
         }
71 71
         $this->set_request_vars($wp);
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function set_request_vars($wp = null)
82 82
     {
83
-        if (! is_admin()) {
83
+        if ( ! is_admin()) {
84 84
             // set request post_id
85 85
             $this->request->set('post_id', $this->get_post_id_from_request($wp));
86 86
             // set request post name
@@ -99,17 +99,17 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function get_post_id_from_request($wp = null)
101 101
     {
102
-        if (! $wp instanceof WP) {
102
+        if ( ! $wp instanceof WP) {
103 103
             global $wp;
104 104
         }
105 105
         $post_id = null;
106 106
         if (isset($wp->query_vars['p'])) {
107 107
             $post_id = $wp->query_vars['p'];
108 108
         }
109
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
109
+        if ( ! $post_id && isset($wp->query_vars['page_id'])) {
110 110
             $post_id = $wp->query_vars['page_id'];
111 111
         }
112
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
112
+        if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
113 113
             $post_id = basename($wp->request);
114 114
         }
115 115
         return $post_id;
@@ -122,19 +122,19 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function get_post_name_from_request($wp = null)
124 124
     {
125
-        if (! $wp instanceof WP) {
125
+        if ( ! $wp instanceof WP) {
126 126
             global $wp;
127 127
         }
128 128
         $post_name = null;
129 129
         if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
130 130
             $post_name = $wp->query_vars['name'];
131 131
         }
132
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
132
+        if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
133 133
             $post_name = $wp->query_vars['pagename'];
134 134
         }
135
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
135
+        if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) {
136 136
             $possible_post_name = basename($wp->request);
137
-            if (! is_numeric($possible_post_name)) {
137
+            if ( ! is_numeric($possible_post_name)) {
138 138
                 /** @type WPDB $wpdb */
139 139
                 global $wpdb;
140 140
                 $SQL =
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                 }
146 146
             }
147 147
         }
148
-        if (! $post_name && $this->get('post_id')) {
148
+        if ( ! $post_name && $this->get('post_id')) {
149 149
             /** @type WPDB $wpdb */
150 150
             global $wpdb;
151 151
             $SQL =
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function get_post_type_from_request($wp = null)
167 167
     {
168
-        if (! $wp instanceof WP) {
168
+        if ( ! $wp instanceof WP) {
169 169
             global $wp;
170 170
         }
171 171
         return isset($wp->query_vars['post_type'])
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         if ($post_id) {
187 187
             $current_page_permalink = get_permalink($post_id);
188 188
         } else {
189
-            if (! $wp instanceof WP) {
189
+            if ( ! $wp instanceof WP) {
190 190
                 global $wp;
191 191
             }
192 192
             if ($wp->request) {
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
213 213
         if (is_array($espresso_CPT_taxonomies)) {
214 214
             foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
215
-                if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) {
215
+                if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
216 216
                     return true;
217 217
                 }
218 218
             }
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
         $post_types = (array) $this->get('post_type');
224 224
         foreach ($post_types as $post_type) {
225 225
             // was a post name passed ?
226
-            if (isset($post_type_CPT_endpoints[ $post_type ])) {
226
+            if (isset($post_type_CPT_endpoints[$post_type])) {
227 227
                 // kk we know this is an espresso page, but is it a specific post ?
228
-                if (! $this->get('post_name')) {
228
+                if ( ! $this->get('post_name')) {
229 229
                     // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
230
-                    $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ])
231
-                        ? $post_type_CPT_endpoints[ $this->get('post_type') ]
230
+                    $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
231
+                        ? $post_type_CPT_endpoints[$this->get('post_type')]
232 232
                         : '';
233 233
                     // if the post type matches on of our then set the endpoint
234 234
                     if ($post_name) {
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function set_notice($key, $value)
250 250
     {
251
-        $this->_notice[ $key ] = $value;
251
+        $this->_notice[$key] = $value;
252 252
     }
253 253
 
254 254
 
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function get_notice($key)
260 260
     {
261
-        return isset($this->_notice[ $key ])
262
-            ? $this->_notice[ $key ]
261
+        return isset($this->_notice[$key])
262
+            ? $this->_notice[$key]
263 263
             : null;
264 264
     }
265 265
 
Please login to merge, or discard this patch.