Completed
Branch FET/custom-qr-code-requirement... (1b6fa1)
by
unknown
12:38 queued 10:55
created
core/services/helpers/datetime/PhpCompatLessFiveSixHelper.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -18,221 +18,221 @@
 block discarded – undo
18 18
 class PhpCompatLessFiveSixHelper extends AbstractHelper
19 19
 {
20 20
 
21
-    /**
22
-     * PhpCompatLessFiveSixHelper constructor.
23
-     *
24
-     * @throws DomainException
25
-     */
26
-    public function __construct()
27
-    {
28
-        if (PHP_VERSION_ID >= 50600) {
29
-            throw new DomainException(
30
-                sprintf(
31
-                    esc_html__(
32
-                        'The %1$s is only usable on php versions less than 5.6.  You\'ll want to use %2$s instead.',
33
-                        'event_espresso'
34
-                    ),
35
-                    __CLASS__,
36
-                    'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'
37
-                )
38
-            );
39
-        }
40
-    }
21
+	/**
22
+	 * PhpCompatLessFiveSixHelper constructor.
23
+	 *
24
+	 * @throws DomainException
25
+	 */
26
+	public function __construct()
27
+	{
28
+		if (PHP_VERSION_ID >= 50600) {
29
+			throw new DomainException(
30
+				sprintf(
31
+					esc_html__(
32
+						'The %1$s is only usable on php versions less than 5.6.  You\'ll want to use %2$s instead.',
33
+						'event_espresso'
34
+					),
35
+					__CLASS__,
36
+					'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'
37
+				)
38
+			);
39
+		}
40
+	}
41 41
 
42
-    /**
43
-     * Returns a timezone string for the provided gmt_offset.
44
-     *
45
-     * @param float|string $gmt_offset
46
-     * @return string
47
-     * @throws EE_Error
48
-     */
49
-    public function getTimezoneStringFromGmtOffset($gmt_offset = '')
50
-    {
51
-        $gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
52
-        if (is_string($gmt_offset_or_timezone_string)) {
53
-            return $gmt_offset_or_timezone_string;
54
-        }
55
-        // well we know its a float, so let's roll with it.
56
-        $gmt_offset = $gmt_offset_or_timezone_string;
57
-        // convert GMT offset to seconds
58
-        $gmt_offset *= HOUR_IN_SECONDS;
59
-        // although we don't know the TZ abbreviation, we know the UTC offset
60
-        $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
61
-        // only use this timezone_string IF it's current offset matches the given offset
62
-        if (! empty($timezone_string)) {
63
-            $offset = null;
64
-            try {
65
-                $offset = $this->getTimezoneOffset(new DateTimeZone($timezone_string));
66
-                if ($offset !== $gmt_offset) {
67
-                    $timezone_string = false;
68
-                }
69
-            } catch (Exception $e) {
70
-                $timezone_string = false;
71
-            }
72
-        }
73
-        // better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()
74
-        // ...
75
-        $timezone_string = $timezone_string !== false
76
-            ? $timezone_string
77
-            : $this->getTimezoneStringFromAbbreviationsList($gmt_offset);
78
-        return $timezone_string;
79
-    }
42
+	/**
43
+	 * Returns a timezone string for the provided gmt_offset.
44
+	 *
45
+	 * @param float|string $gmt_offset
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 */
49
+	public function getTimezoneStringFromGmtOffset($gmt_offset = '')
50
+	{
51
+		$gmt_offset_or_timezone_string = $this->sanitizeInitialIncomingGmtOffsetForGettingTimezoneString($gmt_offset);
52
+		if (is_string($gmt_offset_or_timezone_string)) {
53
+			return $gmt_offset_or_timezone_string;
54
+		}
55
+		// well we know its a float, so let's roll with it.
56
+		$gmt_offset = $gmt_offset_or_timezone_string;
57
+		// convert GMT offset to seconds
58
+		$gmt_offset *= HOUR_IN_SECONDS;
59
+		// although we don't know the TZ abbreviation, we know the UTC offset
60
+		$timezone_string = timezone_name_from_abbr(null, $gmt_offset);
61
+		// only use this timezone_string IF it's current offset matches the given offset
62
+		if (! empty($timezone_string)) {
63
+			$offset = null;
64
+			try {
65
+				$offset = $this->getTimezoneOffset(new DateTimeZone($timezone_string));
66
+				if ($offset !== $gmt_offset) {
67
+					$timezone_string = false;
68
+				}
69
+			} catch (Exception $e) {
70
+				$timezone_string = false;
71
+			}
72
+		}
73
+		// better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()
74
+		// ...
75
+		$timezone_string = $timezone_string !== false
76
+			? $timezone_string
77
+			: $this->getTimezoneStringFromAbbreviationsList($gmt_offset);
78
+		return $timezone_string;
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * @param int  $gmt_offset
84
-     * @param bool $coerce If true, we attempt to coerce with our adjustment table
85
-     * @see self::adjustInvalidGmtOffset
86
-     * @return string
87
-     * @throws EE_Error
88
-     */
89
-    protected function getTimezoneStringFromAbbreviationsList($gmt_offset = 0, $coerce = true)
90
-    {
91
-        $gmt_offset = (int) $gmt_offset;
92
-        /** @var array[] $abbreviations */
93
-        $abbreviations = DateTimeZone::listAbbreviations();
94
-        foreach ($abbreviations as $abbreviation) {
95
-            foreach ($abbreviation as $timezone) {
96
-                if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
97
-                    try {
98
-                        $offset = $this->getTimezoneOffset(new DateTimeZone($timezone['timezone_id']));
99
-                        if ($offset !== $gmt_offset) {
100
-                            continue;
101
-                        }
102
-                        return $timezone['timezone_id'];
103
-                    } catch (Exception $e) {
104
-                        continue;
105
-                    }
106
-                }
107
-            }
108
-        }
109
-        // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
110
-        if ($coerce === true) {
111
-            $timezone_string = $this->getTimezoneStringFromAbbreviationsList(
112
-                $this->adjustInvalidGmtOffsets($gmt_offset),
113
-                false
114
-            );
115
-            if ($timezone_string) {
116
-                return $timezone_string;
117
-            }
118
-        }
119
-        throw new EE_Error(
120
-            sprintf(
121
-                esc_html__(
122
-                    'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
123
-                    'event_espresso'
124
-                ),
125
-                $gmt_offset / HOUR_IN_SECONDS,
126
-                '<a href="http://www.php.net/manual/en/timezones.php">',
127
-                '</a>'
128
-            )
129
-        );
130
-    }
82
+	/**
83
+	 * @param int  $gmt_offset
84
+	 * @param bool $coerce If true, we attempt to coerce with our adjustment table
85
+	 * @see self::adjustInvalidGmtOffset
86
+	 * @return string
87
+	 * @throws EE_Error
88
+	 */
89
+	protected function getTimezoneStringFromAbbreviationsList($gmt_offset = 0, $coerce = true)
90
+	{
91
+		$gmt_offset = (int) $gmt_offset;
92
+		/** @var array[] $abbreviations */
93
+		$abbreviations = DateTimeZone::listAbbreviations();
94
+		foreach ($abbreviations as $abbreviation) {
95
+			foreach ($abbreviation as $timezone) {
96
+				if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) {
97
+					try {
98
+						$offset = $this->getTimezoneOffset(new DateTimeZone($timezone['timezone_id']));
99
+						if ($offset !== $gmt_offset) {
100
+							continue;
101
+						}
102
+						return $timezone['timezone_id'];
103
+					} catch (Exception $e) {
104
+						continue;
105
+					}
106
+				}
107
+			}
108
+		}
109
+		// if $coerce is true, let's see if we can get a timezone string after the offset is adjusted
110
+		if ($coerce === true) {
111
+			$timezone_string = $this->getTimezoneStringFromAbbreviationsList(
112
+				$this->adjustInvalidGmtOffsets($gmt_offset),
113
+				false
114
+			);
115
+			if ($timezone_string) {
116
+				return $timezone_string;
117
+			}
118
+		}
119
+		throw new EE_Error(
120
+			sprintf(
121
+				esc_html__(
122
+					'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
123
+					'event_espresso'
124
+				),
125
+				$gmt_offset / HOUR_IN_SECONDS,
126
+				'<a href="http://www.php.net/manual/en/timezones.php">',
127
+				'</a>'
128
+			)
129
+		);
130
+	}
131 131
 
132 132
 
133
-    /**
134
-     * Depending on PHP version,
135
-     * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
136
-     * To get around that, for these fringe timezones we bump them to a known valid offset.
137
-     * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
138
-     *
139
-     * @param int $gmt_offset
140
-     * @return int
141
-     */
142
-    public function adjustInvalidGmtOffsets($gmt_offset = 0)
143
-    {
144
-        // make sure $gmt_offset is int
145
-        $gmt_offset = (int) $gmt_offset;
146
-        switch ($gmt_offset) {
147
-            // -12
148
-            case -43200:
149
-                $gmt_offset = -39600;
150
-                break;
151
-            // -11.5
152
-            case -41400:
153
-                $gmt_offset = -39600;
154
-                break;
155
-            // -10.5
156
-            case -37800:
157
-                $gmt_offset = -39600;
158
-                break;
159
-            // -8.5
160
-            case -30600:
161
-                $gmt_offset = -28800;
162
-                break;
163
-            // -7.5
164
-            case -27000:
165
-                $gmt_offset = -25200;
166
-                break;
167
-            // -6.5
168
-            case -23400:
169
-                $gmt_offset = -21600;
170
-                break;
171
-            // -5.5
172
-            case -19800:
173
-                $gmt_offset = -18000;
174
-                break;
175
-            // -4.5
176
-            case -16200:
177
-                $gmt_offset = -14400;
178
-                break;
179
-            // -3.5
180
-            case -12600:
181
-                $gmt_offset = -10800;
182
-                break;
183
-            // -2.5
184
-            case -9000:
185
-                $gmt_offset = -7200;
186
-                break;
187
-            // -1.5
188
-            case -5400:
189
-                $gmt_offset = -3600;
190
-                break;
191
-            // -0.5
192
-            case -1800:
193
-                $gmt_offset = 0;
194
-                break;
195
-            // .5
196
-            case 1800:
197
-                $gmt_offset = 3600;
198
-                break;
199
-            // 1.5
200
-            case 5400:
201
-                $gmt_offset = 7200;
202
-                break;
203
-            // 2.5
204
-            case 9000:
205
-                $gmt_offset = 10800;
206
-                break;
207
-            // 3.5
208
-            case 12600:
209
-                $gmt_offset = 14400;
210
-                break;
211
-            // 7.5
212
-            case 27000:
213
-                $gmt_offset = 28800;
214
-                break;
215
-            // 8.5
216
-            case 30600:
217
-                $gmt_offset = 31500;
218
-                break;
219
-            // 10.5
220
-            case 37800:
221
-                $gmt_offset = 39600;
222
-                break;
223
-            // 11.5
224
-            case 41400:
225
-                $gmt_offset = 43200;
226
-                break;
227
-            // 12.75
228
-            case 45900:
229
-                $gmt_offset = 46800;
230
-                break;
231
-            // 13.75
232
-            case 49500:
233
-                $gmt_offset = 50400;
234
-                break;
235
-        }
236
-        return $gmt_offset;
237
-    }
133
+	/**
134
+	 * Depending on PHP version,
135
+	 * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables.
136
+	 * To get around that, for these fringe timezones we bump them to a known valid offset.
137
+	 * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset.
138
+	 *
139
+	 * @param int $gmt_offset
140
+	 * @return int
141
+	 */
142
+	public function adjustInvalidGmtOffsets($gmt_offset = 0)
143
+	{
144
+		// make sure $gmt_offset is int
145
+		$gmt_offset = (int) $gmt_offset;
146
+		switch ($gmt_offset) {
147
+			// -12
148
+			case -43200:
149
+				$gmt_offset = -39600;
150
+				break;
151
+			// -11.5
152
+			case -41400:
153
+				$gmt_offset = -39600;
154
+				break;
155
+			// -10.5
156
+			case -37800:
157
+				$gmt_offset = -39600;
158
+				break;
159
+			// -8.5
160
+			case -30600:
161
+				$gmt_offset = -28800;
162
+				break;
163
+			// -7.5
164
+			case -27000:
165
+				$gmt_offset = -25200;
166
+				break;
167
+			// -6.5
168
+			case -23400:
169
+				$gmt_offset = -21600;
170
+				break;
171
+			// -5.5
172
+			case -19800:
173
+				$gmt_offset = -18000;
174
+				break;
175
+			// -4.5
176
+			case -16200:
177
+				$gmt_offset = -14400;
178
+				break;
179
+			// -3.5
180
+			case -12600:
181
+				$gmt_offset = -10800;
182
+				break;
183
+			// -2.5
184
+			case -9000:
185
+				$gmt_offset = -7200;
186
+				break;
187
+			// -1.5
188
+			case -5400:
189
+				$gmt_offset = -3600;
190
+				break;
191
+			// -0.5
192
+			case -1800:
193
+				$gmt_offset = 0;
194
+				break;
195
+			// .5
196
+			case 1800:
197
+				$gmt_offset = 3600;
198
+				break;
199
+			// 1.5
200
+			case 5400:
201
+				$gmt_offset = 7200;
202
+				break;
203
+			// 2.5
204
+			case 9000:
205
+				$gmt_offset = 10800;
206
+				break;
207
+			// 3.5
208
+			case 12600:
209
+				$gmt_offset = 14400;
210
+				break;
211
+			// 7.5
212
+			case 27000:
213
+				$gmt_offset = 28800;
214
+				break;
215
+			// 8.5
216
+			case 30600:
217
+				$gmt_offset = 31500;
218
+				break;
219
+			// 10.5
220
+			case 37800:
221
+				$gmt_offset = 39600;
222
+				break;
223
+			// 11.5
224
+			case 41400:
225
+				$gmt_offset = 43200;
226
+				break;
227
+			// 12.75
228
+			case 45900:
229
+				$gmt_offset = 46800;
230
+				break;
231
+			// 13.75
232
+			case 49500:
233
+				$gmt_offset = 50400;
234
+				break;
235
+		}
236
+		return $gmt_offset;
237
+	}
238 238
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
         // although we don't know the TZ abbreviation, we know the UTC offset
60 60
         $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
61 61
         // only use this timezone_string IF it's current offset matches the given offset
62
-        if (! empty($timezone_string)) {
62
+        if ( ! empty($timezone_string)) {
63 63
             $offset = null;
64 64
             try {
65 65
                 $offset = $this->getTimezoneOffset(new DateTimeZone($timezone_string));
Please login to merge, or discard this patch.
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_Load_Espresso_Core.core.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -27,114 +27,114 @@
 block discarded – undo
27 27
 class EE_Load_Espresso_Core implements RequestDecoratorInterface, RequestStackCoreAppInterface
28 28
 {
29 29
 
30
-    /**
31
-     * @var RequestInterface $request
32
-     */
33
-    protected $request;
34
-
35
-    /**
36
-     * @var ResponseInterface $response
37
-     */
38
-    protected $response;
39
-
40
-    /**
41
-     * @var EE_Dependency_Map $dependency_map
42
-     */
43
-    protected $dependency_map;
44
-
45
-    /**
46
-     * @var EE_Registry $registry
47
-     */
48
-    protected $registry;
49
-
50
-
51
-    /**
52
-     * EE_Load_Espresso_Core constructor
53
-     *
54
-     * @param EE_Registry       $registry
55
-     * @param EE_Dependency_Map $dependency_map
56
-     * @throws EE_Error
57
-     */
58
-    public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map)
59
-    {
60
-        EE_Error::doing_it_wrong(
61
-            __METHOD__,
62
-            sprintf(
63
-                esc_html__(
64
-                    'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
65
-                    'event_espresso'
66
-                ),
67
-                'EventEspresso\core\services\request\RequestStackCoreApp',
68
-                '\core\services\request',
69
-                'EventEspresso\core\services\request'
70
-            ),
71
-            '4.9.53'
72
-        );
73
-    }
74
-
75
-
76
-    /**
77
-     * handle
78
-     * sets hooks for running rest of system
79
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
80
-     * starting EE Addons from any other point may lead to problems
81
-     *
82
-     * @param RequestInterface  $request
83
-     * @param ResponseInterface $response
84
-     * @return ResponseInterface
85
-     * @throws EE_Error
86
-     * @throws InvalidDataTypeException
87
-     * @throws InvalidInterfaceException
88
-     * @throws InvalidArgumentException
89
-     * @throws DomainException
90
-     */
91
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
92
-    {
93
-    }
94
-
95
-
96
-    /**
97
-     * @return RequestInterface
98
-     */
99
-    public function request()
100
-    {
101
-    }
102
-
103
-
104
-    /**
105
-     * @return ResponseInterface
106
-     */
107
-    public function response()
108
-    {
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EE_Dependency_Map
114
-     * @throws EE_Error
115
-     */
116
-    public function dependency_map()
117
-    {
118
-    }
119
-
120
-
121
-    /**
122
-     * @return EE_Registry
123
-     * @throws EE_Error
124
-     */
125
-    public function registry()
126
-    {
127
-    }
128
-
129
-
130
-    /**
131
-     * called after the request stack has been fully processed
132
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
133
-     *
134
-     * @param RequestInterface  $request
135
-     * @param ResponseInterface $response
136
-     */
137
-    public function handleResponse(RequestInterface $request, ResponseInterface $response)
138
-    {
139
-    }
30
+	/**
31
+	 * @var RequestInterface $request
32
+	 */
33
+	protected $request;
34
+
35
+	/**
36
+	 * @var ResponseInterface $response
37
+	 */
38
+	protected $response;
39
+
40
+	/**
41
+	 * @var EE_Dependency_Map $dependency_map
42
+	 */
43
+	protected $dependency_map;
44
+
45
+	/**
46
+	 * @var EE_Registry $registry
47
+	 */
48
+	protected $registry;
49
+
50
+
51
+	/**
52
+	 * EE_Load_Espresso_Core constructor
53
+	 *
54
+	 * @param EE_Registry       $registry
55
+	 * @param EE_Dependency_Map $dependency_map
56
+	 * @throws EE_Error
57
+	 */
58
+	public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map)
59
+	{
60
+		EE_Error::doing_it_wrong(
61
+			__METHOD__,
62
+			sprintf(
63
+				esc_html__(
64
+					'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
65
+					'event_espresso'
66
+				),
67
+				'EventEspresso\core\services\request\RequestStackCoreApp',
68
+				'\core\services\request',
69
+				'EventEspresso\core\services\request'
70
+			),
71
+			'4.9.53'
72
+		);
73
+	}
74
+
75
+
76
+	/**
77
+	 * handle
78
+	 * sets hooks for running rest of system
79
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
80
+	 * starting EE Addons from any other point may lead to problems
81
+	 *
82
+	 * @param RequestInterface  $request
83
+	 * @param ResponseInterface $response
84
+	 * @return ResponseInterface
85
+	 * @throws EE_Error
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws InvalidInterfaceException
88
+	 * @throws InvalidArgumentException
89
+	 * @throws DomainException
90
+	 */
91
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
92
+	{
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return RequestInterface
98
+	 */
99
+	public function request()
100
+	{
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return ResponseInterface
106
+	 */
107
+	public function response()
108
+	{
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EE_Dependency_Map
114
+	 * @throws EE_Error
115
+	 */
116
+	public function dependency_map()
117
+	{
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return EE_Registry
123
+	 * @throws EE_Error
124
+	 */
125
+	public function registry()
126
+	{
127
+	}
128
+
129
+
130
+	/**
131
+	 * called after the request stack has been fully processed
132
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
133
+	 *
134
+	 * @param RequestInterface  $request
135
+	 * @param ResponseInterface $response
136
+	 */
137
+	public function handleResponse(RequestInterface $request, ResponseInterface $response)
138
+	{
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/EE_Object_Collection.core.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -16,160 +16,160 @@
 block discarded – undo
16 16
 abstract class EE_Object_Collection extends SplObjectStorage implements EEI_Collection
17 17
 {
18 18
 
19
-    /**
20
-     * an interface (or class) name to be used for restricting the type of objects added to the storage
21
-     * this should be set from within the child class constructor
22
-     *
23
-     * @type string $interface
24
-     */
25
-    protected $interface;
26
-
27
-
28
-    /**
29
-     * add
30
-     *
31
-     * attaches an object to the Collection
32
-     * and sets any supplied data associated with the current iterator entry
33
-     * by calling EE_Object_Collection::set_info()
34
-     *
35
-     * @access public
36
-     * @param object $object
37
-     * @param mixed  $info
38
-     * @return bool
39
-     */
40
-    public function add($object, $info = null)
41
-    {
42
-        $class = $this->interface;
43
-        if (! $object instanceof $class) {
44
-            return false;
45
-        }
46
-        $this->attach($object);
47
-        $this->set_info($object, $info);
48
-        return $this->contains($object);
49
-    }
50
-
51
-
52
-    /**
53
-     * set_info
54
-     *
55
-     * Sets the data associated with an object in the Collection
56
-     * if no $info is supplied, then the spl_object_hash() is used
57
-     *
58
-     * @access public
59
-     * @param object $object
60
-     * @param mixed  $info
61
-     * @return bool
62
-     */
63
-    public function set_info($object, $info = null)
64
-    {
65
-        $info = ! empty($info) ? $info : spl_object_hash($object);
66
-        $this->rewind();
67
-        while ($this->valid()) {
68
-            if ($object == $this->current()) {
69
-                $this->setInfo($info);
70
-                $this->rewind();
71
-                return true;
72
-            }
73
-            $this->next();
74
-        }
75
-        return false;
76
-    }
77
-
78
-
79
-    /**
80
-     * get_by_info
81
-     *
82
-     * finds and returns an object in the Collection based on the info that was set using addObject()
83
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
84
-     *
85
-     * @access public
86
-     * @param mixed
87
-     * @return null | object
88
-     */
89
-    public function get_by_info($info)
90
-    {
91
-        $this->rewind();
92
-        while ($this->valid()) {
93
-            if ($info === $this->getInfo()) {
94
-                $object = $this->current();
95
-                $this->rewind();
96
-                return $object;
97
-            }
98
-            $this->next();
99
-        }
100
-        return null;
101
-    }
102
-
103
-
104
-    /**
105
-     * has
106
-     *
107
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
108
-     *
109
-     * @access public
110
-     * @param object $object
111
-     * @return bool
112
-     */
113
-    public function has($object)
114
-    {
115
-        return $this->contains($object);
116
-    }
117
-
118
-
119
-    /**
120
-     * remove
121
-     *
122
-     * detaches an object from the Collection
123
-     *
124
-     * @access public
125
-     * @param $object
126
-     * @return bool
127
-     */
128
-    public function remove($object)
129
-    {
130
-        $this->detach($object);
131
-        return true;
132
-    }
133
-
134
-
135
-    /**
136
-     * set_current
137
-     *
138
-     * advances pointer to the provided object
139
-     *
140
-     * @access public
141
-     * @param $object
142
-     * @return void
143
-     */
144
-    public function set_current($object)
145
-    {
146
-        $this->rewind();
147
-        while ($this->valid()) {
148
-            if ($this->current() === $object) {
149
-                break;
150
-            }
151
-            $this->next();
152
-        }
153
-    }
154
-
155
-
156
-    /**
157
-     * set_current_by_info
158
-     *
159
-     * advances pointer to the object whose info matches that which was provided
160
-     *
161
-     * @access public
162
-     * @param $info
163
-     * @return void
164
-     */
165
-    public function set_current_by_info($info)
166
-    {
167
-        $this->rewind();
168
-        while ($this->valid()) {
169
-            if ($info === $this->getInfo()) {
170
-                break;
171
-            }
172
-            $this->next();
173
-        }
174
-    }
19
+	/**
20
+	 * an interface (or class) name to be used for restricting the type of objects added to the storage
21
+	 * this should be set from within the child class constructor
22
+	 *
23
+	 * @type string $interface
24
+	 */
25
+	protected $interface;
26
+
27
+
28
+	/**
29
+	 * add
30
+	 *
31
+	 * attaches an object to the Collection
32
+	 * and sets any supplied data associated with the current iterator entry
33
+	 * by calling EE_Object_Collection::set_info()
34
+	 *
35
+	 * @access public
36
+	 * @param object $object
37
+	 * @param mixed  $info
38
+	 * @return bool
39
+	 */
40
+	public function add($object, $info = null)
41
+	{
42
+		$class = $this->interface;
43
+		if (! $object instanceof $class) {
44
+			return false;
45
+		}
46
+		$this->attach($object);
47
+		$this->set_info($object, $info);
48
+		return $this->contains($object);
49
+	}
50
+
51
+
52
+	/**
53
+	 * set_info
54
+	 *
55
+	 * Sets the data associated with an object in the Collection
56
+	 * if no $info is supplied, then the spl_object_hash() is used
57
+	 *
58
+	 * @access public
59
+	 * @param object $object
60
+	 * @param mixed  $info
61
+	 * @return bool
62
+	 */
63
+	public function set_info($object, $info = null)
64
+	{
65
+		$info = ! empty($info) ? $info : spl_object_hash($object);
66
+		$this->rewind();
67
+		while ($this->valid()) {
68
+			if ($object == $this->current()) {
69
+				$this->setInfo($info);
70
+				$this->rewind();
71
+				return true;
72
+			}
73
+			$this->next();
74
+		}
75
+		return false;
76
+	}
77
+
78
+
79
+	/**
80
+	 * get_by_info
81
+	 *
82
+	 * finds and returns an object in the Collection based on the info that was set using addObject()
83
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
84
+	 *
85
+	 * @access public
86
+	 * @param mixed
87
+	 * @return null | object
88
+	 */
89
+	public function get_by_info($info)
90
+	{
91
+		$this->rewind();
92
+		while ($this->valid()) {
93
+			if ($info === $this->getInfo()) {
94
+				$object = $this->current();
95
+				$this->rewind();
96
+				return $object;
97
+			}
98
+			$this->next();
99
+		}
100
+		return null;
101
+	}
102
+
103
+
104
+	/**
105
+	 * has
106
+	 *
107
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
108
+	 *
109
+	 * @access public
110
+	 * @param object $object
111
+	 * @return bool
112
+	 */
113
+	public function has($object)
114
+	{
115
+		return $this->contains($object);
116
+	}
117
+
118
+
119
+	/**
120
+	 * remove
121
+	 *
122
+	 * detaches an object from the Collection
123
+	 *
124
+	 * @access public
125
+	 * @param $object
126
+	 * @return bool
127
+	 */
128
+	public function remove($object)
129
+	{
130
+		$this->detach($object);
131
+		return true;
132
+	}
133
+
134
+
135
+	/**
136
+	 * set_current
137
+	 *
138
+	 * advances pointer to the provided object
139
+	 *
140
+	 * @access public
141
+	 * @param $object
142
+	 * @return void
143
+	 */
144
+	public function set_current($object)
145
+	{
146
+		$this->rewind();
147
+		while ($this->valid()) {
148
+			if ($this->current() === $object) {
149
+				break;
150
+			}
151
+			$this->next();
152
+		}
153
+	}
154
+
155
+
156
+	/**
157
+	 * set_current_by_info
158
+	 *
159
+	 * advances pointer to the object whose info matches that which was provided
160
+	 *
161
+	 * @access public
162
+	 * @param $info
163
+	 * @return void
164
+	 */
165
+	public function set_current_by_info($info)
166
+	{
167
+		$this->rewind();
168
+		while ($this->valid()) {
169
+			if ($info === $this->getInfo()) {
170
+				break;
171
+			}
172
+			$this->next();
173
+		}
174
+	}
175 175
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
     public function add($object, $info = null)
41 41
     {
42 42
         $class = $this->interface;
43
-        if (! $object instanceof $class) {
43
+        if ( ! $object instanceof $class) {
44 44
             return false;
45 45
         }
46 46
         $this->attach($object);
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Script_Base.core.php 2 patches
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.
Indentation   +882 added lines, -882 removed lines patch added patch discarded remove patch
@@ -15,886 +15,886 @@
 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
-     * @var EE_Data_Migration_Script_Base
78
-     */
79
-    protected $previous_dms;
80
-
81
-
82
-    /**
83
-     * Returns whether or not this data migration script can operate on the given version of the database.
84
-     * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
85
-     * it's passed a string like '3.1.38B', it should return true.
86
-     * If this DMS is to migrate data from an EE3 addon, you will probably want to use
87
-     * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and
88
-     * EE_Data_Migration_Manager::get_migration_ran() to check that core was already
89
-     * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated
90
-     * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want
91
-     * to run this DMS).
92
-     * If this DMS migrates data from a previous version of this EE4 addon, just
93
-     * comparing $current_database_state_of[ $this->slug() ] will probably suffice.
94
-     * If this DMS should never migrate data, because it's only used to define the initial
95
-     * database state, just return FALSE (and core's activation process will take care
96
-     * of calling its schema_changes_before_migration() and
97
-     * schema_changes_after_migration() for you. )
98
-     *
99
-     * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc)
100
-     * @return boolean
101
-     */
102
-    abstract public function can_migrate_from_version($current_database_state_of);
103
-
104
-
105
-    /**
106
-     * Performs database schema changes that need to occur BEFORE the data is migrated.
107
-     * Eg, if we were going to change user passwords from plaintext to encoded versions
108
-     * during this migration, this would probably add a new column called something like
109
-     * "encoded_password".
110
-     *
111
-     * @return boolean of success
112
-     */
113
-    abstract public function schema_changes_before_migration();
114
-
115
-
116
-    /**
117
-     * Performs the database schema changes that need to occur AFTER the data has been migrated.
118
-     * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords
119
-     * from plaintext to encoded versions, and we had added a column called "encoded_password",
120
-     * this function would probably remove the old column "password" (which still holds the plaintext password)
121
-     * and possibly rename "encoded_password" to "password"
122
-     *
123
-     * @return boolean of success
124
-     */
125
-    abstract public function schema_changes_after_migration();
126
-
127
-
128
-    /**
129
-     * All children of this must call parent::__construct()
130
-     * at the end of their constructor or suffer the consequences!
131
-     *
132
-     * @param TableManager  $table_manager
133
-     * @param TableAnalysis $table_analysis
134
-     */
135
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
136
-    {
137
-        $this->_migration_stages = (array) apply_filters(
138
-            'FHEE__' . get_class($this) . '__construct__migration_stages',
139
-            $this->_migration_stages
140
-        );
141
-        foreach ($this->_migration_stages as $migration_stage) {
142
-            if ($migration_stage instanceof EE_Data_Migration_Script_Stage) {
143
-                $migration_stage->_construct_finalize($this);
144
-            }
145
-        }
146
-        parent::__construct($table_manager, $table_analysis);
147
-    }
148
-
149
-
150
-    /**
151
-     * Place to add hooks and filters for tweaking the migrations page, in order
152
-     * to customize it
153
-     */
154
-    public function migration_page_hooks()
155
-    {
156
-        // by default none are added because we normally like the default look of the migration page
157
-    }
158
-
159
-
160
-    /**
161
-     * Sets the mapping from old table primary keys to new table primary keys.
162
-     * This mapping is automatically persisted as a property on the migration
163
-     *
164
-     * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
165
-     * @param int|string $old_pk    old primary key. Eg events_detail.id's value
166
-     * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
167
-     * @param int|string $new_pk    eg posts.ID
168
-     * @return void
169
-     */
170
-    public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
171
-    {
172
-        // make sure it has the needed keys
173
-        if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
174
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
175
-        }
176
-        $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
177
-    }
178
-
179
-
180
-    /**
181
-     * Gets the new primary key, if provided with the OLD table and the primary key
182
-     * of an item in the old table, and the new table
183
-     *
184
-     * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
185
-     * @param int|string $old_pk    old primary key. Eg events_detail.id's value
186
-     * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
187
-     * @return mixed the primary key on the new table
188
-     */
189
-    public function get_mapping_new_pk($old_table, $old_pk, $new_table)
190
-    {
191
-        if (! isset($this->_mappings[ $old_table ]) ||
192
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
193
-            // try fetching the option
194
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
195
-        }
196
-        return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
197
-            ? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
198
-    }
199
-
200
-
201
-    /**
202
-     * Gets the old primary key, if provided with the OLD table,
203
-     * and the new table and the primary key of an item in the new table
204
-     *
205
-     * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail
206
-     * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts
207
-     * @param mixed  $new_pk
208
-     * @return mixed
209
-     */
210
-    public function get_mapping_old_pk($old_table, $new_table, $new_pk)
211
-    {
212
-        if (! isset($this->_mappings[ $old_table ]) ||
213
-            ! isset($this->_mappings[ $old_table ][ $new_table ])) {
214
-            // try fetching the option
215
-            $this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
216
-        }
217
-        if (isset($this->_mappings[ $old_table ][ $new_table ])) {
218
-            $new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
219
-            if (isset($new_pk_to_old_pk[ $new_pk ])) {
220
-                return $new_pk_to_old_pk[ $new_pk ];
221
-            }
222
-        }
223
-        return null;
224
-    }
225
-
226
-
227
-    /**
228
-     * Gets the mapping array option specified by the table names
229
-     *
230
-     * @param string $old_table_name
231
-     * @param string $new_table_name
232
-     * @return array
233
-     */
234
-    protected function _get_mapping_option($old_table_name, $new_table_name)
235
-    {
236
-        $option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array());
237
-        return $option;
238
-    }
239
-
240
-
241
-    /**
242
-     * Updates the mapping option specified by the table names with the array provided
243
-     *
244
-     * @param string $old_table_name
245
-     * @param string $new_table_name
246
-     * @param array  $mapping_array
247
-     * @return boolean success of updating option
248
-     */
249
-    protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array)
250
-    {
251
-        $success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array, false);
252
-        return $success;
253
-    }
254
-
255
-
256
-    /**
257
-     * Gets the option name for this script to map from $old_table_name to $new_table_name
258
-     *
259
-     * @param string $old_table_name
260
-     * @param string $new_table_name
261
-     * @return string
262
-     */
263
-    protected function _get_mapping_option_name($old_table_name, $new_table_name)
264
-    {
265
-        global $wpdb;
266
-        $old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name);
267
-        $new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
268
-        $migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
269
-        return substr(
270
-            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,
271
-            0,
272
-            64
273
-        );
274
-    }
275
-
276
-
277
-    /**
278
-     * Counts all the records that will be migrated during this data migration.
279
-     * For example, if we were changing old user passwords from plaintext to encoded versions,
280
-     * this would be a count of all users who have passwords. If we were going to also split
281
-     * attendee records into transactions, registrations, and attendee records, this would include
282
-     * the count of all attendees currently in existence in the DB (ie, users + attendees).
283
-     * If you can't determine how many records there are to migrate, just provide a guess: this
284
-     * number will only be used in calculating the percent complete. If you estimate there to be
285
-     * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at
286
-     * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete.
287
-     *
288
-     * @return int
289
-     */
290
-    protected function _count_records_to_migrate()
291
-    {
292
-        $count = 0;
293
-        foreach ($this->stages() as $stage) {
294
-            $count += $stage->count_records_to_migrate();
295
-        }
296
-        return $count;
297
-    }
298
-
299
-
300
-    /**
301
-     * Returns the number of records updated so far. Usually this is easiest to do
302
-     * by just setting a transient and updating it after each migration_step
303
-     *
304
-     * @return int
305
-     */
306
-    public function count_records_migrated()
307
-    {
308
-        $count = 0;
309
-        foreach ($this->stages() as $stage) {
310
-            $count += $stage->count_records_migrated();
311
-        }
312
-        $this->_records_migrated = $count;
313
-        return $count;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param int $num_records_to_migrate_limit
319
-     * @return int
320
-     * @throws EE_Error
321
-     * @throws Exception
322
-     */
323
-    public function migration_step($num_records_to_migrate_limit)
324
-    {
325
-        // reset the feedback message
326
-        $this->_feedback_message = '';
327
-        // if we haven't yet done the 1st schema changes, do them now. buffer any output
328
-        $this->_maybe_do_schema_changes(true);
329
-
330
-        $num_records_actually_migrated = 0;
331
-        $records_migrated_per_stage = array();
332
-        // setup the 'stage' variable, which should hold the last run stage of the migration  (or none at all if nothing runs)
333
-        $stage = null;
334
-        // get the next stage that isn't complete
335
-        foreach ($this->stages() as $stage) {
336
-            if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) {
337
-                try {
338
-                    $records_migrated_during_stage = $stage->migration_step(
339
-                        $num_records_to_migrate_limit - $num_records_actually_migrated
340
-                    );
341
-                    $num_records_actually_migrated += $records_migrated_during_stage;
342
-                    $records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
343
-                } catch (Exception $e) {
344
-                    // yes if we catch an exception here, we consider that migration stage borked.
345
-                    $stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
346
-                    $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
347
-                    $stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
348
-                    throw $e;
349
-                }
350
-                // check that the migration stage didn't mark itself as having a fatal error
351
-                if ($stage->is_broken()) {
352
-                    $this->set_broken();
353
-                    throw new EE_Error($stage->get_last_error());
354
-                }
355
-            }
356
-            // once we've migrated all the number we intended to (possibly from different stages), stop migrating
357
-            // or if we had a fatal error
358
-            // or if the current script stopped early- its not done, but it's done all it thinks we should do on this step
359
-            if ($num_records_actually_migrated >= $num_records_to_migrate_limit
360
-                || $stage->is_broken()
361
-                || $stage->has_more_to_do()
362
-            ) {
363
-                break;
364
-            }
365
-        }
366
-        // check if we're all done this data migration...
367
-        // which is indicated by being done early AND the last stage claims to be done
368
-        if ($stage == null) {
369
-            // this migration script apparently has NO stages... which is super weird, but whatever
370
-            $this->set_completed();
371
-            $this->_maybe_do_schema_changes(false);
372
-        } elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) {
373
-            // apparently we're done, because we couldn't migrate the number we intended to
374
-            $this->set_completed();
375
-            $this->_update_feedback_message(array_reverse($records_migrated_per_stage));
376
-            // do schema changes for after the migration now
377
-            // first double-check we haven't already done this
378
-            $this->_maybe_do_schema_changes(false);
379
-        } else {
380
-            // update feedback message, keeping in mind that we show them with the most recent at the top
381
-            $this->_update_feedback_message(array_reverse($records_migrated_per_stage));
382
-        }
383
-        return $num_records_actually_migrated;
384
-    }
385
-
386
-
387
-    /**
388
-     * Updates the feedback message according to what was done during this migration stage.
389
-     *
390
-     * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records
391
-     *                                          migrated from that stage
392
-     * @return void
393
-     */
394
-    private function _update_feedback_message($records_migrated_per_stage)
395
-    {
396
-        $feedback_message_array = array();
397
-        foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) {
398
-            $feedback_message_array[] = sprintf(
399
-                __("Migrated %d records successfully during %s", "event_espresso"),
400
-                $num_records_migrated,
401
-                $migration_stage_name
402
-            );
403
-        }
404
-        $this->_feedback_message .= implode("<br>", $feedback_message_array);
405
-    }
406
-
407
-
408
-    /**
409
-     * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration
410
-     * (if $before==false). Buffers their outputs and stores them on the class.
411
-     *
412
-     * @param boolean $before
413
-     * @throws Exception
414
-     * @return void
415
-     */
416
-    private function _maybe_do_schema_changes($before = true)
417
-    {
418
-        // so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
419
-        $property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
420
-        if (! $this->{$property_name}) {
421
-            try {
422
-                ob_start();
423
-                if ($before) {
424
-                    $this->schema_changes_before_migration();
425
-                } else {
426
-                    $this->schema_changes_after_migration();
427
-                }
428
-                $output = ob_get_contents();
429
-                ob_end_clean();
430
-            } catch (Exception $e) {
431
-                $this->set_status(EE_Data_Migration_Manager::status_fatal_error);
432
-                throw $e;
433
-            }
434
-            // record that we've done these schema changes
435
-            $this->{$property_name} = true;
436
-            // if there were any warnings etc, record them as non-fatal errors
437
-            if ($output) {
438
-                // there were some warnings
439
-                $this->_errors[] = $output;
440
-            }
441
-        }
442
-    }
443
-
444
-
445
-    /**
446
-     * Wrapper for EEH_Activation::create_table. However, takes into account the request type when
447
-     * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead
448
-     * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to
449
-     * or
450
-     * activated currently. If this is a brand new activation or a migration, and we're indicating this table should
451
-     * not
452
-     * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this
453
-     * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table
454
-     * should be nuked.
455
-     *
456
-     * Just for a bit of context, the migration script's db_schema_changes_* methods
457
-     * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the
458
-     * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was
459
-     * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should
460
-     * be dropped), and during a migration when we're moving the DB to the state of the migration script
461
-     *
462
-     * @param string $table_name
463
-     * @param string $table_definition_sql
464
-     * @param string $engine_string
465
-     */
466
-    protected function _table_is_new_in_this_version(
467
-        $table_name,
468
-        $table_definition_sql,
469
-        $engine_string = 'ENGINE=InnoDB '
470
-    ) {
471
-        $this->_create_table_and_catch_errors(
472
-            $table_name,
473
-            $table_definition_sql,
474
-            $engine_string,
475
-            $this->_pre_existing_table_should_be_dropped(true)
476
-        );
477
-    }
478
-
479
-    /**
480
-     * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table
481
-     * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not
482
-     * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is
483
-     * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as
484
-     * _table_should_exist_previously.
485
-     * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the
486
-     * table shouldn't exist).
487
-     *
488
-     * @param string $table_name
489
-     * @param string $table_definition_sql
490
-     * @param string $engine_string
491
-     */
492
-    protected function _table_is_changed_in_this_version(
493
-        $table_name,
494
-        $table_definition_sql,
495
-        $engine_string = 'ENGINE=MyISAM'
496
-    ) {
497
-        $this->_create_table_and_catch_errors(
498
-            $table_name,
499
-            $table_definition_sql,
500
-            $engine_string,
501
-            $this->_pre_existing_table_should_be_dropped(false)
502
-        );
503
-    }
504
-
505
-
506
-    /**
507
-     * _old_table_exists
508
-     * returns TRUE if the requested table exists in the current database
509
-     *
510
-     * @param string $table_name
511
-     * @return boolean
512
-     */
513
-    protected function _old_table_exists($table_name)
514
-    {
515
-        return $this->_get_table_analysis()->tableExists($table_name);
516
-    }
517
-
518
-
519
-    /**
520
-     * _delete_table_if_empty
521
-     * returns TRUE if the requested table was empty and successfully empty
522
-     *
523
-     * @param string $table_name
524
-     * @return boolean
525
-     */
526
-    protected function _delete_table_if_empty($table_name)
527
-    {
528
-        return EEH_Activation::delete_db_table_if_empty($table_name);
529
-    }
530
-
531
-
532
-    /**
533
-     * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version
534
-     * as these are significantly more efficient or explicit.
535
-     * Please see description of _table_is_new_in_this_version. This function will only set
536
-     * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand
537
-     * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin"
538
-     * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually
539
-     * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table
540
-     * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then
541
-     * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations
542
-     * because apparently it hasn't changed since the previous one, right?
543
-     *
544
-     * @param string $table_name
545
-     * @param string $table_definition_sql
546
-     * @param string $engine_string
547
-     */
548
-    protected function _table_should_exist_previously(
549
-        $table_name,
550
-        $table_definition_sql,
551
-        $engine_string = 'ENGINE=MyISAM'
552
-    ) {
553
-        $this->_create_table_and_catch_errors(
554
-            $table_name,
555
-            $table_definition_sql,
556
-            $engine_string,
557
-            $this->_pre_existing_table_should_be_dropped(false)
558
-        );
559
-    }
560
-
561
-    /**
562
-     * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing
563
-     * a migration, we skip checking this table's structure in the database and just assume it's correct.
564
-     * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs,
565
-     * but important for multisite where migrations can take a very long time otherwise).
566
-     * If the table is known to have changed since previous version, use _table_is_changed_in_this_version().
567
-     * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table
568
-     * shouldn't exist).
569
-     *
570
-     * @param string $table_name
571
-     * @param string $table_definition_sql
572
-     * @param string $engine_string
573
-     */
574
-    protected function _table_has_not_changed_since_previous(
575
-        $table_name,
576
-        $table_definition_sql,
577
-        $engine_string = 'ENGINE=MyISAM'
578
-    ) {
579
-        if ($this->_currently_migrating()) {
580
-            // if we're doing a migration, and this table apparently already exists, then we don't need do anything right?
581
-            return;
582
-        }
583
-        $this->_create_table_and_catch_errors(
584
-            $table_name,
585
-            $table_definition_sql,
586
-            $engine_string,
587
-            $this->_pre_existing_table_should_be_dropped(false)
588
-        );
589
-    }
590
-
591
-    /**
592
-     * Returns whether or not this migration script is being used as part of an actual migration
593
-     *
594
-     * @return boolean
595
-     */
596
-    protected function _currently_migrating()
597
-    {
598
-        // 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)
599
-        return $this->_migrating &&
600
-               $this->can_migrate_from_version(
601
-                   EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set()
602
-               ) &&
603
-               EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance;
604
-    }
605
-
606
-    /**
607
-     * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new,
608
-     * and the plugin's request type.
609
-     * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table
610
-     * shouldn't exist no matter what).
611
-     *
612
-     * @param boolean $table_is_new
613
-     * @return boolean
614
-     */
615
-    protected function _pre_existing_table_should_be_dropped($table_is_new)
616
-    {
617
-        if ($table_is_new) {
618
-            if ($this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation
619
-                || $this->_currently_migrating()
620
-            ) {
621
-                return true;
622
-            } else {
623
-                return false;
624
-            }
625
-        } else {
626
-            if (in_array(
627
-                $this->_get_req_type_for_plugin_corresponding_to_this_dms(),
628
-                array(EE_System::req_type_new_activation)
629
-            )) {
630
-                return true;
631
-            } else {
632
-                return false;
633
-            }
634
-        }
635
-    }
636
-
637
-    /**
638
-     * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS
639
-     *
640
-     * @param string  $table_name
641
-     * @param string  $table_definition_sql
642
-     * @param string  $engine_string
643
-     * @param boolean $drop_pre_existing_tables
644
-     */
645
-    private function _create_table_and_catch_errors(
646
-        $table_name,
647
-        $table_definition_sql,
648
-        $engine_string = 'ENGINE=MyISAM',
649
-        $drop_pre_existing_tables = false
650
-    ) {
651
-        try {
652
-            EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
653
-        } catch (EE_Error $e) {
654
-            $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
655
-            $this->add_error($message);
656
-            $this->_feedback_message .= $message;
657
-        }
658
-    }
659
-
660
-
661
-    /**
662
-     * Gets the request type for the plugin (core or addon) that corresponds to this DMS
663
-     *
664
-     * @return int one of EE_System::_req_type_* constants
665
-     * @throws EE_Error
666
-     */
667
-    private function _get_req_type_for_plugin_corresponding_to_this_dms()
668
-    {
669
-        if ($this->slug() == 'Core') {
670
-            return EE_System::instance()->detect_req_type();
671
-        } else {// it must be for an addon
672
-            $addon_name = $this->slug();
673
-            if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
674
-                return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
675
-            } else {
676
-                throw new EE_Error(
677
-                    sprintf(
678
-                        __(
679
-                            "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",
680
-                            "event_espresso"
681
-                        ),
682
-                        $this->slug(),
683
-                        $addon_name,
684
-                        implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))
685
-                    )
686
-                );
687
-            }
688
-        }
689
-    }
690
-
691
-
692
-    /**
693
-     * returns an array of strings describing errors by all the script's stages
694
-     *
695
-     * @return array
696
-     */
697
-    public function get_errors()
698
-    {
699
-        $all_errors = $this->_errors;
700
-        if (! is_array($all_errors)) {
701
-            $all_errors = array();
702
-        }
703
-        foreach ($this->stages() as $stage) {
704
-            $all_errors = array_merge($stage->get_errors(), $all_errors);
705
-        }
706
-        return $all_errors;
707
-    }
708
-
709
-
710
-    /**
711
-     * Indicates whether or not this migration script should continue
712
-     *
713
-     * @return boolean
714
-     */
715
-    public function can_continue()
716
-    {
717
-        return in_array(
718
-            $this->get_status(),
719
-            EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script
720
-        );
721
-    }
722
-
723
-
724
-    /**
725
-     * Gets all the data migration stages associated with this script. Note:
726
-     * addons can filter this list to add their own stages, and because the list is
727
-     * numerically-indexed, they can insert their stage wherever they like and it will
728
-     * get ordered by the indexes
729
-     *
730
-     * @return EE_Data_Migration_Script_Stage[]
731
-     */
732
-    protected function stages()
733
-    {
734
-        $stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
735
-        ksort($stages);
736
-        return $stages;
737
-    }
738
-
739
-
740
-    /**
741
-     * Gets a string which should describe what's going on currently with this migration, which
742
-     * can be displayed to the user
743
-     *
744
-     * @return string
745
-     */
746
-    public function get_feedback_message()
747
-    {
748
-        return $this->_feedback_message;
749
-    }
750
-
751
-
752
-    /**
753
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
754
-     * properties to the DB. However, we don't want to use __sleep() because its quite
755
-     * possible that this class is defined when it goes to sleep, but NOT available when it
756
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
757
-     */
758
-    public function properties_as_array()
759
-    {
760
-        $properties = parent::properties_as_array();
761
-        $properties['_migration_stages'] = array();
762
-        foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
763
-            $properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
764
-            );
765
-        }
766
-        unset($properties['_mappings']);
767
-        unset($properties['previous_dms']);
768
-
769
-        foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) {
770
-            foreach ($mapping_to_new_table as $new_table_name => $mapping) {
771
-                $this->_set_mapping_option($old_table_name, $new_table_name, $mapping);
772
-            }
773
-        }
774
-        return $properties;
775
-    }
776
-
777
-
778
-    /**
779
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
780
-     * to have been made from the properties_as_array() function.
781
-     *
782
-     * @param array $array_of_properties like what's produced from properties_as_array() method
783
-     * @return void
784
-     */
785
-    public function instantiate_from_array_of_properties($array_of_properties)
786
-    {
787
-        $stages_properties_arrays = $array_of_properties['_migration_stages'];
788
-        unset($array_of_properties['_migration_stages']);
789
-        unset($array_of_properties['class']);
790
-        foreach ($array_of_properties as $property_name => $property_value) {
791
-            $this->{$property_name} = $property_value;
792
-        }
793
-        // _migration_stages are already instantiated, but have only default data
794
-        foreach ($this->_migration_stages as $stage) {
795
-            $stage_data = $this->_find_migration_stage_data_with_classname(
796
-                get_class($stage),
797
-                $stages_properties_arrays
798
-            );
799
-            // SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by
800
-            // an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet)
801
-            if ($stage_data) {
802
-                $stage->instantiate_from_array_of_properties($stage_data);
803
-            }
804
-        }
805
-    }
806
-
807
-
808
-    /**
809
-     * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which
810
-     * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes)
811
-     * for the given classname
812
-     *
813
-     * @param string $classname
814
-     * @param array  $migration_stage_data_arrays
815
-     * @return null
816
-     */
817
-    private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays)
818
-    {
819
-        foreach ($migration_stage_data_arrays as $migration_stage_data_array) {
820
-            if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) {
821
-                return $migration_stage_data_array;
822
-            }
823
-        }
824
-        return null;
825
-    }
826
-
827
-
828
-    /**
829
-     * Returns the version that this script migrates to, based on the script's name.
830
-     * Cannot be overwritten because lots of code needs to know which version a script
831
-     * migrates to knowing only its name.
832
-     *
833
-     * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin
834
-     * that will be updated to. Eg array('Core','4.1.0')
835
-     */
836
-    final public function migrates_to_version()
837
-    {
838
-        return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
839
-    }
840
-
841
-
842
-    /**
843
-     * Gets this addon's slug as it would appear in the current_db_state wp option,
844
-     * and if this migration script is for an addon, it SHOULD match the addon's slug
845
-     * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon.
846
-     * Or 'Core' for core (non-addon).
847
-     *
848
-     * @return string
849
-     */
850
-    public function slug()
851
-    {
852
-        $migrates_to_version_info = $this->migrates_to_version();
853
-        // the slug is the first part of the array
854
-        return $migrates_to_version_info['slug'];
855
-    }
856
-
857
-
858
-    /**
859
-     * Returns the script's priority relative to DMSs from other addons. However, when
860
-     * two DMSs from the same addon/core apply, this is ignored (and instead the version that
861
-     * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs
862
-     * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons,
863
-     * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set
864
-     * the database up so it can run), then you can set "A" to priority 3 or something.
865
-     *
866
-     * @return int
867
-     */
868
-    public function priority()
869
-    {
870
-        return $this->_priority;
871
-    }
872
-
873
-
874
-    /**
875
-     * Sets whether or not this DMS is being ran as part of a migration, instead of
876
-     * just being used to setup (or verify) the current database structure matches
877
-     * what the latest DMS indicates it should be
878
-     *
879
-     * @param boolean $migrating
880
-     * @return void
881
-     */
882
-    public function set_migrating($migrating = true)
883
-    {
884
-        $this->_migrating = $migrating;
885
-    }
886
-
887
-    /**
888
-     * Marks that we think this migration class can continue to migrate
889
-     */
890
-    public function reattempt()
891
-    {
892
-        parent::reattempt();
893
-        // also, we want to reattempt any stages that were marked as borked
894
-        foreach ($this->stages() as $stage) {
895
-            if ($stage->is_broken()) {
896
-                $stage->reattempt();
897
-            }
898
-        }
899
-    }
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
+	 * @var EE_Data_Migration_Script_Base
78
+	 */
79
+	protected $previous_dms;
80
+
81
+
82
+	/**
83
+	 * Returns whether or not this data migration script can operate on the given version of the database.
84
+	 * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and
85
+	 * it's passed a string like '3.1.38B', it should return true.
86
+	 * If this DMS is to migrate data from an EE3 addon, you will probably want to use
87
+	 * EventEspresso\core\services\database\TableAnalysis::tableExists() to check for old EE3 tables, and
88
+	 * EE_Data_Migration_Manager::get_migration_ran() to check that core was already
89
+	 * migrated from EE3 to EE4 (ie, this DMS probably relies on some migration data generated
90
+	 * during the Core 4.1.0 DMS. If core didn't run that DMS, you probably don't want
91
+	 * to run this DMS).
92
+	 * If this DMS migrates data from a previous version of this EE4 addon, just
93
+	 * comparing $current_database_state_of[ $this->slug() ] will probably suffice.
94
+	 * If this DMS should never migrate data, because it's only used to define the initial
95
+	 * database state, just return FALSE (and core's activation process will take care
96
+	 * of calling its schema_changes_before_migration() and
97
+	 * schema_changes_after_migration() for you. )
98
+	 *
99
+	 * @param array $current_database_state_of keys are EE plugin slugs (eg 'Core', 'Calendar', 'Mailchimp', etc)
100
+	 * @return boolean
101
+	 */
102
+	abstract public function can_migrate_from_version($current_database_state_of);
103
+
104
+
105
+	/**
106
+	 * Performs database schema changes that need to occur BEFORE the data is migrated.
107
+	 * Eg, if we were going to change user passwords from plaintext to encoded versions
108
+	 * during this migration, this would probably add a new column called something like
109
+	 * "encoded_password".
110
+	 *
111
+	 * @return boolean of success
112
+	 */
113
+	abstract public function schema_changes_before_migration();
114
+
115
+
116
+	/**
117
+	 * Performs the database schema changes that need to occur AFTER the data has been migrated.
118
+	 * Usually this will mean we'll be removing old columns. Eg, if we were changing passwords
119
+	 * from plaintext to encoded versions, and we had added a column called "encoded_password",
120
+	 * this function would probably remove the old column "password" (which still holds the plaintext password)
121
+	 * and possibly rename "encoded_password" to "password"
122
+	 *
123
+	 * @return boolean of success
124
+	 */
125
+	abstract public function schema_changes_after_migration();
126
+
127
+
128
+	/**
129
+	 * All children of this must call parent::__construct()
130
+	 * at the end of their constructor or suffer the consequences!
131
+	 *
132
+	 * @param TableManager  $table_manager
133
+	 * @param TableAnalysis $table_analysis
134
+	 */
135
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
136
+	{
137
+		$this->_migration_stages = (array) apply_filters(
138
+			'FHEE__' . get_class($this) . '__construct__migration_stages',
139
+			$this->_migration_stages
140
+		);
141
+		foreach ($this->_migration_stages as $migration_stage) {
142
+			if ($migration_stage instanceof EE_Data_Migration_Script_Stage) {
143
+				$migration_stage->_construct_finalize($this);
144
+			}
145
+		}
146
+		parent::__construct($table_manager, $table_analysis);
147
+	}
148
+
149
+
150
+	/**
151
+	 * Place to add hooks and filters for tweaking the migrations page, in order
152
+	 * to customize it
153
+	 */
154
+	public function migration_page_hooks()
155
+	{
156
+		// by default none are added because we normally like the default look of the migration page
157
+	}
158
+
159
+
160
+	/**
161
+	 * Sets the mapping from old table primary keys to new table primary keys.
162
+	 * This mapping is automatically persisted as a property on the migration
163
+	 *
164
+	 * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
165
+	 * @param int|string $old_pk    old primary key. Eg events_detail.id's value
166
+	 * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
167
+	 * @param int|string $new_pk    eg posts.ID
168
+	 * @return void
169
+	 */
170
+	public function set_mapping($old_table, $old_pk, $new_table, $new_pk)
171
+	{
172
+		// make sure it has the needed keys
173
+		if (! isset($this->_mappings[ $old_table ]) || ! isset($this->_mappings[ $old_table ][ $new_table ])) {
174
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
175
+		}
176
+		$this->_mappings[ $old_table ][ $new_table ][ $old_pk ] = $new_pk;
177
+	}
178
+
179
+
180
+	/**
181
+	 * Gets the new primary key, if provided with the OLD table and the primary key
182
+	 * of an item in the old table, and the new table
183
+	 *
184
+	 * @param string     $old_table with wpdb prefix (wp_). Eg: wp_events_detail
185
+	 * @param int|string $old_pk    old primary key. Eg events_detail.id's value
186
+	 * @param string     $new_table with wpdb prefix (wp_). Eg: wp_posts
187
+	 * @return mixed the primary key on the new table
188
+	 */
189
+	public function get_mapping_new_pk($old_table, $old_pk, $new_table)
190
+	{
191
+		if (! isset($this->_mappings[ $old_table ]) ||
192
+			! isset($this->_mappings[ $old_table ][ $new_table ])) {
193
+			// try fetching the option
194
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
195
+		}
196
+		return isset($this->_mappings[ $old_table ][ $new_table ][ $old_pk ])
197
+			? $this->_mappings[ $old_table ][ $new_table ][ $old_pk ] : null;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Gets the old primary key, if provided with the OLD table,
203
+	 * and the new table and the primary key of an item in the new table
204
+	 *
205
+	 * @param string $old_table with wpdb prefix (wp_). Eg: wp_events_detail
206
+	 * @param string $new_table with wpdb prefix (wp_). Eg: wp_posts
207
+	 * @param mixed  $new_pk
208
+	 * @return mixed
209
+	 */
210
+	public function get_mapping_old_pk($old_table, $new_table, $new_pk)
211
+	{
212
+		if (! isset($this->_mappings[ $old_table ]) ||
213
+			! isset($this->_mappings[ $old_table ][ $new_table ])) {
214
+			// try fetching the option
215
+			$this->_mappings[ $old_table ][ $new_table ] = $this->_get_mapping_option($old_table, $new_table);
216
+		}
217
+		if (isset($this->_mappings[ $old_table ][ $new_table ])) {
218
+			$new_pk_to_old_pk = array_flip($this->_mappings[ $old_table ][ $new_table ]);
219
+			if (isset($new_pk_to_old_pk[ $new_pk ])) {
220
+				return $new_pk_to_old_pk[ $new_pk ];
221
+			}
222
+		}
223
+		return null;
224
+	}
225
+
226
+
227
+	/**
228
+	 * Gets the mapping array option specified by the table names
229
+	 *
230
+	 * @param string $old_table_name
231
+	 * @param string $new_table_name
232
+	 * @return array
233
+	 */
234
+	protected function _get_mapping_option($old_table_name, $new_table_name)
235
+	{
236
+		$option = get_option($this->_get_mapping_option_name($old_table_name, $new_table_name), array());
237
+		return $option;
238
+	}
239
+
240
+
241
+	/**
242
+	 * Updates the mapping option specified by the table names with the array provided
243
+	 *
244
+	 * @param string $old_table_name
245
+	 * @param string $new_table_name
246
+	 * @param array  $mapping_array
247
+	 * @return boolean success of updating option
248
+	 */
249
+	protected function _set_mapping_option($old_table_name, $new_table_name, $mapping_array)
250
+	{
251
+		$success = update_option($this->_get_mapping_option_name($old_table_name, $new_table_name), $mapping_array, false);
252
+		return $success;
253
+	}
254
+
255
+
256
+	/**
257
+	 * Gets the option name for this script to map from $old_table_name to $new_table_name
258
+	 *
259
+	 * @param string $old_table_name
260
+	 * @param string $new_table_name
261
+	 * @return string
262
+	 */
263
+	protected function _get_mapping_option_name($old_table_name, $new_table_name)
264
+	{
265
+		global $wpdb;
266
+		$old_table_name_sans_wp = str_replace($wpdb->prefix, "", $old_table_name);
267
+		$new_table_name_sans_wp = str_replace($wpdb->prefix, "", $new_table_name);
268
+		$migrates_to = EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
269
+		return substr(
270
+			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,
271
+			0,
272
+			64
273
+		);
274
+	}
275
+
276
+
277
+	/**
278
+	 * Counts all the records that will be migrated during this data migration.
279
+	 * For example, if we were changing old user passwords from plaintext to encoded versions,
280
+	 * this would be a count of all users who have passwords. If we were going to also split
281
+	 * attendee records into transactions, registrations, and attendee records, this would include
282
+	 * the count of all attendees currently in existence in the DB (ie, users + attendees).
283
+	 * If you can't determine how many records there are to migrate, just provide a guess: this
284
+	 * number will only be used in calculating the percent complete. If you estimate there to be
285
+	 * 100 records to migrate, and it turns out there's 120, we'll just show the migration as being at
286
+	 * 99% until the function "migration_step" returns EE_Data_Migration_Script_Base::status_complete.
287
+	 *
288
+	 * @return int
289
+	 */
290
+	protected function _count_records_to_migrate()
291
+	{
292
+		$count = 0;
293
+		foreach ($this->stages() as $stage) {
294
+			$count += $stage->count_records_to_migrate();
295
+		}
296
+		return $count;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Returns the number of records updated so far. Usually this is easiest to do
302
+	 * by just setting a transient and updating it after each migration_step
303
+	 *
304
+	 * @return int
305
+	 */
306
+	public function count_records_migrated()
307
+	{
308
+		$count = 0;
309
+		foreach ($this->stages() as $stage) {
310
+			$count += $stage->count_records_migrated();
311
+		}
312
+		$this->_records_migrated = $count;
313
+		return $count;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param int $num_records_to_migrate_limit
319
+	 * @return int
320
+	 * @throws EE_Error
321
+	 * @throws Exception
322
+	 */
323
+	public function migration_step($num_records_to_migrate_limit)
324
+	{
325
+		// reset the feedback message
326
+		$this->_feedback_message = '';
327
+		// if we haven't yet done the 1st schema changes, do them now. buffer any output
328
+		$this->_maybe_do_schema_changes(true);
329
+
330
+		$num_records_actually_migrated = 0;
331
+		$records_migrated_per_stage = array();
332
+		// setup the 'stage' variable, which should hold the last run stage of the migration  (or none at all if nothing runs)
333
+		$stage = null;
334
+		// get the next stage that isn't complete
335
+		foreach ($this->stages() as $stage) {
336
+			if ($stage->get_status() == EE_Data_Migration_Manager::status_continue) {
337
+				try {
338
+					$records_migrated_during_stage = $stage->migration_step(
339
+						$num_records_to_migrate_limit - $num_records_actually_migrated
340
+					);
341
+					$num_records_actually_migrated += $records_migrated_during_stage;
342
+					$records_migrated_per_stage[ $stage->pretty_name() ] = $records_migrated_during_stage;
343
+				} catch (Exception $e) {
344
+					// yes if we catch an exception here, we consider that migration stage borked.
345
+					$stage->set_status(EE_Data_Migration_Manager::status_fatal_error);
346
+					$this->set_status(EE_Data_Migration_Manager::status_fatal_error);
347
+					$stage->add_error($e->getMessage() . ". Stack-trace:" . $e->getTraceAsString());
348
+					throw $e;
349
+				}
350
+				// check that the migration stage didn't mark itself as having a fatal error
351
+				if ($stage->is_broken()) {
352
+					$this->set_broken();
353
+					throw new EE_Error($stage->get_last_error());
354
+				}
355
+			}
356
+			// once we've migrated all the number we intended to (possibly from different stages), stop migrating
357
+			// or if we had a fatal error
358
+			// or if the current script stopped early- its not done, but it's done all it thinks we should do on this step
359
+			if ($num_records_actually_migrated >= $num_records_to_migrate_limit
360
+				|| $stage->is_broken()
361
+				|| $stage->has_more_to_do()
362
+			) {
363
+				break;
364
+			}
365
+		}
366
+		// check if we're all done this data migration...
367
+		// which is indicated by being done early AND the last stage claims to be done
368
+		if ($stage == null) {
369
+			// this migration script apparently has NO stages... which is super weird, but whatever
370
+			$this->set_completed();
371
+			$this->_maybe_do_schema_changes(false);
372
+		} elseif ($num_records_actually_migrated < $num_records_to_migrate_limit && ! $stage->has_more_to_do()) {
373
+			// apparently we're done, because we couldn't migrate the number we intended to
374
+			$this->set_completed();
375
+			$this->_update_feedback_message(array_reverse($records_migrated_per_stage));
376
+			// do schema changes for after the migration now
377
+			// first double-check we haven't already done this
378
+			$this->_maybe_do_schema_changes(false);
379
+		} else {
380
+			// update feedback message, keeping in mind that we show them with the most recent at the top
381
+			$this->_update_feedback_message(array_reverse($records_migrated_per_stage));
382
+		}
383
+		return $num_records_actually_migrated;
384
+	}
385
+
386
+
387
+	/**
388
+	 * Updates the feedback message according to what was done during this migration stage.
389
+	 *
390
+	 * @param array $records_migrated_per_stage KEYS are pretty names for each stage; values are the count of records
391
+	 *                                          migrated from that stage
392
+	 * @return void
393
+	 */
394
+	private function _update_feedback_message($records_migrated_per_stage)
395
+	{
396
+		$feedback_message_array = array();
397
+		foreach ($records_migrated_per_stage as $migration_stage_name => $num_records_migrated) {
398
+			$feedback_message_array[] = sprintf(
399
+				__("Migrated %d records successfully during %s", "event_espresso"),
400
+				$num_records_migrated,
401
+				$migration_stage_name
402
+			);
403
+		}
404
+		$this->_feedback_message .= implode("<br>", $feedback_message_array);
405
+	}
406
+
407
+
408
+	/**
409
+	 * Calls either schema_changes_before_migration() (if $before==true) or schema_changes_after_migration
410
+	 * (if $before==false). Buffers their outputs and stores them on the class.
411
+	 *
412
+	 * @param boolean $before
413
+	 * @throws Exception
414
+	 * @return void
415
+	 */
416
+	private function _maybe_do_schema_changes($before = true)
417
+	{
418
+		// so this property will be either _schema_changes_after_migration_ran or _schema_changes_before_migration_ran
419
+		$property_name = '_schema_changes_' . ($before ? 'before' : 'after') . '_migration_ran';
420
+		if (! $this->{$property_name}) {
421
+			try {
422
+				ob_start();
423
+				if ($before) {
424
+					$this->schema_changes_before_migration();
425
+				} else {
426
+					$this->schema_changes_after_migration();
427
+				}
428
+				$output = ob_get_contents();
429
+				ob_end_clean();
430
+			} catch (Exception $e) {
431
+				$this->set_status(EE_Data_Migration_Manager::status_fatal_error);
432
+				throw $e;
433
+			}
434
+			// record that we've done these schema changes
435
+			$this->{$property_name} = true;
436
+			// if there were any warnings etc, record them as non-fatal errors
437
+			if ($output) {
438
+				// there were some warnings
439
+				$this->_errors[] = $output;
440
+			}
441
+		}
442
+	}
443
+
444
+
445
+	/**
446
+	 * Wrapper for EEH_Activation::create_table. However, takes into account the request type when
447
+	 * deciding what to pass for its 4th arg, $drop_pre_existing_tables. Using this function, instead
448
+	 * of _table_should_exist_previously, indicates that this table should be new to the EE version being migrated to
449
+	 * or
450
+	 * activated currently. If this is a brand new activation or a migration, and we're indicating this table should
451
+	 * not
452
+	 * previously exist, then we want to set $drop_pre_existing_tables to TRUE (ie, we shouldn't discover that this
453
+	 * table exists in the DB in EEH_Activation::create_table- if it DOES exist, something's wrong and the old table
454
+	 * should be nuked.
455
+	 *
456
+	 * Just for a bit of context, the migration script's db_schema_changes_* methods
457
+	 * are called basically in 3 cases: on brand new activation of EE4 (ie no previous version of EE existed and the
458
+	 * plugin is being activated and we want to add all the brand new tables), upon reactivation of EE4 (it was
459
+	 * deactivated and then reactivated, in which case we want to just verify the DB structure is ok) that table should
460
+	 * be dropped), and during a migration when we're moving the DB to the state of the migration script
461
+	 *
462
+	 * @param string $table_name
463
+	 * @param string $table_definition_sql
464
+	 * @param string $engine_string
465
+	 */
466
+	protected function _table_is_new_in_this_version(
467
+		$table_name,
468
+		$table_definition_sql,
469
+		$engine_string = 'ENGINE=InnoDB '
470
+	) {
471
+		$this->_create_table_and_catch_errors(
472
+			$table_name,
473
+			$table_definition_sql,
474
+			$engine_string,
475
+			$this->_pre_existing_table_should_be_dropped(true)
476
+		);
477
+	}
478
+
479
+	/**
480
+	 * Like _table_is_new_in_this_version and _table_should_exist_previously, this function verifies the given table
481
+	 * exists. But we understand that this table has CHANGED in this version since the previous version. So it's not
482
+	 * completely new, but it's different. So we need to treat it like a new table in terms of verifying it's schema is
483
+	 * correct on activations, migrations, upgrades; but if it exists when it shouldn't, we need to be as lenient as
484
+	 * _table_should_exist_previously.
485
+	 * 8656]{Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the
486
+	 * table shouldn't exist).
487
+	 *
488
+	 * @param string $table_name
489
+	 * @param string $table_definition_sql
490
+	 * @param string $engine_string
491
+	 */
492
+	protected function _table_is_changed_in_this_version(
493
+		$table_name,
494
+		$table_definition_sql,
495
+		$engine_string = 'ENGINE=MyISAM'
496
+	) {
497
+		$this->_create_table_and_catch_errors(
498
+			$table_name,
499
+			$table_definition_sql,
500
+			$engine_string,
501
+			$this->_pre_existing_table_should_be_dropped(false)
502
+		);
503
+	}
504
+
505
+
506
+	/**
507
+	 * _old_table_exists
508
+	 * returns TRUE if the requested table exists in the current database
509
+	 *
510
+	 * @param string $table_name
511
+	 * @return boolean
512
+	 */
513
+	protected function _old_table_exists($table_name)
514
+	{
515
+		return $this->_get_table_analysis()->tableExists($table_name);
516
+	}
517
+
518
+
519
+	/**
520
+	 * _delete_table_if_empty
521
+	 * returns TRUE if the requested table was empty and successfully empty
522
+	 *
523
+	 * @param string $table_name
524
+	 * @return boolean
525
+	 */
526
+	protected function _delete_table_if_empty($table_name)
527
+	{
528
+		return EEH_Activation::delete_db_table_if_empty($table_name);
529
+	}
530
+
531
+
532
+	/**
533
+	 * It is preferred to use _table_has_not_changed_since_previous or _table_is_changed_in_this_version
534
+	 * as these are significantly more efficient or explicit.
535
+	 * Please see description of _table_is_new_in_this_version. This function will only set
536
+	 * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand
537
+	 * new activation. ie, a more accurate name for this method would be "_table_added_previously_by_this_plugin"
538
+	 * because the table will be cleared out if this is a new activation (ie, if its a new activation, it actually
539
+	 * should exist previously). Otherwise, we'll always set $drop_pre_existing_tables to FALSE because the table
540
+	 * should have existed. Note, if the table is being MODIFIED in this version being activated or migrated to, then
541
+	 * you want _table_is_changed_in_this_version NOT this one. We don't check this table's structure during migrations
542
+	 * because apparently it hasn't changed since the previous one, right?
543
+	 *
544
+	 * @param string $table_name
545
+	 * @param string $table_definition_sql
546
+	 * @param string $engine_string
547
+	 */
548
+	protected function _table_should_exist_previously(
549
+		$table_name,
550
+		$table_definition_sql,
551
+		$engine_string = 'ENGINE=MyISAM'
552
+	) {
553
+		$this->_create_table_and_catch_errors(
554
+			$table_name,
555
+			$table_definition_sql,
556
+			$engine_string,
557
+			$this->_pre_existing_table_should_be_dropped(false)
558
+		);
559
+	}
560
+
561
+	/**
562
+	 * Exactly the same as _table_should_exist_previously(), except if this migration script is currently doing
563
+	 * a migration, we skip checking this table's structure in the database and just assume it's correct.
564
+	 * So this is useful only to improve efficiency when doing migrations (not a big deal for single site installs,
565
+	 * but important for multisite where migrations can take a very long time otherwise).
566
+	 * If the table is known to have changed since previous version, use _table_is_changed_in_this_version().
567
+	 * Assumes only this plugin could have added this table (ie, if its a new activation of this plugin, the table
568
+	 * shouldn't exist).
569
+	 *
570
+	 * @param string $table_name
571
+	 * @param string $table_definition_sql
572
+	 * @param string $engine_string
573
+	 */
574
+	protected function _table_has_not_changed_since_previous(
575
+		$table_name,
576
+		$table_definition_sql,
577
+		$engine_string = 'ENGINE=MyISAM'
578
+	) {
579
+		if ($this->_currently_migrating()) {
580
+			// if we're doing a migration, and this table apparently already exists, then we don't need do anything right?
581
+			return;
582
+		}
583
+		$this->_create_table_and_catch_errors(
584
+			$table_name,
585
+			$table_definition_sql,
586
+			$engine_string,
587
+			$this->_pre_existing_table_should_be_dropped(false)
588
+		);
589
+	}
590
+
591
+	/**
592
+	 * Returns whether or not this migration script is being used as part of an actual migration
593
+	 *
594
+	 * @return boolean
595
+	 */
596
+	protected function _currently_migrating()
597
+	{
598
+		// 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)
599
+		return $this->_migrating &&
600
+			   $this->can_migrate_from_version(
601
+				   EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set()
602
+			   ) &&
603
+			   EE_Maintenance_Mode::instance()->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance;
604
+	}
605
+
606
+	/**
607
+	 * Determines if a table should be dropped, based on whether it's reported to be new in $table_is_new,
608
+	 * and the plugin's request type.
609
+	 * Assumes only this plugin could have added the table (ie, if its a new activation of this plugin, the table
610
+	 * shouldn't exist no matter what).
611
+	 *
612
+	 * @param boolean $table_is_new
613
+	 * @return boolean
614
+	 */
615
+	protected function _pre_existing_table_should_be_dropped($table_is_new)
616
+	{
617
+		if ($table_is_new) {
618
+			if ($this->_get_req_type_for_plugin_corresponding_to_this_dms() == EE_System::req_type_new_activation
619
+				|| $this->_currently_migrating()
620
+			) {
621
+				return true;
622
+			} else {
623
+				return false;
624
+			}
625
+		} else {
626
+			if (in_array(
627
+				$this->_get_req_type_for_plugin_corresponding_to_this_dms(),
628
+				array(EE_System::req_type_new_activation)
629
+			)) {
630
+				return true;
631
+			} else {
632
+				return false;
633
+			}
634
+		}
635
+	}
636
+
637
+	/**
638
+	 * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS
639
+	 *
640
+	 * @param string  $table_name
641
+	 * @param string  $table_definition_sql
642
+	 * @param string  $engine_string
643
+	 * @param boolean $drop_pre_existing_tables
644
+	 */
645
+	private function _create_table_and_catch_errors(
646
+		$table_name,
647
+		$table_definition_sql,
648
+		$engine_string = 'ENGINE=MyISAM',
649
+		$drop_pre_existing_tables = false
650
+	) {
651
+		try {
652
+			EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables);
653
+		} catch (EE_Error $e) {
654
+			$message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString();
655
+			$this->add_error($message);
656
+			$this->_feedback_message .= $message;
657
+		}
658
+	}
659
+
660
+
661
+	/**
662
+	 * Gets the request type for the plugin (core or addon) that corresponds to this DMS
663
+	 *
664
+	 * @return int one of EE_System::_req_type_* constants
665
+	 * @throws EE_Error
666
+	 */
667
+	private function _get_req_type_for_plugin_corresponding_to_this_dms()
668
+	{
669
+		if ($this->slug() == 'Core') {
670
+			return EE_System::instance()->detect_req_type();
671
+		} else {// it must be for an addon
672
+			$addon_name = $this->slug();
673
+			if (EE_Registry::instance()->get_addon_by_name($addon_name)) {
674
+				return EE_Registry::instance()->get_addon_by_name($addon_name)->detect_req_type();
675
+			} else {
676
+				throw new EE_Error(
677
+					sprintf(
678
+						__(
679
+							"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",
680
+							"event_espresso"
681
+						),
682
+						$this->slug(),
683
+						$addon_name,
684
+						implode(",", array_keys(EE_Registry::instance()->get_addons_by_name()))
685
+					)
686
+				);
687
+			}
688
+		}
689
+	}
690
+
691
+
692
+	/**
693
+	 * returns an array of strings describing errors by all the script's stages
694
+	 *
695
+	 * @return array
696
+	 */
697
+	public function get_errors()
698
+	{
699
+		$all_errors = $this->_errors;
700
+		if (! is_array($all_errors)) {
701
+			$all_errors = array();
702
+		}
703
+		foreach ($this->stages() as $stage) {
704
+			$all_errors = array_merge($stage->get_errors(), $all_errors);
705
+		}
706
+		return $all_errors;
707
+	}
708
+
709
+
710
+	/**
711
+	 * Indicates whether or not this migration script should continue
712
+	 *
713
+	 * @return boolean
714
+	 */
715
+	public function can_continue()
716
+	{
717
+		return in_array(
718
+			$this->get_status(),
719
+			EE_Data_Migration_Manager::instance()->stati_that_indicate_to_continue_single_migration_script
720
+		);
721
+	}
722
+
723
+
724
+	/**
725
+	 * Gets all the data migration stages associated with this script. Note:
726
+	 * addons can filter this list to add their own stages, and because the list is
727
+	 * numerically-indexed, they can insert their stage wherever they like and it will
728
+	 * get ordered by the indexes
729
+	 *
730
+	 * @return EE_Data_Migration_Script_Stage[]
731
+	 */
732
+	protected function stages()
733
+	{
734
+		$stages = apply_filters('FHEE__' . get_class($this) . '__stages', $this->_migration_stages);
735
+		ksort($stages);
736
+		return $stages;
737
+	}
738
+
739
+
740
+	/**
741
+	 * Gets a string which should describe what's going on currently with this migration, which
742
+	 * can be displayed to the user
743
+	 *
744
+	 * @return string
745
+	 */
746
+	public function get_feedback_message()
747
+	{
748
+		return $this->_feedback_message;
749
+	}
750
+
751
+
752
+	/**
753
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
754
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
755
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
756
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
757
+	 */
758
+	public function properties_as_array()
759
+	{
760
+		$properties = parent::properties_as_array();
761
+		$properties['_migration_stages'] = array();
762
+		foreach ($this->_migration_stages as $migration_stage_priority => $migration_stage_class) {
763
+			$properties['_migration_stages'][ $migration_stage_priority ] = $migration_stage_class->properties_as_array(
764
+			);
765
+		}
766
+		unset($properties['_mappings']);
767
+		unset($properties['previous_dms']);
768
+
769
+		foreach ($this->_mappings as $old_table_name => $mapping_to_new_table) {
770
+			foreach ($mapping_to_new_table as $new_table_name => $mapping) {
771
+				$this->_set_mapping_option($old_table_name, $new_table_name, $mapping);
772
+			}
773
+		}
774
+		return $properties;
775
+	}
776
+
777
+
778
+	/**
779
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
780
+	 * to have been made from the properties_as_array() function.
781
+	 *
782
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
783
+	 * @return void
784
+	 */
785
+	public function instantiate_from_array_of_properties($array_of_properties)
786
+	{
787
+		$stages_properties_arrays = $array_of_properties['_migration_stages'];
788
+		unset($array_of_properties['_migration_stages']);
789
+		unset($array_of_properties['class']);
790
+		foreach ($array_of_properties as $property_name => $property_value) {
791
+			$this->{$property_name} = $property_value;
792
+		}
793
+		// _migration_stages are already instantiated, but have only default data
794
+		foreach ($this->_migration_stages as $stage) {
795
+			$stage_data = $this->_find_migration_stage_data_with_classname(
796
+				get_class($stage),
797
+				$stages_properties_arrays
798
+			);
799
+			// SO, if we found the stage data that was saved, use it. Otherwise, I guess the stage is new? (maybe added by
800
+			// an addon? Unlikely... not sure why it wouldn't exist, but if it doesn't just treat it like it was never started yet)
801
+			if ($stage_data) {
802
+				$stage->instantiate_from_array_of_properties($stage_data);
803
+			}
804
+		}
805
+	}
806
+
807
+
808
+	/**
809
+	 * Gets the migration data from the array $migration_stage_data_arrays (which is an array of arrays, each of which
810
+	 * is pretty well identical to EE_Data_Migration_Stage objects except all their properties are array indexes)
811
+	 * for the given classname
812
+	 *
813
+	 * @param string $classname
814
+	 * @param array  $migration_stage_data_arrays
815
+	 * @return null
816
+	 */
817
+	private function _find_migration_stage_data_with_classname($classname, $migration_stage_data_arrays)
818
+	{
819
+		foreach ($migration_stage_data_arrays as $migration_stage_data_array) {
820
+			if (isset($migration_stage_data_array['class']) && $migration_stage_data_array['class'] == $classname) {
821
+				return $migration_stage_data_array;
822
+			}
823
+		}
824
+		return null;
825
+	}
826
+
827
+
828
+	/**
829
+	 * Returns the version that this script migrates to, based on the script's name.
830
+	 * Cannot be overwritten because lots of code needs to know which version a script
831
+	 * migrates to knowing only its name.
832
+	 *
833
+	 * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin
834
+	 * that will be updated to. Eg array('Core','4.1.0')
835
+	 */
836
+	final public function migrates_to_version()
837
+	{
838
+		return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this));
839
+	}
840
+
841
+
842
+	/**
843
+	 * Gets this addon's slug as it would appear in the current_db_state wp option,
844
+	 * and if this migration script is for an addon, it SHOULD match the addon's slug
845
+	 * (and also the addon's classname, minus the 'EE_' prefix.). Eg, 'Calendar' for the EE_Calendar addon.
846
+	 * Or 'Core' for core (non-addon).
847
+	 *
848
+	 * @return string
849
+	 */
850
+	public function slug()
851
+	{
852
+		$migrates_to_version_info = $this->migrates_to_version();
853
+		// the slug is the first part of the array
854
+		return $migrates_to_version_info['slug'];
855
+	}
856
+
857
+
858
+	/**
859
+	 * Returns the script's priority relative to DMSs from other addons. However, when
860
+	 * two DMSs from the same addon/core apply, this is ignored (and instead the version that
861
+	 * the script migrates to is used to determine which to run first). The default is 5, but all core DMSs
862
+	 * normally have priority 10. (So if you want a DMS "A" to run before DMS "B", both of which are from addons,
863
+	 * and both of which CAN run at the same time (ie, "B" doesn't depend on "A" to set
864
+	 * the database up so it can run), then you can set "A" to priority 3 or something.
865
+	 *
866
+	 * @return int
867
+	 */
868
+	public function priority()
869
+	{
870
+		return $this->_priority;
871
+	}
872
+
873
+
874
+	/**
875
+	 * Sets whether or not this DMS is being ran as part of a migration, instead of
876
+	 * just being used to setup (or verify) the current database structure matches
877
+	 * what the latest DMS indicates it should be
878
+	 *
879
+	 * @param boolean $migrating
880
+	 * @return void
881
+	 */
882
+	public function set_migrating($migrating = true)
883
+	{
884
+		$this->_migrating = $migrating;
885
+	}
886
+
887
+	/**
888
+	 * Marks that we think this migration class can continue to migrate
889
+	 */
890
+	public function reattempt()
891
+	{
892
+		parent::reattempt();
893
+		// also, we want to reattempt any stages that were marked as borked
894
+		foreach ($this->stages() as $stage) {
895
+			if ($stage->is_broken()) {
896
+				$stage->reattempt();
897
+			}
898
+		}
899
+	}
900 900
 }
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.