Completed
Branch FET/extra-logging-when-trashin... (b6e112)
by
unknown
36:04 queued 27:41
created
core/EE_Log.core.php 2 patches
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -17,261 +17,261 @@
 block discarded – undo
17 17
 class EE_Log
18 18
 {
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    private $_logs_folder = '';
24
-
25
-    /**
26
-     * @var string
27
-     */
28
-    private $_log_file = '';
29
-
30
-    /**
31
-     * @var string
32
-     */
33
-    private $_log = '';
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    private $_debug_file = '';
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    private $_debug_log = '';
44
-
45
-    /**
46
-     * Used for remote logging
47
-     *
48
-     * @var string
49
-     */
50
-    private $_remote_logging_url = '';
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    private $_remote_log = '';
56
-
57
-    /**
58
-     * @var EE_Log
59
-     */
60
-    private static $_instance;
61
-
62
-
63
-    /**
64
-     * @return EE_Log
65
-     */
66
-    public static function instance()
67
-    {
68
-        if (! self::$_instance instanceof EE_Log) {
69
-            self::$_instance = new self();
70
-        }
71
-        return self::$_instance;
72
-    }
73
-
74
-    /**
75
-     * @access private
76
-     * @return EE_Log
77
-     */
78
-    private function __construct()
79
-    {
80
-
81
-        if (! EE_Registry::instance()->CFG->admin->use_full_logging
82
-            && ! EE_Registry::instance()->CFG->admin->use_remote_logging) {
83
-            return;
84
-        }
85
-
86
-        $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS;
87
-        $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name();
88
-        $this->_log = '';
89
-        $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name();
90
-        $this->_debug_log = '';
91
-        $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url;
92
-        $this->_remote_log = '';
93
-
94
-        add_action('admin_init', array($this, 'verify_filesystem'), -10);
95
-        add_action('AHEE_log', array($this, 'log'), 10, 4);
96
-        if (EE_Registry::instance()->CFG->admin->use_full_logging) {
97
-            add_action('shutdown', array($this, 'write_log'), 9999);
98
-            // if WP_DEBUG
99
-            add_action('shutdown', array($this, 'write_debug'), 9999);
100
-        }
101
-        if (EE_Registry::instance()->CFG->admin->use_remote_logging) {
102
-            add_action('shutdown', array($this, 'send_log'), 9999);
103
-        }
104
-    }
105
-
106
-
107
-    /**
108
-     *    verify_filesystem
109
-     * tests that the required files and folders exist and are writable
110
-     *
111
-     */
112
-    public function verify_filesystem()
113
-    {
114
-        try {
115
-            EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file);
116
-            EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file);
117
-            EEH_File::add_htaccess_deny_from_all($this->_logs_folder);
118
-        } catch (EE_Error $e) {
119
-            EE_Error::add_error(
120
-                sprintf(
121
-                    __('Event Espresso logging could not be setup because: %s', 'event_espresso'),
122
-                    '     ' . $e->getMessage()
123
-                ),
124
-                __FILE__,
125
-                __FUNCTION__,
126
-                __LINE__
127
-            );
128
-            return;
129
-        }
130
-    }
131
-
132
-
133
-    /**
134
-     *    _format_message
135
-     *    makes yer log entries look all purdy
136
-     *
137
-     * @param string $file
138
-     * @param string $function
139
-     * @param string $message
140
-     * @param string $type
141
-     * @return string
142
-     */
143
-    private function _format_message($file = '', $function = '', $message = '', $type = '')
144
-    {
145
-        $msg = '----------------------------------------------------------------------------------------' . PHP_EOL;
146
-        $msg .= '[' . current_time('mysql') . '] ';
147
-        $msg .= ! empty($file) ? basename($file) : '';
148
-        $msg .= ! empty($file) && ! empty($function) ? ' -> ' : '';
149
-        $msg .= ! empty($function) ? $function . '()' : '';
150
-        $msg .= PHP_EOL;
151
-        $type = ! empty($type) ? $type : 'log message';
152
-        $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : '';
153
-        return $msg;
154
-    }
155
-
156
-
157
-    /**
158
-     *    log
159
-     * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the
160
-     * EE_Log::write_log() callback
161
-     *
162
-     * @param string $file
163
-     * @param string $function
164
-     * @param string $message
165
-     * @param string $type
166
-     */
167
-    public function log($file = '', $function = '', $message = '', $type = '')
168
-    {
169
-        $this->_log .= $this->_format_message($file, $function, $message, $type);
170
-    }
171
-
172
-
173
-    /**
174
-     * write_log
175
-     * appends the results of the 'AHEE_log' filter to the espresso log file
176
-     */
177
-    public function write_log()
178
-    {
179
-        try {
180
-            // get existing log file and append new log info
181
-            $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log;
182
-            EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log');
183
-        } catch (EE_Error $e) {
184
-            EE_Error::add_error(
185
-                sprintf(
186
-                    __('Could not write to the Event Espresso log file because: %s', 'event_espresso'),
187
-                    '     ' . $e->getMessage()
188
-                ),
189
-                __FILE__,
190
-                __FUNCTION__,
191
-                __LINE__
192
-            );
193
-            return;
194
-        }
195
-    }
196
-
197
-
198
-    /**
199
-     * send_log
200
-     * sends the espresso log to a remote URL via a PHP cURL request
201
-     */
202
-    public function send_log()
203
-    {
204
-
205
-        if (empty($this->_remote_logging_url)) {
206
-            return;
207
-        }
208
-
209
-        $data = 'domain=' . $_SERVER['HTTP_HOST'];
210
-        $data .= '&ip=' . $_SERVER['SERVER_ADDR'];
211
-        $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE'];
212
-        $data .= '&time=' . time();
213
-        $data .= '&remote_log=' . $this->_log;
214
-        $data .= '&request_array=' . json_encode($_REQUEST);
215
-        $data .= '&action=save';
216
-
217
-        if (defined('EELOGGING_PASS')) {
218
-            $data .= '&pass=' . EELOGGING_PASS;
219
-        }
220
-        if (defined('EELOGGING_KEY')) {
221
-            $data .= '&key=' . EELOGGING_KEY;
222
-        }
223
-
224
-        $c = curl_init($this->_remote_logging_url);
225
-        curl_setopt($c, CURLOPT_POST, true);
226
-        curl_setopt($c, CURLOPT_POSTFIELDS, $data);
227
-        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
228
-        curl_exec($c);
229
-        curl_close($c);
230
-    }
231
-
232
-
233
-    /**
234
-     * write_debug
235
-     * writes the contents of the current request's $_GET and $_POST arrays to a log file.
236
-     * previous entries are overwritten
237
-     */
238
-    public function write_debug()
239
-    {
240
-        if (defined('WP_DEBUG') && WP_DEBUG) {
241
-            $this->_debug_log = '';
242
-            foreach ($_GET as $key => $value) {
243
-                $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL;
244
-            }
245
-            foreach ($_POST as $key => $value) {
246
-                $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL;
247
-            }
248
-            try {
249
-                EEH_File::write_to_file(
250
-                    $this->_logs_folder . $this->_debug_file,
251
-                    $this->_debug_log,
252
-                    'Event Espresso Debug Log'
253
-                );
254
-            } catch (EE_Error $e) {
255
-                EE_Error::add_error(
256
-                    sprintf(
257
-                        __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'),
258
-                        '     ' . $e->getMessage()
259
-                    ),
260
-                    __FILE__,
261
-                    __FUNCTION__,
262
-                    __LINE__
263
-                );
264
-                return;
265
-            }
266
-        }
267
-    }
268
-
269
-
270
-    /**
271
-     * __clone
272
-     */
273
-    public function __clone()
274
-    {
275
-        trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR);
276
-    }
20
+	/**
21
+	 * @var string
22
+	 */
23
+	private $_logs_folder = '';
24
+
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private $_log_file = '';
29
+
30
+	/**
31
+	 * @var string
32
+	 */
33
+	private $_log = '';
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	private $_debug_file = '';
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	private $_debug_log = '';
44
+
45
+	/**
46
+	 * Used for remote logging
47
+	 *
48
+	 * @var string
49
+	 */
50
+	private $_remote_logging_url = '';
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	private $_remote_log = '';
56
+
57
+	/**
58
+	 * @var EE_Log
59
+	 */
60
+	private static $_instance;
61
+
62
+
63
+	/**
64
+	 * @return EE_Log
65
+	 */
66
+	public static function instance()
67
+	{
68
+		if (! self::$_instance instanceof EE_Log) {
69
+			self::$_instance = new self();
70
+		}
71
+		return self::$_instance;
72
+	}
73
+
74
+	/**
75
+	 * @access private
76
+	 * @return EE_Log
77
+	 */
78
+	private function __construct()
79
+	{
80
+
81
+		if (! EE_Registry::instance()->CFG->admin->use_full_logging
82
+			&& ! EE_Registry::instance()->CFG->admin->use_remote_logging) {
83
+			return;
84
+		}
85
+
86
+		$this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS;
87
+		$this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name();
88
+		$this->_log = '';
89
+		$this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name();
90
+		$this->_debug_log = '';
91
+		$this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url;
92
+		$this->_remote_log = '';
93
+
94
+		add_action('admin_init', array($this, 'verify_filesystem'), -10);
95
+		add_action('AHEE_log', array($this, 'log'), 10, 4);
96
+		if (EE_Registry::instance()->CFG->admin->use_full_logging) {
97
+			add_action('shutdown', array($this, 'write_log'), 9999);
98
+			// if WP_DEBUG
99
+			add_action('shutdown', array($this, 'write_debug'), 9999);
100
+		}
101
+		if (EE_Registry::instance()->CFG->admin->use_remote_logging) {
102
+			add_action('shutdown', array($this, 'send_log'), 9999);
103
+		}
104
+	}
105
+
106
+
107
+	/**
108
+	 *    verify_filesystem
109
+	 * tests that the required files and folders exist and are writable
110
+	 *
111
+	 */
112
+	public function verify_filesystem()
113
+	{
114
+		try {
115
+			EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file);
116
+			EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file);
117
+			EEH_File::add_htaccess_deny_from_all($this->_logs_folder);
118
+		} catch (EE_Error $e) {
119
+			EE_Error::add_error(
120
+				sprintf(
121
+					__('Event Espresso logging could not be setup because: %s', 'event_espresso'),
122
+					'     ' . $e->getMessage()
123
+				),
124
+				__FILE__,
125
+				__FUNCTION__,
126
+				__LINE__
127
+			);
128
+			return;
129
+		}
130
+	}
131
+
132
+
133
+	/**
134
+	 *    _format_message
135
+	 *    makes yer log entries look all purdy
136
+	 *
137
+	 * @param string $file
138
+	 * @param string $function
139
+	 * @param string $message
140
+	 * @param string $type
141
+	 * @return string
142
+	 */
143
+	private function _format_message($file = '', $function = '', $message = '', $type = '')
144
+	{
145
+		$msg = '----------------------------------------------------------------------------------------' . PHP_EOL;
146
+		$msg .= '[' . current_time('mysql') . '] ';
147
+		$msg .= ! empty($file) ? basename($file) : '';
148
+		$msg .= ! empty($file) && ! empty($function) ? ' -> ' : '';
149
+		$msg .= ! empty($function) ? $function . '()' : '';
150
+		$msg .= PHP_EOL;
151
+		$type = ! empty($type) ? $type : 'log message';
152
+		$msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : '';
153
+		return $msg;
154
+	}
155
+
156
+
157
+	/**
158
+	 *    log
159
+	 * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the
160
+	 * EE_Log::write_log() callback
161
+	 *
162
+	 * @param string $file
163
+	 * @param string $function
164
+	 * @param string $message
165
+	 * @param string $type
166
+	 */
167
+	public function log($file = '', $function = '', $message = '', $type = '')
168
+	{
169
+		$this->_log .= $this->_format_message($file, $function, $message, $type);
170
+	}
171
+
172
+
173
+	/**
174
+	 * write_log
175
+	 * appends the results of the 'AHEE_log' filter to the espresso log file
176
+	 */
177
+	public function write_log()
178
+	{
179
+		try {
180
+			// get existing log file and append new log info
181
+			$this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log;
182
+			EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log');
183
+		} catch (EE_Error $e) {
184
+			EE_Error::add_error(
185
+				sprintf(
186
+					__('Could not write to the Event Espresso log file because: %s', 'event_espresso'),
187
+					'     ' . $e->getMessage()
188
+				),
189
+				__FILE__,
190
+				__FUNCTION__,
191
+				__LINE__
192
+			);
193
+			return;
194
+		}
195
+	}
196
+
197
+
198
+	/**
199
+	 * send_log
200
+	 * sends the espresso log to a remote URL via a PHP cURL request
201
+	 */
202
+	public function send_log()
203
+	{
204
+
205
+		if (empty($this->_remote_logging_url)) {
206
+			return;
207
+		}
208
+
209
+		$data = 'domain=' . $_SERVER['HTTP_HOST'];
210
+		$data .= '&ip=' . $_SERVER['SERVER_ADDR'];
211
+		$data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE'];
212
+		$data .= '&time=' . time();
213
+		$data .= '&remote_log=' . $this->_log;
214
+		$data .= '&request_array=' . json_encode($_REQUEST);
215
+		$data .= '&action=save';
216
+
217
+		if (defined('EELOGGING_PASS')) {
218
+			$data .= '&pass=' . EELOGGING_PASS;
219
+		}
220
+		if (defined('EELOGGING_KEY')) {
221
+			$data .= '&key=' . EELOGGING_KEY;
222
+		}
223
+
224
+		$c = curl_init($this->_remote_logging_url);
225
+		curl_setopt($c, CURLOPT_POST, true);
226
+		curl_setopt($c, CURLOPT_POSTFIELDS, $data);
227
+		curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
228
+		curl_exec($c);
229
+		curl_close($c);
230
+	}
231
+
232
+
233
+	/**
234
+	 * write_debug
235
+	 * writes the contents of the current request's $_GET and $_POST arrays to a log file.
236
+	 * previous entries are overwritten
237
+	 */
238
+	public function write_debug()
239
+	{
240
+		if (defined('WP_DEBUG') && WP_DEBUG) {
241
+			$this->_debug_log = '';
242
+			foreach ($_GET as $key => $value) {
243
+				$this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL;
244
+			}
245
+			foreach ($_POST as $key => $value) {
246
+				$this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL;
247
+			}
248
+			try {
249
+				EEH_File::write_to_file(
250
+					$this->_logs_folder . $this->_debug_file,
251
+					$this->_debug_log,
252
+					'Event Espresso Debug Log'
253
+				);
254
+			} catch (EE_Error $e) {
255
+				EE_Error::add_error(
256
+					sprintf(
257
+						__('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'),
258
+						'     ' . $e->getMessage()
259
+					),
260
+					__FILE__,
261
+					__FUNCTION__,
262
+					__LINE__
263
+				);
264
+				return;
265
+			}
266
+		}
267
+	}
268
+
269
+
270
+	/**
271
+	 * __clone
272
+	 */
273
+	public function __clone()
274
+	{
275
+		trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR);
276
+	}
277 277
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public static function instance()
67 67
     {
68
-        if (! self::$_instance instanceof EE_Log) {
68
+        if ( ! self::$_instance instanceof EE_Log) {
69 69
             self::$_instance = new self();
70 70
         }
71 71
         return self::$_instance;
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
     private function __construct()
79 79
     {
80 80
 
81
-        if (! EE_Registry::instance()->CFG->admin->use_full_logging
81
+        if ( ! EE_Registry::instance()->CFG->admin->use_full_logging
82 82
             && ! EE_Registry::instance()->CFG->admin->use_remote_logging) {
83 83
             return;
84 84
         }
85 85
 
86
-        $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS;
86
+        $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS;
87 87
         $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name();
88 88
         $this->_log = '';
89 89
         $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name();
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
     public function verify_filesystem()
113 113
     {
114 114
         try {
115
-            EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_log_file);
116
-            EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder . $this->_debug_file);
115
+            EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_log_file);
116
+            EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_debug_file);
117 117
             EEH_File::add_htaccess_deny_from_all($this->_logs_folder);
118 118
         } catch (EE_Error $e) {
119 119
             EE_Error::add_error(
120 120
                 sprintf(
121 121
                     __('Event Espresso logging could not be setup because: %s', 'event_espresso'),
122
-                    '     ' . $e->getMessage()
122
+                    '     '.$e->getMessage()
123 123
                 ),
124 124
                 __FILE__,
125 125
                 __FUNCTION__,
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
      */
143 143
     private function _format_message($file = '', $function = '', $message = '', $type = '')
144 144
     {
145
-        $msg = '----------------------------------------------------------------------------------------' . PHP_EOL;
146
-        $msg .= '[' . current_time('mysql') . '] ';
145
+        $msg = '----------------------------------------------------------------------------------------'.PHP_EOL;
146
+        $msg .= '['.current_time('mysql').'] ';
147 147
         $msg .= ! empty($file) ? basename($file) : '';
148 148
         $msg .= ! empty($file) && ! empty($function) ? ' -> ' : '';
149
-        $msg .= ! empty($function) ? $function . '()' : '';
149
+        $msg .= ! empty($function) ? $function.'()' : '';
150 150
         $msg .= PHP_EOL;
151 151
         $type = ! empty($type) ? $type : 'log message';
152
-        $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : '';
152
+        $msg .= ! empty($message) ? "\t".'['.$type.'] '.$message.PHP_EOL : '';
153 153
         return $msg;
154 154
     }
155 155
 
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
     {
179 179
         try {
180 180
             // get existing log file and append new log info
181
-            $this->_log = EEH_File::get_file_contents($this->_logs_folder . $this->_log_file) . $this->_log;
182
-            EEH_File::write_to_file($this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log');
181
+            $this->_log = EEH_File::get_file_contents($this->_logs_folder.$this->_log_file).$this->_log;
182
+            EEH_File::write_to_file($this->_logs_folder.$this->_log_file, $this->_log, 'Event Espresso Log');
183 183
         } catch (EE_Error $e) {
184 184
             EE_Error::add_error(
185 185
                 sprintf(
186 186
                     __('Could not write to the Event Espresso log file because: %s', 'event_espresso'),
187
-                    '     ' . $e->getMessage()
187
+                    '     '.$e->getMessage()
188 188
                 ),
189 189
                 __FILE__,
190 190
                 __FUNCTION__,
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
             return;
207 207
         }
208 208
 
209
-        $data = 'domain=' . $_SERVER['HTTP_HOST'];
210
-        $data .= '&ip=' . $_SERVER['SERVER_ADDR'];
211
-        $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE'];
212
-        $data .= '&time=' . time();
213
-        $data .= '&remote_log=' . $this->_log;
214
-        $data .= '&request_array=' . json_encode($_REQUEST);
209
+        $data = 'domain='.$_SERVER['HTTP_HOST'];
210
+        $data .= '&ip='.$_SERVER['SERVER_ADDR'];
211
+        $data .= '&server_type='.$_SERVER['SERVER_SOFTWARE'];
212
+        $data .= '&time='.time();
213
+        $data .= '&remote_log='.$this->_log;
214
+        $data .= '&request_array='.json_encode($_REQUEST);
215 215
         $data .= '&action=save';
216 216
 
217 217
         if (defined('EELOGGING_PASS')) {
218
-            $data .= '&pass=' . EELOGGING_PASS;
218
+            $data .= '&pass='.EELOGGING_PASS;
219 219
         }
220 220
         if (defined('EELOGGING_KEY')) {
221
-            $data .= '&key=' . EELOGGING_KEY;
221
+            $data .= '&key='.EELOGGING_KEY;
222 222
         }
223 223
 
224 224
         $c = curl_init($this->_remote_logging_url);
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
         if (defined('WP_DEBUG') && WP_DEBUG) {
241 241
             $this->_debug_log = '';
242 242
             foreach ($_GET as $key => $value) {
243
-                $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL;
243
+                $this->_debug_log .= '$_GET["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL;
244 244
             }
245 245
             foreach ($_POST as $key => $value) {
246
-                $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL;
246
+                $this->_debug_log .= '$_POST["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL;
247 247
             }
248 248
             try {
249 249
                 EEH_File::write_to_file(
250
-                    $this->_logs_folder . $this->_debug_file,
250
+                    $this->_logs_folder.$this->_debug_file,
251 251
                     $this->_debug_log,
252 252
                     'Event Espresso Debug Log'
253 253
                 );
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
                 EE_Error::add_error(
256 256
                     sprintf(
257 257
                         __('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'),
258
-                        '     ' . $e->getMessage()
258
+                        '     '.$e->getMessage()
259 259
                     ),
260 260
                     __FILE__,
261 261
                     __FUNCTION__,
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Script_Base.core.php 2 patches
Indentation   +876 added lines, -876 removed lines patch added patch discarded remove patch
@@ -15,880 +15,880 @@
 block discarded – undo
15 15
 abstract class EE_Data_Migration_Script_Base extends EE_Data_Migration_Class_Base
16 16
 {
17 17
 
18
-    /**
19
-     * Set by client code to indicate this DMS is being ran as part of a proper migration,
20
-     * instead of being used to merely setup (or verify) the database structure.
21
-     * Defaults to TRUE, so client code that's NOT using this DMS as part of a proper migration
22
-     * should call EE_Data_Migration_Script_Base::set_migrating( FALSE )
23
-     *
24
-     * @var boolean
25
-     */
26
-    protected $_migrating = true;
27
-
28
-    /**
29
-     * numerically-indexed array where each value is EE_Data_Migration_Script_Stage object
30
-     *
31
-     * @var EE_Data_Migration_Script_Stage[] $migration_functions
32
-     */
33
-    protected $_migration_stages = array();
34
-
35
-    /**
36
-     * Indicates we've already ran the schema changes that needed to happen BEFORE the data migration
37
-     *
38
-     * @var boolean
39
-     */
40
-    protected $_schema_changes_before_migration_ran = null;
41
-
42
-    /**
43
-     * Indicates we've already ran the schema changes that needed to happen AFTER the data migration
44
-     *
45
-     * @var boolean
46
-     */
47
-    protected $_schema_changes_after_migration_ran = null;
48
-
49
-    /**
50
-     * String which describes what's currently happening in this migration
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_feedback_message;
55
-
56
-    /**
57
-     * Indicates the script's priority. Like wp's add_action and add_filter, lower numbers
58
-     * correspond to earlier execution
59
-     *
60
-     * @var int
61
-     */
62
-    protected $_priority = 5;
63
-
64
-    /**
65
-     * Multi-dimensional array that defines the mapping from OLD table Primary Keys
66
-     * to NEW table Primary Keys.
67
-     * Top-level array keys are OLD table names (minus the "wp_" part),
68
-     * 2nd-level array keys are NEW table names (again, minus the "wp_" part),
69
-     * 3rd-level array keys are the OLD table primary keys
70
-     * and 3rd-level array values are the NEW table primary keys
71
-     *
72
-     * @var array
73
-     */
74
-    protected $_mappings = array();
75
-
76
-
77
-    /**
78
-     * Returns whether or not this data migration script can operate on the given version of the database.
79
-     * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
80
-     * it's passed a string like '3.1.38B', it should return true.
81
-     * If this DMS is to migrate data from an EE3 addon, you will probably want to use
82
-     * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and
83
-     * EE_Data_Migration_Manager::get_migration_ran() to check that core was already
84
-     * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated
85
-     * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want
86
-     * to run this DMS).
87
-     * If this DMS migrates data from a previous version of this EE4 addon, just
88
-     * comparing $current_database_state_of[ $this->slug() ] will probably suffice.
89
-     * If this DMS should never migrate data, because it's only used to define the initial
90
-     * database state, just return FALSE (and core's activation process will take care
91
-     * of calling its schema_changes_before_migration() and
92
-     * schema_changes_after_migration() for you. )
93
-     *
94
-     * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc)
95
-     * @return boolean
96
-     */
97
-    abstract public function can_migrate_from_version($current_database_state_of);
98
-
99
-
100
-    /**
101
-     * Performs database schema changes that need to occur BEFORE the data is migrated.
102
-     * Eg, if we were going to change user passwords from plaintext to encoded versions
103
-     * during this migration, this would probably add a new column called something like
104
-     * "encoded_password".
105
-     *
106
-     * @return boolean of success
107
-     */
108
-    abstract public function schema_changes_before_migration();
109
-
110
-
111
-    /**
112
-     * Performs the database schema changes that need to occur AFTER the data has been migrated.
113
-     * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords
114
-     * from plaintext to encoded versions, and we had added a column called "encoded_password",
115
-     * this function would probably remove the old column "password" (which still holds the plaintext password)
116
-     * and possibly rename "encoded_password" to "password"
117
-     *
118
-     * @return boolean of success
119
-     */
120
-    abstract public function schema_changes_after_migration();
121
-
122
-
123
-    /**
124
-     * All children of this must call parent::__construct()
125
-     * at the end of their constructor or suffer the consequences!
126
-     *
127
-     * @param TableManager  $table_manager
128
-     * @param TableAnalysis $table_analysis
129
-     */
130
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
131
-    {
132
-        $this->_migration_stages = (array) apply_filters(
133
-            'FHEE__' . get_class($this) . '__construct__migration_stages',
134
-            $this->_migration_stages
135
-        );
136
-        foreach ($this->_migration_stages as $migration_stage) {
137
-            if ($migration_stage instanceof EE_Data_Migration_Script_Stage) {
138
-                $migration_stage->_construct_finalize($this);
139
-            }
140
-        }
141
-        parent::__construct($table_manager, $table_analysis);
142
-    }
143
-
144
-
145
-    /**
146
-     * Place to add hooks and filters for tweaking the migrations page, in order
147
-     * to customize it
148
-     */
149
-    public function migration_page_hooks()
150
-    {
151
-        // by default none are added because we normally like the default look of the migration page
152
-    }
153
-
154
-
155
-    /**
156
-     * Sets the mapping from old table primary keys to new table primary keys.
157
-     * This mapping is automatically persisted as a property on the migration
158
-     *
159
-     * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
160
-     * @param int|string $old_pk    old primary key. Eg events_detail.id's value
161
-     * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
162
-     * @param int|string $new_pk    eg posts.ID
163
-     * @return void
164
-     */
165
-    public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
166
-    {
167
-        // make sure it has the needed keys
168
-        if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
169
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
170
-        }
171
-        $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
172
-    }
173
-
174
-
175
-    /**
176
-     * Gets the new primary key, if provided with the OLD table and the primary key
177
-     * of an item in the old table, and the new table
178
-     *
179
-     * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
180
-     * @param int|string $old_pk    old primary key. Eg events_detail.id's value
181
-     * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
182
-     * @return mixed the primary key on the new table
183
-     */
184
-    public function get_mapping_new_pk($old_table, $old_pk, $new_table)
185
-    {
186
-        if (! isset($this->_mappings[ $old_table ]) ||
187
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
188
-            // try fetching the option
189
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
190
-        }
191
-        return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
192
-            ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
193
-    }
194
-
195
-
196
-    /**
197
-     * Gets the old primary key, if provided with the OLD table,
198
-     * and the new table and the primary key of an item in the new table
199
-     *
200
-     * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail
201
-     * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts
202
-     * @param mixed  $new_pk
203
-     * @return mixed
204
-     */
205
-    public function get_mapping_old_pk($old_table, $new_table, $new_pk)
206
-    {
207
-        if (! isset($this->_mappings[ $old_table ]) ||
208
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
209
-            // try fetching the option
210
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
211
-        }
212
-        if (isset($this->_mappings[ $old_table ][ $new_table ])) {
213
-            $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
214
-            if (isset($new_pk_to_old_pk[ $new_pk ])) {
215
-                return $new_pk_to_old_pk[ $new_pk ];
216
-            }
217
-        }
218
-        return null;
219
-    }
220
-
221
-
222
-    /**
223
-     * Gets the mapping array option specified by the table names
224
-     *
225
-     * @param string $old_table_name
226
-     * @param string $new_table_name
227
-     * @return array
228
-     */
229
-    protected function _get_mapping_option($old_table_name, $new_table_name)
230
-    {
231
-        $option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array());
232
-        return $option;
233
-    }
234
-
235
-
236
-    /**
237
-     * Updates the mapping option specified by the table names with the array provided
238
-     *
239
-     * @param string $old_table_name
240
-     * @param string $new_table_name
241
-     * @param array  $mapping_array
242
-     * @return boolean success of updating option
243
-     */
244
-    protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array)
245
-    {
246
-        $success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array);
247
-        return $success;
248
-    }
249
-
250
-
251
-    /**
252
-     * Gets the option name for this script to map from $old_table_name to $new_table_name
253
-     *
254
-     * @param string $old_table_name
255
-     * @param string $new_table_name
256
-     * @return string
257
-     */
258
-    protected function _get_mapping_option_name($old_table_name, $new_table_name)
259
-    {
260
-        global $wpdb;
261
-        $old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name);
262
-        $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
263
-        $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
264
-        return substr(
265
-            EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp,
266
-            0,
267
-            64
268
-        );
269
-    }
270
-
271
-
272
-    /**
273
-     * Counts all the records that will be migrated during this data migration.
274
-     * For example, if we were changing old user passwords from plaintext to encoded versions,
275
-     * this would be a count of all users who have passwords. If we were going to also split
276
-     * attendee records into transactions, registrations, and attendee records, this would include
277
-     * the count of all attendees currently in existence in the DB (ie, users + attendees).
278
-     * If you can't determine how many records there are to migrate, just provide a guess: this
279
-     * number will only be used in calculating the percent complete. If you estimate there to be
280
-     * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at
281
-     * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete.
282
-     *
283
-     * @return int
284
-     */
285
-    protected function _count_records_to_migrate()
286
-    {
287
-        $count = 0;
288
-        foreach ($this->stages() as $stage) {
289
-            $count += $stage->count_records_to_migrate();
290
-        }
291
-        return $count;
292
-    }
293
-
294
-
295
-    /**
296
-     * Returns the number of records updated so far. Usually this is easiest to do
297
-     * by just setting a transient and updating it after each migration_step
298
-     *
299
-     * @return int
300
-     */
301
-    public function count_records_migrated()
302
-    {
303
-        $count = 0;
304
-        foreach ($this->stages() as $stage) {
305
-            $count += $stage->count_records_migrated();
306
-        }
307
-        $this->_records_migrated = $count;
308
-        return $count;
309
-    }
310
-
311
-
312
-    /**
313
-     * @param int $num_records_to_migrate_limit
314
-     * @return int
315
-     * @throws EE_Error
316
-     * @throws Exception
317
-     */
318
-    public function migration_step($num_records_to_migrate_limit)
319
-    {
320
-        // reset the feedback message
321
-        $this->_feedback_message = '';
322
-        // if we haven't yet done the 1st schema changes, do them now. buffer any output
323
-        $this->_maybe_do_schema_changes(true);
324
-
325
-        $num_records_actually_migrated = 0;
326
-        $records_migrated_per_stage = array();
327
-        // setup the 'stage' variable, which should hold the last run stage of the migration  (or none at all if nothing runs)
328
-        $stage = null;
329
-        // get the next stage that isn't complete
330
-        foreach ($this->stages() as $stage) {
331
-            if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) {
332
-                try {
333
-                    $records_migrated_during_stage = $stage->migration_step(
334
-                        $num_records_to_migrate_limit - $num_records_actually_migrated
335
-                    );
336
-                    $num_records_actually_migrated += $records_migrated_during_stage;
337
-                    $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
338
-                } catch (Exception $e) {
339
-                    // yes if we catch an exception here, we consider that migration stage borked.
340
-                    $stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
341
-                    $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
342
-                    $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
343
-                    throw $e;
344
-                }
345
-                // check that the migration stage didn't mark itself as having a fatal error
346
-                if ($stage->is_broken()) {
347
-                    $this->set_broken();
348
-                    throw new EE_Error($stage->get_last_error());
349
-                }
350
-            }
351
-            // once we've migrated all the number we intended to (possibly from different stages), stop migrating
352
-            // or if we had a fatal error
353
-            // or if the current script stopped early- its not done, but it's done all it thinks we should do on this step
354
-            if ($num_records_actually_migrated >= $num_records_to_migrate_limit
355
-                || $stage->is_broken()
356
-                || $stage->has_more_to_do()
357
-            ) {
358
-                break;
359
-            }
360
-        }
361
-        // check if we're all done this data migration...
362
-        // which is indicated by being done early AND the last stage claims to be done
363
-        if ($stage == null) {
364
-            // this migration script apparently has NO stages... which is super weird, but whatever
365
-            $this->set_completed();
366
-            $this->_maybe_do_schema_changes(false);
367
-        } elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) {
368
-            // apparently we're done, because we couldn't migrate the number we intended to
369
-            $this->set_completed();
370
-            $this->_update_feedback_message(array_reverse($records_migrated_per_stage));
371
-            // do schema changes for after the migration now
372
-            // first double-check we haven't already done this
373
-            $this->_maybe_do_schema_changes(false);
374
-        } else {
375
-            // update feedback message, keeping in mind that we show them with the most recent at the top
376
-            $this->_update_feedback_message(array_reverse($records_migrated_per_stage));
377
-        }
378
-        return $num_records_actually_migrated;
379
-    }
380
-
381
-
382
-    /**
383
-     * Updates the feedback message according to what was done during this migration stage.
384
-     *
385
-     * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records
386
-     *                                          migrated from that stage
387
-     * @return void
388
-     */
389
-    private function _update_feedback_message($records_migrated_per_stage)
390
-    {
391
-        $feedback_message_array = array();
392
-        foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) {
393
-            $feedback_message_array[] = sprintf(
394
-                __("Migrated %d records successfully during %s", "event_espresso"),
395
-                $num_records_migrated,
396
-                $migration_stage_name
397
-            );
398
-        }
399
-        $this->_feedback_message .= implode("<br>", $feedback_message_array);
400
-    }
401
-
402
-
403
-    /**
404
-     * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration
405
-     * (if $before==false). Buffers their outputs and stores them on the class.
406
-     *
407
-     * @param boolean $before
408
-     * @throws Exception
409
-     * @return void
410
-     */
411
-    private function _maybe_do_schema_changes($before = true)
412
-    {
413
-        // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
414
-        $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
415
-        if (! $this->{$property_name}) {
416
-            try {
417
-                ob_start();
418
-                if ($before) {
419
-                    $this->schema_changes_before_migration();
420
-                } else {
421
-                    $this->schema_changes_after_migration();
422
-                }
423
-                $output = ob_get_contents();
424
-                ob_end_clean();
425
-            } catch (Exception $e) {
426
-                $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
427
-                throw $e;
428
-            }
429
-            // record that we've done these schema changes
430
-            $this->{$property_name} = true;
431
-            // if there were any warnings etc, record them as non-fatal errors
432
-            if ($output) {
433
-                // there were some warnings
434
-                $this->_errors[] = $output;
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * Wrapper for EEH_Activation::create_table. However, takes into account the request type when
442
-     * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead
443
-     * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to
444
-     * or
445
-     * activated currently. If this is a brand new activation or a migration, and we're indicating this table should
446
-     * not
447
-     * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this
448
-     * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table
449
-     * should be nuked.
450
-     *
451
-     * Just for a bit of context, the migration script's db_schema_changes_* methods
452
-     * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the
453
-     * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was
454
-     * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should
455
-     * be dropped), and during a migration when we're moving the DB to the state of the migration script
456
-     *
457
-     * @param string $table_name
458
-     * @param string $table_definition_sql
459
-     * @param string $engine_string
460
-     */
461
-    protected function _table_is_new_in_this_version(
462
-        $table_name,
463
-        $table_definition_sql,
464
-        $engine_string = 'ENGINE=InnoDB '
465
-    ) {
466
-        $this->_create_table_and_catch_errors(
467
-            $table_name,
468
-            $table_definition_sql,
469
-            $engine_string,
470
-            $this->_pre_existing_table_should_be_dropped(true)
471
-        );
472
-    }
473
-
474
-    /**
475
-     * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table
476
-     * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not
477
-     * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is
478
-     * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as
479
-     * _table_should_exist_previously.
480
-     * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the
481
-     * table shouldn't exist).
482
-     *
483
-     * @param string $table_name
484
-     * @param string $table_definition_sql
485
-     * @param string $engine_string
486
-     */
487
-    protected function _table_is_changed_in_this_version(
488
-        $table_name,
489
-        $table_definition_sql,
490
-        $engine_string = 'ENGINE=MyISAM'
491
-    ) {
492
-        $this->_create_table_and_catch_errors(
493
-            $table_name,
494
-            $table_definition_sql,
495
-            $engine_string,
496
-            $this->_pre_existing_table_should_be_dropped(false)
497
-        );
498
-    }
499
-
500
-
501
-    /**
502
-     * _old_table_exists
503
-     * returns TRUE if the requested table exists in the current database
504
-     *
505
-     * @param string $table_name
506
-     * @return boolean
507
-     */
508
-    protected function _old_table_exists($table_name)
509
-    {
510
-        return $this->_get_table_analysis()->tableExists($table_name);
511
-    }
512
-
513
-
514
-    /**
515
-     * _delete_table_if_empty
516
-     * returns TRUE if the requested table was empty and successfully empty
517
-     *
518
-     * @param string $table_name
519
-     * @return boolean
520
-     */
521
-    protected function _delete_table_if_empty($table_name)
522
-    {
523
-        return EEH_Activation::delete_db_table_if_empty($table_name);
524
-    }
525
-
526
-
527
-    /**
528
-     * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version
529
-     * as these are significantly more efficient or explicit.
530
-     * Please see description of _table_is_new_in_this_version. This function will only set
531
-     * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand
532
-     * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin"
533
-     * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually
534
-     * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table
535
-     * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then
536
-     * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations
537
-     * because apparently it hasn't changed since the previous one, right?
538
-     *
539
-     * @param string $table_name
540
-     * @param string $table_definition_sql
541
-     * @param string $engine_string
542
-     */
543
-    protected function _table_should_exist_previously(
544
-        $table_name,
545
-        $table_definition_sql,
546
-        $engine_string = 'ENGINE=MyISAM'
547
-    ) {
548
-        $this->_create_table_and_catch_errors(
549
-            $table_name,
550
-            $table_definition_sql,
551
-            $engine_string,
552
-            $this->_pre_existing_table_should_be_dropped(false)
553
-        );
554
-    }
555
-
556
-    /**
557
-     * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing
558
-     * a migration, we skip checking this table's structure in the database and just assume it's correct.
559
-     * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs,
560
-     * but important for multisite where migrations can take a very long time otherwise).
561
-     * If the table is known to have changed since previous version, use _table_is_changed_in_this_version().
562
-     * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table
563
-     * shouldn't exist).
564
-     *
565
-     * @param string $table_name
566
-     * @param string $table_definition_sql
567
-     * @param string $engine_string
568
-     */
569
-    protected function _table_has_not_changed_since_previous(
570
-        $table_name,
571
-        $table_definition_sql,
572
-        $engine_string = 'ENGINE=MyISAM'
573
-    ) {
574
-        if ($this->_currently_migrating()) {
575
-            // if we're doing a migration, and this table apparently already exists, then we don't need do anything right?
576
-            return;
577
-        }
578
-        $this->_create_table_and_catch_errors(
579
-            $table_name,
580
-            $table_definition_sql,
581
-            $engine_string,
582
-            $this->_pre_existing_table_should_be_dropped(false)
583
-        );
584
-    }
585
-
586
-    /**
587
-     * Returns whether or not this migration script is being used as part of an actual migration
588
-     *
589
-     * @return boolean
590
-     */
591
-    protected function _currently_migrating()
592
-    {
593
-        // we want to know if we are currently performing a migration. We could just believe what was set on the _migrating property, but let's double-check (ie the script should apply and we should be in MM)
594
-        return $this->_migrating &&
595
-               $this->can_migrate_from_version(
596
-                   EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set()
597
-               ) &&
598
-               EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance;
599
-    }
600
-
601
-    /**
602
-     * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new,
603
-     * and the plugin's request type.
604
-     * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table
605
-     * shouldn't exist no matter what).
606
-     *
607
-     * @param boolean $table_is_new
608
-     * @return boolean
609
-     */
610
-    protected function _pre_existing_table_should_be_dropped($table_is_new)
611
-    {
612
-        if ($table_is_new) {
613
-            if ($this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation
614
-                || $this->_currently_migrating()
615
-            ) {
616
-                return true;
617
-            } else {
618
-                return false;
619
-            }
620
-        } else {
621
-            if (in_array(
622
-                $this->_get_req_type_for_plugin_corresponding_to_this_dms(),
623
-                array(EE_System::req_type_new_activation)
624
-            )) {
625
-                return true;
626
-            } else {
627
-                return false;
628
-            }
629
-        }
630
-    }
631
-
632
-    /**
633
-     * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS
634
-     *
635
-     * @param string  $table_name
636
-     * @param string  $table_definition_sql
637
-     * @param string  $engine_string
638
-     * @param boolean $drop_pre_existing_tables
639
-     */
640
-    private function _create_table_and_catch_errors(
641
-        $table_name,
642
-        $table_definition_sql,
643
-        $engine_string = 'ENGINE=MyISAM',
644
-        $drop_pre_existing_tables = false
645
-    ) {
646
-        try {
647
-            EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
648
-        } catch (EE_Error $e) {
649
-            $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
650
-            $this->add_error($message);
651
-            $this->_feedback_message .= $message;
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * Gets the request type for the plugin (core or addon) that corresponds to this DMS
658
-     *
659
-     * @return int one of EE_System::_req_type_* constants
660
-     * @throws EE_Error
661
-     */
662
-    private function _get_req_type_for_plugin_corresponding_to_this_dms()
663
-    {
664
-        if ($this->slug() == 'Core') {
665
-            return EE_System::instance()->detect_req_type();
666
-        } else {// it must be for an addon
667
-            $addon_name = $this->slug();
668
-            if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
669
-                return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
670
-            } else {
671
-                throw new EE_Error(
672
-                    sprintf(
673
-                        __(
674
-                            "The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s",
675
-                            "event_espresso"
676
-                        ),
677
-                        $this->slug(),
678
-                        $addon_name,
679
-                        implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))
680
-                    )
681
-                );
682
-            }
683
-        }
684
-    }
685
-
686
-
687
-    /**
688
-     * returns an array of strings describing errors by all the script's stages
689
-     *
690
-     * @return array
691
-     */
692
-    public function get_errors()
693
-    {
694
-        $all_errors = $this->_errors;
695
-        if (! is_array($all_errors)) {
696
-            $all_errors = array();
697
-        }
698
-        foreach ($this->stages() as $stage) {
699
-            $all_errors = array_merge($stage->get_errors(), $all_errors);
700
-        }
701
-        return $all_errors;
702
-    }
703
-
704
-
705
-    /**
706
-     * Indicates whether or not this migration script should continue
707
-     *
708
-     * @return boolean
709
-     */
710
-    public function can_continue()
711
-    {
712
-        return in_array(
713
-            $this->get_status(),
714
-            EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script
715
-        );
716
-    }
717
-
718
-
719
-    /**
720
-     * Gets all the data migration stages associated with this script. Note:
721
-     * addons can filter this list to add their own stages, and because the list is
722
-     * numerically-indexed, they can insert their stage wherever they like and it will
723
-     * get ordered by the indexes
724
-     *
725
-     * @return EE_Data_Migration_Script_Stage[]
726
-     */
727
-    protected function stages()
728
-    {
729
-        $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
730
-        ksort($stages);
731
-        return $stages;
732
-    }
733
-
734
-
735
-    /**
736
-     * Gets a string which should describe what's going on currently with this migration, which
737
-     * can be displayed to the user
738
-     *
739
-     * @return string
740
-     */
741
-    public function get_feedback_message()
742
-    {
743
-        return $this->_feedback_message;
744
-    }
745
-
746
-
747
-    /**
748
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
749
-     * properties to the DB. However, we don't want to use __sleep() because its quite
750
-     * possible that this class is defined when it goes to sleep, but NOT available when it
751
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
752
-     */
753
-    public function properties_as_array()
754
-    {
755
-        $properties = parent::properties_as_array();
756
-        $properties['_migration_stages'] = array();
757
-        foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
758
-            $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
759
-            );
760
-        }
761
-        unset($properties['_mappings']);
762
-
763
-        foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) {
764
-            foreach ($mapping_to_new_table as $new_table_name => $mapping) {
765
-                $this->_set_mapping_option($old_table_name, $new_table_name, $mapping);
766
-            }
767
-        }
768
-        return $properties;
769
-    }
770
-
771
-
772
-    /**
773
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
774
-     * to have been made from the properties_as_array() function.
775
-     *
776
-     * @param array $array_of_properties like what's produced from properties_as_array() method
777
-     * @return void
778
-     */
779
-    public function instantiate_from_array_of_properties($array_of_properties)
780
-    {
781
-        $stages_properties_arrays = $array_of_properties['_migration_stages'];
782
-        unset($array_of_properties['_migration_stages']);
783
-        unset($array_of_properties['class']);
784
-        foreach ($array_of_properties as $property_name => $property_value) {
785
-            $this->{$property_name} = $property_value;
786
-        }
787
-        // _migration_stages are already instantiated, but have only default data
788
-        foreach ($this->_migration_stages as $stage) {
789
-            $stage_data = $this->_find_migration_stage_data_with_classname(
790
-                get_class($stage),
791
-                $stages_properties_arrays
792
-            );
793
-            // SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by
794
-            // an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet)
795
-            if ($stage_data) {
796
-                $stage->instantiate_from_array_of_properties($stage_data);
797
-            }
798
-        }
799
-    }
800
-
801
-
802
-    /**
803
-     * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which
804
-     * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes)
805
-     * for the given classname
806
-     *
807
-     * @param string $classname
808
-     * @param array  $migration_stage_data_arrays
809
-     * @return null
810
-     */
811
-    private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays)
812
-    {
813
-        foreach ($migration_stage_data_arrays as $migration_stage_data_array) {
814
-            if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) {
815
-                return $migration_stage_data_array;
816
-            }
817
-        }
818
-        return null;
819
-    }
820
-
821
-
822
-    /**
823
-     * Returns the version that this script migrates to, based on the script's name.
824
-     * Cannot be overwritten because lots of code needs to know which version a script
825
-     * migrates to knowing only its name.
826
-     *
827
-     * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin
828
-     * that will be updated to. Eg array('Core','4.1.0')
829
-     */
830
-    final public function migrates_to_version()
831
-    {
832
-        return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
833
-    }
834
-
835
-
836
-    /**
837
-     * Gets this addon's slug as it would appear in the current_db_state wp option,
838
-     * and if this migration script is for an addon, it SHOULD match the addon's slug
839
-     * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon.
840
-     * Or 'Core' for core (non-addon).
841
-     *
842
-     * @return string
843
-     */
844
-    public function slug()
845
-    {
846
-        $migrates_to_version_info = $this->migrates_to_version();
847
-        // the slug is the first part of the array
848
-        return $migrates_to_version_info['slug'];
849
-    }
850
-
851
-
852
-    /**
853
-     * Returns the script's priority relative to DMSs from other addons. However, when
854
-     * two DMSs from the same addon/core apply, this is ignored (and instead the version that
855
-     * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs
856
-     * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons,
857
-     * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set
858
-     * the database up so it can run), then you can set "A" to priority 3 or something.
859
-     *
860
-     * @return int
861
-     */
862
-    public function priority()
863
-    {
864
-        return $this->_priority;
865
-    }
866
-
867
-
868
-    /**
869
-     * Sets whether or not this DMS is being ran as part of a migration, instead of
870
-     * just being used to setup (or verify) the current database structure matches
871
-     * what the latest DMS indicates it should be
872
-     *
873
-     * @param boolean $migrating
874
-     * @return void
875
-     */
876
-    public function set_migrating($migrating = true)
877
-    {
878
-        $this->_migrating = $migrating;
879
-    }
880
-
881
-    /**
882
-     * Marks that we think this migration class can continue to migrate
883
-     */
884
-    public function reattempt()
885
-    {
886
-        parent::reattempt();
887
-        // also, we want to reattempt any stages that were marked as borked
888
-        foreach ($this->stages() as $stage) {
889
-            if ($stage->is_broken()) {
890
-                $stage->reattempt();
891
-            }
892
-        }
893
-    }
18
+	/**
19
+	 * Set by client code to indicate this DMS is being ran as part of a proper migration,
20
+	 * instead of being used to merely setup (or verify) the database structure.
21
+	 * Defaults to TRUE, so client code that's NOT using this DMS as part of a proper migration
22
+	 * should call EE_Data_Migration_Script_Base::set_migrating( FALSE )
23
+	 *
24
+	 * @var boolean
25
+	 */
26
+	protected $_migrating = true;
27
+
28
+	/**
29
+	 * numerically-indexed array where each value is EE_Data_Migration_Script_Stage object
30
+	 *
31
+	 * @var EE_Data_Migration_Script_Stage[] $migration_functions
32
+	 */
33
+	protected $_migration_stages = array();
34
+
35
+	/**
36
+	 * Indicates we've already ran the schema changes that needed to happen BEFORE the data migration
37
+	 *
38
+	 * @var boolean
39
+	 */
40
+	protected $_schema_changes_before_migration_ran = null;
41
+
42
+	/**
43
+	 * Indicates we've already ran the schema changes that needed to happen AFTER the data migration
44
+	 *
45
+	 * @var boolean
46
+	 */
47
+	protected $_schema_changes_after_migration_ran = null;
48
+
49
+	/**
50
+	 * String which describes what's currently happening in this migration
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_feedback_message;
55
+
56
+	/**
57
+	 * Indicates the script's priority. Like wp's add_action and add_filter, lower numbers
58
+	 * correspond to earlier execution
59
+	 *
60
+	 * @var int
61
+	 */
62
+	protected $_priority = 5;
63
+
64
+	/**
65
+	 * Multi-dimensional array that defines the mapping from OLD table Primary Keys
66
+	 * to NEW table Primary Keys.
67
+	 * Top-level array keys are OLD table names (minus the "wp_" part),
68
+	 * 2nd-level array keys are NEW table names (again, minus the "wp_" part),
69
+	 * 3rd-level array keys are the OLD table primary keys
70
+	 * and 3rd-level array values are the NEW table primary keys
71
+	 *
72
+	 * @var array
73
+	 */
74
+	protected $_mappings = array();
75
+
76
+
77
+	/**
78
+	 * Returns whether or not this data migration script can operate on the given version of the database.
79
+	 * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
80
+	 * it's passed a string like '3.1.38B', it should return true.
81
+	 * If this DMS is to migrate data from an EE3 addon, you will probably want to use
82
+	 * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and
83
+	 * EE_Data_Migration_Manager::get_migration_ran() to check that core was already
84
+	 * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated
85
+	 * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want
86
+	 * to run this DMS).
87
+	 * If this DMS migrates data from a previous version of this EE4 addon, just
88
+	 * comparing $current_database_state_of[ $this->slug() ] will probably suffice.
89
+	 * If this DMS should never migrate data, because it's only used to define the initial
90
+	 * database state, just return FALSE (and core's activation process will take care
91
+	 * of calling its schema_changes_before_migration() and
92
+	 * schema_changes_after_migration() for you. )
93
+	 *
94
+	 * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc)
95
+	 * @return boolean
96
+	 */
97
+	abstract public function can_migrate_from_version($current_database_state_of);
98
+
99
+
100
+	/**
101
+	 * Performs database schema changes that need to occur BEFORE the data is migrated.
102
+	 * Eg, if we were going to change user passwords from plaintext to encoded versions
103
+	 * during this migration, this would probably add a new column called something like
104
+	 * "encoded_password".
105
+	 *
106
+	 * @return boolean of success
107
+	 */
108
+	abstract public function schema_changes_before_migration();
109
+
110
+
111
+	/**
112
+	 * Performs the database schema changes that need to occur AFTER the data has been migrated.
113
+	 * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords
114
+	 * from plaintext to encoded versions, and we had added a column called "encoded_password",
115
+	 * this function would probably remove the old column "password" (which still holds the plaintext password)
116
+	 * and possibly rename "encoded_password" to "password"
117
+	 *
118
+	 * @return boolean of success
119
+	 */
120
+	abstract public function schema_changes_after_migration();
121
+
122
+
123
+	/**
124
+	 * All children of this must call parent::__construct()
125
+	 * at the end of their constructor or suffer the consequences!
126
+	 *
127
+	 * @param TableManager  $table_manager
128
+	 * @param TableAnalysis $table_analysis
129
+	 */
130
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
131
+	{
132
+		$this->_migration_stages = (array) apply_filters(
133
+			'FHEE__' . get_class($this) . '__construct__migration_stages',
134
+			$this->_migration_stages
135
+		);
136
+		foreach ($this->_migration_stages as $migration_stage) {
137
+			if ($migration_stage instanceof EE_Data_Migration_Script_Stage) {
138
+				$migration_stage->_construct_finalize($this);
139
+			}
140
+		}
141
+		parent::__construct($table_manager, $table_analysis);
142
+	}
143
+
144
+
145
+	/**
146
+	 * Place to add hooks and filters for tweaking the migrations page, in order
147
+	 * to customize it
148
+	 */
149
+	public function migration_page_hooks()
150
+	{
151
+		// by default none are added because we normally like the default look of the migration page
152
+	}
153
+
154
+
155
+	/**
156
+	 * Sets the mapping from old table primary keys to new table primary keys.
157
+	 * This mapping is automatically persisted as a property on the migration
158
+	 *
159
+	 * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
160
+	 * @param int|string $old_pk    old primary key. Eg events_detail.id's value
161
+	 * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
162
+	 * @param int|string $new_pk    eg posts.ID
163
+	 * @return void
164
+	 */
165
+	public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
166
+	{
167
+		// make sure it has the needed keys
168
+		if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
169
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
170
+		}
171
+		$this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
172
+	}
173
+
174
+
175
+	/**
176
+	 * Gets the new primary key, if provided with the OLD table and the primary key
177
+	 * of an item in the old table, and the new table
178
+	 *
179
+	 * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
180
+	 * @param int|string $old_pk    old primary key. Eg events_detail.id's value
181
+	 * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
182
+	 * @return mixed the primary key on the new table
183
+	 */
184
+	public function get_mapping_new_pk($old_table, $old_pk, $new_table)
185
+	{
186
+		if (! isset($this->_mappings[ $old_table ]) ||
187
+			! isset($this->_mappings[ $old_table ][ $new_table ])) {
188
+			// try fetching the option
189
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
190
+		}
191
+		return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
192
+			? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
193
+	}
194
+
195
+
196
+	/**
197
+	 * Gets the old primary key, if provided with the OLD table,
198
+	 * and the new table and the primary key of an item in the new table
199
+	 *
200
+	 * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail
201
+	 * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts
202
+	 * @param mixed  $new_pk
203
+	 * @return mixed
204
+	 */
205
+	public function get_mapping_old_pk($old_table, $new_table, $new_pk)
206
+	{
207
+		if (! isset($this->_mappings[ $old_table ]) ||
208
+			! isset($this->_mappings[ $old_table ][ $new_table ])) {
209
+			// try fetching the option
210
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
211
+		}
212
+		if (isset($this->_mappings[ $old_table ][ $new_table ])) {
213
+			$new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
214
+			if (isset($new_pk_to_old_pk[ $new_pk ])) {
215
+				return $new_pk_to_old_pk[ $new_pk ];
216
+			}
217
+		}
218
+		return null;
219
+	}
220
+
221
+
222
+	/**
223
+	 * Gets the mapping array option specified by the table names
224
+	 *
225
+	 * @param string $old_table_name
226
+	 * @param string $new_table_name
227
+	 * @return array
228
+	 */
229
+	protected function _get_mapping_option($old_table_name, $new_table_name)
230
+	{
231
+		$option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array());
232
+		return $option;
233
+	}
234
+
235
+
236
+	/**
237
+	 * Updates the mapping option specified by the table names with the array provided
238
+	 *
239
+	 * @param string $old_table_name
240
+	 * @param string $new_table_name
241
+	 * @param array  $mapping_array
242
+	 * @return boolean success of updating option
243
+	 */
244
+	protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array)
245
+	{
246
+		$success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array);
247
+		return $success;
248
+	}
249
+
250
+
251
+	/**
252
+	 * Gets the option name for this script to map from $old_table_name to $new_table_name
253
+	 *
254
+	 * @param string $old_table_name
255
+	 * @param string $new_table_name
256
+	 * @return string
257
+	 */
258
+	protected function _get_mapping_option_name($old_table_name, $new_table_name)
259
+	{
260
+		global $wpdb;
261
+		$old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name);
262
+		$new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
263
+		$migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
264
+		return substr(
265
+			EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp,
266
+			0,
267
+			64
268
+		);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Counts all the records that will be migrated during this data migration.
274
+	 * For example, if we were changing old user passwords from plaintext to encoded versions,
275
+	 * this would be a count of all users who have passwords. If we were going to also split
276
+	 * attendee records into transactions, registrations, and attendee records, this would include
277
+	 * the count of all attendees currently in existence in the DB (ie, users + attendees).
278
+	 * If you can't determine how many records there are to migrate, just provide a guess: this
279
+	 * number will only be used in calculating the percent complete. If you estimate there to be
280
+	 * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at
281
+	 * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete.
282
+	 *
283
+	 * @return int
284
+	 */
285
+	protected function _count_records_to_migrate()
286
+	{
287
+		$count = 0;
288
+		foreach ($this->stages() as $stage) {
289
+			$count += $stage->count_records_to_migrate();
290
+		}
291
+		return $count;
292
+	}
293
+
294
+
295
+	/**
296
+	 * Returns the number of records updated so far. Usually this is easiest to do
297
+	 * by just setting a transient and updating it after each migration_step
298
+	 *
299
+	 * @return int
300
+	 */
301
+	public function count_records_migrated()
302
+	{
303
+		$count = 0;
304
+		foreach ($this->stages() as $stage) {
305
+			$count += $stage->count_records_migrated();
306
+		}
307
+		$this->_records_migrated = $count;
308
+		return $count;
309
+	}
310
+
311
+
312
+	/**
313
+	 * @param int $num_records_to_migrate_limit
314
+	 * @return int
315
+	 * @throws EE_Error
316
+	 * @throws Exception
317
+	 */
318
+	public function migration_step($num_records_to_migrate_limit)
319
+	{
320
+		// reset the feedback message
321
+		$this->_feedback_message = '';
322
+		// if we haven't yet done the 1st schema changes, do them now. buffer any output
323
+		$this->_maybe_do_schema_changes(true);
324
+
325
+		$num_records_actually_migrated = 0;
326
+		$records_migrated_per_stage = array();
327
+		// setup the 'stage' variable, which should hold the last run stage of the migration  (or none at all if nothing runs)
328
+		$stage = null;
329
+		// get the next stage that isn't complete
330
+		foreach ($this->stages() as $stage) {
331
+			if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) {
332
+				try {
333
+					$records_migrated_during_stage = $stage->migration_step(
334
+						$num_records_to_migrate_limit - $num_records_actually_migrated
335
+					);
336
+					$num_records_actually_migrated += $records_migrated_during_stage;
337
+					$records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
338
+				} catch (Exception $e) {
339
+					// yes if we catch an exception here, we consider that migration stage borked.
340
+					$stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
341
+					$this->set_status(EE_Data_Migration_Manager::status_fatal_error);
342
+					$stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
343
+					throw $e;
344
+				}
345
+				// check that the migration stage didn't mark itself as having a fatal error
346
+				if ($stage->is_broken()) {
347
+					$this->set_broken();
348
+					throw new EE_Error($stage->get_last_error());
349
+				}
350
+			}
351
+			// once we've migrated all the number we intended to (possibly from different stages), stop migrating
352
+			// or if we had a fatal error
353
+			// or if the current script stopped early- its not done, but it's done all it thinks we should do on this step
354
+			if ($num_records_actually_migrated >= $num_records_to_migrate_limit
355
+				|| $stage->is_broken()
356
+				|| $stage->has_more_to_do()
357
+			) {
358
+				break;
359
+			}
360
+		}
361
+		// check if we're all done this data migration...
362
+		// which is indicated by being done early AND the last stage claims to be done
363
+		if ($stage == null) {
364
+			// this migration script apparently has NO stages... which is super weird, but whatever
365
+			$this->set_completed();
366
+			$this->_maybe_do_schema_changes(false);
367
+		} elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) {
368
+			// apparently we're done, because we couldn't migrate the number we intended to
369
+			$this->set_completed();
370
+			$this->_update_feedback_message(array_reverse($records_migrated_per_stage));
371
+			// do schema changes for after the migration now
372
+			// first double-check we haven't already done this
373
+			$this->_maybe_do_schema_changes(false);
374
+		} else {
375
+			// update feedback message, keeping in mind that we show them with the most recent at the top
376
+			$this->_update_feedback_message(array_reverse($records_migrated_per_stage));
377
+		}
378
+		return $num_records_actually_migrated;
379
+	}
380
+
381
+
382
+	/**
383
+	 * Updates the feedback message according to what was done during this migration stage.
384
+	 *
385
+	 * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records
386
+	 *                                          migrated from that stage
387
+	 * @return void
388
+	 */
389
+	private function _update_feedback_message($records_migrated_per_stage)
390
+	{
391
+		$feedback_message_array = array();
392
+		foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) {
393
+			$feedback_message_array[] = sprintf(
394
+				__("Migrated %d records successfully during %s", "event_espresso"),
395
+				$num_records_migrated,
396
+				$migration_stage_name
397
+			);
398
+		}
399
+		$this->_feedback_message .= implode("<br>", $feedback_message_array);
400
+	}
401
+
402
+
403
+	/**
404
+	 * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration
405
+	 * (if $before==false). Buffers their outputs and stores them on the class.
406
+	 *
407
+	 * @param boolean $before
408
+	 * @throws Exception
409
+	 * @return void
410
+	 */
411
+	private function _maybe_do_schema_changes($before = true)
412
+	{
413
+		// so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
414
+		$property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
415
+		if (! $this->{$property_name}) {
416
+			try {
417
+				ob_start();
418
+				if ($before) {
419
+					$this->schema_changes_before_migration();
420
+				} else {
421
+					$this->schema_changes_after_migration();
422
+				}
423
+				$output = ob_get_contents();
424
+				ob_end_clean();
425
+			} catch (Exception $e) {
426
+				$this->set_status(EE_Data_Migration_Manager::status_fatal_error);
427
+				throw $e;
428
+			}
429
+			// record that we've done these schema changes
430
+			$this->{$property_name} = true;
431
+			// if there were any warnings etc, record them as non-fatal errors
432
+			if ($output) {
433
+				// there were some warnings
434
+				$this->_errors[] = $output;
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * Wrapper for EEH_Activation::create_table. However, takes into account the request type when
442
+	 * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead
443
+	 * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to
444
+	 * or
445
+	 * activated currently. If this is a brand new activation or a migration, and we're indicating this table should
446
+	 * not
447
+	 * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this
448
+	 * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table
449
+	 * should be nuked.
450
+	 *
451
+	 * Just for a bit of context, the migration script's db_schema_changes_* methods
452
+	 * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the
453
+	 * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was
454
+	 * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should
455
+	 * be dropped), and during a migration when we're moving the DB to the state of the migration script
456
+	 *
457
+	 * @param string $table_name
458
+	 * @param string $table_definition_sql
459
+	 * @param string $engine_string
460
+	 */
461
+	protected function _table_is_new_in_this_version(
462
+		$table_name,
463
+		$table_definition_sql,
464
+		$engine_string = 'ENGINE=InnoDB '
465
+	) {
466
+		$this->_create_table_and_catch_errors(
467
+			$table_name,
468
+			$table_definition_sql,
469
+			$engine_string,
470
+			$this->_pre_existing_table_should_be_dropped(true)
471
+		);
472
+	}
473
+
474
+	/**
475
+	 * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table
476
+	 * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not
477
+	 * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is
478
+	 * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as
479
+	 * _table_should_exist_previously.
480
+	 * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the
481
+	 * table shouldn't exist).
482
+	 *
483
+	 * @param string $table_name
484
+	 * @param string $table_definition_sql
485
+	 * @param string $engine_string
486
+	 */
487
+	protected function _table_is_changed_in_this_version(
488
+		$table_name,
489
+		$table_definition_sql,
490
+		$engine_string = 'ENGINE=MyISAM'
491
+	) {
492
+		$this->_create_table_and_catch_errors(
493
+			$table_name,
494
+			$table_definition_sql,
495
+			$engine_string,
496
+			$this->_pre_existing_table_should_be_dropped(false)
497
+		);
498
+	}
499
+
500
+
501
+	/**
502
+	 * _old_table_exists
503
+	 * returns TRUE if the requested table exists in the current database
504
+	 *
505
+	 * @param string $table_name
506
+	 * @return boolean
507
+	 */
508
+	protected function _old_table_exists($table_name)
509
+	{
510
+		return $this->_get_table_analysis()->tableExists($table_name);
511
+	}
512
+
513
+
514
+	/**
515
+	 * _delete_table_if_empty
516
+	 * returns TRUE if the requested table was empty and successfully empty
517
+	 *
518
+	 * @param string $table_name
519
+	 * @return boolean
520
+	 */
521
+	protected function _delete_table_if_empty($table_name)
522
+	{
523
+		return EEH_Activation::delete_db_table_if_empty($table_name);
524
+	}
525
+
526
+
527
+	/**
528
+	 * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version
529
+	 * as these are significantly more efficient or explicit.
530
+	 * Please see description of _table_is_new_in_this_version. This function will only set
531
+	 * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand
532
+	 * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin"
533
+	 * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually
534
+	 * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table
535
+	 * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then
536
+	 * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations
537
+	 * because apparently it hasn't changed since the previous one, right?
538
+	 *
539
+	 * @param string $table_name
540
+	 * @param string $table_definition_sql
541
+	 * @param string $engine_string
542
+	 */
543
+	protected function _table_should_exist_previously(
544
+		$table_name,
545
+		$table_definition_sql,
546
+		$engine_string = 'ENGINE=MyISAM'
547
+	) {
548
+		$this->_create_table_and_catch_errors(
549
+			$table_name,
550
+			$table_definition_sql,
551
+			$engine_string,
552
+			$this->_pre_existing_table_should_be_dropped(false)
553
+		);
554
+	}
555
+
556
+	/**
557
+	 * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing
558
+	 * a migration, we skip checking this table's structure in the database and just assume it's correct.
559
+	 * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs,
560
+	 * but important for multisite where migrations can take a very long time otherwise).
561
+	 * If the table is known to have changed since previous version, use _table_is_changed_in_this_version().
562
+	 * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table
563
+	 * shouldn't exist).
564
+	 *
565
+	 * @param string $table_name
566
+	 * @param string $table_definition_sql
567
+	 * @param string $engine_string
568
+	 */
569
+	protected function _table_has_not_changed_since_previous(
570
+		$table_name,
571
+		$table_definition_sql,
572
+		$engine_string = 'ENGINE=MyISAM'
573
+	) {
574
+		if ($this->_currently_migrating()) {
575
+			// if we're doing a migration, and this table apparently already exists, then we don't need do anything right?
576
+			return;
577
+		}
578
+		$this->_create_table_and_catch_errors(
579
+			$table_name,
580
+			$table_definition_sql,
581
+			$engine_string,
582
+			$this->_pre_existing_table_should_be_dropped(false)
583
+		);
584
+	}
585
+
586
+	/**
587
+	 * Returns whether or not this migration script is being used as part of an actual migration
588
+	 *
589
+	 * @return boolean
590
+	 */
591
+	protected function _currently_migrating()
592
+	{
593
+		// we want to know if we are currently performing a migration. We could just believe what was set on the _migrating property, but let's double-check (ie the script should apply and we should be in MM)
594
+		return $this->_migrating &&
595
+			   $this->can_migrate_from_version(
596
+				   EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set()
597
+			   ) &&
598
+			   EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance;
599
+	}
600
+
601
+	/**
602
+	 * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new,
603
+	 * and the plugin's request type.
604
+	 * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table
605
+	 * shouldn't exist no matter what).
606
+	 *
607
+	 * @param boolean $table_is_new
608
+	 * @return boolean
609
+	 */
610
+	protected function _pre_existing_table_should_be_dropped($table_is_new)
611
+	{
612
+		if ($table_is_new) {
613
+			if ($this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation
614
+				|| $this->_currently_migrating()
615
+			) {
616
+				return true;
617
+			} else {
618
+				return false;
619
+			}
620
+		} else {
621
+			if (in_array(
622
+				$this->_get_req_type_for_plugin_corresponding_to_this_dms(),
623
+				array(EE_System::req_type_new_activation)
624
+			)) {
625
+				return true;
626
+			} else {
627
+				return false;
628
+			}
629
+		}
630
+	}
631
+
632
+	/**
633
+	 * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS
634
+	 *
635
+	 * @param string  $table_name
636
+	 * @param string  $table_definition_sql
637
+	 * @param string  $engine_string
638
+	 * @param boolean $drop_pre_existing_tables
639
+	 */
640
+	private function _create_table_and_catch_errors(
641
+		$table_name,
642
+		$table_definition_sql,
643
+		$engine_string = 'ENGINE=MyISAM',
644
+		$drop_pre_existing_tables = false
645
+	) {
646
+		try {
647
+			EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
648
+		} catch (EE_Error $e) {
649
+			$message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
650
+			$this->add_error($message);
651
+			$this->_feedback_message .= $message;
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * Gets the request type for the plugin (core or addon) that corresponds to this DMS
658
+	 *
659
+	 * @return int one of EE_System::_req_type_* constants
660
+	 * @throws EE_Error
661
+	 */
662
+	private function _get_req_type_for_plugin_corresponding_to_this_dms()
663
+	{
664
+		if ($this->slug() == 'Core') {
665
+			return EE_System::instance()->detect_req_type();
666
+		} else {// it must be for an addon
667
+			$addon_name = $this->slug();
668
+			if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
669
+				return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
670
+			} else {
671
+				throw new EE_Error(
672
+					sprintf(
673
+						__(
674
+							"The DMS slug '%s' should correspond to the addon's name, which should also be '%s', but no such addon was registered. These are the registered addons' names: %s",
675
+							"event_espresso"
676
+						),
677
+						$this->slug(),
678
+						$addon_name,
679
+						implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))
680
+					)
681
+				);
682
+			}
683
+		}
684
+	}
685
+
686
+
687
+	/**
688
+	 * returns an array of strings describing errors by all the script's stages
689
+	 *
690
+	 * @return array
691
+	 */
692
+	public function get_errors()
693
+	{
694
+		$all_errors = $this->_errors;
695
+		if (! is_array($all_errors)) {
696
+			$all_errors = array();
697
+		}
698
+		foreach ($this->stages() as $stage) {
699
+			$all_errors = array_merge($stage->get_errors(), $all_errors);
700
+		}
701
+		return $all_errors;
702
+	}
703
+
704
+
705
+	/**
706
+	 * Indicates whether or not this migration script should continue
707
+	 *
708
+	 * @return boolean
709
+	 */
710
+	public function can_continue()
711
+	{
712
+		return in_array(
713
+			$this->get_status(),
714
+			EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script
715
+		);
716
+	}
717
+
718
+
719
+	/**
720
+	 * Gets all the data migration stages associated with this script. Note:
721
+	 * addons can filter this list to add their own stages, and because the list is
722
+	 * numerically-indexed, they can insert their stage wherever they like and it will
723
+	 * get ordered by the indexes
724
+	 *
725
+	 * @return EE_Data_Migration_Script_Stage[]
726
+	 */
727
+	protected function stages()
728
+	{
729
+		$stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
730
+		ksort($stages);
731
+		return $stages;
732
+	}
733
+
734
+
735
+	/**
736
+	 * Gets a string which should describe what's going on currently with this migration, which
737
+	 * can be displayed to the user
738
+	 *
739
+	 * @return string
740
+	 */
741
+	public function get_feedback_message()
742
+	{
743
+		return $this->_feedback_message;
744
+	}
745
+
746
+
747
+	/**
748
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
749
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
750
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
751
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
752
+	 */
753
+	public function properties_as_array()
754
+	{
755
+		$properties = parent::properties_as_array();
756
+		$properties['_migration_stages'] = array();
757
+		foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
758
+			$properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
759
+			);
760
+		}
761
+		unset($properties['_mappings']);
762
+
763
+		foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) {
764
+			foreach ($mapping_to_new_table as $new_table_name => $mapping) {
765
+				$this->_set_mapping_option($old_table_name, $new_table_name, $mapping);
766
+			}
767
+		}
768
+		return $properties;
769
+	}
770
+
771
+
772
+	/**
773
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
774
+	 * to have been made from the properties_as_array() function.
775
+	 *
776
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
777
+	 * @return void
778
+	 */
779
+	public function instantiate_from_array_of_properties($array_of_properties)
780
+	{
781
+		$stages_properties_arrays = $array_of_properties['_migration_stages'];
782
+		unset($array_of_properties['_migration_stages']);
783
+		unset($array_of_properties['class']);
784
+		foreach ($array_of_properties as $property_name => $property_value) {
785
+			$this->{$property_name} = $property_value;
786
+		}
787
+		// _migration_stages are already instantiated, but have only default data
788
+		foreach ($this->_migration_stages as $stage) {
789
+			$stage_data = $this->_find_migration_stage_data_with_classname(
790
+				get_class($stage),
791
+				$stages_properties_arrays
792
+			);
793
+			// SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by
794
+			// an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet)
795
+			if ($stage_data) {
796
+				$stage->instantiate_from_array_of_properties($stage_data);
797
+			}
798
+		}
799
+	}
800
+
801
+
802
+	/**
803
+	 * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which
804
+	 * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes)
805
+	 * for the given classname
806
+	 *
807
+	 * @param string $classname
808
+	 * @param array  $migration_stage_data_arrays
809
+	 * @return null
810
+	 */
811
+	private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays)
812
+	{
813
+		foreach ($migration_stage_data_arrays as $migration_stage_data_array) {
814
+			if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) {
815
+				return $migration_stage_data_array;
816
+			}
817
+		}
818
+		return null;
819
+	}
820
+
821
+
822
+	/**
823
+	 * Returns the version that this script migrates to, based on the script's name.
824
+	 * Cannot be overwritten because lots of code needs to know which version a script
825
+	 * migrates to knowing only its name.
826
+	 *
827
+	 * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin
828
+	 * that will be updated to. Eg array('Core','4.1.0')
829
+	 */
830
+	final public function migrates_to_version()
831
+	{
832
+		return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
833
+	}
834
+
835
+
836
+	/**
837
+	 * Gets this addon's slug as it would appear in the current_db_state wp option,
838
+	 * and if this migration script is for an addon, it SHOULD match the addon's slug
839
+	 * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon.
840
+	 * Or 'Core' for core (non-addon).
841
+	 *
842
+	 * @return string
843
+	 */
844
+	public function slug()
845
+	{
846
+		$migrates_to_version_info = $this->migrates_to_version();
847
+		// the slug is the first part of the array
848
+		return $migrates_to_version_info['slug'];
849
+	}
850
+
851
+
852
+	/**
853
+	 * Returns the script's priority relative to DMSs from other addons. However, when
854
+	 * two DMSs from the same addon/core apply, this is ignored (and instead the version that
855
+	 * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs
856
+	 * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons,
857
+	 * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set
858
+	 * the database up so it can run), then you can set "A" to priority 3 or something.
859
+	 *
860
+	 * @return int
861
+	 */
862
+	public function priority()
863
+	{
864
+		return $this->_priority;
865
+	}
866
+
867
+
868
+	/**
869
+	 * Sets whether or not this DMS is being ran as part of a migration, instead of
870
+	 * just being used to setup (or verify) the current database structure matches
871
+	 * what the latest DMS indicates it should be
872
+	 *
873
+	 * @param boolean $migrating
874
+	 * @return void
875
+	 */
876
+	public function set_migrating($migrating = true)
877
+	{
878
+		$this->_migrating = $migrating;
879
+	}
880
+
881
+	/**
882
+	 * Marks that we think this migration class can continue to migrate
883
+	 */
884
+	public function reattempt()
885
+	{
886
+		parent::reattempt();
887
+		// also, we want to reattempt any stages that were marked as borked
888
+		foreach ($this->stages() as $stage) {
889
+			if ($stage->is_broken()) {
890
+				$stage->reattempt();
891
+			}
892
+		}
893
+	}
894 894
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
131 131
     {
132 132
         $this->_migration_stages = (array) apply_filters(
133
-            'FHEE__' . get_class($this) . '__construct__migration_stages',
133
+            'FHEE__'.get_class($this).'__construct__migration_stages',
134 134
             $this->_migration_stages
135 135
         );
136 136
         foreach ($this->_migration_stages as $migration_stage) {
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
     public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
166 166
     {
167 167
         // make sure it has the needed keys
168
-        if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
169
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
168
+        if ( ! isset($this->_mappings[$old_table]) || ! isset($this->_mappings[$old_table][$new_table])) {
169
+            $this->_mappings[$old_table][$new_table] = $this->_get_mapping_option($old_table, $new_table);
170 170
         }
171
-        $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
171
+        $this->_mappings[$old_table][$new_table][$old_pk] = $new_pk;
172 172
     }
173 173
 
174 174
 
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function get_mapping_new_pk($old_table, $old_pk, $new_table)
185 185
     {
186
-        if (! isset($this->_mappings[ $old_table ]) ||
187
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
186
+        if ( ! isset($this->_mappings[$old_table]) ||
187
+            ! isset($this->_mappings[$old_table][$new_table])) {
188 188
             // try fetching the option
189
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
189
+            $this->_mappings[$old_table][$new_table] = $this->_get_mapping_option($old_table, $new_table);
190 190
         }
191
-        return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
192
-            ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
191
+        return isset($this->_mappings[$old_table][$new_table][$old_pk])
192
+            ? $this->_mappings[$old_table][$new_table][$old_pk] : null;
193 193
     }
194 194
 
195 195
 
@@ -204,15 +204,15 @@  discard block
 block discarded – undo
204 204
      */
205 205
     public function get_mapping_old_pk($old_table, $new_table, $new_pk)
206 206
     {
207
-        if (! isset($this->_mappings[ $old_table ]) ||
208
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
207
+        if ( ! isset($this->_mappings[$old_table]) ||
208
+            ! isset($this->_mappings[$old_table][$new_table])) {
209 209
             // try fetching the option
210
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
210
+            $this->_mappings[$old_table][$new_table] = $this->_get_mapping_option($old_table, $new_table);
211 211
         }
212
-        if (isset($this->_mappings[ $old_table ][ $new_table ])) {
213
-            $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
214
-            if (isset($new_pk_to_old_pk[ $new_pk ])) {
215
-                return $new_pk_to_old_pk[ $new_pk ];
212
+        if (isset($this->_mappings[$old_table][$new_table])) {
213
+            $new_pk_to_old_pk = array_flip($this->_mappings[$old_table][$new_table]);
214
+            if (isset($new_pk_to_old_pk[$new_pk])) {
215
+                return $new_pk_to_old_pk[$new_pk];
216 216
             }
217 217
         }
218 218
         return null;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
         $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
263 263
         $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
264 264
         return substr(
265
-            EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix . $migrates_to ['slug'] . '_' . $migrates_to['version'] . '_' . $old_table_name_sans_wp . '_' . $new_table_name_sans_wp,
265
+            EE_Data_Migration_Manager::data_migration_script_mapping_option_prefix.$migrates_to ['slug'].'_'.$migrates_to['version'].'_'.$old_table_name_sans_wp.'_'.$new_table_name_sans_wp,
266 266
             0,
267 267
             64
268 268
         );
@@ -334,12 +334,12 @@  discard block
 block discarded – undo
334 334
                         $num_records_to_migrate_limit - $num_records_actually_migrated
335 335
                     );
336 336
                     $num_records_actually_migrated += $records_migrated_during_stage;
337
-                    $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
337
+                    $records_migrated_per_stage[$stage->pretty_name()] = $records_migrated_during_stage;
338 338
                 } catch (Exception $e) {
339 339
                     // yes if we catch an exception here, we consider that migration stage borked.
340 340
                     $stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
341 341
                     $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
342
-                    $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
342
+                    $stage->add_error($e->getMessage().". Stack-trace:".$e->getTraceAsString());
343 343
                     throw $e;
344 344
                 }
345 345
                 // check that the migration stage didn't mark itself as having a fatal error
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
     private function _maybe_do_schema_changes($before = true)
412 412
     {
413 413
         // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
414
-        $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
415
-        if (! $this->{$property_name}) {
414
+        $property_name = '_schema_changes_'.($before ? 'before' : 'after').'_migration_ran';
415
+        if ( ! $this->{$property_name}) {
416 416
             try {
417 417
                 ob_start();
418 418
                 if ($before) {
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
         try {
647 647
             EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
648 648
         } catch (EE_Error $e) {
649
-            $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
649
+            $message = $e->getMessage().'<br>Stack Trace:'.$e->getTraceAsString();
650 650
             $this->add_error($message);
651 651
             $this->_feedback_message .= $message;
652 652
         }
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
     public function get_errors()
693 693
     {
694 694
         $all_errors = $this->_errors;
695
-        if (! is_array($all_errors)) {
695
+        if ( ! is_array($all_errors)) {
696 696
             $all_errors = array();
697 697
         }
698 698
         foreach ($this->stages() as $stage) {
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
      */
727 727
     protected function stages()
728 728
     {
729
-        $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
729
+        $stages = apply_filters('FHEE__'.get_class($this).'__stages', $this->_migration_stages);
730 730
         ksort($stages);
731 731
         return $stages;
732 732
     }
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
         $properties = parent::properties_as_array();
756 756
         $properties['_migration_stages'] = array();
757 757
         foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
758
-            $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
758
+            $properties['_migration_stages'][$migration_stage_priority] = $migration_stage_class->properties_as_array(
759 759
             );
760 760
         }
761 761
         unset($properties['_mappings']);
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_2_0.dms.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@  discard block
 block discarded – undo
12 12
 // unfortunately, this needs to be done upon INCLUSION of this file,
13 13
 // instead of construction, because it only gets constructed on first page load
14 14
 // (all other times it gets resurrected from a wordpress option)
15
-$stages = glob(EE_CORE . 'data_migration_scripts/4_2_0_stages/*');
15
+$stages = glob(EE_CORE.'data_migration_scripts/4_2_0_stages/*');
16 16
 $class_to_filepath = array();
17
-if (! empty($stages)) {
17
+if ( ! empty($stages)) {
18 18
     foreach ($stages as $filepath) {
19 19
         $matches = array();
20 20
         preg_match('~4_2_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
-        $class_to_filepath[ $matches[1] ] = $filepath;
21
+        $class_to_filepath[$matches[1]] = $filepath;
22 22
     }
23 23
 }
24 24
 // give addons a chance to autoload their stages too
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
         if (version_compare($version_string, '4.2.0', '<=') && version_compare($version_string, '4.1.0', '>=')) {
58 58
 //          echo "$version_string can be migrated fro";
59 59
             return true;
60
-        } elseif (! $version_string) {
60
+        } elseif ( ! $version_string) {
61 61
 //          echo "no version string provided: $version_string";
62 62
             // no version string provided... this must be pre 4.1
63 63
             // because since 4.1 we're
64
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
64
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
65 65
         } else {
66 66
 //          echo "$version_string doesnt apply";
67 67
             return false;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     public function schema_changes_before_migration()
74 74
     {
75 75
         // relies on 4.1's EEH_Activation::create_table
76
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
76
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
77 77
         $table_name = 'esp_answer';
78 78
         $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
79 79
 					REG_ID INT UNSIGNED NOT NULL,
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 $stages = glob(EE_CORE . 'data_migration_scripts/4_2_0_stages/*');
16 16
 $class_to_filepath = array();
17 17
 if (! empty($stages)) {
18
-    foreach ($stages as $filepath) {
19
-        $matches = array();
20
-        preg_match('~4_2_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
-        $class_to_filepath[ $matches[1] ] = $filepath;
22
-    }
18
+	foreach ($stages as $filepath) {
19
+		$matches = array();
20
+		preg_match('~4_2_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
+		$class_to_filepath[ $matches[1] ] = $filepath;
22
+	}
23 23
 }
24 24
 // give addons a chance to autoload their stages too
25 25
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_2_0__autoloaded_stages', $class_to_filepath);
@@ -32,57 +32,57 @@  discard block
 block discarded – undo
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * EE_DMS_Core_4_2_0 constructor.
37
-     *
38
-     * @param TableManager  $table_manager
39
-     * @param TableAnalysis $table_analysis
40
-     */
41
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
42
-    {
43
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.2.0", "event_espresso");
44
-        $this->_priority = 10;
45
-        $this->_migration_stages = array(
46
-            new EE_DMS_4_2_0_question_group_questions(),
47
-            new EE_DMS_4_2_0_datetime_fields(),
48
-        );
49
-        parent::__construct($table_manager, $table_analysis);
50
-    }
35
+	/**
36
+	 * EE_DMS_Core_4_2_0 constructor.
37
+	 *
38
+	 * @param TableManager  $table_manager
39
+	 * @param TableAnalysis $table_analysis
40
+	 */
41
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
42
+	{
43
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.2.0", "event_espresso");
44
+		$this->_priority = 10;
45
+		$this->_migration_stages = array(
46
+			new EE_DMS_4_2_0_question_group_questions(),
47
+			new EE_DMS_4_2_0_datetime_fields(),
48
+		);
49
+		parent::__construct($table_manager, $table_analysis);
50
+	}
51 51
 
52 52
 
53 53
 
54
-    public function can_migrate_from_version($version_array)
55
-    {
56
-        $version_string = $version_array['Core'];
57
-        if (version_compare($version_string, '4.2.0', '<=') && version_compare($version_string, '4.1.0', '>=')) {
54
+	public function can_migrate_from_version($version_array)
55
+	{
56
+		$version_string = $version_array['Core'];
57
+		if (version_compare($version_string, '4.2.0', '<=') && version_compare($version_string, '4.1.0', '>=')) {
58 58
 //          echo "$version_string can be migrated fro";
59
-            return true;
60
-        } elseif (! $version_string) {
59
+			return true;
60
+		} elseif (! $version_string) {
61 61
 //          echo "no version string provided: $version_string";
62
-            // no version string provided... this must be pre 4.1
63
-            // because since 4.1 we're
64
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
65
-        } else {
62
+			// no version string provided... this must be pre 4.1
63
+			// because since 4.1 we're
64
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
65
+		} else {
66 66
 //          echo "$version_string doesnt apply";
67
-            return false;
68
-        }
69
-    }
67
+			return false;
68
+		}
69
+	}
70 70
 
71 71
 
72 72
 
73
-    public function schema_changes_before_migration()
74
-    {
75
-        // relies on 4.1's EEH_Activation::create_table
76
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
77
-        $table_name = 'esp_answer';
78
-        $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
73
+	public function schema_changes_before_migration()
74
+	{
75
+		// relies on 4.1's EEH_Activation::create_table
76
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
77
+		$table_name = 'esp_answer';
78
+		$sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
79 79
 					REG_ID INT UNSIGNED NOT NULL,
80 80
 					QST_ID INT UNSIGNED NOT NULL,
81 81
 					ANS_value TEXT NOT NULL,
82 82
 					PRIMARY KEY  (ANS_ID)";
83
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
84
-        $table_name = 'esp_attendee_meta';
85
-        $sql = "ATTM_ID INT(10) UNSIGNED NOT	NULL AUTO_INCREMENT,
83
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
84
+		$table_name = 'esp_attendee_meta';
85
+		$sql = "ATTM_ID INT(10) UNSIGNED NOT	NULL AUTO_INCREMENT,
86 86
 						ATT_ID BIGINT(20) UNSIGNED NOT NULL,
87 87
 						ATT_fname VARCHAR(45) NOT NULL,
88 88
 						ATT_lname VARCHAR(45) NOT	NULL,
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 								KEY ATT_fname (ATT_fname),
99 99
 								KEY ATT_lname (ATT_lname),
100 100
 								KEY ATT_email (ATT_email(191))";
101
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
102
-        $table_name = 'esp_country';
103
-        $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
101
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
102
+		$table_name = 'esp_country';
103
+		$sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
104 104
 					  CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL,
105 105
 					  RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL,
106 106
 					  CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL,
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 					  CNT_is_EU TINYINT(1) DEFAULT '0',
117 117
 					  CNT_active TINYINT(1) DEFAULT '0',
118 118
 					  PRIMARY KEY  (CNT_ISO)";
119
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
120
-        $table_name = 'esp_datetime';
121
-        $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
119
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
120
+		$table_name = 'esp_datetime';
121
+		$sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
122 122
 				  EVT_ID BIGINT(20) UNSIGNED NOT NULL,
123 123
 				  DTT_name VARCHAR(255) NOT NULL DEFAULT '',
124 124
 				  DTT_description TEXT NOT NULL,
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 						PRIMARY KEY  (DTT_ID),
134 134
 						KEY EVT_ID (EVT_ID),
135 135
 						KEY DTT_is_primary (DTT_is_primary)";
136
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
137
-        $table_name = 'esp_event_meta';
138
-        $sql = "
136
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
137
+		$table_name = 'esp_event_meta';
138
+		$sql = "
139 139
 			EVTM_ID INT NOT NULL AUTO_INCREMENT,
140 140
 			EVT_ID BIGINT(20) UNSIGNED NOT NULL,
141 141
 			EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
@@ -150,31 +150,31 @@  discard block
 block discarded – undo
150 150
 			EVT_external_URL VARCHAR(200) NULL,
151 151
 			EVT_donations TINYINT(1) NULL,
152 152
 			PRIMARY KEY  (EVTM_ID)";
153
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
154
-        $table_name = 'esp_event_question_group';
155
-        $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
153
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
154
+		$table_name = 'esp_event_question_group';
155
+		$sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
156 156
 					EVT_ID BIGINT(20) UNSIGNED NOT NULL,
157 157
 					QSG_ID INT UNSIGNED NOT NULL,
158 158
 					EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
159 159
 					PRIMARY KEY  (EQG_ID)";
160
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
161
-        $table_name = 'esp_event_venue';
162
-        $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,
160
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
161
+		$table_name = 'esp_event_venue';
162
+		$sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,
163 163
 				EVT_ID BIGINT(20) UNSIGNED NOT NULL,
164 164
 				VNU_ID BIGINT(20) UNSIGNED NOT NULL,
165 165
 				EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
166 166
 				PRIMARY KEY  (EVV_ID)";
167
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
168
-        $table_name = 'esp_extra_meta';
169
-        $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,
167
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
168
+		$table_name = 'esp_extra_meta';
169
+		$sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,
170 170
 				OBJ_ID INT(11) DEFAULT NULL,
171 171
 				EXM_type VARCHAR(45) DEFAULT NULL,
172 172
 				EXM_key VARCHAR(45) DEFAULT NULL,
173 173
 				EXM_value TEXT,
174 174
 				PRIMARY KEY  (EXM_ID)";
175
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
176
-        $table_name = 'esp_line_item';
177
-        $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,
175
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
176
+		$table_name = 'esp_line_item';
177
+		$sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,
178 178
 				LIN_code VARCHAR(245) NOT NULL DEFAULT '',
179 179
 				TXN_ID INT(11) DEFAULT NULL,
180 180
 				LIN_name VARCHAR(245) NOT NULL DEFAULT '',
@@ -190,18 +190,18 @@  discard block
 block discarded – undo
190 190
 				OBJ_ID INT(11) DEFAULT NULL,
191 191
 				OBJ_type VARCHAR(45)DEFAULT NULL,
192 192
 				PRIMARY KEY  (LIN_ID)";
193
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
194
-        $table_name = 'esp_message_template';
195
-        $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
193
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
194
+		$table_name = 'esp_message_template';
195
+		$sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
196 196
 					GRP_ID INT(10) UNSIGNED NOT NULL,
197 197
 					MTP_context VARCHAR(50) NOT NULL,
198 198
 					MTP_template_field VARCHAR(30) NOT NULL,
199 199
 					MTP_content TEXT NOT NULL,
200 200
 					PRIMARY KEY  (MTP_ID),
201 201
 					KEY GRP_ID (GRP_ID)";
202
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
203
-        $table_name = 'esp_message_template_group';
204
-        $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
202
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
203
+		$table_name = 'esp_message_template_group';
204
+		$sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
205 205
 					EVT_ID BIGINT(20) UNSIGNED DEFAULT NULL,
206 206
 					MTP_user_id INT(10) NOT NULL DEFAULT '1',
207 207
 					MTP_messenger VARCHAR(30) NOT NULL,
@@ -213,9 +213,9 @@  discard block
 block discarded – undo
213 213
 					PRIMARY KEY  (GRP_ID),
214 214
 					KEY EVT_ID (EVT_ID),
215 215
 					KEY MTP_user_id (MTP_user_id)";
216
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
217
-        $table_name = 'esp_payment';
218
-        $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
216
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
217
+		$table_name = 'esp_payment';
218
+		$sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
219 219
 					TXN_ID INT(10) UNSIGNED DEFAULT NULL,
220 220
 					STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL,
221 221
 					PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 					PRIMARY KEY  (PAY_ID),
232 232
 					KEY TXN_ID (TXN_ID),
233 233
 					KEY PAY_timestamp (PAY_timestamp)";
234
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
235
-        $table_name = "esp_ticket";
236
-        $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
234
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
235
+		$table_name = "esp_ticket";
236
+		$sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
237 237
 					  TTM_ID INT(10) UNSIGNED NOT NULL,
238 238
 					  TKT_name VARCHAR(245) NOT NULL DEFAULT '',
239 239
 					  TKT_description TEXT NOT NULL,
@@ -252,28 +252,28 @@  discard block
 block discarded – undo
252 252
 					  TKT_parent INT(10) UNSIGNED DEFAULT '0',
253 253
 					  TKT_deleted TINYINT(1) NOT NULL DEFAULT '0',
254 254
 					  PRIMARY KEY  (TKT_ID)";
255
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
256
-        $table_name = "esp_ticket_price";
257
-        $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
255
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
256
+		$table_name = "esp_ticket_price";
257
+		$sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
258 258
 					  TKT_ID INT(10) UNSIGNED NOT NULL,
259 259
 					  PRC_ID INT(10) UNSIGNED NOT NULL,
260 260
 					  PRIMARY KEY  (TKP_ID)";
261
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
262
-        $table_name = "esp_datetime_ticket";
263
-        $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
261
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
262
+		$table_name = "esp_datetime_ticket";
263
+		$sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
264 264
 					  DTT_ID INT(10) UNSIGNED NOT NULL,
265 265
 					  TKT_ID INT(10) UNSIGNED NOT NULL,
266 266
 					  PRIMARY KEY  (DTK_ID)";
267
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
268
-        $table_name = "esp_ticket_template";
269
-        $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
267
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
268
+		$table_name = "esp_ticket_template";
269
+		$sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
270 270
 					  TTM_name VARCHAR(45) NOT NULL,
271 271
 					  TTM_description TEXT,
272 272
 					  TTM_file VARCHAR(45),
273 273
 					  PRIMARY KEY  (TTM_ID)";
274
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
275
-        $table_name = "esp_price";
276
-        $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
274
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
275
+		$table_name = "esp_price";
276
+		$sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
277 277
 					  PRT_ID TINYINT(3) UNSIGNED NOT NULL,
278 278
 					  PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',
279 279
 					  PRC_name VARCHAR(245) NOT NULL,
@@ -284,9 +284,9 @@  discard block
 block discarded – undo
284 284
 					  PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
285 285
 					  PRC_parent INT(10) UNSIGNED DEFAULT 0,
286 286
 					  PRIMARY KEY  (PRC_ID)";
287
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
288
-        $table_name = "esp_price_type";
289
-        $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
287
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
288
+		$table_name = "esp_price_type";
289
+		$sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
290 290
 				  PRT_name VARCHAR(45) NOT NULL,
291 291
 				  PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
292 292
 				  PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0',
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 				  PRT_deleted TINYINT(1) NOT NULL DEFAULT '0',
295 295
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
296 296
 				  PRIMARY KEY  (PRT_ID)";
297
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
298
-        $table_name = 'esp_question';
299
-        $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
297
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
298
+		$table_name = 'esp_question';
299
+		$sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
300 300
 					QST_display_text TEXT NOT NULL,
301 301
 					QST_admin_label VARCHAR(255) NOT NULL,
302 302
 					QST_system VARCHAR(25) DEFAULT NULL,
@@ -308,10 +308,10 @@  discard block
 block discarded – undo
308 308
 					QST_wp_user BIGINT UNSIGNED NULL,
309 309
 					QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0,
310 310
 					PRIMARY KEY  (QST_ID)';
311
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
312
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
313
-        $table_name = 'esp_question_group';
314
-        $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
311
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
312
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
313
+		$table_name = 'esp_question_group';
314
+		$sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
315 315
 					QSG_name VARCHAR(255) NOT NULL,
316 316
 					QSG_identifier VARCHAR(100) NOT NULL,
317 317
 					QSG_desc TEXT NULL,
@@ -322,24 +322,24 @@  discard block
 block discarded – undo
322 322
 					QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
323 323
 					PRIMARY KEY  (QSG_ID),
324 324
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
325
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
326
-        $table_name = 'esp_question_group_question';
327
-        $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
325
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
326
+		$table_name = 'esp_question_group_question';
327
+		$sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
328 328
 					QSG_ID INT UNSIGNED NOT NULL,
329 329
 					QST_ID INT UNSIGNED NOT NULL,
330 330
 					QGQ_order INT UNSIGNED NOT NULL DEFAULT 0,
331 331
 					PRIMARY KEY  (QGQ_ID) ";
332
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
333
-        $table_name = 'esp_question_option';
334
-        $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
332
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
333
+		$table_name = 'esp_question_option';
334
+		$sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
335 335
 					QSO_value VARCHAR(255) NOT NULL,
336 336
 					QSO_desc TEXT NOT NULL,
337 337
 					QST_ID INT UNSIGNED NOT NULL,
338 338
 					QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
339 339
 					PRIMARY KEY  (QSO_ID)";
340
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
341
-        $table_name = 'esp_registration';
342
-        $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
340
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
341
+		$table_name = 'esp_registration';
342
+		$sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
343 343
 					  EVT_ID BIGINT(20) UNSIGNED NOT NULL,
344 344
 					  ATT_ID BIGINT(20) UNSIGNED NOT NULL,
345 345
 					  TXN_ID INT(10) UNSIGNED NOT NULL,
@@ -362,25 +362,25 @@  discard block
 block discarded – undo
362 362
 					  KEY STS_ID (STS_ID),
363 363
 					  KEY REG_url_link (REG_url_link),
364 364
 					  KEY REG_code (REG_code)";
365
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
366
-        $table_name = 'esp_checkin';
367
-        $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
365
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
366
+		$table_name = 'esp_checkin';
367
+		$sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
368 368
 					REG_ID INT(10) UNSIGNED NOT NULL,
369 369
 					DTT_ID INT(10) UNSIGNED NOT NULL,
370 370
 					CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
371 371
 					CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
372 372
 					PRIMARY KEY  (CHK_ID)";
373
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
374
-        $table_name = 'esp_state';
375
-        $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
373
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
374
+		$table_name = 'esp_state';
375
+		$sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
376 376
 					  CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
377 377
 					  STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL,
378 378
 					  STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL,
379 379
 					  STA_active TINYINT(1) DEFAULT '1',
380 380
 					  PRIMARY KEY  (STA_ID)";
381
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
382
-        $table_name = 'esp_status';
383
-        $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,
381
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
382
+		$table_name = 'esp_status';
383
+		$sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,
384 384
 					  STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL,
385 385
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
386 386
 					  STS_can_edit TINYINT(1) NOT NULL DEFAULT 0,
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
 					  STS_open TINYINT(1) NOT NULL DEFAULT 1,
389 389
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
390 390
 					  KEY STS_type (STS_type)";
391
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
392
-        $table_name = 'esp_transaction';
393
-        $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
391
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
392
+		$table_name = 'esp_transaction';
393
+		$sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
394 394
 					  TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
395 395
 					  TXN_total DECIMAL(10,3) DEFAULT '0.00',
396 396
 					  TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00',
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
 					  PRIMARY KEY  (TXN_ID),
401 401
 					  KEY TXN_timestamp (TXN_timestamp),
402 402
 					  KEY STS_ID (STS_ID)";
403
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
404
-        $table_name = 'esp_venue_meta';
405
-        $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,
403
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
404
+		$table_name = 'esp_venue_meta';
405
+		$sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,
406 406
 			VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
407 407
 			VNU_address VARCHAR(255) DEFAULT NULL,
408 408
 			VNU_address2 VARCHAR(255) DEFAULT NULL,
@@ -420,36 +420,36 @@  discard block
 block discarded – undo
420 420
 			PRIMARY KEY  (VNUM_ID),
421 421
 			KEY STA_ID (STA_ID),
422 422
 			KEY CNT_ISO (CNT_ISO)";
423
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
424
-        $script_with_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
425
-        // setting up the DEFAULT stats and countries is also essential for the data migrations to run
426
-        // (because many need to convert old string states to foreign keys into the states table)
427
-        $script_with_defaults->insert_default_states();
428
-        $script_with_defaults->insert_default_countries();
429
-        // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations
430
-        $script_with_defaults->insert_default_price_types();
431
-        $script_with_defaults->insert_default_prices();
432
-        $script_with_defaults->insert_default_tickets();
433
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
434
-        EE_Config::instance()->update_espresso_config(false, true);
435
-        return true;
436
-    }
423
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
424
+		$script_with_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
425
+		// setting up the DEFAULT stats and countries is also essential for the data migrations to run
426
+		// (because many need to convert old string states to foreign keys into the states table)
427
+		$script_with_defaults->insert_default_states();
428
+		$script_with_defaults->insert_default_countries();
429
+		// setting up DEFAULT prices, price types, and tickets is also essential for the price migrations
430
+		$script_with_defaults->insert_default_price_types();
431
+		$script_with_defaults->insert_default_prices();
432
+		$script_with_defaults->insert_default_tickets();
433
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
434
+		EE_Config::instance()->update_espresso_config(false, true);
435
+		return true;
436
+	}
437 437
 
438 438
 
439 439
 
440
-    /**
441
-     * We COULD clean up the esp_question.QST_order field here. We'll leave it for now
442
-     *
443
-     * @return boolean
444
-     */
445
-    public function schema_changes_after_migration()
446
-    {
447
-        return true;
448
-    }
440
+	/**
441
+	 * We COULD clean up the esp_question.QST_order field here. We'll leave it for now
442
+	 *
443
+	 * @return boolean
444
+	 */
445
+	public function schema_changes_after_migration()
446
+	{
447
+		return true;
448
+	}
449 449
 
450 450
 
451 451
 
452
-    public function migration_page_hooks()
453
-    {
454
-    }
452
+	public function migration_page_hooks()
453
+	{
454
+	}
455 455
 }
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_update_wp_user_for_question_groups.dmsstage.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
 */
10 10
 class EE_DMS_4_5_0_update_wp_user_for_question_groups extends EE_Data_Migration_Script_Stage_Table
11 11
 {
12
-    public function __construct()
13
-    {
14
-        global $wpdb;
15
-        $this->_pretty_name = __("Question Groups", "event_espresso");
16
-        $this->_old_table = $wpdb->prefix."esp_question_group";
17
-        parent::__construct();
18
-    }
19
-    protected function _migrate_old_row($old_row)
20
-    {
21
-        // foreach ticket row we add the id for the current logged in user.
22
-        global $wpdb;
23
-        $user_id = EEH_Activation::get_default_creator_id();
24
-        $updated = $wpdb->update(
25
-            $this->_old_table,
26
-            array('QSG_wp_user'=>$user_id),
27
-            array('QSG_ID'=>$old_row['QSG_ID']),
28
-            array('%d',// QSG_wp_user
29
-                    ),
30
-            array('%d',// QSG_ID
31
-                    )
32
-        );
33
-        if (false === $updated) {
34
-            $this->add_error(
35
-                sprintf(
36
-                    __(
37
-                        "Error in updating table %s setting QSG_wp_user = %d where QSG_ID = %d",
38
-                        'event_espresso'
39
-                    ),
40
-                    $this->_old_table,
41
-                    $user_id,
42
-                    $old_row['QSG_ID']
43
-                )
44
-            );
45
-        }
46
-    }
12
+	public function __construct()
13
+	{
14
+		global $wpdb;
15
+		$this->_pretty_name = __("Question Groups", "event_espresso");
16
+		$this->_old_table = $wpdb->prefix."esp_question_group";
17
+		parent::__construct();
18
+	}
19
+	protected function _migrate_old_row($old_row)
20
+	{
21
+		// foreach ticket row we add the id for the current logged in user.
22
+		global $wpdb;
23
+		$user_id = EEH_Activation::get_default_creator_id();
24
+		$updated = $wpdb->update(
25
+			$this->_old_table,
26
+			array('QSG_wp_user'=>$user_id),
27
+			array('QSG_ID'=>$old_row['QSG_ID']),
28
+			array('%d',// QSG_wp_user
29
+					),
30
+			array('%d',// QSG_ID
31
+					)
32
+		);
33
+		if (false === $updated) {
34
+			$this->add_error(
35
+				sprintf(
36
+					__(
37
+						"Error in updating table %s setting QSG_wp_user = %d where QSG_ID = %d",
38
+						'event_espresso'
39
+					),
40
+					$this->_old_table,
41
+					$user_id,
42
+					$old_row['QSG_ID']
43
+				)
44
+			);
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@
 block discarded – undo
25 25
             $this->_old_table,
26 26
             array('QSG_wp_user'=>$user_id),
27 27
             array('QSG_ID'=>$old_row['QSG_ID']),
28
-            array('%d',// QSG_wp_user
28
+            array('%d', // QSG_wp_user
29 29
                     ),
30
-            array('%d',// QSG_ID
30
+            array('%d', // QSG_ID
31 31
                     )
32 32
         );
33 33
         if (false === $updated) {
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_update_wp_user_for_prices.dmsstage.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
 */
10 10
 class EE_DMS_4_5_0_update_wp_user_for_prices extends EE_Data_Migration_Script_Stage_Table
11 11
 {
12
-    public function __construct()
13
-    {
14
-        global $wpdb;
15
-        $this->_pretty_name = __("Prices", "event_espresso");
16
-        $this->_old_table = $wpdb->prefix."esp_price";
17
-        parent::__construct();
18
-    }
19
-    protected function _migrate_old_row($old_row)
20
-    {
21
-        // foreach ticket row we add the id for the current logged in user.
22
-        global $wpdb;
23
-        $user_id = EEH_Activation::get_default_creator_id();
24
-        $updated = $wpdb->update(
25
-            $this->_old_table,
26
-            array('PRC_wp_user'=>$user_id),
27
-            array('PRC_ID'=>$old_row['PRC_ID']),
28
-            array('%d',// PRC_wp_user
29
-                    ),
30
-            array('%d',// PRC_ID
31
-                    )
32
-        );
33
-        if (false === $updated) {
34
-            $this->add_error(
35
-                sprintf(
36
-                    __(
37
-                        "Error in updating table %s setting PRC_wp_user = %d where PRC_ID = %d",
38
-                        'event_espresso'
39
-                    ),
40
-                    $this->_old_table,
41
-                    $user_id,
42
-                    $old_row['PRC_ID']
43
-                )
44
-            );
45
-        }
46
-    }
12
+	public function __construct()
13
+	{
14
+		global $wpdb;
15
+		$this->_pretty_name = __("Prices", "event_espresso");
16
+		$this->_old_table = $wpdb->prefix."esp_price";
17
+		parent::__construct();
18
+	}
19
+	protected function _migrate_old_row($old_row)
20
+	{
21
+		// foreach ticket row we add the id for the current logged in user.
22
+		global $wpdb;
23
+		$user_id = EEH_Activation::get_default_creator_id();
24
+		$updated = $wpdb->update(
25
+			$this->_old_table,
26
+			array('PRC_wp_user'=>$user_id),
27
+			array('PRC_ID'=>$old_row['PRC_ID']),
28
+			array('%d',// PRC_wp_user
29
+					),
30
+			array('%d',// PRC_ID
31
+					)
32
+		);
33
+		if (false === $updated) {
34
+			$this->add_error(
35
+				sprintf(
36
+					__(
37
+						"Error in updating table %s setting PRC_wp_user = %d where PRC_ID = %d",
38
+						'event_espresso'
39
+					),
40
+					$this->_old_table,
41
+					$user_id,
42
+					$old_row['PRC_ID']
43
+				)
44
+			);
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@
 block discarded – undo
25 25
             $this->_old_table,
26 26
             array('PRC_wp_user'=>$user_id),
27 27
             array('PRC_ID'=>$old_row['PRC_ID']),
28
-            array('%d',// PRC_wp_user
28
+            array('%d', // PRC_wp_user
29 29
                     ),
30
-            array('%d',// PRC_ID
30
+            array('%d', // PRC_ID
31 31
                     )
32 32
         );
33 33
         if (false === $updated) {
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_update_wp_user_for_tickets.dmsstage.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
 */
10 10
 class EE_DMS_4_5_0_update_wp_user_for_tickets extends EE_Data_Migration_Script_Stage_Table
11 11
 {
12
-    public function __construct()
13
-    {
14
-        global $wpdb;
15
-        $this->_pretty_name = __("Tickets", "event_espresso");
16
-        $this->_old_table = $wpdb->prefix."esp_ticket";
17
-        parent::__construct();
18
-    }
19
-    protected function _migrate_old_row($old_row)
20
-    {
21
-        // foreach ticket row we add the id for the current logged in user.
22
-        global $wpdb;
23
-        $user_id = EEH_Activation::get_default_creator_id();
24
-        $updated = $wpdb->update(
25
-            $this->_old_table,
26
-            array('TKT_wp_user'=>$user_id),
27
-            array('TKT_ID'=>$old_row['TKT_ID']),
28
-            array('%d',// TKT_wp_user
29
-                    ),
30
-            array('%d',// TKT_ID
31
-                    )
32
-        );
33
-        if (false === $updated) {
34
-            $this->add_error(
35
-                sprintf(
36
-                    __(
37
-                        "Error in updating table %s setting TKT_wp_user = %d where TKT_ID = %d",
38
-                        'event_espresso'
39
-                    ),
40
-                    $this->_old_table,
41
-                    $user_id,
42
-                    $old_row['TKT_ID']
43
-                )
44
-            );
45
-        }
46
-    }
12
+	public function __construct()
13
+	{
14
+		global $wpdb;
15
+		$this->_pretty_name = __("Tickets", "event_espresso");
16
+		$this->_old_table = $wpdb->prefix."esp_ticket";
17
+		parent::__construct();
18
+	}
19
+	protected function _migrate_old_row($old_row)
20
+	{
21
+		// foreach ticket row we add the id for the current logged in user.
22
+		global $wpdb;
23
+		$user_id = EEH_Activation::get_default_creator_id();
24
+		$updated = $wpdb->update(
25
+			$this->_old_table,
26
+			array('TKT_wp_user'=>$user_id),
27
+			array('TKT_ID'=>$old_row['TKT_ID']),
28
+			array('%d',// TKT_wp_user
29
+					),
30
+			array('%d',// TKT_ID
31
+					)
32
+		);
33
+		if (false === $updated) {
34
+			$this->add_error(
35
+				sprintf(
36
+					__(
37
+						"Error in updating table %s setting TKT_wp_user = %d where TKT_ID = %d",
38
+						'event_espresso'
39
+					),
40
+					$this->_old_table,
41
+					$user_id,
42
+					$old_row['TKT_ID']
43
+				)
44
+			);
45
+		}
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@
 block discarded – undo
25 25
             $this->_old_table,
26 26
             array('TKT_wp_user'=>$user_id),
27 27
             array('TKT_ID'=>$old_row['TKT_ID']),
28
-            array('%d',// TKT_wp_user
28
+            array('%d', // TKT_wp_user
29 29
                     ),
30
-            array('%d',// TKT_ID
30
+            array('%d', // TKT_ID
31 31
                     )
32 32
         );
33 33
         if (false === $updated) {
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_update_wp_user_for_price_types.dmsstage.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -9,36 +9,36 @@
 block discarded – undo
9 9
 */
10 10
 class EE_DMS_4_5_0_update_wp_user_for_price_types extends EE_Data_Migration_Script_Stage_Table
11 11
 {
12
-    public function __construct()
13
-    {
14
-        global $wpdb;
15
-        $this->_pretty_name = __("Price Types", "event_espresso");
16
-        $this->_old_table = $wpdb->prefix."esp_price_type";
17
-        parent::__construct();
18
-    }
19
-    protected function _migrate_old_row($old_row)
20
-    {
21
-        // foreach ticket row we add the id for the current logged in user.
22
-        global $wpdb;
23
-        $user_id = EEH_Activation::get_default_creator_id();
24
-        $updated = $wpdb->update(
25
-            $this->_old_table,
26
-            array('PRT_wp_user'=>$user_id),
27
-            array('PRT_ID'=>$old_row['PRT_ID']),
28
-            array('%d',// PRT_wp_user
29
-                    ),
30
-            array('%d',// PRT_ID
31
-                    )
32
-        );
33
-        if (false === $updated) {
34
-            $this->add_error(
35
-                sprintf(
36
-                    __("Error in updating table %s setting PRT_wp_user = %d where PRT_ID = %d", 'event_espresso'),
37
-                    $this->_old_table,
38
-                    $user_id,
39
-                    $old_row['PRT_ID']
40
-                )
41
-            );
42
-        }
43
-    }
12
+	public function __construct()
13
+	{
14
+		global $wpdb;
15
+		$this->_pretty_name = __("Price Types", "event_espresso");
16
+		$this->_old_table = $wpdb->prefix."esp_price_type";
17
+		parent::__construct();
18
+	}
19
+	protected function _migrate_old_row($old_row)
20
+	{
21
+		// foreach ticket row we add the id for the current logged in user.
22
+		global $wpdb;
23
+		$user_id = EEH_Activation::get_default_creator_id();
24
+		$updated = $wpdb->update(
25
+			$this->_old_table,
26
+			array('PRT_wp_user'=>$user_id),
27
+			array('PRT_ID'=>$old_row['PRT_ID']),
28
+			array('%d',// PRT_wp_user
29
+					),
30
+			array('%d',// PRT_ID
31
+					)
32
+		);
33
+		if (false === $updated) {
34
+			$this->add_error(
35
+				sprintf(
36
+					__("Error in updating table %s setting PRT_wp_user = %d where PRT_ID = %d", 'event_espresso'),
37
+					$this->_old_table,
38
+					$user_id,
39
+					$old_row['PRT_ID']
40
+				)
41
+			);
42
+		}
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@
 block discarded – undo
25 25
             $this->_old_table,
26 26
             array('PRT_wp_user'=>$user_id),
27 27
             array('PRT_ID'=>$old_row['PRT_ID']),
28
-            array('%d',// PRT_wp_user
28
+            array('%d', // PRT_wp_user
29 29
                     ),
30
-            array('%d',// PRT_ID
30
+            array('%d', // PRT_ID
31 31
                     )
32 32
         );
33 33
         if (false === $updated) {
Please login to merge, or discard this patch.
4_5_0_stages/EE_DMS_4_5_0_invoice_settings.dmsstage.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -15,94 +15,94 @@
 block discarded – undo
15 15
 class EE_DMS_4_5_0_invoice_settings extends EE_Data_Migration_Script_Stage
16 16
 {
17 17
 
18
-    /**
19
-     * Just initializes the status of the migration
20
-     */
21
-    public function __construct()
22
-    {
23
-        $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso');
24
-        parent::__construct();
25
-    }
18
+	/**
19
+	 * Just initializes the status of the migration
20
+	 */
21
+	public function __construct()
22
+	{
23
+		$this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso');
24
+		parent::__construct();
25
+	}
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * _count_records_to_migrate
31
-     * Counts the records to migrate; the public version may cache it
32
-     *
33
-     * @access protected
34
-     * @return int
35
-     */
36
-    protected function _count_records_to_migrate()
37
-    {
38
-        return 1;
39
-    }
29
+	/**
30
+	 * _count_records_to_migrate
31
+	 * Counts the records to migrate; the public version may cache it
32
+	 *
33
+	 * @access protected
34
+	 * @return int
35
+	 */
36
+	protected function _count_records_to_migrate()
37
+	{
38
+		return 1;
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     *    _migration_step
45
-     *
46
-     * @access protected
47
-     * @param int $num_items
48
-     * @throws EE_Error
49
-     * @return int number of items ACTUALLY migrated
50
-     * @throws InvalidDataTypeException
51
-     */
52
-    protected function _migration_step($num_items = 1)
53
-    {
54
-        // if this isn't set then something is really wrong
55
-        if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
56
-            throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
57
-        }
58
-        $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null;
59
-        if (! $invoice_settings) {
60
-            $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
61
-        } else {
62
-            $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
63
-            $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to'];
64
-            $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address'];
65
-            $invoice_settings['template_invoice_email'] = '';
66
-            $invoice_settings['template_invoice_tax_number'] = '';
67
-            unset($invoice_settings['pdf_instructions']);
68
-            unset($invoice_settings['payable_to']);
69
-            unset($invoice_settings['payment_address']);
70
-            EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings;
71
-            EE_Config::instance()->update_espresso_config(false, false);
43
+	/**
44
+	 *    _migration_step
45
+	 *
46
+	 * @access protected
47
+	 * @param int $num_items
48
+	 * @throws EE_Error
49
+	 * @return int number of items ACTUALLY migrated
50
+	 * @throws InvalidDataTypeException
51
+	 */
52
+	protected function _migration_step($num_items = 1)
53
+	{
54
+		// if this isn't set then something is really wrong
55
+		if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
56
+			throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
57
+		}
58
+		$invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null;
59
+		if (! $invoice_settings) {
60
+			$this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
61
+		} else {
62
+			$invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
63
+			$invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to'];
64
+			$invoice_settings['template_invoice_address'] = $invoice_settings['payment_address'];
65
+			$invoice_settings['template_invoice_email'] = '';
66
+			$invoice_settings['template_invoice_tax_number'] = '';
67
+			unset($invoice_settings['pdf_instructions']);
68
+			unset($invoice_settings['payable_to']);
69
+			unset($invoice_settings['payment_address']);
70
+			EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings;
71
+			EE_Config::instance()->update_espresso_config(false, false);
72 72
 
73
-            // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice
74
-            // (why is it tough to change? because we want to update the receipt and invoice message template, but
75
-            // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
76
-            // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
77
-            // also we don't want to build a dependency on the messages code because it is likely to change soon
78
-            if (! in_array($invoice_settings['invoice_css'], array( '', 'simple.css' ))) {
79
-                new PersistentAdminNotice(
80
-                    'invoice_css_not_updated',
81
-                    sprintf(
82
-                        esc_html__(
83
-                            'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.',
84
-                            'event_espresso'
85
-                        ),
86
-                        $invoice_settings['invoice_css']
87
-                    )
88
-                );
89
-            }
90
-            $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
91
-            $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
92
-            $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
93
-            if ($overridden_invoice_body || $overridden_receipt_body) {
94
-                new PersistentAdminNotice(
95
-                    'invoice_overriding_templates',
96
-                    esc_html__(
97
-                        'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
98
-                        'event_espresso'
99
-                    ),
100
-                    true
101
-                );
102
-            }
103
-        }
104
-        // regardless of whether it worked or not, we ought to continue the migration
105
-        $this->set_completed();
106
-        return 1;
107
-    }
73
+			// @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice
74
+			// (why is it tough to change? because we want to update the receipt and invoice message template, but
75
+			// message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
76
+			// update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
77
+			// also we don't want to build a dependency on the messages code because it is likely to change soon
78
+			if (! in_array($invoice_settings['invoice_css'], array( '', 'simple.css' ))) {
79
+				new PersistentAdminNotice(
80
+					'invoice_css_not_updated',
81
+					sprintf(
82
+						esc_html__(
83
+							'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.',
84
+							'event_espresso'
85
+						),
86
+						$invoice_settings['invoice_css']
87
+					)
88
+				);
89
+			}
90
+			$templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
91
+			$overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
92
+			$overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
93
+			if ($overridden_invoice_body || $overridden_receipt_body) {
94
+				new PersistentAdminNotice(
95
+					'invoice_overriding_templates',
96
+					esc_html__(
97
+						'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.',
98
+						'event_espresso'
99
+					),
100
+					true
101
+				);
102
+			}
103
+		}
104
+		// regardless of whether it worked or not, we ought to continue the migration
105
+		$this->set_completed();
106
+		return 1;
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
     protected function _migration_step($num_items = 1)
53 53
     {
54 54
         // if this isn't set then something is really wrong
55
-        if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
55
+        if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
56 56
             throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
57 57
         }
58 58
         $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null;
59
-        if (! $invoice_settings) {
59
+        if ( ! $invoice_settings) {
60 60
             $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
61 61
         } else {
62 62
             $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
76 76
             // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
77 77
             // also we don't want to build a dependency on the messages code because it is likely to change soon
78
-            if (! in_array($invoice_settings['invoice_css'], array( '', 'simple.css' ))) {
78
+            if ( ! in_array($invoice_settings['invoice_css'], array('', 'simple.css'))) {
79 79
                 new PersistentAdminNotice(
80 80
                     'invoice_css_not_updated',
81 81
                     sprintf(
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
                 );
89 89
             }
90 90
             $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
91
-            $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true);
92
-            $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true);
91
+            $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true);
92
+            $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true);
93 93
             if ($overridden_invoice_body || $overridden_receipt_body) {
94 94
                 new PersistentAdminNotice(
95 95
                     'invoice_overriding_templates',
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_5_0.dms.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 // unfortunately, this needs to be done upon INCLUSION of this file,
14 14
 // instead of construction, because it only gets constructed on first page load
15 15
 // (all other times it gets resurrected from a wordpress option)
16
-$stages = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
16
+$stages = glob(EE_CORE.'data_migration_scripts/4_5_0_stages/*');
17 17
 $class_to_filepath = array();
18 18
 foreach ($stages as $filepath) {
19 19
     $matches = array();
20 20
     preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
-    $class_to_filepath[ $matches[1] ] = $filepath;
21
+    $class_to_filepath[$matches[1]] = $filepath;
22 22
 }
23 23
 // give addons a chance to autoload their stages too
24 24
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
         if (version_compare($version_string, '4.5.0', '<=') && version_compare($version_string, '4.3.0', '>=')) {
60 60
 //          echo "$version_string can be migrated from";
61 61
             return true;
62
-        } elseif (! $version_string) {
62
+        } elseif ( ! $version_string) {
63 63
 //          echo "no version string provided: $version_string";
64 64
             // no version string provided... this must be pre 4.3
65
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
65
+            return false; // changed mind. dont want people thinking they should migrate yet because they cant
66 66
         } else {
67 67
 //          echo "$version_string doesnt apply";
68 68
             return false;
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public function schema_changes_before_migration()
75 75
     {
76 76
         // relies on 4.1's EEH_Activation::create_table
77
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
77
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
78 78
         $table_name = 'esp_answer';
79 79
         $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
80 80
 					REG_ID INT UNSIGNED NOT NULL,
@@ -479,18 +479,18 @@  discard block
 block discarded – undo
479 479
     public function insert_default_price_types()
480 480
     {
481 481
         global $wpdb;
482
-        $price_type_table = $wpdb->prefix . "esp_price_type";
482
+        $price_type_table = $wpdb->prefix."esp_price_type";
483 483
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
484
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
484
+            $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table;
485 485
             $price_types_exist = $wpdb->get_var($SQL);
486
-            if (! $price_types_exist) {
486
+            if ( ! $price_types_exist) {
487 487
                 $user_id = EEH_Activation::get_default_creator_id();
488 488
                 $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
489
-							(1, '" . __('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
490
-							(2, '" . __('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
491
-							(3, '" . __('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
492
-							(4, '" . __('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
493
-							(5, '" . __('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
489
+							(1, '".__('Base Price', 'event_espresso')."', 1,  0, 0, $user_id, 0),
490
+							(2, '".__('Percent Discount', 'event_espresso')."', 2,  1, 20, $user_id, 0),
491
+							(3, '".__('Dollar Discount', 'event_espresso')."', 2,  0, 30, $user_id, 0),
492
+							(4, '".__('Percent Surcharge', 'event_espresso')."', 3,  1, 40, $user_id,  0),
493
+							(5, '".__('Dollar Surcharge', 'event_espresso')."', 3,  0, 50, $user_id, 0);";
494 494
                 $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
495 495
                 $wpdb->query($SQL);
496 496
             }
@@ -511,11 +511,11 @@  discard block
 block discarded – undo
511 511
     public function insert_default_prices()
512 512
     {
513 513
         global $wpdb;
514
-        $price_table = $wpdb->prefix . "esp_price";
514
+        $price_table = $wpdb->prefix."esp_price";
515 515
         if ($this->_get_table_analysis()->tableExists($price_table)) {
516
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
516
+            $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table;
517 517
             $prices_exist = $wpdb->get_var($SQL);
518
-            if (! $prices_exist) {
518
+            if ( ! $prices_exist) {
519 519
                 $user_id = EEH_Activation::get_default_creator_id();
520 520
                 $SQL = "INSERT INTO $price_table
521 521
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
     public function insert_default_tickets()
539 539
     {
540 540
         global $wpdb;
541
-        $ticket_table = $wpdb->prefix . "esp_ticket";
541
+        $ticket_table = $wpdb->prefix."esp_ticket";
542 542
         if ($this->_get_table_analysis()->tableExists($ticket_table)) {
543
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
543
+            $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table;
544 544
             $tickets_exist = $wpdb->get_var($SQL);
545
-            if (! $tickets_exist) {
545
+            if ( ! $tickets_exist) {
546 546
                 $user_id = EEH_Activation::get_default_creator_id();
547 547
                 $SQL = "INSERT INTO $ticket_table
548 548
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
                 $wpdb->query($SQL);
554 554
             }
555 555
         }
556
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
556
+        $ticket_price_table = $wpdb->prefix."esp_ticket_price";
557 557
         if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
558
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
558
+            $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table;
559 559
             $ticket_prc_exist = $wpdb->get_var($SQL);
560
-            if (! $ticket_prc_exist) {
560
+            if ( ! $ticket_prc_exist) {
561 561
                 $SQL = "INSERT INTO $ticket_price_table
562 562
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
563 563
 				( 1, 1, 1 )
Please login to merge, or discard this patch.
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 $stages = glob(EE_CORE . 'data_migration_scripts/4_5_0_stages/*');
17 17
 $class_to_filepath = array();
18 18
 foreach ($stages as $filepath) {
19
-    $matches = array();
20
-    preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
-    $class_to_filepath[ $matches[1] ] = $filepath;
19
+	$matches = array();
20
+	preg_match('~4_5_0_stages/(.*).dmsstage.php~', $filepath, $matches);
21
+	$class_to_filepath[ $matches[1] ] = $filepath;
22 22
 }
23 23
 // give addons a chance to autoload their stages too
24 24
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_5_0__autoloaded_stages', $class_to_filepath);
@@ -31,59 +31,59 @@  discard block
 block discarded – undo
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * EE_DMS_Core_4_5_0 constructor.
36
-     *
37
-     * @param TableManager  $table_manager
38
-     * @param TableAnalysis $table_analysis
39
-     */
40
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
41
-    {
42
-        $this->_pretty_name = __("Data Update to Event Espresso 4.5.0", "event_espresso");
43
-        $this->_priority = 10;
44
-        $this->_migration_stages = array(
45
-            new EE_DMS_4_5_0_update_wp_user_for_tickets(),
46
-            new EE_DMS_4_5_0_update_wp_user_for_prices(),
47
-            new EE_DMS_4_5_0_update_wp_user_for_price_types(),
48
-            new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
49
-            new EE_DMS_4_5_0_invoice_settings(),
50
-        );
51
-        parent::__construct($table_manager, $table_analysis);
52
-    }
34
+	/**
35
+	 * EE_DMS_Core_4_5_0 constructor.
36
+	 *
37
+	 * @param TableManager  $table_manager
38
+	 * @param TableAnalysis $table_analysis
39
+	 */
40
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
41
+	{
42
+		$this->_pretty_name = __("Data Update to Event Espresso 4.5.0", "event_espresso");
43
+		$this->_priority = 10;
44
+		$this->_migration_stages = array(
45
+			new EE_DMS_4_5_0_update_wp_user_for_tickets(),
46
+			new EE_DMS_4_5_0_update_wp_user_for_prices(),
47
+			new EE_DMS_4_5_0_update_wp_user_for_price_types(),
48
+			new EE_DMS_4_5_0_update_wp_user_for_question_groups(),
49
+			new EE_DMS_4_5_0_invoice_settings(),
50
+		);
51
+		parent::__construct($table_manager, $table_analysis);
52
+	}
53 53
 
54 54
 
55 55
 
56
-    public function can_migrate_from_version($version_array)
57
-    {
58
-        $version_string = $version_array['Core'];
59
-        if (version_compare($version_string, '4.5.0', '<=') && version_compare($version_string, '4.3.0', '>=')) {
56
+	public function can_migrate_from_version($version_array)
57
+	{
58
+		$version_string = $version_array['Core'];
59
+		if (version_compare($version_string, '4.5.0', '<=') && version_compare($version_string, '4.3.0', '>=')) {
60 60
 //          echo "$version_string can be migrated from";
61
-            return true;
62
-        } elseif (! $version_string) {
61
+			return true;
62
+		} elseif (! $version_string) {
63 63
 //          echo "no version string provided: $version_string";
64
-            // no version string provided... this must be pre 4.3
65
-            return false;// changed mind. dont want people thinking they should migrate yet because they cant
66
-        } else {
64
+			// no version string provided... this must be pre 4.3
65
+			return false;// changed mind. dont want people thinking they should migrate yet because they cant
66
+		} else {
67 67
 //          echo "$version_string doesnt apply";
68
-            return false;
69
-        }
70
-    }
68
+			return false;
69
+		}
70
+	}
71 71
 
72 72
 
73 73
 
74
-    public function schema_changes_before_migration()
75
-    {
76
-        // relies on 4.1's EEH_Activation::create_table
77
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
78
-        $table_name = 'esp_answer';
79
-        $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
74
+	public function schema_changes_before_migration()
75
+	{
76
+		// relies on 4.1's EEH_Activation::create_table
77
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
78
+		$table_name = 'esp_answer';
79
+		$sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
80 80
 					REG_ID INT UNSIGNED NOT NULL,
81 81
 					QST_ID INT UNSIGNED NOT NULL,
82 82
 					ANS_value TEXT NOT NULL,
83 83
 					PRIMARY KEY  (ANS_ID)";
84
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
85
-        $table_name = 'esp_attendee_meta';
86
-        $sql = "ATTM_ID INT(10) UNSIGNED NOT	NULL AUTO_INCREMENT,
84
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
85
+		$table_name = 'esp_attendee_meta';
86
+		$sql = "ATTM_ID INT(10) UNSIGNED NOT	NULL AUTO_INCREMENT,
87 87
 						ATT_ID BIGINT(20) UNSIGNED NOT NULL,
88 88
 						ATT_fname VARCHAR(45) NOT NULL,
89 89
 						ATT_lname VARCHAR(45) NOT	NULL,
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 								KEY ATT_fname (ATT_fname),
100 100
 								KEY ATT_lname (ATT_lname),
101 101
 								KEY ATT_email (ATT_email(191))";
102
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
103
-        $table_name = 'esp_country';
104
-        $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
102
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
103
+		$table_name = 'esp_country';
104
+		$sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
105 105
 					  CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL,
106 106
 					  RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL,
107 107
 					  CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL,
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 					  CNT_is_EU TINYINT(1) DEFAULT '0',
118 118
 					  CNT_active TINYINT(1) DEFAULT '0',
119 119
 					  PRIMARY KEY  (CNT_ISO)";
120
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
121
-        $table_name = 'esp_datetime';
122
-        $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
120
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
121
+		$table_name = 'esp_datetime';
122
+		$sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
123 123
 				  EVT_ID BIGINT(20) UNSIGNED NOT NULL,
124 124
 				  DTT_name VARCHAR(255) NOT NULL DEFAULT '',
125 125
 				  DTT_description TEXT NOT NULL,
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 						PRIMARY KEY  (DTT_ID),
135 135
 						KEY EVT_ID (EVT_ID),
136 136
 						KEY DTT_is_primary (DTT_is_primary)";
137
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
138
-        $table_name = 'esp_event_meta';
139
-        $sql = "
137
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
138
+		$table_name = 'esp_event_meta';
139
+		$sql = "
140 140
 			EVTM_ID INT NOT NULL AUTO_INCREMENT,
141 141
 			EVT_ID BIGINT(20) UNSIGNED NOT NULL,
142 142
 			EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
@@ -151,31 +151,31 @@  discard block
 block discarded – undo
151 151
 			EVT_external_URL VARCHAR(200) NULL,
152 152
 			EVT_donations TINYINT(1) NULL,
153 153
 			PRIMARY KEY  (EVTM_ID)";
154
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
155
-        $table_name = 'esp_event_question_group';
156
-        $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
154
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
155
+		$table_name = 'esp_event_question_group';
156
+		$sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
157 157
 					EVT_ID BIGINT(20) UNSIGNED NOT NULL,
158 158
 					QSG_ID INT UNSIGNED NOT NULL,
159 159
 					EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
160 160
 					PRIMARY KEY  (EQG_ID)";
161
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
162
-        $table_name = 'esp_event_venue';
163
-        $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,
161
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
162
+		$table_name = 'esp_event_venue';
163
+		$sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,
164 164
 				EVT_ID BIGINT(20) UNSIGNED NOT NULL,
165 165
 				VNU_ID BIGINT(20) UNSIGNED NOT NULL,
166 166
 				EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
167 167
 				PRIMARY KEY  (EVV_ID)";
168
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
169
-        $table_name = 'esp_extra_meta';
170
-        $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,
168
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
169
+		$table_name = 'esp_extra_meta';
170
+		$sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,
171 171
 				OBJ_ID INT(11) DEFAULT NULL,
172 172
 				EXM_type VARCHAR(45) DEFAULT NULL,
173 173
 				EXM_key VARCHAR(45) DEFAULT NULL,
174 174
 				EXM_value TEXT,
175 175
 				PRIMARY KEY  (EXM_ID)";
176
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
177
-        $table_name = 'esp_line_item';
178
-        $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,
176
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
177
+		$table_name = 'esp_line_item';
178
+		$sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,
179 179
 				LIN_code VARCHAR(245) NOT NULL DEFAULT '',
180 180
 				TXN_ID INT(11) DEFAULT NULL,
181 181
 				LIN_name VARCHAR(245) NOT NULL DEFAULT '',
@@ -191,19 +191,19 @@  discard block
 block discarded – undo
191 191
 				OBJ_ID INT(11) DEFAULT NULL,
192 192
 				OBJ_type VARCHAR(45)DEFAULT NULL,
193 193
 				PRIMARY KEY  (LIN_ID)";
194
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
195
-        $table_name = 'esp_message_template';
196
-        $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
194
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
195
+		$table_name = 'esp_message_template';
196
+		$sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
197 197
 					GRP_ID INT(10) UNSIGNED NOT NULL,
198 198
 					MTP_context VARCHAR(50) NOT NULL,
199 199
 					MTP_template_field VARCHAR(30) NOT NULL,
200 200
 					MTP_content TEXT NOT NULL,
201 201
 					PRIMARY KEY  (MTP_ID),
202 202
 					KEY GRP_ID (GRP_ID)";
203
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
204
-        $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
205
-        $table_name = 'esp_message_template_group';
206
-        $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
203
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
204
+		$this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID');
205
+		$table_name = 'esp_message_template_group';
206
+		$sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
207 207
 					MTP_user_id INT(10) NOT NULL DEFAULT '1',
208 208
 					MTP_name VARCHAR(245) NOT NULL DEFAULT '',
209 209
 					MTP_description VARCHAR(245) NOT NULL DEFAULT '',
@@ -215,17 +215,17 @@  discard block
 block discarded – undo
215 215
 					MTP_is_active TINYINT(1) NOT NULL DEFAULT '1',
216 216
 					PRIMARY KEY  (GRP_ID),
217 217
 					KEY MTP_user_id (MTP_user_id)";
218
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
219
-        $table_name = 'esp_event_message_template';
220
-        $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
218
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
219
+		$table_name = 'esp_event_message_template';
220
+		$sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
221 221
 					EVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
222 222
 					GRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0,
223 223
 					PRIMARY KEY  (EMT_ID),
224 224
 					KEY EVT_ID (EVT_ID),
225 225
 					KEY GRP_ID (GRP_ID)";
226
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
227
-        $table_name = 'esp_payment';
228
-        $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
226
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
227
+		$table_name = 'esp_payment';
228
+		$sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
229 229
 					TXN_ID INT(10) UNSIGNED DEFAULT NULL,
230 230
 					STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL,
231 231
 					PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -241,28 +241,28 @@  discard block
 block discarded – undo
241 241
 					PRIMARY KEY  (PAY_ID),
242 242
 					KEY TXN_ID (TXN_ID),
243 243
 					KEY PAY_timestamp (PAY_timestamp)";
244
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
245
-        $table_name = "esp_ticket_price";
246
-        $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
244
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
245
+		$table_name = "esp_ticket_price";
246
+		$sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
247 247
 					  TKT_ID INT(10) UNSIGNED NOT NULL,
248 248
 					  PRC_ID INT(10) UNSIGNED NOT NULL,
249 249
 					  PRIMARY KEY  (TKP_ID)";
250
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
251
-        $table_name = "esp_datetime_ticket";
252
-        $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
250
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
251
+		$table_name = "esp_datetime_ticket";
252
+		$sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
253 253
 					  DTT_ID INT(10) UNSIGNED NOT NULL,
254 254
 					  TKT_ID INT(10) UNSIGNED NOT NULL,
255 255
 					  PRIMARY KEY  (DTK_ID)";
256
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
257
-        $table_name = "esp_ticket_template";
258
-        $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
256
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
257
+		$table_name = "esp_ticket_template";
258
+		$sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
259 259
 					  TTM_name VARCHAR(45) NOT NULL,
260 260
 					  TTM_description TEXT,
261 261
 					  TTM_file VARCHAR(45),
262 262
 					  PRIMARY KEY  (TTM_ID)";
263
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
264
-        $table_name = 'esp_question';
265
-        $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
263
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
264
+		$table_name = 'esp_question';
265
+		$sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
266 266
 					QST_display_text TEXT NOT NULL,
267 267
 					QST_admin_label VARCHAR(255) NOT NULL,
268 268
 					QST_system VARCHAR(25) DEFAULT NULL,
@@ -274,25 +274,25 @@  discard block
 block discarded – undo
274 274
 					QST_wp_user BIGINT UNSIGNED NULL,
275 275
 					QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0,
276 276
 					PRIMARY KEY  (QST_ID)';
277
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
278
-        $table_name = 'esp_question_group_question';
279
-        $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
277
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
278
+		$table_name = 'esp_question_group_question';
279
+		$sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
280 280
 					QSG_ID INT UNSIGNED NOT NULL,
281 281
 					QST_ID INT UNSIGNED NOT NULL,
282 282
 					QGQ_order INT UNSIGNED NOT NULL DEFAULT 0,
283 283
 					PRIMARY KEY  (QGQ_ID) ";
284
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
285
-        $table_name = 'esp_question_option';
286
-        $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
284
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
285
+		$table_name = 'esp_question_option';
286
+		$sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
287 287
 					QSO_value VARCHAR(255) NOT NULL,
288 288
 					QSO_desc TEXT NOT NULL,
289 289
 					QST_ID INT UNSIGNED NOT NULL,
290 290
 					QSO_order INT UNSIGNED NOT NULL DEFAULT 0,
291 291
 					QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
292 292
 					PRIMARY KEY  (QSO_ID)";
293
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
294
-        $table_name = 'esp_registration';
295
-        $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
293
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
294
+		$table_name = 'esp_registration';
295
+		$sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
296 296
 					  EVT_ID BIGINT(20) UNSIGNED NOT NULL,
297 297
 					  ATT_ID BIGINT(20) UNSIGNED NOT NULL,
298 298
 					  TXN_ID INT(10) UNSIGNED NOT NULL,
@@ -315,25 +315,25 @@  discard block
 block discarded – undo
315 315
 					  KEY STS_ID (STS_ID),
316 316
 					  KEY REG_url_link (REG_url_link),
317 317
 					  KEY REG_code (REG_code)";
318
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
319
-        $table_name = 'esp_checkin';
320
-        $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
318
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
319
+		$table_name = 'esp_checkin';
320
+		$sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
321 321
 					REG_ID INT(10) UNSIGNED NOT NULL,
322 322
 					DTT_ID INT(10) UNSIGNED NOT NULL,
323 323
 					CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
324 324
 					CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
325 325
 					PRIMARY KEY  (CHK_ID)";
326
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
327
-        $table_name = 'esp_state';
328
-        $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
326
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
327
+		$table_name = 'esp_state';
328
+		$sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
329 329
 					  CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
330 330
 					  STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL,
331 331
 					  STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL,
332 332
 					  STA_active TINYINT(1) DEFAULT '1',
333 333
 					  PRIMARY KEY  (STA_ID)";
334
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
335
-        $table_name = 'esp_status';
336
-        $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,
334
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
335
+		$table_name = 'esp_status';
336
+		$sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,
337 337
 					  STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL,
338 338
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
339 339
 					  STS_can_edit TINYINT(1) NOT NULL DEFAULT 0,
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
 					  STS_open TINYINT(1) NOT NULL DEFAULT 1,
342 342
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
343 343
 					  KEY STS_type (STS_type)";
344
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
345
-        $table_name = 'esp_transaction';
346
-        $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
344
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
345
+		$table_name = 'esp_transaction';
346
+		$sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
347 347
 					  TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
348 348
 					  TXN_total DECIMAL(10,3) DEFAULT '0.00',
349 349
 					  TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00',
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
 					  PRIMARY KEY  (TXN_ID),
355 355
 					  KEY TXN_timestamp (TXN_timestamp),
356 356
 					  KEY STS_ID (STS_ID)";
357
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
358
-        $table_name = 'esp_venue_meta';
359
-        $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,
357
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
358
+		$table_name = 'esp_venue_meta';
359
+		$sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,
360 360
 			VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
361 361
 			VNU_address VARCHAR(255) DEFAULT NULL,
362 362
 			VNU_address2 VARCHAR(255) DEFAULT NULL,
@@ -374,10 +374,10 @@  discard block
 block discarded – undo
374 374
 			PRIMARY KEY  (VNUM_ID),
375 375
 			KEY STA_ID (STA_ID),
376 376
 			KEY CNT_ISO (CNT_ISO)";
377
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
378
-        // modified tables
379
-        $table_name = "esp_price";
380
-        $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
377
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
378
+		// modified tables
379
+		$table_name = "esp_price";
380
+		$sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
381 381
 					  PRT_ID TINYINT(3) UNSIGNED NOT NULL,
382 382
 					  PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',
383 383
 					  PRC_name VARCHAR(245) NOT NULL,
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
 					  PRC_wp_user BIGINT UNSIGNED NULL,
390 390
 					  PRC_parent INT(10) UNSIGNED DEFAULT 0,
391 391
 					  PRIMARY KEY  (PRC_ID)";
392
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
393
-        $table_name = "esp_price_type";
394
-        $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
392
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
393
+		$table_name = "esp_price_type";
394
+		$sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
395 395
 				  PRT_name VARCHAR(45) NOT NULL,
396 396
 				  PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
397 397
 				  PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0',
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
 				  PRT_deleted TINYINT(1) NOT NULL DEFAULT '0',
401 401
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
402 402
 				  PRIMARY KEY  (PRT_ID)";
403
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
404
-        $table_name = "esp_ticket";
405
-        $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
403
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
404
+		$table_name = "esp_ticket";
405
+		$sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
406 406
 					  TTM_ID INT(10) UNSIGNED NOT NULL,
407 407
 					  TKT_name VARCHAR(245) NOT NULL DEFAULT '',
408 408
 					  TKT_description TEXT NOT NULL,
@@ -423,10 +423,10 @@  discard block
 block discarded – undo
423 423
 					  TKT_parent INT(10) UNSIGNED DEFAULT '0',
424 424
 					  TKT_deleted TINYINT(1) NOT NULL DEFAULT '0',
425 425
 					  PRIMARY KEY  (TKT_ID)";
426
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
427
-        $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
428
-        $table_name = 'esp_question_group';
429
-        $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
426
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
427
+		$this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE');
428
+		$table_name = 'esp_question_group';
429
+		$sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
430 430
 					QSG_name VARCHAR(255) NOT NULL,
431 431
 					QSG_identifier VARCHAR(100) NOT NULL,
432 432
 					QSG_desc TEXT NULL,
@@ -438,133 +438,133 @@  discard block
 block discarded – undo
438 438
 					QSG_wp_user BIGINT UNSIGNED NULL,
439 439
 					PRIMARY KEY  (QSG_ID),
440 440
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
441
-        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
442
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
443
-        // (because many need to convert old string states to foreign keys into the states table)
444
-        $script_4_1_defaults->insert_default_states();
445
-        $script_4_1_defaults->insert_default_countries();
446
-        // schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
447
-        $this->insert_default_price_types();
448
-        $this->insert_default_prices();
449
-        $this->insert_default_tickets();
450
-        // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
451
-        EE_Config::instance()->update_espresso_config(false, true);
452
-        return true;
453
-    }
441
+		$this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
442
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
443
+		// (because many need to convert old string states to foreign keys into the states table)
444
+		$script_4_1_defaults->insert_default_states();
445
+		$script_4_1_defaults->insert_default_countries();
446
+		// schema on price, price_types and tickets has changed so use the DEFAULT method in here instead of 4.1's and later.
447
+		$this->insert_default_price_types();
448
+		$this->insert_default_prices();
449
+		$this->insert_default_tickets();
450
+		// setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
451
+		EE_Config::instance()->update_espresso_config(false, true);
452
+		return true;
453
+	}
454 454
 
455 455
 
456 456
 
457
-    /**
458
-     * @return boolean
459
-     */
460
-    public function schema_changes_after_migration()
461
-    {
462
-        return true;
463
-    }
457
+	/**
458
+	 * @return boolean
459
+	 */
460
+	public function schema_changes_after_migration()
461
+	{
462
+		return true;
463
+	}
464 464
 
465 465
 
466 466
 
467
-    public function migration_page_hooks()
468
-    {
469
-    }
467
+	public function migration_page_hooks()
468
+	{
469
+	}
470 470
 
471 471
 
472 472
 
473
-    /**
474
-     * insert_default_price_types
475
-     *
476
-     * @since 4.5.0
477
-     * @return void
478
-     */
479
-    public function insert_default_price_types()
480
-    {
481
-        global $wpdb;
482
-        $price_type_table = $wpdb->prefix . "esp_price_type";
483
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
484
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
485
-            $price_types_exist = $wpdb->get_var($SQL);
486
-            if (! $price_types_exist) {
487
-                $user_id = EEH_Activation::get_default_creator_id();
488
-                $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
473
+	/**
474
+	 * insert_default_price_types
475
+	 *
476
+	 * @since 4.5.0
477
+	 * @return void
478
+	 */
479
+	public function insert_default_price_types()
480
+	{
481
+		global $wpdb;
482
+		$price_type_table = $wpdb->prefix . "esp_price_type";
483
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
484
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table;
485
+			$price_types_exist = $wpdb->get_var($SQL);
486
+			if (! $price_types_exist) {
487
+				$user_id = EEH_Activation::get_default_creator_id();
488
+				$SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_wp_user, PRT_deleted ) VALUES
489 489
 							(1, '" . __('Base Price', 'event_espresso') . "', 1,  0, 0, $user_id, 0),
490 490
 							(2, '" . __('Percent Discount', 'event_espresso') . "', 2,  1, 20, $user_id, 0),
491 491
 							(3, '" . __('Dollar Discount', 'event_espresso') . "', 2,  0, 30, $user_id, 0),
492 492
 							(4, '" . __('Percent Surcharge', 'event_espresso') . "', 3,  1, 40, $user_id,  0),
493 493
 							(5, '" . __('Dollar Surcharge', 'event_espresso') . "', 3,  0, 50, $user_id, 0);";
494
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
495
-                $wpdb->query($SQL);
496
-            }
497
-        }
498
-    }
494
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_price_types__SQL', $SQL);
495
+				$wpdb->query($SQL);
496
+			}
497
+		}
498
+	}
499 499
 
500 500
 
501 501
 
502
-    /**
503
-     * insert DEFAULT prices.
504
-     *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
505
-     * when EEH_Activaion's initialize_db_content is called via  ahook in
506
-     * EE_Brewing_regular
507
-     *
508
-     * @since 4.5.0
509
-     * @return void
510
-     */
511
-    public function insert_default_prices()
512
-    {
513
-        global $wpdb;
514
-        $price_table = $wpdb->prefix . "esp_price";
515
-        if ($this->_get_table_analysis()->tableExists($price_table)) {
516
-            $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
517
-            $prices_exist = $wpdb->get_var($SQL);
518
-            if (! $prices_exist) {
519
-                $user_id = EEH_Activation::get_default_creator_id();
520
-                $SQL = "INSERT INTO $price_table
502
+	/**
503
+	 * insert DEFAULT prices.
504
+	 *  If we're INSTALLING 4.x CAF, then we add a few extra DEFAULT prices
505
+	 * when EEH_Activaion's initialize_db_content is called via  ahook in
506
+	 * EE_Brewing_regular
507
+	 *
508
+	 * @since 4.5.0
509
+	 * @return void
510
+	 */
511
+	public function insert_default_prices()
512
+	{
513
+		global $wpdb;
514
+		$price_table = $wpdb->prefix . "esp_price";
515
+		if ($this->_get_table_analysis()->tableExists($price_table)) {
516
+			$SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table;
517
+			$prices_exist = $wpdb->get_var($SQL);
518
+			if (! $prices_exist) {
519
+				$user_id = EEH_Activation::get_default_creator_id();
520
+				$SQL = "INSERT INTO $price_table
521 521
 							(PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc,  PRC_is_default, PRC_overrides, PRC_wp_user, PRC_order, PRC_deleted, PRC_parent ) VALUES
522 522
 							(1, 1, '0.00', 'Free Admission', '', 1, NULL, $user_id, 0, 0, 0);";
523
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
524
-                $wpdb->query($SQL);
525
-            }
526
-        }
527
-    }
523
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_prices__SQL', $SQL);
524
+				$wpdb->query($SQL);
525
+			}
526
+		}
527
+	}
528 528
 
529 529
 
530 530
 
531
-    /**
532
-     * insert DEFAULT ticket
533
-     * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
534
-     *
535
-     * @since 4.5.0
536
-     * @return void
537
-     */
538
-    public function insert_default_tickets()
539
-    {
540
-        global $wpdb;
541
-        $ticket_table = $wpdb->prefix . "esp_ticket";
542
-        if ($this->_get_table_analysis()->tableExists($ticket_table)) {
543
-            $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
544
-            $tickets_exist = $wpdb->get_var($SQL);
545
-            if (! $tickets_exist) {
546
-                $user_id = EEH_Activation::get_default_creator_id();
547
-                $SQL = "INSERT INTO $ticket_table
531
+	/**
532
+	 * insert DEFAULT ticket
533
+	 * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field
534
+	 *
535
+	 * @since 4.5.0
536
+	 * @return void
537
+	 */
538
+	public function insert_default_tickets()
539
+	{
540
+		global $wpdb;
541
+		$ticket_table = $wpdb->prefix . "esp_ticket";
542
+		if ($this->_get_table_analysis()->tableExists($ticket_table)) {
543
+			$SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
544
+			$tickets_exist = $wpdb->get_var($SQL);
545
+			if (! $tickets_exist) {
546
+				$user_id = EEH_Activation::get_default_creator_id();
547
+				$SQL = "INSERT INTO $ticket_table
548 548
 					( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES
549 549
 					( 1, 0, '"
550
-                       . __("Free Ticket", "event_espresso")
551
-                       . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
552
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
553
-                $wpdb->query($SQL);
554
-            }
555
-        }
556
-        $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
557
-        if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
558
-            $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
559
-            $ticket_prc_exist = $wpdb->get_var($SQL);
560
-            if (! $ticket_prc_exist) {
561
-                $SQL = "INSERT INTO $ticket_price_table
550
+					   . __("Free Ticket", "event_espresso")
551
+					   . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, $user_id, 0);";
552
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL);
553
+				$wpdb->query($SQL);
554
+			}
555
+		}
556
+		$ticket_price_table = $wpdb->prefix . "esp_ticket_price";
557
+		if ($this->_get_table_analysis()->tableExists($ticket_price_table)) {
558
+			$SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
559
+			$ticket_prc_exist = $wpdb->get_var($SQL);
560
+			if (! $ticket_prc_exist) {
561
+				$SQL = "INSERT INTO $ticket_price_table
562 562
 				( TKP_ID, TKT_ID, PRC_ID ) VALUES
563 563
 				( 1, 1, 1 )
564 564
 				";
565
-                $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
566
-                $wpdb->query($SQL);
567
-            }
568
-        }
569
-    }
565
+				$SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL);
566
+				$wpdb->query($SQL);
567
+			}
568
+		}
569
+	}
570 570
 }
Please login to merge, or discard this patch.