Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
drupalorg
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupalorg
Commits
af3b10c2
Commit
af3b10c2
authored
1 week ago
by
Fran Garcia-Linares
Committed by
Neil Drumm
1 week ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3516901
: Bulk import of event volunteers, speakers via CSV and drush
parent
fa78028c
No related branches found
Branches containing commit
No related tags found
1 merge request
!334
Command to bulk update event volunteers via CSV
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
drupalorg/drupalorg.drush.inc
+77
-0
77 additions, 0 deletions
drupalorg/drupalorg.drush.inc
with
77 additions
and
0 deletions
drupalorg/drupalorg.drush.inc
+
77
−
0
View file @
af3b10c2
...
...
@@ -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,76 @@ function drupalorg_drush_command() {
];
}
/**
* Bulk add volunteers and speakers 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
(
'@total user(s) could not be matched: @users.'
,
[
'@total'
=>
count
(
$unmatched_users
),
'@users'
=>
implode
(
', '
,
$unmatched_users
),
]),
LogLevel
::
WARNING
);
}
}
}
function
drush_drupalorg_rebuild_stats
()
{
drupalorg_get_activity
(
TRUE
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment