Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import CSV Command for GMail export #60

Merged
merged 12 commits into from Jun 16, 2017
Merged

Add import CSV Command for GMail export #60

merged 12 commits into from Jun 16, 2017

Conversation

mkaz
Copy link

@mkaz mkaz commented Jun 6, 2017

Adds a Laravel Command to import a Google CSV file, one exported from GMail.

Usage: php artisan import:csv USER FILE

You will need to look up your user id and import, if you create a new account it is most likely 3. So for me I created a new user and downloaded the file as google.csv so the command is:

php artisan import:csv 3 google.csv

I also recommend merging any duplicates on Google/Gmail because there are data constraints on duplicate emails.

@mkaz mkaz mentioned this pull request Jun 6, 2017
@mkaz
Copy link
Author

mkaz commented Jun 7, 2017

There was an issue if data wasn't complete, I fixed it so it won't set as empty strings so the database will get NULLs as expected.

@djaiss
Copy link
Member

djaiss commented Jun 7, 2017

Thanks so much @mkaz

Can you indicate here how to get this CSV from Google? I'll update the README.

@mkaz
Copy link
Author

mkaz commented Jun 7, 2017

@djaiss - sure thing, I was going to make an animated GIF Screenshot, but too difficult with obscuring data.

  1. First go to Contacts by using the Mail drop down on the top left

gmail-export-0

  1. Next go More and select Export

gmail-export-1

  1. Select what list you want to export and the Google CSV format

gmail-export-2

That will save the file to your system, likely in ~/Downloads/google.csv

You can then run it on the command-line using php artisan import:csv 3 google.csv

Replace 3 with your user id for the account you want to import to, I just peeked in the database to get this.

@djaiss
Copy link
Member

djaiss commented Jun 7, 2017

Thanks so much. I'll take care of it tomorrow - it's too late for me now after this incredible day, but I truly appreciate the help here!

@mkaz
Copy link
Author

mkaz commented Jun 7, 2017

@djaiss - great tool, thanks for building and open sourcing it. I'm glad to help out.
I'm adding a couple of extra checks so good it'll be tomorrow.
Cheers!

mkaz and others added 2 commits June 6, 2017 18:58
Adds a check to see if First, Middle, or Last name is set and
doesn't import if not set. You can't click into a Contact without
a name, so probably not worth importing.

Also adds output for how many records imported
@djaiss
Copy link
Member

djaiss commented Jun 7, 2017

Added some comments.

$contact = new Contact();
$contact->account_id = $user->id;

if ( ! empty( $data[1] ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first check should be to verify that either $data[0] or $data[1] contains a value (Name or given name) because these are the only data that we need to import. If we don't have one of these two values, we can't import the row, period (a contact without a name won't work in the current UI).
Can you make this check? Thanks a lot!

}

// gender required - default to female
$contact->gender = ( substr($data[15], 0, 1 ) == 'm' ) ? 'male' : 'female';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed that today. You can now default to none.

mkaz added 2 commits June 7, 2017 19:14
Removed gender import, there is no way to set this in Gmail interface
and from what I can tell the field has no data and now is not required.
@mkaz
Copy link
Author

mkaz commented Jun 8, 2017

@djaiss updated with requests 👍

@djaiss
Copy link
Member

djaiss commented Jun 8, 2017

@mkaz thanks!

I've tried it but all the contacts that I import are empty.

Instead of blank I should at least get a firstname... Any idea why? I took the CSV from Google Contact using the instructions you've provided.

image

@erdmenchen
Copy link

Why do we need to search for a users id if we could also use the email address to identify a user for linking the imported data?
Just make the command usabe on the first run...dont make me search for my id...its easier to remember my email address...

@yamakadi
Copy link

Wouldn't it be better to have a way to import and export vcards instead of limiting it to just google contacts? Not all providers use the same extended syntax for non-standard fields (such as custom labels), but standard fields shouldn't be an issue.

@mkaz
Copy link
Author

mkaz commented Jun 10, 2017

This was a quick and simple way to import some data in a format that I had it in - if it works for you then great. Ideally, an importer that can handle any format would be great with a front-end and not having to look up users or use the command-line.

@erdmenchen
Copy link

Then why not trigger this import via the UI?
For example inside the settings area.
And get the user id from the logged in user...

@djaiss
Copy link
Member

djaiss commented Jun 12, 2017

@mkaz do you know why I got these errors?

djaiss pushed a commit that referenced this pull request Jun 12, 2017
This pull request adds a command to import vcards (similar to #60 ).

Usage: php artisan import:vcard {user: User's email address} {path: Path to a .vcf file} 

The command checks whether an email already exists, so duplicates shouldn't be an issue.
@mkaz
Copy link
Author

mkaz commented Jun 12, 2017

@djaiss I double checked my process and all worked fine for me. I'm not sure if Google exports them in different orders and uses the header to determine which is which. My implementation assumed that it was the same fixed order for every export, which would make sense.

If you import your csv file into Excel you can see which column maps to which field

@djaiss djaiss merged commit 551c486 into monicahq:master Jun 16, 2017
@github-actions
Copy link

This pull request has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants