I have a long list of donations that I want to import. My first step was to ensure that all the contacts in the list exist in CiviCRM - that's done, and I spent a while deduplicating the records. Next, I imported all the donations that mapped cleanly using email addresses. That worked well.
Now I have a couple hundred donations left where the only identifying information is the contact's First Name and Last Name field. It seems like the right thing to do now is to write a script that determines whether each of my First/Last pairs is unique among all contacts, and if so, pull the Contact ID so that I can put an ID in each line of the import data, and finally import the donations. After this, I think there should only be a handful of donations to add manually.
I was initially trying to write a script like so:
if (($handle = fopen($argv[1], "r")) !== FALSE) {
$header = fgetcsv($handle, 1000);
fputcsv(STDOUT, $header);
echo ",contact_id\n";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row = array_combine($header, $data);
$result = civicrm_api4('Contact', 'get', [
'select' => ['primary_contact_id'],
'where' => [['first_name', '=', $row['Firstname']],
['last_name', '=', $row['Lastname']]]]);
if (count($result) != 1) {
continue;
}
row[] = $result[0]['id'];
fputcsv(STDOUT, $row);
echo "\n";
}
fclose($handle);
}
However, I got stuck trying to load the API library, and eventually I found the page https://docs.civicrm.org/dev/en/latest/extensions/advanced/ , which tells me I shouldn't be attempting to write a script like this (but it also says that its own self is out of date...).
So what would be a good way to go about this? I don't anticipate needing to do this exact task again, so I don't need to make it repeatable, but it would be good to learn what the "paved path" is here because I'm sure there will be other tasks to perform at various times.