PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Database / UserMetaMigrationsService.php
UserMetaMigrationsService.php
51 lines 902 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Database;
4
5 /**
6 * Update user meta that was incorrectly saved.
7 */
8 class UserMetaMigrationsService extends GeneralMigration {
9 /**
10 * Run the migration.
11 *
12 * @return void
13 */
14 public function run() {
15 $this->flushRoles();
16 $this->runUserMetaMigration();
17 }
18
19 /**
20 * Migrate user meta
21 *
22 * @return void
23 */
24 public function runUserMetaMigration() {
25 $customers = get_users(
26 array(
27 'meta_key' => 'sc_customer_ids',
28 )
29 );
30
31 // we don't have customers.
32 if ( empty( $customers ) ) {
33 return;
34 }
35
36 // updating will re-sanitize these values that were incorrectly sanitized.
37 foreach ( $customers as $customer ) {
38 update_user_meta( $customer->ID, 'sc_customer_ids', $customer->sc_customer_ids );
39 }
40 }
41
42 /**
43 * Always flush roles when version changes.
44 *
45 * @return void
46 */
47 public function flushRoles() {
48 \SureCart::roles()->create();
49 }
50 }
51