[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[EP-tech] Re: Subject trees
Thanks John,
That would be the same documentation that I've skipped over a dozen times trying to trace the function... maybe I should change the comments to a more contrasting colour... and also using the right syntax helps (EP::DO::Subject::create rather than EP::DO::Subject->create)
Point of note though, the $name parameter appears to actually be an array of hashes with a slightly different format from the comment - the line below is the one that finally worked!
$new_subject_obj = EPrints::DataObj::Subject::create($repository,"new_subject_id",[{"name"=>"New Subject Name",lang=>"en"}],["ROOT"],0);
Thanks for your help! (still not sure about whether create_child has a bug or I do though, in case anyone wants to dig deeper?)
Alan
From: eprints-tech-bounces at ecs.soton.ac.uk [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of John Salter
Sent: 07 January 2016 10:58
To: 'eprints-tech at ecs.soton.ac.uk' <eprints-tech at ecs.soton.ac.uk>
Subject: [EP-tech] Re: Subject trees
Aahhhhh, this is a good'un...
In ~/perl_lib/EPrints/DataObj/Subject.pm, lines 278-291... I'll recreate them here:
######################################################################
# =pod
#
# =item $subject = EPrints::DataObj::Subject::create( $session, $id, $name, $parents, $depositable )
#
# Creates a new subject in the database. $id is the ID of the subject,
# $name is a multilang data structure with the name of the subject in
# one or more languages. eg. { en=>"Trousers", en-us=>"Pants}. $parents
# is a reference to an array containing the ID's of one or more other
# subjects (don't make loops!). If $depositable is true then eprints may
# belong to this subject.
#
# =cut
######################################################################
As you can see - a nice block of documentation... but unfortunately, each line starts with a '#' - so the pod doesn't get parsed as a pod - and you don't get to see what's going on! (this is still the case in https://github.com/eprints/eprints/blob/3.3/perl_lib/EPrints/DataObj/Subject.pm - I'll patch it!).
Cheers,
John
From: eprints-tech-bounces at ecs.soton.ac.uk<mailto:eprints-tech-bounces at ecs.soton.ac.uk> [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of Alan.Stiles
Sent: 07 January 2016 10:10
To: eprints-tech at ecs.soton.ac.uk<mailto:eprints-tech at ecs.soton.ac.uk>
Subject: [EP-tech] Re: Subject trees
What documentation are you looking at John? Think I'm fighting with the parameters on 'create'. When I try the following code:
#!/usr/bin/perl -w -I/opt/eprints3/perl_lib
use strict;
use EPrints;
my $ep = EPrints->new();
my $repository = $ep->repository( "repoid" );
my $tech_item = EPrints::DataObj::Subject->create($repository, "new_item_id",[{"name"=>"New Item Description"}],["parentid"],1);
I get an error message
Can't use string ("EPrints::DataObj::Subject") as a HASH ref while "strict refs" in use at /opt/eprints3/perl_lib/EPrints/DataObj.pm line 968.
Within 'create_child' it uses $self->{subjectid} as the value for parentid, but from debugging it looks like the value is actually in $self->{data}->{subjectid} not sure if this is me not understanding something about eprints structure or a possible bug?
The subjects don't seem to need commit() to add them (at least via create_child - I had it in the code originally but it didn't seem to make a difference) and reindexing the subject dataset hasn't done anything. Thanks for the ideas though.
Alan
From: eprints-tech-bounces at ecs.soton.ac.uk<mailto:eprints-tech-bounces at ecs.soton.ac.uk> [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of John Salter
Sent: 06 January 2016 21:20
To: 'eprints-tech at ecs.soton.ac.uk' <eprints-tech at ecs.soton.ac.uk<mailto:eprints-tech at ecs.soton.ac.uk>>
Subject: [EP-tech] Re: Subject trees
No experience - but looking at the documentation, you could possibly achieve what you need with the 'create' method instead?
Other thoughts are:
- does anything change when you commit() the new subject?
- does reindexing the subjects change anything?
Cheers,
John
From: eprints-tech-bounces at ecs.soton.ac.uk<mailto:eprints-tech-bounces at ecs.soton.ac.uk> [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of Alan.Stiles
Sent: 06 January 2016 17:35
To: eprints-tech at ecs.soton.ac.uk<mailto:eprints-tech at ecs.soton.ac.uk>
Subject: [EP-tech] Subject trees
Hi all,
Anyone have any experience with updating the subject tree via the API? (using 3.3.10 but current github module for EPrints::DataObj::Subject looks similar)
I'm trying to add a new top level entry with the following code snippet...
my $rootsubj = EPrints::DataObj::Subject->new($repository,"ROOT");
exit unless defined($rootsubj);
my $newsubj = $rootsubj->create_child("newid",[{name=>"New Top Level Subject"}],0);
It creates the subject, but orphaned rather than linked to the ROOT object as I'd expect...
Any clues?
Alan Stiles
Digital Repository Developer
Library Services, The Open University
-- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). The Open University is authorised and regulated by the Financial Conduct Authority.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20160107/c7f2f328/attachment-0001.html