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