Completed
Pull Request — Gutenberg/master (#757)
by Darren
27:11
created
core/services/helpers/datetime/PhpCompatGreaterFiveSixHelper.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -8,91 +8,91 @@
 block discarded – undo
8 8
 
9 9
 class PhpCompatGreaterFiveSixHelper extends AbstractHelper
10 10
 {
11
-    /**
12
-     * PhpCompatLessFiveSixHelper constructor.
13
-     *
14
-     * @throws DomainException
15
-     */
16
-    public function __construct()
17
-    {
18
-        if (PHP_VERSION_ID < 50600) {
19
-            throw new DomainException(
20
-                sprintf(
21
-                    esc_html__(
22
-                        'The %1$s is only usable on php versions greater than 5.6.  You\'ll want to use %2$s instead.',
23
-                        'event_espresso'
24
-                    ),
25
-                    __CLASS__,
26
-                    'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
27
-                )
28
-            );
29
-        }
30
-    }
11
+	/**
12
+	 * PhpCompatLessFiveSixHelper constructor.
13
+	 *
14
+	 * @throws DomainException
15
+	 */
16
+	public function __construct()
17
+	{
18
+		if (PHP_VERSION_ID < 50600) {
19
+			throw new DomainException(
20
+				sprintf(
21
+					esc_html__(
22
+						'The %1$s is only usable on php versions greater than 5.6.  You\'ll want to use %2$s instead.',
23
+						'event_espresso'
24
+					),
25
+					__CLASS__,
26
+					'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper'
27
+				)
28
+			);
29
+		}
30
+	}
31 31
 
32
-    /**
33
-     * Returns a timezone string for the provided gmt_offset.
34
-     * This is a valid timezone string that can be sent into DateTimeZone
35
-     *
36
-     * @param float|string $gmt_offset
37
-     * @return string
38
-     */
39
-    public function getTimezoneStringFromGmtOffset($gmt_offset = '')
40
-    {
41
-        $gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
42
-        return is_float($gmt_offset_or_timezone_string)
43
-            ? $this->convertWpGmtOffsetForDateTimeZone($gmt_offset_or_timezone_string)
44
-            : $gmt_offset_or_timezone_string;
45
-    }
32
+	/**
33
+	 * Returns a timezone string for the provided gmt_offset.
34
+	 * This is a valid timezone string that can be sent into DateTimeZone
35
+	 *
36
+	 * @param float|string $gmt_offset
37
+	 * @return string
38
+	 */
39
+	public function getTimezoneStringFromGmtOffset($gmt_offset = '')
40
+	{
41
+		$gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
42
+		return is_float($gmt_offset_or_timezone_string)
43
+			? $this->convertWpGmtOffsetForDateTimeZone($gmt_offset_or_timezone_string)
44
+			: $gmt_offset_or_timezone_string;
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * Returns a formatted offset for use as an argument for constructing DateTimeZone
51
-     * @param float $gmt_offset This should be a float representing the gmt_offset.
52
-     * @return string
53
-     */
54
-    protected function convertWpGmtOffsetForDateTimeZone($gmt_offset)
55
-    {
56
-        $gmt_offset = (float) $gmt_offset;
57
-        $is_negative = $gmt_offset < 0;
58
-        $gmt_offset *= 100;
59
-        $gmt_offset = absint($gmt_offset);
60
-        // negative and need zero padding?
61
-        if (strlen($gmt_offset) < 4) {
62
-            $gmt_offset = str_pad($gmt_offset, 4, '0', STR_PAD_LEFT);
63
-        }
64
-        $gmt_offset = $this->convertToTimeFraction($gmt_offset);
65
-        // return something like -1300, -0200 or +1300, +0200
66
-        return $is_negative ? '-' . $gmt_offset : '+' . $gmt_offset;
67
-    }
49
+	/**
50
+	 * Returns a formatted offset for use as an argument for constructing DateTimeZone
51
+	 * @param float $gmt_offset This should be a float representing the gmt_offset.
52
+	 * @return string
53
+	 */
54
+	protected function convertWpGmtOffsetForDateTimeZone($gmt_offset)
55
+	{
56
+		$gmt_offset = (float) $gmt_offset;
57
+		$is_negative = $gmt_offset < 0;
58
+		$gmt_offset *= 100;
59
+		$gmt_offset = absint($gmt_offset);
60
+		// negative and need zero padding?
61
+		if (strlen($gmt_offset) < 4) {
62
+			$gmt_offset = str_pad($gmt_offset, 4, '0', STR_PAD_LEFT);
63
+		}
64
+		$gmt_offset = $this->convertToTimeFraction($gmt_offset);
65
+		// return something like -1300, -0200 or +1300, +0200
66
+		return $is_negative ? '-' . $gmt_offset : '+' . $gmt_offset;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * Converts something like `1550` to `1530` or `0275` to `0245`
72
-     * Incoming offset should be a positive value, this will mutate negative values. Be aware!
73
-     * @param int $offset
74
-     * @return mixed
75
-     */
76
-    protected function convertToTimeFraction($offset)
77
-    {
78
-        $first_part = substr($offset, 0, 2);
79
-        $second_part = substr($offset, 2, 2);
80
-        $second_part = str_replace(array('25', '50', '75'), array('15', '30', '45'), $second_part);
81
-        return $first_part . $second_part;
82
-    }
70
+	/**
71
+	 * Converts something like `1550` to `1530` or `0275` to `0245`
72
+	 * Incoming offset should be a positive value, this will mutate negative values. Be aware!
73
+	 * @param int $offset
74
+	 * @return mixed
75
+	 */
76
+	protected function convertToTimeFraction($offset)
77
+	{
78
+		$first_part = substr($offset, 0, 2);
79
+		$second_part = substr($offset, 2, 2);
80
+		$second_part = str_replace(array('25', '50', '75'), array('15', '30', '45'), $second_part);
81
+		return $first_part . $second_part;
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * Get Timezone offset for given timezone object
87
-     *
88
-     * @param DateTimeZone $date_time_zone
89
-     * @param null|int     $time
90
-     * @return int
91
-     */
92
-    public function getTimezoneOffset(DateTimezone $date_time_zone, $time = null)
93
-    {
94
-        $time = is_int($time) || $time === null ? $time : (int) strtotime($time);
95
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
96
-        return $date_time_zone->getOffset(new DateTime('@' . $time));
97
-    }
85
+	/**
86
+	 * Get Timezone offset for given timezone object
87
+	 *
88
+	 * @param DateTimeZone $date_time_zone
89
+	 * @param null|int     $time
90
+	 * @return int
91
+	 */
92
+	public function getTimezoneOffset(DateTimezone $date_time_zone, $time = null)
93
+	{
94
+		$time = is_int($time) || $time === null ? $time : (int) strtotime($time);
95
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
96
+		return $date_time_zone->getOffset(new DateTime('@' . $time));
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         }
64 64
         $gmt_offset = $this->convertToTimeFraction($gmt_offset);
65 65
         // return something like -1300, -0200 or +1300, +0200
66
-        return $is_negative ? '-' . $gmt_offset : '+' . $gmt_offset;
66
+        return $is_negative ? '-'.$gmt_offset : '+'.$gmt_offset;
67 67
     }
68 68
 
69 69
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         $first_part = substr($offset, 0, 2);
79 79
         $second_part = substr($offset, 2, 2);
80 80
         $second_part = str_replace(array('25', '50', '75'), array('15', '30', '45'), $second_part);
81
-        return $first_part . $second_part;
81
+        return $first_part.$second_part;
82 82
     }
83 83
 
84 84
 
@@ -93,6 +93,6 @@  discard block
 block discarded – undo
93 93
     {
94 94
         $time = is_int($time) || $time === null ? $time : (int) strtotime($time);
95 95
         $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
96
-        return $date_time_zone->getOffset(new DateTime('@' . $time));
96
+        return $date_time_zone->getOffset(new DateTime('@'.$time));
97 97
     }
98 98
 }
Please login to merge, or discard this patch.
core/services/helpers/datetime/AbstractHelper.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -12,136 +12,136 @@  discard block
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Ensures that a valid timezone string is returned.
17
-     *
18
-     * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
19
-     *                                 settings (or derive from set UTC offset).
20
-     * @return string
21
-     * @throws EE_Error
22
-     */
23
-    public function getValidTimezoneString($timezone_string = '')
24
-    {
25
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
26
-        $timezone_string = ! empty($timezone_string)
27
-            ? $timezone_string
28
-            : $this->getTimezoneStringFromGmtOffset();
29
-        $this->validateTimezone($timezone_string);
30
-        return $timezone_string;
31
-    }
15
+	/**
16
+	 * Ensures that a valid timezone string is returned.
17
+	 *
18
+	 * @param string $timezone_string  When not provided then attempt to use the timezone_string set in the WP Time
19
+	 *                                 settings (or derive from set UTC offset).
20
+	 * @return string
21
+	 * @throws EE_Error
22
+	 */
23
+	public function getValidTimezoneString($timezone_string = '')
24
+	{
25
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
26
+		$timezone_string = ! empty($timezone_string)
27
+			? $timezone_string
28
+			: $this->getTimezoneStringFromGmtOffset();
29
+		$this->validateTimezone($timezone_string);
30
+		return $timezone_string;
31
+	}
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
37
-     *
38
-     * @param string $timezone_string
39
-     * @param bool   $throw_error
40
-     * @return bool
41
-     * @throws EE_Error
42
-     */
43
-    public function validateTimezone($timezone_string, $throw_error = true)
44
-    {
45
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a
46
-        // DateTimeZone object with it
47
-        try {
48
-            new DateTimeZone($timezone_string);
49
-        } catch (Exception $e) {
50
-            // sometimes we take exception to exceptions
51
-            if (! $throw_error) {
52
-                return false;
53
-            }
54
-            throw new EE_Error(
55
-                sprintf(
56
-                    esc_html__(
57
-                        'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
58
-                        'event_espresso'
59
-                    ),
60
-                    $timezone_string,
61
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
62
-                    '</a>'
63
-                )
64
-            );
65
-        }
66
-        return true;
67
-    }
35
+	/**
36
+	 * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
37
+	 *
38
+	 * @param string $timezone_string
39
+	 * @param bool   $throw_error
40
+	 * @return bool
41
+	 * @throws EE_Error
42
+	 */
43
+	public function validateTimezone($timezone_string, $throw_error = true)
44
+	{
45
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a
46
+		// DateTimeZone object with it
47
+		try {
48
+			new DateTimeZone($timezone_string);
49
+		} catch (Exception $e) {
50
+			// sometimes we take exception to exceptions
51
+			if (! $throw_error) {
52
+				return false;
53
+			}
54
+			throw new EE_Error(
55
+				sprintf(
56
+					esc_html__(
57
+						'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
58
+						'event_espresso'
59
+					),
60
+					$timezone_string,
61
+					'<a href="http://www.php.net/manual/en/timezones.php">',
62
+					'</a>'
63
+				)
64
+			);
65
+		}
66
+		return true;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * Gets the site's GMT offset based on either the timezone string
72
-     * (in which case the gmt offset will vary depending on the location's
73
-     * observance of daylight savings time) or the gmt_offset wp option
74
-     *
75
-     * @return int  seconds offset
76
-     */
77
-    public function getSiteTimezoneGmtOffset()
78
-    {
79
-        $timezone_string = (string) get_option('timezone_string');
80
-        if ($timezone_string) {
81
-            try {
82
-                $timezone = new DateTimeZone($timezone_string);
83
-                return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC
84
-            } catch (Exception $e) {
85
-            }
86
-        }
87
-        $offset = get_option('gmt_offset');
88
-        return (int) ($offset * HOUR_IN_SECONDS);
89
-    }
70
+	/**
71
+	 * Gets the site's GMT offset based on either the timezone string
72
+	 * (in which case the gmt offset will vary depending on the location's
73
+	 * observance of daylight savings time) or the gmt_offset wp option
74
+	 *
75
+	 * @return int  seconds offset
76
+	 */
77
+	public function getSiteTimezoneGmtOffset()
78
+	{
79
+		$timezone_string = (string) get_option('timezone_string');
80
+		if ($timezone_string) {
81
+			try {
82
+				$timezone = new DateTimeZone($timezone_string);
83
+				return $timezone->getOffset(new DateTime()); // in WordPress DateTime defaults to UTC
84
+			} catch (Exception $e) {
85
+			}
86
+		}
87
+		$offset = get_option('gmt_offset');
88
+		return (int) ($offset * HOUR_IN_SECONDS);
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * Get Timezone offset for given timezone object
94
-     *
95
-     * @param DateTimeZone $date_time_zone
96
-     * @param null|int     $time
97
-     * @return int
98
-     * @throws DomainException
99
-     */
100
-    public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
101
-    {
102
-        $transition = $this->getTimezoneTransitions($date_time_zone, $time);
103
-        if (! isset($transition['offset'])) {
104
-            throw new DomainException(
105
-                sprintf(
106
-                    esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
107
-                    print_r($transition, true)
108
-                )
109
-            );
110
-        }
111
-        return $transition['offset'];
112
-    }
92
+	/**
93
+	 * Get Timezone offset for given timezone object
94
+	 *
95
+	 * @param DateTimeZone $date_time_zone
96
+	 * @param null|int     $time
97
+	 * @return int
98
+	 * @throws DomainException
99
+	 */
100
+	public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
101
+	{
102
+		$transition = $this->getTimezoneTransitions($date_time_zone, $time);
103
+		if (! isset($transition['offset'])) {
104
+			throw new DomainException(
105
+				sprintf(
106
+					esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
107
+					print_r($transition, true)
108
+				)
109
+			);
110
+		}
111
+		return $transition['offset'];
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * Provide a timezone select input
117
-     *
118
-     * @param string $timezone_string
119
-     * @return string
120
-     * @throws EE_Error
121
-     */
122
-    public function timezoneSelectInput($timezone_string = '')
123
-    {
124
-        // get WP date time format
125
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
126
-        // if passed a value, then use that, else get WP option
127
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
128
-        // check if the timezone is valid but don't throw any errors if it isn't
129
-        $timezone_string = $this->validateTimezone($timezone_string, false)
130
-            ? $timezone_string
131
-            : '';
132
-        $gmt_offset      = get_option('gmt_offset');
133
-        $check_zone_info = true;
134
-        if (empty($timezone_string)) {
135
-            // Create a UTC+- zone if no timezone string exists
136
-            $timezone_string = 'UTC';
137
-            $check_zone_info = false;
138
-            if ($gmt_offset > 0) {
139
-                $timezone_string = 'UTC+' . $gmt_offset;
140
-            } elseif ($gmt_offset < 0) {
141
-                $timezone_string = 'UTC' . $gmt_offset;
142
-            }
143
-        }
144
-        ?>
115
+	/**
116
+	 * Provide a timezone select input
117
+	 *
118
+	 * @param string $timezone_string
119
+	 * @return string
120
+	 * @throws EE_Error
121
+	 */
122
+	public function timezoneSelectInput($timezone_string = '')
123
+	{
124
+		// get WP date time format
125
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
126
+		// if passed a value, then use that, else get WP option
127
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
128
+		// check if the timezone is valid but don't throw any errors if it isn't
129
+		$timezone_string = $this->validateTimezone($timezone_string, false)
130
+			? $timezone_string
131
+			: '';
132
+		$gmt_offset      = get_option('gmt_offset');
133
+		$check_zone_info = true;
134
+		if (empty($timezone_string)) {
135
+			// Create a UTC+- zone if no timezone string exists
136
+			$timezone_string = 'UTC';
137
+			$check_zone_info = false;
138
+			if ($gmt_offset > 0) {
139
+				$timezone_string = 'UTC+' . $gmt_offset;
140
+			} elseif ($gmt_offset < 0) {
141
+				$timezone_string = 'UTC' . $gmt_offset;
142
+			}
143
+		}
144
+		?>
145 145
         <p>
146 146
             <label for="timezone_string"><?php _e('timezone', 'event_espresso'); ?></label>
147 147
             <select id="timezone_string" name="timezone_string">
@@ -154,150 +154,150 @@  discard block
 block discarded – undo
154 154
         <p>
155 155
         <span>
156 156
             <?php
157
-            printf(
158
-                __('%1$sUTC%2$s time is %3$s', 'event_espresso'),
159
-                '<abbr title="Coordinated Universal Time">',
160
-                '</abbr>',
161
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
162
-            );
163
-            ?></span>
157
+			printf(
158
+				__('%1$sUTC%2$s time is %3$s', 'event_espresso'),
159
+				'<abbr title="Coordinated Universal Time">',
160
+				'</abbr>',
161
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
162
+			);
163
+			?></span>
164 164
         <?php
165
-        if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
165
+		if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
166 166
         <br/><span><?php printf(__('Local time is %1$s', 'event_espresso'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
167 167
     <?php
168
-        endif; ?>
168
+		endif; ?>
169 169
 
170 170
         <?php
171
-        if ($check_zone_info && $timezone_string) : ?>
171
+		if ($check_zone_info && $timezone_string) : ?>
172 172
         <br/>
173 173
         <span>
174 174
                 <?php
175
-                // Set TZ so localtime works.
176
-                date_default_timezone_set($timezone_string);
177
-                $now = localtime(time(), true);
178
-                if ($now['tm_isdst']) {
179
-                    _e('This timezone is currently in daylight saving time.', 'event_espresso');
180
-                } else {
181
-                    _e('This timezone is currently in standard time.', 'event_espresso');
182
-                }
183
-                ?>
175
+				// Set TZ so localtime works.
176
+				date_default_timezone_set($timezone_string);
177
+				$now = localtime(time(), true);
178
+				if ($now['tm_isdst']) {
179
+					_e('This timezone is currently in daylight saving time.', 'event_espresso');
180
+				} else {
181
+					_e('This timezone is currently in standard time.', 'event_espresso');
182
+				}
183
+				?>
184 184
             <br/>
185 185
             <?php
186
-            if (function_exists('timezone_transitions_get')) {
187
-                $found                   = false;
188
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
189
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
190
-                $right_now               = time();
191
-                $tr['isdst']             = false;
192
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
193
-                    if ($tr['ts'] > $right_now) {
194
-                        $found = true;
195
-                        break;
196
-                    }
197
-                }
198
-                if ($found) {
199
-                    $message = $tr['isdst']
200
-                        ? __(' Daylight saving time begins on: %s.', 'event_espresso')
201
-                        : __(' Standard time begins  on: %s.', 'event_espresso');
202
-                    // Add the difference between the current offset and the new offset to ts to get the correct
203
-                    // transition time from date_i18n().
204
-                    printf(
205
-                        $message,
206
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
207
-                    );
208
-                } else {
209
-                    _e('This timezone does not observe daylight saving time.', 'event_espresso');
210
-                }
211
-            }
212
-            // Set back to UTC.
213
-            date_default_timezone_set('UTC');
214
-            ?>
186
+			if (function_exists('timezone_transitions_get')) {
187
+				$found                   = false;
188
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
189
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
190
+				$right_now               = time();
191
+				$tr['isdst']             = false;
192
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
193
+					if ($tr['ts'] > $right_now) {
194
+						$found = true;
195
+						break;
196
+					}
197
+				}
198
+				if ($found) {
199
+					$message = $tr['isdst']
200
+						? __(' Daylight saving time begins on: %s.', 'event_espresso')
201
+						: __(' Standard time begins  on: %s.', 'event_espresso');
202
+					// Add the difference between the current offset and the new offset to ts to get the correct
203
+					// transition time from date_i18n().
204
+					printf(
205
+						$message,
206
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
207
+					);
208
+				} else {
209
+					_e('This timezone does not observe daylight saving time.', 'event_espresso');
210
+				}
211
+			}
212
+			// Set back to UTC.
213
+			date_default_timezone_set('UTC');
214
+			?>
215 215
         </span></p>
216 216
         <?php
217
-        endif;
218
-    }
217
+		endif;
218
+	}
219 219
 
220 220
 
221
-    /**
222
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
223
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
224
-     * the site is used.
225
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
226
-     * computed timestamp (i.e. date_i18n() )
227
-     *
228
-     * @param int    $unix_timestamp  if 0, then time() will be used.
229
-     * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
230
-     *                                site will be used.
231
-     * @return int      unix_timestamp value with the offset applied for the given timezone.
232
-     * @throws EE_Error
233
-     */
234
-    public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
235
-    {
236
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
237
-        $timezone_string = $this->getValidTimezoneString($timezone_string);
238
-        $TimeZone        = new DateTimeZone($timezone_string);
239
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
240
-        $offset          = timezone_offset_get($TimeZone, $DateTime);
241
-        return (int) $DateTime->format('U') + (int) $offset;
242
-    }
221
+	/**
222
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
223
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
224
+	 * the site is used.
225
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
226
+	 * computed timestamp (i.e. date_i18n() )
227
+	 *
228
+	 * @param int    $unix_timestamp  if 0, then time() will be used.
229
+	 * @param string $timezone_string timezone_string. If empty, then the current set timezone for the
230
+	 *                                site will be used.
231
+	 * @return int      unix_timestamp value with the offset applied for the given timezone.
232
+	 * @throws EE_Error
233
+	 */
234
+	public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = '')
235
+	{
236
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
237
+		$timezone_string = $this->getValidTimezoneString($timezone_string);
238
+		$TimeZone        = new DateTimeZone($timezone_string);
239
+		$DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
240
+		$offset          = timezone_offset_get($TimeZone, $DateTime);
241
+		return (int) $DateTime->format('U') + (int) $offset;
242
+	}
243 243
 
244 244
 
245
-    /**
246
-     * Get Timezone Transitions
247
-     *
248
-     * @param DateTimeZone $date_time_zone
249
-     * @param int|null     $time
250
-     * @param bool         $first_only
251
-     * @return array|mixed
252
-     */
253
-    public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
254
-    {
255
-        $time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
256
-        $time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
257
-        $transitions = $date_time_zone->getTransitions($time);
258
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
259
-    }
245
+	/**
246
+	 * Get Timezone Transitions
247
+	 *
248
+	 * @param DateTimeZone $date_time_zone
249
+	 * @param int|null     $time
250
+	 * @param bool         $first_only
251
+	 * @return array|mixed
252
+	 */
253
+	public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true)
254
+	{
255
+		$time        = is_int($time) || $time === null ? $time : (int) strtotime($time);
256
+		$time        = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
257
+		$transitions = $date_time_zone->getTransitions($time);
258
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
259
+	}
260 260
 
261 261
 
262 262
 
263
-    /**
264
-     * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
265
-     *
266
-     * @param int $gmt_offset
267
-     * @return int
268
-     */
269
-    public function adjustInvalidGmtOffsets($gmt_offset = 0)
270
-    {
271
-        return $gmt_offset;
272
-    }
263
+	/**
264
+	 * Default to just returning the provided $gmt_offset.  Children can override if adjustment needed.
265
+	 *
266
+	 * @param int $gmt_offset
267
+	 * @return int
268
+	 */
269
+	public function adjustInvalidGmtOffsets($gmt_offset = 0)
270
+	{
271
+		return $gmt_offset;
272
+	}
273 273
 
274 274
 
275 275
 
276
-    /**
277
-     * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
278
-     * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
279
-     * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
280
-     * offset.
281
-     * @param  float|string $gmt_offset
282
-     * @return float|string
283
-     */
284
-    protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
285
-    {
286
-        // if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
287
-        // set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
288
-        // that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
289
-        if ($gmt_offset === '') {
290
-            // autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
291
-            if (get_option('timezone_string')) {
292
-                return (string) get_option('timezone_string');
293
-            }
294
-        }
295
-        $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
296
-        $gmt_offset = (float) $gmt_offset;
297
-        // if $gmt_offset is 0 or is still an empty string, then just return UTC
298
-        if ($gmt_offset === (float) 0) {
299
-            return 'UTC';
300
-        }
301
-        return $gmt_offset;
302
-    }
276
+	/**
277
+	 * This receives an incoming gmt_offset and santizes it.  If the provide value is an empty string, then this will
278
+	 * attempt to get the offset from the timezone string.  If this returns a string, then a timezone string was
279
+	 * successfully derived from existing timezone_string in the db.  If not, then a float is returned for the provided
280
+	 * offset.
281
+	 * @param  float|string $gmt_offset
282
+	 * @return float|string
283
+	 */
284
+	protected function sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset)
285
+	{
286
+		// if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is
287
+		// set because it will override `gmt_offset` via `pre_get_option` filter.  If that's set, then let's just use
288
+		// that!  Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic.
289
+		if ($gmt_offset === '') {
290
+			// autoloaded so no need to set to a variable.  There will not be multiple hits to the db.
291
+			if (get_option('timezone_string')) {
292
+				return (string) get_option('timezone_string');
293
+			}
294
+		}
295
+		$gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset');
296
+		$gmt_offset = (float) $gmt_offset;
297
+		// if $gmt_offset is 0 or is still an empty string, then just return UTC
298
+		if ($gmt_offset === (float) 0) {
299
+			return 'UTC';
300
+		}
301
+		return $gmt_offset;
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             new DateTimeZone($timezone_string);
49 49
         } catch (Exception $e) {
50 50
             // sometimes we take exception to exceptions
51
-            if (! $throw_error) {
51
+            if ( ! $throw_error) {
52 52
                 return false;
53 53
             }
54 54
             throw new EE_Error(
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null)
101 101
     {
102 102
         $transition = $this->getTimezoneTransitions($date_time_zone, $time);
103
-        if (! isset($transition['offset'])) {
103
+        if ( ! isset($transition['offset'])) {
104 104
             throw new DomainException(
105 105
                 sprintf(
106 106
                     esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'),
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     public function timezoneSelectInput($timezone_string = '')
123 123
     {
124 124
         // get WP date time format
125
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
125
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
126 126
         // if passed a value, then use that, else get WP option
127 127
         $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string');
128 128
         // check if the timezone is valid but don't throw any errors if it isn't
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
             $timezone_string = 'UTC';
137 137
             $check_zone_info = false;
138 138
             if ($gmt_offset > 0) {
139
-                $timezone_string = 'UTC+' . $gmt_offset;
139
+                $timezone_string = 'UTC+'.$gmt_offset;
140 140
             } elseif ($gmt_offset < 0) {
141
-                $timezone_string = 'UTC' . $gmt_offset;
141
+                $timezone_string = 'UTC'.$gmt_offset;
142 142
             }
143 143
         }
144 144
         ?>
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
                 __('%1$sUTC%2$s time is %3$s', 'event_espresso'),
159 159
                 '<abbr title="Coordinated Universal Time">',
160 160
                 '</abbr>',
161
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
161
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
162 162
             );
163 163
             ?></span>
164 164
         <?php
165
-        if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
166
-        <br/><span><?php printf(__('Local time is %1$s', 'event_espresso'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
165
+        if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
166
+        <br/><span><?php printf(__('Local time is %1$s', 'event_espresso'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
167 167
     <?php
168 168
         endif; ?>
169 169
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
                     // transition time from date_i18n().
204 204
                     printf(
205 205
                         $message,
206
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'
206
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'
207 207
                     );
208 208
                 } else {
209 209
                     _e('This timezone does not observe daylight saving time.', 'event_espresso');
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
         $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
237 237
         $timezone_string = $this->getValidTimezoneString($timezone_string);
238 238
         $TimeZone        = new DateTimeZone($timezone_string);
239
-        $DateTime        = new DateTime('@' . $unix_timestamp, $TimeZone);
239
+        $DateTime        = new DateTime('@'.$unix_timestamp, $TimeZone);
240 240
         $offset          = timezone_offset_get($TimeZone, $DateTime);
241 241
         return (int) $DateTime->format('U') + (int) $offset;
242 242
     }
Please login to merge, or discard this patch.
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
-                    ' &nbsp; &nbsp; ' . $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
-                    ' &nbsp; &nbsp; ' . $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
-                        ' &nbsp; &nbsp; ' . $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
+					' &nbsp; &nbsp; ' . $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
+					' &nbsp; &nbsp; ' . $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
+						' &nbsp; &nbsp; ' . $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
-                    ' &nbsp; &nbsp; ' . $e->getMessage()
122
+                    ' &nbsp; &nbsp; '.$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
-                    ' &nbsp; &nbsp; ' . $e->getMessage()
187
+                    ' &nbsp; &nbsp; '.$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
-                        ' &nbsp; &nbsp; ' . $e->getMessage()
258
+                        ' &nbsp; &nbsp; '.$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.