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