From 801d296c0c4c53dacd194af2fb52918be93f2350 Mon Sep 17 00:00:00 2001 From: Fran Garcia-Linares <14157-fjgarlin@users.noreply.drupalcode.org> Date: Wed, 2 Apr 2025 14:57:06 +0000 Subject: [PATCH 1/3] Add new command. --- drupalorg/drupalorg.drush.inc | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drupalorg/drupalorg.drush.inc b/drupalorg/drupalorg.drush.inc index dd8cf0e3..2d526c78 100644 --- a/drupalorg/drupalorg.drush.inc +++ b/drupalorg/drupalorg.drush.inc @@ -26,6 +26,13 @@ function drupalorg_drush_command() { 'drupalorg-org-credit' => [ 'description' => 'Update organization credit totals.', ], + 'drupalorg-event-volunteers' => [ + 'description' => 'Update speakers, volunteers fields from an event in bulk.', + 'arguments' => [ + 'event_nid' => 'Event node ID.', + 'csv_file' => 'CSV file containing the list.', + ], + ], 'drupalorg-integrity' => [ 'description' => 'Integrity check for a non-ideal world.', ], @@ -181,6 +188,75 @@ function drupalorg_drush_command() { ]; } +/** + * Bulk add volunteers and speakders to an event. + */ +function drush_drupalorg_event_volunteers($event_nid, $csv_file) { + // Load the event node. + if (!($event = node_load($event_nid))) { + drush_set_error(dt('Could not load the event.')); + return; + } + + if ($event->type !== 'event') { + drush_set_error(dt('Node ID is not an event.')); + return; + } + + // Read CSV. + // Format - 2 columns: [username|mail|user],[coc|organizer|speaker|volunteer]. + if (!file_exists($csv_file)) { + drush_set_error(dt('Could not find the file.')); + return; + } + + $map_field = [ + 'coc' => 'field_code_of_conduct_contact', + 'organizer' => 'field_organizers', + 'speaker' => 'field_event_speakers', + 'volunteer' => 'field_event_volunteers', + ]; + + $csv = array_map('str_getcsv', file($csv_file)); + if (!empty($csv)) { + $unmatched_users = []; + foreach ($csv as $line) { + if (is_array($line) && count($line) === 2) { + if (is_numeric($line[0])) { + $loading_function = 'user_load'; + } + elseif (strpos($line[0], '@') !== FALSE) { + $loading_function = 'user_load_by_mail'; + } + else { + $loading_function = 'user_load_by_name'; + } + $user = $loading_function($line[0]); + $volunteer_field = isset($map_field[$line[1]]) ? $map_field[$line[1]] : 'field_event_volunteers'; + if (!empty($user)) { + drush_log(dt('Adding user @uid as @type.', [ + '@uid' => $user->uid, + '@type' => $volunteer_field, + ])); + $event->{$volunteer_field}[LANGUAGE_NONE][] = [ + 'target_id' => $user->uid, + ]; + } + else { + $unmatched_users[] = $line[0]; + } + } + } + drush_log(dt('Saving event.')); + node_save($event); + if (!empty($unmatched_users)) { + drush_log(dt('The following users could not be matched: @users.', [ + '@users' => implode(', ', $unmatched_users), + ]), LogLevel::WARNING); + } + } +} + function drush_drupalorg_rebuild_stats() { drupalorg_get_activity(TRUE); } -- GitLab From 22a468d0cc20dedd4a93d9ea89f20a7b672e8d33 Mon Sep 17 00:00:00 2001 From: Fran Garcia-Linares <14157-fjgarlin@users.noreply.drupalcode.org> Date: Wed, 2 Apr 2025 15:30:16 +0000 Subject: [PATCH 2/3] Apply 1 suggestion(s) to 1 file(s) --- drupalorg/drupalorg.drush.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drupalorg/drupalorg.drush.inc b/drupalorg/drupalorg.drush.inc index 2d526c78..a800adf7 100644 --- a/drupalorg/drupalorg.drush.inc +++ b/drupalorg/drupalorg.drush.inc @@ -189,7 +189,7 @@ function drupalorg_drush_command() { } /** - * Bulk add volunteers and speakders to an event. + * Bulk add volunteers and speakers to an event. */ function drush_drupalorg_event_volunteers($event_nid, $csv_file) { // Load the event node. -- GitLab From 7210dcfb5ddb610edd50aa435e5bebfe9c075bfc Mon Sep 17 00:00:00 2001 From: Fran Garcia-Linares <14157-fjgarlin@users.noreply.drupalcode.org> Date: Wed, 2 Apr 2025 20:13:57 +0000 Subject: [PATCH 3/3] Add count to the message. --- drupalorg/drupalorg.drush.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drupalorg/drupalorg.drush.inc b/drupalorg/drupalorg.drush.inc index a800adf7..6fe6024a 100644 --- a/drupalorg/drupalorg.drush.inc +++ b/drupalorg/drupalorg.drush.inc @@ -250,7 +250,8 @@ function drush_drupalorg_event_volunteers($event_nid, $csv_file) { drush_log(dt('Saving event.')); node_save($event); if (!empty($unmatched_users)) { - drush_log(dt('The following users could not be matched: @users.', [ + drush_log(dt('@total user(s) could not be matched: @users.', [ + '@total' => count($unmatched_users), '@users' => implode(', ', $unmatched_users), ]), LogLevel::WARNING); } -- GitLab