regen user names, removed profiles & member_type field from user form
This commit is contained in:
parent
63f54f17ef
commit
a2a53addf3
|
@ -10,7 +10,6 @@ dependencies:
|
||||||
- field.field.user.user.field_showroom
|
- field.field.user.user.field_showroom
|
||||||
module:
|
module:
|
||||||
- path
|
- path
|
||||||
- profile
|
|
||||||
- user
|
- user
|
||||||
id: user.user.default
|
id: user.user.default
|
||||||
targetEntityType: user
|
targetEntityType: user
|
||||||
|
@ -22,20 +21,6 @@ content:
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
contact_company_profiles:
|
|
||||||
type: profile_form
|
|
||||||
weight: 8
|
|
||||||
region: content
|
|
||||||
settings:
|
|
||||||
form_mode: default
|
|
||||||
third_party_settings: { }
|
|
||||||
customer_profiles:
|
|
||||||
type: profile_form
|
|
||||||
weight: 7
|
|
||||||
region: content
|
|
||||||
settings:
|
|
||||||
form_mode: default
|
|
||||||
third_party_settings: { }
|
|
||||||
field_company:
|
field_company:
|
||||||
type: entity_reference_autocomplete
|
type: entity_reference_autocomplete
|
||||||
weight: 1
|
weight: 1
|
||||||
|
@ -46,12 +31,6 @@ content:
|
||||||
size: 60
|
size: 60
|
||||||
placeholder: ''
|
placeholder: ''
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
field_member_type:
|
|
||||||
type: options_select
|
|
||||||
weight: 4
|
|
||||||
region: content
|
|
||||||
settings: { }
|
|
||||||
third_party_settings: { }
|
|
||||||
field_memo:
|
field_memo:
|
||||||
type: string_textarea
|
type: string_textarea
|
||||||
weight: 3
|
weight: 3
|
||||||
|
@ -71,7 +50,7 @@ content:
|
||||||
placeholder: ''
|
placeholder: ''
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
language:
|
language:
|
||||||
weight: 9
|
weight: 5
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
|
@ -80,31 +59,28 @@ content:
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
member_profiles:
|
|
||||||
type: profile_form
|
|
||||||
weight: 6
|
|
||||||
region: content
|
|
||||||
settings:
|
|
||||||
form_mode: default
|
|
||||||
third_party_settings: { }
|
|
||||||
path:
|
path:
|
||||||
type: path
|
type: path
|
||||||
weight: 11
|
weight: 7
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
simplenews:
|
simplenews:
|
||||||
weight: 5
|
weight: 4
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
timezone:
|
timezone:
|
||||||
weight: 10
|
weight: 6
|
||||||
region: content
|
region: content
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
hidden:
|
hidden:
|
||||||
commerce_remote_id: true
|
commerce_remote_id: true
|
||||||
contact: true
|
contact: true
|
||||||
|
contact_company_profiles: true
|
||||||
|
customer_profiles: true
|
||||||
|
field_member_type: true
|
||||||
google_analytics: true
|
google_analytics: true
|
||||||
langcode: true
|
langcode: true
|
||||||
|
member_profiles: true
|
||||||
|
|
|
@ -0,0 +1,186 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
//
|
||||||
|
// This example demonstrates how to write a drush
|
||||||
|
// script. These scripts are run with the php-script command.
|
||||||
|
//
|
||||||
|
use Drush\Drush;
|
||||||
|
|
||||||
|
$this->output()->writeln("User names regenerating");
|
||||||
|
|
||||||
|
$this->output()->writeln("The extra options/arguments to this command were:");
|
||||||
|
$this->output()->writeln(print_r($extra, true));
|
||||||
|
// if ($extra[0] === "delete") {
|
||||||
|
// $delete = true;
|
||||||
|
// } else {
|
||||||
|
// $delete = false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
$database = \Drupal::database();
|
||||||
|
|
||||||
|
// __ __ _ _
|
||||||
|
// | \ \ ___ <_>| | ___
|
||||||
|
// | |<_> || || |<_-<
|
||||||
|
// |_|_|_|<___||_||_|/__/
|
||||||
|
|
||||||
|
|
||||||
|
$this->output()->writeln("");
|
||||||
|
|
||||||
|
$result = $database->query("
|
||||||
|
SELECT mail
|
||||||
|
FROM {users_field_data}
|
||||||
|
GROUP BY mail
|
||||||
|
HAVING COUNT(*) > 1");
|
||||||
|
|
||||||
|
$dupmail = [];
|
||||||
|
foreach ($result as $user) {
|
||||||
|
// $this->output()->writeln($user->mail);
|
||||||
|
$dupmail[] = $user->mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output()->writeln(count($dupmail) . ' dup emails');
|
||||||
|
|
||||||
|
|
||||||
|
$this->output()->writeln("");
|
||||||
|
|
||||||
|
|
||||||
|
$this->output()->writeln("All users Name <- Mail");
|
||||||
|
$ufd_query = $database->select('users_field_data', 'ufd')
|
||||||
|
->fields('ufd', ['uid', 'name', 'mail'])
|
||||||
|
->condition('ufd.uid', [0,1], 'NOT IN')
|
||||||
|
->condition('mail', $dupmail, 'NOT IN');
|
||||||
|
|
||||||
|
|
||||||
|
$ufd_result = $ufd_query->execute();
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($ufd_result as $ufd) {
|
||||||
|
$user_updated = $database->update('users_field_data')
|
||||||
|
->fields([
|
||||||
|
'name' => $ufd->mail
|
||||||
|
])
|
||||||
|
->condition('uid', $ufd->uid)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// __ __ _
|
||||||
|
// | \ \ ___ ._ _ _ | |_ ___ _ _ ___
|
||||||
|
// | |/ ._>| ' ' || . \/ ._>| '_><_-<
|
||||||
|
// |_|_|_|\___.|_|_|_||___/\___.|_| /__/
|
||||||
|
|
||||||
|
$this->output()->writeln("");
|
||||||
|
|
||||||
|
$this->output()->writeln("All users Name <- Profile member");
|
||||||
|
|
||||||
|
$p_query = $database->select('profile', 'p');
|
||||||
|
$p_query->join('profile__field_name', 'pfn', 'pfn.entity_id = p.profile_id');
|
||||||
|
$p_query->join('profile__field_first_name', 'pffn', 'pffn.entity_id = p.profile_id');
|
||||||
|
$p_query->join('user__roles', 'ur', 'ur.entity_id = p.uid');
|
||||||
|
$p_query->join('users_field_data', 'ufd', 'ufd.uid = p.uid');
|
||||||
|
$p_query
|
||||||
|
->fields('p', ['profile_id', 'uid'])
|
||||||
|
->fields('pfn', ['field_name_value'])
|
||||||
|
->fields('pffn', ['field_first_name_value'])
|
||||||
|
->fields('ur', ['entity_id', 'roles_target_id'])
|
||||||
|
->fields('ufd', ['mail'])
|
||||||
|
->condition('p.type', 'member')
|
||||||
|
->condition('ur.roles_target_id', 'adherent');
|
||||||
|
|
||||||
|
$p_result = $p_query->execute();
|
||||||
|
|
||||||
|
// avoid duplicates
|
||||||
|
$members = [];
|
||||||
|
foreach ($p_result as $p) {
|
||||||
|
// $this->output()->writeln("profile name ". $p->field_first_name_value . ' ' . $p->field_name_value);
|
||||||
|
$name = $p->field_first_name_value . ' ' . $p->field_name_value;
|
||||||
|
$name = str_replace(' Col.', '', $name);
|
||||||
|
if (!in_array($name, array_values($members), true)) {
|
||||||
|
$members[] = [
|
||||||
|
"name" => $name,
|
||||||
|
"mail" => $p->mail,
|
||||||
|
"uid" => $p->uid
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $members = array_unique($members);
|
||||||
|
// array_multisort($members);
|
||||||
|
// $this->output()->writeln(print_r($members, true));
|
||||||
|
|
||||||
|
// $this->output()->writeln(print_r(array_count_values($members)));
|
||||||
|
|
||||||
|
$this->output()->writeln("members count ". count($members));
|
||||||
|
|
||||||
|
$prev_name = "";
|
||||||
|
foreach ($members as $member) {
|
||||||
|
$this->output()->writeln("updating " . $member['uid'] . " " . $member['name'] . " | " . $member['mail']);
|
||||||
|
$user_updated = $database->update('users_field_data')
|
||||||
|
->fields([
|
||||||
|
'name' => $member['name']
|
||||||
|
])
|
||||||
|
->condition('uid', $member['uid'])
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ___ _
|
||||||
|
// | _> _ _ ___ _| |_ ___ ._ _ _ ___ _ _ ___
|
||||||
|
// | <__| | |<_-< | | / . \| ' ' |/ ._>| '_><_-<
|
||||||
|
// `___/`___|/__/ |_| \___/|_|_|_|\___.|_| /__/
|
||||||
|
|
||||||
|
|
||||||
|
$this->output()->writeln("All users Name <- Profile customer");
|
||||||
|
|
||||||
|
$p_query = $database->select('profile', 'p');
|
||||||
|
$p_query->join('profile__address', 'pa', 'pa.entity_id = p.profile_id');
|
||||||
|
$p_query->join('user__roles', 'ur', 'ur.entity_id = p.uid');
|
||||||
|
$p_query->join('users_field_data', 'ufd', 'ufd.uid = p.uid');
|
||||||
|
$p_query
|
||||||
|
->fields('p', ['profile_id', 'uid'])
|
||||||
|
->fields('pa', ['address_given_name', 'address_family_name'])
|
||||||
|
->fields('ur', ['entity_id', 'roles_target_id'])
|
||||||
|
->fields('ufd', ['mail'])
|
||||||
|
->condition('p.type', 'customer')
|
||||||
|
->condition('ufd.mail', ['info@materio.com'], 'NOT IN')
|
||||||
|
->condition('ur.roles_target_id', 'adherent');
|
||||||
|
|
||||||
|
$p_result = $p_query->execute();
|
||||||
|
|
||||||
|
// avoid duplicates
|
||||||
|
$customers = [];
|
||||||
|
foreach ($p_result as $p) {
|
||||||
|
// $this->output()->writeln("profile name ". $p->field_first_name_value . ' ' . $p->field_name_value);
|
||||||
|
$name = $p->address_given_name . ' ' . $p->address_family_name;
|
||||||
|
$name = str_replace(' Col.', '', $name);
|
||||||
|
if (!in_array($name, array_values($customers), true)) {
|
||||||
|
$customers[] = [
|
||||||
|
"name" => $name,
|
||||||
|
"mail" => $p->mail,
|
||||||
|
"uid" => $p->uid
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $customers = array_unique($customers);
|
||||||
|
// array_multisort($customers);
|
||||||
|
// $this->output()->writeln(print_r($customers, true));
|
||||||
|
|
||||||
|
// $this->output()->writeln(print_r(array_count_values($customers)));
|
||||||
|
|
||||||
|
|
||||||
|
$this->output()->writeln("customers count ". count($customers));
|
||||||
|
|
||||||
|
$prev_name = "";
|
||||||
|
foreach ($customers as $customer) {
|
||||||
|
$this->output()->writeln("updating " . $customer['uid'] . " " . $customer['name'] . " | " . $customer['mail']);
|
||||||
|
$user_updated = $database->update('users_field_data')
|
||||||
|
->fields([
|
||||||
|
'name' => $customer['name']
|
||||||
|
])
|
||||||
|
->condition('uid', $customer['uid'])
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue