From 6cc38442303f7772478f8918a52064507522f710 Mon Sep 17 00:00:00 2001 From: bach Date: Fri, 16 Jul 2021 17:03:32 +0200 Subject: [PATCH] added member_type on user migration --- .../migrate_plus.migration.d7_users.yml | 9 ++++ .../src/Plugin/migrate/source/D7Users.php | 53 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/web/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_users.yml b/web/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_users.yml index 055ec612..5b55d917 100644 --- a/web/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_users.yml +++ b/web/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_users.yml @@ -105,6 +105,15 @@ process: # migration: d7_file # no_stub: true + field_member_type: member_type + # plugin: static_map + # source: member_type + # default_value: 0 + # map: + # 0:abo01-A + # 1:abo01-B + # 2:abo01-C + migration_dependencies: required: - d7_allpublicfiles diff --git a/web/modules/custom/materio_migrate/src/Plugin/migrate/source/D7Users.php b/web/modules/custom/materio_migrate/src/Plugin/migrate/source/D7Users.php index 5b4c5b3d..a913ca8a 100644 --- a/web/modules/custom/materio_migrate/src/Plugin/migrate/source/D7Users.php +++ b/web/modules/custom/materio_migrate/src/Plugin/migrate/source/D7Users.php @@ -134,6 +134,59 @@ class D7Users extends FieldableEntity { } } + // Member Type + // check if aaf + $field_memo = $row->getSourceProperty('field_memo'); + if ( stripos($field_memo[0]['value'], 'membre aaf') !== false ){ + // drush_print($row->getSourceProperty('mail').' member_type: AAF'); + $row->setSourceProperty('member_type', 2); + } else { + // get the uber_cart order infos + $query = $this->select('uc_orders', 'uco') + ->fields('uco', ['uid', 'order_id']); + $query->leftJoin('uc_order_products', 'ucop', 'ucop.order_id=uco.order_id'); + $query->fields('ucop', ['model']); + $query->condition('uid', $row->getSourceProperty('uid')); + $query->condition('ucop.nid', 11849); + $query->orderBy('uco.created', 'DESC'); + $orders = $query->execute()->fetchAll(); + + + if(count($orders)){ + $first_order = array_shift($orders); + // drush_print($row->getSourceProperty('mail')); + // drush_print(print_r($first_order, true)); + switch($first_order['model']){ + case "abo01-A": + $member_type = 0; + break; + case "abo01-B": + $member_type = 1; + break; + case "abo01-C": + $member_type = 1; + // add bad phone number to memo field + $memo .= "#migration: multijoueurs \n"; + break; + } + if(isset($member_type)){ + // drush_print($row->getSourceProperty('mail').' member_type: '.$member_type); + $row->setSourceProperty('member_type', $member_type); + } + + } + // abo01-A 1 (web) + // abo01-B 2 (web+showroom) + // abo01-C 2 (web+showroom) + } + + // record migration errors in field_memo + if(isset($memo)){ + $field_memo = $row->getSourceProperty('field_memo'); + $field_memo[0]['value'] .= "\n".$memo; + $row->setSourceProperty('field_memo', $field_memo); + } + return parent::prepareRow($row); }