Adding your own configuration variable

From EPrints Documentation
Jump to: navigation, search


There are a number of reason why you would want to add your own configuration data to EPrints.

For me, I wanted to centralise the details for a database connection I needed for some secondary data (I had reasons for not including it in the main EPrints database)


To get the configuration variables into the system, the best way is to create a new configurations script:

 # {oarj} is the general configuration area
 $c->{oarj} = {} unless exists $c->{oarj}; # only create it if it doesn't exist
 # {db_conf} is a set of variables within that area
 $c->{oarj}->{db_conf} = {
    db_name     => 'myDB',
    db_hostname => '',
    db_username => 'user',
    db_password => 'password',

Reading the configuration

Once we have the configuration, we need to be able to read it back:

 my $ep = $self->{session};
 my $db_conf = $ep->get_repository->get_conf( "oarj","db_conf" );
 my $dbh     = DBI->connect(
   { AutoCommit        => 0,
     PrintError        => 1,
     showErrorStatment => 1
     or $self->{processor}->add_message( "error",
   $session->make_text("cannot connect to ".$db_conf->{db_name}.": $DBI::errstr") );

There you are...