Batch import from CSV

732 views
Skip to first unread message

Aethaelweard

unread,
Dec 17, 2009, 6:35:40 AM12/17/09
to ResourceSpace
What a fabulous application, and open source! Big thanks are owing to
Oxfam, the original developers and all the people who have contributed
to ResourceSpace. I hope the rest of us can help it grow!

Like many other people I need to put together a script to import a
batch of files into ResourceSpace along with metadata from a CSV.
Basically I'm hoping to write a PHP script that will do what the edit
and upload pages do, over and over for a batch of assets of various
types.

I've seen the examples on the forum, but as a complete newbie I'm
having trouble clarifying the basic steps an import script needs to
do. This is how it looks to me so far:

1. Read the first line of the CSV, which gives us the filename of the
first asset and its metadata.
2. Create a resource in ResourceSpace, giving it a temporary ref which
is the negative of the ref of the user doing the import. (So if I'm
user 2, give the resource ref -2).
3. Update the resource data for that asset using the data from the
CSV. (Assuming we've worked out the data mapping in advance.)
4. Copy the file into the ResourceSpace filestore.
5. Give the resource a "proper" resource ref.
6. Generate preview files, extracted text and keywords from the file
we've just copied in.
7. Loop back to next line of CSV.

Could some kind benefactor please give us any hints about which
functions we should call to do steps 2 to 6? If there's no function
that'll automatically create the right folder within /filestore to
store a new resource, what file structure should we use so the assets
are properly organised?

Thanks guys
Aethaelweard

Tom Gleason

unread,
Dec 21, 2009, 8:24:14 PM12/21/09
to resour...@googlegroups.com
There are many ways to go about this. You don't need to create a
temporary ref, though. You can just create the resources directly with
a script, but here's another suggestion:

Once I had a bunch of numbered files and an accompanying CSV sheet
with metadata. If you have a solid relationship between the filenames
and the same names on your CSV sheet, you might want to just upload
all the resources without metadata first. That's the big part, and
once its done you can leave the files as they are and run a script
against them as many times as you need to get it all right. In your
script, for each line, find the resource that has that filename, and
then for each field, update the proper field in RS.

What I would normally do is rename the headers on the CSV to the
corresponding field IDs in resourcespace. That makes the program much
easier to comprehend...
you find the resource $ref, then for each field,
update_field($ref,$field,"value");

Tom

> --
>
> You received this message because you are subscribed to the Google Groups "ResourceSpace" group.
> To post to this group, send email to resour...@googlegroups.com.
> To unsubscribe from this group, send email to resourcespac...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/resourcespace?hl=en.
>
>
>

--
Tom Gleason
-
http://resourcespace.blogspot.com/

Tom Gleason

unread,
Dec 21, 2009, 8:33:59 PM12/21/09
to resour...@googlegroups.com
Another option is to script the addition of metadata to the resources
via exiftool outside of RS, so that you can just upload the files and
have ResourceSpace extract the fields from the files upon upload.

Blue-J

unread,
Dec 22, 2009, 3:44:22 AM12/22/09
to ResourceSpace
Hi Aethaelweard; thanks for your warmth and enthusiasm! This is great
stuff. I've written you off-board and look forward to hearing your
response. This is something along the lines that has already gotten a
lot of thought and I'd love to see if we can pool resources here.

- J

Reply all
Reply to author
Forward
0 new messages