Exporting repository - command line, csv

102 views
Skip to first unread message

Matthew Bruton

unread,
Mar 27, 2020, 2:04:11 PM3/27/20
to ica-ato...@googlegroups.com
Hi there,

I'm having difficulty exporting a repository into a csv in the command line.

I am following the intructions which say the following:

php symfony csv:export --criteria="i.repository_id = (SELECT object_id FROM
slug WHERE slug='example-repo-slug')" /path/to/my/exportFolder


If I leave out the path, it starts exporting (but I can't find the file anywhere). If I put in
the path then it gives and error saying there are too many arguments. See attachment.

Questions:

1. Am I right in presuming that leaving the path as simply "/" will export to the path I am in? Namely /usr/share/nginx/atom .
Or do I need to specify the path more broadly?

2. Do I then put in the name of the CSV , say exampleexport.csv , at the end of this path?

I have tried both these options and they don't work. Exact same error.

So I am at a loss, and need the help of the community here. Perhaps there are extra arguments I need to add,
or another way to phrase the command, but if so, I have no idea what to put in because I am following
the documentation.

Many thanks in advance,
Matthew

P.S. I am putting the slug address from after "index.php", so it reads "slug='/myexamplerespository" rather
 than index.php/myexamplerepository.
Don't think that is the problem, but just mentioning it in case.
error screen expo1.png

Dan Gillean

unread,
Mar 27, 2020, 3:51:02 PM3/27/20
to ICA-AtoM Users
Hi Matthew, 

It's really hard to hell from that screenshot, but: 

Make sure you enter command in a single line - it's broken up into two lines in the docs simply due to available space, but I've just tested the following with our public demo data in my local vagrant box and it worked as expected: 

php symfony csv:export --criteria="i.repository_id = (SELECT object_id FROM slug WHERE slug='art-gallery-of-ontario-research-library-and-archives')" /vagrant/ago-test.csv

You will at minimum need to specify the filename of the CSV - I also tried the above command just with test.csv as the path, and it created my expected export exactly where I was (at the root AtoM installation directory). 

The other thing you could try is to simplify the criteria by first using the MySQL command prompt to fetch the repository id. Then you can simplify the criteria in the export command so it doesn't have a nested SELECT statement. Here's an example I tried that worked: 

mysql-query-repo-id.png

Let us know if this helps! 

Dan Gillean, MAS, MLIS
AtoM Program Manager
Artefactual Systems, Inc.
604-527-2056
@accesstomemory
he / him


On Fri, Mar 27, 2020 at 2:04 PM Matthew Bruton <matthewb...@gmail.com> wrote:
Hi there,

I'm having difficulty exporting a repository into a csv in the command line.

I am following the intructions which say the following:

php symfony csv:export --criteria="i.repository_id = (SELECT object_id FROM
slug WHERE slug='example-repo-slug')" /path/to/my/exportFolder


If I leave out the path, it starts exporting (but I can't find the file anywhere). If I put in
the path then it gives and error saying there are too many arguments. See attachment.

Questions:

1. Am I right in presuming that leaving the path as simply "/" will export to the path I am in? Namely /usr/share/nginx/atom .
 Or do I need to specify the path?


2. Do I then put in the name of the CSV , say exampleexport.csv , at the end of this path?

I have tried both these options and they don't work. Exact same error.

So I am at a loss, and need the help of the community here. Perhaps there are extra arguments I need to add,
or another way to phrase the command, but if so, I have no idea what to put in because I am following
the documentation.

Many thanks in advance,
Matthew

--
You received this message because you are subscribed to the Google Groups "AtoM Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ica-atom-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ica-atom-users/bc817d79-08dd-467a-8fd8-a6a56198970d%40googlegroups.com.

Matthew Bruton

unread,
Mar 31, 2020, 10:47:36 AM3/31/20
to AtoM Users
Dan,

Thanks.

I did it again, precisely typing down what you wrote. I tried both ways of doing it including the mysql id.

Now I am having a new problem. Instead of the error above, it seems to execute fine, but says 0 descriptions exported, when it does.

I can't find the csv file anywhere.

Any more ideas of things I should try/check?
error exp.png

Matthew Bruton

unread,
Apr 23, 2020, 11:53:59 AM4/23/20
to AtoM Users
any ideas?

Dan Gillean

unread,
Apr 23, 2020, 12:29:20 PM4/23/20
to ICA-AtoM Users
Hi Matthew, 

Sorry, I lost track of this thread - thanks for the prompt. 

First, perhaps let's try a few maintenance tasks to make sure things are well constructed in the database. Let's try running the slug generation task, and the build nested set task, to make sure nothing needed is missing from the database: 
  • php symfony propel:generate-slugs
  • php symfony propel:build-nested-set
See: 
The other thing we can do is double-check that your descriptions are actually associated with that object ID in the database, using SQL. You'll need to access the MysQL command-prompt to run the following. 

Accessing MySQL

To access the MySQL command prompt so we can run SQL queries,  we will need to know the MySQL username, password, and database name used during installation. If you can't recall for certain what credentials you used, you can always check in config/config.php - for example, to see this file you could run the following from the root AtoM installation directory, which should be /usr/share/nginx/atom if you have followed our recommended installation instructions: 

  • sudo nano config/config.php

You should see the database name and credentials listed near the top of the file. You can also check your database username and password in /root/.my.cnf like so:

  • sudo cat  /root/.my.cnf

Once you have the database name, MySQL user name, and password, we can use these to access the MySQL command prompt. Assuming in the following example that your database name is atom and your user and password are root, you could access the prompt like so: 

  • mysql -u root -proot atom;

Notice that there is a space between the -u and root, but NOT between the -p and the root password. Alternatively, you can leave no password following the -p, and you will be prompted to enter it by the command prompt before proceeding. 


At this point, we should have access to the MySQL command prompt, which should look like this: 


mysql>


Check the count of top-level descriptions associated with a particular repository

We've previously retrieved the object ID of your repository record, using the slug. We did that with the following: 
  • SELECT object_id FROM slug WHERE slug="this-is-my-repository-slug"; 
Now we can try the following query, which should return a count of how many top-level descriptions are associated with that repository in the database: 
  • SELECT COUNT(*) FROM information_object WHERE repository_id='25753' AND parent_id="1";
If that count returns 0, then either we have the wrong repository ID value, or else your descriptions are not actually associated with that repository. 

If that still doesn't work

If the above solutions don't seem to point to anything amiss that would lead the export to fail, then it may be worth double-checking whether or not there is any obvious data corruption in your installation. We have some queries here that might help find it: 
I'd also suggest testing an export of one of your description hierarchies from the clipboard, including all descendants, to see if it works. If you can remind me about your installation details that might help as well - some prompts for information to include here: 
There's also a couple workarounds you could try to get what you need. 

First, if you go to your repository record, the holdings browse list on the left side of the page includes a link to "Browse XX holdings." This will take you to a search results page limited to the current repository, and top level descriptions. 

From here, you could try two possible approaches: 

The first would be to manually add all these top-level descriptions to the Clipboard, and then run the export from there, including descendants. See: 
The other option you could try would be removing the top-level description filter (so all descriptions are displaying), trying to find a sort order that preserves the hierarchical arrangement as best as possible (perhaps sorting by reference code or identifier, for example), and then using the "Export CSV" button at the top of the search results to export all of these. See: 
Note that, with this option, the descriptions in the export CSV will likely be in the order of the search results. This means that, if at some point in the results, a child record appears BEFORE a parent record, then you'll have problems when you try to reimport this to another AtoM instance in the future, unless you take some time to manually reorder the CSV rows. This is why I suggested doing everything you can with the sort options to try to order things as best as possible in advance. 

Hope this helps! Let us know what you find. 

Cheers, 

Dan Gillean, MAS, MLIS
AtoM Program Manager
Artefactual Systems, Inc.
604-527-2056
@accesstomemory
he / him

--
You received this message because you are subscribed to the Google Groups "AtoM Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ica-atom-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages