Export accounts

Hello,
how can I export to CSV all grav accounts?
Should I build a plugin or does a method already exist?

Thanks

@samuele, What would be the use case for that?

Since Grav is a flatfile based CMS, all that is needed is copying the /user/accounts folder.

I have a site with a thousand of accounts and my client wants to export it to CSV to verify data.

@samuele, AFAIK, Grav does not have the tools for this. However, conversion of YAML to CSV has quite a few search hits on the web.

do you think the data manager plugin could be useful or configured for this case?

@samuele, I don’t know the plugin. Have you tried it?

I take a look…it seemed not, but I have to study it better.

It can because I have done this with form data. Several years ago though, may be able to dig that code out if you are interested.

I think for a one-off, I would use a conversion tool. There may be an online converter or an importer into Google Sheets or Excel. You could even write a custom PHP (Perl/Python) script. I do that when importing legacy website databases as CSV into Grav sometimes.

@hughbris Yes, I’m interested if you can dig that code out. I’d like to make this function available from the admin panel and before writing a plugin, I think it is better to find out standard/available options instead of writing a custom plugin…if it is possible :wink:.
Thanks

1 Like

I just took a look and it’s not quite how I remembered. In fact, the CSV export is part of the Data Manager plugin by default. (It was PDF export I’d added.)

image

Accounts are not featured in Data Manager’s dataset options. However, I realised that I could copy the accounts folder to user/data and then it appears as a dataset.

The problem with the CSV button is that on my Grav I get a runtime error Failed to save file /var/www/grav/tmp/data-manager/629afad6dfc81.csv/. I don’t know if this is just me and I couldn’t easily debug it. Would you try a CSV export and tell me if that error comes up for you? (I can see there’s an issue about it.)

If we can’t overcome this error, I am pretty sure we can create a hack to work around it to get your export. We don’t have to store this file (where it’s throwing the error), we can just serve it to the browser.

Yes, I’ve the same error. I left this comment.

1 Like

Cool, you worked around it. So if you copy accounts to the user/data folder, can you export user CSV?

Yes, in data directory I created a sym link to user/accounts and it’s done :wink:

1 Like