Update script ?

83 views
Skip to first unread message

antoine.y

unread,
Mar 16, 2017, 12:15:35 PM3/16/17
to islandora
Hello,

I need some help to find out how to update values in Islandora with a script, as I'd like to keep my data up to date (we have something like 8.000 scholars that come from an external source).
 
Is there a way to perform a "sql like" query to update islandora objects ? 

For example, updating a title with the PID of an object, in sql it would be something like : 

UPDATE Collection1 SET mods_titleInfo_title_s = 'My New Title' WHERE PID = 'islandora:16552;'

So I can have a list of input PIDs that I can process in a foreach.

I have tested the module "Islandora Search and Replace", but it only allows to search a strict string and replace it with another, not to perform requests.

Thanks a lot for your help.

Regards

jy

unread,
Mar 16, 2017, 2:03:12 PM3/16/17
to isla...@googlegroups.com
If you look in the includes directory of this repo you will see some code examples of how to access and manipulate fedora objects.  You will also need to become familiar with the tuque API.  This assumes you are comfortable working in php and have access to the repo server.

https://github.com/jyobb/islandora_management_utilities

https://wiki.duraspace.org/display/ISLANDORA712/Build,+Access,+Modify+and+Delete+Fedora+objects+with+the+Tuque+interface

--
For more information about using this group, please read our Listserv Guidelines: http://islandora.ca/content/welcome-islandora-listserv
---
You received this message because you are subscribed to the Google Groups "islandora" group.
To unsubscribe from this group and stop receiving emails from it, send an email to islandora+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/islandora.
To view this discussion on the web visit https://groups.google.com/d/msgid/islandora/9c99cc08-188a-4863-be6f-069dfb38ef60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dp...@metro.org

unread,
Mar 16, 2017, 3:43:10 PM3/16/17
to islandora
Hi Antonine.

Since Islandora Objects are Fedora Objects really and they live inside Fedora repository as XML files and binary "things" attached to a main XML file (the infamous FOXML file) there is not a single language (like SQL) that allows you to update their properties. There are some modules (like the https://github.com/discoverygarden/islandora_xquery) of the find and replace that can do some manipulations but at the end of the day you would end doing something in two stages:

1 - have SPARQL or SOLR to select and filter Objects and get a list of PID
2. programmatic access to modify them (remember, some things like label, etc can be accessed directly as proporties of an php object, others like MODS metadata via xml manipulation) after you did the selecting-of-what-is-relevant part

I would suggest starting here:


And i do like this module of the Fabulous Mark Jordan. I can help you understand what you need to do to process a list PIDs and change objects (sounds that familiar to your needs?)



Cheers!

Diego Pino
Metro.org


On Thursday, March 16, 2017 at 2:03:12 PM UTC-4, John wrote:
If you look in the includes directory of this repo you will see some code examples of how to access and manipulate fedora objects.  You will also need to become familiar with the tuque API.  This assumes you are comfortable working in php and have access to the repo server.

https://github.com/jyobb/islandora_management_utilities

https://wiki.duraspace.org/display/ISLANDORA712/Build,+Access,+Modify+and+Delete+Fedora+objects+with+the+Tuque+interface
On Thu, Mar 16, 2017 at 10:15 AM, antoine.y <yeeee...@gmail.com> wrote:
Hello,

I need some help to find out how to update values in Islandora with a script, as I'd like to keep my data up to date (we have something like 8.000 scholars that come from an external source).
 
Is there a way to perform a "sql like" query to update islandora objects ? 

For example, updating a title with the PID of an object, in sql it would be something like : 

UPDATE Collection1 SET mods_titleInfo_title_s = 'My New Title' WHERE PID = 'islandora:16552;'

So I can have a list of input PIDs that I can process in a foreach.

I have tested the module "Islandora Search and Replace", but it only allows to search a strict string and replace it with another, not to perform requests.

Thanks a lot for your help.

Regards

--
For more information about using this group, please read our Listserv Guidelines: http://islandora.ca/content/welcome-islandora-listserv
---
You received this message because you are subscribed to the Google Groups "islandora" group.
To unsubscribe from this group and stop receiving emails from it, send an email to islandora+...@googlegroups.com.

antoine.y

unread,
Mar 17, 2017, 11:11:40 AM3/17/17
to islandora
Thanks guys for your answers ! I took some ideas in your different links, and I now have a prototype of something that seems to work. It's been easier than what I expected.

If one day someone needs to do something like that, here is my - friday morning, quick, raw... - code :

<?php
//Includes files and loading Drupal's functions
chdir
("/var/www/drupal");
define
('DRUPAL_ROOT', getcwd());
require_once
'./includes/bootstrap.inc';
include
(DRUPAL_ROOT . '/sites/all/libraries/constants.php');
drupal_bootstrap
(DRUPAL_BOOTSTRAP_FULL);


$statusCode
= '206055';
updatePersonWithStatusCode
($statusCode);

function updatePersonWithStatusCode($statusCodeInput)
{
 
//Solr request to get the PID of the author with "MADS_status"
 $personToUpdate
= FEDORA_REQUEST_URL . '/select?q=MADS_status_ms:"' . $statusCodeInput . '"' .
 
'&fl=PID' .
 
'&rows=1&wt=json';

 
//Curl call
 $curl
= curl_init($personToUpdate);
 curl_setopt
($curl, CURLOPT_RETURNTRANSFER, true);
 $curl_response
= curl_exec($curl);
 curl_close
($curl);
 $decodedRequest
= json_decode($curl_response, true);


 
//Get the author's PID
 $pidAuthorToUpdate
= $decodedRequest['response']['docs'][0]['PID'];

 
//Loading islandora object
 $object
= islandora_object_load($pidAuthorToUpdate);

 
//Init repository connection
 
if($object)
 
{
 $repository
= $object->repository;
 
}

 
//Loading MADS from the object
 $mads
= simplexml_load_string($object['MADS']->content);

 
//Changing the email of current object
 $mads
->affiliation->address->email = 'new_...@example.com';

 
//Writing xml file
 $mads
->asXML('test.mads');

 
//Setting MADS modification in Islandora
 $object
['MADS']->setContentFromFile('test.mads');
}
?>


I now will have to read my external source and do a loop on this function, nothing hard. I'm gonna see if it works for 8000+ scholars...

Thanks again for your help, I'll all your links in my favs, very useful. Best regards.

Antoine


click...@gmail.com

unread,
Apr 7, 2017, 7:27:21 AM4/7/17
to islandora
Hi Antoine,

in case you (or someone else) need a solution for batch transformation of datastreams, please feel free to use our tool:
http://gitlab.srce.hr/alen-zubic/fdtt_community

Kind regards,
Alen
Reply all
Reply to author
Forward
0 new messages